From: Andreas Fenkart <afenkart@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 6/7] tools: env: factor out parse_common_args
Date: Thu, 26 Nov 2015 11:52:33 +0100 [thread overview]
Message-ID: <1448535154-6350-7-git-send-email-andreas.fenkart@dev.digitalstrom.org> (raw)
In-Reply-To: <1448535154-6350-1-git-send-email-andreas.fenkart@dev.digitalstrom.org>
Signed-off-by: Andreas Fenkart <andreas.fenkart@dev.digitalstrom.org>
---
tools/env/fw_env_main.c | 63 +++++++++++++++++++++++++++++--------------------
1 file changed, 38 insertions(+), 25 deletions(-)
diff --git a/tools/env/fw_env_main.c b/tools/env/fw_env_main.c
index daf4688..e7ba95e 100644
--- a/tools/env/fw_env_main.c
+++ b/tools/env/fw_env_main.c
@@ -81,7 +81,7 @@ void usage(void)
);
}
-int parse_printenv_args(int argc, char *argv[])
+static void parse_common_args(int argc, char *argv[])
{
int c;
@@ -89,27 +89,53 @@ int parse_printenv_args(int argc, char *argv[])
common_args.config_file = CONFIG_FILE;
#endif
- while ((c = getopt_long (argc, argv, "a:c:ns:h",
- long_options, NULL)) != EOF) {
+ while ((c = getopt_long(argc, argv, ":a:c:h", long_options, NULL)) !=
+ EOF) {
switch (c) {
case 'a':
if (parse_aes_key(optarg, common_args.aes_key)) {
fprintf(stderr, "AES key parse error\n");
- return EXIT_FAILURE;
+ exit(EXIT_FAILURE);
}
common_args.aes_flag = 1;
break;
#ifdef CONFIG_FILE
case 'c':
+ printf("config file\n");
common_args.config_file = optarg;
break;
#endif
+ case 'h':
+ usage();
+ exit(EXIT_SUCCESS);
+ break;
+ default:
+ /* ignore unknown options */
+ break;
+ }
+ }
+
+ /* Reset getopt for the next pass. */
+ opterr = 1;
+ optind = 1;
+}
+
+int parse_printenv_args(int argc, char *argv[])
+{
+ int c;
+
+ parse_common_args(argc, argv);
+
+ while ((c = getopt_long(argc, argv, "a:c:ns:h", long_options, NULL)) !=
+ EOF) {
+ switch (c) {
case 'n':
printenv_args.name_suppress = 1;
break;
+ case 'a':
+ case 'c':
case 'h':
- usage();
- exit(EXIT_SUCCESS);
+ /* ignore common options */
break;
default: /* '?' */
usage();
@@ -124,31 +150,18 @@ int parse_setenv_args(int argc, char *argv[])
{
int c;
-#ifdef CONFIG_FILE
- common_args.config_file = CONFIG_FILE;
-#endif
+ parse_common_args(argc, argv);
- while ((c = getopt_long (argc, argv, "a:c:ns:h",
- long_options, NULL)) != EOF) {
+ while ((c = getopt_long(argc, argv, "a:c:ns:h", long_options, NULL)) !=
+ EOF) {
switch (c) {
- case 'a':
- if (parse_aes_key(optarg, common_args.aes_key)) {
- fprintf(stderr, "AES key parse error\n");
- return EXIT_FAILURE;
- }
- common_args.aes_flag = 1;
- break;
-#ifdef CONFIG_FILE
- case 'c':
- common_args.config_file = optarg;
- break;
-#endif
case 's':
setenv_args.script_file = optarg;
break;
+ case 'a':
+ case 'c':
case 'h':
- usage();
- exit(EXIT_SUCCESS);
+ /* ignore common options */
break;
default: /* '?' */
usage();
--
2.6.2
next prev parent reply other threads:[~2015-11-26 10:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-26 10:52 [U-Boot] [PATCH v2 0/7] tools: env: simplify argument parsing Andreas Fenkart
2015-11-26 10:52 ` [U-Boot] [PATCH v2 1/7] tools: env validate: pass values as 0-based array Andreas Fenkart
2015-11-26 10:52 ` [U-Boot] [PATCH v2 2/7] tools: env: make parse_aes_key stateless Andreas Fenkart
2015-11-26 10:52 ` [U-Boot] [PATCH v2 3/7] tools: env: introduce setenv/printenv argument structs Andreas Fenkart
2015-11-26 10:52 ` [U-Boot] [PATCH v2 4/7] tools: env: parse aes key / suppress flag into argument struct Andreas Fenkart
2015-11-26 10:52 ` [U-Boot] [PATCH v2 5/7] tools: env: shift optind arguments and fix argument indices Andreas Fenkart
2015-11-26 10:52 ` Andreas Fenkart [this message]
2015-11-26 10:52 ` [U-Boot] [PATCH v2 7/7] tools: env: update usage strings Andreas Fenkart
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=1448535154-6350-7-git-send-email-andreas.fenkart@dev.digitalstrom.org \
--to=afenkart@gmail.com \
--cc=u-boot@lists.denx.de \
/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