diff options
author | Jim Meyering <jim@meyering.net> | 1993-04-29 05:26:22 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1993-04-29 05:26:22 +0000 |
commit | 2ff4fc16721b6caac08c16c851024b51b16a1824 (patch) | |
tree | 34d2aba87f63f370d03812e5c8660c2e84b3908e /src/wc.c | |
parent | 19272693f57193a57e5c4c66f65c791b2ee97378 (diff) | |
download | coreutils-2ff4fc16721b6caac08c16c851024b51b16a1824.tar.xz |
add --version and --help
Diffstat (limited to 'src/wc.c')
-rw-r--r-- | src/wc.c | 38 |
1 files changed, 32 insertions, 6 deletions
@@ -22,6 +22,7 @@ #include <getopt.h> #include <sys/types.h> #include "system.h" +#include "version.h" /* Size of atomic reads. */ #define BUFFER_SIZE (16 * 1024) @@ -32,6 +33,9 @@ static void wc (); static void wc_file (); static void write_counts (); +/* The name this program was run with. */ +char *program_name; + /* Cumulative number of lines, words, and chars in all files so far. */ static unsigned long total_lines, total_words, total_chars; @@ -41,21 +45,36 @@ static int print_lines, print_words, print_chars; /* Nonzero if we have ever read the standard input. */ static int have_read_stdin; -/* The name this program was run with. */ -char *program_name; - /* The error code to return to the system. */ static int exit_status; +/* 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 longopts[] = { {"bytes", no_argument, NULL, 'c'}, {"chars", no_argument, NULL, 'c'}, {"lines", no_argument, NULL, 'l'}, {"words", no_argument, NULL, 'w'}, + {"help", no_argument, &flag_help, 1}, + {"version", no_argument, &flag_version, 1}, {NULL, 0, NULL, 0} }; +static void +usage () +{ + fprintf (stderr, "\ +Usage: %s [-clw] [--bytes] [--chars] [--lines] [--words]\n\ + [--help] [--version] [file...]\n", + program_name); + exit (1); +} + void main (argc, argv) int argc; @@ -72,6 +91,9 @@ main (argc, argv) while ((optc = getopt_long (argc, argv, "clw", longopts, (int *) 0)) != EOF) switch (optc) { + case 0: + break; + case 'c': print_chars = 1; break; @@ -85,11 +107,15 @@ main (argc, argv) break; default: - fprintf (stderr, "\ -Usage: %s [-clw] [--bytes] [--chars] [--lines] [--words] [file...]\n", argv[0]); - exit (1); + usage (); } + if (flag_version) + fprintf (stderr, "%s\n", version_string); + + if (flag_help) + usage (); + if (print_lines + print_words + print_chars == 0) print_lines = print_words = print_chars = 1; |