From 8f5d77d5e4d979acf21507c0e764a11709de8db5 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 7 Oct 2008 15:33:54 +0200 Subject: Add option parsing via getopt, cleanup Makefile --- Makefile | 15 +++++++++++---- config.c | 2 +- wmiistatus.c | 16 ++++++++++++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index dc58c46..3640b27 100644 --- 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 diff --git a/config.c b/config.c index aa7973e..da1d387 100644 --- 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; } diff --git a/wmiistatus.c b/wmiistatus.c index 714da1a..1dd551e 100644 --- a/wmiistatus.c +++ b/wmiistatus.c @@ -49,6 +49,7 @@ #include #include #include +#include #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")); -- cgit v1.2.3