1 /* $XConsortium: cppsetup.c,v 1.13 94/04/17 20:10:32 gildea Exp $ */
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.
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 pdp11 | vax | ns16000 | mc68000 | 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
;
62 cppsetup(line
, filep
, inc
)
64 register struct filepointer
*filep
;
65 register struct inclist
*inc
;
67 register char *p
, savec
;
68 static boolean setupdone
= FALSE
;
83 * put a newline back on the end, and set up pend, etc.
98 pperror(tag
, x0
,x1
,x2
,x3
,x4
)
99 int tag
,x0
,x1
,x2
,x3
,x4
;
101 warning("\"%s\", line %d: ", currentinc
->i_file
, currentfile
->f_line
);
102 warning(x0
,x1
,x2
,x3
,x4
);
109 fatalerr("Fatal error: %s\n", s
);
113 #include "ifparser.h"
115 struct filepointer
*filep
;
121 _my_if_errors (ip
, cp
, expecting
)
124 const char *expecting
;
126 #ifdef DEBUG_MKDEPEND
127 struct _parse_data
*pd
= (struct _parse_data
*) ip
->data
;
128 int lineno
= pd
->filep
->f_line
;
129 char *filename
= pd
->inc
->i_file
;
134 sprintf (prefix
, "\"%s\":%d", filename
, lineno
);
135 prefixlen
= strlen(prefix
);
136 fprintf (stderr
, "%s: %s", prefix
, pd
->line
);
138 if (i
> 0 && pd
->line
[i
-1] != '\n') {
141 for (i
+= prefixlen
+ 3; i
> 0; i
--) {
144 fprintf (stderr
, "^--- expecting %s\n", expecting
);
145 #endif /* DEBUG_MKDEPEND */
153 #define MAXNAMELEN 256
156 _lookup_variable (var
, len
)
160 char tmpbuf
[MAXNAMELEN
+ 1];
162 if (len
> MAXNAMELEN
)
165 strncpy (tmpbuf
, var
, len
);
167 return isdefined(tmpbuf
);
172 _my_eval_defined (ip
, var
, len
)
178 if (_lookup_variable (var
, len
))
184 #define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
187 _my_eval_variable (ip
, var
, len
)
196 s
= _lookup_variable (var
, len
);
201 if (!isvarfirstletter(*var
))
203 s
= _lookup_variable (var
, strlen(var
));
210 int cppsetup(line
, filep
, inc
)
212 register struct filepointer
*filep
;
213 register struct inclist
*inc
;
216 struct _parse_data pd
;
222 ip
.funcs
.handle_error
= _my_if_errors
;
223 ip
.funcs
.eval_defined
= _my_eval_defined
;
224 ip
.funcs
.eval_variable
= _my_eval_variable
;
225 ip
.data
= (char *) &pd
;
227 (void) ParseIfExpression (&ip
, line
, &val
);