[BACK]Return to var.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / make

Annotation of src/usr.bin/make/var.h, Revision 1.7

1.1       espie       1: #ifndef VAR_H
                      2: #define VAR_H
                      3: /*
                      4:  * Copyright (c) 2001 Marc Espie.
                      5:  *
                      6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
                      9:  * 1. Redistributions of source code must retain the above copyright
                     10:  *    notice, this list of conditions and the following disclaimer.
                     11:  * 2. Redistributions in binary form must reproduce the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer in the
                     13:  *    documentation and/or other materials provided with the distribution.
                     14:  *
                     15:  * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
                     16:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
                     17:  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
                     18:  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OPENBSD
                     19:  * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
                     20:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
                     21:  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     22:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     23:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     24:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
                     25:  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     26:  */
                     27:
                     28: extern void Var_Init(void);
                     29: #ifdef CLEANUP
                     30: extern void Var_End(void);
                     31: #else
                     32: #define Var_End()
                     33: #endif
                     34:
1.2       espie      35: extern void Var_setCheckEnvFirst(bool);
1.1       espie      36:
1.4       espie      37: /* Global variable handling. */
1.1       espie      38: /* value = Var_Valuei(name, end);
                     39:  *     Returns value of global variable name/end, or NULL if inexistent. */
                     40: extern char *Var_Valuei(const char *, const char *);
                     41: #define Var_Value(n)   Var_Valuei(n, NULL)
1.4       espie      42:
                     43: /* isDefined = Var_Definedi(name, end);
                     44:  *     Checks whether global variable name/end is defined. */
1.2       espie      45: extern bool Var_Definedi(const char *, const char *);
1.1       espie      46:
1.6       espie      47: /* Var_Seti_with_ctxt(name, end, val, ctxt);
1.4       espie      48:  *     Sets value val of variable name/end.  Copies val.
                     49:  *     ctxt can be VAR_CMD (command line) or VAR_GLOBAL (normal variable). */
1.6       espie      50: extern void Var_Seti_with_ctxt(const char *, const char *, const char *,
1.2       espie      51:        int);
1.6       espie      52: #define Var_Set(n, v)  Var_Seti_with_ctxt(n, NULL, v, VAR_GLOBAL)
                     53: #define Var_Seti(n, e, v) Var_Seti_with_ctxt(n, e, v, VAR_GLOBAL)
                     54: /* Var_Appendi_with_ctxt(name, end, val, cxt);
1.1       espie      55:  *     Appends value val to variable name/end in context ctxt, defining it
                     56:  *     if it does not already exist, and inserting one space otherwise. */
1.6       espie      57: extern void Var_Appendi_with_ctxt(const char *, const char *,
1.2       espie      58:        const char *, int);
1.6       espie      59: #define Var_Append(n, v)       Var_Appendi_with_ctxt(n, NULL, v, VAR_GLOBAL)
                     60: #define Var_Appendi(n, e, v)   Var_Appendi_with_ctxt(n, e, v, VAR_GLOBAL)
1.1       espie      61:
1.4       espie      62: /* Var_Deletei(name, end);
                     63:  *     Deletes a global variable. */
                     64: extern void Var_Deletei(const char *, const char *);
1.1       espie      65:
1.4       espie      66: /* Dynamic variable indices */
1.1       espie      67: #define TARGET_INDEX   0
                     68: #define PREFIX_INDEX   1
                     69: #define ARCHIVE_INDEX  2
                     70: #define MEMBER_INDEX   3
                     71: #define OODATE_INDEX   4
                     72: #define ALLSRC_INDEX   5
                     73: #define IMPSRC_INDEX   6
1.4       espie      74: /* value = Varq_Value(index, node);
                     75:  *     Returns value of dynamic variable for a given node. */
1.1       espie      76: extern char *Varq_Value(int,  GNode *);
1.4       espie      77: /* Varq_Set(index, val, node);
                     78:  *     Sets value of dynamic variable for a given node. Copies val. */
1.1       espie      79: extern void Varq_Set(int, const char *, GNode *);
1.4       espie      80: /* Varq_Append(index, val, node);
                     81:  *     Appends to value of dynamic variable for a given node. */
1.1       espie      82: extern void Varq_Append(int, const char *, GNode *);
                     83:
                     84: /* SymTable_Init(t);
                     85:  *     Inits the local symtable in a GNode. */
                     86: extern void SymTable_Init(SymTable *);
                     87: /* SymTable_destroy(t);
                     88:  *     Destroys the local symtable in a GNode. */
                     89: extern void SymTable_Destroy(SymTable *);
                     90:
                     91: /* Several ways to parse a variable specification. */
                     92: /* value = Var_Parse(varspec, ctxt, undef_is_bad, &length, &freeit);
                     93:  *     Parses a variable specification varspec and evaluates it in context
                     94:  *     ctxt.  Returns the resulting value, freeit indicates whether it's
                     95:  *     a copy that should be freed when no longer needed.  If it's not a
                     96:  *     copy, it's only valid until the next time variables are set.
                     97:  *     The length of the spec is returned in length, e.g., varspec begins
                     98:  *     at the $ and ends at the closing } or ).  Returns special value
                     99:  *     var_Error if a problem occurred. */
                    100: extern char *Var_Parse(const char *, SymTable *, bool, size_t *,
                    101:        bool *);
                    102: /* Note that var_Error is an instance of the empty string "", so that
                    103:  * callers who don't care don't need to. */
                    104: extern char    var_Error[];
                    105:
1.5       espie     106: /* ok = Var_ParseSkip(&varspec, ctxt, &ok);
                    107:  *     Parses a variable specification and returns true if the varspec
                    108:  *     is correct. Advances pointer past specification.  */
                    109: extern bool Var_ParseSkip(const char **, SymTable *);
1.1       espie     110:
                    111: /* ok = Var_ParseBuffer(buf, varspec, ctxt, undef_is_bad, &length);
                    112:  *     Similar to Var_Parse, except the value is directly appended to
                    113:  *     buffer buf. */
                    114: extern bool Var_ParseBuffer(Buffer, const char *, SymTable *,
                    115:        bool, size_t *);
                    116:
                    117:
                    118: /* The substitution itself */
                    119: /* subst = Var_Subst(str, ctxt, undef_is_bad);
                    120:  *     Substitutes all variable values in string str under context ctxt.
                    121:  *     Emit a PARSE_FATAL error if undef_is_bad and an undef variable is
                    122:  *     encountered. The result is always a copy that should be free. */
                    123: extern char *Var_Subst(const char *, SymTable *, bool);
1.7     ! espie     124: /* subst = Var_Substi(str, estr, ctxt, undef_if_bad);
        !           125:  */
        !           126: extern char *Var_Substi(const char *, const char *, SymTable *, bool);
1.1       espie     127:
1.4       espie     128:
                    129: /* For loop handling.
                    130:  *     // Create handle for variable name.
                    131:  *     handle = Var_NewLoopVar(name, end);
                    132:  *     // set up buffer
                    133:  *     for (...)
                    134:  *             // Substitute val for variable in str, and accumulate in buffer
                    135:  *             Var_SubstVar(buffer, str, handle, val);
                    136:  *     // Free handle
                    137:  *     Var_DeleteLoopVar(handle);
                    138:  */
                    139: struct LoopVar;        /* opaque handle */
                    140: struct LoopVar *Var_NewLoopVar(const char *, const char *);
                    141: void Var_DeleteLoopVar(struct LoopVar *);
                    142: extern void Var_SubstVar(Buffer, const char *, struct LoopVar *, const char *);
                    143:
1.1       espie     144:
                    145: /* Var_Dump();
                    146:  *     Print out all global variables. */
                    147: extern void Var_Dump(void);
                    148:
                    149: /* Var_AddCmdline(name);
                    150:  *     Add all variable values from VAR_CMD to variable name.
                    151:  *     Used to propagate variable values to submakes through MAKEFLAGS.  */
                    152: extern void Var_AddCmdline(const char *);
                    153:
1.2       espie     154: /* stuff common to var.c and varparse.c */
1.3       espie     155: extern bool    errorIsOkay;
1.1       espie     156:
1.4       espie     157: #define                VAR_GLOBAL      0
1.2       espie     158:        /* Variables defined in a global context, e.g in the Makefile itself */
                    159: #define                VAR_CMD         1
                    160:        /* Variables defined on the command line */
                    161:
1.4       espie     162: #define POISON_INVALID         0
                    163: #define POISON_DEFINED         1
1.2       espie     164: #define POISON_NORMAL          64
                    165: #define POISON_EMPTY           128
                    166: #define POISON_NOT_DEFINED     256
1.1       espie     167:
1.2       espie     168: extern void Var_MarkPoisoned(const char *, const char *, unsigned int);
1.1       espie     169:
                    170: #endif