summaryrefslogtreecommitdiffstats
path: root/misc-utils/getopt.c
diff options
context:
space:
mode:
authorSami Kerola2014-12-07 01:40:11 +0100
committerSami Kerola2014-12-08 21:07:01 +0100
commit80dd38e9fb06ef445d2d75749181098c893aabb6 (patch)
tree1aeede203a5d9e94764971bf98fec11f82d11a4a /misc-utils/getopt.c
parentgetopt: prefer switch-case rather than long if statement (diff)
downloadkernel-qcow2-util-linux-80dd38e9fb06ef445d2d75749181098c893aabb6.tar.gz
kernel-qcow2-util-linux-80dd38e9fb06ef445d2d75749181098c893aabb6.tar.xz
kernel-qcow2-util-linux-80dd38e9fb06ef445d2d75749181098c893aabb6.zip
getopt: change --shell argument parsing function
Avoid passing getopt_control stucture in when returning a value is enough. CC: Frodo Looijaard <frodo@frodo.looijaard.name> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'misc-utils/getopt.c')
-rw-r--r--misc-utils/getopt.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/misc-utils/getopt.c b/misc-utils/getopt.c
index 8134558d1..2940a7d2a 100644
--- a/misc-utils/getopt.c
+++ b/misc-utils/getopt.c
@@ -295,19 +295,17 @@ static void add_long_options(struct getopt_control *ctl, char *options)
}
}
-static void set_shell(struct getopt_control *ctl, const char *new_shell)
+static shell_t shell_type(const char *new_shell)
{
if (!strcmp(new_shell, "bash"))
- ctl->shell = BASH;
- else if (!strcmp(new_shell, "tcsh"))
- ctl->shell = TCSH;
- else if (!strcmp(new_shell, "sh"))
- ctl->shell = BASH;
- else if (!strcmp(new_shell, "csh"))
- ctl->shell = TCSH;
- else
- parse_error(_
- ("unknown shell after -s or --shell argument"));
+ return BASH;
+ if (!strcmp(new_shell, "sh"))
+ return BASH;
+ if (!strcmp(new_shell, "tcsh"))
+ return TCSH;
+ if (!strcmp(new_shell, "csh"))
+ return TCSH;
+ parse_error(_("unknown shell after -s or --shell argument"));
}
static void __attribute__ ((__noreturn__)) print_help(void)
@@ -419,7 +417,7 @@ int main(int argc, char *argv[])
ctl.quiet_output = 1;
break;
case 's':
- set_shell(&ctl, optarg);
+ ctl.shell = shell_type(optarg);
break;
case 'T':
return TEST_EXIT_CODE;