From f305f28c8dbac109c1038d430c7125222ee90703 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Fri, 2 Mar 2018 19:02:48 -0800 Subject: fixes #254 nngcat should have a --version option We only add a basic --version (also -V). I'm still trying to figure out how to convince cmake to emit its compilation flags into a file where we can use them for output. --- docs/man/nngcat.adoc | 4 ++++ src/nng.c | 11 +++++++++++ src/nng.h | 8 +++++--- tools/nngcat/nngcat.c | 5 +++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/docs/man/nngcat.adoc b/docs/man/nngcat.adoc index 49e4b05a..e5528536 100644 --- a/docs/man/nngcat.adoc +++ b/docs/man/nngcat.adoc @@ -17,6 +17,8 @@ nngcat - command line access to Scalabity Protocols *nngcat* --help +*nngcat* --version + *nngcat* [_OPTION_]... == DESCRIPTION @@ -41,6 +43,8 @@ equa === Generic *-h, --help*:: Get usage help. +*-V, --version*:: + Print the version and exit. *-v, --verbose*:: Select verbose operation. *-q, --silent*:: diff --git a/src/nng.c b/src/nng.c index b7255904..19b33220 100644 --- a/src/nng.c +++ b/src/nng.c @@ -8,6 +8,7 @@ // found online at https://opensource.org/licenses/MIT. // +#include "nng.h" #include "core/nng_impl.h" // This file provides the "public" API. This is a thin wrapper around @@ -1212,3 +1213,13 @@ nng_url_clone(nng_url **dstp, const nng_url *src) { return (nni_url_clone(dstp, src)); } + +#define xstr(a) str(a) +#define str(a) #a + +const char * +nng_version(void) +{ + return (xstr(NNG_MAJOR_VERSION) "." xstr(NNG_MINOR_VERSION) "." xstr( + NNG_PATCH_VERSION)); +} diff --git a/src/nng.h b/src/nng.h index e2cdb8fa..7615785d 100644 --- a/src/nng.h +++ b/src/nng.h @@ -47,9 +47,9 @@ extern "C" { // may not necessarily match the ABI versions. Right now at // version 0, you should not be making any forward compatibility // assumptions. -#define NNG_MAJOR_VERSION 0 -#define NNG_MINOR_VERSION 5 -#define NNG_PATCH_VERSION 0 +#define NNG_MAJOR_VERSION 0 +#define NNG_MINOR_VERSION 5 +#define NNG_PATCH_VERSION 0 // Types common to nng. typedef uint32_t nng_socket; @@ -698,6 +698,8 @@ NNG_DECL void nng_url_free(nng_url *); // nng_url_clone clones a URL structure. NNG_DECL int nng_url_clone(nng_url **, const nng_url *); +// nng_version returns the library version as a human readable string. +NNG_DECL const char *nng_version(void); #ifdef __cplusplus } #endif diff --git a/tools/nngcat/nngcat.c b/tools/nngcat/nngcat.c index 2f5ef563..064e4635 100644 --- a/tools/nngcat/nngcat.c +++ b/tools/nngcat/nngcat.c @@ -96,6 +96,7 @@ enum options { OPT_CACERT, OPT_KEYFILE, OPT_CERTFILE, + OPT_VERSION, }; static nng_optspec opts[] = { @@ -179,6 +180,7 @@ static nng_optspec opts[] = { .o_val = OPT_CERTFILE, .o_arg = true, }, + { .o_name = "version", .o_short = 'V', .o_val = OPT_VERSION }, // Sentinel. { .o_name = NULL, .o_val = 0 }, @@ -784,6 +786,9 @@ main(int ac, const char **av) case OPT_INSECURE: insecure = 1; break; + case OPT_VERSION: + printf("%s\n", nng_version()); + exit(0); } } switch (rv) { -- cgit v1.2.3-70-g09d2