From 2ff4fc16721b6caac08c16c851024b51b16a1824 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 29 Apr 1993 05:26:22 +0000 Subject: add --version and --help --- src/fold.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'src/fold.c') diff --git a/src/fold.c b/src/fold.c index fcdd885b1..ca20a2839 100644 --- a/src/fold.c +++ b/src/fold.c @@ -24,10 +24,14 @@ #include #include #include "system.h" +#include "version.h" char *xrealloc (); void error (); +/* The name this program was run with. */ +char *program_name; + static int adjust_column (); static int fold_file (); @@ -40,17 +44,32 @@ static int count_bytes; /* If nonzero, at least one of the files we read was 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[] = { {"bytes", no_argument, NULL, 'b'}, {"spaces", no_argument, NULL, 's'}, {"width", required_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 [-bs] [-w width] [--bytes] [--spaces] [--width=width]\n\ + [--help] [--version] [file...]\n", + program_name); + exit (1); +} + void main (argc, argv) int argc; @@ -69,6 +88,9 @@ main (argc, argv) { switch (optc) { + case 0: + break; + case 'b': /* Count bytes rather than columns. */ count_bytes = 1; break; @@ -84,13 +106,16 @@ main (argc, argv) break; default: - fprintf (stderr, "\ -Usage: %s [-bs] [-w width] [--bytes] [--spaces] [--width=width] [file...]\n", - argv[0]); - exit (1); + usage (); } } + if (flag_version) + fprintf (stderr, "%s\n", version_string); + + if (flag_help) + usage (); + if (argc == optind) errs |= fold_file ("-", width); else -- cgit v1.2.3-54-g00ecf