diff options
author | Christian Hesse <mail@eworm.de> | 2015-07-03 14:46:52 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2015-07-03 14:46:52 +0200 |
commit | 6bc5a120866bbe5e03d42e57bbe987e54525d096 (patch) | |
tree | b1b380d4b5215c6f0a25a1247b855c3591525cca /pacredir.c | |
parent | 20fe29aaf9f64850e21b1c0ced95278c7a4a4329 (diff) | |
download | paccache-6bc5a120866bbe5e03d42e57bbe987e54525d096.tar.gz paccache-6bc5a120866bbe5e03d42e57bbe987e54525d096.tar.zst |
add --version option
Diffstat (limited to 'pacredir.c')
-rw-r--r-- | pacredir.c | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -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)); |