Mercurial > nxg > jason
changeset 1:8834a6154573
Library version functions
author | Norman Gray <norman@astro.gla.ac.uk> |
---|---|
date | Wed, 04 Sep 2013 22:34:58 +0100 |
parents | 1b3f35f9f37f |
children | 27a0f5a39536 |
files | README.md configure.ac src/jason.c src/jason.h src/json-parse.y src/json2der.1 src/json2der.c src/json_lex.lex |
diffstat | 8 files changed, 64 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/README.md Wed Sep 04 22:00:24 2013 +0100 +++ b/README.md Wed Sep 04 22:34:58 2013 +0100 @@ -92,6 +92,11 @@ cannot be parsed, then this returns `NULL`, and an explanation is available from the function `const char* unsupported_message()`. + const char* jason_version_string(void); + int jason_version_number(void); + +Return information about the library version number. + Though this library is not intended as a general JSON parser, the contents of the `JsonObject` structure should be fairly stable. See the `jason.h` header for the details.
--- a/configure.ac Wed Sep 04 22:00:24 2013 +0100 +++ b/configure.ac Wed Sep 04 22:34:58 2013 +0100 @@ -1,7 +1,9 @@ dnl Make release version numbers match /^[0-9.]*$/ dnl Experimental ones are ...x, and betas are ...bn AC_INIT(jason, 0.1x, norman@astro.gla.ac.uk) -AC_DEFINE(RELEASEDATE, "2013 February 8", [Release date of the current version]) +AC_DEFINE(RELEASE_DATE, "2013 XXX xx", [Release date of the current version]) + +AC_SUBST(LIBRARY_HOMEPAGE, [http://bitbucket.org/nxg/jason]) dnl Embed a snapshot identifier in the binary, if it's not a release version if expr $PACKAGE_VERSION : ['[0-9.]*$'] >/dev/null; then @@ -13,8 +15,14 @@ AC_DEFINE_UNQUOTED([SNAPSHOTID], ["$SNAPSHOTID"], [Description of snapshot, or blank if release version]) +PACKAGE_VERSION_INTEGER=[`echo ${PACKAGE_VERSION}-0 | awk -F'[^0-9]*' '{printf "%d 1000000* %d 1000* %d++p", $1,$2,$3}' | dc`] +AC_SUBST(PACKAGE_VERSION_INTEGER) +AC_DEFINE_UNQUOTED([PACKAGE_VERSION_INTEGER], + [$PACKAGE_VERSION_INTEGER], + [Version number as an integer: major*1e6+minor*1e3+release]) AC_CONFIG_AUX_DIR([m4]) dnl tidy these away +AC_CONFIG_HEADERS([src/config.h]) AM_INIT_AUTOMAKE LT_INIT @@ -26,7 +34,6 @@ AC_C_BIGENDIAN AC_PROG_CC -AC_CONFIG_HEADERS(config.h) AC_PROG_LEX AC_PATH_PROG(BISON, bison)
--- a/src/jason.c Wed Sep 04 22:00:24 2013 +0100 +++ b/src/jason.c Wed Sep 04 22:34:58 2013 +0100 @@ -5,6 +5,8 @@ #include <setjmp.h> #include <math.h> +#include <config.h> +#define JASON_IMPLEMENTATION 1 #include "jason.h" #include "util.h" @@ -1279,4 +1281,34 @@ unsupported_msg[0] = '\0'; return parse_der_bytes_internal(b, blen, actuallen); } + +/** + * Return a version string for the library. + * The form of the string is unspecified, but is intended to be printable + * + * @see jason_version_number + */ +const char* jason_version_string(void) +{ + const char* snapshotid = SNAPSHOTID; + if (snapshotid[0] == '\0') { + // empty string -- release version + return PACKAGE_STRING ", " RELEASE_DATE; + } else { + // snapshot version + return PACKAGE_STRING ", " SNAPSHOTID; + } +} +/** + * Return a number which indicates the version and release numbers of + * the library. The number is formed by major_version * 1e6 + + * minor_version * 1e3 + release_number + * + * @see jason_version_string + */ +int jason_version_number(void) +{ + return PACKAGE_VERSION_INTEGER; +} +
--- a/src/jason.h Wed Sep 04 22:00:24 2013 +0100 +++ b/src/jason.h Wed Sep 04 22:34:58 2013 +0100 @@ -57,6 +57,11 @@ JsonObject parse_der_bytes(byte*, size_t, size_t*); const char* unsupported_message(); +const char* jason_version_string(); +int jason_version_number(); + +#if JASON_IMPLEMENTATION + JsonObject make_string(const char*); JsonObject make_integer(jsonint); JsonObject make_real(double); @@ -67,4 +72,6 @@ JsonObject make_kv(const char*, JsonObject); JsonObject append_object(JsonObject, JsonObject); +#endif /* JASON_IMPLEMENTATION */ + #endif /* JASON_H_DEFINED */
--- a/src/json-parse.y Wed Sep 04 22:00:24 2013 +0100 +++ b/src/json-parse.y Wed Sep 04 22:34:58 2013 +0100 @@ -2,6 +2,7 @@ %{ #include <assert.h> + #define JASON_IMPLEMENTATION 1 #include "jason.h" int yylex(void);
--- a/src/json2der.1 Wed Sep 04 22:00:24 2013 +0100 +++ b/src/json2der.1 Wed Sep 04 22:34:58 2013 +0100 @@ -3,7 +3,7 @@ json2der .SH SYNOPSIS .B json2der -[-h] [-D] [-ifile] [-ofile] [-ffmt] [-tfmt] [json-string] +[-h] [-DhV] [-ifile] [-ofile] [-ffmt] [-tfmt] [json-string] .SH DESCRIPTION Converts a JSON expression to a DER equivalent, or decodes the supported subset of DER into JSON. @@ -58,6 +58,9 @@ .TP .I -h Writes out a help message. +.TP +.I -V +Displays the library version number and exits. .SH SEE ALSO DER is specified in ITU-T Rec. X.690, as part of the ASN/1 suite of standards. See the ITU-T recommendation,
--- a/src/json2der.c Wed Sep 04 22:00:24 2013 +0100 +++ b/src/json2der.c Wed Sep 04 22:34:58 2013 +0100 @@ -34,7 +34,7 @@ progname = argv[0]; - while ((ch = getopt(argc, argv, "DLhi:f:o:t:")) != -1) { + while ((ch = getopt(argc, argv, "DLhi:f:o:t:V")) != -1) { switch (ch) { case 'D': /* short for -fder -tjson */ input_format = FMT_DER; @@ -73,6 +73,10 @@ fprintf(stderr, "Can't open file %s to write\n", optarg); } break; + case 'V': + puts(jason_version_string()); + exit(0); + break; case 'h': /* FALL THROUGH */ default: