restore keywords
[unix-history] / usr / src / old / cpp / cpp.c
CommitLineData
66cbbe7c 1#ifndef lint
ce2749d6 2static char sccsid[] = "@(#)cpp.c 1.15 %G%";
66cbbe7c 3#endif lint
9372792e 4
66cbbe7c
RH
5#ifdef FLEXNAMES
6#define NCPS 128
7#else
8#define NCPS 8
9#endif
10
11# include "stdio.h"
9372792e 12# include "ctype.h"
66cbbe7c
RH
13/* C command
14/* written by John F. Reiser
15/* July/August 1978
16*/
17
18#define STATIC
19
061309d9 20#define FIRSTOPEN -2
c5a72b19 21#define STDIN 0
66cbbe7c
RH
22#define READ 0
23#define WRITE 1
24#define SALT '#'
d9f07ef8
KM
25#if !defined BUFSIZ || BUFSIZ < 8192
26#undef BUFSIZ
27#define BUFSIZ 8192
66cbbe7c
RH
28#endif
29
30char *pbeg,*pbuf,*pend;
31char *outp,*inp;
32char *newp;
33char cinit;
34
35/* some code depends on whether characters are sign or zero extended */
36/* #if '\377' < 0 not used here, old cpp doesn't understand */
ce2749d6 37#if pdp11 | vax | mc68000 | tahoe
66cbbe7c
RH
38#define COFF 128
39#else
40#define COFF 0
41#endif
42
43# if gcos
44#define ALFSIZ 512 /* alphabet size */
45# else
46#define ALFSIZ 256 /* alphabet size */
47# endif
48char macbit[ALFSIZ+11];
49char toktyp[ALFSIZ];
50#define BLANK 1
51#define IDENT 2
52#define NUMBR 3
53
54/* a superimposed code is used to reduce the number of calls to the
55/* symbol table lookup routine. (if the kth character of an identifier
56/* is 'a' and there are no macro names whose kth character is 'a'
57/* then the identifier cannot be a macro name, hence there is no need
58/* to look in the symbol table.) 'scw1' enables the test based on
59/* single characters and their position in the identifier. 'scw2'
60/* enables the test based on adjacent pairs of characters and their
61/* position in the identifier. scw1 typically costs 1 indexed fetch,
62/* an AND, and a jump per character of identifier, until the identifier
63/* is known as a non-macro name or until the end of the identifier.
64/* scw1 is inexpensive. scw2 typically costs 4 indexed fetches,
65/* an add, an AND, and a jump per character of identifier, but it is also
66/* slightly more effective at reducing symbol table searches.
67/* scw2 usually costs too much because the symbol table search is
68/* usually short; but if symbol table search should become expensive,
69/* the code is here.
70/* using both scw1 and scw2 is of dubious value.
71*/
72#define scw1 1
73#define scw2 0
74
75#if scw2
76char t21[ALFSIZ],t22[ALFSIZ],t23[ALFSIZ+NCPS];
77#endif
78
79#if scw1
80#define b0 1
81#define b1 2
82#define b2 4
83#define b3 8
84#define b4 16
85#define b5 32
86#define b6 64
87#define b7 128
88#endif
89
90#define IB 1
91#define SB 2
92#define NB 4
93#define CB 8
94#define QB 16
95#define WB 32
96char fastab[ALFSIZ];
97char slotab[ALFSIZ];
98char *ptrtab;
99#define isslo (ptrtab==(slotab+COFF))
100#define isid(a) ((fastab+COFF)[a]&IB)
101#define isspc(a) (ptrtab[a]&SB)
102#define isnum(a) ((fastab+COFF)[a]&NB)
103#define iscom(a) ((fastab+COFF)[a]&CB)
104#define isquo(a) ((fastab+COFF)[a]&QB)
105#define iswarn(a) ((fastab+COFF)[a]&WB)
106
107#define eob(a) ((a)>=pend)
108#define bob(a) (pbeg>=(a))
109
8c7b88c5
SL
110# define cputc(a,b) if(!flslvl) putc(a,b)
111
66cbbe7c
RH
112char buffer[NCPS+BUFSIZ+BUFSIZ+NCPS];
113
7e5ed264
KM
114char *lastcopy;
115
116char *malloc(), *realloc();
66cbbe7c
RH
117
118# define DROP 0xFE /* special character not legal ASCII or EBCDIC */
119# define WARN DROP
120# define SAME 0
121# define MAXINC 10
122# define MAXFRE 14 /* max buffers of macro pushback */
123# define MAXFRM 31 /* max number of formals/actuals to a macro */
124
125static char warnc = WARN;
126
127int mactop,fretop;
128char *instack[MAXFRE],*bufstack[MAXFRE],*endbuf[MAXFRE];
129
130int plvl; /* parenthesis level during scan for macro actuals */
131int maclin; /* line number of macro call requiring actuals */
132char *macfil; /* file name of macro call requiring actuals */
133char *macnam; /* name of macro requiring actuals */
134int maclvl; /* # calls since last decrease in nesting level */
135char *macforw; /* pointer which must be exceeded to decrease nesting level */
136int macdam; /* offset to macforw due to buffer shifting */
137
138#if tgp
139int tgpscan; /* flag for dump(); */
140#endif
141
142STATIC int inctop[MAXINC];
143STATIC char *fnames[MAXINC];
144STATIC char *dirnams[MAXINC]; /* actual directory of #include files */
145STATIC int fins[MAXINC];
146STATIC int lineno[MAXINC];
147
148STATIC char *dirs[10]; /* -I and <> directories */
149char *strdex(), *copy(), *subst(), *trmdir();
150struct symtab *stsym();
061309d9 151STATIC int fin = FIRSTOPEN;
66cbbe7c
RH
152STATIC FILE *fout = stdout;
153STATIC int nd = 1;
154STATIC int pflag; /* don't put out lines "# 12 foo.c" */
8c7b88c5 155int passcom; /* don't delete comments */
c5a72b19 156int incomment; /* True if parsing a comment */
66cbbe7c 157STATIC int rflag; /* allow macro recursion */
61a8d43d
KM
158STATIC int mflag; /* generate makefile dependencies */
159STATIC char *infile; /* name of .o file to build dependencies from */
160STATIC FILE *mout; /* file to place dependencies on */
161#define START 1
162#define CONT 2
163#define BACK 3
66cbbe7c
RH
164STATIC int ifno;
165# define NPREDEF 20
166STATIC char *prespc[NPREDEF];
167STATIC char **predef = prespc;
168STATIC char *punspc[NPREDEF];
169STATIC char **prund = punspc;
170STATIC int exfail;
171struct symtab {
172 char *name;
173 char *value;
174} *lastsym, *lookup(), *slookup();
175
176# if gcos
177#include <setjmp.h>
178static jmp_buf env;
179# define main mainpp
180# undef exit
181# define exit(S) longjmp(env, 1)
182# define open(S,D) fileno(fopen(S, "r"))
183# define close(F) fclose(_f[F])
184extern FILE *_f[];
185# define symsiz 500
186# else
8c7b88c5 187# define symsiz 2000 /* std = 500, wnj aug 1979 */
66cbbe7c
RH
188# endif
189STATIC struct symtab stab[symsiz];
190
191STATIC struct symtab *defloc;
192STATIC struct symtab *udfloc;
193STATIC struct symtab *incloc;
194STATIC struct symtab *ifloc;
195STATIC struct symtab *elsloc;
196STATIC struct symtab *eifloc;
197STATIC struct symtab *ifdloc;
198STATIC struct symtab *ifnloc;
199STATIC struct symtab *ysysloc;
200STATIC struct symtab *varloc;
201STATIC struct symtab *lneloc;
202STATIC struct symtab *ulnloc;
203STATIC struct symtab *uflloc;
7e5ed264 204STATIC struct symtab *identloc; /* Sys 5r3 compatibility */
66cbbe7c
RH
205STATIC int trulvl;
206STATIC int flslvl;
207
61a8d43d
KM
208sayline(where)
209 int where;
210{
211 if (mflag && where==START) fprintf(mout, "%s: %s\n", infile, fnames[ifno]);
66cbbe7c
RH
212 if (pflag==0) fprintf(fout,"# %d \"%s\"\n", lineno[ifno], fnames[ifno]);
213}
214
215/* data structure guide
216/*
217/* most of the scanning takes place in the buffer:
218/*
219/* (low address) (high address)
220/* pbeg pbuf pend
221/* | <-- BUFSIZ chars --> | <-- BUFSIZ chars --> |
222/* _______________________________________________________________________
223/* |_______________________________________________________________________|
224/* | | |
225/* |<-- waiting -->| |<-- waiting -->
226/* | to be |<-- current -->| to be
227/* | written | token | scanned
228/* | | |
229/* outp inp p
230/*
231/* *outp first char not yet written to output file
232/* *inp first char of current token
233/* *p first char not yet scanned
234/*
235/* macro expansion: write from *outp to *inp (chars waiting to be written),
236/* ignore from *inp to *p (chars of the macro call), place generated
237/* characters in front of *p (in reverse order), update pointers,
238/* resume scanning.
239/*
240/* symbol table pointers point to just beyond the end of macro definitions;
241/* the first preceding character is the number of formal parameters.
242/* the appearance of a formal in the body of a definition is marked by
243/* 2 chars: the char WARN, and a char containing the parameter number.
244/* the first char of a definition is preceded by a zero character.
245/*
246/* when macro expansion attempts to back up over the beginning of the
247/* buffer, some characters preceding *pend are saved in a side buffer,
248/* the address of the side buffer is put on 'instack', and the rest
249/* of the main buffer is moved to the right. the end of the saved buffer
250/* is kept in 'endbuf' since there may be nulls in the saved buffer.
251/*
252/* similar action is taken when an 'include' statement is processed,
253/* except that the main buffer must be completely emptied. the array
254/* element 'inctop[ifno]' records the last side buffer saved when
255/* file 'ifno' was included. these buffers remain dormant while
256/* the file is being read, and are reactivated at end-of-file.
257/*
258/* instack[0 : mactop] holds the addresses of all pending side buffers.
259/* instack[inctop[ifno]+1 : mactop-1] holds the addresses of the side
260/* buffers which are "live"; the side buffers instack[0 : inctop[ifno]]
261/* are dormant, waiting for end-of-file on the current file.
262/*
7e5ed264 263/* space for side buffers is obtained from 'malloc' and is never returned.
66cbbe7c
RH
264/* bufstack[0:fretop-1] holds addresses of side buffers which
265/* are available for use.
266*/
267
268dump() {
269/* write part of buffer which lies between outp and inp .
270/* this should be a direct call to 'write', but the system slows to a crawl
271/* if it has to do an unaligned copy. thus we buffer. this silly loop
272/* is 15% of the total time, thus even the 'putc' macro is too slow.
273*/
274 register char *p1,*p2; register FILE *f;
275 if ((p1=outp)==inp || flslvl!=0) return;
276#if tgp
277#define MAXOUT 80
278 if (!tgpscan) {/* scan again to insure <= MAXOUT chars between linefeeds */
279 register char c,*pblank; char savc,stopc,brk;
280 tgpscan=1; brk=stopc=pblank=0; p2=inp; savc= *p2; *p2='\0';
281 while (c= *p1++) {
282 if (c=='\\') c= *p1++;
283 if (stopc==c) stopc=0;
284 else if (c=='"' || c=='\'') stopc=c;
285 if (p1-outp>MAXOUT && pblank!=0) {
286 *pblank++='\n'; inp=pblank; dump(); brk=1; pblank=0;
287 }
288 if (c==' ' && stopc==0) pblank=p1-1;
289 }
61a8d43d 290 if (brk) sayline(CONT);
66cbbe7c
RH
291 *p2=savc; inp=p2; p1=outp; tgpscan=0;
292 }
293#endif
294 f=fout;
295# if gcos
296/* filter out "$ program c" card if first line of input */
297/* gmatch is a simple pattern matcher in the GCOS Standard Library */
298{ static int gmfirst = 0;
299 if (!gmfirst) {
300 ++gmfirst;
301 if (gmatch(p1, "^$*program[ \t]*c*"))
302 p1 = strdex(p1, '\n');
303 }
304}
305# endif
306 while (p1<inp) putc(*p1++,f);
307 outp=p1;
308}
309
310char *
311refill(p) register char *p; {
312/* dump buffer. save chars from inp to p. read into buffer at pbuf,
313/* contiguous with p. update pointers, return new p.
314*/
315 register char *np,*op; register int ninbuf;
316 dump(); np=pbuf-(p-inp); op=inp;
317 if (bob(np+1)) {pperror("token too long"); np=pbeg; p=inp+BUFSIZ;}
318 macdam += np-inp; outp=inp=np;
319 while (op<p) *np++= *op++;
320 p=np;
321 for (;;) {
322 if (mactop>inctop[ifno]) {/* retrieve hunk of pushed-back macro text */
323 op=instack[--mactop]; np=pbuf;
324 do {while (*np++= *op++);} while (op<endbuf[mactop]); pend=np-1;
325 /* make buffer space avail for 'include' processing */
326 if (fretop<MAXFRE) bufstack[fretop++]=instack[mactop];
327 return(p);
328 } else {/* get more text from file(s) */
329 maclvl=0;
330 if (0<(ninbuf=read(fin,pbuf,BUFSIZ))) {
331 pend=pbuf+ninbuf; *pend='\0';
332 return(p);
333 }
334 /* end of #include file */
335 if (ifno==0) {/* end of input */
336 if (plvl!=0) {
337 int n=plvl,tlin=lineno[ifno]; char *tfil=fnames[ifno];
338 lineno[ifno]=maclin; fnames[ifno]=macfil;
339 pperror("%s: unterminated macro call",macnam);
340 lineno[ifno]=tlin; fnames[ifno]=tfil;
341 np=p; *np++='\n'; /* shut off unterminated quoted string */
342 while (--n>=0) *np++=')'; /* supply missing parens */
343 pend=np; *np='\0'; if (plvl<0) plvl=0;
344 return(p);
345 }
28801486 346 if (trulvl || flslvl)
c5a72b19
KM
347 if (incomment)
348 pperror("unterminated comment");
349 else
350 pperror("missing endif");
66cbbe7c
RH
351 inp=p; dump(); exit(exfail);
352 }
61a8d43d 353 close(fin); fin=fins[--ifno]; dirs[0]=dirnams[ifno]; sayline(BACK);
66cbbe7c
RH
354 }
355 }
356}
357
358#define BEG 0
359#define LF 1
360
361char *
362cotoken(p) register char *p; {
363 register int c,i; char quoc;
364 static int state = BEG;
365
366 if (state!=BEG) goto prevlf;
367for (;;) {
368again:
369 while (!isspc(*p++));
370 switch (*(inp=p-1)) {
371 case 0: {
372 if (eob(--p)) {p=refill(p); goto again;}
373 else ++p; /* ignore null byte */
374 } break;
375 case '|': case '&': for (;;) {/* sloscan only */
376 if (*p++== *inp) break;
377 if (eob(--p)) p=refill(p);
378 else break;
379 } break;
380 case '=': case '!': for (;;) {/* sloscan only */
381 if (*p++=='=') break;
382 if (eob(--p)) p=refill(p);
383 else break;
384 } break;
385 case '<': case '>': for (;;) {/* sloscan only */
386 if (*p++=='=' || p[-2]==p[-1]) break;
387 if (eob(--p)) p=refill(p);
388 else break;
389 } break;
390 case '\\': for (;;) {
391 if (*p++=='\n') {++lineno[ifno]; break;}
392 if (eob(--p)) p=refill(p);
393 else {++p; break;}
394 } break;
395 case '/': for (;;) {
396 if (*p++=='*') {/* comment */
c5a72b19 397 incomment++;
66cbbe7c
RH
398 if (!passcom) {inp=p-2; dump(); ++flslvl;}
399 for (;;) {
400 while (!iscom(*p++));
401 if (p[-1]=='*') for (;;) {
402 if (*p++=='/') goto endcom;
403 if (eob(--p)) {
404 if (!passcom) {inp=p; p=refill(p);}
405 else if ((p-inp)>=BUFSIZ) {/* split long comment */
406 inp=p; p=refill(p); /* last char written is '*' */
8c7b88c5 407 cputc('/',fout); /* terminate first part */
66cbbe7c
RH
408 /* and fake start of 2nd */
409 outp=inp=p-=3; *p++='/'; *p++='*'; *p++='*';
410 } else p=refill(p);
411 } else break;
412 } else if (p[-1]=='\n') {
413 ++lineno[ifno]; if (!passcom) putc('\n',fout);
414 } else if (eob(--p)) {
415 if (!passcom) {inp=p; p=refill(p);}
416 else if ((p-inp)>=BUFSIZ) {/* split long comment */
417 inp=p; p=refill(p);
8c7b88c5 418 cputc('*',fout); cputc('/',fout);
66cbbe7c
RH
419 outp=inp=p-=2; *p++='/'; *p++='*';
420 } else p=refill(p);
421 } else ++p; /* ignore null byte */
422 }
423 endcom:
c5a72b19 424 incomment--;
66cbbe7c
RH
425 if (!passcom) {outp=inp=p; --flslvl; goto again;}
426 break;
427 }
428 if (eob(--p)) p=refill(p);
429 else break;
430 } break;
431# if gcos
432 case '`':
433# endif
434 case '"': case '\'': {
435 quoc=p[-1];
436 for (;;) {
437 while (!isquo(*p++));
438 if (p[-1]==quoc) break;
439 if (p[-1]=='\n') {--p; break;} /* bare \n terminates quotation */
440 if (p[-1]=='\\') for (;;) {
441 if (*p++=='\n') {++lineno[ifno]; break;} /* escaped \n ignored */
442 if (eob(--p)) p=refill(p);
443 else {++p; break;}
444 } else if (eob(--p)) p=refill(p);
445 else ++p; /* it was a different quote character */
446 }
447 } break;
448 case '\n': {
449 ++lineno[ifno]; if (isslo) {state=LF; return(p);}
450prevlf:
451 state=BEG;
452 for (;;) {
453 if (*p++=='#') return(p);
454 if (eob(inp= --p)) p=refill(p);
455 else goto again;
456 }
457 } break;
458 case '0': case '1': case '2': case '3': case '4':
459 case '5': case '6': case '7': case '8': case '9':
460 for (;;) {
461 while (isnum(*p++));
462 if (eob(--p)) p=refill(p);
463 else break;
464 } break;
465 case 'A': case 'B': case 'C': case 'D': case 'E':
466 case 'F': case 'G': case 'H': case 'I': case 'J':
467 case 'K': case 'L': case 'M': case 'N': case 'O':
468 case 'P': case 'Q': case 'R': case 'S': case 'T':
469 case 'U': case 'V': case 'W': case 'X': case 'Y':
470 case 'Z': case '_':
471 case 'a': case 'b': case 'c': case 'd': case 'e':
472 case 'f': case 'g': case 'h': case 'i': case 'j':
473 case 'k': case 'l': case 'm': case 'n': case 'o':
474 case 'p': case 'q': case 'r': case 's': case 't':
475 case 'u': case 'v': case 'w': case 'x': case 'y':
476 case 'z':
477#if scw1
478#define tmac1(c,bit) if (!xmac1(c,bit,&)) goto nomac
479#define xmac1(c,bit,op) ((macbit+COFF)[c] op (bit))
480#else
481#define tmac1(c,bit)
482#define xmac1(c,bit,op)
483#endif
484
485#if scw2
486#define tmac2(c0,c1,cpos) if (!xmac2(c0,c1,cpos,&)) goto nomac
487#define xmac2(c0,c1,cpos,op)\
488 ((macbit+COFF)[(t21+COFF)[c0]+(t22+COFF)[c1]] op (t23+COFF+cpos)[c0])
489#else
490#define tmac2(c0,c1,cpos)
491#define xmac2(c0,c1,cpos,op)
492#endif
493
494 if (flslvl) goto nomac;
495 for (;;) {
496 c= p[-1]; tmac1(c,b0);
497 i= *p++; if (!isid(i)) goto endid; tmac1(i,b1); tmac2(c,i,0);
498 c= *p++; if (!isid(c)) goto endid; tmac1(c,b2); tmac2(i,c,1);
499 i= *p++; if (!isid(i)) goto endid; tmac1(i,b3); tmac2(c,i,2);
500 c= *p++; if (!isid(c)) goto endid; tmac1(c,b4); tmac2(i,c,3);
501 i= *p++; if (!isid(i)) goto endid; tmac1(i,b5); tmac2(c,i,4);
502 c= *p++; if (!isid(c)) goto endid; tmac1(c,b6); tmac2(i,c,5);
503 i= *p++; if (!isid(i)) goto endid; tmac1(i,b7); tmac2(c,i,6);
504 tmac2(i,0,7);
505 while (isid(*p++));
506 if (eob(--p)) {refill(p); p=inp+1; continue;}
507 goto lokid;
508 endid:
509 if (eob(--p)) {refill(p); p=inp+1; continue;}
510 tmac2(p[-1],0,-1+(p-inp));
511 lokid:
512 slookup(inp,p,0); if (newp) {p=newp; goto again;}
513 else break;
514 nomac:
515 while (isid(*p++));
516 if (eob(--p)) {p=refill(p); goto nomac;}
517 else break;
518 } break;
519 } /* end of switch */
520
521 if (isslo) return(p);
522} /* end of infinite loop */
523}
524
525char *
526skipbl(p) register char *p; {/* get next non-blank token */
527 do {outp=inp=p; p=cotoken(p);} while ((toktyp+COFF)[*inp]==BLANK);
528 return(p);
529}
530
531char *
532unfill(p) register char *p; {
533/* take <= BUFSIZ chars from right end of buffer and put them on instack .
534/* slide rest of buffer to the right, update pointers, return new p.
535*/
536 register char *np,*op; register int d;
537 if (mactop>=MAXFRE) {
538 pperror("%s: too much pushback",macnam);
539 p=inp=pend; dump(); /* begin flushing pushback */
540 while (mactop>inctop[ifno]) {p=refill(p); p=inp=pend; dump();}
541 }
542 if (fretop>0) np=bufstack[--fretop];
543 else {
7e5ed264
KM
544 np=malloc(BUFSIZ+1);
545 if (np==NULL) {pperror("no space"); exit(exfail);}
546 np[BUFSIZ]='\0';
66cbbe7c
RH
547 }
548 instack[mactop]=np; op=pend-BUFSIZ; if (op<p) op=p;
549 for (;;) {while (*np++= *op++); if (eob(op)) break;} /* out with old */
550 endbuf[mactop++]=np; /* mark end of saved text */
551 np=pbuf+BUFSIZ; op=pend-BUFSIZ; pend=np; if (op<p) op=p;
552 while (outp<op) *--np= *--op; /* slide over new */
553 if (bob(np)) pperror("token too long");
554 d=np-outp; outp+=d; inp+=d; macdam+=d; return(p+d);
555}
556
557char *
558doincl(p) register char *p; {
559 int filok,inctype;
560 register char *cp; char **dirp,*nfil; char filname[BUFSIZ];
561
562 p=skipbl(p); cp=filname;
563 if (*inp++=='<') {/* special <> syntax */
564 inctype=1;
565 ++flslvl; /* prevent macro expansion */
566 for (;;) {
567 outp=inp=p; p=cotoken(p);
568 if (*inp=='\n') {--p; *cp='\0'; break;}
569 if (*inp=='>') { *cp='\0'; break;}
570# ifdef gimpel
571 if (*inp=='.' && !intss()) *inp='#';
572# endif
573 while (inp<p) *cp++= *inp++;
574 }
575 --flslvl; /* reenable macro expansion */
576 } else if (inp[-1]=='"') {/* regular "" syntax */
577 inctype=0;
578# ifdef gimpel
579 while (inp<p) {if (*inp=='.' && !intss()) *inp='#'; *cp++= *inp++;}
580# else
581 while (inp<p) *cp++= *inp++;
582# endif
583 if (*--cp=='"') *cp='\0';
584 } else {pperror("bad include syntax",0); inctype=2;}
585 /* flush current file to \n , then write \n */
586 ++flslvl; do {outp=inp=p; p=cotoken(p);} while (*inp!='\n'); --flslvl;
587 inp=p; dump(); if (inctype==2) return(p);
588 /* look for included file */
589 if (ifno+1 >=MAXINC) {
590 pperror("Unreasonable include nesting",0); return(p);
591 }
7e5ed264 592 if((nfil=malloc(BUFSIZ))==NULL) {pperror("no space"); exit(exfail);}
66cbbe7c
RH
593 filok=0;
594 for (dirp=dirs+inctype; *dirp; ++dirp) {
595 if (
596# if gcos
597 strdex(filname, '/')
598# else
599 filname[0]=='/'
600# endif
601 || **dirp=='\0') strcpy(nfil,filname);
602 else {
603 strcpy(nfil,*dirp);
604# if unix || gcos
605 strcat(nfil,"/");
606# endif
607#ifdef ibm
608#ifndef gimpel
609 strcat(nfil,".");
610#endif
611#endif
612 strcat(nfil,filname);
613 }
614 if (0<(fins[ifno+1]=open(nfil,READ))) {
615 filok=1; fin=fins[++ifno]; break;
616 }
617 }
7e5ed264 618 if(filok==0){pperror("Can't find include file %s",filname);free(nfil);}
66cbbe7c 619 else {
7e5ed264
KM
620 nfil=realloc(nfil,strlen(nfil)+1);
621 lineno[ifno]=1; fnames[ifno]=nfil;
66cbbe7c 622 dirnams[ifno]=dirs[0]=trmdir(copy(nfil));
61a8d43d 623 sayline(START);
66cbbe7c
RH
624 /* save current contents of buffer */
625 while (!eob(p)) p=unfill(p);
626 inctop[ifno]=mactop;
627 }
628 return(p);
629}
630
631equfrm(a,p1,p2) register char *a,*p1,*p2; {
632 register char c; int flag;
633 c= *p2; *p2='\0';
634 flag=strcmp(a,p1); *p2=c; return(flag==SAME);
635}
636
637char *
638dodef(p) char *p; {/* process '#define' */
639 register char *pin,*psav,*cf;
640 char **pf,**qf; int b,c,params; struct symtab *np;
7e5ed264
KM
641 char *oldval;
642 char *space, *newspace;
66cbbe7c
RH
643 char *formal[MAXFRM]; /* formal[n] is name of nth formal */
644 char formtxt[BUFSIZ]; /* space for formal names */
db4b8c35
DS
645 int opt_passcom=passcom;
646
647 passcom=0; /* don't put comments in macro expansions */
66cbbe7c 648
66cbbe7c
RH
649 ++flslvl; /* prevent macro expansion during 'define' */
650 p=skipbl(p); pin=inp;
651 if ((toktyp+COFF)[*pin]!=IDENT) {
db4b8c35
DS
652 ppwarn("illegal macro name"); while (*inp!='\n') p=skipbl(p);
653 passcom=opt_passcom; return(p);
66cbbe7c
RH
654 }
655 np=slookup(pin,p,1);
7e5ed264 656 if (oldval=np->value) free(lastcopy); /* was previously defined */
66cbbe7c
RH
657 b=1; cf=pin;
658 while (cf<p) {/* update macbit */
659 c= *cf++; xmac1(c,b,|=); b=(b+b)&0xFF;
660 if (cf!=p) xmac2(c,*cf,-1+(cf-pin),|=);
661 else xmac2(c,0,-1+(cf-pin),|=);
662 }
663 params=0; outp=inp=p; p=cotoken(p); pin=inp;
664 if (*pin=='(') {/* with parameters; identify the formals */
665 cf=formtxt; pf=formal;
666 for (;;) {
667 p=skipbl(p); pin=inp;
668 if (*pin=='\n') {
669 --lineno[ifno]; --p; pperror("%s: missing )",np->name); break;
670 }
671 if (*pin==')') break;
672 if (*pin==',') continue;
673 if ((toktyp+COFF)[*pin]!=IDENT) {
674 c= *p; *p='\0'; pperror("bad formal: %s",pin); *p=c;
675 } else if (pf>= &formal[MAXFRM]) {
676 c= *p; *p='\0'; pperror("too many formals: %s",pin); *p=c;
677 } else {
678 *pf++=cf; while (pin<p) *cf++= *pin++; *cf++='\0'; ++params;
679 }
680 }
681 if (params==0) --params; /* #define foo() ... */
682 } else if (*pin=='\n') {--lineno[ifno]; --p;}
683 /* remember beginning of macro body, so that we can
684 /* warn if a redefinition is different from old value.
685 */
7e5ed264 686 space=psav=malloc(BUFSIZ);
db4b8c35
DS
687 if (space==NULL) {
688 pperror("too much defining");
689 passcom=opt_passcom;
690 return(p);
691 }
7e5ed264 692 *psav++ = '\0';
66cbbe7c
RH
693 for (;;) {/* accumulate definition until linefeed */
694 outp=inp=p; p=cotoken(p); pin=inp;
695 if (*pin=='\\' && pin[1]=='\n') {putc('\n',fout); continue;} /* ignore escaped lf */
696 if (*pin=='\n') break;
697 if (params) {/* mark the appearance of formals in the definiton */
698 if ((toktyp+COFF)[*pin]==IDENT) {
699 for (qf=pf; --qf>=formal; ) {
700 if (equfrm(*qf,pin,p)) {
701 *psav++=qf-formal+1; *psav++=WARN; pin=p; break;
702 }
703 }
704 } else if (*pin=='"' || *pin=='\''
705# if gcos
706 || *pin=='`'
707# endif
708 ) {/* inside quotation marks, too */
709 char quoc= *pin;
710 for (*psav++= *pin++; pin<p && *pin!=quoc; ) {
711 while (pin<p && !isid(*pin)) *psav++= *pin++;
712 cf=pin; while (cf<p && isid(*cf)) ++cf;
713 for (qf=pf; --qf>=formal; ) {
714 if (equfrm(*qf,pin,cf)) {
715 *psav++=qf-formal+1; *psav++=WARN; pin=cf; break;
716 }
717 }
718 while (pin<cf) *psav++= *pin++;
719 }
720 }
721 }
722 while (pin<p) *psav++= *pin++;
723 }
724 *psav++=params; *psav++='\0';
725 if ((cf=oldval)!=NULL) {/* redefinition */
726 --cf; /* skip no. of params, which may be zero */
727 while (*--cf); /* go back to the beginning */
7e5ed264 728 if (0!=strcmp(++cf,space+1)) {/* redefinition different from old */
66cbbe7c
RH
729 --lineno[ifno]; ppwarn("%s redefined",np->name); ++lineno[ifno];
730 np->value=psav-1;
7e5ed264 731 } else free(space); /* identical redef.; reclaim space */
66cbbe7c 732 } else np->value=psav-1;
7e5ed264
KM
733 --flslvl; inp=pin;
734 if (np->value == psav-1) {
735 newspace = realloc(space, psav-space);
736 if (newspace==NULL) {pperror("no space"); exit(exfail);}
737 /*
738 * Adjust pointer in case this moved.
739 */
740 np->value += newspace-space;
741 }
db4b8c35 742 passcom=opt_passcom;
7e5ed264 743 return(p);
66cbbe7c
RH
744}
745
746#define fasscan() ptrtab=fastab+COFF
747#define sloscan() ptrtab=slotab+COFF
748
749char *
750control(p) register char *p; {/* find and handle preprocessor control lines */
751 register struct symtab *np;
752for (;;) {
753 fasscan(); p=cotoken(p); if (*inp=='\n') ++inp; dump();
754 sloscan(); p=skipbl(p);
755 *--inp=SALT; outp=inp; ++flslvl; np=slookup(inp,p,0); --flslvl;
756 if (np==defloc) {/* define */
757 if (flslvl==0) {p=dodef(p); continue;}
758 } else if (np==incloc) {/* include */
759 if (flslvl==0) {p=doincl(p); continue;}
760 } else if (np==ifnloc) {/* ifndef */
761 ++flslvl; p=skipbl(p); np=slookup(inp,p,0); --flslvl;
762 if (flslvl==0 && np->value==0) ++trulvl;
763 else ++flslvl;
764 } else if (np==ifdloc) {/* ifdef */
765 ++flslvl; p=skipbl(p); np=slookup(inp,p,0); --flslvl;
766 if (flslvl==0 && np->value!=0) ++trulvl;
767 else ++flslvl;
768 } else if (np==eifloc) {/* endif */
61a8d43d 769 if (flslvl) {if (--flslvl==0) sayline(CONT);}
66cbbe7c
RH
770 else if (trulvl) --trulvl;
771 else pperror("If-less endif",0);
772 } else if (np==elsloc) {/* else */
773 if (flslvl) {
774 if (--flslvl!=0) ++flslvl;
61a8d43d 775 else {++trulvl; sayline(CONT);}
66cbbe7c
RH
776 }
777 else if (trulvl) {++flslvl; --trulvl;}
778 else pperror("If-less else",0);
779 } else if (np==udfloc) {/* undefine */
780 if (flslvl==0) {
781 ++flslvl; p=skipbl(p); slookup(inp,p,DROP); --flslvl;
782 }
783 } else if (np==ifloc) {/* if */
784#if tgp
785 pperror(" IF not implemented, true assumed", 0);
786 if (flslvl==0) ++trulvl; else ++flslvl;
787#else
788 newp=p;
789 if (flslvl==0 && yyparse()) ++trulvl; else ++flslvl;
790 p=newp;
791#endif
792 } else if (np==lneloc) {/* line */
793 if (flslvl==0 && pflag==0) {
c5a72b19
KM
794 char *savestring();
795 char filename[BUFSIZ], *cp = filename;
796 outp=inp=p; *--outp='#';
797 /* Find the line number.. */
798 do {
799 p = cotoken(p);
800 } while (!isnum(*inp) && *inp != '\n');
801 if (isnum(*inp))
802 lineno[ifno] = atoi(inp)-1;
803 /* Skip over the blank token */
804 inp = p;
805 if (*inp != '\n') {
806 p = cotoken(p); inp = p;
9372792e 807 }
c5a72b19
KM
808 /* Add a quote if missing.. */
809 if (*inp != '\n') {
810 p = cotoken(p);
811 /* Add a quote if missing.. */
812 if (*inp == '"')
813 inp++;
814 else {
815 dump();
816 *--outp = '"';
817 }
818 while (*inp != '\n') {
819 while (inp < p && *inp != '"' &&
820 cp < filename+sizeof(filename))
821 *cp++ = *inp++;
822 if (*inp == '"')
823 break;
824 inp = p; p = cotoken(p);
825 }
826 fnames[ifno] = savestring(filename, cp);
827 /* Add a quote if missing.. */
828 if (*inp != '"') {
829 dump();
830 *--outp = '"';
831 }
832 }
833 while (*inp != '\n')
834 p = cotoken(p);
66cbbe7c
RH
835 continue;
836 }
7e5ed264
KM
837 } else if (np==identloc) {/* ident (for Sys 5r3 compat) */
838 while(*inp!='\n') p=cotoken(p);
66cbbe7c
RH
839 } else if (*++inp=='\n') outp=inp; /* allows blank line after # */
840 else pperror("undefined control",0);
841 /* flush to lf */
842 ++flslvl; while (*inp!='\n') {outp=inp=p; p=cotoken(p);} --flslvl;
843}
844}
845
9372792e
RH
846char *
847savestring(start, finish)
848 register char *start, *finish;
849{
850 char *retbuf;
851 register char *cp;
852
853 retbuf = (char *) calloc(finish - start + 1, sizeof (char));
854 cp = retbuf;
855 while (start < finish)
856 *cp++ = *start++;
857 *cp = 0;
858 return(retbuf);
859}
860
66cbbe7c
RH
861struct symtab *
862stsym(s) register char *s; {
863 char buf[BUFSIZ]; register char *p;
864
865 /* make definition look exactly like end of #define line */
866 /* copy to avoid running off end of world when param list is at end */
867 p=buf; while (*p++= *s++);
868 p=buf; while (isid(*p++)); /* skip first identifier */
869 if (*--p=='=') {*p++=' '; while (*p++);}
870 else {s=" 1"; while (*p++= *s++);}
871 pend=p; *--p='\n';
872 sloscan(); dodef(buf); return(lastsym);
873}
874
875struct symtab *
876ppsym(s) char *s; {/* kluge */
877 register struct symtab *sp;
7e5ed264
KM
878 register char *name;
879
880 cinit=SALT; sp=stsym(s); name = malloc(strlen(sp->name)+1+1);
881 name[0] = '#'; strcpy(name+1, sp->name); sp->name = name;
882 cinit=0; return(sp);
66cbbe7c
RH
883}
884
885/* VARARGS1 */
886pperror(s,x,y) char *s; {
887 if (fnames[ifno][0]) fprintf(stderr,
888# if gcos
889 "*%c* \"%s\", line ", exfail >= 0 ? 'F' : 'W',
890# else
891 "%s: ",
892# endif
893 fnames[ifno]);
894 fprintf(stderr, "%d: ",lineno[ifno]);
895 fprintf(stderr, s, x, y);
896 fprintf(stderr,"\n");
897 ++exfail;
898}
899
900yyerror(s,a,b) char *s; {
901 pperror(s,a,b);
902}
903
904ppwarn(s,x) char *s; {
905 int fail = exfail;
906 exfail = -1;
907 pperror(s,x);
908 exfail = fail;
909}
910
911struct symtab *
912lookup(namep, enterf)
913char *namep;
914{
915 register char *np, *snp;
916 register int c, i; int around;
917 register struct symtab *sp;
918
919 /* namep had better not be too long (currently, <=NCPS chars) */
920 np=namep; around=0; i=cinit;
921 while (c= *np++) i += i+c; c=i; /* c=i for register usage on pdp11 */
922 c %= symsiz; if (c<0) c += symsiz;
923 sp = &stab[c];
924 while (snp=sp->name) {
925 np = namep;
926 while (*snp++ == *np) if (*np++ == '\0') {
927 if (enterf==DROP) {sp->name[0]= DROP; sp->value=0;}
928 return(lastsym=sp);
929 }
930 if (--sp < &stab[0])
931 if (around) {pperror("too many defines", 0); exit(exfail);}
932 else {++around; sp = &stab[symsiz-1];}
933 }
934 if (enterf==1) sp->name=namep;
935 return(lastsym=sp);
936}
937
938struct symtab *
939slookup(p1,p2,enterf) register char *p1,*p2; int enterf;{
940 register char *p3; char c2,c3; struct symtab *np;
941 c2= *p2; *p2='\0'; /* mark end of token */
942 if ((p2-p1)>NCPS) p3=p1+NCPS; else p3=p2;
943 c3= *p3; *p3='\0'; /* truncate to NCPS chars or less */
944 if (enterf==1) p1=copy(p1);
945 np=lookup(p1,enterf); *p3=c3; *p2=c2;
946 if (np->value!=0 && flslvl==0) newp=subst(p2,np);
947 else newp=0;
948 return(np);
949}
950
951char *
952subst(p,sp) register char *p; struct symtab *sp; {
953 static char match[]="%s: argument mismatch";
954 register char *ca,*vp; int params;
8c7b88c5
SL
955 char *actual[MAXFRM]; /* actual[n] is text of nth actual */
956 char actused[MAXFRM]; /* for newline processing in actuals */
957 char acttxt[BUFSIZ]; /* space for actuals */
958 int nlines = 0;
66cbbe7c
RH
959
960 if (0==(vp=sp->value)) return(p);
961 if ((p-macforw)<=macdam) {
962 if (++maclvl>symsiz && !rflag) {
963 pperror("%s: macro recursion",sp->name); return(p);
964 }
965 } else maclvl=0; /* level decreased */
966 macforw=p; macdam=0; /* new target for decrease in level */
967 macnam=sp->name;
968 dump();
969 if (sp==ulnloc) {
970 vp=acttxt; *vp++='\0';
971 sprintf(vp,"%d",lineno[ifno]); while (*vp++);
972 } else if (sp==uflloc) {
973 vp=acttxt; *vp++='\0';
974 sprintf(vp,"\"%s\"",fnames[ifno]); while (*vp++);
975 }
976 if (0!=(params= *--vp&0xFF)) {/* definition calls for params */
977 register char **pa;
978 ca=acttxt; pa=actual;
979 if (params==0xFF) params=1; /* #define foo() ... */
980 sloscan(); ++flslvl; /* no expansion during search for actuals */
981 plvl= -1;
982 do p=skipbl(p); while (*inp=='\n'); /* skip \n too */
983 if (*inp=='(') {
984 maclin=lineno[ifno]; macfil=fnames[ifno];
985 for (plvl=1; plvl!=0; ) {
986 *ca++='\0';
987 for (;;) {
988 outp=inp=p; p=cotoken(p);
989 if (*inp=='(') ++plvl;
990 if (*inp==')' && --plvl==0) {--params; break;}
991 if (plvl==1 && *inp==',') {--params; break;}
992 while (inp<p) *ca++= *inp++;
993 if (ca> &acttxt[BUFSIZ])
994 pperror("%s: actuals too long",sp->name);
995 }
996 if (pa>= &actual[MAXFRM]) ppwarn(match,sp->name);
8c7b88c5 997 else { actused[pa-actual]=0; *pa++=ca; }
66cbbe7c 998 }
8c7b88c5
SL
999 nlines = lineno[ifno] - maclin;
1000 lineno[ifno] = maclin; /* don't count newlines here */
66cbbe7c
RH
1001 }
1002 if (params!=0) ppwarn(match,sp->name);
1003 while (--params>=0) *pa++=""+1; /* null string for missing actuals */
1004 --flslvl; fasscan();
1005 }
1006 for (;;) {/* push definition onto front of input stack */
1007 while (!iswarn(*--vp)) {
1008 if (bob(p)) {outp=inp=p; p=unfill(p);}
1009 *--p= *vp;
1010 }
1011 if (*vp==warnc) {/* insert actual param */
1012 ca=actual[*--vp-1];
1013 while (*--ca) {
1014 if (bob(p)) {outp=inp=p; p=unfill(p);}
8c7b88c5
SL
1015 /* Actuals with newlines confuse line numbering */
1016 if (*ca == '\n' && actused[*vp-1])
1017 if (*(ca-1) == '\\') ca--;
1018 else *--p = ' ';
1019 else { *--p= *ca; if (*ca == '\n') nlines--; }
66cbbe7c 1020 }
8c7b88c5
SL
1021 actused[*vp-1] = 1;
1022 } else {
1023 if (nlines > 0 )
1024 while (nlines-- > 0)
1025 *--p = '\n';
1026 break;
1027 }
66cbbe7c
RH
1028 }
1029 outp=inp=p;
1030 return(p);
1031}
1032
1033
1034
1035
1036char *
1037trmdir(s) register char *s; {
1038 register char *p = s;
1039 while (*p++); --p; while (p>s && *--p!='/');
1040# if unix
1041 if (p==s) *p++='.';
1042# endif
1043 *p='\0';
1044 return(s);
1045}
1046
1047STATIC char *
1048copy(s) register char *s; {
1049 register char *old;
1050
7e5ed264
KM
1051 old = malloc(strlen(s)+1);
1052 if (old==NULL) {pperror("no space"); exit(exfail);}
1053 strcpy(old, s);
1054 return(lastcopy=old);
66cbbe7c
RH
1055}
1056
1057char *
1058strdex(s,c) char *s,c; {
1059 while (*s) if (*s++==c) return(--s);
1060 return(0);
1061}
1062
1063yywrap(){ return(1); }
1064
1065main(argc,argv)
1066 char *argv[];
1067{
1068 register int i,c;
1069 register char *p;
1070 char *tf,**cp2;
1071
1072# if gcos
1073 if (setjmp(env)) return (exfail);
1074# endif
1075 p="_$ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
1076 i=0;
1077 while (c= *p++) {
1078 (fastab+COFF)[c] |= IB|NB|SB; (toktyp+COFF)[c]=IDENT;
1079#if scw2
1080 /* 53 == 63-10; digits rarely appear in identifiers,
1081 /* and can never be the first char of an identifier.
1082 /* 11 == 53*53/sizeof(macbit) .
1083 */
1084 ++i; (t21+COFF)[c]=(53*i)/11; (t22+COFF)[c]=i%11;
1085#endif
1086 }
1087 p="0123456789.";
1088 while (c= *p++) {(fastab+COFF)[c] |= NB|SB; (toktyp+COFF)[c]=NUMBR;}
1089# if gcos
1090 p="\n\"'`/\\";
1091# else
1092 p="\n\"'/\\";
1093# endif
1094 while (c= *p++) (fastab+COFF)[c] |= SB;
1095# if gcos
1096 p="\n\"'`\\";
1097# else
1098 p="\n\"'\\";
1099# endif
1100 while (c= *p++) (fastab+COFF)[c] |= QB;
1101 p="*\n"; while (c= *p++) (fastab+COFF)[c] |= CB;
1102 (fastab+COFF)[warnc] |= WB;
1103 (fastab+COFF)['\0'] |= CB|QB|SB|WB;
1104 for (i=ALFSIZ; --i>=0; ) slotab[i]=fastab[i]|SB;
1105 p=" \t\013\f\r"; /* note no \n; \v not legal for vertical tab? */
1106 while (c= *p++) (toktyp+COFF)[c]=BLANK;
1107#if scw2
1108 for ((t23+COFF)[i=ALFSIZ+7-COFF]=1; --i>=-COFF; )
1109 if (((t23+COFF)[i]=(t23+COFF+1)[i]<<1)==0) (t23+COFF)[i]=1;
1110#endif
1111
1112# if unix
1113 fnames[ifno=0] = ""; dirnams[0]=dirs[0]=".";
1114# endif
1115# if ibm
1116 fnames[ifno=0] = "";
1117# endif
1118# if gcos
1119 if (inquire(stdin, _TTY)) freopen("*src", "rt", stdin);
1120# endif
1121# if gimpel || gcos
1122 fnames[ifno=0] = (char *)inquire(stdin, _FILENAME);
1123 dirnams[0] = dirs[0] = trmdir(copy(fnames[0]));
1124# endif
1125 for(i=1; i<argc; i++)
1126 {
1127 switch(argv[i][0])
1128 {
1129 case '-':
1130# if gcos
1131 switch(toupper(argv[i][1])) { /* case-independent on GCOS */
1132# else
1133 switch(argv[i][1]) {
1134# endif
61a8d43d 1135 case 'M': mflag++;
66cbbe7c
RH
1136 case 'P': pflag++;
1137 case 'E': continue;
1138 case 'R': ++rflag; continue;
1139 case 'C': passcom++; continue;
1140 case 'D':
1141 if (predef>prespc+NPREDEF) {
1142 pperror("too many -D options, ignoring %s",argv[i]);
1143 continue;
1144 }
1145 /* ignore plain "-D" (no argument) */
1146 if (*(argv[i]+2)) *predef++ = argv[i]+2;
1147 continue;
1148 case 'U':
1149 if (prund>punspc+NPREDEF) {
1150 pperror("too many -U options, ignoring %s",argv[i]);
1151 continue;
1152 }
1153 *prund++ = argv[i]+2;
1154 continue;
1155 case 'I':
1156 if (nd>8) pperror("excessive -I file (%s) ignored",argv[i]);
1157 else dirs[nd++] = argv[i]+2;
1158 continue;
1159 case '\0': continue;
1160 default:
1161 pperror("unknown flag %s", argv[i]);
1162 continue;
1163 }
1164 default:
061309d9 1165 if (fin==FIRSTOPEN) {
66cbbe7c
RH
1166 if (0>(fin=open(argv[i], READ))) {
1167 pperror("No source file %s",argv[i]); exit(8);
1168 }
1169 fnames[ifno]=copy(argv[i]);
61a8d43d 1170 infile=copy(argv[i]);
9372792e 1171 dirs[0]=dirnams[ifno]=trmdir(argv[i]);
66cbbe7c
RH
1172# ifndef gcos
1173/* too dangerous to have file name in same syntactic position
1174 be input or output file depending on file redirections,
1175 so force output to stdout, willy-nilly
1176 [i don't see what the problem is. jfr]
1177*/
1178 } else if (fout==stdout) {
66cbbe7c
RH
1179 if (NULL==(fout=fopen(argv[i], "w"))) {
1180 pperror("Can't create %s", argv[i]); exit(8);
ba27d052 1181 } else fclose(stdout);
66cbbe7c
RH
1182# endif
1183 } else pperror("extraneous name %s", argv[i]);
1184 }
1185 }
c5a72b19
KM
1186 if (fin == FIRSTOPEN)
1187 fin = STDIN;
66cbbe7c 1188
61a8d43d
KM
1189 if (mflag) {
1190 if (infile==(char *)0) {
1191 fprintf(stderr,
1192 "no input file specified with -M flag\n");
1193 exit(8);
1194 }
1195 tf=(char *)rindex(infile, '.');
1196 if (tf==0) {
1197 fprintf(stderr, "missing component name on %s\n",
1198 infile);
1199 exit(8);
1200 }
1201 tf[1]='o';
1202 tf=(char *)rindex(infile, '/');
1203 if (tf!=(char *)0)
1204 infile = tf + 1;
1205 mout=fout;
1206 if (NULL==(fout=fopen("/dev/null", "w"))) {
1207 pperror("Can't open /dev/null");
1208 exit(8);
1209 }
1210 }
66cbbe7c
RH
1211 fins[ifno]=fin;
1212 exfail = 0;
1213 /* after user -I files here are the standard include libraries */
1214# if unix
1215 dirs[nd++] = "/usr/include";
1216# endif
1217# if gcos
1218 dirs[nd++] = "cc/include";
1219# endif
1220# if ibm
1221# ifndef gimpel
1222 dirs[nd++] = "BTL$CLIB";
1223# endif
1224# endif
1225# ifdef gimpel
1226 dirs[nd++] = intss() ? "SYS3.C." : "" ;
1227# endif
1228 /* dirs[nd++] = "/compool"; */
1229 dirs[nd++] = 0;
1230 defloc=ppsym("define");
1231 udfloc=ppsym("undef");
1232 incloc=ppsym("include");
1233 elsloc=ppsym("else");
1234 eifloc=ppsym("endif");
1235 ifdloc=ppsym("ifdef");
1236 ifnloc=ppsym("ifndef");
1237 ifloc=ppsym("if");
1238 lneloc=ppsym("line");
7e5ed264 1239 identloc=ppsym("ident"); /* Sys 5r3 compatibility */
66cbbe7c
RH
1240 for (i=sizeof(macbit)/sizeof(macbit[0]); --i>=0; ) macbit[i]=0;
1241# if unix
1242 ysysloc=stsym("unix");
1243# endif
1244# if gcos
1245 ysysloc=stsym ("gcos");
1246# endif
1247# if ibm
1248 ysysloc=stsym ("ibm");
1249# endif
1250# if pdp11
1251 varloc=stsym("pdp11");
1252# endif
1253# if vax
1254 varloc=stsym("vax");
1255# endif
ce2749d6
SL
1256# if tahoe
1257 varloc=stsym("tahoe");
1258# endif
66cbbe7c
RH
1259# if interdata
1260 varloc=stsym ("interdata");
1261# endif
1262# if tss
1263 varloc=stsym ("tss");
1264# endif
1265# if os
1266 varloc=stsym ("os");
1267# endif
1268# if mert
1269 varloc=stsym ("mert");
5f18cf8b
SL
1270# endif
1271# if mc68000
1272 varloc=stsym("mc68000");
1273# endif
1274# if sun
1275 varloc=stsym("sun");
66cbbe7c
RH
1276# endif
1277 ulnloc=stsym ("__LINE__");
1278 uflloc=stsym ("__FILE__");
1279
1280 tf=fnames[ifno]; fnames[ifno]="command line"; lineno[ifno]=1;
1281 cp2=prespc;
1282 while (cp2<predef) stsym(*cp2++);
1283 cp2=punspc;
1284 while (cp2<prund) {
1285 if (p=strdex(*cp2, '=')) *p++='\0';
1286 lookup(*cp2++, DROP);
1287 }
1288 fnames[ifno]=tf;
1289 pbeg=buffer+NCPS; pbuf=pbeg+BUFSIZ; pend=pbuf+BUFSIZ;
1290
1291 trulvl = 0; flslvl = 0;
61a8d43d 1292 lineno[0] = 1; sayline(START);
66cbbe7c
RH
1293 outp=inp=pend;
1294 control(pend);
1295 return (exfail);
1296}