summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2012-07-04 23:39:03 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2012-07-04 23:39:05 +0200
commit1d3ab47e13a7d16db43c2b6b19e85115681e23c9 (patch)
tree42e58bda63bb871ced6e14b0c2d2cf15b2043751
parentc6e82ee5437618cf09c0955839b4a2b1b167cc4a (diff)
downloadbarebox-1d3ab47e13a7d16db43c2b6b19e85115681e23c9.tar.gz
barebox-1d3ab47e13a7d16db43c2b6b19e85115681e23c9.tar.xz
hush getopt: shift argv arguments
Make the nonopt arguments to a script available starting from $1 after running getopt. This allows for scripts which use option parsing but also have nonopts. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--common/hush.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/common/hush.c b/common/hush.c
index 3ac1d10195..8200931387 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -521,6 +521,8 @@ static int builtin_getopt(struct p_context *ctx, struct child_prog *child,
o->optarg = xstrdup(optarg);
list_add_tail(&o->list, &ctx->options);
}
+ ctx->global_argv += optind - 1;
+ ctx->global_argc -= optind - 1;
}
ctx->options_parsed = 1;
@@ -1899,7 +1901,8 @@ static const __maybe_unused char cmd_getopt_help[] =
"hush option parser. <optstring> is a string with valid options. Add\n"
"a colon to an options if this option has a required argument or two\n"
"colons for an optional argument. The current option is saved in <var>,\n"
-"arguments are saved in OPTARG.\n";
+"arguments are saved in OPTARG. After this command additional nonopts\n"
+"can be accessed starting from $1\n";
BAREBOX_CMD_START(getopt)
.cmd = do_getopt,