Include long-options.h
authorJim Meyering <jim@meyering.net>
Thu, 4 Mar 1999 05:09:05 +0000 (05:09 +0000)
committerJim Meyering <jim@meyering.net>
Thu, 4 Mar 1999 05:09:05 +0000 (05:09 +0000)
[long_options]: Remove the "help" and "version" entries.
(main): Use parse_long_options, including author name(s).
Remove the show_version and show_help blocks.

20 files changed:
src/chgrp.c
src/chmod.c
src/chown.c
src/cp.c
src/dd.c
src/df.c
src/dircolors.c
src/du.c
src/install.c
src/ln.c
src/ls.c
src/mkdir.c
src/mkfifo.c
src/mknod.c
src/mv.c
src/rm.c
src/rmdir.c
src/shred.c
src/sync.c
src/touch.c

index 19d233c..109edbc 100644 (file)
 #include <getopt.h>
 
 #include "system.h"
-#include "xstrtoul.h"
 #include "closeout.h"
 #include "error.h"
-#include "savedir.h"
 #include "group-member.h"
+#include "long-options.h"
+#include "savedir.h"
+#include "xstrtoul.h"
 
 /* MAXUID may come from limits.h *or* sys/params.h (via system.h) above. */
 #ifndef MAXUID
@@ -97,12 +98,6 @@ static const char *groupname;
    This file must exist.  */
 static char *reference_file;
 
-/* If nonzero, display usage information and exit.  */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit.  */
-static int show_version;
-
 static struct option const long_options[] =
 {
   {"recursive", no_argument, 0, 'R'},
@@ -112,8 +107,6 @@ static struct option const long_options[] =
   {"quiet", no_argument, 0, 'f'},
   {"reference", required_argument, 0, CHAR_MAX + 1},
   {"verbose", no_argument, 0, 'v'},
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
   {0, 0, 0, 0}
 };
 
@@ -335,6 +328,9 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+  parse_long_options (argc, argv, "chgrp", GNU_PACKAGE, VERSION,
+                     "David MacKenzie", usage);
+
   recurse = force_silent = 0;
 
   while ((optc = getopt_long (argc, argv, "Rcfhv", long_options, NULL)) != -1)
@@ -366,16 +362,6 @@ main (int argc, char **argv)
        }
     }
 
-  if (show_version)
-    {
-      printf ("chgrp (%s) %s\n", GNU_PACKAGE, VERSION);
-      close_stdout ();
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
-
   if (argc - optind + (reference_file ? 1 : 0) <= 1)
     {
       error (0, 0, _("too few arguments"));
index 66537ca..c2d978d 100644 (file)
 #include <getopt.h>
 #include <sys/types.h>
 
-#include "modechange.h"
 #include "system.h"
 #include "closeout.h"
 #include "error.h"
-#include "savedir.h"
 #include "filemode.h"
+#include "long-options.h"
+#include "modechange.h"
+#include "savedir.h"
 
 enum Change_status
 {
@@ -70,12 +71,6 @@ static enum Verbosity verbosity = V_off;
    of this file.  This file must exist.  */
 static char *reference_file;
 
-/* If nonzero, display usage information and exit.  */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit.  */
-static int show_version;
-
 static struct option const long_options[] =
 {
   {"recursive", no_argument, 0, 'R'},
@@ -84,8 +79,6 @@ static struct option const long_options[] =
   {"quiet", no_argument, 0, 'f'},
   {"reference", required_argument, 0, CHAR_MAX + 1},
   {"verbose", no_argument, 0, 'v'},
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
   {0, 0, 0, 0}
 };
 
@@ -279,6 +272,9 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+  parse_long_options (argc, argv, "chmod", GNU_PACKAGE, VERSION,
+                     "David MacKenzie", usage);
+
   recurse = force_silent = 0;
 
   while (1)
@@ -331,16 +327,6 @@ main (int argc, char **argv)
        }
     }
 
-  if (show_version)
-    {
-      printf ("chmod (%s) %s\n", GNU_PACKAGE, VERSION);
-      close_stdout ();
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
-
   if (modeind == 0 && reference_file == NULL)
     modeind = optind++;
 
index d74ea74..49e6f93 100644 (file)
@@ -38,8 +38,9 @@
 #include "system.h"
 #include "closeout.h"
 #include "error.h"
-#include "savedir.h"
+#include "long-options.h"
 #include "lchown.h"
+#include "savedir.h"
 
 #ifndef _POSIX_VERSION
 struct passwd *getpwnam ();
@@ -103,12 +104,6 @@ static char *groupname;
    of this file.  This file must exist.  */
 static char *reference_file;
 
-/* If nonzero, display usage information and exit.  */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit.  */
-static int show_version;
-
 static struct option const long_options[] =
 {
   {"recursive", no_argument, 0, 'R'},
@@ -119,8 +114,6 @@ static struct option const long_options[] =
   {"silent", no_argument, 0, 'f'},
   {"reference", required_argument, 0, CHAR_MAX + 1},
   {"verbose", no_argument, 0, 'v'},
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
   {0, 0, 0, 0}
 };
 
@@ -333,6 +326,9 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+  parse_long_options (argc, argv, "chown", GNU_PACKAGE, VERSION,
+                     "David MacKenzie", usage);
+
   recurse = force_silent = 0;
 
   while ((optc = getopt_long (argc, argv, "Rcfhv", long_options, NULL)) != -1)
@@ -367,16 +363,6 @@ main (int argc, char **argv)
        }
     }
 
-  if (show_version)
-    {
-      printf ("chown (%s) %s\n", GNU_PACKAGE, VERSION);
-      close_stdout ();
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
-
   if (argc - optind + (reference_file ? 1 : 0) <= 1)
     {
       error (0, 0, _("too few arguments"));
index 26c21f6..bdc399b 100644 (file)
--- a/src/cp.c
+++ b/src/cp.c
 #include <getopt.h>
 
 #include "system.h"
-#include "backupfile.h"
 #include "argmatch.h"
-#include "path-concat.h"
+#include "backupfile.h"
 #include "closeout.h"
-#include "cp-hash.h"
 #include "copy.h"
+#include "cp-hash.h"
 #include "error.h"
 #include "dirname.h"
+#include "long-options.h"
+#include "path-concat.h"
 
 #ifndef _POSIX_VERSION
 uid_t geteuid ();
@@ -83,12 +84,6 @@ static enum Sparse_type const sparse_type[] =
 /* The error code to return to the system. */
 static int exit_status = 0;
 
-/* If nonzero, display usage information and exit.  */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit.  */
-static int show_version;
-
 static struct option const long_opts[] =
 {
   {"archive", no_argument, NULL, 'a'},
@@ -108,8 +103,6 @@ static struct option const long_opts[] =
   {"update", no_argument, NULL, 'u'},
   {"verbose", no_argument, NULL, 'v'},
   {"version-control", required_argument, NULL, 'V'},
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
   {NULL, 0, NULL, 0}
 };
 
@@ -638,6 +631,10 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+  parse_long_options (argc, argv, "cp", GNU_PACKAGE, VERSION,
+                     "Torbjorn Granlund, David MacKenzie, and Jim Meyering",
+                     usage);
+
   cp_option_init (&x);
 
   /* FIXME: consider not calling getenv for SIMPLE_BACKUP_SUFFIX unless
@@ -746,16 +743,6 @@ main (int argc, char **argv)
        }
     }
 
-  if (show_version)
-    {
-      printf ("cp (%s) %s\n", GNU_PACKAGE, VERSION);
-      close_stdout ();
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
-
   if (x.hard_link && x.symbolic_link)
     {
       error (0, 0, _("cannot make both hard and symbolic links"));
index 9f21bb9..f63688f 100644 (file)
--- a/src/dd.c
+++ b/src/dd.c
 #include <signal.h>
 #include <getopt.h>
 
-#include "human.h"
 #include "system.h"
 #include "closeout.h"
 #include "error.h"
+#include "human.h"
+#include "long-options.h"
 #include "safe-read.h"
 
 #ifndef SIGINFO
@@ -266,16 +267,8 @@ static unsigned char const ebcdic_to_ascii[] =
   070, 071, 0372, 0373, 0374, 0375, 0376, 0377
 };
 
-/* If nonzero, display usage information and exit.  */
-static int show_help;
-
-/* If nonzero, 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}
 };
 
@@ -1111,6 +1104,9 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+  parse_long_options (argc, argv, "dd", GNU_PACKAGE, VERSION,
+                     "Paul Rubin, David MacKenzie, and Stuart Kemp", usage);
+
   /* Initialize translation table to identity translation. */
   for (i = 0; i < 256; i++)
     trans_table[i] = i;
@@ -1118,16 +1114,6 @@ main (int argc, char **argv)
   /* Decode arguments. */
   scanargs (argc, argv);
 
-  if (show_version)
-    {
-      printf ("dd (%s) %s\n", GNU_PACKAGE, VERSION);
-      close_stdout ();
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
-
   apply_translations ();
 
   if (input_file != NULL)
index 0a43f07..8ebe412 100644 (file)
--- a/src/df.c
+++ b/src/df.c
 #include <getopt.h>
 #include <assert.h>
 
-#include "mountlist.h"
-#include "fsusage.h"
 #include "system.h"
-#include "save-cwd.h"
 #include "closeout.h"
+#include "dirname.h"
 #include "error.h"
+#include "fsusage.h"
 #include "human.h"
-#include "dirname.h"
+#include "long-options.h"
+#include "mountlist.h"
+#include "save-cwd.h"
 
 void strip_trailing_slashes ();
 char *xstrdup ();
@@ -103,12 +104,6 @@ static struct fs_type_list *fs_exclude_list;
 /* Linked list of mounted filesystems. */
 static struct mount_entry *mount_list;
 
-/* If nonzero, display usage information and exit.  */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit.  */
-static int show_version;
-
 /* If nonzero, print filesystem type as well.  */
 static int print_type;
 
@@ -128,8 +123,6 @@ static struct option const long_options[] =
   {"no-sync", no_argument, NULL, CHAR_MAX + 2},
   {"type", required_argument, NULL, 't'},
   {"exclude-type", required_argument, NULL, 'x'},
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
   {NULL, 0, NULL, 0}
 };
 
@@ -622,6 +615,10 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+  parse_long_options (argc, argv, "df", GNU_PACKAGE, VERSION,
+           "Torbjorn Granlund, David MacKenzie, Larry McVoy, and Paul Eggert",
+                     usage);
+
   fs_select_list = NULL;
   fs_exclude_list = NULL;
   inode_format = 0;
@@ -696,16 +693,6 @@ main (int argc, char **argv)
        }
     }
 
-  if (show_version)
-    {
-      printf ("df (%s) %s\n", GNU_PACKAGE, VERSION);
-      close_stdout ();
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
-
   /* Fail if the same file system type was both selected and excluded.  */
   {
     int match = 0;
index cfed5c4..f69e931 100644 (file)
@@ -30,6 +30,7 @@
 #include "long-options.h"
 #include "closeout.h"
 #include "error.h"
+#include "long-options.h"
 #include "obstack.h"
 #include "dircolors.h"
 
@@ -82,9 +83,7 @@ static struct option const long_options[] =
     {"sh", no_argument, NULL, 'b'},
     {"csh", no_argument, NULL, 'c'},
     {"c-shell", no_argument, NULL, 'c'},
-    {"help", no_argument, NULL, 'h'},
     {"print-database", no_argument, NULL, 'p'},
-    {"version", no_argument, NULL, 'v'},
     {NULL, 0, NULL, 0}
   };
 
@@ -428,7 +427,8 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
-  parse_long_options (argc, argv, "dircolors", GNU_PACKAGE, VERSION, usage);
+  parse_long_options (argc, argv, "dircolors", GNU_PACKAGE, VERSION,
+                     "H. Peter Anvin", usage);
 
   while ((optc = getopt_long (argc, argv, "bcp", long_options, NULL)) != -1)
     switch (optc)
index be8c227..dfa4bd5 100644 (file)
--- a/src/du.c
+++ b/src/du.c
 #include <sys/types.h>
 #include <assert.h>
 
-#include "exclude.h"
 #include "system.h"
-#include "save-cwd.h"
 #include "closeout.h"
 #include "error.h"
+#include "exclude.h"
 #include "human.h"
-#include "xstrtol.h"
+#include "long-options.h"
+#include "save-cwd.h"
 #include "savedir.h"
+#include "xstrtol.h"
 
 /* Initial number of entries in each hash table entry's table of inodes.  */
 #define INITIAL_HASH_MODULE 100
@@ -163,12 +164,6 @@ static int (*xstat) ();
 /* The exit status to use if we don't get any fatal errors. */
 static int exit_status;
 
-/* If nonzero, display usage information and exit.  */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit.  */
-static int show_version;
-
 /* File name patterns to exclude.  */
 static struct exclude *exclude;
 
@@ -194,18 +189,12 @@ static struct option const long_options[] =
   {"separate-dirs", no_argument, NULL, 'S'},
   {"summarize", no_argument, NULL, 's'},
   {"total", no_argument, NULL, 'c'},
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
   {NULL, 0, NULL, 0}
 };
 
 void
-usage (int status, char *reason)
+usage (int status)
 {
-  if (reason != NULL)
-    fprintf (status == 0 ? stdout : stderr, "%s: %s\n",
-            program_name, reason);
-
   if (status != 0)
     fprintf (stderr, _("Try `%s --help' for more information.\n"),
             program_name);
@@ -262,6 +251,10 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+  parse_long_options (argc, argv, "du", GNU_PACKAGE, VERSION,
+           "Torbjorn Granlund, David MacKenzie, Larry McVoy, and Paul Eggert",
+                     usage);
+
   exclude = new_exclude ();
   xstat = lstat;
 
@@ -351,23 +344,16 @@ main (int argc, char **argv)
          break;
 
        default:
-         usage (1, (char *) 0);
+         usage (1);
        }
     }
 
-  if (show_version)
+  if (opt_all && opt_summarize_only)
     {
-      printf ("du (%s) %s\n", GNU_PACKAGE, VERSION);
-      close_stdout ();
-      exit (0);
+      error (0, 0, _("cannot both summarize and show all entries"));
+      usage (1);
     }
 
-  if (show_help)
-    usage (0, NULL);
-
-  if (opt_all && opt_summarize_only)
-    usage (1, _("cannot both summarize and show all entries"));
-
   if (opt_summarize_only && max_depth_specified && max_depth == 0)
     {
       error (0, 0,
@@ -379,7 +365,7 @@ main (int argc, char **argv)
       error (0, 0,
             _("warning: summarizing conflicts with --max-depth=%d"),
               max_depth);
-      usage (1, NULL);
+      usage (1);
     }
 
   if (opt_summarize_only)
index 757a710..71de8e4 100644 (file)
 
 #include "system.h"
 #include "backupfile.h"
-#include "modechange.h"
-#include "makepath.h"
 #include "closeout.h"
 #include "error.h"
-#include "xstrtol.h"
-#include "path-concat.h"
 #include "cp-hash.h"
 #include "copy.h"
 #include "dirname.h"
+#include "long-options.h"
+#include "makepath.h"
+#include "modechange.h"
+#include "path-concat.h"
+#include "xstrtol.h"
 
 #if HAVE_SYS_WAIT_H
 # include <sys/wait.h>
@@ -165,12 +166,6 @@ static int strip_files;
 /* If nonzero, install a directory instead of a regular file. */
 static int dir_arg;
 
-/* If nonzero, display usage information and exit.  */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit.  */
-static int show_version;
-
 static struct option const long_options[] =
 {
   {"strip", no_argument, NULL, 's'},
@@ -183,8 +178,6 @@ static struct option const long_options[] =
   {"suffix", required_argument, NULL, 'S'},
   {"version-control", required_argument, NULL, 'V'},
   {"verbose", no_argument, NULL, 'v'},
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
   {NULL, 0, NULL, 0}
 };
 
@@ -242,6 +235,9 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+  parse_long_options (argc, argv, "install", GNU_PACKAGE, VERSION,
+                     "David MacKenzie", usage);
+
   cp_option_init (&x);
 
   owner_name = NULL;
@@ -304,16 +300,6 @@ main (int argc, char **argv)
        }
     }
 
-  if (show_version)
-    {
-      printf ("install (%s) %s\n", GNU_PACKAGE, VERSION);
-      close_stdout ();
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
-
   /* Check for invalid combinations of arguments. */
   if (dir_arg && strip_files)
     error (1, 0,
index e60cc6e..9f3fd8e 100644 (file)
--- a/src/ln.c
+++ b/src/ln.c
@@ -29,8 +29,9 @@
 #include "system.h"
 #include "backupfile.h"
 #include "closeout.h"
-#include "error.h"
 #include "dirname.h"
+#include "error.h"
+#include "long-options.h"
 
 int link ();                   /* Some systems don't declare this anywhere. */
 
@@ -97,12 +98,6 @@ static int hard_dir_link;
    symlink-to-dir before creating the new link.  */
 static int dereference_dest_dir_symlinks = 1;
 
-/* If nonzero, display usage information and exit.  */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit.  */
-static int show_version;
-
 static struct option const long_options[] =
 {
   {"backup", no_argument, NULL, 'b'},
@@ -114,8 +109,6 @@ static struct option const long_options[] =
   {"symbolic", no_argument, NULL, 's'},
   {"verbose", no_argument, NULL, 'v'},
   {"version-control", required_argument, NULL, 'V'},
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
   {NULL, 0, NULL, 0}
 };
 
@@ -386,6 +379,9 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+  parse_long_options (argc, argv, "ln", GNU_PACKAGE, VERSION,
+                     "Mike Parker and David MacKenzie", usage);
+
   /* FIXME: consider not calling getenv for SIMPLE_BACKUP_SUFFIX unless
      we'll actually use simple_backup_suffix.  */
   version = getenv ("SIMPLE_BACKUP_SUFFIX");
@@ -444,16 +440,6 @@ main (int argc, char **argv)
        }
     }
 
-  if (show_version)
-    {
-      printf ("ln (%s) %s\n", GNU_PACKAGE, VERSION);
-      close_stdout ();
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
-
   if (optind == argc)
     {
       error (0, 0, _("missing file argument"));
index 7cbfadb..17a0b33 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
 #include "system.h"
 #include <fnmatch.h>
 
-#include "obstack.h"
-#include "ls.h"
+#include "argmatch.h"
 #include "closeout.h"
 #include "error.h"
 #include "human.h"
-#include "argmatch.h"
-#include "xstrtol.h"
-#include "strverscmp.h"
-#include "quotearg.h"
 #include "filemode.h"
+#include "long-options.h"
+#include "ls.h"
+#include "obstack.h"
 #include "path-concat.h"
+#include "quotearg.h"
+#include "strverscmp.h"
+#include "xstrtol.h"
 
 #define obstack_chunk_alloc malloc
 #define obstack_chunk_free free
@@ -528,12 +529,6 @@ static int format_needs_stat;
 
 static int exit_status;
 
-/* If nonzero, display usage information and exit.  */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit.  */
-static int show_version;
-
 static struct option const long_options[] =
 {
   {"all", no_argument, 0, 'a'},
@@ -567,8 +562,6 @@ static struct option const long_options[] =
   {"sort", required_argument, 0, 10},
   {"tabsize", required_argument, 0, 'T'},
   {"time", required_argument, 0, 11},
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
   {"color", optional_argument, 0, 13},
   {"block-size", required_argument, 0, 17},
   {NULL, 0, NULL, 0}
@@ -720,6 +713,13 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+#define PROGRAM_NAME (ls_mode == LS_LS ? "ls" \
+                     : (ls_mode == LS_MULTI_COL \
+                        ? "dir" : "vdir"))
+
+  parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
+                     "Richard Stallman and David MacKenzie", usage);
+
   exit_status = 0;
   dir_defaulted = 1;
   print_dir_name = 1;
@@ -728,19 +728,6 @@ main (int argc, char **argv)
 
   i = decode_switches (argc, argv);
 
-  if (show_version)
-    {
-      printf ("%s (%s) %s\n",
-             (ls_mode == LS_LS ? "ls"
-              : (ls_mode == LS_MULTI_COL ? "dir" : "vdir")),
-             GNU_PACKAGE, VERSION);
-      close_stdout ();
-      exit (EXIT_SUCCESS);
-    }
-
-  if (show_help)
-    usage (EXIT_SUCCESS);
-
   if (print_with_color)
     {
       parse_ls_color ();
index 1801367..e201a7e 100644 (file)
 #include <sys/types.h>
 
 #include "system.h"
-#include "modechange.h"
-#include "makepath.h"
 #include "closeout.h"
 #include "error.h"
+#include "long-options.h"
+#include "makepath.h"
+#include "modechange.h"
 
 /* The name this program was run with. */
 char *program_name;
@@ -34,19 +35,11 @@ char *program_name;
 /* If nonzero, ensure that all parents of the specified directory exist.  */
 static int path_mode;
 
-/* If nonzero, display usage information and exit.  */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit.  */
-static int show_version;
-
 static struct option const longopts[] =
 {
   {"mode", required_argument, NULL, 'm'},
   {"parents", no_argument, NULL, 'p'},
-  {"help", no_argument, &show_help, 1},
   {"verbose", no_argument, NULL, 2},
-  {"version", no_argument, &show_version, 1},
   {NULL, 0, NULL, 0}
 };
 
@@ -89,6 +82,9 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+  parse_long_options (argc, argv, "mkdir", GNU_PACKAGE, VERSION,
+                     "David MacKenzie", usage);
+
   path_mode = 0;
 
   while ((optc = getopt_long (argc, argv, "pm:", longopts, NULL)) != -1)
@@ -111,16 +107,6 @@ main (int argc, char **argv)
        }
     }
 
-  if (show_version)
-    {
-      printf ("mkdir (%s) %s\n", GNU_PACKAGE, VERSION);
-      close_stdout ();
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
-
   if (optind == argc)
     {
       error (0, 0, _("too few arguments"));
index 3b09a55..09c05e3 100644 (file)
 #include <sys/types.h>
 
 #include "system.h"
-#include "modechange.h"
 #include "closeout.h"
 #include "error.h"
+#include "long-options.h"
+#include "modechange.h"
 
 /* The name this program was run with. */
 char *program_name;
 
-/* If nonzero, display usage information and exit.  */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit.  */
-static int show_version;
-
 static struct option const longopts[] =
 {
   {"mode", required_argument, NULL, 'm'},
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
   {NULL, 0, NULL, 0}
 };
 
@@ -87,6 +80,9 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+  parse_long_options (argc, argv, "mkfifo", GNU_PACKAGE, VERSION,
+                     "David MacKenzie", usage);
+
   symbolic_mode = NULL;
 
 #ifndef S_ISFIFO
@@ -106,16 +102,6 @@ main (int argc, char **argv)
        }
     }
 
-  if (show_version)
-    {
-      printf ("mkfifo (%s) %s\n", GNU_PACKAGE, VERSION);
-      close_stdout ();
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
-
   if (optind == argc)
     {
       error (0, 0, _("too few arguments"));
index a813b9f..96bc4be 100644 (file)
 #include <sys/types.h>
 
 #include "system.h"
-#include "modechange.h"
 #include "closeout.h"
 #include "error.h"
+#include "long-options.h"
+#include "modechange.h"
 #include "xstrtol.h"
 
 /* The name this program was run with. */
 char *program_name;
 
-/* If nonzero, display usage information and exit.  */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit.  */
-static int show_version;
-
 static struct option const longopts[] =
 {
   {"mode", required_argument, NULL, 'm'},
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
   {NULL, 0, NULL, 0}
 };
 
@@ -99,6 +92,9 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+  parse_long_options (argc, argv, "mknod", GNU_PACKAGE, VERSION,
+                     "David MacKenzie", usage);
+
   symbolic_mode = NULL;
 
   while ((optc = getopt_long (argc, argv, "m:", longopts, NULL)) != -1)
@@ -115,16 +111,6 @@ main (int argc, char **argv)
        }
     }
 
-  if (show_version)
-    {
-      printf ("mknod (%s) %s\n", GNU_PACKAGE, VERSION);
-      close_stdout ();
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
-
   newmode = 0666 & ~umask (0);
   if (symbolic_mode)
     {
index 89f0feb..b56d4d4 100644 (file)
--- a/src/mv.c
+++ b/src/mv.c
 #include <assert.h>
 
 #include "system.h"
-#include "path-concat.h"
 #include "backupfile.h"
 #include "closeout.h"
-#include "cp-hash.h"
 #include "copy.h"
-#include "remove.h"
+#include "cp-hash.h"
 #include "error.h"
+#include "long-options.h"
+#include "path-concat.h"
+#include "remove.h"
 
 /* Initial number of entries in each hash table entry's table of inodes.  */
 #define INITIAL_HASH_MODULE 100
@@ -74,12 +75,6 @@ char *program_name;
 /* If nonzero, stdin is a tty. */
 static int stdin_tty;
 
-/* If nonzero, display usage information and exit.  */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit.  */
-static int show_version;
-
 static struct option const long_options[] =
 {
   {"backup", no_argument, NULL, 'b'},
@@ -89,8 +84,6 @@ static struct option const long_options[] =
   {"update", no_argument, NULL, 'u'},
   {"verbose", no_argument, NULL, 'v'},
   {"version-control", required_argument, NULL, 'V'},
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
   {NULL, 0, NULL, 0}
 };
 
@@ -375,6 +368,9 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+  parse_long_options (argc, argv, "mv", GNU_PACKAGE, VERSION,
+                     "Mike Parker, David MacKenzie, and Jim Meyering", usage);
+
   cp_option_init (&x);
 
   /* FIXME: consider not calling getenv for SIMPLE_BACKUP_SUFFIX unless
@@ -420,16 +416,6 @@ main (int argc, char **argv)
        }
     }
 
-  if (show_version)
-    {
-      printf ("mv (%s) %s\n", GNU_PACKAGE, VERSION);
-      close_stdout ();
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
-
   if (argc < optind + 2)
     {
       error (0, 0, "%s", (argc == optind
index 1642ec3..1dbdfbb 100644 (file)
--- a/src/rm.c
+++ b/src/rm.c
 #include <sys/types.h>
 #include <assert.h>
 
-#include "save-cwd.h"
 #include "system.h"
 #include "closeout.h"
 #include "error.h"
+#include "long-options.h"
 #include "remove.h"
+#include "save-cwd.h"
 
 void strip_trailing_slashes ();
 
 /* Name this program was run with.  */
 char *program_name;
 
-/* If nonzero, display usage information and exit.  */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit.  */
-static int show_version;
-
 static struct option const long_opts[] =
 {
   {"directory", no_argument, NULL, 'd'},
@@ -73,8 +68,6 @@ static struct option const long_opts[] =
   {"interactive", no_argument, NULL, 'i'},
   {"recursive", no_argument, NULL, 'r'},
   {"verbose", no_argument, NULL, 'v'},
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
   {NULL, 0, NULL, 0}
 };
 
@@ -127,6 +120,10 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+  parse_long_options (argc, argv, "rm", GNU_PACKAGE, VERSION,
+           "Paul Rubin, David MacKenzie, Richard Stallman, and Jim Meyering",
+                     usage);
+
   rm_option_init (&x);
 
   while ((c = getopt_long (argc, argv, "dfirvR", long_opts, NULL)) != -1)
@@ -158,16 +155,6 @@ main (int argc, char **argv)
        }
     }
 
-  if (show_version)
-    {
-      printf ("rm (%s) %s\n", GNU_PACKAGE, VERSION);
-      close_stdout ();
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
-
   if (optind == argc)
     {
       if (x.ignore_missing_files)
index 7050484..81e437e 100644 (file)
@@ -30,6 +30,7 @@
 #include "system.h"
 #include "closeout.h"
 #include "error.h"
+#include "long-options.h"
 
 #ifndef EEXIST
 # define EEXIST 0
@@ -54,12 +55,6 @@ static int ignore_fail_on_non_empty;
 /* If nonzero, output a diagnostic for every directory processed.  */
 static int verbose;
 
-/* If nonzero, display usage information and exit.  */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit.  */
-static int show_version;
-
 static struct option const longopts[] =
 {
   /* Don't name this `--force' because it's not close enough in meaning
@@ -69,8 +64,6 @@ static struct option const longopts[] =
   {"path", no_argument, NULL, 'p'},
   {"parents", no_argument, NULL, 'p'},
   {"verbose", no_argument, NULL, 14},
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
   {NULL, 0, NULL, 0}
 };
 
@@ -152,6 +145,9 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+  parse_long_options (argc, argv, "rmdir", GNU_PACKAGE, VERSION,
+                     "David MacKenzie", usage);
+
   empty_paths = 0;
 
   while ((optc = getopt_long (argc, argv, "p", longopts, NULL)) != -1)
@@ -174,16 +170,6 @@ main (int argc, char **argv)
        }
     }
 
-  if (show_version)
-    {
-      printf ("rmdir (%s) %s\n", GNU_PACKAGE, VERSION);
-      close_stdout ();
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
-
   if (optind == argc)
     {
       error (0, 0, _("too few arguments"));
index 14478c6..6746286 100644 (file)
 #include <stdarg.h>            /* Used by pferror */
 
 #include "system.h"
-#include "xstrtoul.h"
 #include "closeout.h"
 #include "error.h"
+#include "long-options.h"
+#include "xstrtoul.h"
 
 #define DEFAULT_PASSES 25      /* Default */
 
@@ -84,12 +85,6 @@ struct Options
   int zero_fill;
 };
 
-/* If nonzero, display usage information and exit.  */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit.  */
-static int show_version;
-
 static struct option const long_opts[] =
 {
   {"device", no_argument, NULL, 'd'},
@@ -99,8 +94,6 @@ static struct option const long_opts[] =
   {"preserve", no_argument, NULL, 'p'},
   {"verbose", no_argument, NULL, 'v'},
   {"zero", required_argument, NULL, 'z'},
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
   {NULL, 0, NULL, 0}
 };
 
@@ -1290,6 +1283,9 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+  parse_long_options (argc, argv, "shred", GNU_PACKAGE, VERSION,
+                     "Colin Plumb", usage);
+
   isaac_seed (&s);
 
   memset (&flags, 0, sizeof flags);
@@ -1347,16 +1343,6 @@ main (int argc, char **argv)
        }
     }
 
-  if (show_version)
-    {
-      printf ("shred (%s) %s\n", GNU_PACKAGE, VERSION);
-      close_stdout ();
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
-
   file = argv + optind;
   n_files = argc - optind;
 
index 43ec1fa..2d9e588 100644 (file)
@@ -58,7 +58,8 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
-  parse_long_options (argc, argv, "sync", GNU_PACKAGE, VERSION, usage);
+  parse_long_options (argc, argv, "sync", GNU_PACKAGE, VERSION,
+                     "Jim Meyering", usage);
 
   if (argc != 1)
     error (0, 0, _("ignoring all arguments"));
index 9a366c2..b8435ce 100644 (file)
 #include <sys/types.h>
 
 #include "system.h"
+#include "argmatch.h"
 #include "closeout.h"
 #include "error.h"
-#include "argmatch.h"
 #include "getdate.h"
-#include "safe-read.h"
+#include "long-options.h"
 #include "posixtm.h"
+#include "safe-read.h"
 
 #ifndef STDC_HEADERS
 time_t time ();
@@ -73,12 +74,6 @@ static char *ref_file;
 /* Info about the reference file. */
 static struct stat ref_stats;
 
-/* If nonzero, display usage information and exit.  */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit.  */
-static int show_version;
-
 static struct option const longopts[] =
 {
   {"time", required_argument, 0, CHAR_MAX + 1},
@@ -86,8 +81,6 @@ static struct option const longopts[] =
   {"date", required_argument, 0, 'd'},
   {"file", required_argument, 0, 'r'},
   {"reference", required_argument, 0, 'r'},
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
   {0, 0, 0, 0}
 };
 
@@ -237,6 +230,10 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+  parse_long_options (argc, argv, "touch", GNU_PACKAGE, VERSION,
+    "Paul Rubin, Arnold Robbins, Jim Kingdon, David MacKenzie, and Randy Smith",
+                     usage);
+
   change_times = no_create = use_ref = posix_date = flexible_date = 0;
   newtime = (time_t) -1;
 
@@ -294,16 +291,6 @@ main (int argc, char **argv)
        }
     }
 
-  if (show_version)
-    {
-      printf ("touch (%s) %s\n", GNU_PACKAGE, VERSION);
-      close_stdout ();
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
-
   if (change_times == 0)
     change_times = CH_ATIME | CH_MTIME;