[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.19

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