1 /* $Xorg: cppsetup.c,v 1.3 2000/08/17 19:41:50 cpqbld Exp $ */
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.
23 /* $XFree86: xc/config/makedepend/cppsetup.c,v 3.9 2001/04/29 23:25:02 tsi Exp $ */
29 * This file is strictly for the sake of cpy.y and yylex.c (if
30 * you indeed have the source for cpp).
39 #if defined(pdp11) || defined(vax) || defined(ns16000) || defined(mc68000) || defined(ibm032)
45 * These variables used by cpy.y and yylex.c
47 extern char *outp
, *inp
, *newp
, *pend
;
55 struct filepointer
*currentfile
;
56 struct inclist
*currentinc
;
59 cppsetup(char *line
, struct filepointer
*filep
, struct inclist
*inc
)
62 static boolean setupdone
= FALSE
;
77 * put a newline back on the end, and set up pend, etc.
92 struct symtab
**lookup(symbol
)
95 static struct symtab
*undefined
;
98 sp
= isdefined(symbol
, currentinc
, NULL
);
101 (*sp
)->s_value
= NULL
;
106 pperror(tag
, x0
,x1
,x2
,x3
,x4
)
107 int tag
,x0
,x1
,x2
,x3
,x4
;
109 warning("\"%s\", line %d: ", currentinc
->i_file
, currentfile
->f_line
);
110 warning(x0
,x1
,x2
,x3
,x4
);
117 fatalerr("Fatal error: %s\n", s
);
121 #include "ifparser.h"
123 struct filepointer
*filep
;
129 my_if_errors (IfParser
*ip
, const char *cp
, const char *expecting
)
131 struct _parse_data
*pd
= (struct _parse_data
*) ip
->data
;
132 int lineno
= pd
->filep
->f_line
;
133 char *filename
= pd
->inc
->i_file
;
138 sprintf (prefix
, "\"%s\":%d", filename
, lineno
);
139 prefixlen
= strlen(prefix
);
140 fprintf (stderr
, "%s: %s", prefix
, pd
->line
);
142 if (i
> 0 && pd
->line
[i
-1] != '\n') {
145 for (i
+= prefixlen
+ 3; i
> 0; i
--) {
148 fprintf (stderr
, "^--- expecting %s\n", expecting
);
153 #define MAXNAMELEN 256
155 static struct symtab
**
156 lookup_variable (IfParser
*ip
, const char *var
, int len
)
158 char tmpbuf
[MAXNAMELEN
+ 1];
159 struct _parse_data
*pd
= (struct _parse_data
*) ip
->data
;
161 if (len
> MAXNAMELEN
)
164 strncpy (tmpbuf
, var
, len
);
166 return isdefined (tmpbuf
, pd
->inc
, NULL
);
171 my_eval_defined (IfParser
*ip
, const char *var
, int len
)
173 if (lookup_variable (ip
, var
, len
))
179 #define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
182 my_eval_variable (IfParser
*ip
, const char *var
, int len
)
187 s
= lookup_variable (ip
, var
, len
);
192 if (!isvarfirstletter(*var
) || !strcmp((*s
)->s_name
, var
))
194 s
= lookup_variable (ip
, var
, strlen(var
));
197 var
= ParseIfExpression(ip
, var
, &val
);
198 if (var
&& *var
) debug(4, ("extraneous: '%s'\n", var
));
203 cppsetup(char *line
, struct filepointer
*filep
, struct inclist
*inc
)
206 struct _parse_data pd
;
212 ip
.funcs
.handle_error
= my_if_errors
;
213 ip
.funcs
.eval_defined
= my_eval_defined
;
214 ip
.funcs
.eval_variable
= my_eval_variable
;
215 ip
.data
= (char *) &pd
;
217 (void) ParseIfExpression (&ip
, line
, &val
);