ref: 876c748841b7c52b69953dcd5b49016414a3aae4
parent: b213e5a835707e8d347e804d9911c13526138f07
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon May 11 06:11:04 EDT 2015
Unify string and function arrays in preprocessor() It is cleaner and shorter.
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -137,21 +137,17 @@
{
char *q;
unsigned short n;
- static char **bp, *cmds[] = {
- "define",
- "include",
- "line",
- "pragma",
- "error",
- NULL
+ static struct {
+ char *name;
+ char *(*fun)(char *);
+ } *bp, cmds[] = {
+ "define", define,
+ "include", include,
+ "line", line,
+ "pragma", pragma,
+ "error", usererr,
+ NULL, NULL
};
- static char *(*funs[])(char *) = {
- define,
- include,
- line,
- pragma,
- usererr
- };
while (isspace(*p))
++p;
@@ -164,10 +160,8 @@
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')