Add option parsing via getopt, cleanup Makefile

This commit is contained in:
Michael Stapelberg 2008-10-07 15:33:54 +02:00
parent b9948793a5
commit 8f5d77d5e4
3 changed files with 26 additions and 7 deletions

View File

@ -1,7 +1,14 @@
wmiistatus: wmiistatus.c wmiistatus.h config.h config.c Makefile CFLAGS+=-Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare
gcc -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare -g -c -o wmiistatus.o wmiistatus.c CFLAGS+=-g
gcc -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare -g -c -o config.o config.c CFLAGS+=-DPREFIX=\"\"
gcc -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare -g -o wmiistatus *.o
wmiistatus: wmiistatus.o wmiistatus.h config.h config.o
clean:
rm *.o
distclean: clean
rm wmiistatus
install: install:
install -m 755 -d $(DESTDIR)/usr/bin install -m 755 -d $(DESTDIR)/usr/bin

View File

@ -179,7 +179,7 @@ int load_configuration(const char *configfile) {
fclose(handle); fclose(handle);
if (wmii_path == NULL) if (wmii_path == NULL)
die("No wmii_path specified in configuration file"); exit(-4);
return result; return result;
} }

View File

@ -49,6 +49,7 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <glob.h> #include <glob.h>
#include <dirent.h> #include <dirent.h>
#include <getopt.h>
#define _IS_WMIISTATUS_C #define _IS_WMIISTATUS_C
#include "wmiistatus.h" #include "wmiistatus.h"
@ -323,13 +324,24 @@ static bool process_runs(const char *path) {
return (stat(procbuf, &statbuf) >= 0); return (stat(procbuf, &statbuf) >= 0);
} }
int main(void) { int main(int argc, char *argv[]) {
char part[512], char part[512],
pathbuf[512], pathbuf[512],
*end; *end;
unsigned int i; 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(); cleanup_rbar_dir();
if (wlan_interface) if (wlan_interface)
create_file(concat(order[ORDER_WLAN],"wlan")); create_file(concat(order[ORDER_WLAN],"wlan"));