/[pcre]/code/trunk/pcre_version.c
ViewVC logotype

Diff of /code/trunk/pcre_version.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 87 by nigel, Sat Feb 24 21:41:21 2007 UTC revision 145 by ph10, Wed Apr 4 14:06:52 2007 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2006 University of Cambridge             Copyright (c) 1997-2007 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 49  string that identifies the PCRE version Line 49  string that identifies the PCRE version
49  *          Return version string                 *  *          Return version string                 *
50  *************************************************/  *************************************************/
51    
52    /* These macros are the standard way of turning unquoted text into C strings.
53    They allow macros like PCRE_MAJOR to be defined without quotes, which is
54    convenient for user programs that want to test its value. */
55    
56  #define STRING(a)  # a  #define STRING(a)  # a
57  #define XSTRING(s) STRING(s)  #define XSTRING(s) STRING(s)
58    
59  PCRE_DATA_SCOPE const char *  /* A problem turned up with PCRE_PRERELEASE, which is defined empty for
60    production releases. Originally, it was used naively in this code:
61    
62      return XSTRING(PCRE_MAJOR)
63             "." XSTRING(PCRE_MINOR)
64                 XSTRING(PCRE_PRERELEASE)
65             " " XSTRING(PCRE_DATE);
66    
67    However, when PCRE_PRERELEASE is empty, this leads to an attempted expansion of
68    STRING(). The C standard states: "If (before argument substitution) any
69    argument consists of no preprocessing tokens, the behavior is undefined." It
70    turns out the gcc treats this case as a single empty string - which is what we
71    really want - but Visual C grumbles about the lack of an argument for the
72    macro. Unfortunately, both are within their rights. To cope with both ways of
73    handling this, I had resort to some messy hackery that does a test at run time.
74    I could find no way of detecting that a macro is defined as an empty string at
75    pre-processor time. This hack uses a standard trick for avoiding calling
76    the STRING macro with an empty argument when doing the test. */
77    
78    PCRE_EXP_DEFN const char *
79  pcre_version(void)  pcre_version(void)
80  {  {
81  return XSTRING(PCRE_MAJOR)  return (XSTRING(Z PCRE_PRERELEASE)[1] == 0)?
82         "." XSTRING(PCRE_MINOR)    XSTRING(PCRE_MAJOR.PCRE_MINOR PCRE_DATE) :
83             XSTRING(PCRE_PRERELEASE)    XSTRING(PCRE_MAJOR.PCRE_MINOR) XSTRING(PCRE_PRERELEASE PCRE_DATE);
        " " XSTRING(PCRE_DATE);  
84  }  }
85    
86  /* End of pcre_version.c */  /* End of pcre_version.c */

Legend:
Removed from v.87  
changed lines
  Added in v.145

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12