Special case the non-parametric and the free-field macro expansion

This makes the code easier to understand and also has the advantage
that "parsed" will be NULL for the normal cases.

No functual changes.
This commit is contained in:
Michael Schroeder 2021-10-25 10:41:12 +02:00 committed by Panu Matilainen
parent 243d01ff46
commit 374c0edac0
1 changed files with 24 additions and 16 deletions

View File

@ -1513,23 +1513,31 @@ expandMacro(MacroBuf mb, const char *src, size_t slen)
continue; continue;
} }
/* Grab args for parametric macros */ if (me->opts == NULL) {
/* Simple non-parametric macro */
doMacro(mb, me, NULL, NULL);
s = se;
continue;
}
ARGV_t args = NULL; ARGV_t args = NULL;
size_t fwd = 0;
if (me->opts != NULL) {
argvAdd(&args, me->name); argvAdd(&args, me->name);
if (g) { if ((me->flags & ME_PARSE) != 0 && fe == se) {
grabArgs(mb, me, &args, g, ge, 0); /* Special free-field macros define/global/dnl */
} else if (me->flags & ME_PARSE) { size_t fwd = 0;
argvAdd(&args, se); argvAdd(&args, se);
} else if (lastc) {
fwd = (grabArgs(mb, me, &args, fe, lastc, 1) - se);
}
}
doMacro(mb, me, args, &fwd); doMacro(mb, me, args, &fwd);
if (args != NULL) se += fwd;
} else {
/* Grab args for parametric macros */
if (g)
se = grabArgs(mb, me, &args, g, ge, 0);
else if (lastc)
se = grabArgs(mb, me, &args, fe, lastc, 1);
doMacro(mb, me, args, NULL);
}
argvFree(args); argvFree(args);
s = se + (g ? 0 : fwd); s = se;
} }
mbFini(mb, me, &med); mbFini(mb, me, &med);