1 /* $TOG: cppsetup.c /main/18 1998/02/06 11:09:35 kaleb $ */
4 Copyright (c) 1993, 1994, 1998 The Open Group
8 The above copyright notice and this permission notice shall be included in
9 all copies or substantial portions of the Software.
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
15 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 Except as contained in this notice, the name of The Open Group shall not be
19 used in advertising or otherwise to promote the sale, use or other dealings
20 in this Software without prior written authorization from The Open Group.
28 * This file is strictly for the sake of cpy.y and yylex.c (if
29 * you indeed have the source for cpp).
38 #if pdp11 | vax | ns16000 | mc68000 | ibm032
44 * These variables used by cpy.y and yylex.c
46 extern char *outp, *inp, *newp, *pend;
54 struct filepointer *currentfile;
55 struct inclist *currentinc;
57 cppsetup(line, filep, inc)
59 register struct filepointer *filep;
60 register struct inclist *inc;
62 register char *p, savec;
63 static boolean setupdone = FALSE;
78 * put a newline back on the end, and set up pend, etc.
93 struct symtab **lookup(symbol)
96 static struct symtab *undefined;
99 sp = isdefined(symbol, currentinc, NULL);
102 (*sp)->s_value = NULL;
107 pperror(tag, x0,x1,x2,x3,x4)
108 int tag,x0,x1,x2,x3,x4;
110 warning("\"%s\", line %d: ", currentinc->i_file, currentfile->f_line);
111 warning(x0,x1,x2,x3,x4);
118 fatalerr("Fatal error: %s\n", s);
122 #include "ifparser.h"
124 struct filepointer *filep;
130 my_if_errors (ip, cp, expecting)
133 const char *expecting;
135 struct _parse_data *pd = (struct _parse_data *) ip->data;
136 int lineno = pd->filep->f_line;
137 char *filename = pd->inc->i_file;
142 sprintf (prefix, "\"%s\":%d", filename, lineno);
143 prefixlen = strlen(prefix);
144 fprintf (stderr, "%s: %s", prefix, pd->line);
146 if (i > 0 && pd->line[i-1] != '\n') {
149 for (i += prefixlen + 3; i > 0; i--) {
152 fprintf (stderr, "^--- expecting %s\n", expecting);
157 #define MAXNAMELEN 256
159 static struct symtab **
160 lookup_variable (ip, var, len)
165 char tmpbuf[MAXNAMELEN + 1];
166 struct _parse_data *pd = (struct _parse_data *) ip->data;
168 if (len > MAXNAMELEN)
171 strncpy (tmpbuf, var, len);
173 return isdefined (tmpbuf, pd->inc, NULL);
178 my_eval_defined (ip, var, len)
183 if (lookup_variable (ip, var, len))
189 #define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
192 my_eval_variable (ip, var, len)
199 s = lookup_variable (ip, var, len);
204 if (!isvarfirstletter(*var))
206 s = lookup_variable (ip, var, strlen(var));
209 return strtol(var, NULL, 0);
213 cppsetup(line, filep, inc)
215 register struct filepointer *filep;
216 register struct inclist *inc;
219 struct _parse_data pd;
225 ip.funcs.handle_error = my_if_errors;
226 ip.funcs.eval_defined = my_eval_defined;
227 ip.funcs.eval_variable = my_eval_variable;
228 ip.data = (char *) &pd;
230 (void) ParseIfExpression (&ip, line, &val);