version 1.17, 2020/06/10 21:05:02 |
version 1.18, 2020/06/10 21:05:50 |
|
|
char c; |
char c; |
FILE *fp; |
FILE *fp; |
char buf[200], name[200], def[200]; |
char buf[200], name[200], def[200]; |
|
enum { TOK_UNKNOWN, TOK_ENUM, TOK_DEFINE } tokentype = TOK_UNKNOWN; |
|
|
printf("#include <stdio.h>\n"); |
printf("#include <stdio.h>\n"); |
printf("#include \"awk.h\"\n"); |
printf("#include \"awk.h\"\n"); |
|
|
i = 0; |
i = 0; |
while (fgets(buf, sizeof buf, fp) != NULL) { |
while (fgets(buf, sizeof buf, fp) != NULL) { |
// 199 is sizeof(def) - 1 |
// 199 is sizeof(def) - 1 |
n = sscanf(buf, "%1c %199s %199s %d", &c, def, name, &tok); |
if (tokentype != TOK_ENUM) { |
if (n != 4 || c != '#' || strcmp(def, "define") != 0) |
n = sscanf(buf, "%1c %199s %199s %d", &c, def, name, |
continue; /* not a valid #define */ |
&tok); |
if (strcmp(name, "YYSTYPE_IS_DECLARED") == 0) |
if (n == 4 && c == '#' && strcmp(def, "define") == 0) { |
|
tokentype = TOK_DEFINE; |
|
} else if (tokentype != TOK_UNKNOWN) { |
|
continue; |
|
} |
|
} |
|
if (tokentype != TOK_DEFINE) { |
|
/* not a valid #define, bison uses enums now */ |
|
n = sscanf(buf, "%199s = %d,\n", name, &tok); |
|
if (n != 2) |
|
continue; |
|
tokentype = TOK_ENUM; |
|
} |
|
if (strcmp(name, "YYSTYPE_IS_DECLARED") == 0) { |
|
tokentype = TOK_UNKNOWN; |
continue; |
continue; |
|
} |
if (tok < FIRSTTOKEN || tok > LASTTOKEN) { |
if (tok < FIRSTTOKEN || tok > LASTTOKEN) { |
|
tokentype = TOK_UNKNOWN; |
/* fprintf(stderr, "maketab: funny token %d %s ignored\n", tok, buf); */ |
/* fprintf(stderr, "maketab: funny token %d %s ignored\n", tok, buf); */ |
continue; |
continue; |
} |
} |