NCBI C++ ToolKit
pcre2_config.c
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /*************************************************
2 * Perl-Compatible Regular Expressions *
3 *************************************************/
4 
5 /* PCRE is a library of functions to support regular expressions whose syntax
6 and semantics are as close as possible to those of the Perl 5 language.
7 
8  Written by Philip Hazel
9  Original API code Copyright (c) 1997-2012 University of Cambridge
10  New API code Copyright (c) 2016-2020 University of Cambridge
11 
12 -----------------------------------------------------------------------------
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 
16  * Redistributions of source code must retain the above copyright notice,
17  this list of conditions and the following disclaimer.
18 
19  * Redistributions in binary form must reproduce the above copyright
20  notice, this list of conditions and the following disclaimer in the
21  documentation and/or other materials provided with the distribution.
22 
23  * Neither the name of the University of Cambridge nor the names of its
24  contributors may be used to endorse or promote products derived from
25  this software without specific prior written permission.
26 
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 POSSIBILITY OF SUCH DAMAGE.
38 -----------------------------------------------------------------------------
39 */
40 
41 #ifdef HAVE_CONFIG_H
42 #include "config.h"
43 #endif
44 
45 /* Save the configured link size, which is in bytes. In 16-bit and 32-bit modes
46 its value gets changed by pcre2_intmodedep.h (included by pcre2_internal.h) to
47 be in code units. */
48 
50 
51 #include "pcre2_internal.h"
52 
53 /* These macros are the standard way of turning unquoted text into C strings.
54 They allow macros like PCRE2_MAJOR to be defined without quotes, which is
55 convenient for user programs that want to test their values. */
56 
57 #define STRING(a) # a
58 #define XSTRING(s) STRING(s)
59 
60 
61 /*************************************************
62 * Return info about what features are configured *
63 *************************************************/
64 
65 /* If where is NULL, the length of memory required is returned.
66 
67 Arguments:
68  what what information is required
69  where where to put the information
70 
71 Returns: 0 if a numerical value is returned
72  >= 0 if a string value
73  PCRE2_ERROR_BADOPTION if "where" not recognized
74  or JIT target requested when JIT not enabled
75 */
76 
78 pcre2_config(uint32_t what, void *where)
79 {
80 if (where == NULL) /* Requests a length */
81  {
82  switch(what)
83  {
84  default:
85  return PCRE2_ERROR_BADOPTION;
86 
87  case PCRE2_CONFIG_BSR:
91  case PCRE2_CONFIG_JIT:
97  case PCRE2_CONFIG_STACKRECURSE: /* Obsolete */
100  return sizeof(uint32_t);
101 
102  /* These are handled below */
103 
107  break;
108  }
109  }
110 
111 switch (what)
112  {
113  default:
114  return PCRE2_ERROR_BADOPTION;
115 
116  case PCRE2_CONFIG_BSR:
117 #ifdef BSR_ANYCRLF
118  *((uint32_t *)where) = PCRE2_BSR_ANYCRLF;
119 #else
120  *((uint32_t *)where) = PCRE2_BSR_UNICODE;
121 #endif
122  break;
123 
125  *((uint32_t *)where) = 0
126 #ifdef SUPPORT_PCRE2_8
127  + 1
128 #endif
129 #ifdef SUPPORT_PCRE2_16
130  + 2
131 #endif
132 #ifdef SUPPORT_PCRE2_32
133  + 4
134 #endif
135  ;
136  break;
137 
139  *((uint32_t *)where) = MATCH_LIMIT_DEPTH;
140  break;
141 
143  *((uint32_t *)where) = HEAP_LIMIT;
144  break;
145 
146  case PCRE2_CONFIG_JIT:
147 #ifdef SUPPORT_JIT
148  *((uint32_t *)where) = 1;
149 #else
150  *((uint32_t *)where) = 0;
151 #endif
152  break;
153 
155 #ifdef SUPPORT_JIT
156  {
157  const char *v = PRIV(jit_get_target)();
158  return (int)(1 + ((where == NULL)?
159  strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)));
160  }
161 #else
162  return PCRE2_ERROR_BADOPTION;
163 #endif
164 
166  *((uint32_t *)where) = (uint32_t)configured_link_size;
167  break;
168 
170  *((uint32_t *)where) = MATCH_LIMIT;
171  break;
172 
174  *((uint32_t *)where) = NEWLINE_DEFAULT;
175  break;
176 
178 #ifdef NEVER_BACKSLASH_C
179  *((uint32_t *)where) = 1;
180 #else
181  *((uint32_t *)where) = 0;
182 #endif
183  break;
184 
186  *((uint32_t *)where) = PARENS_NEST_LIMIT;
187  break;
188 
189  /* This is now obsolete. The stack is no longer used via recursion for
190  handling backtracking in pcre2_match(). */
191 
193  *((uint32_t *)where) = 0;
194  break;
195 
197  *((uint32_t *)where) = TABLES_LENGTH;
198  break;
199 
201  {
202 #if defined SUPPORT_UNICODE
203  const char *v = PRIV(unicode_version);
204 #else
205  const char *v = "Unicode not supported";
206 #endif
207  return (int)(1 + ((where == NULL)?
208  strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)));
209  }
210  break;
211 
213 #if defined SUPPORT_UNICODE
214  *((uint32_t *)where) = 1;
215 #else
216  *((uint32_t *)where) = 0;
217 #endif
218  break;
219 
220  /* The hackery in setting "v" below is to cope with the case when
221  PCRE2_PRERELEASE is set to an empty string (which it is for real releases).
222  If the second alternative is used in this case, it does not leave a space
223  before the date. On the other hand, if all four macros are put into a single
224  XSTRING when PCRE2_PRERELEASE is not empty, an unwanted space is inserted.
225  There are problems using an "obvious" approach like this:
226 
227  XSTRING(PCRE2_MAJOR) "." XSTRING(PCRE_MINOR)
228  XSTRING(PCRE2_PRERELEASE) " " XSTRING(PCRE_DATE)
229 
230  because, when PCRE2_PRERELEASE is empty, this leads to an attempted expansion
231  of STRING(). The C standard states: "If (before argument substitution) any
232  argument consists of no preprocessing tokens, the behavior is undefined." It
233  turns out the gcc treats this case as a single empty string - which is what
234  we really want - but Visual C grumbles about the lack of an argument for the
235  macro. Unfortunately, both are within their rights. As there seems to be no
236  way to test for a macro's value being empty at compile time, we have to
237  resort to a runtime test. */
238 
240  {
241  const char *v = (XSTRING(Z PCRE2_PRERELEASE)[1] == 0)?
242  XSTRING(PCRE2_MAJOR.PCRE2_MINOR PCRE2_DATE) :
244  return (int)(1 + ((where == NULL)?
245  strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)));
246  }
247  }
248 
249 return 0;
250 }
251 
252 /* End of pcre2_config.c */
Uint4 uint32_t
#define NULL
Definition: ncbistd.hpp:225
#define Z
printf format modifier for size_t
Definition: mdb.c:334
#define PCRE2_CONFIG_TABLES_LENGTH
Definition: pcre2.h:467
#define PCRE2_CONFIG_NEWLINE
Definition: pcre2.h:456
#define PCRE2_BSR_ANYCRLF
Definition: pcre2.h:224
#define PCRE2_ERROR_BADOPTION
Definition: pcre2.h:381
#define PCRE2_CONFIG_DEPTHLIMIT
Definition: pcre2.h:458
#define PCRE2_UCHAR
Definition: pcre2.h:825
#define PCRE2_CONFIG_UNICODE
Definition: pcre2.h:461
#define PCRE2_CONFIG_BSR
Definition: pcre2.h:451
#define PCRE2_CONFIG_HEAPLIMIT
Definition: pcre2.h:464
#define PCRE2_CONFIG_STACKRECURSE
Definition: pcre2.h:460
#define PCRE2_MAJOR
Definition: pcre2.h:44
#define PCRE2_CONFIG_NEVER_BACKSLASH_C
Definition: pcre2.h:465
#define PCRE2_CONFIG_MATCHLIMIT
Definition: pcre2.h:455
#define PCRE2_CONFIG_UNICODE_VERSION
Definition: pcre2.h:462
#define PCRE2_CONFIG_LINKSIZE
Definition: pcre2.h:454
#define PCRE2_CALL_CONVENTION
Definition: pcre2.h:87
#define PCRE2_CONFIG_PARENSLIMIT
Definition: pcre2.h:457
#define PCRE2_CONFIG_JIT
Definition: pcre2.h:452
#define PCRE2_PRERELEASE
Definition: pcre2.h:46
#define PCRE2_BSR_UNICODE
Definition: pcre2.h:223
#define PCRE2_CONFIG_COMPILED_WIDTHS
Definition: pcre2.h:466
#define PCRE2_CONFIG_VERSION
Definition: pcre2.h:463
#define PCRE2_CONFIG_JITTARGET
Definition: pcre2.h:453
#define PCRE2_DATE
Definition: pcre2.h:47
PCRE2_EXPORT int PCRE2_CALL_CONVENTION pcre2_config(uint32_t what, void *where)
Definition: pcre2_config.c:78
static int configured_link_size
Definition: pcre2_config.c:49
#define XSTRING(s)
Definition: pcre2_config.c:58
#define TABLES_LENGTH
#define PCRE2_EXP_DEFN
#define PRIV(name)
const char *PRIV() jit_get_target(void)
#define uint32_t
Definition: config.h:42
#define MATCH_LIMIT_DEPTH
Definition: config.h:128
#define NEWLINE_DEFAULT
Definition: config.h:159
#define LINK_SIZE
Definition: config.h:97
#define HEAP_LIMIT
Definition: config.h:88
#define MATCH_LIMIT
Definition: config.h:114
#define PARENS_NEST_LIMIT
Definition: config.h:187
Modified on Fri Sep 20 14:57:06 2024 by modify_doxy.py rev. 669887