summaryrefslogtreecommitdiff
path: root/src/split.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1993-04-29 05:26:22 +0000
committerJim Meyering <jim@meyering.net>1993-04-29 05:26:22 +0000
commit2ff4fc16721b6caac08c16c851024b51b16a1824 (patch)
tree34d2aba87f63f370d03812e5c8660c2e84b3908e /src/split.c
parent19272693f57193a57e5c4c66f65c791b2ee97378 (diff)
downloadcoreutils-2ff4fc16721b6caac08c16c851024b51b16a1824.tar.xz
add --version and --help
Diffstat (limited to 'src/split.c')
-rw-r--r--src/split.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/split.c b/src/split.c
index 980edf310..07b37aef9 100644
--- a/src/split.c
+++ b/src/split.c
@@ -25,6 +25,7 @@
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "version.h"
char *xmalloc ();
void error ();
@@ -38,7 +39,7 @@ static void cwrite ();
static void lines_split ();
static void next_file_name ();
-/* Name under which this program was invoked. */
+/* The name this program was run with. */
char *program_name;
/* Base name of output files. */
@@ -64,7 +65,23 @@ static int input_desc;
/* Descriptor on which output file is open. */
static int output_desc;
-
+
+/* 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", required_argument, NULL, 'b'},
+ {"lines", required_argument, NULL, 'l'},
+ {"line-bytes", required_argument, NULL, 'C'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
+ {NULL, 0, NULL, 0}
+};
+
static void
usage (reason)
char *reason;
@@ -74,18 +91,10 @@ usage (reason)
fprintf (stderr, "\
Usage: %s [-lines] [-l lines] [-b bytes[bkm]] [-C bytes[bkm]]\n\
[--lines=lines] [--bytes=bytes[bkm]] [--line-bytes=bytes[bkm]]\n\
- [infile [outfile-prefix]]\n",
+ [--help] [--version] [infile [outfile-prefix]]\n",
program_name);
exit (2);
}
-
-static struct option const longopts[] =
-{
- {"bytes", required_argument, NULL, 'b'},
- {"lines", required_argument, NULL, 'l'},
- {"line-bytes", required_argument, NULL, 'C'},
- {NULL, 0, NULL, 0}
-};
void
main (argc, argv)
@@ -123,6 +132,9 @@ main (argc, argv)
switch (c)
{
+ case 0:
+ break;
+
case 'b':
if (split_type != type_undef)
usage ("cannot split in more than one way");
@@ -172,6 +184,12 @@ main (argc, argv)
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
/* Handle default case. */
if (split_type == type_undef)
{