1 /* $Xorg: cppsetup.c,v 1.5 2001/02/09 02:03:16 xorgcvs Exp $ */
4 Copyright (c) 1993, 1994, 1998 The Open Group
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from The Open Group.
27 /* $XFree86: xc/config/makedepend/cppsetup.c,v 3.11 2001/12/17 20:52:22 dawes Exp $ */
33 * This file is strictly for the sake of cpy.y and yylex.c (if
34 * you indeed have the source for cpp).
43 #if defined(pdp11) || defined(vax) || defined(ns16000) || defined(mc68000) || defined(ibm032)
49 * These variables used by cpy.y and yylex.c
51 extern char *outp
, *inp
, *newp
, *pend
;
59 struct filepointer
*currentfile
;
60 struct inclist
*currentinc
;
63 cppsetup(char *line
, struct filepointer
*filep
, struct inclist
*inc
)
66 static boolean setupdone
= FALSE
;
81 * put a newline back on the end, and set up pend, etc.
96 struct symtab
**lookup(symbol
)
99 static struct symtab
*undefined
;
102 sp
= isdefined(symbol
, currentinc
, NULL
);
105 (*sp
)->s_value
= NULL
;
110 pperror(tag
, x0
,x1
,x2
,x3
,x4
)
111 int tag
,x0
,x1
,x2
,x3
,x4
;
113 warning("\"%s\", line %d: ", currentinc
->i_file
, currentfile
->f_line
);
114 warning(x0
,x1
,x2
,x3
,x4
);
121 fatalerr("Fatal error: %s\n", s
);
125 #include "ifparser.h"
127 struct filepointer
*filep
;
134 my_if_errors (IfParser
*ip
, const char *cp
, const char *expecting
)
136 struct _parse_data
*pd
= (struct _parse_data
*) ip
->data
;
137 int lineno
= pd
->filep
->f_line
;
138 char *filename
= pd
->filename
;
143 sprintf (prefix
, "\"%s\":%d", filename
, lineno
);
144 prefixlen
= strlen(prefix
);
145 fprintf (stderr
, "%s: %s", prefix
, pd
->line
);
147 if (i
> 0 && pd
->line
[i
-1] != '\n') {
150 for (i
+= prefixlen
+ 3; i
> 0; i
--) {
153 fprintf (stderr
, "^--- expecting %s\n", expecting
);
158 #define MAXNAMELEN 256
160 static struct symtab
**
161 lookup_variable (IfParser
*ip
, const char *var
, int len
)
163 char tmpbuf
[MAXNAMELEN
+ 1];
164 struct _parse_data
*pd
= (struct _parse_data
*) ip
->data
;
166 if (len
> MAXNAMELEN
)
169 strncpy (tmpbuf
, var
, len
);
171 return isdefined (tmpbuf
, pd
->inc
, NULL
);
176 my_eval_defined (IfParser
*ip
, const char *var
, int len
)
178 if (lookup_variable (ip
, var
, len
))
184 #define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
187 my_eval_variable (IfParser
*ip
, const char *var
, int len
)
192 s
= lookup_variable (ip
, var
, len
);
197 if (!isvarfirstletter(*var
) || !strcmp((*s
)->s_name
, var
))
199 s
= lookup_variable (ip
, var
, strlen(var
));
202 var
= ParseIfExpression(ip
, var
, &val
);
203 if (var
&& *var
) debug(4, ("extraneous: '%s'\n", var
));
208 cppsetup(char *filename
,
210 struct filepointer
*filep
,
214 struct _parse_data pd
;
220 pd
.filename
= filename
;
221 ip
.funcs
.handle_error
= my_if_errors
;
222 ip
.funcs
.eval_defined
= my_eval_defined
;
223 ip
.funcs
.eval_variable
= my_eval_variable
;
224 ip
.data
= (char *) &pd
;
226 (void) ParseIfExpression (&ip
, line
, &val
);