summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1999-03-04 05:09:05 +0000
committerJim Meyering <jim@meyering.net>1999-03-04 05:09:05 +0000
commit61fa70ac19d9202f6509e97e4bda1f4ab8f5d1fd (patch)
tree1fb89b9b511548ea40a899b6c60f1371cf6123f4 /src
parentd0bdbe00ba72224915a61589a399bc0e86d74d80 (diff)
downloadcoreutils-61fa70ac19d9202f6509e97e4bda1f4ab8f5d1fd.tar.xz
Include long-options.h
[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.
Diffstat (limited to 'src')
-rw-r--r--src/chgrp.c26
-rw-r--r--src/chmod.c26
-rw-r--r--src/chown.c24
-rw-r--r--src/cp.c29
-rw-r--r--src/dd.c24
-rw-r--r--src/df.c31
-rw-r--r--src/dircolors.c6
-rw-r--r--src/du.c42
-rw-r--r--src/install.c30
-rw-r--r--src/ln.c24
-rw-r--r--src/ls.c41
-rw-r--r--src/mkdir.c26
-rw-r--r--src/mkfifo.c24
-rw-r--r--src/mknod.c24
-rw-r--r--src/mv.c28
-rw-r--r--src/rm.c25
-rw-r--r--src/rmdir.c22
-rw-r--r--src/shred.c24
-rw-r--r--src/sync.c3
-rw-r--r--src/touch.c27
20 files changed, 130 insertions, 376 deletions
diff --git a/src/chgrp.c b/src/chgrp.c
index 19d233c69..109edbc57 100644
--- a/src/chgrp.c
+++ b/src/chgrp.c
@@ -24,11 +24,12 @@
#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"));
diff --git a/src/chmod.c b/src/chmod.c
index 66537ca1e..c2d978dad 100644
--- a/src/chmod.c
+++ b/src/chmod.c
@@ -22,12 +22,13 @@
#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++;
diff --git a/src/chown.c b/src/chown.c
index d74ea74c6..49e6f932c 100644
--- a/src/chown.c
+++ b/src/chown.c
@@ -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"));
diff --git a/src/cp.c b/src/cp.c
index 26c21f6d1..bdc399b8a 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -28,14 +28,15 @@
#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"));
diff --git a/src/dd.c b/src/dd.c
index 9f21bb9fa..f63688f3a 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -29,10 +29,11 @@
#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)
diff --git a/src/df.c b/src/df.c
index 0a43f07c0..8ebe412da 100644
--- a/src/df.c
+++ b/src/df.c
@@ -28,14 +28,15 @@
#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;
diff --git a/src/dircolors.c b/src/dircolors.c
index cfed5c43d..f69e931cf 100644
--- a/src/dircolors.c
+++ b/src/dircolors.c
@@ -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)
diff --git a/src/du.c b/src/du.c
index be8c227cb..dfa4bd5a6 100644
--- a/src/du.c
+++ b/src/du.c
@@ -51,14 +51,15 @@
#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)
diff --git a/src/install.c b/src/install.c
index 757a710aa..71de8e41b 100644
--- a/src/install.c
+++ b/src/install.c
@@ -73,15 +73,16 @@
#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,
diff --git a/src/ln.c b/src/ln.c
index e60cc6e74..9f3fd8e8f 100644
--- 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"));
diff --git a/src/ls.c b/src/ls.c
index 7cbfadbd8..17a0b33f1 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -63,17 +63,18 @@
#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 ();
diff --git a/src/mkdir.c b/src/mkdir.c
index 18013671b..e201a7ead 100644
--- a/src/mkdir.c
+++ b/src/mkdir.c
@@ -23,10 +23,11 @@
#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"));
diff --git a/src/mkfifo.c b/src/mkfifo.c
index 3b09a55c8..09c05e372 100644
--- a/src/mkfifo.c
+++ b/src/mkfifo.c
@@ -28,24 +28,17 @@
#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"));
diff --git a/src/mknod.c b/src/mknod.c
index a813b9f7e..96bc4befd 100644
--- a/src/mknod.c
+++ b/src/mknod.c
@@ -33,25 +33,18 @@
#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)
{
diff --git a/src/mv.c b/src/mv.c
index 89f0feba7..b56d4d4b7 100644
--- a/src/mv.c
+++ b/src/mv.c
@@ -48,13 +48,14 @@
#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
diff --git a/src/rm.c b/src/rm.c
index 1642ec3fb..1dbdfbbf7 100644
--- a/src/rm.c
+++ b/src/rm.c
@@ -49,23 +49,18 @@
#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)
diff --git a/src/rmdir.c b/src/rmdir.c
index 705048428..81e437e9f 100644
--- a/src/rmdir.c
+++ b/src/rmdir.c
@@ -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"));
diff --git a/src/shred.c b/src/shred.c
index 14478c67a..67462868b 100644
--- a/src/shred.c
+++ b/src/shred.c
@@ -63,9 +63,10 @@
#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;
diff --git a/src/sync.c b/src/sync.c
index 43ec1fab1..2d9e588a0 100644
--- a/src/sync.c
+++ b/src/sync.c
@@ -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"));
diff --git a/src/touch.c b/src/touch.c
index 9a366c274..b8435ce91 100644
--- a/src/touch.c
+++ b/src/touch.c
@@ -24,12 +24,13 @@
#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;