1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* $XConsortium: cppsetup.c,v 1.13 94/04/17 20:10:32 gildea Exp $ */
5 Copyright (c) 1993, 1994 X Consortium
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 Except as contained in this notice, the name of the X Consortium shall not be
25 used in advertising or otherwise to promote the sale, use or other dealings
26 in this Software without prior written authorization from the X Consortium.
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 pdp11 | vax | ns16000 | mc68000 | 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 pperror(tag
, x0
,x1
,x2
,x3
,x4
)
100 int tag
,x0
,x1
,x2
,x3
,x4
;
102 warning("\"%s\", line %d: ", currentinc
->i_file
, currentfile
->f_line
);
103 warning(x0
,x1
,x2
,x3
,x4
);
110 fatalerr("Fatal error: %s\n", s
);
114 #include "ifparser.h"
116 struct filepointer
*filep
;
122 _my_if_errors (ip
, cp
, expecting
)
125 const char *expecting
;
127 #ifdef DEBUG_MKDEPEND
128 struct _parse_data
*pd
= (struct _parse_data
*) ip
->data
;
129 int lineno
= pd
->filep
->f_line
;
130 char *filename
= pd
->inc
->i_file
;
135 sprintf (prefix
, "\"%s\":%d", filename
, lineno
);
136 prefixlen
= strlen(prefix
);
137 fprintf (stderr
, "%s: %s", prefix
, pd
->line
);
139 if (i
> 0 && pd
->line
[i
-1] != '\n') {
142 for (i
+= prefixlen
+ 3; i
> 0; i
--) {
145 fprintf (stderr
, "^--- expecting %s\n", expecting
);
146 #endif /* DEBUG_MKDEPEND */
154 #define MAXNAMELEN 256
157 _lookup_variable (var
, len
)
161 char tmpbuf
[MAXNAMELEN
+ 1];
163 if (len
> MAXNAMELEN
)
166 strncpy (tmpbuf
, var
, len
);
168 return isdefined(tmpbuf
);
173 _my_eval_defined (ip
, var
, len
)
179 if (_lookup_variable (var
, len
))
185 #define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
188 _my_eval_variable (ip
, var
, len
)
197 s
= _lookup_variable (var
, len
);
202 if (!isvarfirstletter(*var
))
204 s
= _lookup_variable (var
, strlen(var
));
211 int cppsetup(line
, filep
, inc
)
213 register struct filepointer
*filep
;
214 register struct inclist
*inc
;
217 struct _parse_data pd
;
223 ip
.funcs
.handle_error
= _my_if_errors
;
224 ip
.funcs
.eval_defined
= _my_eval_defined
;
225 ip
.funcs
.eval_variable
= _my_eval_variable
;
226 ip
.data
= (char *) &pd
;
228 (void) ParseIfExpression (&ip
, line
, &val
);
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */