From 200ca3f1b4b0f37bb189eb246603102fc6f19865 Mon Sep 17 00:00:00 2001 From: "Philip.Hazel" Date: Mon, 23 Jun 2014 17:07:24 +0000 Subject: [PATCH] Add --version as a pcre2test option, and add a comment to config. --- src/pcre2_config.c | 23 +++++++++++++++++++---- src/pcre2test.c | 34 ++++++++++++++++++++++------------ 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/pcre2_config.c b/src/pcre2_config.c index 40b30d4..ba362fe 100644 --- a/src/pcre2_config.c +++ b/src/pcre2_config.c @@ -143,16 +143,31 @@ FIXME: This needs re-design. #endif break; + /* The hackery in setting "v" below is to cope with the case when + PCRE2_PRERELEASE is set to an empty string (which it is for real releases). + If the second alternative is used in this case, it does not leave a space + before the date. On the other hand, if all four macros are put into a single + XSTRING when PCRE2_PRERELEASE is not empty, an unwanted space is inserted. + There are problems using an "obvious" approach like this: + + XSTRING(PCRE2_MAJOR) "." XSTRING(PCRE_MINOR) + XSTRING(PCRE2_PRERELEASE) " " XSTRING(PCRE_DATE) + + because, when PCRE2_PRERELEASE is empty, this leads to an attempted expansion + of STRING(). The C standard states: "If (before argument substitution) any + argument consists of no preprocessing tokens, the behavior is undefined." It + turns out the gcc treats this case as a single empty string - which is what + we really want - but Visual C grumbles about the lack of an argument for the + macro. Unfortunately, both are within their rights. As there seems to be no + way to test for a macro's value being empty at compile time, we have to + resort to a runtime test. */ + case PCRE2_CONFIG_VERSION: { PCRE2_UCHAR *t = (PCRE2_UCHAR *)where; -/* const char *v = (XSTRING(Z PCRE2_PRERELEASE)[1] == 0)? XSTRING(PCRE2_MAJOR.PCRE2_MINOR PCRE2_DATE) : XSTRING(PCRE2_MAJOR.PCRE2_MINOR) XSTRING(PCRE2_PRERELEASE PCRE2_DATE); -*/ - const char *v = XSTRING(PCRE2_MAJOR.PCRE2_MINOR) - XSTRING(PCRE2_PRERELEASE PCRE2_DATE); if (strlen(v) >= BYTES2CU(length) - 1) return PCRE2_ERROR_BADLENGTH; while (*v != 0) *t++ = *v++; *t = 0; diff --git a/src/pcre2test.c b/src/pcre2test.c index 48b6e65..8f1f085 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -4678,18 +4678,18 @@ printf(" -32 use the 32-bit library\n"); #endif printf(" -b set default pattern control 'fullbincode'\n"); printf(" -C show PCRE2 compile-time options and exit\n"); -printf(" -C arg show a specific compile-time option and exit\n"); -printf(" with its value if numeric (else 0). The arg can be:\n"); -printf(" bsr \\R type [ANYCRLF, ANY]\n"); -printf(" ebcdic compiled for EBCDIC character code [0,1]\n"); -printf(" ebcdic-nl NL code if compiled for EBCDIC\n"); -printf(" jit just-in-time compiler supported [0, 1]\n"); -printf(" linksize internal link size [2, 3, 4]\n"); -printf(" newline newline type [CR, LF, CRLF, ANYCRLF, ANY]\n"); -printf(" pcre8 8 bit library support enabled [0, 1]\n"); -printf(" pcre16 16 bit library support enabled [0, 1]\n"); -printf(" pcre32 32 bit library support enabled [0, 1]\n"); -printf(" utf Unicode Transformation Format supported [0, 1]\n"); +printf(" -C arg show a specific compile-time option and exit with its\n"); +printf(" value if numeric (else 0). The arg can be:\n"); +printf(" bsr \\R type [ANYCRLF, ANY]\n"); +printf(" ebcdic compiled for EBCDIC character code [0,1]\n"); +printf(" ebcdic-nl NL code if compiled for EBCDIC\n"); +printf(" jit just-in-time compiler supported [0, 1]\n"); +printf(" linksize internal link size [2, 3, 4]\n"); +printf(" newline newline type [CR, LF, CRLF, ANYCRLF, ANY]\n"); +printf(" pcre8 8 bit library support enabled [0, 1]\n"); +printf(" pcre16 16 bit library support enabled [0, 1]\n"); +printf(" pcre32 32 bit library support enabled [0, 1]\n"); +printf(" utf Unicode Transformation Format supported [0, 1]\n"); printf(" -d set default pattern control 'debug'\n"); printf(" -help show usage information\n"); printf(" -i set default pattern control 'info'\n"); @@ -4701,6 +4701,7 @@ printf(" -t [] time compilation and execution, repeating times\n"); printf(" -tm [] time execution (matching) only, repeating times\n"); printf(" -T same as -t, but show total times at the end\n"); printf(" -TM same as -tm, but show total time at the end\n"); +printf(" -version show PCRE2 version and exit\n"); } @@ -5014,6 +5015,15 @@ while (argc > 1 && argv[op][0] == '-') usage(); goto EXIT; } + + /* Show version */ + + else if (strcmp(arg, "-version") == 0 || + strcmp(arg, "--version") == 0) + { + print_version(stdout); + goto EXIT; + } /* The following options save their data for processing once we know what the running mode is. */