LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / soltools / mkdepend / cppsetup.c
blobe731e9fb47c12fd256aa72e7120a8a0d129f4152
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 <ctype.h>
32 #include "def.h"
34 #ifdef CPP
36 * This file is strictly for the sake of cpy.y and yylex.c (if
37 * you indeed have the source for cpp).
39 #define IB 1
40 #define SB 2
41 #define NB 4
42 #define CB 8
43 #define QB 16
44 #define WB 32
45 #define SALT '#'
46 #if pdp11 | vax | ns16000 | mc68000 | ibm032
47 #define COFF 128
48 #else
49 #define COFF 0
50 #endif
52 * These variables used by cpy.y and yylex.c
54 extern char *outp, *inp, *newp, *pend;
55 extern char *ptrtab;
56 extern char fastab[];
57 extern char slotab[];
60 * cppsetup
62 struct filepointer *currentfile;
63 struct inclist *currentinc;
65 cppsetup(line, filep, inc)
66 char *line;
67 struct filepointer *filep;
68 struct inclist *inc;
70 char *p, savec;
71 static boolean setupdone = FALSE;
72 boolean value;
74 if (!setupdone) {
75 cpp_varsetup();
76 setupdone = TRUE;
79 currentfile = filep;
80 currentinc = inc;
81 inp = newp = line;
82 for (p=newp; *p; p++)
86 * put a newline back on the end, and set up pend, etc.
88 *p++ = '\n';
89 savec = *p;
90 *p = '\0';
91 pend = p;
93 ptrtab = slotab+COFF;
94 *--inp = SALT;
95 outp=inp;
96 value = yyparse();
97 *p = savec;
98 return value;
101 pperror(tag, x0,x1,x2,x3,x4)
102 int tag,x0,x1,x2,x3,x4;
104 warning("\"%s\", line %d: ", currentinc->i_file, currentfile->f_line);
105 warning(x0,x1,x2,x3,x4);
109 yyerror(s)
110 char *s;
112 fatalerr("Fatal error: %s\n", s);
114 #else /* not CPP */
116 #include "ifparser.h"
118 static const char *
119 my_if_errors (IfParser *ip, const char *cp, const char *expecting)
121 #ifdef DEBUG_MKDEPEND
122 struct parse_data *pd = (struct parse_data *) ip->data;
123 int lineno = pd->filep->f_line;
124 char *filename = pd->inc->i_file;
125 char prefix[300];
126 int prefixlen;
127 int i;
129 sprintf (prefix, "\"%s\":%d", filename, lineno);
130 prefixlen = strlen(prefix);
131 fprintf (stderr, "%s: %s", prefix, pd->line);
132 i = cp - pd->line;
133 if (i > 0 && pd->line[i-1] != '\n') {
134 putc ('\n', stderr);
136 for (i += prefixlen + 3; i > 0; i--) {
137 putc (' ', stderr);
139 fprintf (stderr, "^--- expecting %s\n", expecting);
140 #endif /* DEBUG_MKDEPEND */
141 (void)ip;
142 (void)cp;
143 (void)expecting;
144 return NULL;
148 #define MAXNAMELEN 256
150 static char *
151 lookup_variable (const char *var, size_t len)
153 char tmpbuf[MAXNAMELEN + 1];
155 if (len > MAXNAMELEN)
156 return NULL;
158 strncpy (tmpbuf, var, len);
159 tmpbuf[len] = '\0';
160 return isdefined(tmpbuf);
164 static int
165 my_eval_defined (IfParser *ip, const char *var, size_t len)
167 (void)ip;
168 if (lookup_variable (var, len))
169 return 1;
170 else
171 return 0;
174 #define isvarfirstletter(ccc) (isalpha((unsigned char)(ccc)) || (ccc) == '_')
176 static int
177 my_eval_variable (IfParser *ip, const char *var, size_t len)
179 char *s;
181 (void)ip;
183 s = lookup_variable (var, len);
184 if (!s)
185 return 0;
186 do {
187 var = s;
188 if (!isvarfirstletter(*var))
189 break;
190 s = lookup_variable (var, strlen(var));
191 } while (s);
193 return atoi(var);
197 int cppsetup(char const *line)
199 IfParser ip;
200 int val = 0;
202 ip.funcs.handle_error = my_if_errors;
203 ip.funcs.eval_defined = my_eval_defined;
204 ip.funcs.eval_variable = my_eval_variable;
206 (void) ParseIfExpression (&ip, line, &val);
207 if (val)
208 return IF;
209 else
210 return IFFALSE;
212 #endif /* CPP */
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */