[hackers] [scroll][PATCH] Add version option

From: Steve Ward <planet36_AT_gmail.com>
Date: Fri, 1 May 2020 21:40:49 -0400

---
 config.mk |  2 +-
 scroll.c  | 12 ++++++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/config.mk b/config.mk
index 622cbdb..5676b85 100644
--- a/config.mk
+++ b/config.mk
_AT_@ -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
_AT_@ -47,6 +47,8 @@
 
 #define LENGTH(X)	(sizeof (X) / sizeof ((X)[0]))
 
+const char *argv0;
+
 TAILQ_HEAD(tailhead, line) head;
 
 struct line {
_AT_@ -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
_AT_@ -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;
_AT_@ -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();
-- 
2.20.1
Received on Sat May 02 2020 - 03:40:49 CEST

This archive was generated by hypermail 2.3.0 : Sat May 02 2020 - 03:48:37 CEST