From 2ff4fc16721b6caac08c16c851024b51b16a1824 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 29 Apr 1993 05:26:22 +0000 Subject: add --version and --help --- src/cat.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'src/cat.c') diff --git a/src/cat.c b/src/cat.c index a2b1c14af..044c9a971 100644 --- a/src/cat.c +++ b/src/cat.c @@ -29,6 +29,7 @@ #include #endif #include "system.h" +#include "version.h" #define max(h,i) ((h) > (i) ? (h) : (i)) @@ -82,7 +83,7 @@ usage (reason) fprintf (stderr, "\ Usage: %s [-benstuvAET] [--number] [--number-nonblank] [--squeeze-blank]\n\ [--show-nonprinting] [--show-ends] [--show-tabs] [--show-all]\n\ - [file...]\n", + [--help] [--version] [file...]\n", program_name); exit (2); @@ -132,8 +133,16 @@ main (argc, argv) int mark_line_ends = 0; int quote = 0; int output_tabs = 1; + +/* If non-zero, call cat, otherwise call simple_cat to do the actual work. */ int options = 0; + /* If non-zero, display usage information and exit. */ + static int flag_help; + + /* If non-zero, print the version on standard error. */ + static int flag_version; + static struct option const long_options[] = { {"number-nonblank", no_argument, NULL, 'b'}, @@ -143,6 +152,8 @@ main (argc, argv) {"show-ends", no_argument, NULL, 'E'}, {"show-tabs", no_argument, NULL, 'T'}, {"show-all", no_argument, NULL, 'A'}, + {"help", no_argument, &flag_help, 1}, + {"version", no_argument, &flag_version, 1}, {NULL, 0, NULL, 0} }; @@ -153,52 +164,62 @@ main (argc, argv) while ((c = getopt_long (argc, argv, "benstuvAET", long_options, (int *) 0)) != EOF) { - options++; switch (c) { + case 0: + break; + case 'b': + ++options; numbers = 1; numbers_at_empty_lines = 0; break; case 'e': + ++options; mark_line_ends = 1; quote = 1; break; case 'n': + ++options; numbers = 1; break; case 's': + ++options; squeeze_empty_lines = 1; break; case 't': + ++options; output_tabs = 0; quote = 1; break; case 'u': /* We provide the -u feature unconditionally. */ - options--; break; case 'v': + ++options; quote = 1; break; case 'A': + ++options; quote = 1; mark_line_ends = 1; output_tabs = 0; break; case 'E': + ++options; mark_line_ends = 1; break; case 'T': + ++options; output_tabs = 0; break; @@ -207,6 +228,12 @@ main (argc, argv) } } + if (flag_version) + fprintf (stderr, "%s\n", version_string); + + if (flag_help) + usage (); + output_desc = 1; /* Get device, i-node number, and optimal blocksize of output. */ @@ -278,8 +305,9 @@ main (argc, argv) goto contin; } - /* Select which version of `cat' to use. If any options (more than -u) - were specified, use `cat', otherwise use `simple_cat'. */ + /* Select which version of `cat' to use. If any options (more than -u, + --version, or --help) were specified, use `cat', otherwise use + `simple_cat'. */ if (options == 0) { -- cgit v1.2.3-54-g00ecf