tools/pcre/pcre_version.c
author John Schoenick <john@pointysoftware.net>
Wed Jun 01 20:36:16 2011 -0400 (2011-06-01)
changeset 3292 f428ffc8a3fe
parent 2762 d2d467bf1b5a
child 3831 babd0eee3c5e
permissions -rw-r--r--
Fixed regression in FindEntityByClassname from bug 4899 (bug 4941, r=predcrab).
dvander@2762
     1
/*************************************************
dvander@2762
     2
*      Perl-Compatible Regular Expressions       *
dvander@2762
     3
*************************************************/
dvander@2762
     4
dvander@2762
     5
/* PCRE is a library of functions to support regular expressions whose syntax
dvander@2762
     6
and semantics are as close as possible to those of the Perl 5 language.
dvander@2762
     7
dvander@2762
     8
                       Written by Philip Hazel
dvander@2762
     9
           Copyright (c) 1997-2008 University of Cambridge
dvander@2762
    10
dvander@2762
    11
-----------------------------------------------------------------------------
dvander@2762
    12
Redistribution and use in source and binary forms, with or without
dvander@2762
    13
modification, are permitted provided that the following conditions are met:
dvander@2762
    14
dvander@2762
    15
    * Redistributions of source code must retain the above copyright notice,
dvander@2762
    16
      this list of conditions and the following disclaimer.
dvander@2762
    17
dvander@2762
    18
    * Redistributions in binary form must reproduce the above copyright
dvander@2762
    19
      notice, this list of conditions and the following disclaimer in the
dvander@2762
    20
      documentation and/or other materials provided with the distribution.
dvander@2762
    21
dvander@2762
    22
    * Neither the name of the University of Cambridge nor the names of its
dvander@2762
    23
      contributors may be used to endorse or promote products derived from
dvander@2762
    24
      this software without specific prior written permission.
dvander@2762
    25
dvander@2762
    26
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
dvander@2762
    27
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
dvander@2762
    28
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
dvander@2762
    29
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
dvander@2762
    30
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
dvander@2762
    31
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
dvander@2762
    32
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dvander@2762
    33
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
dvander@2762
    34
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
dvander@2762
    35
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
dvander@2762
    36
POSSIBILITY OF SUCH DAMAGE.
dvander@2762
    37
-----------------------------------------------------------------------------
dvander@2762
    38
*/
dvander@2762
    39
dvander@2762
    40
dvander@2762
    41
/* This module contains the external function pcre_version(), which returns a
dvander@2762
    42
string that identifies the PCRE version that is in use. */
dvander@2762
    43
dvander@2762
    44
dvander@2762
    45
#ifdef HAVE_CONFIG_H
dvander@2762
    46
#include "config.h"
dvander@2762
    47
#endif
dvander@2762
    48
dvander@2762
    49
#include "pcre_internal.h"
dvander@2762
    50
dvander@2762
    51
dvander@2762
    52
/*************************************************
dvander@2762
    53
*          Return version string                 *
dvander@2762
    54
*************************************************/
dvander@2762
    55
dvander@2762
    56
/* These macros are the standard way of turning unquoted text into C strings.
dvander@2762
    57
They allow macros like PCRE_MAJOR to be defined without quotes, which is
dvander@2762
    58
convenient for user programs that want to test its value. */
dvander@2762
    59
dvander@2762
    60
#define STRING(a)  # a
dvander@2762
    61
#define XSTRING(s) STRING(s)
dvander@2762
    62
dvander@2762
    63
/* A problem turned up with PCRE_PRERELEASE, which is defined empty for
dvander@2762
    64
production releases. Originally, it was used naively in this code:
dvander@2762
    65
dvander@2762
    66
  return XSTRING(PCRE_MAJOR)
dvander@2762
    67
         "." XSTRING(PCRE_MINOR)
dvander@2762
    68
             XSTRING(PCRE_PRERELEASE)
dvander@2762
    69
         " " XSTRING(PCRE_DATE);
dvander@2762
    70
dvander@2762
    71
However, when PCRE_PRERELEASE is empty, this leads to an attempted expansion of
dvander@2762
    72
STRING(). The C standard states: "If (before argument substitution) any
dvander@2762
    73
argument consists of no preprocessing tokens, the behavior is undefined." It
dvander@2762
    74
turns out the gcc treats this case as a single empty string - which is what we
dvander@2762
    75
really want - but Visual C grumbles about the lack of an argument for the
dvander@2762
    76
macro. Unfortunately, both are within their rights. To cope with both ways of
dvander@2762
    77
handling this, I had resort to some messy hackery that does a test at run time.
dvander@2762
    78
I could find no way of detecting that a macro is defined as an empty string at
dvander@2762
    79
pre-processor time. This hack uses a standard trick for avoiding calling
dvander@2762
    80
the STRING macro with an empty argument when doing the test. */
dvander@2762
    81
dvander@2762
    82
PCRE_EXP_DEFN const char * PCRE_CALL_CONVENTION
dvander@2762
    83
pcre_version(void)
dvander@2762
    84
{
dvander@2762
    85
return (XSTRING(Z PCRE_PRERELEASE)[1] == 0)?
dvander@2762
    86
  XSTRING(PCRE_MAJOR.PCRE_MINOR PCRE_DATE) :
dvander@2762
    87
  XSTRING(PCRE_MAJOR.PCRE_MINOR) XSTRING(PCRE_PRERELEASE PCRE_DATE);
dvander@2762
    88
}
dvander@2762
    89
dvander@2762
    90
/* End of pcre_version.c */