]> git.sur5r.net Git - i3/i3status/commitdiff
Add option parsing via getopt, cleanup Makefile
authorMichael Stapelberg <michael+x200@stapelberg.de>
Tue, 7 Oct 2008 13:33:54 +0000 (15:33 +0200)
committerMichael Stapelberg <michael+x200@stapelberg.de>
Tue, 7 Oct 2008 13:33:54 +0000 (15:33 +0200)
Makefile
config.c
wmiistatus.c

index dc58c46e5fe1e8226a4f445fd24ba78b781a8767..3640b273c1c1b4a6d1ec45a2f895728d271cd016 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,14 @@
-wmiistatus: wmiistatus.c wmiistatus.h config.h config.c Makefile
-       gcc -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare -g -c -o wmiistatus.o wmiistatus.c
-       gcc -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare -g -c -o config.o config.c
-       gcc -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare -g -o wmiistatus *.o
+CFLAGS+=-Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare
+CFLAGS+=-g
+CFLAGS+=-DPREFIX=\"\"
+
+wmiistatus: wmiistatus.o wmiistatus.h config.h config.o
+
+clean:
+       rm *.o
+
+distclean: clean
+       rm wmiistatus
 
 install:
        install -m 755 -d $(DESTDIR)/usr/bin
index aa7973e0009296e0109d2734d9bd6925a1d44162..da1d387f589e02fc0bc5fa16162aa5a9aa474e41 100644 (file)
--- a/config.c
+++ b/config.c
@@ -179,7 +179,7 @@ int load_configuration(const char *configfile) {
        fclose(handle);
 
        if (wmii_path == NULL)
-               die("No wmii_path specified in configuration file");
+               exit(-4);
 
        return result;
 }
index 714da1a9c7b78d7ffee36f9164bb67592cec56d1..1dd551e006eac5056d9faa0242a3b9f38cddeca9 100644 (file)
@@ -49,6 +49,7 @@
 #include <arpa/inet.h>
 #include <glob.h>
 #include <dirent.h>
+#include <getopt.h>
 
 #define _IS_WMIISTATUS_C
 #include "wmiistatus.h"
@@ -323,13 +324,24 @@ static bool process_runs(const char *path) {
        return (stat(procbuf, &statbuf) >= 0);
 }
 
-int main(void) {
+int main(int argc, char *argv[]) {
        char part[512],
             pathbuf[512],
             *end;
        unsigned int i;
 
-       load_configuration("/etc/wmiistatus.conf");
+       char *configfile = PREFIX "/etc/wmiistatus.conf";
+       int o, option_index = 0;
+       struct option long_options[] = {
+               {"config", required_argument, 0, 'c'},
+               {0, 0, 0, 0}
+       };
+
+       while ((o = getopt_long(argc, argv, "c:", long_options, &option_index)) != -1)
+               if ((char)o == 'c')
+                       configfile = optarg;
+
+       load_configuration(configfile);
        cleanup_rbar_dir();
        if (wlan_interface)
                create_file(concat(order[ORDER_WLAN],"wlan"));