From c072ef6bb8cd8ad5bb02263a44f1cc0aa51d72a2 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 22 Jan 2021 12:40:36 +0200 Subject: [PATCH] Let %define and %global take name and body as separate arguments doDefine() wants macro file-style "name body" string as an argument, but when called through rpmExpandThisMacro() you'd expect to put the name and body in separate arguments. Properly handling this in the macro engine guts is more than I'm prepared to do at the moment, but we can detect the multiple arguments case and turn the arguments into something that doDefine groks. This will matter when we add support for calling macros as native Lua elements. --- rpmio/macro.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/rpmio/macro.c b/rpmio/macro.c index 1e5df89c4..7993e9e5d 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -762,16 +762,29 @@ doUndefine(MacroBuf mb, rpmMacroEntry me, ARGV_t argv) return 0; } +static size_t doArgvDefine(MacroBuf mb, ARGV_t argv, int level, int expand) +{ + char *args = NULL; + size_t ret; + const char *se = argv[1]; + + /* handle the "programmatic" case where macro name is arg1 and body arg2 */ + if (argv[2]) + se = args = rstrscat(NULL, argv[1], " ", argv[2], NULL); + + ret = doDefine(mb, se, level, expand); + free(args); + return ret; +} + static size_t doDef(MacroBuf mb, rpmMacroEntry me, ARGV_t argv) { - const char *se = argv[1]; - return doDefine(mb, se, mb->level, 0); + return doArgvDefine(mb, argv, mb->level, 0); } static size_t doGlobal(MacroBuf mb, rpmMacroEntry me, ARGV_t argv) { - const char *se = argv[1]; - return doDefine(mb, se, RMIL_GLOBAL, 1); + return doArgvDefine(mb, argv, RMIL_GLOBAL, 1); } static size_t doDump(MacroBuf mb, rpmMacroEntry me, ARGV_t argv)