commit 117d7db63f8b0c6fb4c00f1003d2577538a9f517
parent cbafbee9b7f97f09490e39a4994434e1c2008b0f
Author: Steve Ward <planet36@gmail.com>
Date: Fri, 1 May 2020 21:40:49 -0400
Add version option
Diffstat:
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/config.mk b/config.mk
@@ -6,7 +6,7 @@ PREFIX = /usr/local
BINDIR = $(PREFIX)/bin
MANDIR = $(PREFIX)/share/man
-CPPFLAGS = -D_DEFAULT_SOURCE
+CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_DEFAULT_SOURCE
# if your system is not POSIX, add -std=c99 to CFLAGS
CFLAGS = -Os
LDFLAGS = -s
diff --git a/scroll.c b/scroll.c
@@ -47,6 +47,8 @@
#define LENGTH(X) (sizeof (X) / sizeof ((X)[0]))
+const char *argv0;
+
TAILQ_HEAD(tailhead, line) head;
struct line {
@@ -402,7 +404,7 @@ jumpdown(char *buf, size_t size)
void
usage(void) {
- die("usage: scroll [-Mh] [-m mem] [program]");
+ die("usage: %s [-Mvh] [-m mem] [program]", argv0);
}
int
@@ -411,10 +413,13 @@ main(int argc, char *argv[])
int ch;
struct rlimit rlimit;
+ argv0 = argv[0];
+
if (getrlimit(RLIMIT_DATA, &rlimit) == -1)
die("getrlimit");
- while ((ch = getopt(argc, argv, "Mm:h")) != -1) {
+ const char *optstring = "Mm:vh";
+ while ((ch = getopt(argc, argv, optstring)) != -1) {
switch (ch) {
case 'M':
rlimit.rlim_cur = rlimit.rlim_max;
@@ -424,6 +429,9 @@ main(int argc, char *argv[])
if (errno != 0)
die("strtoull: %s", optarg);
break;
+ case 'v':
+ die("%s " VERSION, argv0);
+ break;
case 'h':
default:
usage();