2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: cppsetup.c /main/18 1998/02/06 11:09:35 kaleb $ */
26 Copyright (c) 1993, 1994, 1998 The Open Group
30 The above copyright notice and this permission notice shall be included in
31 all copies or substantial portions of the Software.
33 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
37 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
38 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 Except as contained in this notice, the name of The Open Group shall not be
41 used in advertising or otherwise to promote the sale, use or other dealings
42 in this Software without prior written authorization from The Open Group.
50 * This file is strictly for the sake of cpy.y and yylex.c (if
51 * you indeed have the source for cpp).
60 #if pdp11 | vax | ns16000 | mc68000 | ibm032
66 * These variables used by cpy.y and yylex.c
68 extern char *outp, *inp, *newp, *pend;
76 struct filepointer *currentfile;
77 struct inclist *currentinc;
79 cppsetup(line, filep, inc)
81 register struct filepointer *filep;
82 register struct inclist *inc;
84 register char *p, savec;
85 static boolean setupdone = FALSE;
100 * put a newline back on the end, and set up pend, etc.
107 ptrtab = slotab+COFF;
115 struct symtab **lookup(symbol)
118 static struct symtab *undefined;
121 sp = isdefined(symbol, currentinc, NULL);
124 (*sp)->s_value = NULL;
129 pperror(tag, x0,x1,x2,x3,x4)
130 int tag,x0,x1,x2,x3,x4;
132 warning("\"%s\", line %d: ", currentinc->i_file, currentfile->f_line);
133 warning(x0,x1,x2,x3,x4);
140 fatalerr("Fatal error: %s\n", s);
144 #include "ifparser.h"
146 struct filepointer *filep;
152 my_if_errors (ip, cp, expecting)
155 const char *expecting;
157 struct _parse_data *pd = (struct _parse_data *) ip->data;
158 int lineno = pd->filep->f_line;
159 char *filename = pd->inc->i_file;
164 sprintf (prefix, "\"%s\":%d", filename, lineno);
165 prefixlen = strlen(prefix);
166 fprintf (stderr, "%s: %s", prefix, pd->line);
168 if (i > 0 && pd->line[i-1] != '\n') {
171 for (i += prefixlen + 3; i > 0; i--) {
174 fprintf (stderr, "^--- expecting %s\n", expecting);
179 #define MAXNAMELEN 256
181 static struct symtab **
182 lookup_variable (ip, var, len)
187 char tmpbuf[MAXNAMELEN + 1];
188 struct _parse_data *pd = (struct _parse_data *) ip->data;
190 if (len > MAXNAMELEN)
193 strncpy (tmpbuf, var, len);
195 return isdefined (tmpbuf, pd->inc, NULL);
200 my_eval_defined (ip, var, len)
205 if (lookup_variable (ip, var, len))
211 #define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
214 my_eval_variable (ip, var, len)
221 s = lookup_variable (ip, var, len);
226 if (!isvarfirstletter(*var))
228 s = lookup_variable (ip, var, strlen(var));
231 return strtol(var, NULL, 0);
235 cppsetup(line, filep, inc)
237 register struct filepointer *filep;
238 register struct inclist *inc;
241 struct _parse_data pd;
247 ip.funcs.handle_error = my_if_errors;
248 ip.funcs.eval_defined = my_eval_defined;
249 ip.funcs.eval_variable = my_eval_variable;
250 ip.data = (char *) &pd;
252 (void) ParseIfExpression (&ip, line, &val);