10 if(c < '0' || c > '9')
13 while(c >= '0' && c <= '9') {
30 if(cp <= symb+NSYMB-UTFmax)
38 if(cp <= symb+NSYMB-UTFmax)
41 if(c >= Runeself || isalnum(c) || c == '_')
47 if(cp > symb+NSYMB-UTFmax)
48 yyerror("symbol too large: %s", symb);
57 if(c < Runeself && !isalpha(c) && c != '_') {
80 if(getc() != '.' || getc() != '.')
81 yyerror("bad dots in macro");
83 return slookup("__VA_ARGS__");
113 yyerror("comment across newline");
132 p = strchr(symb, '=');
136 l = strlen(p) + 2; /* +1 null, +1 nargs */
148 s->macro = "\0001"; /* \000 is nargs */
151 print("#define (-D) %s %s\n", s->name, s->macro+1);
160 "ifdef", 0, /* macif(0) */
161 "ifndef", 0, /* macif(1) */
162 "else", 0, /* macif(2) */
182 s = slookup("endif");
183 for(i=0; mactab[i].macname; i++)
184 if(strcmp(s->name, mactab[i].macname) == 0) {
191 yyerror("unknown #: %s", s->name);
203 yyerror("syntax in #undef");
214 char *args[NARG], *base;
215 int n, i, c, len, dots;
222 yyerror("macro redefined: %s", s->name);
232 a = getsymdots(&dots);
236 yyerror("too many arguments in #define: %s", s->name);
256 if(c >= Runeself || isalpha(c) || c == '_') {
260 if(strcmp(symb, args[i]) == 0)
264 base = allocn(base, len, i);
265 memcpy(base+len, symb, i);
269 base = allocn(base, len, 2);
271 base[len++] = 'a' + i;
276 base = allocn(base, len, 1);
282 if(c == '"' || c == '\''){
283 base = allocn(base, len, 1);
311 yyerror("comment and newline in define: %s", s->name);
318 base = allocn(base, len, 1);
336 base = allocn(base, len, 1);
344 base = allocn(base, len, 1);
347 base = allocn(base, len, 1);
349 c = ((--fi.c < 0)? filbuf(): (*fi.p++ & 0xff));
353 yyerror("eof in a macro: %s", s->name);
358 base = allocn(base, len, 1);
367 print("#define %s %s\n", s->name, s->macro+1);
372 yyerror("syntax in #define");
374 yyerror("syntax in #define: %s", s->name);
379 macexpand(Sym *s, char *b)
383 char *arg[NARG], *cp, *ob, *ecp, dots;
387 strcpy(b, s->macro+1);
389 print("#expand %s %s\n", s->name, ob);
393 nargs = (char)(*s->macro & ~VARMAC) - 1;
394 dots = *s->macro & VARMAC;
405 ecp = cp + sizeof(buf)-UTFmax;
458 while((c = getc()) != '\n')
468 if(n == nargs && dots) {
492 yyerror("argument mismatch expanding: %s", s->name);
522 print("#expand %s %s\n", s->name, ob);
526 yyerror("syntax in macro expansion: %s", s->name);
531 yyerror("too much text in macro expansion: %s", s->name);
539 char str[STRINGSZ], *hp;
563 for(i=0; i<ninclude; i++) {
564 if(i == 0 && c0 == '>')
566 strcpy(symb, include[i]);
568 if(strcmp(symb, "./") == 0)
577 c = strlen(symb) + 1;
583 memcpy(hunk, symb, c);
593 yyerror("syntax in #include");
610 if(c == ' ' || c == '\t') {
617 strcpy(symb, "<noname>");
635 c = strlen(symb) + 1;
641 memcpy(hunk, symb, c);
649 yyerror("syntax in #line");
666 if((s->macro != 0) ^ f)
686 if(strcmp(s->name, "endif") == 0) {
694 if(strcmp(s->name, "ifdef") == 0 || strcmp(s->name, "ifndef") == 0) {
698 if(l == 0 && f != 2 && strcmp(s->name, "else") == 0) {
705 yyerror("syntax in #if(n)def");
719 if(s && strcmp(s->name, "lib") == 0)
721 if(s && strcmp(s->name, "pack") == 0) {
725 if(s && strcmp(s->name, "fpround") == 0) {
729 if(s && strcmp(s->name, "profile") == 0) {
733 if(s && strcmp(s->name, "varargck") == 0) {
737 if(s && strcmp(s->name, "incomplete") == 0) {
741 while(getnsc() != '\n')
767 * put pragma-line in as a funny history
769 c = strlen(symb) + 1;
775 memcpy(hunk, symb, c);
779 h = alloc(sizeof(Hist));
795 yyerror("syntax in #pragma lib");
806 if(c < 0 || c == '\n')
812 linehist(char *f, int offset)
817 * overwrite the last #line directive if
818 * no alloc has happened since the last one
820 if(newflag == 0 && ehist != H && offset != 0 && ehist->offset != 0)
821 if(f && ehist->name && strcmp(f, ehist->name) == 0) {
822 ehist->line = lineno;
823 ehist->offset = offset;
830 print("%4ld: %s (#line %d)\n", lineno, f, offset);
832 print("%4ld: %s\n", lineno, f);
834 print("%4ld: <pop>\n", lineno);
837 h = alloc(sizeof(Hist));