1 /* $XConsortium: cppsetup.c /main/17 1996/09/28 16:15:03 rws $ */
4 Copyright (c) 1993, 1994 X Consortium
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 Except as contained in this notice, the name of the X Consortium shall not be
24 used in advertising or otherwise to promote the sale, use or other dealings
25 in this Software without prior written authorization from the X Consortium.
28 /* $XFree86: xc/config/makedepend/cppsetup.c,v 3.2 1996/12/30 13:57:53 dawes Exp $ */
34 * This file is strictly for the sake of cpy.y and yylex.c (if
35 * you indeed have the source for cpp).
44 #if defined(pdp11) || defined(vax) || defined(ns16000) || defined(mc68000) || defined(ibm032)
50 * These variables used by cpy.y and yylex.c
52 extern char *outp, *inp, *newp, *pend;
60 struct filepointer *currentfile;
61 struct inclist *currentinc;
63 cppsetup(line, filep, inc)
65 register struct filepointer *filep;
66 register struct inclist *inc;
68 register char *p, savec;
69 static boolean setupdone = FALSE;
84 * put a newline back on the end, and set up pend, etc.
99 struct symtab **lookup(symbol)
102 static struct symtab *undefined;
105 sp = isdefined(symbol, currentinc, NULL);
108 (*sp)->s_value = NULL;
113 pperror(tag, x0,x1,x2,x3,x4)
114 int tag,x0,x1,x2,x3,x4;
116 warning("\"%s\", line %d: ", currentinc->i_file, currentfile->f_line);
117 warning(x0,x1,x2,x3,x4);
124 fatalerr("Fatal error: %s\n", s);
128 #include "ifparser.h"
130 struct filepointer *filep;
136 my_if_errors (ip, cp, expecting)
139 const char *expecting;
141 struct _parse_data *pd = (struct _parse_data *) ip->data;
142 int lineno = pd->filep->f_line;
143 char *filename = pd->inc->i_file;
148 sprintf (prefix, "\"%s\":%d", filename, lineno);
149 prefixlen = strlen(prefix);
150 fprintf (stderr, "%s: %s", prefix, pd->line);
152 if (i > 0 && pd->line[i-1] != '\n') {
155 for (i += prefixlen + 3; i > 0; i--) {
158 fprintf (stderr, "^--- expecting %s\n", expecting);
163 #define MAXNAMELEN 256
165 static struct symtab **
166 lookup_variable (ip, var, len)
171 char tmpbuf[MAXNAMELEN + 1];
172 struct _parse_data *pd = (struct _parse_data *) ip->data;
174 if (len > MAXNAMELEN)
177 strncpy (tmpbuf, var, len);
179 return isdefined (tmpbuf, pd->inc, NULL);
184 my_eval_defined (ip, var, len)
189 if (lookup_variable (ip, var, len))
195 #define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
198 my_eval_variable (ip, var, len)
205 s = lookup_variable (ip, var, len);
210 if (!isvarfirstletter(*var))
212 s = lookup_variable (ip, var, strlen(var));
215 return strtol(var, NULL, 0);
219 cppsetup(line, filep, inc)
221 register struct filepointer *filep;
222 register struct inclist *inc;
225 struct _parse_data pd;
231 ip.funcs.handle_error = my_if_errors;
232 ip.funcs.eval_defined = my_eval_defined;
233 ip.funcs.eval_variable = my_eval_variable;
234 ip.data = (char *) &pd;
236 (void) ParseIfExpression (&ip, line, &val);