summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAndreas Fenkart <andreas.fenkart@digitalstrom.com>2015-12-09 13:13:26 +0100
committerTom Rini <trini@konsulko.com>2016-02-08 10:10:32 -0500
commitaf93e3d8ababbca05f94ed3ad89e3e277b31ffd5 (patch)
tree08887297eb7956fb1364287ec9111409871335e7 /tools
parent1ce686978c03d4fd025c7e93b7a18d4a87f547ec (diff)
downloadu-boot-imx-af93e3d8ababbca05f94ed3ad89e3e277b31ffd5.zip
u-boot-imx-af93e3d8ababbca05f94ed3ad89e3e277b31ffd5.tar.gz
u-boot-imx-af93e3d8ababbca05f94ed3ad89e3e277b31ffd5.tar.bz2
tools: env: factor out parse_common_args
Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/env/fw_env_main.c62
1 files changed, 37 insertions, 25 deletions
diff --git a/tools/env/fw_env_main.c b/tools/env/fw_env_main.c
index daf4688..39c8771 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,13 +89,13 @@ 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;
@@ -104,12 +104,37 @@ int parse_printenv_args(int argc, char *argv[])
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 +149,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();