Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
cppsetup.c
Go to the documentation of this file.
1/* $XConsortium: cppsetup.c /main/17 1996/09/28 16:15:03 rws $ */
2/*
3
4Copyright (c) 1993, 1994 X Consortium
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23Except as contained in this notice, the name of the X Consortium shall not be
24used in advertising or otherwise to promote the sale, use or other dealings
25in this Software without prior written authorization from the X Consortium.
26
27*/
28/* $XFree86: xc/config/makedepend/cppsetup.c,v 3.2 1996/12/30 13:57:53 dawes Exp $ */
29
30#include "def.h"
31
32#ifdef CPP
33/*
34 * This file is strictly for the sake of cpy.y and yylex.c (if
35 * you indeed have the source for cpp).
36 */
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 defined(pdp11) || defined(vax) || defined(ns16000) || defined(mc68000) || defined(ibm032)
45#define COFF 128
46#else
47#define COFF 0
48#endif
49/*
50 * These variables used by cpy.y and yylex.c
51 */
52extern char *outp, *inp, *newp, *pend;
53extern char *ptrtab;
54extern char fastab[];
55extern char slotab[];
56
57/*
58 * cppsetup
59 */
60struct filepointer *currentfile;
61struct inclist *currentinc;
62
63int cppsetup(register char *line, register struct filepointer *filep, register struct inclist *inc)
64{
65 register char *p, savec;
66 static boolean setupdone = FALSE;
67 boolean value;
68
69 if (!setupdone) {
70 cpp_varsetup();
71 setupdone = TRUE;
72 }
73
74 currentfile = filep;
75 currentinc = inc;
76 inp = newp = line;
77 for (p = newp; *p; p++)
78 ;
79
80 /*
81 * put a newline back on the end, and set up pend, etc.
82 */
83 *p++ = '\n';
84 savec = *p;
85 *p = '\0';
86 pend = p;
87
88 ptrtab = slotab + COFF;
89 *--inp = SALT;
90 outp = inp;
91 value = yyparse();
92 *p = savec;
93 return(value);
94}
95
96struct symtab **lookup(char *symbol)
97{
98 static struct symtab *undefined;
99 struct symtab **sp;
100
101 sp = isdefined(symbol, currentinc, NULL);
102 if (sp == NULL) {
103 sp = &undefined;
104 (*sp)->s_value = NULL;
105 }
106 return (sp);
107}
108
109void pperror(int tag, int x0, int x1, int x2, int x3, int x4)
110{
111 warning("\"%s\", line %d: ", currentinc->i_file, currentfile->f_line);
112 warning(x0, x1, x2, x3, x4);
113}
114
115void yyerror(register char *s)
116{
117 fatalerr("Fatal error: %s\n", s);
118}
119#else /* not CPP */
120
121#include "ifparser.h"
124 struct inclist *inc;
125 const char *line;
126};
127
128static const char *my_if_errors(IfParser *ip, const char *cp, const char *expecting)
129{
130 struct _parse_data *pd = (struct _parse_data *) ip->data;
131 int lineno = pd->filep->f_line;
132 char *filename = pd->inc->i_file;
133 char *prefix;
134 int prefixlen;
135 int i;
136
137 prefix = (char*)malloc(strlen(filename) + 32);
138 sprintf(prefix, "\"%s\":%d", filename, lineno);
139 prefixlen = strlen(prefix);
140 fprintf(stderr, "%s: warning: %s", prefix, pd->line);
141 i = cp - pd->line;
142 if (i > 0 && pd->line[i-1] != '\n') {
143 putc('\n', stderr);
144 }
145 for (i += prefixlen + 11; i > 0; i--) {
146 putc(' ', stderr);
147 }
148 fprintf(stderr, "^--- expecting %s\n", expecting);
149 free(prefix);
150 return NULL;
151}
152
153
154#define MAXNAMELEN 256
155
156static struct symtab **lookup_variable(IfParser *ip, const char *var, int len)
157{
158 char tmpbuf[MAXNAMELEN + 1];
159 struct _parse_data *pd = (struct _parse_data *) ip->data;
160
161 if (len > MAXNAMELEN)
162 return 0;
163
164 strncpy(tmpbuf, var, len);
165 tmpbuf[len] = '\0';
166 return isdefined(tmpbuf, pd->inc, NULL);
167}
168
169static int my_eval_defined(IfParser *ip, const char *var, int len)
170{
171 if (lookup_variable(ip, var, len))
172 return 1;
173 else
174 return 0;
175}
176
177#define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
178
179static long my_eval_variable(IfParser *ip, const char *var, int len)
180{
181 struct symtab **s;
182
183 s = lookup_variable(ip, var, len);
184 if (!s)
185 return 0;
186 do {
187 var = (*s)->s_value;
188 if (!isvarfirstletter(*var))
189 break;
190 s = lookup_variable(ip, var, (int)strlen(var));
191 } while (s);
192
193 return strtol(var, NULL, 0);
194}
195
196int cppsetup(register char *line, register struct filepointer *filep, register struct inclist *inc)
197{
198 IfParser ip;
199 struct _parse_data pd;
200 long val = 0;
201
202 pd.filep = filep;
203 pd.inc = inc;
204 pd.line = line;
208 ip.data = (char *) & pd;
209
210 (void) ParseIfExpression(&ip, line, &val);
211 if (val)
212 return IF;
213 else
214 return IFFALSE;
215}
216#endif /* CPP */
#define void
Definition Tailor.h:179
#define NULL
Definition ZInflate.c:15
#define free
Definition civetweb.c:1578
#define malloc
Definition civetweb.c:1575
int cppsetup(register char *line, register struct filepointer *filep, register struct inclist *inc)
Definition cppsetup.c:196
#define isvarfirstletter(ccc)
Definition cppsetup.c:177
static int my_eval_defined(IfParser *ip, const char *var, int len)
Definition cppsetup.c:169
#define MAXNAMELEN
Definition cppsetup.c:154
static const char * my_if_errors(IfParser *ip, const char *cp, const char *expecting)
Definition cppsetup.c:128
static long my_eval_variable(IfParser *ip, const char *var, int len)
Definition cppsetup.c:179
static struct symtab ** lookup_variable(IfParser *ip, const char *var, int len)
Definition cppsetup.c:156
#define IFFALSE
Definition def.h:70
struct symtab ** isdefined(char *, struct inclist *, struct inclist **)
#define TRUE
Definition def.h:50
#define FALSE
Definition def.h:51
#define IF
Definition def.h:54
void fatalerr(char *,...)
Definition main.c:751
void warning(char *,...)
Definition main.c:761
auto filename
TLine * line
const char * ParseIfExpression()
struct _if_parser IfParser
TSpectrum2 * s
Definition peaks2.C:33
struct _if_parser::@027027246057006304321352073053150242041373171134 funcs
long(* eval_variable)(struct _if_parser *, const char *, int)
Definition ifparser.h:71
char * data
Definition ifparser.h:74
const char *(* handle_error)(struct _if_parser *, const char *, const char *)
Definition ifparser.h:70
int(* eval_defined)(struct _if_parser *, const char *, int)
Definition ifparser.h:72
struct inclist * inc
Definition cppsetup.c:124
struct filepointer * filep
Definition cppsetup.c:123
const char * line
Definition cppsetup.c:125
long f_line
Definition def.h:124
Definition def.h:106
char * i_file
Definition def.h:108
Definition def.h:94
char * s_value
Definition def.h:96