Showing the changes to sys/src/cmd/cpp (8 of 11749 files). Show all
Unified · Split
| @@ -16,7 +16,7 @@ int ifdepth; · 15 unmodified lines | ||
| 16 | 16 | int ifsatisfied[NIF]; |
| 17 | 17 | int skipping; |
| 18 | 18 | |
| 19 | −void | |
| 19 | +int | |
| 20 | 20 | main(int argc, char **argv) |
| 21 | 21 | { |
| 22 | 22 | Tokenrow tr; |
| @@ -36,6 +36,7 @@ main(int argc, char **argv) · 13 unmodified lines | ||
| 36 | 36 | flushout(); |
| 37 | 37 | fflush(stderr); |
| 38 | 38 | exits(nerrs? "errors" : 0); |
| 39 | + return 0; | |
| 39 | 40 | } |
| 40 | 41 | |
| 41 | 42 | void |
| @@ -266,12 +267,13 @@ error(enum errtype type, char *string, ...) · 224 unmodified lines | ||
| 266 | 267 | char *cp, *ep; |
| 267 | 268 | Token *tp; |
| 268 | 269 | Tokenrow *trp; |
| 270 | + Source *s; | |
| 269 | 271 | int i; |
| 270 | 272 | |
| 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); | |
| 275 | 277 | va_start(ap, string); |
| 276 | 278 | for (ep=string; *ep; ep++) { |
| 277 | 279 | if (*ep=='%') { |
| @@ -36,8 +36,8 @@ typedef struct token { · 35 unmodified lines | ||
| 36 | 36 | unsigned char type; |
| 37 | 37 | unsigned char flag; |
| 38 | 38 | unsigned short hideset; |
| 39 | − unsigned short wslen; | |
| 40 | − unsigned short len; | |
| 39 | + unsigned int wslen; | |
| 40 | + unsigned int len; | |
| 41 | 41 | uchar *t; |
| 42 | 42 | } Token; |
| 43 | 43 | |
| @@ -134,6 +134,7 @@ int newhideset(int, Nlist *); · 90 unmodified lines | ||
| 134 | 134 | int unionhideset(int, int); |
| 135 | 135 | void iniths(void); |
| 136 | 136 | void setobjname(char *); |
| 137 | +void clearwstab(void); | |
| 137 | 138 | #define rowlen(tokrow) ((tokrow)->lp - (tokrow)->bp) |
| 138 | 139 | |
| 139 | 140 | extern char *outp; |
| @@ -149,3 +150,4 @@ extern int verbose; · 9 unmodified lines | ||
| 149 | 150 | extern int Cplusplus; |
| 150 | 151 | extern Nlist *kwdefined; |
| 151 | 152 | extern Includelist includelist[NINCLUDE]; |
| 153 | +extern char wd[]; | |
| @@ -112,7 +112,7 @@ eval(Tokenrow *trp, int kw) · 111 unmodified lines | ||
| 112 | 112 | return 0; |
| 113 | 113 | } |
| 114 | 114 | np = lookup(trp->tp, 0); |
| 115 | − return (kw==KIFDEF) == (np && np->flag&ISDEFINED); | |
| 115 | + return (kw==KIFDEF) == (np && np->flag&(ISDEFINED|ISMAC)); | |
| 116 | 116 | } |
| 117 | 117 | ntok = trp->tp - trp->bp; |
| 118 | 118 | kwdefined->val = KDEFINED; /* activate special meaning of defined */ |
| @@ -398,7 +398,7 @@ tokval(Token *tp) · 279 unmodified lines | ||
| 398 | 398 | break; |
| 399 | 399 | |
| 400 | 400 | case NAME1: |
| 401 | − if ((np = lookup(tp, 0)) && np->flag&ISDEFINED) | |
| 401 | + if ((np = lookup(tp, 0)) && np->flag&(ISDEFINED|ISMAC)) | |
| 402 | 402 | v.val = 1; |
| 403 | 403 | break; |
| 404 | 404 | |
| @@ -66,7 +66,7 @@ doinclude(Tokenrow *trp) · 65 unmodified lines | ||
| 66 | 66 | write(1,"\n",1); |
| 67 | 67 | } |
| 68 | 68 | if (fd >= 0) { |
| 69 | − if (++incdepth > 10) | |
| 69 | + if (++incdepth > 20) | |
| 70 | 70 | error(FATAL, "#include too deeply nested"); |
| 71 | 71 | setsource((char*)newstring((uchar*)iname, strlen(iname), 0), fd, NULL); |
| 72 | 72 | genline(); |
| @@ -95,6 +95,11 @@ genline(void) · 22 unmodified lines | ||
| 95 | 95 | p += sizeof("#line ")-1; |
| 96 | 96 | p = (uchar*)outnum((char*)p, cursource->line); |
| 97 | 97 | *p++ = ' '; *p++ = '"'; |
| 98 | + if (cursource->filename[0]!='/' && wd[0]) { | |
| 99 | + strcpy((char*)p, wd); | |
| 100 | + p += strlen(wd); | |
| 101 | + *p++ = '/'; | |
| 102 | + } | |
| 98 | 103 | strcpy((char*)p, cursource->filename); |
| 99 | 104 | p += strlen((char*)p); |
| 100 | 105 | *p++ = '"'; *p++ = '\n'; |
| @@ -550,6 +550,9 @@ setsource(char *name, int fd, char *str) · 549 unmodified lines | ||
| 550 | 550 | s->lineinc = 0; |
| 551 | 551 | s->fd = fd; |
| 552 | 552 | s->filename = name; |
| 553 | + s->next = cursource; | |
| 554 | + s->ifdepth = 0; | |
| 555 | + cursource = s; | |
| 553 | 556 | /* slop at right for EOB */ |
| 554 | 557 | if (str) { |
| 555 | 558 | len = strlen(str); |
| @@ -557,15 +560,15 @@ setsource(char *name, int fd, char *str) · 1 unmodified line | ||
| 557 | 560 | s->inp = s->inb; |
| 558 | 561 | strncpy((char *)s->inp, str, len); |
| 559 | 562 | } 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); | |
| 561 | 567 | s->inp = s->inb; |
| 562 | 568 | len = 0; |
| 563 | 569 | } |
| 564 | 570 | s->inl = s->inp+len; |
| 565 | 571 | s->inl[0] = s->inl[1] = EOB; |
| 566 | − s->next = cursource; | |
| 567 | − s->ifdepth = 0; | |
| 568 | − cursource = s; | |
| 569 | 572 | return s; |
| 570 | 573 | } |
| 571 | 574 | |
| @@ -72,7 +72,7 @@ dodefine(Tokenrow *trp) · 71 unmodified lines | ||
| 72 | 72 | if (comparetokens(def, np->vp) |
| 73 | 73 | || (np->ap==NULL) != (args==NULL) |
| 74 | 74 | || np->ap && comparetokens(args, np->ap)) |
| 75 | − error(ERROR, "Macro redefinition of %t", tp); | |
| 75 | + error(ERROR, "Macro redefinition of %t", trp->bp+2); | |
| 76 | 76 | } |
| 77 | 77 | if (args) { |
| 78 | 78 | Tokenrow *tap; |
| @@ -10,6 +10,7 @@ int verbose; · 9 unmodified lines | ||
| 10 | 10 | int Mflag; |
| 11 | 11 | int Cplusplus; |
| 12 | 12 | Nlist *kwdefined; |
| 13 | +char wd[128]; | |
| 13 | 14 | |
| 14 | 15 | #define NLSIZE 128 |
| 15 | 16 | |
| @@ -84,6 +85,8 @@ setup(int argc, char **argv) · 68 unmodified lines | ||
| 84 | 85 | includelist[1].file = NULL; |
| 85 | 86 | error(WARNING, "Unknown $objtype"); |
| 86 | 87 | } |
| 88 | + if (getwd(wd, sizeof(wd))==0) | |
| 89 | + wd[0] = '\0'; | |
| 87 | 90 | includelist[0].file = "/sys/include"; |
| 88 | 91 | includelist[0].always = 1; |
| 89 | 92 | setsource("", -1, 0); |
| @@ -121,6 +124,9 @@ setup(int argc, char **argv) · 31 unmodified lines | ||
| 121 | 124 | case '+': |
| 122 | 125 | Cplusplus++; |
| 123 | 126 | break; |
| 127 | + case 'W': | |
| 128 | + clearwstab(); | |
| 129 | + break; | |
| 124 | 130 | default: |
| 125 | 131 | error(FATAL, "Unknown argument"); |
| 126 | 132 | break; |
| @@ -171,6 +177,7 @@ lookup(Token *tp, int install) · 44 unmodified lines | ||
| 171 | 177 | } |
| 172 | 178 | if (install) { |
| 173 | 179 | np = new(Nlist); |
| 180 | + np->val = 0; | |
| 174 | 181 | np->vp = NULL; |
| 175 | 182 | np->ap = NULL; |
| 176 | 183 | np->flag = 0; |
| @@ -73,11 +73,23 @@ static const char wstab[] = { · 72 unmodified lines | ||
| 73 | 73 | 0, /* UMINUS */ |
| 74 | 74 | }; |
| 75 | 75 | |
| 76 | +void | |
| 77 | +clearwstab(void) | |
| 78 | +{ | |
| 79 | + int i; | |
| 80 | + | |
| 81 | + for (i = 0; i < sizeof(wstab); i++) | |
| 82 | + wstab[i] = 0; | |
| 83 | +} | |
| 84 | + | |
| 76 | 85 | void |
| 77 | 86 | maketokenrow(int size, Tokenrow *trp) |
| 78 | 87 | { |
| 79 | 88 | 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; | |
| 81 | 93 | trp->tp = trp->bp; |
| 82 | 94 | trp->lp = trp->bp; |
| 83 | 95 | } |
| @@ -300,8 +312,15 @@ puttokens(Tokenrow *trp) · 216 unmodified lines | ||
| 300 | 312 | len += tp->wslen+tp->len; |
| 301 | 313 | } |
| 302 | 314 | 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 | + } | |
| 305 | 324 | } |
| 306 | 325 | if (wbp >= &wbuf[OBS]) { |
| 307 | 326 | write(1, wbuf, OBS); |