Kaynağa Gözat

Add version option

Steve Ward 5 yıl önce
ebeveyn
işleme
117d7db63f
2 değiştirilmiş dosya ile 11 ekleme ve 3 silme
  1. 1 1
      config.mk
  2. 10 2
      scroll.c

+ 1 - 1
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

+ 10 - 2
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();