scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 876c748841b7c52b69953dcd5b49016414a3aae4
parent b213e5a835707e8d347e804d9911c13526138f07
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 11 May 2015 10:11:04 +0200

Unify string and function arrays in preprocessor()

It is cleaner and shorter.

Diffstat:
cc1/cpp.c | 30++++++++++++------------------
1 file changed, 12 insertions(+), 18 deletions(-)

diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -137,20 +137,16 @@ preprocessor(char *p) { char *q; unsigned short n; - static char **bp, *cmds[] = { - "define", - "include", - "line", - "pragma", - "error", - NULL - }; - static char *(*funs[])(char *) = { - define, - include, - line, - pragma, - usererr + static struct { + char *name; + char *(*fun)(char *); + } *bp, cmds[] = { + "define", define, + "include", include, + "line", line, + "pragma", pragma, + "error", usererr, + NULL, NULL }; while (isspace(*p)) @@ -164,10 +160,8 @@ preprocessor(char *p) n = q - p; while (isspace(*q)) ++q; - for (bp = cmds; *bp; ++bp) { - if (strncmp(*bp, p, n)) - continue; - q = (*funs[bp - cmds])(q); + for (bp = cmds; bp->name && strncmp(bp->name, p, n); ++bp) { + q = (*bp->fun)(q); while (isspace(*q++)) /* nothing */; if (*q != '\0')