summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1999-03-04 05:36:10 +0000
committerJim Meyering <jim@meyering.net>1999-03-04 05:36:10 +0000
commit88cbad981787d34f3dc8118bde16416c12a50421 (patch)
tree1a8993c9e22726767a534efd76dd619bfc80752d /src
parent0ae96f236175101ddc6c8f0eaf46d08f88173486 (diff)
downloadcoreutils-88cbad981787d34f3dc8118bde16416c12a50421.tar.xz
Include long-options.h
[long_options]: Remove the "help" and "version" entries. Remove declarations of show_help and show_version. (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/cat.c21
-rw-r--r--src/cksum.c25
-rw-r--r--src/comm.c21
-rw-r--r--src/csplit.c23
-rw-r--r--src/cut.c23
-rw-r--r--src/expand.c21
-rw-r--r--src/fmt.c21
-rw-r--r--src/fold.c23
-rw-r--r--src/head.c21
-rw-r--r--src/nl.c23
-rw-r--r--src/od.c23
-rw-r--r--src/paste.c23
-rw-r--r--src/pr.c23
-rw-r--r--src/split.c23
-rw-r--r--src/sum.c21
-rw-r--r--src/tac.c21
-rw-r--r--src/tail.c24
-rw-r--r--src/tr.c21
-rw-r--r--src/unexpand.c21
-rw-r--r--src/uniq.c21
-rw-r--r--src/wc.c21
21 files changed, 96 insertions, 368 deletions
diff --git a/src/cat.c b/src/cat.c
index 5afae0da0..8e429a716 100644
--- a/src/cat.c
+++ b/src/cat.c
@@ -32,6 +32,7 @@
#endif
#include "system.h"
#include "error.h"
+#include "long-options.h"
#include "safe-read.h"
/* Undefine, to avoid warning about redefinition on some systems. */
@@ -510,12 +511,6 @@ main (int argc, char **argv)
/* If nonzero, call cat, otherwise call simple_cat to do the actual work. */
int options = 0;
- /* If nonzero, display usage information and exit. */
- static int show_help;
-
- /* If nonzero, print the version on standard output then exit. */
- static int show_version;
-
static struct option const long_options[] =
{
{"number-nonblank", no_argument, NULL, 'b'},
@@ -528,8 +523,6 @@ main (int argc, char **argv)
#if O_BINARY
{"binary", no_argument, NULL, 'B'},
#endif
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -538,6 +531,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "cat", GNU_PACKAGE, VERSION,
+ "Torbjorn Granlund and Richard M. Stallman", usage);
+
/* Parse command line options. */
while ((c = getopt_long (argc, argv,
@@ -619,15 +615,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("cat (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
output_desc = 1;
/* Get device, i-node number, and optimal blocksize of output. */
diff --git a/src/cksum.c b/src/cksum.c
index 01aba44e5..6d67585d9 100644
--- a/src/cksum.c
+++ b/src/cksum.c
@@ -12,8 +12,8 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* Written by Q. Frank Xia, qx@math.columbia.edu.
Cosmetic changes and reorganization by David MacKenzie, djm@gnu.ai.mit.edu.
@@ -108,6 +108,7 @@ main ()
# include <getopt.h>
# include <sys/types.h>
# include "system.h"
+# include "long-options.h"
# include "error.h"
/* Number of bytes to read at once. */
@@ -116,16 +117,8 @@ main ()
/* 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 then 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}
};
@@ -294,6 +287,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "cksum", GNU_PACKAGE, VERSION,
+ "Q. Frank Xia", usage);
+
have_read_stdin = 0;
while ((c = getopt_long (argc, argv, "", long_options, NULL)) != -1)
@@ -308,15 +304,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("cksum (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
if (optind >= argc)
{
if (cksum ("-", 0) < 0)
diff --git a/src/comm.c b/src/comm.c
index 9a04d05d9..a31e0a9b0 100644
--- a/src/comm.c
+++ b/src/comm.c
@@ -24,6 +24,7 @@
#include <sys/types.h>
#include "system.h"
#include "linebuffer.h"
+#include "long-options.h"
#include "error.h"
/* Undefine, to avoid warning about redefinition on some systems. */
@@ -42,16 +43,8 @@ static int only_file_2;
/* If nonzero, print lines that are found in both files. */
static int both;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output then 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}
};
@@ -221,6 +214,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "comm", GNU_PACKAGE, VERSION,
+ "Richard Stallman and David MacKenzie", usage);
+
only_file_1 = 1;
only_file_2 = 1;
both = 1;
@@ -247,15 +243,6 @@ main (int argc, char **argv)
usage (1);
}
- if (show_version)
- {
- printf ("comm (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
if (optind + 2 != argc)
usage (1);
diff --git a/src/csplit.c b/src/csplit.c
index fab4c9f4f..c52d90f20 100644
--- a/src/csplit.c
+++ b/src/csplit.c
@@ -31,9 +31,10 @@
#include <regex.h>
#include "error.h"
+#include "long-options.h"
+#include "safe-read.h"
#include "xstrtoul.h"
#include "xalloc.h"
-#include "safe-read.h"
#ifdef STDC_HEADERS
# include <stdlib.h>
@@ -202,12 +203,6 @@ static struct control *controls;
/* Number of elements in `controls'. */
static unsigned int control_used;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output then exit. */
-static int show_version;
-
static struct option const longopts[] =
{
{"digits", required_argument, NULL, 'n'},
@@ -217,8 +212,6 @@ static struct option const longopts[] =
{"elide-empty-files", no_argument, NULL, 'z'},
{"prefix", required_argument, NULL, 'f'},
{"suffix-format", required_argument, NULL, 'b'},
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -1379,6 +1372,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "csplit", GNU_PACKAGE, VERSION,
+ "Stuart Kemp and David MacKenzie", usage);
+
global_argv = argv;
controls = NULL;
control_used = 0;
@@ -1458,15 +1454,6 @@ main (int argc, char **argv)
usage (1);
}
- if (show_version)
- {
- printf ("csplit (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
if (argc - optind < 2)
{
error (0, 0, _("too few arguments"));
diff --git a/src/cut.c b/src/cut.c
index e8047c95e..257677efe 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -1,5 +1,5 @@
/* cut - remove parts of lines of files
- Copyright (C) 1984, 1997, 1998 by David M. Ihnat
+ Copyright (C) 1984, 1997, 1998, 1999 by David M. Ihnat
This program is a total rewrite of the Bell Laboratories Unix(Tm)
command of the same name, as of System V. It contains no proprietary
@@ -66,6 +66,7 @@
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "long-options.h"
#include "error.h"
char *xstrdup ();
@@ -168,12 +169,6 @@ static char *output_delimiter_string;
/* Nonzero if we have ever read standard input. */
static int have_read_stdin;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output then exit. */
-static int show_version;
-
static struct option const longopts[] =
{
{"bytes", required_argument, 0, 'b'},
@@ -182,8 +177,6 @@ static struct option const longopts[] =
{"delimiter", required_argument, 0, 'd'},
{"only-delimited", no_argument, 0, 's'},
{"output-delimiter", required_argument, 0, CHAR_MAX + 1},
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{0, 0, 0, 0}
};
@@ -696,6 +689,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "cut", GNU_PACKAGE, VERSION,
+ "David Ihnat, David MacKenzie, and Jim Meyering", usage);
+
operating_mode = undefined_mode;
/* By default, all non-delimited lines are printed. */
@@ -759,15 +755,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("cut (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
if (operating_mode == undefined_mode)
FATAL_ERROR (_("you must specify a list of bytes, characters, or fields"));
diff --git a/src/expand.c b/src/expand.c
index 20d74a91e..b0fe973fc 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -40,6 +40,7 @@
#include <sys/types.h>
#include "system.h"
#include "error.h"
+#include "long-options.h"
/* The number of bytes added at a time to the amount of memory
allocated for the output line. */
@@ -83,18 +84,10 @@ static int have_read_stdin;
/* Status to return to the system. */
static int exit_status;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output then exit. */
-static int show_version;
-
static struct option const longopts[] =
{
{"tabs", required_argument, NULL, 't'},
{"initial", no_argument, NULL, 'i'},
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -340,6 +333,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "expand", GNU_PACKAGE, VERSION,
+ "David MacKenzie", usage);
+
while ((c = getopt_long (argc, argv, "it:,0123456789", longopts, NULL)) != -1)
{
switch (c)
@@ -367,15 +363,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("expand (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
add_tabstop (tabval);
validate_tabstops (tab_list, first_free_tab);
diff --git a/src/fmt.c b/src/fmt.c
index 2aabbe96e..7aa973885 100644
--- a/src/fmt.c
+++ b/src/fmt.c
@@ -28,6 +28,7 @@
#include "system.h"
#include "error.h"
+#include "long-options.h"
#include "xstrtol.h"
/* The following parameters represent the program's idea of what is
@@ -164,12 +165,6 @@ static void put_space PARAMS ((int space));
/* The name this program was run with. */
const char *program_name;
-/* If nonzero, display usage information and exit. */
-static int show_help = 0;
-
-/* If nonzero, print the version on standard output and exit. */
-static int show_version = 0;
-
/* Option values. */
/* If TRUE, first 2 lines may have different indent (default FALSE). */
@@ -297,12 +292,10 @@ In -wNUMBER, the letter `w' may be omitted.\n"),
static const struct option long_options[] =
{
{"crown-margin", no_argument, NULL, 'c'},
- {"help", no_argument, &show_help, 1},
{"prefix", required_argument, NULL, 'p'},
{"split-only", no_argument, NULL, 's'},
{"tagged-paragraph", no_argument, NULL, 't'},
{"uniform-spacing", no_argument, NULL, 'u'},
- {"version", no_argument, &show_version, 1},
{"width", required_argument, NULL, 'w'},
{0, 0, 0, 0},
};
@@ -317,6 +310,9 @@ main (register int argc, register char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "fmt", GNU_PACKAGE, VERSION,
+ "Ross Paterson", usage);
+
crown = tagged = split = uniform = FALSE;
max_width = WIDTH;
prefix = "";
@@ -382,15 +378,6 @@ main (register int argc, register char **argv)
}
- if (show_version)
- {
- printf ("fmt (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
best_width = max_width * (2 * (100 - LEEWAY) + 1) / 200;
if (optind == argc)
diff --git a/src/fold.c b/src/fold.c
index 3997e3d08..aaa42afcb 100644
--- a/src/fold.c
+++ b/src/fold.c
@@ -24,8 +24,9 @@
#include <sys/types.h>
#include "system.h"
-#include "xstrtol.h"
#include "error.h"
+#include "long-options.h"
+#include "xstrtol.h"
/* The name this program was run with. */
char *program_name;
@@ -39,19 +40,11 @@ static int count_bytes;
/* If nonzero, at least one of the files we read was standard input. */
static int have_read_stdin;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output then exit. */
-static int show_version;
-
static struct option const longopts[] =
{
{"bytes", no_argument, NULL, 'b'},
{"spaces", no_argument, NULL, 's'},
{"width", required_argument, NULL, 'w'},
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -243,6 +236,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "fold", GNU_PACKAGE, VERSION,
+ "David MacKenzie", usage);
+
break_spaces = count_bytes = have_read_stdin = 0;
/* Turn any numeric options into -w options. */
@@ -291,15 +287,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("fold (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
if (argc == optind)
errs |= fold_file ("-", width);
else
diff --git a/src/head.c b/src/head.c
index 2933fee3b..8a4fdbe99 100644
--- a/src/head.c
+++ b/src/head.c
@@ -31,6 +31,7 @@
#include <sys/types.h>
#include "system.h"
#include "error.h"
+#include "long-options.h"
#include "xstrtoul.h"
#include "safe-read.h"
@@ -58,12 +59,6 @@ char *program_name;
/* Have we ever read standard input? */
static int have_read_stdin;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output then exit. */
-static int show_version;
-
static struct option const long_options[] =
{
{"bytes", required_argument, NULL, 'c'},
@@ -71,8 +66,6 @@ static struct option const long_options[] =
{"quiet", no_argument, NULL, 'q'},
{"silent", no_argument, NULL, 'q'},
{"verbose", no_argument, NULL, 'v'},
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -268,6 +261,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "head", GNU_PACKAGE, VERSION,
+ "David MacKenzie", usage);
+
have_read_stdin = 0;
print_headers = 0;
@@ -372,15 +368,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("head (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
if (header_mode == always
|| (header_mode == multiple_files && optind < argc - 1))
print_headers = 1;
diff --git a/src/nl.c b/src/nl.c
index e092e5109..4365686c8 100644
--- a/src/nl.c
+++ b/src/nl.c
@@ -24,12 +24,13 @@
#include <sys/types.h>
#include <getopt.h>
-#include "linebuffer.h"
#include "system.h"
#include <regex.h>
#include "error.h"
+#include "linebuffer.h"
+#include "long-options.h"
#include "xstrtol.h"
#ifndef TRUE
@@ -139,12 +140,6 @@ static int line_no;
/* Nonzero if we have ever read standard input. */
static int have_read_stdin;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output then exit. */
-static int show_version;
-
static struct option const longopts[] =
{
{"header-numbering", required_argument, NULL, 'h'},
@@ -158,8 +153,6 @@ static struct option const longopts[] =
{"number-width", required_argument, NULL, 'w'},
{"number-format", required_argument, NULL, 'n'},
{"section-delimiter", required_argument, NULL, 'd'},
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -452,6 +445,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "nl", GNU_PACKAGE, VERSION,
+ "Scott Bartram and David MacKenzie", usage);
+
have_read_stdin = 0;
while ((c = getopt_long (argc, argv, "h:b:f:v:i:pl:s:w:n:d:", longopts,
@@ -559,15 +555,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("nl (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
/* Initialize the section delimiters. */
c = strlen (section_del);
diff --git a/src/od.c b/src/od.c
index bfa623183..03eba9366 100644
--- a/src/od.c
+++ b/src/od.c
@@ -24,8 +24,9 @@
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
-#include "xstrtoul.h"
#include "error.h"
+#include "long-options.h"
+#include "xstrtoul.h"
#if defined(__GNUC__) || defined(STDC_HEADERS)
# include <float.h>
@@ -239,12 +240,6 @@ static enum size_spec integral_type_size[MAX_INTEGRAL_TYPE_SIZE + 1];
#define MAX_FP_TYPE_SIZE sizeof(LONG_DOUBLE)
static enum size_spec fp_type_size[MAX_FP_TYPE_SIZE + 1];
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output then exit. */
-static int show_version;
-
static struct option const long_options[] =
{
/* POSIX options. */
@@ -258,8 +253,6 @@ static struct option const long_options[] =
{"strings", optional_argument, NULL, 's'},
{"traditional", no_argument, NULL, 'B'},
{"width", optional_argument, NULL, 'w'},
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -1600,6 +1593,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "od", GNU_PACKAGE, VERSION,
+ "Jim Meyering", usage);
+
err = 0;
for (i = 0; i <= MAX_INTEGRAL_TYPE_SIZE; i++)
@@ -1769,15 +1765,6 @@ the maximum\nrepresentable value of type `long'"), optarg);
if (n_failed_decodes > 0)
exit (EXIT_FAILURE);
- if (show_version)
- {
- printf ("od (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
if (flag_dump_strings && n_specs > 0)
error (EXIT_FAILURE, 0,
_("no type may be specified when dumping strings"));
diff --git a/src/paste.c b/src/paste.c
index 21f7a0cb9..f5a3f8d6e 100644
--- a/src/paste.c
+++ b/src/paste.c
@@ -1,5 +1,5 @@
/* paste - merge lines of files
- Copyright (C) 1984, 1997, 1998 by David M. Ihnat
+ Copyright (C) 1984, 1997, 1998, 1999 by David M. Ihnat
This program is a total rewrite of the Bell Laboratories Unix(Tm)
command of the same name, as of System V. It contains no proprietary
@@ -45,6 +45,7 @@
#include <sys/types.h>
#include "system.h"
#include "error.h"
+#include "long-options.h"
/* Indicates that no delimiter should be added in the current position. */
#define EMPTY_DELIM '\0'
@@ -73,18 +74,10 @@ static char *delims;
/* A pointer to the character after the end of `delims'. */
static char *delim_end;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output then exit. */
-static int show_version;
-
static struct option const longopts[] =
{
{"serial", no_argument, 0, 's'},
{"delimiters", required_argument, 0, 'd'},
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{0, 0, 0, 0}
};
@@ -438,6 +431,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "paste", GNU_PACKAGE, VERSION,
+ "David M. Ihnat", usage);
+
have_read_stdin = 0;
serial_merge = 0;
delims = default_delims;
@@ -467,15 +463,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("paste (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
if (optind == argc)
argv[argc++] = "-";
diff --git a/src/pr.c b/src/pr.c
index 1b0c0a624..850bcef03 100644
--- a/src/pr.c
+++ b/src/pr.c
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-/* Author: Pete TerMaat. */
+/* By Pete TerMaat, with considerable refinement by Roland Huebner. */
/* Things to watch: Sys V screws up on ...
pr -n -3 -s: /usr/dict/words
@@ -175,6 +175,7 @@
#include <time.h>
#include "system.h"
#include "error.h"
+#include "long-options.h"
#include "xstrtol.h"
#ifndef TRUE
@@ -558,12 +559,6 @@ static char *header;
static int *clump_buff;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output then exit. */
-static int show_version;
-
/* True means we read the line no. lines_per_body in skip_read
called by skip_to_page. That variable controls the coincidence of a
"FF set by hand" and "full_page_printed", see above the definition of
@@ -576,8 +571,6 @@ static int test_suite;
static struct option const long_options[] =
{
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{"test", no_argument, &test_suite, 1},
{"pages", required_argument, NULL, CHAR_MAX + 1},
{"columns", required_argument, NULL, CHAR_MAX + 2},
@@ -689,6 +682,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "pr", GNU_PACKAGE, VERSION,
+ "Pete TerMaat and Roland Huebner", usage);
+
n_files = 0;
file_names = (argc > 1
? (char **) xmalloc ((argc - 1) * sizeof (char *))
@@ -881,15 +877,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("pr (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
if (parallel_files && explicit_columns)
error (EXIT_FAILURE, 0,
_("Cannot specify number of columns when printing in parallel."));
diff --git a/src/split.c b/src/split.c
index fbf332bfc..10bcd1770 100644
--- a/src/split.c
+++ b/src/split.c
@@ -29,8 +29,9 @@
#include "system.h"
#include "error.h"
-#include "xstrtol.h"
+#include "long-options.h"
#include "safe-read.h"
+#include "xstrtol.h"
int full_write ();
@@ -56,12 +57,6 @@ static int input_desc;
/* Descriptor on which output file is open. */
static int output_desc;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output then exit. */
-static int show_version;
-
/* If nonzero, print a diagnostic on standard error just before each
output file is opened. */
static int verbose;
@@ -72,8 +67,6 @@ static struct option const longopts[] =
{"lines", required_argument, NULL, 'l'},
{"line-bytes", required_argument, NULL, 'C'},
{"verbose", no_argument, NULL, 2},
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -349,6 +342,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "split", GNU_PACKAGE, VERSION,
+ "Torbjorn Granlund and Richard M. Stallman", usage);
+
/* Parse command line options. */
infile = "-";
@@ -449,15 +445,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("split (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
/* Handle default case. */
if (split_type == type_undef)
{
diff --git a/src/sum.c b/src/sum.c
index ddc2336a8..0a7d8ca4e 100644
--- a/src/sum.c
+++ b/src/sum.c
@@ -26,6 +26,7 @@
#include <getopt.h>
#include "system.h"
#include "error.h"
+#include "long-options.h"
#include "safe-read.h"
/* The name this program was run with. */
@@ -37,17 +38,9 @@ static int have_read_stdin;
/* Right-rotate 32-bit integer variable C. */
#define ROTATE_RIGHT(c) if ((c) & 01) (c) = ((c) >>1) + 0x8000; else (c) >>= 1;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output then exit. */
-static int show_version;
-
static struct option const longopts[] =
{
{"sysv", no_argument, NULL, 's'},
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -216,6 +209,9 @@ main (int argc, char **argv)
have_read_stdin = 0;
+ parse_long_options (argc, argv, "sum", GNU_PACKAGE, VERSION,
+ "Kayvan Aghaiepour and David MacKenzie", usage);
+
while ((optc = getopt_long (argc, argv, "rs", longopts, NULL)) != -1)
{
switch (optc)
@@ -236,15 +232,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("sum (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
files_given = argc - optind;
if (files_given == 0)
{
diff --git a/src/tac.c b/src/tac.c
index 3d9d9d314..79b4ecb48 100644
--- a/src/tac.c
+++ b/src/tac.c
@@ -45,6 +45,7 @@ tac -r -s '.\|
#include <regex.h>
#include "error.h"
+#include "long-options.h"
#include "safe-read.h"
#if defined __MSDOS__ || defined _WIN32
@@ -102,19 +103,11 @@ static unsigned G_buffer_size;
/* The compiled regular expression representing `separator'. */
static struct re_pattern_buffer compiled_separator;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output then exit. */
-static int show_version;
-
static struct option const longopts[] =
{
{"before", no_argument, NULL, 'b'},
{"regex", no_argument, NULL, 'r'},
{"separator", required_argument, NULL, 's'},
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -614,6 +607,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "tac", GNU_PACKAGE, VERSION,
+ "Jay Lepreau and David MacKenzie", usage);
+
errors = 0;
separator = "\n";
sentinel_length = 1;
@@ -641,15 +637,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("tac (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
if (sentinel_length == 0)
{
compiled_separator.allocated = 100;
diff --git a/src/tail.c b/src/tail.c
index 3f5095f30..7be926e46 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -32,9 +32,10 @@
#include "system.h"
#include "argmatch.h"
-#include "xstrtoul.h"
#include "error.h"
+#include "long-options.h"
#include "safe-read.h"
+#include "xstrtoul.h"
#ifndef OFF_T_MIN
# define OFF_T_MIN TYPE_MINIMUM (off_t)
@@ -160,12 +161,6 @@ static unsigned int sleep_interval = 1;
/* Nonzero if we have ever read standard input. */
static int have_read_stdin;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output then exit. */
-static int show_version;
-
static struct option const long_options[] =
{
{"allow-missing", no_argument, NULL, CHAR_MAX + 1},
@@ -178,8 +173,6 @@ static struct option const long_options[] =
{"silent", no_argument, NULL, 'q'},
{"sleep-interval", required_argument, NULL, 's'},
{"verbose", no_argument, NULL, 'v'},
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -1348,6 +1341,10 @@ main (int argc, char **argv)
have_read_stdin = 0;
+ parse_long_options (argc, argv, "tail", GNU_PACKAGE, VERSION,
+ "Paul Rubin, David MacKenzie, Ian Lance Taylor, and Jim Meyering",
+ usage);
+
{
int found_obsolescent;
int fail;
@@ -1366,15 +1363,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("tail (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
/* To start printing with item N_UNITS from the start of the file, skip
N_UNITS - 1 items. `tail +0' is actually meaningless, but for Unix
compatibility it's treated the same as `tail +1'. */
diff --git a/src/tr.c b/src/tr.c
index 061cabb4d..ae0055ac6 100644
--- a/src/tr.c
+++ b/src/tr.c
@@ -27,6 +27,7 @@
#include "system.h"
#include "error.h"
+#include "long-options.h"
#include "safe-read.h"
#define N_CHARS (UCHAR_MAX + 1)
@@ -298,20 +299,12 @@ static SET_TYPE in_delete_set[N_CHARS];
two specification strings and the delete switch is not given. */
static char xlate[N_CHARS];
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output then exit. */
-static int show_version;
-
static struct option const long_options[] =
{
{"complement", no_argument, NULL, 'c'},
{"delete", no_argument, NULL, 'd'},
{"squeeze-repeats", no_argument, NULL, 's'},
{"truncate-set1", no_argument, NULL, 't'},
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -1805,6 +1798,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "tr", GNU_PACKAGE, VERSION,
+ "Jim Meyering", usage);
+
while ((c = getopt_long (argc, argv, "cdst", long_options, NULL)) != -1)
{
switch (c)
@@ -1834,15 +1830,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("tr (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
posix_pedantic = (getenv ("POSIXLY_CORRECT") != NULL);
non_option_args = argc - optind;
diff --git a/src/unexpand.c b/src/unexpand.c
index 48276c4cc..9d508f995 100644
--- a/src/unexpand.c
+++ b/src/unexpand.c
@@ -42,6 +42,7 @@
#include <sys/types.h>
#include "system.h"
+#include "long-options.h"
#include "error.h"
/* The number of bytes added at a time to the amount of memory
@@ -86,18 +87,10 @@ static int have_read_stdin;
/* Status to return to the system. */
static int exit_status;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output then exit. */
-static int show_version;
-
static struct option const longopts[] =
{
{"tabs", required_argument, NULL, 't'},
{"all", no_argument, NULL, 'a'},
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -391,6 +384,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "unexpand", GNU_PACKAGE, VERSION,
+ "David MacKenzie", usage);
+
have_read_stdin = 0;
exit_status = 0;
convert_entire_line = 0;
@@ -425,15 +421,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("unexpand (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
add_tabstop (tabval);
validate_tabstops (tab_list, first_free_tab);
diff --git a/src/uniq.c b/src/uniq.c
index 5916ba9c2..5f664178b 100644
--- a/src/uniq.c
+++ b/src/uniq.c
@@ -25,6 +25,7 @@
#include "system.h"
#include "linebuffer.h"
+#include "long-options.h"
#include "error.h"
#include "xstrtol.h"
#include "memcasecmp.h"
@@ -69,12 +70,6 @@ static enum output_mode mode;
/* If nonzero, ignore case when comparing. */
static int ignore_case;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output then exit. */
-static int show_version;
-
static struct option const longopts[] =
{
{"count", no_argument, NULL, 'c'},
@@ -85,8 +80,6 @@ static struct option const longopts[] =
{"skip-fields", required_argument, NULL, 'f'},
{"skip-chars", required_argument, NULL, 's'},
{"check-chars", required_argument, NULL, 'w'},
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -291,6 +284,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "uniq", GNU_PACKAGE, VERSION,
+ "Richard Stallman and David MacKenzie", usage);
+
skip_chars = 0;
skip_fields = 0;
check_chars = 0;
@@ -379,15 +375,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("uniq (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
if (optind >= 2 && !STREQ (argv[optind - 1], "--"))
{
/* Interpret non-option arguments with leading `+' only
diff --git a/src/wc.c b/src/wc.c
index a105cafe2..97dc02520 100644
--- a/src/wc.c
+++ b/src/wc.c
@@ -29,6 +29,7 @@
#include "system.h"
#include "error.h"
#include "human.h"
+#include "long-options.h"
#include "safe-read.h"
/* Size of atomic reads. */
@@ -53,12 +54,6 @@ static int have_read_stdin;
/* The error code to return to the system. */
static int exit_status;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output then exits. */
-static int show_version;
-
static struct option const longopts[] =
{
{"bytes", no_argument, NULL, 'c'},
@@ -66,8 +61,6 @@ static struct option const longopts[] =
{"lines", no_argument, NULL, 'l'},
{"words", no_argument, NULL, 'w'},
{"max-line-length", no_argument, NULL, 'L'},
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -304,6 +297,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "wc", GNU_PACKAGE, VERSION,
+ "Paul Rubin and David MacKenzie", usage);
+
exit_status = 0;
print_lines = print_words = print_chars = print_linelength = 0;
total_lines = total_words = total_chars = max_line_length = 0;
@@ -334,15 +330,6 @@ main (int argc, char **argv)
usage (1);
}
- if (show_version)
- {
- printf ("wc (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (EXIT_SUCCESS);
- }
-
- if (show_help)
- usage (0);
-
if (print_lines + print_words + print_chars + print_linelength == 0)
print_lines = print_words = print_chars = 1;