Bug 417561, disable tagging of Talkback now we have prebuilt packages, r=rhelmer
[mozilla-1.9.git] / config / mkdepend / cppsetup.c
blob49a746ac4891268ef6fd6ac0177301d3ad92ec33
1 /* $Xorg: cppsetup.c,v 1.5 2001/02/09 02:03:16 xorgcvs Exp $ */
2 /*
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
10 documentation.
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 $ */
29 #include "def.h"
31 #ifdef CPP
33 * This file is strictly for the sake of cpy.y and yylex.c (if
34 * you indeed have the source for cpp).
36 #define IB 1
37 #define SB 2
38 #define NB 4
39 #define CB 8
40 #define QB 16
41 #define WB 32
42 #define SALT '#'
43 #if defined(pdp11) || defined(vax) || defined(ns16000) || defined(mc68000) || defined(ibm032)
44 #define COFF 128
45 #else
46 #define COFF 0
47 #endif
49 * These variables used by cpy.y and yylex.c
51 extern char *outp, *inp, *newp, *pend;
52 extern char *ptrtab;
53 extern char fastab[];
54 extern char slotab[];
57 * cppsetup
59 struct filepointer *currentfile;
60 struct inclist *currentinc;
62 int
63 cppsetup(char *line, struct filepointer *filep, struct inclist *inc)
65 char *p, savec;
66 static boolean setupdone = FALSE;
67 boolean value;
69 if (!setupdone) {
70 cpp_varsetup();
71 setupdone = TRUE;
74 currentfile = filep;
75 currentinc = inc;
76 inp = newp = line;
77 for (p=newp; *p; p++)
81 * put a newline back on the end, and set up pend, etc.
83 *p++ = '\n';
84 savec = *p;
85 *p = '\0';
86 pend = p;
88 ptrtab = slotab+COFF;
89 *--inp = SALT;
90 outp=inp;
91 value = yyparse();
92 *p = savec;
93 return(value);
96 struct symtab **lookup(symbol)
97 char *symbol;
99 static struct symtab *undefined;
100 struct symtab **sp;
102 sp = isdefined(symbol, currentinc, NULL);
103 if (sp == NULL) {
104 sp = &undefined;
105 (*sp)->s_value = NULL;
107 return (sp);
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);
118 yyerror(s)
119 register char *s;
121 fatalerr("Fatal error: %s\n", s);
123 #else /* not CPP */
125 #include "ifparser.h"
126 struct _parse_data {
127 struct filepointer *filep;
128 struct inclist *inc;
129 char *filename;
130 const char *line;
133 static const char *
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;
139 char prefix[300];
140 int prefixlen;
141 int i;
143 sprintf (prefix, "\"%s\":%d", filename, lineno);
144 prefixlen = strlen(prefix);
145 fprintf (stderr, "%s: %s", prefix, pd->line);
146 i = cp - pd->line;
147 if (i > 0 && pd->line[i-1] != '\n') {
148 putc ('\n', stderr);
150 for (i += prefixlen + 3; i > 0; i--) {
151 putc (' ', stderr);
153 fprintf (stderr, "^--- expecting %s\n", expecting);
154 return NULL;
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)
167 return 0;
169 strncpy (tmpbuf, var, len);
170 tmpbuf[len] = '\0';
171 return isdefined (tmpbuf, pd->inc, NULL);
175 static int
176 my_eval_defined (IfParser *ip, const char *var, int len)
178 if (lookup_variable (ip, var, len))
179 return 1;
180 else
181 return 0;
184 #define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
186 static long
187 my_eval_variable (IfParser *ip, const char *var, int len)
189 long val;
190 struct symtab **s;
192 s = lookup_variable (ip, var, len);
193 if (!s)
194 return 0;
195 do {
196 var = (*s)->s_value;
197 if (!isvarfirstletter(*var) || !strcmp((*s)->s_name, var))
198 break;
199 s = lookup_variable (ip, var, strlen(var));
200 } while (s);
202 var = ParseIfExpression(ip, var, &val);
203 if (var && *var) debug(4, ("extraneous: '%s'\n", var));
204 return val;
208 cppsetup(char *filename,
209 char *line,
210 struct filepointer *filep,
211 struct inclist *inc)
213 IfParser ip;
214 struct _parse_data pd;
215 long val = 0;
217 pd.filep = filep;
218 pd.inc = inc;
219 pd.line = line;
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);
227 if (val)
228 return IF;
229 else
230 return IFFALSE;
232 #endif /* CPP */