History

Plan 9 from Bell Labs Second Edition 1995-04-05

David du Colombier committed 31 years ago2e-1995-04-05

Commit 219b2ee1 parent bd389b311749 files · +2555453 −1889727Browse files

Showing the changes to sys/src/cmd/cpp (8 of 11749 files). Show all

Unified · Split

8 files
  1. sys/src/cmd/cpp/cpp.c +7 −5
  2. sys/src/cmd/cpp/cpp.h +4 −2
  3. sys/src/cmd/cpp/eval.c +2 −2
  4. sys/src/cmd/cpp/include.c +6 −1
  5. sys/src/cmd/cpp/lex.c +7 −4
  6. sys/src/cmd/cpp/macro.c +1 −1
  7. sys/src/cmd/cpp/nlist.c +7 −0
  8. sys/src/cmd/cpp/tokens.c +22 −3
sys/src/cmd/cpp/cpp.c+7−5
@@ -16,7 +16,7 @@ int ifdepth; · 15 unmodified lines
1616 int ifsatisfied[NIF];
1717 int skipping;
1818
19−void
19+int
2020 main(int argc, char **argv)
2121 {
2222 Tokenrow tr;
@@ -36,6 +36,7 @@ main(int argc, char **argv) · 13 unmodified lines
3636 flushout();
3737 fflush(stderr);
3838 exits(nerrs? "errors" : 0);
39+ return 0;
3940 }
4041
4142 void
@@ -266,12 +267,13 @@ error(enum errtype type, char *string, ...) · 224 unmodified lines
266267 char *cp, *ep;
267268 Token *tp;
268269 Tokenrow *trp;
270+ Source *s;
269271 int i;
270272
271− if (*cursource->filename)
272− fprintf(stderr, "cpp: %s:%d: ", cursource->filename, cursource->line);
273− else
274− fprintf(stderr, "cpp: ");
273+ fprintf(stderr, "cpp: ");
274+ for (s=cursource; s; s=s->next)
275+ if (*s->filename)
276+ fprintf(stderr, "%s:%d ", s->filename, s->line);
275277 va_start(ap, string);
276278 for (ep=string; *ep; ep++) {
277279 if (*ep=='%') {
sys/src/cmd/cpp/cpp.h+4−2
@@ -36,8 +36,8 @@ typedef struct token { · 35 unmodified lines
3636 unsigned char type;
3737 unsigned char flag;
3838 unsigned short hideset;
39− unsigned short wslen;
40− unsigned short len;
39+ unsigned int wslen;
40+ unsigned int len;
4141 uchar *t;
4242 } Token;
4343
@@ -134,6 +134,7 @@ int newhideset(int, Nlist *); · 90 unmodified lines
134134 int unionhideset(int, int);
135135 void iniths(void);
136136 void setobjname(char *);
137+void clearwstab(void);
137138 #define rowlen(tokrow) ((tokrow)->lp - (tokrow)->bp)
138139
139140 extern char *outp;
@@ -149,3 +150,4 @@ extern int verbose; · 9 unmodified lines
149150 extern int Cplusplus;
150151 extern Nlist *kwdefined;
151152 extern Includelist includelist[NINCLUDE];
153+extern char wd[];
sys/src/cmd/cpp/eval.c+2−2
@@ -112,7 +112,7 @@ eval(Tokenrow *trp, int kw) · 111 unmodified lines
112112 return 0;
113113 }
114114 np = lookup(trp->tp, 0);
115− return (kw==KIFDEF) == (np && np->flag&ISDEFINED);
115+ return (kw==KIFDEF) == (np && np->flag&(ISDEFINED|ISMAC));
116116 }
117117 ntok = trp->tp - trp->bp;
118118 kwdefined->val = KDEFINED; /* activate special meaning of defined */
@@ -398,7 +398,7 @@ tokval(Token *tp) · 279 unmodified lines
398398 break;
399399
400400 case NAME1:
401− if ((np = lookup(tp, 0)) && np->flag&ISDEFINED)
401+ if ((np = lookup(tp, 0)) && np->flag&(ISDEFINED|ISMAC))
402402 v.val = 1;
403403 break;
404404
sys/src/cmd/cpp/include.c+6−1
@@ -66,7 +66,7 @@ doinclude(Tokenrow *trp) · 65 unmodified lines
6666 write(1,"\n",1);
6767 }
6868 if (fd >= 0) {
69− if (++incdepth > 10)
69+ if (++incdepth > 20)
7070 error(FATAL, "#include too deeply nested");
7171 setsource((char*)newstring((uchar*)iname, strlen(iname), 0), fd, NULL);
7272 genline();
@@ -95,6 +95,11 @@ genline(void) · 22 unmodified lines
9595 p += sizeof("#line ")-1;
9696 p = (uchar*)outnum((char*)p, cursource->line);
9797 *p++ = ' '; *p++ = '"';
98+ if (cursource->filename[0]!='/' && wd[0]) {
99+ strcpy((char*)p, wd);
100+ p += strlen(wd);
101+ *p++ = '/';
102+ }
98103 strcpy((char*)p, cursource->filename);
99104 p += strlen((char*)p);
100105 *p++ = '"'; *p++ = '\n';
sys/src/cmd/cpp/lex.c+7−4
@@ -550,6 +550,9 @@ setsource(char *name, int fd, char *str) · 549 unmodified lines
550550 s->lineinc = 0;
551551 s->fd = fd;
552552 s->filename = name;
553+ s->next = cursource;
554+ s->ifdepth = 0;
555+ cursource = s;
553556 /* slop at right for EOB */
554557 if (str) {
555558 len = strlen(str);
@@ -557,15 +560,15 @@ setsource(char *name, int fd, char *str) · 1 unmodified line
557560 s->inp = s->inb;
558561 strncpy((char *)s->inp, str, len);
559562 } else {
560− s->inb = domalloc(INS+4);
563+ Dir d;
564+ if (dirfstat(fd, &d) < 0)
565+ d.length = 0;
566+ s->inb = domalloc((d.length<INS? INS: d.length)+4);
561567 s->inp = s->inb;
562568 len = 0;
563569 }
564570 s->inl = s->inp+len;
565571 s->inl[0] = s->inl[1] = EOB;
566− s->next = cursource;
567− s->ifdepth = 0;
568− cursource = s;
569572 return s;
570573 }
571574
sys/src/cmd/cpp/macro.c+1−1
@@ -72,7 +72,7 @@ dodefine(Tokenrow *trp) · 71 unmodified lines
7272 if (comparetokens(def, np->vp)
7373 || (np->ap==NULL) != (args==NULL)
7474 || np->ap && comparetokens(args, np->ap))
75− error(ERROR, "Macro redefinition of %t", tp);
75+ error(ERROR, "Macro redefinition of %t", trp->bp+2);
7676 }
7777 if (args) {
7878 Tokenrow *tap;
sys/src/cmd/cpp/nlist.c+7−0
@@ -10,6 +10,7 @@ int verbose; · 9 unmodified lines
1010 int Mflag;
1111 int Cplusplus;
1212 Nlist *kwdefined;
13+char wd[128];
1314
1415 #define NLSIZE 128
1516
@@ -84,6 +85,8 @@ setup(int argc, char **argv) · 68 unmodified lines
8485 includelist[1].file = NULL;
8586 error(WARNING, "Unknown $objtype");
8687 }
88+ if (getwd(wd, sizeof(wd))==0)
89+ wd[0] = '\0';
8790 includelist[0].file = "/sys/include";
8891 includelist[0].always = 1;
8992 setsource("", -1, 0);
@@ -121,6 +124,9 @@ setup(int argc, char **argv) · 31 unmodified lines
121124 case '+':
122125 Cplusplus++;
123126 break;
127+ case 'W':
128+ clearwstab();
129+ break;
124130 default:
125131 error(FATAL, "Unknown argument");
126132 break;
@@ -171,6 +177,7 @@ lookup(Token *tp, int install) · 44 unmodified lines
171177 }
172178 if (install) {
173179 np = new(Nlist);
180+ np->val = 0;
174181 np->vp = NULL;
175182 np->ap = NULL;
176183 np->flag = 0;
sys/src/cmd/cpp/tokens.c+22−3
@@ -73,11 +73,23 @@ static const char wstab[] = { · 72 unmodified lines
7373 0, /* UMINUS */
7474 };
7575
76+void
77+clearwstab(void)
78+{
79+ int i;
80+
81+ for (i = 0; i < sizeof(wstab); i++)
82+ wstab[i] = 0;
83+}
84+
7685 void
7786 maketokenrow(int size, Tokenrow *trp)
7887 {
7988 trp->max = size;
80− trp->bp = (Token *)domalloc(size*sizeof(Token));
89+ if (size>0)
90+ trp->bp = (Token *)domalloc(size*sizeof(Token));
91+ else
92+ trp->bp = NULL;
8193 trp->tp = trp->bp;
8294 trp->lp = trp->bp;
8395 }
@@ -300,8 +312,15 @@ puttokens(Tokenrow *trp) · 216 unmodified lines
300312 len += tp->wslen+tp->len;
301313 }
302314 if (Mflag==0) {
303− memcpy(wbp, p, len);
304− wbp += len;
315+ if (len>OBS/2) { /* handle giant token */
316+ if (wbp > wbuf)
317+ write(1, wbuf, wbp-wbuf);
318+ write(1, p, len);
319+ wbp = wbuf;
320+ } else {
321+ memcpy(wbp, p, len);
322+ wbp += len;
323+ }
305324 }
306325 if (wbp >= &wbuf[OBS]) {
307326 write(1, wbuf, OBS);