]> granicus.if.org Git - shadow/commitdiff
Split process_flags() out of main().
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Mon, 31 Dec 2007 14:52:52 +0000 (14:52 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Mon, 31 Dec 2007 14:52:52 +0000 (14:52 +0000)
ChangeLog
src/chsh.c

index 05879f0e3b2cde990cbeade17a253bb8b757fe8b..f18bac435e4492e304990b5c6a36381bc6a490c6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2007-12-31  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * src/chsh.c: Split process_flags() out of main().
+
 2007-12-31  Nicolas François  <nicolas.francois@centraliens.net>
 
        * src/chfn.c: New function: process_flags() split out of main().
index b34a43d21a724a523007beed712c9fa275ff1ff5..008da868f0d055aac36a83ae2fd49796cd2332bb 100644 (file)
@@ -71,6 +71,7 @@ static void usage (void);
 static void new_fields (void);
 static int check_shell (const char *);
 static int restricted_shell (const char *);
+static void process_flags (int argc, char **argv);
 
 /*
  * usage - print command line syntax and exit
@@ -167,6 +168,46 @@ static int check_shell (const char *sh)
        return found;
 }
 
+/*
+ *  * process_flags - parse the command line options
+ *
+ *     It will not return if an error is encountered.
+ */
+static void process_flags (int argc, char **argv)
+{
+       int option_index = 0;
+       int c;
+       static struct option long_options[] = {
+               {"help", no_argument, NULL, 'h'},
+               {"shell", required_argument, NULL, 's'},
+               {NULL, 0, NULL, '\0'}
+       };
+
+       while ((c =
+               getopt_long (argc, argv, "hs:", long_options,
+                            &option_index)) != -1) {
+               switch (c) {
+               case 'h':
+                       usage ();
+                       break;
+               case 's':
+                       sflg++;
+                       STRFCPY (loginsh, optarg);
+                       break;
+               default:
+                       usage ();
+               }
+       }
+
+       /*
+        * There should be only one remaining argument at most and it should
+        * be the user's name.
+        */
+       if (argc > (optind + 1)) {
+               usage ();
+       }
+}
+
 /*
  * chsh - this command controls changes to the user's shell
  *
@@ -204,42 +245,8 @@ int main (int argc, char **argv)
 
        OPENLOG ("chsh");
 
-       /*
-        * There is only one option, but use getopt() anyway to
-        * keep things consistent.
-        */
-       {
-               int option_index = 0;
-               int c;
-               static struct option long_options[] = {
-                       {"help", no_argument, NULL, 'h'},
-                       {"shell", required_argument, NULL, 's'},
-                       {NULL, 0, NULL, '\0'}
-               };
-
-               while ((c =
-                       getopt_long (argc, argv, "hs:", long_options,
-                                    &option_index)) != -1) {
-                       switch (c) {
-                       case 'h':
-                               usage ();
-                               break;
-                       case 's':
-                               sflg++;
-                               STRFCPY (loginsh, optarg);
-                               break;
-                       default:
-                               usage ();
-                       }
-               }
-       }
-
-       /*
-        * There should be only one remaining argument at most and it should
-        * be the user's name.
-        */
-       if (argc > optind + 1)
-               usage ();
+       /* parse the command line options */
+       process_flags (argc, argv);
 
        /*
         * Get the name of the user to check. It is either the command line