summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2019-10-28 19:14:29 -0600
committerAaron Ball <nullspoon@oper.io>2019-10-28 19:14:29 -0600
commit97410850f9d8ffd6846bd8f19ecf9e7e5d9cb48e (patch)
tree698bbf23a1d76bf97efb9a3fa0ab14ab98f570f0
parent037736c60d3361b1acae57ed1e8913ba0ac4c9b7 (diff)
downloadluminous-97410850f9d8ffd6846bd8f19ecf9e7e5d9cb48e.tar.gz
luminous-97410850f9d8ffd6846bd8f19ecf9e7e5d9cb48e.tar.xz
Add version support
Initial commit at version 1.1.0-rc1. This adds support for the -V,--version switches to print current program version to stdout.
-rw-r--r--Makefile10
-rw-r--r--src/main.c31
2 files changed, 35 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 15186c0..1497243 100644
--- a/Makefile
+++ b/Makefile
@@ -5,10 +5,18 @@ BINDIR=/usr/bin
INITDIR=/etc/rc.d
CONFDIR=/etc/
+VERSION = 1
+PATCHLEVEL = 1
+SUBLEVEL = 0
+EXTRAVERSION = -rc1
+
+VERSTR = "$(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL))$(EXTRAVERSION)"
+
+
all:
if [ ! -d obj ]; then mkdir obj; fi
cc $(CCOPTS) $(DBG) src/config.c -c -o obj/config.o
- cc $(CCOPTS) $(DBG) obj/*.o src/main.c -o luminous
+ cc $(CCOPTS) $(DBG) -DVERSTR=$(VERSTR) obj/*.o src/main.c -o luminous
install:
install -D luminous ${DESTDIR}/${BINDIR}/luminous
diff --git a/src/main.c b/src/main.c
index f3ab73a..5a790e2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,6 +24,10 @@
#define CONF "/etc/luminous.conf"
+// For string macros
+#define xstr(s) str(s)
+#define str(s) #s
+
struct props {
int lvl;
@@ -48,6 +52,19 @@ void props_new(struct props* p) {
/**
+ * version_print:
+ * @fd File descriptor to print version information to
+ *
+ * Prints version information for the current build to the specified file
+ * descriptor.
+ * NOTE: Version information is pulled from a macro defined by the Makefile.
+ */
+void version_print(FILE* fd) {
+ fprintf(fd, "luminous %s\n", xstr(VERSTR));
+}
+
+
+/**
* fgeti:
* @path
*
@@ -177,11 +194,12 @@ void usage() {
" luminous --rate 10 --step 8 --level [+-]400\n"
"\n"
"Arguments:\n"
-" -h,--help Print this helptext\n"
-" -s,--step Fade step (default: 6)\n"
-" -r,--rate Time in milliseconds between fade steps (default: 10)\n"
-" -l,--level Brightness level to change to. Supports absolute values and\n"
-" relative values prefixed with + and -."
+" -h,--help Print this helptext\n"
+" -s,--step Fade step (default: 6)\n"
+" -r,--rate Time in milliseconds between fade steps (default: 10)\n"
+" -l,--level Brightness level to change to. Supports absolute values and\n"
+" relative values prefixed with + and -.\n"
+" -V,--version Print program version"
"\n\n"
);
}
@@ -226,6 +244,9 @@ int parseargs(struct props* out, int argc, char* argv[]) {
} else {
out->lvl = atoi(argv[i]);
}
+ } else if(strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) {
+ version_print(stdout);
+ return -2;
} else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
usage();
return -2;

Generated by cgit