commit 117d7db63f8b0c6fb4c00f1003d2577538a9f517
Author:     Steve Ward <[email protected]>
AuthorDate: Fri May 1 21:40:49 2020 -0400
Commit:     Jan Klemkow <[email protected]>
CommitDate: Sun May 3 21:55:27 2020 +0200

    Add version option

diff --git a/config.mk b/config.mk
index 622cbdb..5676b85 100644
--- 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
index 25c5d1a..86241b8 100644
--- 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();

Reply via email to