]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
getopt: change --shell argument parsing function
authorSami Kerola <kerolasa@iki.fi>
Sun, 7 Dec 2014 00:40:11 +0000 (00:40 +0000)
committerSami Kerola <kerolasa@iki.fi>
Mon, 8 Dec 2014 20:07:01 +0000 (20:07 +0000)
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>
misc-utils/getopt.c

index 8134558d1abb941ec1c5e64b48b736583b5f5446..2940a7d2ae77570f20128917efee529214efd110 100644 (file)
@@ -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;