Skip to contentSkip to conversation

- add --version to command line

PATCH New Joe Perches 1 participant 1 message Apr 30, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 - add --version to command line

sparse doesn't support --version.
Perhaps a patch like this is acceptable?

Makefile +1 -0
index 3eab17e..dfcb6b7 100644
@@ -5,6 +5,7 @@ OS ?= linux
 CC ?= gcc
 CFLAGS ?= -O2 -finline-functions -fno-strict-aliasing -g
 CFLAGS += -Wall -Wwrite-strings
+CFLAGS += -DSPARSE_VERSION=$(VERSION)
 LDFLAGS ?= -g
 AR ?= ar
 
lib.c +18 -1
index 0abcc9a..7f29174 100644
@@ -823,6 +823,19 @@ static struct symbol_list *sparse_initial(void)
 	return sparse_tokenstream(token);
 }
 
+#define stringize_1(x)	#x
+#define stringize(x)		stringize_1(x)
+
+static void handle_version(char *name)
+{
+	char* exe = strrchr(name, '/');
+	if (exe)
+		exe++;
+	else
+		exe = name;
+	die("%s %s", exe, stringize(SPARSE_VERSION));
+}
+
 struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list **filelist)
 {
 	char **args;
@@ -838,7 +851,11 @@ struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list
 			break;
 
 		if (arg[0] == '-' && arg[1]) {
-			args = handle_switch(arg+1, args);
+			if (!strcmp("-version", &arg[1])) {
+				handle_version(argv[0]);
+			} else {
+				args = handle_switch(arg+1, args);
+			}
 			continue;
 		}
 		add_ptr_list_notag(filelist, arg);