mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-19 21:51:31 +00:00
tools: env: factor out parse_common_args
Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
This commit is contained in:
parent
1ce686978c
commit
af93e3d8ab
1 changed files with 38 additions and 26 deletions
64
tools/env/fw_env_main.c
vendored
64
tools/env/fw_env_main.c
vendored
|
@ -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;
|
int c;
|
||||||
|
|
||||||
|
@ -89,13 +89,13 @@ int parse_printenv_args(int argc, char *argv[])
|
||||||
common_args.config_file = CONFIG_FILE;
|
common_args.config_file = CONFIG_FILE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while ((c = getopt_long (argc, argv, "a:c:ns:h",
|
while ((c = getopt_long(argc, argv, ":a:c:h", long_options, NULL)) !=
|
||||||
long_options, NULL)) != EOF) {
|
EOF) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'a':
|
case 'a':
|
||||||
if (parse_aes_key(optarg, common_args.aes_key)) {
|
if (parse_aes_key(optarg, common_args.aes_key)) {
|
||||||
fprintf(stderr, "AES key parse error\n");
|
fprintf(stderr, "AES key parse error\n");
|
||||||
return EXIT_FAILURE;
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
common_args.aes_flag = 1;
|
common_args.aes_flag = 1;
|
||||||
break;
|
break;
|
||||||
|
@ -104,13 +104,38 @@ int parse_printenv_args(int argc, char *argv[])
|
||||||
common_args.config_file = optarg;
|
common_args.config_file = optarg;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 'n':
|
|
||||||
printenv_args.name_suppress = 1;
|
|
||||||
break;
|
|
||||||
case 'h':
|
case 'h':
|
||||||
usage();
|
usage();
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
break;
|
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':
|
||||||
|
/* ignore common options */
|
||||||
|
break;
|
||||||
default: /* '?' */
|
default: /* '?' */
|
||||||
usage();
|
usage();
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -124,31 +149,18 @@ int parse_setenv_args(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
#ifdef CONFIG_FILE
|
parse_common_args(argc, argv);
|
||||||
common_args.config_file = CONFIG_FILE;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
while ((c = getopt_long (argc, argv, "a:c:ns:h",
|
while ((c = getopt_long(argc, argv, "a:c:ns:h", long_options, NULL)) !=
|
||||||
long_options, NULL)) != EOF) {
|
EOF) {
|
||||||
switch (c) {
|
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':
|
case 's':
|
||||||
setenv_args.script_file = optarg;
|
setenv_args.script_file = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'a':
|
||||||
|
case 'c':
|
||||||
case 'h':
|
case 'h':
|
||||||
usage();
|
/* ignore common options */
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
break;
|
break;
|
||||||
default: /* '?' */
|
default: /* '?' */
|
||||||
usage();
|
usage();
|
||||||
|
|
Loading…
Add table
Reference in a new issue