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/cut.c | |
parent | 19272693f57193a57e5c4c66f65c791b2ee97378 (diff) | |
download | coreutils-2ff4fc16721b6caac08c16c851024b51b16a1824.tar.xz |
add --version and --help
Diffstat (limited to 'src/cut.c')
-rw-r--r-- | src/cut.c | 31 |
1 files changed, 25 insertions, 6 deletions
@@ -64,6 +64,7 @@ #include <getopt.h> #include <sys/types.h> #include "system.h" +#include "version.h" char *xmalloc (); char *xrealloc (); @@ -119,6 +120,9 @@ enum operating_mode field_mode }; +/* The name this program was run with. */ +char *program_name; + static enum operating_mode operating_mode; /* If nonzero, @@ -131,8 +135,11 @@ static unsigned char delim; /* Nonzero if we have ever read standard input. */ static int have_read_stdin; -/* 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[] = { @@ -141,6 +148,8 @@ static struct option const longopts[] = {"fields", required_argument, 0, 'f'}, {"delimiter", required_argument, 0, 'd'}, {"only-delimited", no_argument, 0, 's'}, + {"help", no_argument, &flag_help, 1}, + {"version", no_argument, &flag_version, 1}, {0, 0, 0, 0} }; @@ -172,6 +181,9 @@ main (argc, argv) { switch (optc) { + case 0: + break; + case 'b': case 'c': /* Build the byte list. */ @@ -212,6 +224,12 @@ main (argc, argv) } } + if (flag_version) + fprintf (stderr, "%s\n", version_string); + + if (flag_help) + usage (); + if (operating_mode == undefined_mode) usage (); @@ -570,10 +588,11 @@ static void usage () { fprintf (stderr, "\ -Usage: %s {-b byte-list,--bytes=byte-list} [-n] [file...]\n\ - %s {-c character-list,--characters=character-list} [file...]\n\ - %s {-f field-list,--fields=field-list} [-d delim] [-s]\n\ - [--delimiter=delim] [--only-delimited] [file...]\n", +Usage: %s {-b byte-list,--bytes=byte-list} [-n] [file...] <options> \n\ + %s {-c character-list,--characters=character-list} <options> [file...]\n\ + %s {-f field-list,--fields=field-list} [-d delim] [-s] \n\ + [--delimiter=delim] [--only-delimited] <options> [file...]\n\ + Options: [--help] [--version]\n", program_name, program_name, program_name); exit (2); } |