10 if(c < '0' || c > '9')
13 while(c >= '0' && c <= '9') {
28 if(!isalpha(c) && c != '_' && c < Runeself) {
33 if(cp <= symb+NSYMB-4)
36 if(isalnum(c) || c == '_' || c >= Runeself)
43 yyerror("symbol too large: %s", symb);
62 if(getc() != '.' || getc() != '.')
63 yyerror("bad dots in macro");
65 return slookup("__VA_ARGS__");
95 yyerror("comment across newline");
114 p = strchr(symb, '=');
118 l = strlen(p) + 2; /* +1 null, +1 nargs */
130 s->macro = "\0001"; /* \000 is nargs */
133 print("#define (-D) %s %s\n", s->name, s->macro+1);
142 "ifdef", 0, /* macif(0) */
143 "ifndef", 0, /* macif(1) */
144 "else", 0, /* macif(2) */
164 s = slookup("endif");
165 for(i=0; mactab[i].macname; i++)
166 if(strcmp(s->name, mactab[i].macname) == 0) {
173 yyerror("unknown #: %s", s->name);
185 yyerror("syntax in #undef");
196 char *args[NARG], *np, *base;
197 int n, i, c, len, dots;
204 yyerror("macro redefined: %s", s->name);
214 a = getsymdots(&dots);
218 yyerror("too many arguments in #define: %s", s->name);
238 if(isalpha(c) || c == '_') {
242 while(isalnum(c) || c == '_') {
248 if(strcmp(symb, args[i]) == 0)
252 base = allocn(base, len, i);
253 memcpy(base+len, symb, i);
257 base = allocn(base, len, 2);
259 base[len++] = 'a' + i;
264 base = allocn(base, len, 1);
270 if(c == '"' || c == '\''){
271 base = allocn(base, len, 1);
299 yyerror("comment and newline in define: %s", s->name);
306 base = allocn(base, len, 1);
324 base = allocn(base, len, 1);
332 base = allocn(base, len, 1);
335 base = allocn(base, len, 1);
337 c = ((--fi.c < 0)? filbuf(): (*fi.p++ & 0xff));
341 yyerror("eof in a macro: %s", s->name);
346 base = allocn(base, len, 1);
355 print("#define %s %s\n", s->name, s->macro+1);
360 yyerror("syntax in #define");
362 yyerror("syntax in #define: %s", s->name);
367 macexpand(Sym *s, char *b)
371 char *arg[NARG], *cp, *ob, *ecp, dots;
375 strcpy(b, s->macro+1);
377 print("#expand %s %s\n", s->name, ob);
381 nargs = (char)(*s->macro & ~VARMAC) - 1;
382 dots = *s->macro & VARMAC;
393 ecp = cp + sizeof(buf)-4;
446 while((c = getc()) != '\n')
456 if(n == nargs && dots) {
480 yyerror("argument mismatch expanding: %s", s->name);
510 print("#expand %s %s\n", s->name, ob);
514 yyerror("syntax in macro expansion: %s", s->name);
519 yyerror("too much text in macro expansion: %s", s->name);
527 char str[STRINGSZ], *hp;
551 for(i=0; i<ninclude; i++) {
552 if(i == 0 && c0 == '>')
554 strcpy(symb, include[i]);
556 if(strcmp(symb, "./") == 0)
565 c = strlen(symb) + 1;
571 memcpy(hunk, symb, c);
581 yyerror("syntax in #include");
598 if(c == ' ' || c == '\t') {
605 strcpy(symb, "<noname>");
623 c = strlen(symb) + 1;
629 memcpy(hunk, symb, c);
637 yyerror("syntax in #line");
654 if((s->macro != 0) ^ f)
674 if(strcmp(s->name, "endif") == 0) {
682 if(strcmp(s->name, "ifdef") == 0 || strcmp(s->name, "ifndef") == 0) {
686 if(l == 0 && f != 2 && strcmp(s->name, "else") == 0) {
693 yyerror("syntax in #if(n)def");
707 if(s && strcmp(s->name, "lib") == 0)
709 if(s && strcmp(s->name, "pack") == 0) {
713 if(s && strcmp(s->name, "fpround") == 0) {
717 if(s && strcmp(s->name, "profile") == 0) {
721 if(s && strcmp(s->name, "varargck") == 0) {
725 if(s && strcmp(s->name, "incomplete") == 0) {
729 while(getnsc() != '\n')
755 * put pragma-line in as a funny history
757 c = strlen(symb) + 1;
763 memcpy(hunk, symb, c);
767 h = alloc(sizeof(Hist));
783 yyerror("syntax in #pragma lib");
794 if(c < 0 || c == '\n')
800 linehist(char *f, int offset)
805 * overwrite the last #line directive if
806 * no alloc has happened since the last one
808 if(newflag == 0 && ehist != H && offset != 0 && ehist->offset != 0)
809 if(f && ehist->name && strcmp(f, ehist->name) == 0) {
810 ehist->line = lineno;
811 ehist->offset = offset;
818 print("%4ld: %s (#line %d)\n", lineno, f, offset);
820 print("%4ld: %s\n", lineno, f);
822 print("%4ld: <pop>\n", lineno);
825 h = alloc(sizeof(Hist));
846 if(thunk >= 10L*NHUNK)
848 h = (char*)mysbrk(nh);
850 yyerror("out of memory");