aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2015-07-03 14:37:55 +0200
committerGravatar Christian Hesse <mail@eworm.de>2015-07-03 14:37:55 +0200
commit93ea01fa30b08b70868c7ff83c10632e3012af5e (patch)
tree407c06e6dcec833b64633c8d9d559ab0125b7949
parent9d7d9e101b0306df50fa96eb4485b4b1f7c8b489 (diff)
downloadjournal-notify-93ea01fa30b08b70868c7ff83c10632e3012af5e.tar.gz
journal-notify-93ea01fa30b08b70868c7ff83c10632e3012af5e.tar.zst
add --version option
-rw-r--r--journal-notify.c21
-rw-r--r--journal-notify.h2
2 files changed, 19 insertions, 4 deletions
diff --git a/journal-notify.c b/journal-notify.c
index f7ee36a..c711d5d 100644
--- a/journal-notify.c
+++ b/journal-notify.c
@@ -9,7 +9,7 @@
const char * program = NULL;
-const static char optstring[] = "aehi:m:nor:t:vx:X:";
+const static char optstring[] = "aehi:m:nor:t:vVx:X:";
const static struct option options_long[] = {
/* name has_arg flag val */
{ "and", no_argument, NULL, 'a' },
@@ -22,6 +22,7 @@ const static struct option options_long[] = {
{ "regex", required_argument, NULL, 'r' },
{ "timeout", required_argument, NULL, 't' },
{ "verbose", no_argument, NULL, 'v' },
+ { "version", no_argument, NULL, 'V' },
{ "execute", required_argument, NULL, 'x' },
{ "execute-only", required_argument, NULL, 'X' },
{ 0, 0, 0, 0 }
@@ -116,6 +117,8 @@ int main(int argc, char **argv) {
struct timeval tv_last = (struct timeval){ 0 }, tv_now = (struct timeval){ 0 };
unsigned int notification_count = 0;
+ unsigned int version = 0, help = 0;
+
program = argv[0];
/* get command line options - part I
@@ -126,20 +129,30 @@ int main(int argc, char **argv) {
regex_flags |= REG_EXTENDED;
break;
case 'h':
- fprintf(stderr, "usage: %s [-e] [-h] [-i ICON] [-m MATCH] [-o -m MATCH] [-a -m MATCH] [-n] [-r REGEX] [-t SECONDS] [-vv]\n", program);
- return EXIT_SUCCESS;
+ help++;
+ break;
case 'n':
regex_flags |= REG_ICASE;
break;
case 'v':
verbose++;
break;
+ case 'V':
+ verbose++;
+ version++;
+ break;
}
}
/* say hello */
if (verbose > 0)
- printf("%s v%s (compiled: " __DATE__ ", " __TIME__ ")\n", program, VERSION);
+ printf("%s: %s v%s (compiled: " __DATE__ ", " __TIME__ ")\n", program, PROGNAME, VERSION);
+
+ if (help > 0)
+ fprintf(stderr, "usage: %s [-e] [-h] [-i ICON] [-m MATCH] [-o -m MATCH] [-a -m MATCH] [-n] [-r REGEX] [-t SECONDS] [-v[v]] [-V] [-x EXECUTE] [-X EXECUTE]\n", program);
+
+ if (version > 0 || help > 0)
+ return EXIT_SUCCESS;
/* open journal */
if ((rc = sd_journal_open(&journal, SD_JOURNAL_LOCAL_ONLY + SD_JOURNAL_SYSTEM)) < 0) {
diff --git a/journal-notify.h b/journal-notify.h
index 0a6e0b4..d905ce4 100644
--- a/journal-notify.h
+++ b/journal-notify.h
@@ -26,6 +26,8 @@
#include "config.h"
#include "version.h"
+#define PROGNAME "journal-notify"
+
#define DEFAULTICON "dialog-information"
const char * priorities[] = {