Annotation of src/usr.bin/make/var.h, Revision 1.5
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:
47: /* Var_Seti(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.1 espie 50: extern void Var_Seti(const char *, const char *, const char *,
1.2 espie 51: int);
1.1 espie 52: #define Var_Set(n, v, ctxt) Var_Seti(n, NULL, v, ctxt)
53: /* Var_Appendi(name, end, val, cxt);
54: * Appends value val to variable name/end in context ctxt, defining it
55: * if it does not already exist, and inserting one space otherwise. */
56: extern void Var_Appendi(const char *, const char *,
1.2 espie 57: const char *, int);
1.1 espie 58: #define Var_Append(n, v, ctxt) Var_Appendi(n, NULL, v, ctxt)
59:
1.4 espie 60: /* Var_Deletei(name, end);
61: * Deletes a global variable. */
62: extern void Var_Deletei(const char *, const char *);
1.1 espie 63:
1.4 espie 64: /* Dynamic variable indices */
1.1 espie 65: #define TARGET_INDEX 0
66: #define PREFIX_INDEX 1
67: #define ARCHIVE_INDEX 2
68: #define MEMBER_INDEX 3
69: #define OODATE_INDEX 4
70: #define ALLSRC_INDEX 5
71: #define IMPSRC_INDEX 6
1.4 espie 72: /* value = Varq_Value(index, node);
73: * Returns value of dynamic variable for a given node. */
1.1 espie 74: extern char *Varq_Value(int, GNode *);
1.4 espie 75: /* Varq_Set(index, val, node);
76: * Sets value of dynamic variable for a given node. Copies val. */
1.1 espie 77: extern void Varq_Set(int, const char *, GNode *);
1.4 espie 78: /* Varq_Append(index, val, node);
79: * Appends to value of dynamic variable for a given node. */
1.1 espie 80: extern void Varq_Append(int, const char *, GNode *);
81:
82: /* SymTable_Init(t);
83: * Inits the local symtable in a GNode. */
84: extern void SymTable_Init(SymTable *);
85: /* SymTable_destroy(t);
86: * Destroys the local symtable in a GNode. */
87: extern void SymTable_Destroy(SymTable *);
88:
89: /* Several ways to parse a variable specification. */
90: /* value = Var_Parse(varspec, ctxt, undef_is_bad, &length, &freeit);
91: * Parses a variable specification varspec and evaluates it in context
92: * ctxt. Returns the resulting value, freeit indicates whether it's
93: * a copy that should be freed when no longer needed. If it's not a
94: * copy, it's only valid until the next time variables are set.
95: * The length of the spec is returned in length, e.g., varspec begins
96: * at the $ and ends at the closing } or ). Returns special value
97: * var_Error if a problem occurred. */
98: extern char *Var_Parse(const char *, SymTable *, bool, size_t *,
99: bool *);
100: /* Note that var_Error is an instance of the empty string "", so that
101: * callers who don't care don't need to. */
102: extern char var_Error[];
103:
1.5 ! espie 104: /* ok = Var_ParseSkip(&varspec, ctxt, &ok);
! 105: * Parses a variable specification and returns true if the varspec
! 106: * is correct. Advances pointer past specification. */
! 107: extern bool Var_ParseSkip(const char **, SymTable *);
1.1 espie 108:
109: /* ok = Var_ParseBuffer(buf, varspec, ctxt, undef_is_bad, &length);
110: * Similar to Var_Parse, except the value is directly appended to
111: * buffer buf. */
112: extern bool Var_ParseBuffer(Buffer, const char *, SymTable *,
113: bool, size_t *);
114:
115:
116: /* The substitution itself */
117: /* subst = Var_Subst(str, ctxt, undef_is_bad);
118: * Substitutes all variable values in string str under context ctxt.
119: * Emit a PARSE_FATAL error if undef_is_bad and an undef variable is
120: * encountered. The result is always a copy that should be free. */
121: extern char *Var_Subst(const char *, SymTable *, bool);
122:
1.4 espie 123:
124: /* For loop handling.
125: * // Create handle for variable name.
126: * handle = Var_NewLoopVar(name, end);
127: * // set up buffer
128: * for (...)
129: * // Substitute val for variable in str, and accumulate in buffer
130: * Var_SubstVar(buffer, str, handle, val);
131: * // Free handle
132: * Var_DeleteLoopVar(handle);
133: */
134: struct LoopVar; /* opaque handle */
135: struct LoopVar *Var_NewLoopVar(const char *, const char *);
136: void Var_DeleteLoopVar(struct LoopVar *);
137: extern void Var_SubstVar(Buffer, const char *, struct LoopVar *, const char *);
138:
1.1 espie 139:
140: /* Var_Dump();
141: * Print out all global variables. */
142: extern void Var_Dump(void);
143:
144: /* Var_AddCmdline(name);
145: * Add all variable values from VAR_CMD to variable name.
146: * Used to propagate variable values to submakes through MAKEFLAGS. */
147: extern void Var_AddCmdline(const char *);
148:
1.2 espie 149: /* stuff common to var.c and varparse.c */
1.3 espie 150: extern bool errorIsOkay;
1.1 espie 151:
1.4 espie 152: #define VAR_GLOBAL 0
1.2 espie 153: /* Variables defined in a global context, e.g in the Makefile itself */
154: #define VAR_CMD 1
155: /* Variables defined on the command line */
156:
1.4 espie 157: #define POISON_INVALID 0
158: #define POISON_DEFINED 1
1.2 espie 159: #define POISON_NORMAL 64
160: #define POISON_EMPTY 128
161: #define POISON_NOT_DEFINED 256
1.1 espie 162:
1.2 espie 163: extern void Var_MarkPoisoned(const char *, const char *, unsigned int);
1.1 espie 164:
165: #endif