aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2015-07-03 14:46:52 +0200
committerGravatar Christian Hesse <mail@eworm.de>2015-07-03 14:46:52 +0200
commit6bc5a120866bbe5e03d42e57bbe987e54525d096 (patch)
treeb1b380d4b5215c6f0a25a1247b855c3591525cca
parent20fe29aaf9f64850e21b1c0ced95278c7a4a4329 (diff)
downloadpaccache-6bc5a120866bbe5e03d42e57bbe987e54525d096.tar.gz
paccache-6bc5a120866bbe5e03d42e57bbe987e54525d096.tar.zst
add --version option
-rw-r--r--pacredir.c22
-rw-r--r--pacredir.h1
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 {