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/csplit.c | |
parent | 19272693f57193a57e5c4c66f65c791b2ee97378 (diff) | |
download | coreutils-2ff4fc16721b6caac08c16c851024b51b16a1824.tar.xz |
add --version and --help
Diffstat (limited to 'src/csplit.c')
-rw-r--r-- | src/csplit.c | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/src/csplit.c b/src/csplit.c index 8d27ce03f..e5b6ed68d 100644 --- a/src/csplit.c +++ b/src/csplit.c @@ -24,6 +24,7 @@ #include <signal.h> #include "regex.h" #include "system.h" +#include "version.h" #ifdef STDC_HEADERS #include <stdlib.h> @@ -118,6 +119,9 @@ struct buffer_record struct buffer_record *next; }; +/* The name this program was run with. */ +char *program_name; + /* Input file descriptor. */ static int input_desc = 0; @@ -179,8 +183,23 @@ static struct control *controls; /* Number of elements in `controls'. */ static unsigned control_used; -/* 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[] = +{ + {"digits", required_argument, NULL, 'n'}, + {"quiet", no_argument, NULL, 's'}, + {"silent", no_argument, NULL, 's'}, + {"keep-files", no_argument, NULL, 'k'}, + {"prefix", required_argument, NULL, 'f'}, + {"help", no_argument, &flag_help, 1}, + {"version", no_argument, &flag_version, 1}, + {NULL, 0, NULL, 0} +}; /* Allocate N bytes of memory dynamically, with error checking. */ @@ -1191,16 +1210,6 @@ interrupt_handler () cleanup (); } -static struct option const longopts[] = -{ - {"digits", required_argument, NULL, 'n'}, - {"quiet", no_argument, NULL, 's'}, - {"silent", no_argument, NULL, 's'}, - {"keep-files", no_argument, NULL, 'k'}, - {"prefix", required_argument, NULL, 'f'}, - {NULL, 0, NULL, 0} -}; - void main (argc, argv) int argc; @@ -1254,6 +1263,9 @@ main (argc, argv) != EOF) switch (optc) { + case 0: + break; + case 'f': prefix = optarg; break; @@ -1275,6 +1287,12 @@ main (argc, argv) usage (); } + if (flag_version) + fprintf (stderr, "%s\n", version_string); + + if (flag_help) + usage (); + if (optind >= argc - 1) usage (); @@ -1300,7 +1318,8 @@ usage () { fprintf (stderr, "\ Usage: %s [-sk] [-f prefix] [-n digits] [--prefix=prefix]\n\ - [--digits=digits] [--quiet] [--silent] [--keep-files] file pattern...\n", + [--digits=digits] [--quiet] [--silent] [--keep-files]\n\ + [--help] [--version] file pattern...\n", program_name); exit (1); } |