From 16f4940a89df5dfe21ed545e28e17d65e6bd72a9 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sat, 9 Aug 2014 11:03:16 +0200 Subject: allow to give long arguments --- journal-notify.c | 19 +++++++++++++++++-- journal-notify.h | 5 +++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/journal-notify.c b/journal-notify.c index 9819f07..ea73666 100644 --- a/journal-notify.c +++ b/journal-notify.c @@ -9,6 +9,21 @@ const char * program = NULL; +const static char optstring[] = "aehi:m:nor:v"; +const static struct option options_long[] = { + /* name has_arg flag val */ + { "and", no_argument, NULL, 'a' }, + { "extended-regex", no_argument, NULL, 'e' }, + { "help", no_argument, NULL, 'h' }, + { "icon", required_argument, NULL, 'i' }, + { "match", required_argument, NULL, 'm' }, + { "no-case", no_argument, NULL, 'n' }, + { "or", no_argument, NULL, 'o' }, + { "regex", required_argument, NULL, 'r' }, + { "verbose", no_argument, NULL, 'v' }, + { 0, 0, 0, 0 } +}; + /*** notify ***/ int notify(const char * summary, const char * body, const char * icon) { NotifyNotification * notification; @@ -55,7 +70,7 @@ int main(int argc, char **argv) { /* get command line options - part I * just get -h (help), -e and -n (regex options) here */ - while ((i = getopt(argc, argv, OPTSTRING)) != -1) { + while ((i = getopt_long(argc, argv, optstring, options_long, NULL)) != -1) { switch (i) { case 'e': regex_flags |= REG_EXTENDED; @@ -86,7 +101,7 @@ int main(int argc, char **argv) { } /* get command line options - part II*/ - while ((i = getopt(argc, argv, OPTSTRING)) != -1) { + while ((i = getopt_long(argc, argv, optstring, options_long, NULL)) != -1) { switch (i) { case 'a': if (verbose > 1) diff --git a/journal-notify.h b/journal-notify.h index c16942d..858b9c8 100644 --- a/journal-notify.h +++ b/journal-notify.h @@ -8,10 +8,12 @@ #ifndef _JOURNAL_NOTIFY_H #define _JOURNAL_NOTIFY_H +#include +#include #include #include #include -#include +#include #include @@ -19,7 +21,6 @@ #include "version.h" -#define OPTSTRING "aehi:m:nor:v" #define DEFAULTICON "dialog-information" /*** notify ***/ -- cgit v1.2.3-70-g09d2