/[pcre]/code/trunk/pcre_internal.h
ViewVC logotype

Contents of /code/trunk/pcre_internal.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1083 - (show annotations)
Tue Oct 16 15:55:24 2012 UTC (7 years, 1 month ago) by chpe
File MIME type: text/plain
File size: 105980 byte(s)
pcre32: Mask out bits >= 22 on 32-bit characters in UTF-32 mode

UTF-32 only uses 21 bits, so the upper bits may be used to store flags
etc. To allow passing the unmodified internal buffers to pcre32, make
pcre32 mask out those upper bits.

TODO: do the same for the JIT compiler, and add tests
1 /*************************************************
2 * Perl-Compatible Regular Expressions *
3 *************************************************/
4
5
6 /* PCRE is a library of functions to support regular expressions whose syntax
7 and semantics are as close as possible to those of the Perl 5 language.
8
9 Written by Philip Hazel
10 Copyright (c) 1997-2012 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 /* This header contains definitions that are shared between the different
42 modules, but which are not relevant to the exported API. This includes some
43 functions whose names all begin with "_pcre_", "_pcre16_" or "_pcre32_"
44 depending on the PRIV macro. */
45
46 #ifndef PCRE_INTERNAL_H
47 #define PCRE_INTERNAL_H
48
49 /* Define PCRE_DEBUG to get debugging output on stdout. */
50
51 #if 0
52 #define PCRE_DEBUG
53 #endif
54
55 /* PCRE is compiled as an 8 bit library if it is not requested otherwise. */
56 #if !defined COMPILE_PCRE16 && ! defined COMPILE_PCRE32
57 #define COMPILE_PCRE8
58 #endif
59
60 /* If SUPPORT_UCP is defined, SUPPORT_UTF must also be defined. The
61 "configure" script ensures this, but not everybody uses "configure". */
62
63 #if defined SUPPORT_UCP && !(defined SUPPORT_UTF)
64 #define SUPPORT_UTF 1
65 #endif
66
67 /* We define SUPPORT_UTF if SUPPORT_UTF8 is enabled for compatibility
68 reasons with existing code. */
69
70 #if defined SUPPORT_UTF8 && !(defined SUPPORT_UTF)
71 #define SUPPORT_UTF 1
72 #endif
73
74 /* Fixme: SUPPORT_UTF8 should be eventually disappear from the code.
75 Until then we define it if SUPPORT_UTF is defined. */
76
77 #if defined SUPPORT_UTF && !(defined SUPPORT_UTF8)
78 #define SUPPORT_UTF8 1
79 #endif
80
81 /* We do not support both EBCDIC and UTF-8/16/32 at the same time. The "configure"
82 script prevents both being selected, but not everybody uses "configure". */
83
84 #if defined EBCDIC && defined SUPPORT_UTF
85 #error The use of both EBCDIC and SUPPORT_UTF is not supported.
86 #endif
87
88 /* Use a macro for debugging printing, 'cause that eliminates the use of #ifdef
89 inline, and there are *still* stupid compilers about that don't like indented
90 pre-processor statements, or at least there were when I first wrote this. After
91 all, it had only been about 10 years then...
92
93 It turns out that the Mac Debugging.h header also defines the macro DPRINTF, so
94 be absolutely sure we get our version. */
95
96 #undef DPRINTF
97 #ifdef PCRE_DEBUG
98 #define DPRINTF(p) printf p
99 #else
100 #define DPRINTF(p) /* Nothing */
101 #endif
102
103
104 /* Standard C headers plus the external interface definition. The only time
105 setjmp and stdarg are used is when NO_RECURSE is set. */
106
107 #include <ctype.h>
108 #include <limits.h>
109 #include <stddef.h>
110 #include <stdio.h>
111 #include <stdlib.h>
112 #include <string.h>
113
114 /* When compiling a DLL for Windows, the exported symbols have to be declared
115 using some MS magic. I found some useful information on this web page:
116 http://msdn2.microsoft.com/en-us/library/y4h7bcy6(VS.80).aspx. According to the
117 information there, using __declspec(dllexport) without "extern" we have a
118 definition; with "extern" we have a declaration. The settings here override the
119 setting in pcre.h (which is included below); it defines only PCRE_EXP_DECL,
120 which is all that is needed for applications (they just import the symbols). We
121 use:
122
123 PCRE_EXP_DECL for declarations
124 PCRE_EXP_DEFN for definitions of exported functions
125 PCRE_EXP_DATA_DEFN for definitions of exported variables
126
127 The reason for the two DEFN macros is that in non-Windows environments, one
128 does not want to have "extern" before variable definitions because it leads to
129 compiler warnings. So we distinguish between functions and variables. In
130 Windows, the two should always be the same.
131
132 The reason for wrapping this in #ifndef PCRE_EXP_DECL is so that pcretest,
133 which is an application, but needs to import this file in order to "peek" at
134 internals, can #include pcre.h first to get an application's-eye view.
135
136 In principle, people compiling for non-Windows, non-Unix-like (i.e. uncommon,
137 special-purpose environments) might want to stick other stuff in front of
138 exported symbols. That's why, in the non-Windows case, we set PCRE_EXP_DEFN and
139 PCRE_EXP_DATA_DEFN only if they are not already set. */
140
141 #ifndef PCRE_EXP_DECL
142 # ifdef _WIN32
143 # ifndef PCRE_STATIC
144 # define PCRE_EXP_DECL extern __declspec(dllexport)
145 # define PCRE_EXP_DEFN __declspec(dllexport)
146 # define PCRE_EXP_DATA_DEFN __declspec(dllexport)
147 # else
148 # define PCRE_EXP_DECL extern
149 # define PCRE_EXP_DEFN
150 # define PCRE_EXP_DATA_DEFN
151 # endif
152 # else
153 # ifdef __cplusplus
154 # define PCRE_EXP_DECL extern "C"
155 # else
156 # define PCRE_EXP_DECL extern
157 # endif
158 # ifndef PCRE_EXP_DEFN
159 # define PCRE_EXP_DEFN PCRE_EXP_DECL
160 # endif
161 # ifndef PCRE_EXP_DATA_DEFN
162 # define PCRE_EXP_DATA_DEFN
163 # endif
164 # endif
165 #endif
166
167 /* When compiling with the MSVC compiler, it is sometimes necessary to include
168 a "calling convention" before exported function names. (This is secondhand
169 information; I know nothing about MSVC myself). For example, something like
170
171 void __cdecl function(....)
172
173 might be needed. In order so make this easy, all the exported functions have
174 PCRE_CALL_CONVENTION just before their names. It is rarely needed; if not
175 set, we ensure here that it has no effect. */
176
177 #ifndef PCRE_CALL_CONVENTION
178 #define PCRE_CALL_CONVENTION
179 #endif
180
181 /* We need to have types that specify unsigned 8, 16 and 32-bit integers. We
182 cannot determine these outside the compilation (e.g. by running a program as
183 part of "configure") because PCRE is often cross-compiled for use on other
184 systems. Instead we make use of the maximum sizes that are available at
185 preprocessor time in standard C environments. */
186
187 typedef unsigned char pcre_uint8;
188
189 #if USHRT_MAX == 65535
190 typedef unsigned short pcre_uint16;
191 typedef short pcre_int16;
192 #elif UINT_MAX == 65535
193 typedef unsigned int pcre_uint16;
194 typedef int pcre_int16;
195 #else
196 #error Cannot determine a type for 16-bit unsigned integers
197 #endif
198
199 #if UINT_MAX == 4294967295
200 typedef unsigned int pcre_uint32;
201 typedef int pcre_int32;
202 #elif ULONG_MAX == 4294967295
203 typedef unsigned long int pcre_uint32;
204 typedef long int pcre_int32;
205 #else
206 #error Cannot determine a type for 32-bit unsigned integers
207 #endif
208
209 /* When checking for integer overflow in pcre_compile(), we need to handle
210 large integers. If a 64-bit integer type is available, we can use that.
211 Otherwise we have to cast to double, which of course requires floating point
212 arithmetic. Handle this by defining a macro for the appropriate type. If
213 stdint.h is available, include it; it may define INT64_MAX. Systems that do not
214 have stdint.h (e.g. Solaris) may have inttypes.h. The macro int64_t may be set
215 by "configure". */
216
217 #if HAVE_STDINT_H
218 #include <stdint.h>
219 #elif HAVE_INTTYPES_H
220 #include <inttypes.h>
221 #endif
222
223 #if defined INT64_MAX || defined int64_t
224 #define INT64_OR_DOUBLE int64_t
225 #else
226 #define INT64_OR_DOUBLE double
227 #endif
228
229 /* All character handling must be done as unsigned characters. Otherwise there
230 are problems with top-bit-set characters and functions such as isspace().
231 However, we leave the interface to the outside world as char * or short *,
232 because that should make things easier for callers. This character type is
233 called pcre_uchar.
234
235 The IN_UCHARS macro multiply its argument with the byte size of the current
236 pcre_uchar type. Useful for memcpy and such operations, whose require the
237 byte size of their input/output buffers.
238
239 The MAX_255 macro checks whether its pcre_uchar input is less than 256.
240
241 The TABLE_GET macro is designed for accessing elements of tables whose contain
242 exactly 256 items. When the character is able to contain more than 256
243 items, some check is needed before accessing these tables.
244 */
245
246 #if defined COMPILE_PCRE8
247
248 typedef unsigned char pcre_uchar;
249 #define IN_UCHARS(x) (x)
250 #define MAX_255(c) 1
251 #define TABLE_GET(c, table, default) ((table)[c])
252
253 #elif defined COMPILE_PCRE16
254
255 #if USHRT_MAX != 65535
256 /* This is a warning message. Change PCRE_UCHAR16 to a 16 bit data type in
257 pcre.h(.in) and disable (comment out) this message. */
258 #error Warning: PCRE_UCHAR16 is not a 16 bit data type.
259 #endif
260
261 typedef pcre_uint16 pcre_uchar;
262 #define UCHAR_SHIFT (1)
263 #define IN_UCHARS(x) ((x) << UCHAR_SHIFT)
264 #define MAX_255(c) ((c) <= 255u)
265 #define TABLE_GET(c, table, default) (MAX_255(c)? ((table)[c]):(default))
266
267 #elif defined COMPILE_PCRE32
268
269 typedef pcre_uint32 pcre_uchar;
270 #define UCHAR_SHIFT (2)
271 #define IN_UCHARS(x) ((x) << UCHAR_SHIFT)
272 #define MAX_255(c) ((c) <= 255u)
273 #define TABLE_GET(c, table, default) (MAX_255(c)? ((table)[c]):(default))
274
275 /* Assert that pcre_uchar32 is a 32-bit type */
276 typedef int __assert_pcre_uchar32_size[sizeof(pcre_uchar) == 4 ? 1 : -1];
277
278 #else
279 #error Unsupported compiling mode
280 #endif /* COMPILE_PCRE[8|16|32] */
281
282 /* This is an unsigned int value that no character can ever have. UTF-8
283 characters only go up to 0x7fffffff (though Unicode doesn't go beyond
284 0x0010ffff). */
285
286 #define NOTACHAR 0xffffffff
287
288 /* PCRE is able to support several different kinds of newline (CR, LF, CRLF,
289 "any" and "anycrlf" at present). The following macros are used to package up
290 testing for newlines. NLBLOCK, PSSTART, and PSEND are defined in the various
291 modules to indicate in which datablock the parameters exist, and what the
292 start/end of string field names are. */
293
294 #define NLTYPE_FIXED 0 /* Newline is a fixed length string */
295 #define NLTYPE_ANY 1 /* Newline is any Unicode line ending */
296 #define NLTYPE_ANYCRLF 2 /* Newline is CR, LF, or CRLF */
297
298 /* This macro checks for a newline at the given position */
299
300 #define IS_NEWLINE(p) \
301 ((NLBLOCK->nltype != NLTYPE_FIXED)? \
302 ((p) < NLBLOCK->PSEND && \
303 PRIV(is_newline)((p), NLBLOCK->nltype, NLBLOCK->PSEND, \
304 &(NLBLOCK->nllen), utf)) \
305 : \
306 ((p) <= NLBLOCK->PSEND - NLBLOCK->nllen && \
307 (p)[0] == NLBLOCK->nl[0] && \
308 (NLBLOCK->nllen == 1 || (p)[1] == NLBLOCK->nl[1]) \
309 ) \
310 )
311
312 /* This macro checks for a newline immediately preceding the given position */
313
314 #define WAS_NEWLINE(p) \
315 ((NLBLOCK->nltype != NLTYPE_FIXED)? \
316 ((p) > NLBLOCK->PSSTART && \
317 PRIV(was_newline)((p), NLBLOCK->nltype, NLBLOCK->PSSTART, \
318 &(NLBLOCK->nllen), utf)) \
319 : \
320 ((p) >= NLBLOCK->PSSTART + NLBLOCK->nllen && \
321 (p)[-NLBLOCK->nllen] == NLBLOCK->nl[0] && \
322 (NLBLOCK->nllen == 1 || (p)[-NLBLOCK->nllen+1] == NLBLOCK->nl[1]) \
323 ) \
324 )
325
326 /* When PCRE is compiled as a C++ library, the subject pointer can be replaced
327 with a custom type. This makes it possible, for example, to allow pcre_exec()
328 to process subject strings that are discontinuous by using a smart pointer
329 class. It must always be possible to inspect all of the subject string in
330 pcre_exec() because of the way it backtracks. Two macros are required in the
331 normal case, for sign-unspecified and unsigned char pointers. The former is
332 used for the external interface and appears in pcre.h, which is why its name
333 must begin with PCRE_. */
334
335 #ifdef CUSTOM_SUBJECT_PTR
336 #define PCRE_PUCHAR CUSTOM_SUBJECT_PTR
337 #else
338 #define PCRE_PUCHAR const pcre_uchar *
339 #endif
340
341 /* Include the public PCRE header and the definitions of UCP character property
342 values. */
343
344 #include "pcre.h"
345 #include "ucp.h"
346
347 /* When compiling for use with the Virtual Pascal compiler, these functions
348 need to have their names changed. PCRE must be compiled with the -DVPCOMPAT
349 option on the command line. */
350
351 #ifdef VPCOMPAT
352 #define strlen(s) _strlen(s)
353 #define strncmp(s1,s2,m) _strncmp(s1,s2,m)
354 #define memcmp(s,c,n) _memcmp(s,c,n)
355 #define memcpy(d,s,n) _memcpy(d,s,n)
356 #define memmove(d,s,n) _memmove(d,s,n)
357 #define memset(s,c,n) _memset(s,c,n)
358 #else /* VPCOMPAT */
359
360 /* To cope with SunOS4 and other systems that lack memmove() but have bcopy(),
361 define a macro for memmove() if HAVE_MEMMOVE is false, provided that HAVE_BCOPY
362 is set. Otherwise, include an emulating function for those systems that have
363 neither (there some non-Unix environments where this is the case). */
364
365 #ifndef HAVE_MEMMOVE
366 #undef memmove /* some systems may have a macro */
367 #ifdef HAVE_BCOPY
368 #define memmove(a, b, c) bcopy(b, a, c)
369 #else /* HAVE_BCOPY */
370 static void *
371 pcre_memmove(void *d, const void *s, size_t n)
372 {
373 size_t i;
374 unsigned char *dest = (unsigned char *)d;
375 const unsigned char *src = (const unsigned char *)s;
376 if (dest > src)
377 {
378 dest += n;
379 src += n;
380 for (i = 0; i < n; ++i) *(--dest) = *(--src);
381 return (void *)dest;
382 }
383 else
384 {
385 for (i = 0; i < n; ++i) *dest++ = *src++;
386 return (void *)(dest - n);
387 }
388 }
389 #define memmove(a, b, c) pcre_memmove(a, b, c)
390 #endif /* not HAVE_BCOPY */
391 #endif /* not HAVE_MEMMOVE */
392 #endif /* not VPCOMPAT */
393
394
395 /* PCRE keeps offsets in its compiled code as 2-byte quantities (always stored
396 in big-endian order) by default. These are used, for example, to link from the
397 start of a subpattern to its alternatives and its end. The use of 2 bytes per
398 offset limits the size of the compiled regex to around 64K, which is big enough
399 for almost everybody. However, I received a request for an even bigger limit.
400 For this reason, and also to make the code easier to maintain, the storing and
401 loading of offsets from the byte string is now handled by the macros that are
402 defined here.
403
404 The macros are controlled by the value of LINK_SIZE. This defaults to 2 in
405 the config.h file, but can be overridden by using -D on the command line. This
406 is automated on Unix systems via the "configure" command. */
407
408 #if defined COMPILE_PCRE8
409
410 #if LINK_SIZE == 2
411
412 #define PUT(a,n,d) \
413 (a[n] = (d) >> 8), \
414 (a[(n)+1] = (d) & 255)
415
416 #define GET(a,n) \
417 (((a)[n] << 8) | (a)[(n)+1])
418
419 #define MAX_PATTERN_SIZE (1 << 16)
420
421
422 #elif LINK_SIZE == 3
423
424 #define PUT(a,n,d) \
425 (a[n] = (d) >> 16), \
426 (a[(n)+1] = (d) >> 8), \
427 (a[(n)+2] = (d) & 255)
428
429 #define GET(a,n) \
430 (((a)[n] << 16) | ((a)[(n)+1] << 8) | (a)[(n)+2])
431
432 #define MAX_PATTERN_SIZE (1 << 24)
433
434
435 #elif LINK_SIZE == 4
436
437 #define PUT(a,n,d) \
438 (a[n] = (d) >> 24), \
439 (a[(n)+1] = (d) >> 16), \
440 (a[(n)+2] = (d) >> 8), \
441 (a[(n)+3] = (d) & 255)
442
443 #define GET(a,n) \
444 (((a)[n] << 24) | ((a)[(n)+1] << 16) | ((a)[(n)+2] << 8) | (a)[(n)+3])
445
446 /* Keep it positive */
447 #define MAX_PATTERN_SIZE (1 << 30)
448
449 #else
450 #error LINK_SIZE must be either 2, 3, or 4
451 #endif
452
453 #elif defined COMPILE_PCRE16
454
455 #if LINK_SIZE == 2
456
457 /* Redefine LINK_SIZE as a multiple of sizeof(pcre_uchar) */
458 #undef LINK_SIZE
459 #define LINK_SIZE 1
460
461 #define PUT(a,n,d) \
462 (a[n] = (d))
463
464 #define GET(a,n) \
465 (a[n])
466
467 #define MAX_PATTERN_SIZE (1 << 16)
468
469 #elif LINK_SIZE == 3 || LINK_SIZE == 4
470
471 /* Redefine LINK_SIZE as a multiple of sizeof(pcre_uchar) */
472 #undef LINK_SIZE
473 #define LINK_SIZE 2
474
475 #define PUT(a,n,d) \
476 (a[n] = (d) >> 16), \
477 (a[(n)+1] = (d) & 65535)
478
479 #define GET(a,n) \
480 (((a)[n] << 16) | (a)[(n)+1])
481
482 /* Keep it positive */
483 #define MAX_PATTERN_SIZE (1 << 30)
484
485 #else
486 #error LINK_SIZE must be either 2, 3, or 4
487 #endif
488
489 #elif defined COMPILE_PCRE32
490
491 /* Only supported LINK_SIZE is 4 */
492 /* Redefine LINK_SIZE as a multiple of sizeof(pcre_uchar) */
493 #undef LINK_SIZE
494 #define LINK_SIZE 1
495
496 #define PUT(a,n,d) \
497 (a[n] = (d))
498
499 #define GET(a,n) \
500 (a[n])
501
502 /* Keep it positive */
503 #define MAX_PATTERN_SIZE (1 << 30)
504
505 #else
506 #error Unsupported compiling mode
507 #endif /* COMPILE_PCRE[8|16|32] */
508
509 /* Convenience macro defined in terms of the others */
510
511 #define PUTINC(a,n,d) PUT(a,n,d), a += LINK_SIZE
512
513
514 /* PCRE uses some other 2-byte quantities that do not change when the size of
515 offsets changes. There are used for repeat counts and for other things such as
516 capturing parenthesis numbers in back references. */
517
518 #if defined COMPILE_PCRE8
519
520 #define IMM2_SIZE 2
521
522 #define PUT2(a,n,d) \
523 a[n] = (d) >> 8; \
524 a[(n)+1] = (d) & 255
525
526 #define GET2(a,n) \
527 (((a)[n] << 8) | (a)[(n)+1])
528
529 #elif defined COMPILE_PCRE16
530
531 #define IMM2_SIZE 1
532
533 #define PUT2(a,n,d) \
534 a[n] = d
535
536 #define GET2(a,n) \
537 a[n]
538
539 #elif defined COMPILE_PCRE32
540
541 #define IMM2_SIZE 1
542
543 #define PUT2(a,n,d) \
544 a[n] = d
545
546 #define GET2(a,n) \
547 a[n]
548
549 #else
550 #error Unsupported compiling mode
551 #endif /* COMPILE_PCRE[8|16|32] */
552
553 #define PUT2INC(a,n,d) PUT2(a,n,d), a += IMM2_SIZE
554
555 /* The maximum length of a MARK name is currently one data unit; it may be
556 changed in future to be a fixed number of bytes or to depend on LINK_SIZE. */
557
558 #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
559 #define MAX_MARK ((1u << 16) - 1)
560 #else
561 #define MAX_MARK ((1u << 8) - 1)
562 #endif
563
564 /* When UTF encoding is being used, a character is no longer just a single
565 byte. The macros for character handling generate simple sequences when used in
566 character-mode, and more complicated ones for UTF characters. GETCHARLENTEST
567 and other macros are not used when UTF is not supported, so they are not
568 defined. To make sure they can never even appear when UTF support is omitted,
569 we don't even define them. */
570
571 #ifndef SUPPORT_UTF
572
573 /* #define MAX_VALUE_FOR_SINGLE_CHAR */
574 /* #define HAS_EXTRALEN(c) */
575 /* #define GET_EXTRALEN(c) */
576 /* #define NOT_FIRSTCHAR(c) */
577 #define GETCHAR(c, eptr) c = *eptr;
578 #define GETCHARTEST(c, eptr) c = *eptr;
579 #define GETCHARINC(c, eptr) c = *eptr++;
580 #define GETCHARINCTEST(c, eptr) c = *eptr++;
581 #define GETCHARLEN(c, eptr, len) c = *eptr;
582 /* #define GETCHARLENTEST(c, eptr, len) */
583 /* #define BACKCHAR(eptr) */
584 /* #define FORWARDCHAR(eptr) */
585 /* #define ACROSSCHAR(condition, eptr, action) */
586
587 #else /* SUPPORT_UTF */
588
589 #if defined COMPILE_PCRE8
590
591 /* These macros were originally written in the form of loops that used data
592 from the tables whose names start with PRIV(utf8_table). They were rewritten by
593 a user so as not to use loops, because in some environments this gives a
594 significant performance advantage, and it seems never to do any harm. */
595
596 /* Tells the biggest code point which can be encoded as a single character. */
597
598 #define MAX_VALUE_FOR_SINGLE_CHAR 127
599
600 /* Tests whether the code point needs extra characters to decode. */
601
602 #define HAS_EXTRALEN(c) ((c) >= 0xc0)
603
604 /* Returns with the additional number of characters if IS_MULTICHAR(c) is TRUE.
605 Otherwise it has an undefined behaviour. */
606
607 #define GET_EXTRALEN(c) (PRIV(utf8_table4)[(c) & 0x3f])
608
609 /* Returns TRUE, if the given character is not the first character
610 of a UTF sequence. */
611
612 #define NOT_FIRSTCHAR(c) (((c) & 0xc0) == 0x80)
613
614 /* Base macro to pick up the remaining bytes of a UTF-8 character, not
615 advancing the pointer. */
616
617 #define GETUTF8(c, eptr) \
618 { \
619 if ((c & 0x20) == 0) \
620 c = ((c & 0x1f) << 6) | (eptr[1] & 0x3f); \
621 else if ((c & 0x10) == 0) \
622 c = ((c & 0x0f) << 12) | ((eptr[1] & 0x3f) << 6) | (eptr[2] & 0x3f); \
623 else if ((c & 0x08) == 0) \
624 c = ((c & 0x07) << 18) | ((eptr[1] & 0x3f) << 12) | \
625 ((eptr[2] & 0x3f) << 6) | (eptr[3] & 0x3f); \
626 else if ((c & 0x04) == 0) \
627 c = ((c & 0x03) << 24) | ((eptr[1] & 0x3f) << 18) | \
628 ((eptr[2] & 0x3f) << 12) | ((eptr[3] & 0x3f) << 6) | \
629 (eptr[4] & 0x3f); \
630 else \
631 c = ((c & 0x01) << 30) | ((eptr[1] & 0x3f) << 24) | \
632 ((eptr[2] & 0x3f) << 18) | ((eptr[3] & 0x3f) << 12) | \
633 ((eptr[4] & 0x3f) << 6) | (eptr[5] & 0x3f); \
634 }
635
636 /* Get the next UTF-8 character, not advancing the pointer. This is called when
637 we know we are in UTF-8 mode. */
638
639 #define GETCHAR(c, eptr) \
640 c = *eptr; \
641 if (c >= 0xc0) GETUTF8(c, eptr);
642
643 /* Get the next UTF-8 character, testing for UTF-8 mode, and not advancing the
644 pointer. */
645
646 #define GETCHARTEST(c, eptr) \
647 c = *eptr; \
648 if (utf && c >= 0xc0) GETUTF8(c, eptr);
649
650 /* Base macro to pick up the remaining bytes of a UTF-8 character, advancing
651 the pointer. */
652
653 #define GETUTF8INC(c, eptr) \
654 { \
655 if ((c & 0x20) == 0) \
656 c = ((c & 0x1f) << 6) | (*eptr++ & 0x3f); \
657 else if ((c & 0x10) == 0) \
658 { \
659 c = ((c & 0x0f) << 12) | ((*eptr & 0x3f) << 6) | (eptr[1] & 0x3f); \
660 eptr += 2; \
661 } \
662 else if ((c & 0x08) == 0) \
663 { \
664 c = ((c & 0x07) << 18) | ((*eptr & 0x3f) << 12) | \
665 ((eptr[1] & 0x3f) << 6) | (eptr[2] & 0x3f); \
666 eptr += 3; \
667 } \
668 else if ((c & 0x04) == 0) \
669 { \
670 c = ((c & 0x03) << 24) | ((*eptr & 0x3f) << 18) | \
671 ((eptr[1] & 0x3f) << 12) | ((eptr[2] & 0x3f) << 6) | \
672 (eptr[3] & 0x3f); \
673 eptr += 4; \
674 } \
675 else \
676 { \
677 c = ((c & 0x01) << 30) | ((*eptr & 0x3f) << 24) | \
678 ((eptr[1] & 0x3f) << 18) | ((eptr[2] & 0x3f) << 12) | \
679 ((eptr[3] & 0x3f) << 6) | (eptr[4] & 0x3f); \
680 eptr += 5; \
681 } \
682 }
683
684 /* Get the next UTF-8 character, advancing the pointer. This is called when we
685 know we are in UTF-8 mode. */
686
687 #define GETCHARINC(c, eptr) \
688 c = *eptr++; \
689 if (c >= 0xc0) GETUTF8INC(c, eptr);
690
691 /* Get the next character, testing for UTF-8 mode, and advancing the pointer.
692 This is called when we don't know if we are in UTF-8 mode. */
693
694 #define GETCHARINCTEST(c, eptr) \
695 c = *eptr++; \
696 if (utf && c >= 0xc0) GETUTF8INC(c, eptr);
697
698 /* Base macro to pick up the remaining bytes of a UTF-8 character, not
699 advancing the pointer, incrementing the length. */
700
701 #define GETUTF8LEN(c, eptr, len) \
702 { \
703 if ((c & 0x20) == 0) \
704 { \
705 c = ((c & 0x1f) << 6) | (eptr[1] & 0x3f); \
706 len++; \
707 } \
708 else if ((c & 0x10) == 0) \
709 { \
710 c = ((c & 0x0f) << 12) | ((eptr[1] & 0x3f) << 6) | (eptr[2] & 0x3f); \
711 len += 2; \
712 } \
713 else if ((c & 0x08) == 0) \
714 {\
715 c = ((c & 0x07) << 18) | ((eptr[1] & 0x3f) << 12) | \
716 ((eptr[2] & 0x3f) << 6) | (eptr[3] & 0x3f); \
717 len += 3; \
718 } \
719 else if ((c & 0x04) == 0) \
720 { \
721 c = ((c & 0x03) << 24) | ((eptr[1] & 0x3f) << 18) | \
722 ((eptr[2] & 0x3f) << 12) | ((eptr[3] & 0x3f) << 6) | \
723 (eptr[4] & 0x3f); \
724 len += 4; \
725 } \
726 else \
727 {\
728 c = ((c & 0x01) << 30) | ((eptr[1] & 0x3f) << 24) | \
729 ((eptr[2] & 0x3f) << 18) | ((eptr[3] & 0x3f) << 12) | \
730 ((eptr[4] & 0x3f) << 6) | (eptr[5] & 0x3f); \
731 len += 5; \
732 } \
733 }
734
735 /* Get the next UTF-8 character, not advancing the pointer, incrementing length
736 if there are extra bytes. This is called when we know we are in UTF-8 mode. */
737
738 #define GETCHARLEN(c, eptr, len) \
739 c = *eptr; \
740 if (c >= 0xc0) GETUTF8LEN(c, eptr, len);
741
742 /* Get the next UTF-8 character, testing for UTF-8 mode, not advancing the
743 pointer, incrementing length if there are extra bytes. This is called when we
744 do not know if we are in UTF-8 mode. */
745
746 #define GETCHARLENTEST(c, eptr, len) \
747 c = *eptr; \
748 if (utf && c >= 0xc0) GETUTF8LEN(c, eptr, len);
749
750 /* If the pointer is not at the start of a character, move it back until
751 it is. This is called only in UTF-8 mode - we don't put a test within the macro
752 because almost all calls are already within a block of UTF-8 only code. */
753
754 #define BACKCHAR(eptr) while((*eptr & 0xc0) == 0x80) eptr--
755
756 /* Same as above, just in the other direction. */
757 #define FORWARDCHAR(eptr) while((*eptr & 0xc0) == 0x80) eptr++
758
759 /* Same as above, but it allows a fully customizable form. */
760 #define ACROSSCHAR(condition, eptr, action) \
761 while((condition) && ((eptr) & 0xc0) == 0x80) action
762
763 #elif defined COMPILE_PCRE16
764
765 /* Tells the biggest code point which can be encoded as a single character. */
766
767 #define MAX_VALUE_FOR_SINGLE_CHAR 65535
768
769 /* Tests whether the code point needs extra characters to decode. */
770
771 #define HAS_EXTRALEN(c) (((c) & 0xfc00) == 0xd800)
772
773 /* Returns with the additional number of characters if IS_MULTICHAR(c) is TRUE.
774 Otherwise it has an undefined behaviour. */
775
776 #define GET_EXTRALEN(c) 1
777
778 /* Returns TRUE, if the given character is not the first character
779 of a UTF sequence. */
780
781 #define NOT_FIRSTCHAR(c) (((c) & 0xfc00) == 0xdc00)
782
783 /* Base macro to pick up the low surrogate of a UTF-16 character, not
784 advancing the pointer. */
785
786 #define GETUTF16(c, eptr) \
787 { c = (((c & 0x3ff) << 10) | (eptr[1] & 0x3ff)) + 0x10000; }
788
789 /* Get the next UTF-16 character, not advancing the pointer. This is called when
790 we know we are in UTF-16 mode. */
791
792 #define GETCHAR(c, eptr) \
793 c = *eptr; \
794 if ((c & 0xfc00) == 0xd800) GETUTF16(c, eptr);
795
796 /* Get the next UTF-16 character, testing for UTF-16 mode, and not advancing the
797 pointer. */
798
799 #define GETCHARTEST(c, eptr) \
800 c = *eptr; \
801 if (utf && (c & 0xfc00) == 0xd800) GETUTF16(c, eptr);
802
803 /* Base macro to pick up the low surrogate of a UTF-16 character, advancing
804 the pointer. */
805
806 #define GETUTF16INC(c, eptr) \
807 { c = (((c & 0x3ff) << 10) | (*eptr++ & 0x3ff)) + 0x10000; }
808
809 /* Get the next UTF-16 character, advancing the pointer. This is called when we
810 know we are in UTF-16 mode. */
811
812 #define GETCHARINC(c, eptr) \
813 c = *eptr++; \
814 if ((c & 0xfc00) == 0xd800) GETUTF16INC(c, eptr);
815
816 /* Get the next character, testing for UTF-16 mode, and advancing the pointer.
817 This is called when we don't know if we are in UTF-16 mode. */
818
819 #define GETCHARINCTEST(c, eptr) \
820 c = *eptr++; \
821 if (utf && (c & 0xfc00) == 0xd800) GETUTF16INC(c, eptr);
822
823 /* Base macro to pick up the low surrogate of a UTF-16 character, not
824 advancing the pointer, incrementing the length. */
825
826 #define GETUTF16LEN(c, eptr, len) \
827 { c = (((c & 0x3ff) << 10) | (eptr[1] & 0x3ff)) + 0x10000; len++; }
828
829 /* Get the next UTF-16 character, not advancing the pointer, incrementing
830 length if there is a low surrogate. This is called when we know we are in
831 UTF-16 mode. */
832
833 #define GETCHARLEN(c, eptr, len) \
834 c = *eptr; \
835 if ((c & 0xfc00) == 0xd800) GETUTF16LEN(c, eptr, len);
836
837 /* Get the next UTF-816character, testing for UTF-16 mode, not advancing the
838 pointer, incrementing length if there is a low surrogate. This is called when
839 we do not know if we are in UTF-16 mode. */
840
841 #define GETCHARLENTEST(c, eptr, len) \
842 c = *eptr; \
843 if (utf && (c & 0xfc00) == 0xd800) GETUTF16LEN(c, eptr, len);
844
845 /* If the pointer is not at the start of a character, move it back until
846 it is. This is called only in UTF-16 mode - we don't put a test within the
847 macro because almost all calls are already within a block of UTF-16 only
848 code. */
849
850 #define BACKCHAR(eptr) if ((*eptr & 0xfc00) == 0xdc00) eptr--
851
852 /* Same as above, just in the other direction. */
853 #define FORWARDCHAR(eptr) if ((*eptr & 0xfc00) == 0xdc00) eptr++
854
855 /* Same as above, but it allows a fully customizable form. */
856 #define ACROSSCHAR(condition, eptr, action) \
857 if ((condition) && ((eptr) & 0xfc00) == 0xdc00) action
858
859 #elif defined COMPILE_PCRE32
860
861 /* These are unnecessary for the 32-bit library */
862 #undef MAX_VALUE_FOR_SINGLE_CHAR
863 #undef HAS_EXTRALEN
864 #undef GET_EXTRALEN
865 #undef NOT_FIRSTCHAR
866
867 #define UTF32_MASK (0x1ffffful)
868
869 /* Get the next UTF-32 character, not advancing the pointer. This is called when
870 we know we are in UTF-32 mode. */
871
872 #define GETCHAR(c, eptr) \
873 c = (*eptr) & UTF32_MASK;
874
875 /* Get the next UTF-32 character, testing for UTF-32 mode, and not advancing the
876 pointer. */
877
878 #define GETCHARTEST(c, eptr) \
879 c = *eptr; \
880 if (utf) c &= UTF32_MASK;
881
882 /* Get the next UTF-32 character, advancing the pointer. This is called when we
883 know we are in UTF-32 mode. */
884
885 #define GETCHARINC(c, eptr) \
886 c = (*eptr++) & UTF32_MASK;
887
888 /* Get the next character, testing for UTF-32 mode, and advancing the pointer.
889 This is called when we don't know if we are in UTF-32 mode. */
890
891 #define GETCHARINCTEST(c, eptr) \
892 c = *eptr++; \
893 if (utf) c &= UTF32_MASK;
894
895 /* Get the next UTF-32 character, not advancing the pointer, not incrementing
896 length (since all UTF-32 is of length 1). This is called when we know we are in
897 UTF-32 mode. */
898
899 #define GETCHARLEN(c, eptr, len) \
900 GETCHAR(c, eptr)
901
902 /* Get the next UTF-32character, testing for UTF-32 mode, not advancing the
903 pointer, not incrementing the length (since all UTF-32 is of length 1).
904 This is called when we do not know if we are in UTF-32 mode. */
905
906 #define GETCHARLENTEST(c, eptr, len) \
907 GETCHARTEST(c, eptr)
908
909 /* If the pointer is not at the start of a character, move it back until
910 it is. This is called only in UTF-32 mode - we don't put a test within the
911 macro because almost all calls are already within a block of UTF-32 only
912 code. */
913
914 #define BACKCHAR(eptr) do { } while (0)
915
916 /* Same as above, just in the other direction. */
917 #define FORWARDCHAR(eptr) do { } while (0)
918
919 /* Same as above, but it allows a fully customizable form. */
920 #define ACROSSCHAR(condition, eptr, action) do { } while (0)
921
922 #else
923 #error Unsupported compiling mode
924 #endif /* COMPILE_PCRE[8|16|32] */
925
926 #endif /* SUPPORT_UTF */
927
928 /* Tests for Unicode horizontal and vertical whitespace characters must check a
929 number of different values. Using a switch statement for this generates the
930 fastest code (no loop, no memory access), and there are several places in the
931 interpreter code where this happens. In order to ensure that all the case lists
932 remain in step, we use macros so that there is only one place where the lists
933 are defined.
934
935 These values are also required as lists in pcre_compile.c when processing \h,
936 \H, \v and \V in a character class. The lists are defined in pcre_tables.c, but
937 macros that define the values are here so that all the definitions are
938 together. The lists must be in ascending character order, terminated by
939 NOTACHAR (which is 0xffffffff).
940
941 Any changes should ensure that the various macros are kept in step with each
942 other. NOTE: The values also appear in pcre_jit_compile.c. */
943
944 /* ------ ASCII/Unicode environments ------ */
945
946 #ifndef EBCDIC
947
948 #define HSPACE_LIST \
949 CHAR_HT, CHAR_SPACE, 0xa0, \
950 0x1680, 0x180e, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, \
951 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202f, 0x205f, 0x3000, \
952 NOTACHAR
953
954 #define HSPACE_MULTIBYTE_CASES \
955 case 0x1680: /* OGHAM SPACE MARK */ \
956 case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ \
957 case 0x2000: /* EN QUAD */ \
958 case 0x2001: /* EM QUAD */ \
959 case 0x2002: /* EN SPACE */ \
960 case 0x2003: /* EM SPACE */ \
961 case 0x2004: /* THREE-PER-EM SPACE */ \
962 case 0x2005: /* FOUR-PER-EM SPACE */ \
963 case 0x2006: /* SIX-PER-EM SPACE */ \
964 case 0x2007: /* FIGURE SPACE */ \
965 case 0x2008: /* PUNCTUATION SPACE */ \
966 case 0x2009: /* THIN SPACE */ \
967 case 0x200A: /* HAIR SPACE */ \
968 case 0x202f: /* NARROW NO-BREAK SPACE */ \
969 case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ \
970 case 0x3000 /* IDEOGRAPHIC SPACE */
971
972 #define HSPACE_BYTE_CASES \
973 case CHAR_HT: \
974 case CHAR_SPACE: \
975 case 0xa0 /* NBSP */
976
977 #define HSPACE_CASES \
978 HSPACE_BYTE_CASES: \
979 HSPACE_MULTIBYTE_CASES
980
981 #define VSPACE_LIST \
982 CHAR_LF, CHAR_VT, CHAR_FF, CHAR_CR, CHAR_NEL, 0x2028, 0x2029, NOTACHAR
983
984 #define VSPACE_MULTIBYTE_CASES \
985 case 0x2028: /* LINE SEPARATOR */ \
986 case 0x2029 /* PARAGRAPH SEPARATOR */
987
988 #define VSPACE_BYTE_CASES \
989 case CHAR_LF: \
990 case CHAR_VT: \
991 case CHAR_FF: \
992 case CHAR_CR: \
993 case CHAR_NEL
994
995 #define VSPACE_CASES \
996 VSPACE_BYTE_CASES: \
997 VSPACE_MULTIBYTE_CASES
998
999 /* ------ EBCDIC environments ------ */
1000
1001 #else
1002 #define HSPACE_LIST CHAR_HT, CHAR_SPACE
1003
1004 #define HSPACE_BYTE_CASES \
1005 case CHAR_HT: \
1006 case CHAR_SPACE
1007
1008 #define HSPACE_CASES HSPACE_BYTE_CASES
1009
1010 #ifdef EBCDIC_NL25
1011 #define VSPACE_LIST \
1012 CHAR_VT, CHAR_FF, CHAR_CR, CHAR_NEL, CHAR_LF, NOTACHAR
1013 #else
1014 #define VSPACE_LIST \
1015 CHAR_VT, CHAR_FF, CHAR_CR, CHAR_LF, CHAR_NEL, NOTACHAR
1016 #endif
1017
1018 #define VSPACE_BYTE_CASES \
1019 case CHAR_LF: \
1020 case CHAR_VT: \
1021 case CHAR_FF: \
1022 case CHAR_CR: \
1023 case CHAR_NEL
1024
1025 #define VSPACE_CASES VSPACE_BYTE_CASES
1026 #endif /* EBCDIC */
1027
1028 /* ------ End of whitespace macros ------ */
1029
1030
1031
1032 /* Private flags containing information about the compiled regex. They used to
1033 live at the top end of the options word, but that got almost full, so now they
1034 are in a 16-bit flags word. From release 8.00, PCRE_NOPARTIAL is unused, as
1035 the restrictions on partial matching have been lifted. It remains for backwards
1036 compatibility. */
1037
1038 #define PCRE_MODE8 0x0001 /* compiled in 8 bit mode */
1039 #define PCRE_MODE16 0x0002 /* compiled in 16 bit mode */
1040 #define PCRE_MODE32 0x0004 /* compiled in 32 bit mode */
1041 #define PCRE_FIRSTSET 0x0010 /* first_char is set */
1042 #define PCRE_FCH_CASELESS 0x0020 /* caseless first char */
1043 #define PCRE_REQCHSET 0x0040 /* req_byte is set */
1044 #define PCRE_RCH_CASELESS 0x0080 /* caseless requested char */
1045 #define PCRE_STARTLINE 0x0100 /* start after \n for multiline */
1046 #define PCRE_NOPARTIAL 0x0200 /* can't use partial with this regex */
1047 #define PCRE_JCHANGED 0x0400 /* j option used in regex */
1048 #define PCRE_HASCRORLF 0x0800 /* explicit \r or \n in pattern */
1049 #define PCRE_HASTHEN 0x1000 /* pattern contains (*THEN) */
1050
1051 #if defined COMPILE_PCRE8
1052 #define PCRE_MODE PCRE_MODE8
1053 #elif defined COMPILE_PCRE16
1054 #define PCRE_MODE PCRE_MODE16
1055 #elif defined COMPILE_PCRE32
1056 #define PCRE_MODE PCRE_MODE32
1057 #endif
1058 #define PCRE_MODE_MASK (PCRE_MODE8 | PCRE_MODE16 | PCRE_MODE32)
1059
1060 /* Flags for the "extra" block produced by pcre_study(). */
1061
1062 #define PCRE_STUDY_MAPPED 0x0001 /* a map of starting chars exists */
1063 #define PCRE_STUDY_MINLEN 0x0002 /* a minimum length field exists */
1064
1065 /* Masks for identifying the public options that are permitted at compile
1066 time, run time, or study time, respectively. */
1067
1068 #define PCRE_NEWLINE_BITS (PCRE_NEWLINE_CR|PCRE_NEWLINE_LF|PCRE_NEWLINE_ANY| \
1069 PCRE_NEWLINE_ANYCRLF)
1070
1071 #define PUBLIC_COMPILE_OPTIONS \
1072 (PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \
1073 PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY|PCRE_UTF8| \
1074 PCRE_NO_AUTO_CAPTURE|PCRE_NO_UTF8_CHECK|PCRE_AUTO_CALLOUT|PCRE_FIRSTLINE| \
1075 PCRE_DUPNAMES|PCRE_NEWLINE_BITS|PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE| \
1076 PCRE_JAVASCRIPT_COMPAT|PCRE_UCP|PCRE_NO_START_OPTIMIZE)
1077
1078 #define PUBLIC_EXEC_OPTIONS \
1079 (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NOTEMPTY_ATSTART| \
1080 PCRE_NO_UTF8_CHECK|PCRE_PARTIAL_HARD|PCRE_PARTIAL_SOFT|PCRE_NEWLINE_BITS| \
1081 PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE|PCRE_NO_START_OPTIMIZE)
1082
1083 #define PUBLIC_DFA_EXEC_OPTIONS \
1084 (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NOTEMPTY_ATSTART| \
1085 PCRE_NO_UTF8_CHECK|PCRE_PARTIAL_HARD|PCRE_PARTIAL_SOFT|PCRE_DFA_SHORTEST| \
1086 PCRE_DFA_RESTART|PCRE_NEWLINE_BITS|PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE| \
1087 PCRE_NO_START_OPTIMIZE)
1088
1089 #define PUBLIC_STUDY_OPTIONS \
1090 (PCRE_STUDY_JIT_COMPILE|PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE| \
1091 PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE|PCRE_STUDY_EXTRA_NEEDED)
1092
1093 /* Magic number to provide a small check against being handed junk. */
1094
1095 #define MAGIC_NUMBER 0x50435245UL /* 'PCRE' */
1096
1097 /* This variable is used to detect a loaded regular expression
1098 in different endianness. */
1099
1100 #define REVERSED_MAGIC_NUMBER 0x45524350UL /* 'ERCP' */
1101
1102 /* The maximum remaining length of subject we are prepared to search for a
1103 req_byte match. */
1104
1105 #define REQ_BYTE_MAX 1000
1106
1107 /* Miscellaneous definitions. The #ifndef is to pacify compiler warnings in
1108 environments where these macros are defined elsewhere. Unfortunately, there
1109 is no way to do the same for the typedef. */
1110
1111 typedef int BOOL;
1112
1113 #ifndef FALSE
1114 #define FALSE 0
1115 #define TRUE 1
1116 #endif
1117
1118 /* If PCRE is to support UTF-8 on EBCDIC platforms, we cannot use normal
1119 character constants like '*' because the compiler would emit their EBCDIC code,
1120 which is different from their ASCII/UTF-8 code. Instead we define macros for
1121 the characters so that they always use the ASCII/UTF-8 code when UTF-8 support
1122 is enabled. When UTF-8 support is not enabled, the definitions use character
1123 literals. Both character and string versions of each character are needed, and
1124 there are some longer strings as well.
1125
1126 This means that, on EBCDIC platforms, the PCRE library can handle either
1127 EBCDIC, or UTF-8, but not both. To support both in the same compiled library
1128 would need different lookups depending on whether PCRE_UTF8 was set or not.
1129 This would make it impossible to use characters in switch/case statements,
1130 which would reduce performance. For a theoretical use (which nobody has asked
1131 for) in a minority area (EBCDIC platforms), this is not sensible. Any
1132 application that did need both could compile two versions of the library, using
1133 macros to give the functions distinct names. */
1134
1135 #ifndef SUPPORT_UTF
1136
1137 /* UTF-8 support is not enabled; use the platform-dependent character literals
1138 so that PCRE works in both ASCII and EBCDIC environments, but only in non-UTF
1139 mode. Newline characters are problematic in EBCDIC. Though it has CR and LF
1140 characters, a common practice has been to use its NL (0x15) character as the
1141 line terminator in C-like processing environments. However, sometimes the LF
1142 (0x25) character is used instead, according to this Unicode document:
1143
1144 http://unicode.org/standard/reports/tr13/tr13-5.html
1145
1146 PCRE defaults EBCDIC NL to 0x15, but has a build-time option to select 0x25
1147 instead. Whichever is *not* chosen is defined as NEL.
1148
1149 In both ASCII and EBCDIC environments, CHAR_NL and CHAR_LF are synonyms for the
1150 same code point. */
1151
1152 #ifdef EBCDIC
1153
1154 #ifndef EBCDIC_NL25
1155 #define CHAR_NL '\x15'
1156 #define CHAR_NEL '\x25'
1157 #define STR_NL "\x15"
1158 #define STR_NEL "\x25"
1159 #else
1160 #define CHAR_NL '\x25'
1161 #define CHAR_NEL '\x15'
1162 #define STR_NL "\x25"
1163 #define STR_NEL "\x15"
1164 #endif
1165
1166 #define CHAR_LF CHAR_NL
1167 #define STR_LF STR_NL
1168
1169 #define CHAR_ESC '\047'
1170 #define CHAR_DEL '\007'
1171 #define STR_ESC "\047"
1172 #define STR_DEL "\007"
1173
1174 #else /* Not EBCDIC */
1175
1176 /* In ASCII/Unicode, linefeed is '\n' and we equate this to NL for
1177 compatibility. NEL is the Unicode newline character; make sure it is
1178 a positive value. */
1179
1180 #define CHAR_LF '\n'
1181 #define CHAR_NL CHAR_LF
1182 #define CHAR_NEL ((unsigned char)'\x85')
1183 #define CHAR_ESC '\033'
1184 #define CHAR_DEL '\177'
1185
1186 #define STR_LF "\n"
1187 #define STR_NL STR_LF
1188 #define STR_NEL "\x85"
1189 #define STR_ESC "\033"
1190 #define STR_DEL "\177"
1191
1192 #endif /* EBCDIC */
1193
1194 /* The remaining definitions work in both environments. */
1195
1196 #define CHAR_HT '\t'
1197 #define CHAR_VT '\v'
1198 #define CHAR_FF '\f'
1199 #define CHAR_CR '\r'
1200 #define CHAR_BS '\b'
1201 #define CHAR_BEL '\a'
1202
1203 #define CHAR_SPACE ' '
1204 #define CHAR_EXCLAMATION_MARK '!'
1205 #define CHAR_QUOTATION_MARK '"'
1206 #define CHAR_NUMBER_SIGN '#'
1207 #define CHAR_DOLLAR_SIGN '$'
1208 #define CHAR_PERCENT_SIGN '%'
1209 #define CHAR_AMPERSAND '&'
1210 #define CHAR_APOSTROPHE '\''
1211 #define CHAR_LEFT_PARENTHESIS '('
1212 #define CHAR_RIGHT_PARENTHESIS ')'
1213 #define CHAR_ASTERISK '*'
1214 #define CHAR_PLUS '+'
1215 #define CHAR_COMMA ','
1216 #define CHAR_MINUS '-'
1217 #define CHAR_DOT '.'
1218 #define CHAR_SLASH '/'
1219 #define CHAR_0 '0'
1220 #define CHAR_1 '1'
1221 #define CHAR_2 '2'
1222 #define CHAR_3 '3'
1223 #define CHAR_4 '4'
1224 #define CHAR_5 '5'
1225 #define CHAR_6 '6'
1226 #define CHAR_7 '7'
1227 #define CHAR_8 '8'
1228 #define CHAR_9 '9'
1229 #define CHAR_COLON ':'
1230 #define CHAR_SEMICOLON ';'
1231 #define CHAR_LESS_THAN_SIGN '<'
1232 #define CHAR_EQUALS_SIGN '='
1233 #define CHAR_GREATER_THAN_SIGN '>'
1234 #define CHAR_QUESTION_MARK '?'
1235 #define CHAR_COMMERCIAL_AT '@'
1236 #define CHAR_A 'A'
1237 #define CHAR_B 'B'
1238 #define CHAR_C 'C'
1239 #define CHAR_D 'D'
1240 #define CHAR_E 'E'
1241 #define CHAR_F 'F'
1242 #define CHAR_G 'G'
1243 #define CHAR_H 'H'
1244 #define CHAR_I 'I'
1245 #define CHAR_J 'J'
1246 #define CHAR_K 'K'
1247 #define CHAR_L 'L'
1248 #define CHAR_M 'M'
1249 #define CHAR_N 'N'
1250 #define CHAR_O 'O'
1251 #define CHAR_P 'P'
1252 #define CHAR_Q 'Q'
1253 #define CHAR_R 'R'
1254 #define CHAR_S 'S'
1255 #define CHAR_T 'T'
1256 #define CHAR_U 'U'
1257 #define CHAR_V 'V'
1258 #define CHAR_W 'W'
1259 #define CHAR_X 'X'
1260 #define CHAR_Y 'Y'
1261 #define CHAR_Z 'Z'
1262 #define CHAR_LEFT_SQUARE_BRACKET '['
1263 #define CHAR_BACKSLASH '\\'
1264 #define CHAR_RIGHT_SQUARE_BRACKET ']'
1265 #define CHAR_CIRCUMFLEX_ACCENT '^'
1266 #define CHAR_UNDERSCORE '_'
1267 #define CHAR_GRAVE_ACCENT '`'
1268 #define CHAR_a 'a'
1269 #define CHAR_b 'b'
1270 #define CHAR_c 'c'
1271 #define CHAR_d 'd'
1272 #define CHAR_e 'e'
1273 #define CHAR_f 'f'
1274 #define CHAR_g 'g'
1275 #define CHAR_h 'h'
1276 #define CHAR_i 'i'
1277 #define CHAR_j 'j'
1278 #define CHAR_k 'k'
1279 #define CHAR_l 'l'
1280 #define CHAR_m 'm'
1281 #define CHAR_n 'n'
1282 #define CHAR_o 'o'
1283 #define CHAR_p 'p'
1284 #define CHAR_q 'q'
1285 #define CHAR_r 'r'
1286 #define CHAR_s 's'
1287 #define CHAR_t 't'
1288 #define CHAR_u 'u'
1289 #define CHAR_v 'v'
1290 #define CHAR_w 'w'
1291 #define CHAR_x 'x'
1292 #define CHAR_y 'y'
1293 #define CHAR_z 'z'
1294 #define CHAR_LEFT_CURLY_BRACKET '{'
1295 #define CHAR_VERTICAL_LINE '|'
1296 #define CHAR_RIGHT_CURLY_BRACKET '}'
1297 #define CHAR_TILDE '~'
1298
1299 #define STR_HT "\t"
1300 #define STR_VT "\v"
1301 #define STR_FF "\f"
1302 #define STR_CR "\r"
1303 #define STR_BS "\b"
1304 #define STR_BEL "\a"
1305
1306 #define STR_SPACE " "
1307 #define STR_EXCLAMATION_MARK "!"
1308 #define STR_QUOTATION_MARK "\""
1309 #define STR_NUMBER_SIGN "#"
1310 #define STR_DOLLAR_SIGN "$"
1311 #define STR_PERCENT_SIGN "%"
1312 #define STR_AMPERSAND "&"
1313 #define STR_APOSTROPHE "'"
1314 #define STR_LEFT_PARENTHESIS "("
1315 #define STR_RIGHT_PARENTHESIS ")"
1316 #define STR_ASTERISK "*"
1317 #define STR_PLUS "+"
1318 #define STR_COMMA ","
1319 #define STR_MINUS "-"
1320 #define STR_DOT "."
1321 #define STR_SLASH "/"
1322 #define STR_0 "0"
1323 #define STR_1 "1"
1324 #define STR_2 "2"
1325 #define STR_3 "3"
1326 #define STR_4 "4"
1327 #define STR_5 "5"
1328 #define STR_6 "6"
1329 #define STR_7 "7"
1330 #define STR_8 "8"
1331 #define STR_9 "9"
1332 #define STR_COLON ":"
1333 #define STR_SEMICOLON ";"
1334 #define STR_LESS_THAN_SIGN "<"
1335 #define STR_EQUALS_SIGN "="
1336 #define STR_GREATER_THAN_SIGN ">"
1337 #define STR_QUESTION_MARK "?"
1338 #define STR_COMMERCIAL_AT "@"
1339 #define STR_A "A"
1340 #define STR_B "B"
1341 #define STR_C "C"
1342 #define STR_D "D"
1343 #define STR_E "E"
1344 #define STR_F "F"
1345 #define STR_G "G"
1346 #define STR_H "H"
1347 #define STR_I "I"
1348 #define STR_J "J"
1349 #define STR_K "K"
1350 #define STR_L "L"
1351 #define STR_M "M"
1352 #define STR_N "N"
1353 #define STR_O "O"
1354 #define STR_P "P"
1355 #define STR_Q "Q"
1356 #define STR_R "R"
1357 #define STR_S "S"
1358 #define STR_T "T"
1359 #define STR_U "U"
1360 #define STR_V "V"
1361 #define STR_W "W"
1362 #define STR_X "X"
1363 #define STR_Y "Y"
1364 #define STR_Z "Z"
1365 #define STR_LEFT_SQUARE_BRACKET "["
1366 #define STR_BACKSLASH "\\"
1367 #define STR_RIGHT_SQUARE_BRACKET "]"
1368 #define STR_CIRCUMFLEX_ACCENT "^"
1369 #define STR_UNDERSCORE "_"
1370 #define STR_GRAVE_ACCENT "`"
1371 #define STR_a "a"
1372 #define STR_b "b"
1373 #define STR_c "c"
1374 #define STR_d "d"
1375 #define STR_e "e"
1376 #define STR_f "f"
1377 #define STR_g "g"
1378 #define STR_h "h"
1379 #define STR_i "i"
1380 #define STR_j "j"
1381 #define STR_k "k"
1382 #define STR_l "l"
1383 #define STR_m "m"
1384 #define STR_n "n"
1385 #define STR_o "o"
1386 #define STR_p "p"
1387 #define STR_q "q"
1388 #define STR_r "r"
1389 #define STR_s "s"
1390 #define STR_t "t"
1391 #define STR_u "u"
1392 #define STR_v "v"
1393 #define STR_w "w"
1394 #define STR_x "x"
1395 #define STR_y "y"
1396 #define STR_z "z"
1397 #define STR_LEFT_CURLY_BRACKET "{"
1398 #define STR_VERTICAL_LINE "|"
1399 #define STR_RIGHT_CURLY_BRACKET "}"
1400 #define STR_TILDE "~"
1401
1402 #define STRING_ACCEPT0 "ACCEPT\0"
1403 #define STRING_COMMIT0 "COMMIT\0"
1404 #define STRING_F0 "F\0"
1405 #define STRING_FAIL0 "FAIL\0"
1406 #define STRING_MARK0 "MARK\0"
1407 #define STRING_PRUNE0 "PRUNE\0"
1408 #define STRING_SKIP0 "SKIP\0"
1409 #define STRING_THEN "THEN"
1410
1411 #define STRING_alpha0 "alpha\0"
1412 #define STRING_lower0 "lower\0"
1413 #define STRING_upper0 "upper\0"
1414 #define STRING_alnum0 "alnum\0"
1415 #define STRING_ascii0 "ascii\0"
1416 #define STRING_blank0 "blank\0"
1417 #define STRING_cntrl0 "cntrl\0"
1418 #define STRING_digit0 "digit\0"
1419 #define STRING_graph0 "graph\0"
1420 #define STRING_print0 "print\0"
1421 #define STRING_punct0 "punct\0"
1422 #define STRING_space0 "space\0"
1423 #define STRING_word0 "word\0"
1424 #define STRING_xdigit "xdigit"
1425
1426 #define STRING_DEFINE "DEFINE"
1427
1428 #define STRING_CR_RIGHTPAR "CR)"
1429 #define STRING_LF_RIGHTPAR "LF)"
1430 #define STRING_CRLF_RIGHTPAR "CRLF)"
1431 #define STRING_ANY_RIGHTPAR "ANY)"
1432 #define STRING_ANYCRLF_RIGHTPAR "ANYCRLF)"
1433 #define STRING_BSR_ANYCRLF_RIGHTPAR "BSR_ANYCRLF)"
1434 #define STRING_BSR_UNICODE_RIGHTPAR "BSR_UNICODE)"
1435 #ifdef COMPILE_PCRE8
1436 #define STRING_UTF_RIGHTPAR "UTF8)"
1437 #endif
1438 #ifdef COMPILE_PCRE16
1439 #define STRING_UTF_RIGHTPAR "UTF16)"
1440 #endif
1441 #ifdef COMPILE_PCRE32
1442 #define STRING_UTF_RIGHTPAR "UTF32)"
1443 #endif
1444 #define STRING_UCP_RIGHTPAR "UCP)"
1445 #define STRING_NO_START_OPT_RIGHTPAR "NO_START_OPT)"
1446
1447 #else /* SUPPORT_UTF */
1448
1449 /* UTF-8 support is enabled; always use UTF-8 (=ASCII) character codes. This
1450 works in both modes non-EBCDIC platforms, and on EBCDIC platforms in UTF-8 mode
1451 only. */
1452
1453 #define CHAR_HT '\011'
1454 #define CHAR_VT '\013'
1455 #define CHAR_FF '\014'
1456 #define CHAR_CR '\015'
1457 #define CHAR_LF '\012'
1458 #define CHAR_NL CHAR_LF
1459 #define CHAR_NEL ((unsigned char)'\x85')
1460 #define CHAR_BS '\010'
1461 #define CHAR_BEL '\007'
1462 #define CHAR_ESC '\033'
1463 #define CHAR_DEL '\177'
1464
1465 #define CHAR_SPACE '\040'
1466 #define CHAR_EXCLAMATION_MARK '\041'
1467 #define CHAR_QUOTATION_MARK '\042'
1468 #define CHAR_NUMBER_SIGN '\043'
1469 #define CHAR_DOLLAR_SIGN '\044'
1470 #define CHAR_PERCENT_SIGN '\045'
1471 #define CHAR_AMPERSAND '\046'
1472 #define CHAR_APOSTROPHE '\047'
1473 #define CHAR_LEFT_PARENTHESIS '\050'
1474 #define CHAR_RIGHT_PARENTHESIS '\051'
1475 #define CHAR_ASTERISK '\052'
1476 #define CHAR_PLUS '\053'
1477 #define CHAR_COMMA '\054'
1478 #define CHAR_MINUS '\055'
1479 #define CHAR_DOT '\056'
1480 #define CHAR_SLASH '\057'
1481 #define CHAR_0 '\060'
1482 #define CHAR_1 '\061'
1483 #define CHAR_2 '\062'
1484 #define CHAR_3 '\063'
1485 #define CHAR_4 '\064'
1486 #define CHAR_5 '\065'
1487 #define CHAR_6 '\066'
1488 #define CHAR_7 '\067'
1489 #define CHAR_8 '\070'
1490 #define CHAR_9 '\071'
1491 #define CHAR_COLON '\072'
1492 #define CHAR_SEMICOLON '\073'
1493 #define CHAR_LESS_THAN_SIGN '\074'
1494 #define CHAR_EQUALS_SIGN '\075'
1495 #define CHAR_GREATER_THAN_SIGN '\076'
1496 #define CHAR_QUESTION_MARK '\077'
1497 #define CHAR_COMMERCIAL_AT '\100'
1498 #define CHAR_A '\101'
1499 #define CHAR_B '\102'
1500 #define CHAR_C '\103'
1501 #define CHAR_D '\104'
1502 #define CHAR_E '\105'
1503 #define CHAR_F '\106'
1504 #define CHAR_G '\107'
1505 #define CHAR_H '\110'
1506 #define CHAR_I '\111'
1507 #define CHAR_J '\112'
1508 #define CHAR_K '\113'
1509 #define CHAR_L '\114'
1510 #define CHAR_M '\115'
1511 #define CHAR_N '\116'
1512 #define CHAR_O '\117'
1513 #define CHAR_P '\120'
1514 #define CHAR_Q '\121'
1515 #define CHAR_R '\122'
1516 #define CHAR_S '\123'
1517 #define CHAR_T '\124'
1518 #define CHAR_U '\125'
1519 #define CHAR_V '\126'
1520 #define CHAR_W '\127'
1521 #define CHAR_X '\130'
1522 #define CHAR_Y '\131'
1523 #define CHAR_Z '\132'
1524 #define CHAR_LEFT_SQUARE_BRACKET '\133'
1525 #define CHAR_BACKSLASH '\134'
1526 #define CHAR_RIGHT_SQUARE_BRACKET '\135'
1527 #define CHAR_CIRCUMFLEX_ACCENT '\136'
1528 #define CHAR_UNDERSCORE '\137'
1529 #define CHAR_GRAVE_ACCENT '\140'
1530 #define CHAR_a '\141'
1531 #define CHAR_b '\142'
1532 #define CHAR_c '\143'
1533 #define CHAR_d '\144'
1534 #define CHAR_e '\145'
1535 #define CHAR_f '\146'
1536 #define CHAR_g '\147'
1537 #define CHAR_h '\150'
1538 #define CHAR_i '\151'
1539 #define CHAR_j '\152'
1540 #define CHAR_k '\153'
1541 #define CHAR_l '\154'
1542 #define CHAR_m '\155'
1543 #define CHAR_n '\156'
1544 #define CHAR_o '\157'
1545 #define CHAR_p '\160'
1546 #define CHAR_q '\161'
1547 #define CHAR_r '\162'
1548 #define CHAR_s '\163'
1549 #define CHAR_t '\164'
1550 #define CHAR_u '\165'
1551 #define CHAR_v '\166'
1552 #define CHAR_w '\167'
1553 #define CHAR_x '\170'
1554 #define CHAR_y '\171'
1555 #define CHAR_z '\172'
1556 #define CHAR_LEFT_CURLY_BRACKET '\173'
1557 #define CHAR_VERTICAL_LINE '\174'
1558 #define CHAR_RIGHT_CURLY_BRACKET '\175'
1559 #define CHAR_TILDE '\176'
1560
1561 #define STR_HT "\011"
1562 #define STR_VT "\013"
1563 #define STR_FF "\014"
1564 #define STR_CR "\015"
1565 #define STR_NL "\012"
1566 #define STR_BS "\010"
1567 #define STR_BEL "\007"
1568 #define STR_ESC "\033"
1569 #define STR_DEL "\177"
1570
1571 #define STR_SPACE "\040"
1572 #define STR_EXCLAMATION_MARK "\041"
1573 #define STR_QUOTATION_MARK "\042"
1574 #define STR_NUMBER_SIGN "\043"
1575 #define STR_DOLLAR_SIGN "\044"
1576 #define STR_PERCENT_SIGN "\045"
1577 #define STR_AMPERSAND "\046"
1578 #define STR_APOSTROPHE "\047"
1579 #define STR_LEFT_PARENTHESIS "\050"
1580 #define STR_RIGHT_PARENTHESIS "\051"
1581 #define STR_ASTERISK "\052"
1582 #define STR_PLUS "\053"
1583 #define STR_COMMA "\054"
1584 #define STR_MINUS "\055"
1585 #define STR_DOT "\056"
1586 #define STR_SLASH "\057"
1587 #define STR_0 "\060"
1588 #define STR_1 "\061"
1589 #define STR_2 "\062"
1590 #define STR_3 "\063"
1591 #define STR_4 "\064"
1592 #define STR_5 "\065"
1593 #define STR_6 "\066"
1594 #define STR_7 "\067"
1595 #define STR_8 "\070"
1596 #define STR_9 "\071"
1597 #define STR_COLON "\072"
1598 #define STR_SEMICOLON "\073"
1599 #define STR_LESS_THAN_SIGN "\074"
1600 #define STR_EQUALS_SIGN "\075"
1601 #define STR_GREATER_THAN_SIGN "\076"
1602 #define STR_QUESTION_MARK "\077"
1603 #define STR_COMMERCIAL_AT "\100"
1604 #define STR_A "\101"
1605 #define STR_B "\102"
1606 #define STR_C "\103"
1607 #define STR_D "\104"
1608 #define STR_E "\105"
1609 #define STR_F "\106"
1610 #define STR_G "\107"
1611 #define STR_H "\110"
1612 #define STR_I "\111"
1613 #define STR_J "\112"
1614 #define STR_K "\113"
1615 #define STR_L "\114"
1616 #define STR_M "\115"
1617 #define STR_N "\116"
1618 #define STR_O "\117"
1619 #define STR_P "\120"
1620 #define STR_Q "\121"
1621 #define STR_R "\122"
1622 #define STR_S "\123"
1623 #define STR_T "\124"
1624 #define STR_U "\125"
1625 #define STR_V "\126"
1626 #define STR_W "\127"
1627 #define STR_X "\130"
1628 #define STR_Y "\131"
1629 #define STR_Z "\132"
1630 #define STR_LEFT_SQUARE_BRACKET "\133"
1631 #define STR_BACKSLASH "\134"
1632 #define STR_RIGHT_SQUARE_BRACKET "\135"
1633 #define STR_CIRCUMFLEX_ACCENT "\136"
1634 #define STR_UNDERSCORE "\137"
1635 #define STR_GRAVE_ACCENT "\140"
1636 #define STR_a "\141"
1637 #define STR_b "\142"
1638 #define STR_c "\143"
1639 #define STR_d "\144"
1640 #define STR_e "\145"
1641 #define STR_f "\146"
1642 #define STR_g "\147"
1643 #define STR_h "\150"
1644 #define STR_i "\151"
1645 #define STR_j "\152"
1646 #define STR_k "\153"
1647 #define STR_l "\154"
1648 #define STR_m "\155"
1649 #define STR_n "\156"
1650 #define STR_o "\157"
1651 #define STR_p "\160"
1652 #define STR_q "\161"
1653 #define STR_r "\162"
1654 #define STR_s "\163"
1655 #define STR_t "\164"
1656 #define STR_u "\165"
1657 #define STR_v "\166"
1658 #define STR_w "\167"
1659 #define STR_x "\170"
1660 #define STR_y "\171"
1661 #define STR_z "\172"
1662 #define STR_LEFT_CURLY_BRACKET "\173"
1663 #define STR_VERTICAL_LINE "\174"
1664 #define STR_RIGHT_CURLY_BRACKET "\175"
1665 #define STR_TILDE "\176"
1666
1667 #define STRING_ACCEPT0 STR_A STR_C STR_C STR_E STR_P STR_T "\0"
1668 #define STRING_COMMIT0 STR_C STR_O STR_M STR_M STR_I STR_T "\0"
1669 #define STRING_F0 STR_F "\0"
1670 #define STRING_FAIL0 STR_F STR_A STR_I STR_L "\0"
1671 #define STRING_MARK0 STR_M STR_A STR_R STR_K "\0"
1672 #define STRING_PRUNE0 STR_P STR_R STR_U STR_N STR_E "\0"
1673 #define STRING_SKIP0 STR_S STR_K STR_I STR_P "\0"
1674 #define STRING_THEN STR_T STR_H STR_E STR_N
1675
1676 #define STRING_alpha0 STR_a STR_l STR_p STR_h STR_a "\0"
1677 #define STRING_lower0 STR_l STR_o STR_w STR_e STR_r "\0"
1678 #define STRING_upper0 STR_u STR_p STR_p STR_e STR_r "\0"
1679 #define STRING_alnum0 STR_a STR_l STR_n STR_u STR_m "\0"
1680 #define STRING_ascii0 STR_a STR_s STR_c STR_i STR_i "\0"
1681 #define STRING_blank0 STR_b STR_l STR_a STR_n STR_k "\0"
1682 #define STRING_cntrl0 STR_c STR_n STR_t STR_r STR_l "\0"
1683 #define STRING_digit0 STR_d STR_i STR_g STR_i STR_t "\0"
1684 #define STRING_graph0 STR_g STR_r STR_a STR_p STR_h "\0"
1685 #define STRING_print0 STR_p STR_r STR_i STR_n STR_t "\0"
1686 #define STRING_punct0 STR_p STR_u STR_n STR_c STR_t "\0"
1687 #define STRING_space0 STR_s STR_p STR_a STR_c STR_e "\0"
1688 #define STRING_word0 STR_w STR_o STR_r STR_d "\0"
1689 #define STRING_xdigit STR_x STR_d STR_i STR_g STR_i STR_t
1690
1691 #define STRING_DEFINE STR_D STR_E STR_F STR_I STR_N STR_E
1692
1693 #define STRING_CR_RIGHTPAR STR_C STR_R STR_RIGHT_PARENTHESIS
1694 #define STRING_LF_RIGHTPAR STR_L STR_F STR_RIGHT_PARENTHESIS
1695 #define STRING_CRLF_RIGHTPAR STR_C STR_R STR_L STR_F STR_RIGHT_PARENTHESIS
1696 #define STRING_ANY_RIGHTPAR STR_A STR_N STR_Y STR_RIGHT_PARENTHESIS
1697 #define STRING_ANYCRLF_RIGHTPAR STR_A STR_N STR_Y STR_C STR_R STR_L STR_F STR_RIGHT_PARENTHESIS
1698 #define STRING_BSR_ANYCRLF_RIGHTPAR STR_B STR_S STR_R STR_UNDERSCORE STR_A STR_N STR_Y STR_C STR_R STR_L STR_F STR_RIGHT_PARENTHESIS
1699 #define STRING_BSR_UNICODE_RIGHTPAR STR_B STR_S STR_R STR_UNDERSCORE STR_U STR_N STR_I STR_C STR_O STR_D STR_E STR_RIGHT_PARENTHESIS
1700 #ifdef COMPILE_PCRE8
1701 #define STRING_UTF_RIGHTPAR STR_U STR_T STR_F STR_8 STR_RIGHT_PARENTHESIS
1702 #endif
1703 #ifdef COMPILE_PCRE16
1704 #define STRING_UTF_RIGHTPAR STR_U STR_T STR_F STR_1 STR_6 STR_RIGHT_PARENTHESIS
1705 #endif
1706 #ifdef COMPILE_PCRE32
1707 #define STRING_UTF_RIGHTPAR STR_U STR_T STR_F STR_3 STR_2 STR_RIGHT_PARENTHESIS
1708 #endif
1709 #define STRING_UCP_RIGHTPAR STR_U STR_C STR_P STR_RIGHT_PARENTHESIS
1710 #define STRING_NO_START_OPT_RIGHTPAR STR_N STR_O STR_UNDERSCORE STR_S STR_T STR_A STR_R STR_T STR_UNDERSCORE STR_O STR_P STR_T STR_RIGHT_PARENTHESIS
1711
1712 #endif /* SUPPORT_UTF */
1713
1714 /* Escape items that are just an encoding of a particular data value. */
1715
1716 #ifndef ESC_e
1717 #define ESC_e CHAR_ESC
1718 #endif
1719
1720 #ifndef ESC_f
1721 #define ESC_f CHAR_FF
1722 #endif
1723
1724 #ifndef ESC_n
1725 #define ESC_n CHAR_LF
1726 #endif
1727
1728 #ifndef ESC_r
1729 #define ESC_r CHAR_CR
1730 #endif
1731
1732 /* We can't officially use ESC_t because it is a POSIX reserved identifier
1733 (presumably because of all the others like size_t). */
1734
1735 #ifndef ESC_tee
1736 #define ESC_tee CHAR_HT
1737 #endif
1738
1739 /* Codes for different types of Unicode property */
1740
1741 #define PT_ANY 0 /* Any property - matches all chars */
1742 #define PT_LAMP 1 /* L& - the union of Lu, Ll, Lt */
1743 #define PT_GC 2 /* Specified general characteristic (e.g. L) */
1744 #define PT_PC 3 /* Specified particular characteristic (e.g. Lu) */
1745 #define PT_SC 4 /* Script (e.g. Han) */
1746 #define PT_ALNUM 5 /* Alphanumeric - the union of L and N */
1747 #define PT_SPACE 6 /* Perl space - Z plus 9,10,12,13 */
1748 #define PT_PXSPACE 7 /* POSIX space - Z plus 9,10,11,12,13 */
1749 #define PT_WORD 8 /* Word - L plus N plus underscore */
1750 #define PT_CLIST 9 /* Pseudo-property: match character list */
1751
1752 /* Flag bits and data types for the extended class (OP_XCLASS) for classes that
1753 contain characters with values greater than 255. */
1754
1755 #define XCL_NOT 0x01 /* Flag: this is a negative class */
1756 #define XCL_MAP 0x02 /* Flag: a 32-byte map is present */
1757
1758 #define XCL_END 0 /* Marks end of individual items */
1759 #define XCL_SINGLE 1 /* Single item (one multibyte char) follows */
1760 #define XCL_RANGE 2 /* A range (two multibyte chars) follows */
1761 #define XCL_PROP 3 /* Unicode property (2-byte property code follows) */
1762 #define XCL_NOTPROP 4 /* Unicode inverted property (ditto) */
1763
1764 /* These are escaped items that aren't just an encoding of a particular data
1765 value such as \n. They must have non-zero values, as check_escape() returns
1766 0 for a data character. Also, they must appear in the same order as in the opcode
1767 definitions below, up to ESC_z. There's a dummy for OP_ALLANY because it
1768 corresponds to "." in DOTALL mode rather than an escape sequence. It is also
1769 used for [^] in JavaScript compatibility mode, and for \C in non-utf mode. In
1770 non-DOTALL mode, "." behaves like \N.
1771
1772 The special values ESC_DU, ESC_du, etc. are used instead of ESC_D, ESC_d, etc.
1773 when PCRE_UCP is set and replacement of \d etc by \p sequences is required.
1774 They must be contiguous, and remain in order so that the replacements can be
1775 looked up from a table.
1776
1777 Negative numbers are used to encode a backreference (\1, \2, \3, etc.) in
1778 check_escape(). There are two tests in the code for an escape
1779 greater than ESC_b and less than ESC_Z to detect the types that may be
1780 repeated. These are the types that consume characters. If any new escapes are
1781 put in between that don't consume a character, that code will have to change.
1782 */
1783
1784 enum { ESC_A = 1, ESC_G, ESC_K, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s,
1785 ESC_W, ESC_w, ESC_N, ESC_dum, ESC_C, ESC_P, ESC_p, ESC_R, ESC_H,
1786 ESC_h, ESC_V, ESC_v, ESC_X, ESC_Z, ESC_z,
1787 ESC_E, ESC_Q, ESC_g, ESC_k,
1788 ESC_DU, ESC_du, ESC_SU, ESC_su, ESC_WU, ESC_wu };
1789
1790 /* Opcode table: Starting from 1 (i.e. after OP_END), the values up to
1791 OP_EOD must correspond in order to the list of escapes immediately above.
1792
1793 *** NOTE NOTE NOTE *** Whenever this list is updated, the two macro definitions
1794 that follow must also be updated to match. There are also tables called
1795 "coptable" and "poptable" in pcre_dfa_exec.c that must be updated. */
1796
1797 enum {
1798 OP_END, /* 0 End of pattern */
1799
1800 /* Values corresponding to backslashed metacharacters */
1801
1802 OP_SOD, /* 1 Start of data: \A */
1803 OP_SOM, /* 2 Start of match (subject + offset): \G */
1804 OP_SET_SOM, /* 3 Set start of match (\K) */
1805 OP_NOT_WORD_BOUNDARY, /* 4 \B */
1806 OP_WORD_BOUNDARY, /* 5 \b */
1807 OP_NOT_DIGIT, /* 6 \D */
1808 OP_DIGIT, /* 7 \d */
1809 OP_NOT_WHITESPACE, /* 8 \S */
1810 OP_WHITESPACE, /* 9 \s */
1811 OP_NOT_WORDCHAR, /* 10 \W */
1812 OP_WORDCHAR, /* 11 \w */
1813
1814 OP_ANY, /* 12 Match any character except newline (\N) */
1815 OP_ALLANY, /* 13 Match any character */
1816 OP_ANYBYTE, /* 14 Match any byte (\C); different to OP_ANY for UTF-8 */
1817 OP_NOTPROP, /* 15 \P (not Unicode property) */
1818 OP_PROP, /* 16 \p (Unicode property) */
1819 OP_ANYNL, /* 17 \R (any newline sequence) */
1820 OP_NOT_HSPACE, /* 18 \H (not horizontal whitespace) */
1821 OP_HSPACE, /* 19 \h (horizontal whitespace) */
1822 OP_NOT_VSPACE, /* 20 \V (not vertical whitespace) */
1823 OP_VSPACE, /* 21 \v (vertical whitespace) */
1824 OP_EXTUNI, /* 22 \X (extended Unicode sequence */
1825 OP_EODN, /* 23 End of data or \n at end of data (\Z) */
1826 OP_EOD, /* 24 End of data (\z) */
1827
1828 OP_CIRC, /* 25 Start of line - not multiline */
1829 OP_CIRCM, /* 26 Start of line - multiline */
1830 OP_DOLL, /* 27 End of line - not multiline */
1831 OP_DOLLM, /* 28 End of line - multiline */
1832 OP_CHAR, /* 29 Match one character, casefully */
1833 OP_CHARI, /* 30 Match one character, caselessly */
1834 OP_NOT, /* 31 Match one character, not the given one, casefully */
1835 OP_NOTI, /* 32 Match one character, not the given one, caselessly */
1836
1837 /* The following sets of 13 opcodes must always be kept in step because
1838 the offset from the first one is used to generate the others. */
1839
1840 /**** Single characters, caseful, must precede the caseless ones ****/
1841
1842 OP_STAR, /* 33 The maximizing and minimizing versions of */
1843 OP_MINSTAR, /* 34 these six opcodes must come in pairs, with */
1844 OP_PLUS, /* 35 the minimizing one second. */
1845 OP_MINPLUS, /* 36 */
1846 OP_QUERY, /* 37 */
1847 OP_MINQUERY, /* 38 */
1848
1849 OP_UPTO, /* 39 From 0 to n matches of one character, caseful*/
1850 OP_MINUPTO, /* 40 */
1851 OP_EXACT, /* 41 Exactly n matches */
1852
1853 OP_POSSTAR, /* 42 Possessified star, caseful */
1854 OP_POSPLUS, /* 43 Possessified plus, caseful */
1855 OP_POSQUERY, /* 44 Posesssified query, caseful */
1856 OP_POSUPTO, /* 45 Possessified upto, caseful */
1857
1858 /**** Single characters, caseless, must follow the caseful ones */
1859
1860 OP_STARI, /* 46 */
1861 OP_MINSTARI, /* 47 */
1862 OP_PLUSI, /* 48 */
1863 OP_MINPLUSI, /* 49 */
1864 OP_QUERYI, /* 50 */
1865 OP_MINQUERYI, /* 51 */
1866
1867 OP_UPTOI, /* 52 From 0 to n matches of one character, caseless */
1868 OP_MINUPTOI, /* 53 */
1869 OP_EXACTI, /* 54 */
1870
1871 OP_POSSTARI, /* 55 Possessified star, caseless */
1872 OP_POSPLUSI, /* 56 Possessified plus, caseless */
1873 OP_POSQUERYI, /* 57 Posesssified query, caseless */
1874 OP_POSUPTOI, /* 58 Possessified upto, caseless */
1875
1876 /**** The negated ones must follow the non-negated ones, and match them ****/
1877 /**** Negated single character, caseful; must precede the caseless ones ****/
1878
1879 OP_NOTSTAR, /* 59 The maximizing and minimizing versions of */
1880 OP_NOTMINSTAR, /* 60 these six opcodes must come in pairs, with */
1881 OP_NOTPLUS, /* 61 the minimizing one second. They must be in */
1882 OP_NOTMINPLUS, /* 62 exactly the same order as those above. */
1883 OP_NOTQUERY, /* 63 */
1884 OP_NOTMINQUERY, /* 64 */
1885
1886 OP_NOTUPTO, /* 65 From 0 to n matches, caseful */
1887 OP_NOTMINUPTO, /* 66 */
1888 OP_NOTEXACT, /* 67 Exactly n matches */
1889
1890 OP_NOTPOSSTAR, /* 68 Possessified versions, caseful */
1891 OP_NOTPOSPLUS, /* 69 */
1892 OP_NOTPOSQUERY, /* 70 */
1893 OP_NOTPOSUPTO, /* 71 */
1894
1895 /**** Negated single character, caseless; must follow the caseful ones ****/
1896
1897 OP_NOTSTARI, /* 72 */
1898 OP_NOTMINSTARI, /* 73 */
1899 OP_NOTPLUSI, /* 74 */
1900 OP_NOTMINPLUSI, /* 75 */
1901 OP_NOTQUERYI, /* 76 */
1902 OP_NOTMINQUERYI, /* 77 */
1903
1904 OP_NOTUPTOI, /* 78 From 0 to n matches, caseless */
1905 OP_NOTMINUPTOI, /* 79 */
1906 OP_NOTEXACTI, /* 80 Exactly n matches */
1907
1908 OP_NOTPOSSTARI, /* 81 Possessified versions, caseless */
1909 OP_NOTPOSPLUSI, /* 82 */
1910 OP_NOTPOSQUERYI, /* 83 */
1911 OP_NOTPOSUPTOI, /* 84 */
1912
1913 /**** Character types ****/
1914
1915 OP_TYPESTAR, /* 85 The maximizing and minimizing versions of */
1916 OP_TYPEMINSTAR, /* 86 these six opcodes must come in pairs, with */
1917 OP_TYPEPLUS, /* 87 the minimizing one second. These codes must */
1918 OP_TYPEMINPLUS, /* 88 be in exactly the same order as those above. */
1919 OP_TYPEQUERY, /* 89 */
1920 OP_TYPEMINQUERY, /* 90 */
1921
1922 OP_TYPEUPTO, /* 91 From 0 to n matches */
1923 OP_TYPEMINUPTO, /* 92 */
1924 OP_TYPEEXACT, /* 93 Exactly n matches */
1925
1926 OP_TYPEPOSSTAR, /* 94 Possessified versions */
1927 OP_TYPEPOSPLUS, /* 95 */
1928 OP_TYPEPOSQUERY, /* 96 */
1929 OP_TYPEPOSUPTO, /* 97 */
1930
1931 /* These are used for character classes and back references; only the
1932 first six are the same as the sets above. */
1933
1934 OP_CRSTAR, /* 98 The maximizing and minimizing versions of */
1935 OP_CRMINSTAR, /* 99 all these opcodes must come in pairs, with */
1936 OP_CRPLUS, /* 100 the minimizing one second. These codes must */
1937 OP_CRMINPLUS, /* 101 be in exactly the same order as those above. */
1938 OP_CRQUERY, /* 102 */
1939 OP_CRMINQUERY, /* 103 */
1940
1941 OP_CRRANGE, /* 104 These are different to the three sets above. */
1942 OP_CRMINRANGE, /* 105 */
1943
1944 /* End of quantifier opcodes */
1945
1946 OP_CLASS, /* 106 Match a character class, chars < 256 only */
1947 OP_NCLASS, /* 107 Same, but the bitmap was created from a negative
1948 class - the difference is relevant only when a
1949 character > 255 is encountered. */
1950 OP_XCLASS, /* 108 Extended class for handling > 255 chars within the
1951 class. This does both positive and negative. */
1952 OP_REF, /* 109 Match a back reference, casefully */
1953 OP_REFI, /* 110 Match a back reference, caselessly */
1954 OP_RECURSE, /* 111 Match a numbered subpattern (possibly recursive) */
1955 OP_CALLOUT, /* 112 Call out to external function if provided */
1956
1957 OP_ALT, /* 113 Start of alternation */
1958 OP_KET, /* 114 End of group that doesn't have an unbounded repeat */
1959 OP_KETRMAX, /* 115 These two must remain together and in this */
1960 OP_KETRMIN, /* 116 order. They are for groups the repeat for ever. */
1961 OP_KETRPOS, /* 117 Possessive unlimited repeat. */
1962
1963 /* The assertions must come before BRA, CBRA, ONCE, and COND, and the four
1964 asserts must remain in order. */
1965
1966 OP_REVERSE, /* 118 Move pointer back - used in lookbehind assertions */
1967 OP_ASSERT, /* 119 Positive lookahead */
1968 OP_ASSERT_NOT, /* 120 Negative lookahead */
1969 OP_ASSERTBACK, /* 121 Positive lookbehind */
1970 OP_ASSERTBACK_NOT, /* 122 Negative lookbehind */
1971
1972 /* ONCE, ONCE_NC, BRA, BRAPOS, CBRA, CBRAPOS, and COND must come immediately
1973 after the assertions, with ONCE first, as there's a test for >= ONCE for a
1974 subpattern that isn't an assertion. The POS versions must immediately follow
1975 the non-POS versions in each case. */
1976
1977 OP_ONCE, /* 123 Atomic group, contains captures */
1978 OP_ONCE_NC, /* 124 Atomic group containing no captures */
1979 OP_BRA, /* 125 Start of non-capturing bracket */
1980 OP_BRAPOS, /* 126 Ditto, with unlimited, possessive repeat */
1981 OP_CBRA, /* 127 Start of capturing bracket */
1982 OP_CBRAPOS, /* 128 Ditto, with unlimited, possessive repeat */
1983 OP_COND, /* 129 Conditional group */
1984
1985 /* These five must follow the previous five, in the same order. There's a
1986 check for >= SBRA to distinguish the two sets. */
1987
1988 OP_SBRA, /* 130 Start of non-capturing bracket, check empty */
1989 OP_SBRAPOS, /* 131 Ditto, with unlimited, possessive repeat */
1990 OP_SCBRA, /* 132 Start of capturing bracket, check empty */
1991 OP_SCBRAPOS, /* 133 Ditto, with unlimited, possessive repeat */
1992 OP_SCOND, /* 134 Conditional group, check empty */
1993
1994 /* The next two pairs must (respectively) be kept together. */
1995
1996 OP_CREF, /* 135 Used to hold a capture number as condition */
1997 OP_NCREF, /* 136 Same, but generated by a name reference*/
1998 OP_RREF, /* 137 Used to hold a recursion number as condition */
1999 OP_NRREF, /* 138 Same, but generated by a name reference*/
2000 OP_DEF, /* 139 The DEFINE condition */
2001
2002 OP_BRAZERO, /* 140 These two must remain together and in this */
2003 OP_BRAMINZERO, /* 141 order. */
2004 OP_BRAPOSZERO, /* 142 */
2005
2006 /* These are backtracking control verbs */
2007
2008 OP_MARK, /* 143 always has an argument */
2009 OP_PRUNE, /* 144 */
2010 OP_PRUNE_ARG, /* 145 same, but with argument */
2011 OP_SKIP, /* 146 */
2012 OP_SKIP_ARG, /* 147 same, but with argument */
2013 OP_THEN, /* 148 */
2014 OP_THEN_ARG, /* 149 same, but with argument */
2015 OP_COMMIT, /* 150 */
2016
2017 /* These are forced failure and success verbs */
2018
2019 OP_FAIL, /* 151 */
2020 OP_ACCEPT, /* 152 */
2021 OP_ASSERT_ACCEPT, /* 153 Used inside assertions */
2022 OP_CLOSE, /* 154 Used before OP_ACCEPT to close open captures */
2023
2024 /* This is used to skip a subpattern with a {0} quantifier */
2025
2026 OP_SKIPZERO, /* 155 */
2027
2028 /* This is not an opcode, but is used to check that tables indexed by opcode
2029 are the correct length, in order to catch updating errors - there have been
2030 some in the past. */
2031
2032 OP_TABLE_LENGTH
2033 };
2034
2035 /* *** NOTE NOTE NOTE *** Whenever the list above is updated, the two macro
2036 definitions that follow must also be updated to match. There are also tables
2037 called "coptable" and "poptable" in pcre_dfa_exec.c that must be updated. */
2038
2039
2040 /* This macro defines textual names for all the opcodes. These are used only
2041 for debugging, and some of them are only partial names. The macro is referenced
2042 only in pcre_printint.c, which fills out the full names in many cases (and in
2043 some cases doesn't actually use these names at all). */
2044
2045 #define OP_NAME_LIST \
2046 "End", "\\A", "\\G", "\\K", "\\B", "\\b", "\\D", "\\d", \
2047 "\\S", "\\s", "\\W", "\\w", "Any", "AllAny", "Anybyte", \
2048 "notprop", "prop", "\\R", "\\H", "\\h", "\\V", "\\v", \
2049 "extuni", "\\Z", "\\z", \
2050 "^", "^", "$", "$", "char", "chari", "not", "noti", \
2051 "*", "*?", "+", "+?", "?", "??", \
2052 "{", "{", "{", \
2053 "*+","++", "?+", "{", \
2054 "*", "*?", "+", "+?", "?", "??", \
2055 "{", "{", "{", \
2056 "*+","++", "?+", "{", \
2057 "*", "*?", "+", "+?", "?", "??", \
2058 "{", "{", "{", \
2059 "*+","++", "?+", "{", \
2060 "*", "*?", "+", "+?", "?", "??", \
2061 "{", "{", "{", \
2062 "*+","++", "?+", "{", \
2063 "*", "*?", "+", "+?", "?", "??", "{", "{", "{", \
2064 "*+","++", "?+", "{", \
2065 "*", "*?", "+", "+?", "?", "??", "{", "{", \
2066 "class", "nclass", "xclass", "Ref", "Refi", \
2067 "Recurse", "Callout", \
2068 "Alt", "Ket", "KetRmax", "KetRmin", "KetRpos", \
2069 "Reverse", "Assert", "Assert not", "AssertB", "AssertB not", \
2070 "Once", "Once_NC", \
2071 "Bra", "BraPos", "CBra", "CBraPos", \
2072 "Cond", \
2073 "SBra", "SBraPos", "SCBra", "SCBraPos", \
2074 "SCond", \
2075 "Cond ref", "Cond nref", "Cond rec", "Cond nrec", "Cond def", \
2076 "Brazero", "Braminzero", "Braposzero", \
2077 "*MARK", "*PRUNE", "*PRUNE", "*SKIP", "*SKIP", \
2078 "*THEN", "*THEN", "*COMMIT", "*FAIL", \
2079 "*ACCEPT", "*ASSERT_ACCEPT", \
2080 "Close", "Skip zero"
2081
2082
2083 /* This macro defines the length of fixed length operations in the compiled
2084 regex. The lengths are used when searching for specific things, and also in the
2085 debugging printing of a compiled regex. We use a macro so that it can be
2086 defined close to the definitions of the opcodes themselves.
2087
2088 As things have been extended, some of these are no longer fixed lenths, but are
2089 minima instead. For example, the length of a single-character repeat may vary
2090 in UTF-8 mode. The code that uses this table must know about such things. */
2091
2092 #define OP_LENGTHS \
2093 1, /* End */ \
2094 1, 1, 1, 1, 1, /* \A, \G, \K, \B, \b */ \
2095 1, 1, 1, 1, 1, 1, /* \D, \d, \S, \s, \W, \w */ \
2096 1, 1, 1, /* Any, AllAny, Anybyte */ \
2097 3, 3, /* \P, \p */ \
2098 1, 1, 1, 1, 1, /* \R, \H, \h, \V, \v */ \
2099 1, /* \X */ \
2100 1, 1, 1, 1, 1, 1, /* \Z, \z, ^, ^M, $, $M */ \
2101 2, /* Char - the minimum length */ \
2102 2, /* Chari - the minimum length */ \
2103 2, /* not */ \
2104 2, /* noti */ \
2105 /* Positive single-char repeats ** These are */ \
2106 2, 2, 2, 2, 2, 2, /* *, *?, +, +?, ?, ?? ** minima in */ \
2107 2+IMM2_SIZE, 2+IMM2_SIZE, /* upto, minupto ** mode */ \
2108 2+IMM2_SIZE, /* exact */ \
2109 2, 2, 2, 2+IMM2_SIZE, /* *+, ++, ?+, upto+ */ \
2110 2, 2, 2, 2, 2, 2, /* *I, *?I, +I, +?I, ?I, ??I ** UTF-8 */ \
2111 2+IMM2_SIZE, 2+IMM2_SIZE, /* upto I, minupto I */ \
2112 2+IMM2_SIZE, /* exact I */ \
2113 2, 2, 2, 2+IMM2_SIZE, /* *+I, ++I, ?+I, upto+I */ \
2114 /* Negative single-char repeats - only for chars < 256 */ \
2115 2, 2, 2, 2, 2, 2, /* NOT *, *?, +, +?, ?, ?? */ \
2116 2+IMM2_SIZE, 2+IMM2_SIZE, /* NOT upto, minupto */ \
2117 2+IMM2_SIZE, /* NOT exact */ \
2118 2, 2, 2, 2+IMM2_SIZE, /* Possessive NOT *, +, ?, upto */ \
2119 2, 2, 2, 2, 2, 2, /* NOT *I, *?I, +I, +?I, ?I, ??I */ \
2120 2+IMM2_SIZE, 2+IMM2_SIZE, /* NOT upto I, minupto I */ \
2121 2+IMM2_SIZE, /* NOT exact I */ \
2122 2, 2, 2, 2+IMM2_SIZE, /* Possessive NOT *I, +I, ?I, upto I */ \
2123 /* Positive type repeats */ \
2124 2, 2, 2, 2, 2, 2, /* Type *, *?, +, +?, ?, ?? */ \
2125 2+IMM2_SIZE, 2+IMM2_SIZE, /* Type upto, minupto */ \
2126 2+IMM2_SIZE, /* Type exact */ \
2127 2, 2, 2, 2+IMM2_SIZE, /* Possessive *+, ++, ?+, upto+ */ \
2128 /* Character class & ref repeats */ \
2129 1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */ \
2130 1+2*IMM2_SIZE, 1+2*IMM2_SIZE, /* CRRANGE, CRMINRANGE */ \
2131 1+(32/sizeof(pcre_uchar)), /* CLASS */ \
2132 1+(32/sizeof(pcre_uchar)), /* NCLASS */ \
2133 0, /* XCLASS - variable length */ \
2134 1+IMM2_SIZE, /* REF */ \
2135 1+IMM2_SIZE, /* REFI */ \
2136 1+LINK_SIZE, /* RECURSE */ \
2137 2+2*LINK_SIZE, /* CALLOUT */ \
2138 1+LINK_SIZE, /* Alt */ \
2139 1+LINK_SIZE, /* Ket */ \
2140 1+LINK_SIZE, /* KetRmax */ \
2141 1+LINK_SIZE, /* KetRmin */ \
2142 1+LINK_SIZE, /* KetRpos */ \
2143 1+LINK_SIZE, /* Reverse */ \
2144 1+LINK_SIZE, /* Assert */ \
2145 1+LINK_SIZE, /* Assert not */ \
2146 1+LINK_SIZE, /* Assert behind */ \
2147 1+LINK_SIZE, /* Assert behind not */ \
2148 1+LINK_SIZE, /* ONCE */ \
2149 1+LINK_SIZE, /* ONCE_NC */ \
2150 1+LINK_SIZE, /* BRA */ \
2151 1+LINK_SIZE, /* BRAPOS */ \
2152 1+LINK_SIZE+IMM2_SIZE, /* CBRA */ \
2153 1+LINK_SIZE+IMM2_SIZE, /* CBRAPOS */ \
2154 1+LINK_SIZE, /* COND */ \
2155 1+LINK_SIZE, /* SBRA */ \
2156 1+LINK_SIZE, /* SBRAPOS */ \
2157 1+LINK_SIZE+IMM2_SIZE, /* SCBRA */ \
2158 1+LINK_SIZE+IMM2_SIZE, /* SCBRAPOS */ \
2159 1+LINK_SIZE, /* SCOND */ \
2160 1+IMM2_SIZE, 1+IMM2_SIZE, /* CREF, NCREF */ \
2161 1+IMM2_SIZE, 1+IMM2_SIZE, /* RREF, NRREF */ \
2162 1, /* DEF */ \
2163 1, 1, 1, /* BRAZERO, BRAMINZERO, BRAPOSZERO */ \
2164 3, 1, 3, /* MARK, PRUNE, PRUNE_ARG */ \
2165 1, 3, /* SKIP, SKIP_ARG */ \
2166 1, 3, /* THEN, THEN_ARG */ \
2167 1, 1, 1, 1, /* COMMIT, FAIL, ACCEPT, ASSERT_ACCEPT */ \
2168 1+IMM2_SIZE, 1 /* CLOSE, SKIPZERO */
2169
2170 /* A magic value for OP_RREF and OP_NRREF to indicate the "any recursion"
2171 condition. */
2172
2173 #define RREF_ANY 0xffff
2174
2175 /* Compile time error code numbers. They are given names so that they can more
2176 easily be tracked. When a new number is added, the table called eint in
2177 pcreposix.c must be updated. */
2178
2179 enum { ERR0, ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9,
2180 ERR10, ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19,
2181 ERR20, ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR28, ERR29,
2182 ERR30, ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39,
2183 ERR40, ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49,
2184 ERR50, ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58, ERR59,
2185 ERR60, ERR61, ERR62, ERR63, ERR64, ERR65, ERR66, ERR67, ERR68, ERR69,
2186 ERR70, ERR71, ERR72, ERR73, ERR74, ERR75, ERR76, ERR77, ERRCOUNT };
2187
2188 /* JIT compiling modes. The function list is indexed by them. */
2189 enum { JIT_COMPILE, JIT_PARTIAL_SOFT_COMPILE, JIT_PARTIAL_HARD_COMPILE,
2190 JIT_NUMBER_OF_COMPILE_MODES };
2191
2192 /* The real format of the start of the pcre block; the index of names and the
2193 code vector run on as long as necessary after the end. We store an explicit
2194 offset to the name table so that if a regex is compiled on one host, saved, and
2195 then run on another where the size of pointers is different, all might still
2196 be well. For the case of compiled-on-4 and run-on-8, we include an extra
2197 pointer that is always NULL. For future-proofing, a few dummy fields were
2198 originally included - even though you can never get this planning right - but
2199 there is only one left now.
2200
2201 NOTE NOTE NOTE:
2202 Because people can now save and re-use compiled patterns, any additions to this
2203 structure should be made at the end, and something earlier (e.g. a new
2204 flag in the options or one of the dummy fields) should indicate that the new
2205 fields are present. Currently PCRE always sets the dummy fields to zero.
2206 NOTE NOTE NOTE
2207 */
2208
2209 #if defined COMPILE_PCRE8
2210 #define REAL_PCRE real_pcre
2211 #elif defined COMPILE_PCRE16
2212 #define REAL_PCRE real_pcre16
2213 #elif defined COMPILE_PCRE32
2214 #define REAL_PCRE real_pcre32
2215 #endif
2216
2217 /* It is necessary to fork the struct for 32 bit, since it needs to use
2218 * pcre_uchar for first_char and req_char. Can't put an ifdef inside the
2219 * typedef since pcretest needs access to the struct of the 8-, 16-
2220 * and 32-bit variants. */
2221
2222 typedef struct real_pcre8_or_16 {
2223 pcre_uint32 magic_number;
2224 pcre_uint32 size; /* Total that was malloced */
2225 pcre_uint32 options; /* Public options */
2226 pcre_uint16 flags; /* Private flags */
2227 pcre_uint16 max_lookbehind; /* Longest lookbehind (characters) */
2228 pcre_uint16 top_bracket; /* Highest numbered group */
2229 pcre_uint16 top_backref; /* Highest numbered back reference */
2230 pcre_uint16 first_char; /* Starting character */
2231 pcre_uint16 req_char; /* This character must be seen */
2232 pcre_uint16 name_table_offset; /* Offset to name table that follows */
2233 pcre_uint16 name_entry_size; /* Size of any name items */
2234 pcre_uint16 name_count; /* Number of name items */
2235 pcre_uint16 ref_count; /* Reference count */
2236 const pcre_uint8 *tables; /* Pointer to tables or NULL for std */
2237 const pcre_uint8 *nullpad; /* NULL padding */
2238 } real_pcre8_or_16;
2239
2240 typedef struct real_pcre8_or_16 real_pcre;
2241 typedef struct real_pcre8_or_16 real_pcre16;
2242
2243 typedef struct real_pcre32 {
2244 pcre_uint32 magic_number;
2245 pcre_uint32 size; /* Total that was malloced */
2246 pcre_uint32 options; /* Public options */
2247 pcre_uint16 flags; /* Private flags */
2248 pcre_uint16 max_lookbehind; /* Longest lookbehind (characters) */
2249 pcre_uint16 top_bracket; /* Highest numbered group */
2250 pcre_uint16 top_backref; /* Highest numbered back reference */
2251 pcre_uint32 first_char; /* Starting character */
2252 pcre_uint32 req_char; /* This character must be seen */
2253 pcre_uint16 name_table_offset; /* Offset to name table that follows */
2254 pcre_uint16 name_entry_size; /* Size of any name items */
2255 pcre_uint16 name_count; /* Number of name items */
2256 pcre_uint16 ref_count; /* Reference count */
2257 pcre_uint16 dummy1; /* for later expansion */
2258 pcre_uint16 dummy2; /* for later expansion */
2259 const pcre_uint8 *tables; /* Pointer to tables or NULL for std */
2260 void *nullpad; /* for later expansion */
2261 } real_pcre32;
2262
2263 /* Assert that the size of REAL_PCRE is divisible by 8 */
2264 typedef int __assert_real_pcre_size_divisible_8[(sizeof(REAL_PCRE) % 8) == 0 ? 1 : -1];
2265
2266 /* Needed in pcretest to access some fields in the real_pcre* structures
2267 * directly. They're unified for 8/16/32 bits since the structs only differ
2268 * after these fields; if that ever changes, need to fork those defines into
2269 * 8/16 and 32 bit versions. */
2270 #define REAL_PCRE_MAGIC(re) (((REAL_PCRE*)re)->magic_number)
2271 #define REAL_PCRE_SIZE(re) (((REAL_PCRE*)re)->size)
2272 #define REAL_PCRE_OPTIONS(re) (((REAL_PCRE*)re)->options)
2273 #define REAL_PCRE_FLAGS(re) (((REAL_PCRE*)re)->flags)
2274
2275 /* The format of the block used to store data from pcre_study(). The same
2276 remark (see NOTE above) about extending this structure applies. */
2277
2278 typedef struct pcre_study_data {
2279 pcre_uint32 size; /* Total that was malloced */
2280 pcre_uint32 flags; /* Private flags */
2281 pcre_uint8 start_bits[32]; /* Starting char bits */
2282 pcre_uint32 minlength; /* Minimum subject length */
2283 } pcre_study_data;
2284
2285 /* Structure for building a chain of open capturing subpatterns during
2286 compiling, so that instructions to close them can be compiled when (*ACCEPT) is
2287 encountered. This is also used to identify subpatterns that contain recursive
2288 back references to themselves, so that they can be made atomic. */
2289
2290 typedef struct open_capitem {
2291 struct open_capitem *next; /* Chain link */
2292 pcre_uint16 number; /* Capture number */
2293 pcre_uint16 flag; /* Set TRUE if recursive back ref */
2294 } open_capitem;
2295
2296 /* Structure for passing "static" information around between the functions
2297 doing the compiling, so that they are thread-safe. */
2298
2299 typedef struct compile_data {
2300 const pcre_uint8 *lcc; /* Points to lower casing table */
2301 const pcre_uint8 *fcc; /* Points to case-flipping table */
2302 const pcre_uint8 *cbits; /* Points to character type table */
2303 const pcre_uint8 *ctypes; /* Points to table of type maps */
2304 const pcre_uchar *start_workspace;/* The start of working space */
2305 const pcre_uchar *start_code; /* The start of the compiled code */
2306 const pcre_uchar *start_pattern; /* The start of the pattern */
2307 const pcre_uchar *end_pattern; /* The end of the pattern */
2308 open_capitem *open_caps; /* Chain of open capture items */
2309 pcre_uchar *hwm; /* High watermark of workspace */
2310 pcre_uchar *name_table; /* The name/number table */
2311 int names_found; /* Number of entries so far */
2312 int name_entry_size; /* Size of each entry */
2313 int workspace_size; /* Size of workspace */
2314 int bracount; /* Count of capturing parens as we compile */
2315 int final_bracount; /* Saved value after first pass */
2316 int max_lookbehind; /* Maximum lookbehind (characters) */
2317 int top_backref; /* Maximum back reference */
2318 unsigned int backref_map; /* Bitmap of low back refs */
2319 int assert_depth; /* Depth of nested assertions */
2320 int external_options; /* External (initial) options */
2321 int external_flags; /* External flag bits to be set */
2322 int req_varyopt; /* "After variable item" flag for reqbyte */
2323 BOOL had_accept; /* (*ACCEPT) encountered */
2324 BOOL had_pruneorskip; /* (*PRUNE) or (*SKIP) encountered */
2325 BOOL check_lookbehind; /* Lookbehinds need later checking */
2326 int nltype; /* Newline type */
2327 int nllen; /* Newline string length */
2328 pcre_uchar nl[4]; /* Newline string when fixed length */
2329 } compile_data;
2330
2331 /* Structure for maintaining a chain of pointers to the currently incomplete
2332 branches, for testing for left recursion while compiling. */
2333
2334 typedef struct branch_chain {
2335 struct branch_chain *outer;
2336 pcre_uchar *current_branch;
2337 } branch_chain;
2338
2339 /* Structure for items in a linked list that represents an explicit recursive
2340 call within the pattern; used by pcre_exec(). */
2341
2342 typedef struct recursion_info {
2343 struct recursion_info *prevrec; /* Previous recursion record (or NULL) */
2344 int group_num; /* Number of group that was called */
2345 int *offset_save; /* Pointer to start of saved offsets */
2346 int saved_max; /* Number of saved offsets */
2347 PCRE_PUCHAR subject_position; /* Position at start of recursion */
2348 } recursion_info;
2349
2350 /* A similar structure for pcre_dfa_exec(). */
2351
2352 typedef struct dfa_recursion_info {
2353 struct dfa_recursion_info *prevrec;
2354 int group_num;
2355 PCRE_PUCHAR subject_position;
2356 } dfa_recursion_info;
2357
2358 /* Structure for building a chain of data for holding the values of the subject
2359 pointer at the start of each subpattern, so as to detect when an empty string
2360 has been matched by a subpattern - to break infinite loops; used by
2361 pcre_exec(). */
2362
2363 typedef struct eptrblock {
2364 struct eptrblock *epb_prev;
2365 PCRE_PUCHAR epb_saved_eptr;
2366 } eptrblock;
2367
2368
2369 /* Structure for passing "static" information around between the functions
2370 doing traditional NFA matching, so that they are thread-safe. */
2371
2372 typedef struct match_data {
2373 unsigned long int match_call_count; /* As it says */
2374 unsigned long int match_limit; /* As it says */
2375 unsigned long int match_limit_recursion; /* As it says */
2376 int *offset_vector; /* Offset vector */
2377 int offset_end; /* One past the end */
2378 int offset_max; /* The maximum usable for return data */
2379 int nltype; /* Newline type */
2380 int nllen; /* Newline string length */
2381 int name_count; /* Number of names in name table */
2382 int name_entry_size; /* Size of entry in names table */
2383 pcre_uchar *name_table; /* Table of names */
2384 pcre_uchar nl[4]; /* Newline string when fixed */
2385 const pcre_uint8 *lcc; /* Points to lower casing table */
2386 const pcre_uint8 *fcc; /* Points to case-flipping table */
2387 const pcre_uint8 *ctypes; /* Points to table of type maps */
2388 BOOL offset_overflow; /* Set if too many extractions */
2389 BOOL notbol; /* NOTBOL flag */
2390 BOOL noteol; /* NOTEOL flag */
2391 BOOL utf; /* UTF-8 / UTF-16 flag */
2392 BOOL jscript_compat; /* JAVASCRIPT_COMPAT flag */
2393 BOOL use_ucp; /* PCRE_UCP flag */
2394 BOOL endonly; /* Dollar not before final \n */
2395 BOOL notempty; /* Empty string match not wanted */
2396 BOOL notempty_atstart; /* Empty string match at start not wanted */
2397 BOOL hitend; /* Hit the end of the subject at some point */
2398 BOOL bsr_anycrlf; /* \R is just any CRLF, not full Unicode */
2399 BOOL hasthen; /* Pattern contains (*THEN) */
2400 BOOL ignore_skip_arg; /* For re-run when SKIP name not found */
2401 const pcre_uchar *start_code; /* For use when recursing */
2402 PCRE_PUCHAR start_subject; /* Start of the subject string */
2403 PCRE_PUCHAR end_subject; /* End of the subject string */
2404 PCRE_PUCHAR start_match_ptr; /* Start of matched string */
2405 PCRE_PUCHAR end_match_ptr; /* Subject position at end match */
2406 PCRE_PUCHAR start_used_ptr; /* Earliest consulted character */
2407 int partial; /* PARTIAL options */
2408 int end_offset_top; /* Highwater mark at end of match */
2409 int capture_last; /* Most recent capture number */
2410 int start_offset; /* The start offset value */
2411 int match_function_type; /* Set for certain special calls of MATCH() */
2412 eptrblock *eptrchain; /* Chain of eptrblocks for tail recursions */
2413 int eptrn; /* Next free eptrblock */
2414 recursion_info *recursive; /* Linked list of recursion data */
2415 void *callout_data; /* To pass back to callouts */
2416 const pcre_uchar *mark; /* Mark pointer to pass back on success */
2417 const pcre_uchar *nomatch_mark;/* Mark pointer to pass back on failure */
2418 const pcre_uchar *once_target; /* Where to back up to for atomic groups */
2419 #ifdef NO_RECURSE
2420 void *match_frames_base; /* For remembering malloc'd frames */
2421 #endif
2422 } match_data;
2423
2424 /* A similar structure is used for the same purpose by the DFA matching
2425 functions. */
2426
2427 typedef struct dfa_match_data {
2428 const pcre_uchar *start_code; /* Start of the compiled pattern */
2429 const pcre_uchar *start_subject ; /* Start of the subject string */
2430 const pcre_uchar *end_subject; /* End of subject string */
2431 const pcre_uchar *start_used_ptr; /* Earliest consulted character */
2432 const pcre_uint8 *tables; /* Character tables */
2433 int start_offset; /* The start offset value */
2434 int moptions; /* Match options */
2435 int poptions; /* Pattern options */
2436 int nltype; /* Newline type */
2437 int nllen; /* Newline string length */
2438 pcre_uchar nl[4]; /* Newline string when fixed */
2439 void *callout_data; /* To pass back to callouts */
2440 dfa_recursion_info *recursive; /* Linked list of recursion data */
2441 } dfa_match_data;
2442
2443 /* Bit definitions for entries in the pcre_ctypes table. */
2444
2445 #define ctype_space 0x01
2446 #define ctype_letter 0x02
2447 #define ctype_digit 0x04
2448 #define ctype_xdigit 0x08
2449 #define ctype_word 0x10 /* alphanumeric or '_' */
2450 #define ctype_meta 0x80 /* regexp meta char or zero (end pattern) */
2451
2452 /* Offsets for the bitmap tables in pcre_cbits. Each table contains a set
2453 of bits for a class map. Some classes are built by combining these tables. */
2454
2455 #define cbit_space 0 /* [:space:] or \s */
2456 #define cbit_xdigit 32 /* [:xdigit:] */
2457 #define cbit_digit 64 /* [:digit:] or \d */
2458 #define cbit_upper 96 /* [:upper:] */
2459 #define cbit_lower 128 /* [:lower:] */
2460 #define cbit_word 160 /* [:word:] or \w */
2461 #define cbit_graph 192 /* [:graph:] */
2462 #define cbit_print 224 /* [:print:] */
2463 #define cbit_punct 256 /* [:punct:] */
2464 #define cbit_cntrl 288 /* [:cntrl:] */
2465 #define cbit_length 320 /* Length of the cbits table */
2466
2467 /* Offsets of the various tables from the base tables pointer, and
2468 total length. */
2469
2470 #define lcc_offset 0
2471 #define fcc_offset 256
2472 #define cbits_offset 512
2473 #define ctypes_offset (cbits_offset + cbit_length)
2474 #define tables_length (ctypes_offset + 256)
2475
2476 /* Internal function and data prefixes. */
2477
2478 #if defined COMPILE_PCRE8
2479 #ifndef PUBL
2480 #define PUBL(name) pcre_##name
2481 #endif
2482 #ifndef PRIV
2483 #define PRIV(name) _pcre_##name
2484 #endif
2485 #elif defined COMPILE_PCRE16
2486 #ifndef PUBL
2487 #define PUBL(name) pcre16_##name
2488 #endif
2489 #ifndef PRIV
2490 #define PRIV(name) _pcre16_##name
2491 #endif
2492 #elif defined COMPILE_PCRE32
2493 #ifndef PUBL
2494 #define PUBL(name) pcre32_##name
2495 #endif
2496 #ifndef PRIV
2497 #define PRIV(name) _pcre32_##name
2498 #endif
2499 #else
2500 #error Unsupported compiling mode
2501 #endif /* COMPILE_PCRE[8|16|32] */
2502
2503 /* Layout of the UCP type table that translates property names into types and
2504 codes. Each entry used to point directly to a name, but to reduce the number of
2505 relocations in shared libraries, it now has an offset into a single string
2506 instead. */
2507
2508 typedef struct {
2509 pcre_uint16 name_offset;
2510 pcre_uint16 type;
2511 pcre_uint16 value;
2512 } ucp_type_table;
2513
2514
2515 /* Internal shared data tables. These are tables that are used by more than one
2516 of the exported public functions. They have to be "external" in the C sense,
2517 but are not part of the PCRE public API. The data for these tables is in the
2518 pcre_tables.c module. */
2519
2520 #ifdef COMPILE_PCRE8
2521 extern const int PRIV(utf8_table1)[];
2522 extern const int PRIV(utf8_table1_size);
2523 extern const int PRIV(utf8_table2)[];
2524 extern const int PRIV(utf8_table3)[];
2525 extern const pcre_uint8 PRIV(utf8_table4)[];
2526 #endif /* COMPILE_PCRE8 */
2527
2528 extern const char PRIV(utt_names)[];
2529 extern const ucp_type_table PRIV(utt)[];
2530 extern const int PRIV(utt_size);
2531
2532 extern const pcre_uint8 PRIV(OP_lengths)[];
2533 extern const pcre_uint8 PRIV(default_tables)[];
2534
2535 extern const pcre_uint32 PRIV(hspace_list)[];
2536 extern const pcre_uint32 PRIV(vspace_list)[];
2537
2538
2539 /* Internal shared functions. These are functions that are used by more than
2540 one of the exported public functions. They have to be "external" in the C
2541 sense, but are not part of the PCRE public API. */
2542
2543 /* String comparison functions. */
2544 #if defined COMPILE_PCRE8
2545
2546 #define STRCMP_UC_UC(str1, str2) \
2547 strcmp((char *)(str1), (char *)(str2))
2548 #define STRCMP_UC_C8(str1, str2) \
2549 strcmp((char *)(str1), (str2))
2550 #define STRNCMP_UC_UC(str1, str2, num) \
2551 strncmp((char *)(str1), (char *)(str2), (num))
2552 #define STRNCMP_UC_C8(str1, str2, num) \
2553 strncmp((char *)(str1), (str2), (num))
2554 #define STRLEN_UC(str) strlen((const char *)str)
2555
2556 #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2557
2558 extern int PRIV(strcmp_uc_uc)(const pcre_uchar *,
2559 const pcre_uchar *);
2560 extern int PRIV(strcmp_uc_c8)(const pcre_uchar *,
2561 const char *);
2562 extern int PRIV(strncmp_uc_uc)(const pcre_uchar *,
2563 const pcre_uchar *, unsigned int num);
2564 extern int PRIV(strncmp_uc_c8)(const pcre_uchar *,
2565 const char *, unsigned int num);
2566 extern unsigned int PRIV(strlen_uc)(const pcre_uchar *str);
2567
2568 #define STRCMP_UC_UC(str1, str2) \
2569 PRIV(strcmp_uc_uc)((str1), (str2))
2570 #define STRCMP_UC_C8(str1, str2) \
2571 PRIV(strcmp_uc_c8)((str1), (str2))
2572 #define STRNCMP_UC_UC(str1, str2, num) \
2573 PRIV(strncmp_uc_uc)((str1), (str2), (num))
2574 #define STRNCMP_UC_C8(str1, str2, num) \
2575 PRIV(strncmp_uc_c8)((str1), (str2), (num))
2576 #define STRLEN_UC(str) PRIV(strlen_uc)(str)
2577
2578 #endif /* COMPILE_PCRE[8|16|32] */
2579
2580 extern const pcre_uchar *PRIV(find_bracket)(const pcre_uchar *, BOOL, int);
2581 extern BOOL PRIV(is_newline)(PCRE_PUCHAR, int, PCRE_PUCHAR,
2582 int *, BOOL);
2583 extern int PRIV(ord2utf)(pcre_uint32, pcre_uchar *);
2584 extern int PRIV(valid_utf)(PCRE_PUCHAR, int, int *);
2585 extern BOOL PRIV(was_newline)(PCRE_PUCHAR, int, PCRE_PUCHAR,
2586 int *, BOOL);
2587 extern BOOL PRIV(xclass)(pcre_uint32, const pcre_uchar *, BOOL);
2588
2589 #ifdef SUPPORT_JIT
2590 extern void PRIV(jit_compile)(const REAL_PCRE *,
2591 PUBL(extra) *, int);
2592 extern int PRIV(jit_exec)(const REAL_PCRE *, const PUBL(extra) *,
2593 const pcre_uchar *, int, int, int, int *, int);
2594 extern void PRIV(jit_free)(void *);
2595 extern int PRIV(jit_get_size)(void *);
2596 extern const char* PRIV(jit_get_target)(void);
2597 #endif
2598
2599 /* Unicode character database (UCD) */
2600
2601 typedef struct {
2602 pcre_uint8 script; /* ucp_Arabic, etc. */
2603 pcre_uint8 chartype; /* ucp_Cc, etc. (general categories) */
2604 pcre_uint8 gbprop; /* ucp_gbControl, etc. (grapheme break property) */
2605 pcre_uint8 caseset; /* offset to multichar other cases or zero */
2606 pcre_int32 other_case; /* offset to other case, or zero if none */
2607 } ucd_record;
2608
2609 extern const pcre_uint32 PRIV(ucd_caseless_sets)[];
2610 extern const ucd_record PRIV(ucd_records)[];
2611 extern const pcre_uint8 PRIV(ucd_stage1)[];
2612 extern const pcre_uint16 PRIV(ucd_stage2)[];
2613 extern const int PRIV(ucp_gentype)[];
2614 extern const pcre_uint32 PRIV(ucp_gbtable)[];
2615 #ifdef SUPPORT_JIT
2616 extern const int PRIV(ucp_typerange)[];
2617 #endif
2618
2619 #ifdef SUPPORT_UCP
2620 /* UCD access macros */
2621
2622 #define UCD_BLOCK_SIZE 128
2623 #define GET_UCD(ch) (PRIV(ucd_records) + \
2624 PRIV(ucd_stage2)[PRIV(ucd_stage1)[(int)(ch) / UCD_BLOCK_SIZE] * \
2625 UCD_BLOCK_SIZE + (int)(ch) % UCD_BLOCK_SIZE])
2626
2627 #define UCD_CHARTYPE(ch) GET_UCD(ch)->chartype
2628 #define UCD_SCRIPT(ch) GET_UCD(ch)->script
2629 #define UCD_CATEGORY(ch) PRIV(ucp_gentype)[UCD_CHARTYPE(ch)]
2630 #define UCD_GRAPHBREAK(ch) GET_UCD(ch)->gbprop
2631 #define UCD_CASESET(ch) GET_UCD(ch)->caseset
2632 #define UCD_OTHERCASE(ch) ((pcre_uint32)((int)ch + (int)(GET_UCD(ch)->other_case)))
2633
2634 #endif /* SUPPORT_UCP */
2635
2636 #endif
2637
2638 /* End of pcre_internal.h */

Properties

Name Value
svn:eol-style native
svn:keywords "Author Date Id Revision Url"

  ViewVC Help
Powered by ViewVC 1.1.5