From 6bc5a120866bbe5e03d42e57bbe987e54525d096 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 3 Jul 2015 14:46:52 +0200 Subject: add --version option --- pacredir.c | 22 ++++++++++++++++++---- pacredir.h | 1 + 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/pacredir.c b/pacredir.c index 8ab2127..6fb07e9 100644 --- a/pacredir.c +++ b/pacredir.c @@ -8,11 +8,12 @@ /* define structs and functions */ #include "pacredir.h" -const static char optstring[] = "hv"; +const static char optstring[] = "hvV"; const static struct option options_long[] = { /* name has_arg flag val */ { "help", no_argument, NULL, 'h' }, { "verbose", no_argument, NULL, 'v' }, + { "version", no_argument, NULL, 'V' }, { 0, 0, 0, 0 } }; @@ -500,19 +501,32 @@ int main(int argc, char ** argv) { struct hosts * tmphosts; struct sockaddr_in address; + unsigned int version = 0, help = 0; + /* get the verbose status */ while ((i = getopt_long(argc, argv, optstring, options_long, NULL)) != -1) { switch (i) { case 'h': - write_log(stdout, "usage: %s [-h] [-v]\n", argv[0]); - return EXIT_SUCCESS; + help++; + break; case 'v': verbose++; break; + case 'V': + verbose++; + version++; + break; } } - write_log(stdout, "Starting pacredir/" VERSION " (compiled: " __DATE__ ", " __TIME__ " for " ARCH ")\n"); + if (verbose > 0) + write_log(stdout, "%s: %s v%s (compiled: " __DATE__ ", " __TIME__ " for %s)\n", argv[0], PROGNAME, VERSION, ARCH); + + if (help > 0) + write_log(stdout, "usage: %s [-h] [-v] [-V]\n", argv[0]); + + if (version > 0 || help > 0) + return EXIT_SUCCESS; /* allocate first struct element as dummy */ hosts = malloc(sizeof(struct hosts)); diff --git a/pacredir.h b/pacredir.h index 7f031a6..2cbed4d 100644 --- a/pacredir.h +++ b/pacredir.h @@ -40,6 +40,7 @@ #include "config.h" #include "version.h" +#define PROGNAME "pacredir" /* services */ struct services { -- cgit v1.2.3-70-g09d2