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 35 extern GSymT *VAR_GLOBAL; /* Variables defined in a global context, e.g 36 * in the Makefile itself */ 37 extern GSymT *VAR_CMD; /* Variables defined on the command line */ 38 39 /* Global contexts handling. */ 40 /* value = Var_Valuei(name, end); 41 * Returns value of global variable name/end, or NULL if inexistent. */ 42 extern char *Var_Valuei(const char *, const char *); 43 #define Var_Value(n) Var_Valuei(n, NULL) 44 45 /* Var_Seti(name, end, val, ctxt); 46 * Sets value val of variable name/end in context ctxt. Copies val. */ 47 extern void Var_Seti(const char *, const char *, const char *, 48 GSymT *); 49 #define Var_Set(n, v, ctxt) Var_Seti(n, NULL, v, ctxt) 50 /* Var_Appendi(name, end, val, cxt); 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. */ 53 extern void Var_Appendi(const char *, const char *, 54 const char *, GSymT *); 55 #define Var_Append(n, v, ctxt) Var_Appendi(n, NULL, v, ctxt) 56 57 /* Var_Delete(name); 58 * Deletes a variable from the global context. */ 59 extern void Var_Delete(const char *); 60 61 /* Local context handling */ 62 #define TARGET_INDEX 0 63 #define PREFIX_INDEX 1 64 #define ARCHIVE_INDEX 2 65 #define MEMBER_INDEX 3 66 #define OODATE_INDEX 4 67 #define ALLSRC_INDEX 5 68 #define IMPSRC_INDEX 6 69 extern char *Varq_Value(int, GNode *); 70 extern void Varq_Set(int, const char *, GNode *); 71 extern void Varq_Append(int, const char *, GNode *); 72 73 /* SymTable_Init(t); 74 * Inits the local symtable in a GNode. */ 75 extern void SymTable_Init(SymTable *); 76 /* SymTable_destroy(t); 77 * Destroys the local symtable in a GNode. */ 78 extern void SymTable_Destroy(SymTable *); 79 80 /* Several ways to parse a variable specification. */ 81 /* value = Var_Parse(varspec, ctxt, undef_is_bad, &length, &freeit); 82 * Parses a variable specification varspec and evaluates it in context 83 * ctxt. Returns the resulting value, freeit indicates whether it's 84 * a copy that should be freed when no longer needed. If it's not a 85 * copy, it's only valid until the next time variables are set. 86 * The length of the spec is returned in length, e.g., varspec begins 87 * at the $ and ends at the closing } or ). Returns special value 88 * var_Error if a problem occurred. */ 89 extern char *Var_Parse(const char *, SymTable *, bool, size_t *, 90 bool *); 91 /* Note that var_Error is an instance of the empty string "", so that 92 * callers who don't care don't need to. */ 93 extern char var_Error[]; 94 95 /* length = Var_ParseSkip(varspec, ctxt, &ok); 96 * Parses a variable specification and returns the specification 97 * length. Fills ok if the varspec is correct, that pointer can be 98 * NULL if this information is not needed. */ 99 extern size_t Var_ParseSkip(const char *, SymTable *, bool *); 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); 114 115 /* Var_SubstVar(buf, str, varname, val); 116 * Substitutes variable varname with value val in string str, adding 117 * the result to buffer buf. undefs are never error. */ 118 extern void Var_SubstVar(Buffer, const char *, const char *, const char *); 119 120 /* Note that substituting to a buffer in Var_Subst is not useful. On the 121 * other hand, handling intervals in Var_Subst and Var_Parse would be 122 * useful, but this is hard. */ 123 124 /* Var_Dump(); 125 * Print out all global variables. */ 126 extern void Var_Dump(void); 127 128 /* Var_AddCmdline(name); 129 * Add all variable values from VAR_CMD to variable name. 130 * Used to propagate variable values to submakes through MAKEFLAGS. */ 131 extern void Var_AddCmdline(const char *); 132 133 134 extern bool oldVars; /* Do old-style variable substitution */ 135 136 extern bool checkEnvFirst; /* true if environment should be searched for 137 * variables before the global context */ 138 139 #endif 140