From 8cff633cec69c31d3af6fe6ac7727046188661f6 Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Wed, 28 Jul 2010 17:13:59 -0700 Subject: [PATCH] - getopted. - remove old dist target conflict. --- Makefile | 2 -- corewatcher.c | 49 ++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 57e9365..355f80d 100644 --- a/Makefile +++ b/Makefile @@ -43,8 +43,6 @@ clean: rm -f *~ *.o *.ko DEADJOE corewatcher corewatcher-applet *.out */*~ corewatcher.8.gz @(cd po/ && $(MAKE) $@) -dist: clean - rm -rf .git .gitignore push.sh .*~ */*~ test/*dbg install-system: corewatcher.8.gz -mkdir -p $(DESTDIR)$(MANDIR) diff --git a/corewatcher.c b/corewatcher.c index b7d3ce9..1adb8af 100644 --- a/corewatcher.c +++ b/corewatcher.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -50,11 +51,28 @@ #include "corewatcher.h" + +static struct option opts[] = { + { "nodaemon", 0, NULL, 'n' }, + { "debug", 0, NULL, 'd' }, + { "help", 0, NULL, 'h' }, + { 0, 0, NULL, 0 } +}; + + static DBusConnection *bus; int pinged; int testmode; +static void usage(const char *name) +{ + printf("Usage: %s [OPTIONS...]\n", name); + printf(" -n, --nodaemon Do not daemonize, run in foreground\n"); + printf(" -d, --debug Enable debug mode\n"); + printf(" -h, --help Display this help message\n"); +} + static DBusHandlerResult got_message( DBusConnection __unused *conn, DBusMessage *message, @@ -143,13 +161,30 @@ int main(int argc, char**argv) read_config_file("/etc/corewatcher.conf"); - if (argc > 1 && strstr(argv[1], "--nodaemon")) - godaemon = 0; - if (argc > 1 && strstr(argv[1], "--debug")) { - printf("Starting corewatcher in debug mode\n"); - godaemon = 0; - testmode = 1; - opted_in = 2; + while (1) { + int c; + int i; + + c = getopt_long(argc, argv, "dnh", opts, &i); + if (c == -1) + break; + + switch(c) { + case 'd': + godaemon = 0; + break; + case 'n': + printf("Starting corewatcher in debug mode\n"); + godaemon = 0; + testmode = 1; + opted_in = 2; + break; + case 'h': + usage(argv[0]); + return EXIT_SUCCESS; + default: + break; + } } if (!opted_in && !testmode) { -- 2.7.4