From 70624fd2ab0e580b7a34e0e9f3a83fc0d59b53c4 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Mon, 23 May 2011 17:11:28 -0500 Subject: [PATCH] cmd: Fix parsing positional args If the first parameter of a libcmd syntax is a flag, cmd_Parse was skipping over positional arguments, since j will be 0 at this point (the j variable is only used if we're processing an explicit switch). Effectively revert this area to what it was before a2f1ca5fd52ac2fb7e68b101bbe3da9878c10474 so such positional parameters work again. Also move the j variable to inside the only block in which it is used, to try and avoid such mistakes in the future. Change-Id: Ifa52cecf50a3f561c70de351a9ebd026e90eeeab Reviewed-on: http://gerrit.openafs.org/4711 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/cmd/cmd.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cmd/cmd.c b/src/cmd/cmd.c index 3b97102..764b95c 100644 --- a/src/cmd/cmd.c +++ b/src/cmd/cmd.c @@ -792,7 +792,6 @@ cmd_Parse(int argc, char **argv, struct cmd_syndesc **outsyntax) struct cmd_syndesc *ts = NULL; struct cmd_parmdesc *tparm; int i; - int j = 0; int curType; int positional; int ambig; @@ -917,6 +916,7 @@ cmd_Parse(int argc, char **argv, struct cmd_syndesc **outsyntax) * are considered switches. This allow negative numbers. */ if ((argv[i][0] == '-') && !isdigit(argv[i][1])) { + int j; /* Find switch */ if (strrchr(argv[i], '=') != NULL) { @@ -989,10 +989,17 @@ cmd_Parse(int argc, char **argv, struct cmd_syndesc **outsyntax) continue; } - if (ts->parms[j].type != CMD_FLAG) { - code = AddItem(tparm, argv[i], pname); - if (code) + if (tparm->type == CMD_SINGLE || + tparm->type == CMD_SINGLE_OR_FLAG) { + if (tparm->items) { + fprintf(stderr, "%sToo many values after switch %s\n", + NName(pname, ": "), tparm->name); + code = CMD_NOTLIST; goto out; + } + AddItem(tparm, argv[i], pname); /* Add to end of list */ + } else if (tparm->type == CMD_LIST) { + AddItem(tparm, argv[i], pname); /* Add to end of list */ } /* Now, if we're in positional mode, advance to the next item */ -- 1.9.4