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