From 7d3a87ca1838d9a0983ab8532fc697cbca75a1d5 Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Thu, 6 Feb 2020 21:17:08 +0100 Subject: [PATCH] Remove duplicated code in macro expansion The code for macro existence checking and flag processing is exactly the same. --- rpmio/macro.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/rpmio/macro.c b/rpmio/macro.c index daf13896c..25c879c3c 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -1492,41 +1492,24 @@ expandMacro(MacroBuf mb, const char *src, size_t slen) } } - /* XXX Special processing for flags */ - if (*f == '-') { - if ((me == NULL && !negate) || /* Without -f, skip %{-f...} */ - (me != NULL && negate)) { /* With -f, skip %{!-f...} */ + /* XXX Special processing for flags and existance test */ + if (*f == '-' || chkexist) { + if ((me == NULL && !negate) || /* Without existance, skip %{?...} */ + (me != NULL && negate)) { /* With existance, skip %{!?...} */ s = se; continue; } - if (g && g < ge) { /* Expand X in %{-f:X} */ + if (g && g < ge) { /* Expand X in %{...:X} */ expandMacro(mb, g, gn); } else - if (me && me->body && *me->body) {/* Expand %{-f}/%{-f*} */ + if (me && me->body && *me->body) {/* Expand macro body */ expandMacro(mb, me->body, 0); } s = se; 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 */ /* XXX hack to permit non-overloaded %foo to be passed */ c = '%'; /* XXX only need to save % */