]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
.
authorJim Meyering <jim@meyering.net>
Sun, 13 Feb 1994 20:27:08 +0000 (20:27 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 13 Feb 1994 20:27:08 +0000 (20:27 +0000)
src/basename.c
src/dirname.c

index c89b13c2761d3bd7d2185aa99a70b0f05015d3bf..6fc11302e98e75b6abf144a561ab7110da9e1dec 100644 (file)
 
 #include <stdio.h>
 #include <sys/types.h>
-#include <getopt.h>
 
-#include "version.h"
 #include "system.h"
+#include "long-options.h"
 
 char *basename ();
 void strip_trailing_slashes ();
@@ -51,19 +50,6 @@ static void remove_suffix ();
 /* The name this program was run with. */
 char *program_name;
 
-/* If non-zero, display usage information and exit.  */
-static int show_help;
-
-/* If non-zero, print the version on standard output and exit.  */
-static int show_version;
-
-static struct option const long_options[] =
-{
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
-  {0, 0, 0, 0}
-};
-
 static void
 usage (status)
      int status;
@@ -89,40 +75,20 @@ main (argc, argv)
      char **argv;
 {
   char *name;
-  int c;
 
   program_name = argv[0];
 
-  while ((c = getopt_long (argc, argv, "", long_options, (int *) 0)) != EOF)
-    {
-      switch (c)
-       {
-       case 0:
-         break;
-
-       default:
-         usage (1);
-       }
-    }
-
-  if (show_version)
-    {
-      printf ("%s\n", version_string);
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
+  parse_long_options (argc, argv, usage);
 
-  if (argc - optind == 0 || argc - optind > 2)
+  if (argc == 1 || argc > 3)
     usage (1);
 
-  strip_trailing_slashes (argv[optind]);
+  strip_trailing_slashes (argv[1]);
 
-  name = basename (argv[optind]);
+  name = basename (argv[1]);
 
   if (argc == 3)
-    remove_suffix (name, argv[optind + 1]);
+    remove_suffix (name, argv[2]);
 
   puts (name);
 
index b615ba13d351d536cbe16bcd491350d4299b8c3c..a0345be7ae8e3d6ac610719f5fc6384e7de719f3 100644 (file)
 
 #include <stdio.h>
 #include <sys/types.h>
-#include <getopt.h>
 
-#include "version.h"
 #include "system.h"
+#include "long-options.h"
 
 void strip_trailing_slashes ();
 
 /* The name this program was run with. */
 char *program_name;
 
-/* If non-zero, display usage information and exit.  */
-static int show_help;
-
-/* If non-zero, print the version on standard output and exit.  */
-static int show_version;
-
-static struct option const long_options[] =
-{
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
-  {0, 0, 0, 0}
-};
-
 static void
 usage (status)
      int status;
@@ -79,35 +65,15 @@ main (argc, argv)
 {
   register char *path;
   register char *slash;
-  int c;
 
   program_name = argv[0];
 
-  while ((c = getopt_long (argc, argv, "", long_options, (int *) 0)) != EOF)
-    {
-      switch (c)
-       {
-       case 0:
-         break;
-
-       default:
-         usage (1);
-       }
-    }
-
-  if (show_version)
-    {
-      printf ("%s\n", version_string);
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
+  parse_long_options (argc, argv, usage);
 
-  if (argc - optind != 1)
+  if (argc != 2)
     usage (1);
 
-  path = argv[optind];
+  path = argv[1];
   strip_trailing_slashes (path);
 
   slash = rindex (path, '/');