From 1f88268f898a2e1cebe137c75ca031d5b44e30e2 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Fri, 24 Mar 2023 16:21:13 +0100 Subject: [PATCH] Add macro '%-x**' containing all occurrences of the flag '-x' or '-x '. Flags are added to this macro with the flag and argument in the original notation and separated from previous by spaces. Fix #546 --- docs/manual/macros.md | 3 ++- rpmio/macro.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/manual/macros.md b/docs/manual/macros.md index c0e5e799c7..9112841cbb 100644 --- a/docs/manual/macros.md +++ b/docs/manual/macros.md @@ -39,7 +39,8 @@ macros are available: %** all arguments (including any processed flags) %# the number of arguments %{-f} if present at invocation, the flag f itself (including the argument) - %{-f*} if present at invocation, the argument to flag f + %{-f*} if present at invocation, the argument to the last occurence of flag f + %{-f**} if present at invocation, all occurrences of flag f (flag and argument, space separated) (rpm >= 4.18) %1, %2 the arguments themselves (after getopt(3) processing) ``` diff --git a/rpmio/macro.c b/rpmio/macro.c index b78aee955b..187e5cf0f1 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -859,6 +859,21 @@ static int mbopt(int c, const char *oarg, int oint, void *data) pushMacro(mb->mc, name, NULL, oarg, mb->level, ME_AUTO | ME_LITERAL); free(name); } + + rasprintf(&name, "-%c**", c); + rpmMacroEntry *mep = findEntry(mb->mc, name, 0, NULL); + if (mep && oarg) + rasprintf(&body, "%s -%c%s%s", (*mep)->body, c, fill, oarg); + else if (mep) + rasprintf(&body, "%s -%c", (*mep)->body, c); + else if (oarg) + rasprintf(&body, "-%c%s%s", c, fill, oarg); + else + rasprintf(&body, "-%c", c); + pushMacro(mb->mc, name, NULL, body, mb->level, ME_AUTO | ME_LITERAL); + free(name); + free(body); + return 0; }