Remove duplicated code in macro expansion

The code for macro existence checking and flag processing
is exactly the same.
This commit is contained in:
Michael Schroeder 2020-02-06 21:17:08 +01:00 committed by Panu Matilainen
parent abcb0af241
commit 7d3a87ca18
1 changed files with 6 additions and 23 deletions

View File

@ -1492,41 +1492,24 @@ expandMacro(MacroBuf mb, const char *src, size_t slen)
} }
} }
/* XXX Special processing for flags */ /* XXX Special processing for flags and existance test */
if (*f == '-') { if (*f == '-' || chkexist) {
if ((me == NULL && !negate) || /* Without -f, skip %{-f...} */ if ((me == NULL && !negate) || /* Without existance, skip %{?...} */
(me != NULL && negate)) { /* With -f, skip %{!-f...} */ (me != NULL && negate)) { /* With existance, skip %{!?...} */
s = se; s = se;
continue; continue;
} }
if (g && g < ge) { /* Expand X in %{-f:X} */ if (g && g < ge) { /* Expand X in %{...:X} */
expandMacro(mb, g, gn); expandMacro(mb, g, gn);
} else } else
if (me && me->body && *me->body) {/* Expand %{-f}/%{-f*} */ if (me && me->body && *me->body) {/* Expand macro body */
expandMacro(mb, me->body, 0); expandMacro(mb, me->body, 0);
} }
s = se; s = se;
continue; continue;
} }
/* XXX Special processing for macro existence */
if (chkexist) {
if ((me == NULL && !negate) || /* Without -f, skip %{?f...} */
(me != NULL && negate)) { /* With -f, skip %{!?f...} */
s = se;
continue;
}
if (g && g < ge) { /* Expand X in %{?f:X} */
expandMacro(mb, g, gn);
} else
if (me && me->body && *me->body) { /* Expand %{?f}/%{?f*} */
expandMacro(mb, me->body, 0);
}
s = se;
continue;
}
if (me == NULL) { /* leave unknown %... as is */ if (me == NULL) { /* leave unknown %... as is */
/* XXX hack to permit non-overloaded %foo to be passed */ /* XXX hack to permit non-overloaded %foo to be passed */
c = '%'; /* XXX only need to save % */ c = '%'; /* XXX only need to save % */