10 char *outptr
= outbuf
;
13 struct token nltoken
= {NL
, 0, 0, 1, (uchar
*) "\n", 0};
20 char rcsid
[] = "$Version 1.2 $ $Revision: 1.5 $ $Date: 2006-06-20 05:05:46 $";
26 main(int argc
, char **argv
)
33 fprintf(stderr
,"%s","cpp version 17.8.1999\n");
51 process(Tokenrow
* trp
)
57 if (trp
->tp
>= trp
->lp
)
59 trp
->tp
= trp
->lp
= trp
->bp
;
61 anymacros
|= gettokens(trp
, 1);
64 if (trp
->tp
->type
== END
)
68 if (cursource
->ifdepth
)
70 "Unterminated conditional in #include");
72 cursource
->line
+= cursource
->lineinc
;
79 error(ERROR
, "Unterminated #if/#ifdef/#ifndef");
82 if (trp
->tp
->type
== SHARP
)
88 if (!skipping
&& anymacros
)
94 cursource
->line
+= cursource
->lineinc
;
95 if (cursource
->lineinc
> 1)
104 control(Tokenrow
* trp
)
110 if (tp
->type
!= NAME
)
112 if (tp
->type
== NUMBER
)
115 error(ERROR
, "Unidentifiable control line");
116 return; /* else empty line */
118 if ((np
= lookup(tp
, 0)) == NULL
|| ((np
->flag
& ISKW
) == 0 && !skipping
))
120 error(WARNING
, "Unknown preprocessor control %t", tp
);
128 if (--ifdepth
< skipping
)
130 --cursource
->ifdepth
;
137 if (++ifdepth
>= NIF
)
138 error(FATAL
, "#if too deeply nested");
139 ++cursource
->ifdepth
;
144 if (ifdepth
<= skipping
)
160 if (tp
->type
!= NAME
|| trp
->lp
- trp
->bp
!= 4)
162 error(ERROR
, "Syntax error in #undef");
165 if ((np
= lookup(tp
, 0)) != NULL
)
167 np
->flag
&= ~ISDEFINED
;
172 error(INFO
, "Macro deletion of %s(%r)", np
->name
, np
->ap
);
174 error(INFO
, "Macro deletion of %s", np
->name
);
181 for (tp
= trp
->tp
- 1; ((tp
->type
!= NL
) && (tp
< trp
->lp
)); tp
++)
188 if (++ifdepth
>= NIF
)
189 error(FATAL
, "#if too deeply nested");
190 ++cursource
->ifdepth
;
191 ifsatisfied
[ifdepth
] = 0;
192 if (eval(trp
, np
->val
))
193 ifsatisfied
[ifdepth
] = 1;
201 error(ERROR
, "#elif with no #if");
204 if (ifsatisfied
[ifdepth
] == 2)
205 error(ERROR
, "#elif after #else");
206 if (eval(trp
, np
->val
))
208 if (ifsatisfied
[ifdepth
])
213 ifsatisfied
[ifdepth
] = 1;
221 if (ifdepth
== 0 || cursource
->ifdepth
== 0)
223 error(ERROR
, "#else with no #if");
226 if (ifsatisfied
[ifdepth
] == 2)
227 error(ERROR
, "#else after #else");
228 if (trp
->lp
- trp
->bp
!= 3)
229 error(ERROR
, "Syntax error in #else");
230 skipping
= ifsatisfied
[ifdepth
] ? ifdepth
: 0;
231 ifsatisfied
[ifdepth
] = 2;
235 if (ifdepth
== 0 || cursource
->ifdepth
== 0)
237 error(ERROR
, "#endif with no #if");
241 --cursource
->ifdepth
;
242 if (trp
->lp
- trp
->bp
!= 3)
243 error(WARNING
, "Syntax error in #endif");
248 error(WARNING
, "#error directive: %r", trp
);
253 expandrow(trp
, "<line>");
256 if (tp
+ 1 >= trp
->lp
|| tp
->type
!= NUMBER
|| tp
+ 3 < trp
->lp
257 || (tp
+ 3 == trp
->lp
258 && ((tp
+ 1)->type
!= STRING
|| *(tp
+ 1)->t
== 'L')))
260 error(ERROR
, "Syntax error in #line");
263 cursource
->line
= atol((char *) tp
->t
) - 1;
264 if (cursource
->line
< 0 || cursource
->line
>= 32768)
265 error(WARNING
, "#line specifies number out of range");
267 if (tp
+ 1 < trp
->lp
)
268 cursource
->filename
= (char *) newstring(tp
->t
+ 1, tp
->len
- 2, 0);
272 error(ERROR
, "Bad syntax for control line");
276 doinclude(trp
, -1, 1);
281 doinclude(trp
, -1, 0);
286 doinclude(trp
, cursource
->pathdepth
, 0);
295 error(ERROR
, "Preprocessor control `%t' not yet implemented", tp
);
305 void *p
= malloc(size
);
308 error(FATAL
, "Out of memory from malloc");
319 error(enum errtype type
, char *string
,...)
328 fprintf(stderr
, "cpp: ");
329 for (s
= cursource
; s
; s
= s
->next
)
331 fprintf(stderr
, "%s:%d ", s
->filename
, s
->line
);
332 va_start(ap
, string
);
333 for (ep
= string
; *ep
; ep
++)
341 c
= (char) va_arg(ap
, int);
342 fprintf(stderr
, "%c", c
);
346 cp
= va_arg(ap
, char *);
347 fprintf(stderr
, "%s", cp
);
352 fprintf(stderr
, "%d", i
);
356 tp
= va_arg(ap
, Token
*);
357 fprintf(stderr
, "%.*s", (int)tp
->len
, tp
->t
);
361 trp
= va_arg(ap
, Tokenrow
*);
362 for (tp
= trp
->tp
; tp
< trp
->lp
&& tp
->type
!= NL
; tp
++)
364 if (tp
> trp
->tp
&& tp
->wslen
)
366 fprintf(stderr
, "%.*s", (int)tp
->len
, tp
->t
);