summaryrefslogtreecommitdiff
path: root/src/cat.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/cat.c
parent19272693f57193a57e5c4c66f65c791b2ee97378 (diff)
downloadcoreutils-2ff4fc16721b6caac08c16c851024b51b16a1824.tar.xz
add --version and --help
Diffstat (limited to 'src/cat.c')
-rw-r--r--src/cat.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/cat.c b/src/cat.c
index a2b1c14af..044c9a971 100644
--- a/src/cat.c
+++ b/src/cat.c
@@ -29,6 +29,7 @@
#include <sys/ioctl.h>
#endif
#include "system.h"
+#include "version.h"
#define max(h,i) ((h) > (i) ? (h) : (i))
@@ -82,7 +83,7 @@ usage (reason)
fprintf (stderr, "\
Usage: %s [-benstuvAET] [--number] [--number-nonblank] [--squeeze-blank]\n\
[--show-nonprinting] [--show-ends] [--show-tabs] [--show-all]\n\
- [file...]\n",
+ [--help] [--version] [file...]\n",
program_name);
exit (2);
@@ -132,8 +133,16 @@ main (argc, argv)
int mark_line_ends = 0;
int quote = 0;
int output_tabs = 1;
+
+/* If non-zero, call cat, otherwise call simple_cat to do the actual work. */
int options = 0;
+ /* 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 long_options[] =
{
{"number-nonblank", no_argument, NULL, 'b'},
@@ -143,6 +152,8 @@ main (argc, argv)
{"show-ends", no_argument, NULL, 'E'},
{"show-tabs", no_argument, NULL, 'T'},
{"show-all", no_argument, NULL, 'A'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
@@ -153,52 +164,62 @@ main (argc, argv)
while ((c = getopt_long (argc, argv, "benstuvAET", long_options, (int *) 0))
!= EOF)
{
- options++;
switch (c)
{
+ case 0:
+ break;
+
case 'b':
+ ++options;
numbers = 1;
numbers_at_empty_lines = 0;
break;
case 'e':
+ ++options;
mark_line_ends = 1;
quote = 1;
break;
case 'n':
+ ++options;
numbers = 1;
break;
case 's':
+ ++options;
squeeze_empty_lines = 1;
break;
case 't':
+ ++options;
output_tabs = 0;
quote = 1;
break;
case 'u':
/* We provide the -u feature unconditionally. */
- options--;
break;
case 'v':
+ ++options;
quote = 1;
break;
case 'A':
+ ++options;
quote = 1;
mark_line_ends = 1;
output_tabs = 0;
break;
case 'E':
+ ++options;
mark_line_ends = 1;
break;
case 'T':
+ ++options;
output_tabs = 0;
break;
@@ -207,6 +228,12 @@ main (argc, argv)
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
output_desc = 1;
/* Get device, i-node number, and optimal blocksize of output. */
@@ -278,8 +305,9 @@ main (argc, argv)
goto contin;
}
- /* Select which version of `cat' to use. If any options (more than -u)
- were specified, use `cat', otherwise use `simple_cat'. */
+ /* Select which version of `cat' to use. If any options (more than -u,
+ --version, or --help) were specified, use `cat', otherwise use
+ `simple_cat'. */
if (options == 0)
{