Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / soltools / mkdepend / cppsetup.c
blob708e75dc099e9ebe5591b0f2c0378bd310245d55
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 $ */
3 /*
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.
30 #include "def.h"
32 #ifdef CPP
34 * This file is strictly for the sake of cpy.y and yylex.c (if
35 * you indeed have the source for cpp).
37 #define IB 1
38 #define SB 2
39 #define NB 4
40 #define CB 8
41 #define QB 16
42 #define WB 32
43 #define SALT '#'
44 #if pdp11 | vax | ns16000 | mc68000 | ibm032
45 #define COFF 128
46 #else
47 #define COFF 0
48 #endif
50 * These variables used by cpy.y and yylex.c
52 extern char *outp, *inp, *newp, *pend;
53 extern char *ptrtab;
54 extern char fastab[];
55 extern char slotab[];
58 * cppsetup
60 struct filepointer *currentfile;
61 struct inclist *currentinc;
63 cppsetup(line, filep, inc)
64 char *line;
65 struct filepointer *filep;
66 struct inclist *inc;
68 char *p, savec;
69 static boolean setupdone = FALSE;
70 boolean value;
72 if (!setupdone) {
73 cpp_varsetup();
74 setupdone = TRUE;
77 currentfile = filep;
78 currentinc = inc;
79 inp = newp = line;
80 for (p=newp; *p; p++)
84 * put a newline back on the end, and set up pend, etc.
86 *p++ = '\n';
87 savec = *p;
88 *p = '\0';
89 pend = p;
91 ptrtab = slotab+COFF;
92 *--inp = SALT;
93 outp=inp;
94 value = yyparse();
95 *p = savec;
96 return value;
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);
107 yyerror(s)
108 char *s;
110 fatalerr("Fatal error: %s\n", s);
112 #else /* not CPP */
114 #include "ifparser.h"
115 struct parse_data {
116 struct filepointer *filep;
117 struct inclist *inc;
118 const char *line;
121 static const char *
122 my_if_errors (IfParser *ip, const char *cp, const char *expecting)
124 #ifdef DEBUG_MKDEPEND
125 struct parse_data *pd = (struct parse_data *) ip->data;
126 int lineno = pd->filep->f_line;
127 char *filename = pd->inc->i_file;
128 char prefix[300];
129 int prefixlen;
130 int i;
132 sprintf (prefix, "\"%s\":%d", filename, lineno);
133 prefixlen = strlen(prefix);
134 fprintf (stderr, "%s: %s", prefix, pd->line);
135 i = cp - pd->line;
136 if (i > 0 && pd->line[i-1] != '\n') {
137 putc ('\n', stderr);
139 for (i += prefixlen + 3; i > 0; i--) {
140 putc (' ', stderr);
142 fprintf (stderr, "^--- expecting %s\n", expecting);
143 #endif /* DEBUG_MKDEPEND */
144 (void)ip;
145 (void)cp;
146 (void)expecting;
147 return NULL;
151 #define MAXNAMELEN 256
153 static char *
154 lookup_variable (const char *var, size_t len)
156 char tmpbuf[MAXNAMELEN + 1];
158 if (len > MAXNAMELEN)
159 return NULL;
161 strncpy (tmpbuf, var, len);
162 tmpbuf[len] = '\0';
163 return isdefined(tmpbuf);
167 static int
168 my_eval_defined (IfParser *ip, const char *var, size_t len)
170 (void)ip;
171 if (lookup_variable (var, len))
172 return 1;
173 else
174 return 0;
177 #define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
179 static int
180 my_eval_variable (IfParser *ip, const char *var, size_t len)
182 char *s;
184 (void)ip;
186 s = lookup_variable (var, len);
187 if (!s)
188 return 0;
189 do {
190 var = s;
191 if (!isvarfirstletter(*var))
192 break;
193 s = lookup_variable (var, strlen(var));
194 } while (s);
196 return atoi(var);
200 int cppsetup(char *line, struct filepointer *filep, struct inclist *inc)
202 IfParser ip;
203 struct parse_data pd;
204 int val = 0;
206 pd.filep = filep;
207 pd.inc = inc;
208 pd.line = line;
209 ip.funcs.handle_error = my_if_errors;
210 ip.funcs.eval_defined = my_eval_defined;
211 ip.funcs.eval_variable = my_eval_variable;
212 ip.data = (char *) &pd;
214 (void) ParseIfExpression (&ip, line, &val);
215 if (val)
216 return IF;
217 else
218 return IFFALSE;
220 #endif /* CPP */
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */