mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 1/3] hush getopt: shift argv arguments
Date: Thu,  5 Jul 2012 09:18:38 +0200	[thread overview]
Message-ID: <1341472720-3248-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1341472720-3248-1-git-send-email-s.hauer@pengutronix.de>

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>
---
 common/hush.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/common/hush.c b/common/hush.c
index 3ac1d10..8200931 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,
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2012-07-05  7:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-05  7:18 [PATCH] defenv-2 updates Sascha Hauer
2012-07-05  7:18 ` Sascha Hauer [this message]
2012-07-05  7:18 ` [PATCH 2/3] defenv-2: Add usage information for bootargs scripts Sascha Hauer
2012-07-05  7:22   ` Eric Bénard
2012-07-05  7:35     ` Sascha Hauer
2012-07-05  7:18 ` [PATCH 3/3] defenv-2: improve boot script Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1341472720-3248-2-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox