summaryrefslogtreecommitdiff
path: root/src/tac.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/tac.c
parent19272693f57193a57e5c4c66f65c791b2ee97378 (diff)
downloadcoreutils-2ff4fc16721b6caac08c16c851024b51b16a1824.tar.xz
add --version and --help
Diffstat (limited to 'src/tac.c')
-rw-r--r--src/tac.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/tac.c b/src/tac.c
index 8f3c94aab..8107823e9 100644
--- a/src/tac.c
+++ b/src/tac.c
@@ -41,6 +41,7 @@ tac -r -s '.\|
#include <signal.h>
#include <regex.h>
#include "system.h"
+#include "version.h"
#ifndef STDC_HEADERS
char *malloc ();
@@ -101,14 +102,32 @@ static unsigned buffer_size;
/* The compiled regular expression representing `separator'. */
static struct re_pattern_buffer compiled_separator;
+/* 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[] =
{
{"before", no_argument, &separator_ends_record, 0},
{"regex", no_argument, &sentinel_length, 0},
{"separator", required_argument, NULL, 's'},
+ {"help", no_argument, &flag_help, 1},
+ {"version", no_argument, &flag_version, 1},
{NULL, 0, NULL, 0}
};
+static void
+usage ()
+{
+ fprintf (stderr, "\
+Usage: %s [-br] [-s separator] [--before] [--regex] [--separator=separator]\n\
+ [--help] [--version] [file...]\n",
+ program_name);
+ exit (1);
+}
+
void
main (argc, argv)
int argc;
@@ -143,14 +162,16 @@ main (argc, argv)
error (1, 0, "separator cannot be empty");
break;
default:
- fprintf (stderr, "\
-Usage: %s [-br] [-s separator] [--before] [--regex] [--separator=separator]\n\
- [file...]\n",
- program_name);
- exit (1);
+ usage ();
}
}
+ if (flag_version)
+ fprintf (stderr, "%s\n", version_string);
+
+ if (flag_help)
+ usage ();
+
if (sentinel_length == 0)
{
compiled_separator.allocated = 100;