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