Skip to content

Commit

Permalink
Don't let macro '%-x' add extra space between flag and argument
Browse files Browse the repository at this point in the history
  • Loading branch information
rhabacker committed Mar 24, 2023
1 parent 6bf2211 commit b969a46
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions rpmio/macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -829,16 +829,23 @@ static void doDump(MacroBuf mb, rpmMacroEntry me, ARGV_t argv, size_t *parsed)
rpmDumpMacroTable(mb->mc, NULL);
}

typedef struct {
MacroBuf mb;
char **argv;
} MacroOptData;

static int mbopt(int c, const char *oarg, int oint, void *data)
static int mbopt(int c, const char *oarg, int oint, MacroOptData *data)
{
MacroBuf mb = data;
char *name = NULL, *body = NULL;
MacroBuf mb = data->mb;
char *name = NULL, *body = NULL, *fill = " ";

if (oint > 1 && data->argv[oint-1] && data->argv[oint-1][0] == '-') {
fill = "";
}
/* Define option macros. */
rasprintf(&name, "-%c", c);
if (oarg) {
rasprintf(&body, "-%c %s", c, oarg);
rasprintf(&body, "-%c%s%s", c, fill, oarg);
} else {
rasprintf(&body, "-%c", c);
}
Expand Down Expand Up @@ -887,8 +894,9 @@ setupArgs(MacroBuf mb, const rpmMacroEntry me, ARGV_t argv)
pushMacro(mb->mc, "**", NULL, args, mb->level, ME_AUTO | ME_LITERAL);
free(args);

MacroOptData data = { mb, argv };
argc = argvCount(argv);
ind = rgetopt(argc, argv, me->opts, mbopt, mb);
ind = rgetopt(argc, argv, me->opts, mbopt, &data);

if (ind < 0) {
mbErr(mb, 1, _("Unknown option %c in %s(%s)\n"), -ind,
Expand Down

0 comments on commit b969a46

Please sign in to comment.