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/uniq.c | |
parent | 19272693f57193a57e5c4c66f65c791b2ee97378 (diff) | |
download | coreutils-2ff4fc16721b6caac08c16c851024b51b16a1824.tar.xz |
add --version and --help
Diffstat (limited to 'src/uniq.c')
-rw-r--r-- | src/uniq.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/uniq.c b/src/uniq.c index 944727f81..b902602a5 100644 --- a/src/uniq.c +++ b/src/uniq.c @@ -25,6 +25,7 @@ #include <sys/types.h> #include "system.h" #include "linebuffer.h" +#include "version.h" #define min(x, y) ((x) < (y) ? (x) : (y)) @@ -36,6 +37,9 @@ static void check_file (); static void usage (); static void writeline (); +/* The name this program was run with. */ +char *program_name; + /* Number of fields to skip on each line when doing comparisons. */ static int skip_fields; @@ -65,8 +69,11 @@ enum output_mode /* Which lines to output. */ static enum output_mode mode; -/* The name this program was run with. */ -char *program_name; +/* 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[] = { @@ -76,6 +83,8 @@ 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, &flag_help, 1}, + {"version", no_argument, &flag_version, 1}, {NULL, 0, NULL, 0} }; @@ -99,6 +108,9 @@ main (argc, argv) { switch (optc) { + case 0: + break; + case '0': case '1': case '2': @@ -141,6 +153,12 @@ main (argc, argv) } } + if (flag_version) + fprintf (stderr, "%s\n", version_string); + + if (flag_help) + usage (); + while (optind < argc && argv[optind][0] == '+') skip_chars = atoi (argv[optind++]); @@ -314,7 +332,7 @@ usage () Usage: %s [-cdu] [-f skip-fields] [-s skip-chars] [-w check-chars]\n\ [-#skip-fields] [+#skip-chars] [--count] [--repeated] [--unique]\n\ [--skip-fields=skip-fields] [--skip-chars=skip-chars]\n\ - [--check-chars=check-chars] [infile] [outfile]\n", + [--check-chars=check-chars] [--help] [--version] [infile] [outfile]\n", program_name); exit (1); } |