File indexing completed on 2018-03-02 18:44:41 UTC
view on githubraw file Latest commit bf5846c3 on 2004-02-25 18:19:54 UTC
bf5846c3a1 Ed H*0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070 #include "def.h"
0071
0072 #ifdef CPP
0073
0074
0075
0076
0077 #define IB 1
0078 #define SB 2
0079 #define NB 4
0080 #define CB 8
0081 #define QB 16
0082 #define WB 32
0083 #define SALT '#'
0084 #if pdp11 | vax | ns16000 | mc68000 | ibm032
0085 #define COFF 128
0086 #else
0087 #define COFF 0
0088 #endif
0089
0090
0091
0092 extern char *outp, *inp, *newp, *pend;
0093 extern char *ptrtab;
0094 extern char fastab[];
0095 extern char slotab[];
0096
0097
0098
0099
0100 struct filepointer *currentfile;
0101 struct inclist *currentinc;
0102
0103 cppsetup(line, filep, inc)
0104 register char *line;
0105 register struct filepointer *filep;
0106 register struct inclist *inc;
0107 {
0108 register char *p, savec;
0109 static boolean setupdone = FALSE;
0110 boolean value;
0111
0112 if (!setupdone) {
0113 cpp_varsetup();
0114 setupdone = TRUE;
0115 }
0116
0117 currentfile = filep;
0118 currentinc = inc;
0119 inp = newp = line;
0120 for (p=newp; *p; p++)
0121 ;
0122
0123
0124
0125
0126 *p++ = '\n';
0127 savec = *p;
0128 *p = '\0';
0129 pend = p;
0130
0131 ptrtab = slotab+COFF;
0132 *--inp = SALT;
0133 outp=inp;
0134 value = yyparse();
0135 *p = savec;
0136 return(value);
0137 }
0138
0139 struct symtab *lookup(symbol)
0140 char *symbol;
0141 {
0142 static struct symtab undefined;
0143 struct symtab *sp;
0144
0145 sp = isdefined(symbol, currentinc, NULL);
0146 if (sp == NULL) {
0147 sp = &undefined;
0148 sp->s_value = NULL;
0149 }
0150 return (sp);
0151 }
0152
0153 pperror(tag, x0,x1,x2,x3,x4)
0154 int tag,x0,x1,x2,x3,x4;
0155 {
0156 warning("\"%s\", line %d: ", currentinc->i_file, currentfile->f_line);
0157 warning(x0,x1,x2,x3,x4);
0158 }
0159
0160
0161 yyerror(s)
0162 register char *s;
0163 {
0164 fatalerr("Fatal error: %s\n", s);
0165 }
0166 #else
0167
0168 #include "ifparser.h"
0169 struct _parse_data {
0170 struct filepointer *filep;
0171 struct inclist *inc;
0172 const char *line;
0173 };
0174
0175 static const char *
0176 _my_if_errors (ip, cp, expecting)
0177 IfParser *ip;
0178 const char *cp;
0179 const char *expecting;
0180 {
0181 struct _parse_data *pd = (struct _parse_data *) ip->data;
0182 int lineno = pd->filep->f_line;
0183 char *filename = pd->inc->i_file;
0184 char prefix[300];
0185 int prefixlen;
0186 int i;
0187
0188 sprintf (prefix, "\"%s\":%d", filename, lineno);
0189 prefixlen = strlen(prefix);
0190 fprintf (stderr, "%s: %s", prefix, pd->line);
0191 i = cp - pd->line;
0192 if (i > 0 && pd->line[i-1] != '\n') {
0193 putc ('\n', stderr);
0194 }
0195 for (i += prefixlen + 3; i > 0; i--) {
0196 putc (' ', stderr);
0197 }
0198 fprintf (stderr, "^--- expecting %s\n", expecting);
0199 return NULL;
0200 }
0201
0202
0203 #define MAXNAMELEN 256
0204
0205 static struct symtab *
0206 _lookup_variable (ip, var, len)
0207 IfParser *ip;
0208 const char *var;
0209 int len;
0210 {
0211 char tmpbuf[MAXNAMELEN + 1];
0212 struct _parse_data *pd = (struct _parse_data *) ip->data;
0213
0214 if (len > MAXNAMELEN)
0215 return 0;
0216
0217 strncpy (tmpbuf, var, len);
0218 tmpbuf[len] = '\0';
0219 return isdefined (tmpbuf, pd->inc, NULL);
0220 }
0221
0222
0223 static int
0224 _my_eval_defined (ip, var, len)
0225 IfParser *ip;
0226 const char *var;
0227 int len;
0228 {
0229 if (_lookup_variable (ip, var, len))
0230 return 1;
0231 else
0232 return 0;
0233 }
0234
0235 #define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
0236
0237 static int
0238 _my_eval_variable (ip, var, len)
0239 IfParser *ip;
0240 const char *var;
0241 int len;
0242 {
0243 struct symtab *s;
0244
0245 s = _lookup_variable (ip, var, len);
0246 if (!s)
0247 return 0;
0248 do {
0249 var = s->s_value;
0250 if (!isvarfirstletter(*var))
0251 break;
0252 s = _lookup_variable (ip, var, strlen(var));
0253 } while (s);
0254
0255 return atoi(var);
0256 }
0257
0258
0259 cppsetup(line, filep, inc)
0260 register char *line;
0261 register struct filepointer *filep;
0262 register struct inclist *inc;
0263 {
0264 IfParser ip;
0265 struct _parse_data pd;
0266 int val = 0;
0267
0268 pd.filep = filep;
0269 pd.inc = inc;
0270 pd.line = line;
0271 ip.funcs.handle_error = _my_if_errors;
0272 ip.funcs.eval_defined = _my_eval_defined;
0273 ip.funcs.eval_variable = _my_eval_variable;
0274 ip.data = (char *) &pd;
0275
0276 (void) ParseIfExpression (&ip, line, &val);
0277 if (val)
0278 return IF;
0279 else
0280 return IFFALSE;
0281 }
0282 #endif
0283