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

Contents of /code/trunk/pcretest.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1254 - (show annotations)
Fri Feb 22 12:46:26 2013 UTC (6 years, 6 months ago) by ph10
File MIME type: text/plain
File size: 164737 byte(s)
Added some #ifdef __VMS code to pcretest.c.
1 /*************************************************
2 * PCRE testing program *
3 *************************************************/
4
5 /* This program was hacked up as a tester for PCRE. I really should have
6 written it more tidily in the first place. Will I ever learn? It has grown and
7 been extended and consequently is now rather, er, *very* untidy in places. The
8 addition of 16-bit support has made it even worse. :-(
9
10 -----------------------------------------------------------------------------
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions are met:
13
14 * Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20
21 * Neither the name of the University of Cambridge nor the names of its
22 contributors may be used to endorse or promote products derived from
23 this software without specific prior written permission.
24
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 POSSIBILITY OF SUCH DAMAGE.
36 -----------------------------------------------------------------------------
37 */
38
39 /* This program now supports the testing of all of the 8-bit, 16-bit, and
40 32-bit PCRE libraries in a single program. This is different from the modules
41 such as pcre_compile.c in the library itself, which are compiled separately for
42 each mode. If two modes are enabled, for example, pcre_compile.c is compiled
43 twice. By contrast, pcretest.c is compiled only once. Therefore, it must not
44 make use of any of the macros from pcre_internal.h that depend on
45 COMPILE_PCRE8, COMPILE_PCRE16, or COMPILE_PCRE32. It does, however, make use of
46 SUPPORT_PCRE8, SUPPORT_PCRE16, and SUPPORT_PCRE32 to ensure that it calls only
47 supported library functions. */
48
49 #ifdef HAVE_CONFIG_H
50 #include "config.h"
51 #endif
52
53 #include <ctype.h>
54 #include <stdio.h>
55 #include <string.h>
56 #include <stdlib.h>
57 #include <time.h>
58 #include <locale.h>
59 #include <errno.h>
60
61 /* Both libreadline and libedit are optionally supported. The user-supplied
62 original patch uses readline/readline.h for libedit, but in at least one system
63 it is installed as editline/readline.h, so the configuration code now looks for
64 that first, falling back to readline/readline.h. */
65
66 #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
67 #ifdef HAVE_UNISTD_H
68 #include <unistd.h>
69 #endif
70 #if defined(SUPPORT_LIBREADLINE)
71 #include <readline/readline.h>
72 #include <readline/history.h>
73 #else
74 #if defined(HAVE_EDITLINE_READLINE_H)
75 #include <editline/readline.h>
76 #else
77 #include <readline/readline.h>
78 #endif
79 #endif
80 #endif
81
82 /* A number of things vary for Windows builds. Originally, pcretest opened its
83 input and output without "b"; then I was told that "b" was needed in some
84 environments, so it was added for release 5.0 to both the input and output. (It
85 makes no difference on Unix-like systems.) Later I was told that it is wrong
86 for the input on Windows. I've now abstracted the modes into two macros that
87 are set here, to make it easier to fiddle with them, and removed "b" from the
88 input mode under Windows. */
89
90 #if defined(_WIN32) || defined(WIN32)
91 #include <io.h> /* For _setmode() */
92 #include <fcntl.h> /* For _O_BINARY */
93 #define INPUT_MODE "r"
94 #define OUTPUT_MODE "wb"
95
96 #ifndef isatty
97 #define isatty _isatty /* This is what Windows calls them, I'm told, */
98 #endif /* though in some environments they seem to */
99 /* be already defined, hence the #ifndefs. */
100 #ifndef fileno
101 #define fileno _fileno
102 #endif
103
104 /* A user sent this fix for Borland Builder 5 under Windows. */
105
106 #ifdef __BORLANDC__
107 #define _setmode(handle, mode) setmode(handle, mode)
108 #endif
109
110 /* Not Windows */
111
112 #else
113 #include <sys/time.h> /* These two includes are needed */
114 #include <sys/resource.h> /* for setrlimit(). */
115 #if defined NATIVE_ZOS /* z/OS uses non-binary I/O */
116 #define INPUT_MODE "r"
117 #define OUTPUT_MODE "w"
118 #else
119 #define INPUT_MODE "rb"
120 #define OUTPUT_MODE "wb"
121 #endif
122 #endif
123
124 #ifdef __VMS
125 #include <ssdef.h>
126 void vms_setsymbol( char *, char *, int );
127 #endif
128
129
130 #define PRIV(name) name
131
132 /* We have to include pcre_internal.h because we need the internal info for
133 displaying the results of pcre_study() and we also need to know about the
134 internal macros, structures, and other internal data values; pcretest has
135 "inside information" compared to a program that strictly follows the PCRE API.
136
137 Although pcre_internal.h does itself include pcre.h, we explicitly include it
138 here before pcre_internal.h so that the PCRE_EXP_xxx macros get set
139 appropriately for an application, not for building PCRE. */
140
141 #include "pcre.h"
142 #include "pcre_internal.h"
143
144 /* The pcre_printint() function, which prints the internal form of a compiled
145 regex, is held in a separate file so that (a) it can be compiled in either
146 8-, 16- or 32-bit mode, and (b) it can be #included directly in pcre_compile.c
147 when that is compiled in debug mode. */
148
149 #ifdef SUPPORT_PCRE8
150 void pcre_printint(pcre *external_re, FILE *f, BOOL print_lengths);
151 #endif
152 #ifdef SUPPORT_PCRE16
153 void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths);
154 #endif
155 #ifdef SUPPORT_PCRE32
156 void pcre32_printint(pcre *external_re, FILE *f, BOOL print_lengths);
157 #endif
158
159 /* We need access to some of the data tables that PCRE uses. So as not to have
160 to keep two copies, we include the source files here, changing the names of the
161 external symbols to prevent clashes. */
162
163 #define PCRE_INCLUDED
164
165 #include "pcre_tables.c"
166 #include "pcre_ucd.c"
167
168 /* The definition of the macro PRINTABLE, which determines whether to print an
169 output character as-is or as a hex value when showing compiled patterns, is
170 the same as in the printint.src file. We uses it here in cases when the locale
171 has not been explicitly changed, so as to get consistent output from systems
172 that differ in their output from isprint() even in the "C" locale. */
173
174 #ifdef EBCDIC
175 #define PRINTABLE(c) ((c) >= 64 && (c) < 255)
176 #else
177 #define PRINTABLE(c) ((c) >= 32 && (c) < 127)
178 #endif
179
180 #define PRINTOK(c) (locale_set? isprint(c) : PRINTABLE(c))
181
182 /* Posix support is disabled in 16 or 32 bit only mode. */
183 #if !defined SUPPORT_PCRE8 && !defined NOPOSIX
184 #define NOPOSIX
185 #endif
186
187 /* It is possible to compile this test program without including support for
188 testing the POSIX interface, though this is not available via the standard
189 Makefile. */
190
191 #if !defined NOPOSIX
192 #include "pcreposix.h"
193 #endif
194
195 /* It is also possible, originally for the benefit of a version that was
196 imported into Exim, to build pcretest without support for UTF8 or UTF16 (define
197 NOUTF), without the interface to the DFA matcher (NODFA). In fact, we
198 automatically cut out the UTF support if PCRE is built without it. */
199
200 #ifndef SUPPORT_UTF
201 #ifndef NOUTF
202 #define NOUTF
203 #endif
204 #endif
205
206 /* To make the code a bit tidier for 8/16/32-bit support, we define macros
207 for all the pcre[16]_xxx functions (except pcre16_fullinfo, which is called
208 only from one place and is handled differently). I couldn't dream up any way of
209 using a single macro to do this in a generic way, because of the many different
210 argument requirements. We know that at least one of SUPPORT_PCRE8 and
211 SUPPORT_PCRE16 must be set. First define macros for each individual mode; then
212 use these in the definitions of generic macros.
213
214 **** Special note about the PCHARSxxx macros: the address of the string to be
215 printed is always given as two arguments: a base address followed by an offset.
216 The base address is cast to the correct data size for 8 or 16 bit data; the
217 offset is in units of this size. If the string were given as base+offset in one
218 argument, the casting might be incorrectly applied. */
219
220 #ifdef SUPPORT_PCRE8
221
222 #define PCHARS8(lv, p, offset, len, f) \
223 lv = pchars((pcre_uint8 *)(p) + offset, len, f)
224
225 #define PCHARSV8(p, offset, len, f) \
226 (void)pchars((pcre_uint8 *)(p) + offset, len, f)
227
228 #define READ_CAPTURE_NAME8(p, cn8, cn16, cn32, re) \
229 p = read_capture_name8(p, cn8, re)
230
231 #define STRLEN8(p) ((int)strlen((char *)p))
232
233 #define SET_PCRE_CALLOUT8(callout) \
234 pcre_callout = callout
235
236 #define PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata) \
237 pcre_assign_jit_stack(extra, callback, userdata)
238
239 #define PCRE_COMPILE8(re, pat, options, error, erroffset, tables) \
240 re = pcre_compile((char *)pat, options, error, erroffset, tables)
241
242 #define PCRE_COPY_NAMED_SUBSTRING8(rc, re, bptr, offsets, count, \
243 namesptr, cbuffer, size) \
244 rc = pcre_copy_named_substring(re, (char *)bptr, offsets, count, \
245 (char *)namesptr, cbuffer, size)
246
247 #define PCRE_COPY_SUBSTRING8(rc, bptr, offsets, count, i, cbuffer, size) \
248 rc = pcre_copy_substring((char *)bptr, offsets, count, i, cbuffer, size)
249
250 #define PCRE_DFA_EXEC8(count, re, extra, bptr, len, start_offset, options, \
251 offsets, size_offsets, workspace, size_workspace) \
252 count = pcre_dfa_exec(re, extra, (char *)bptr, len, start_offset, options, \
253 offsets, size_offsets, workspace, size_workspace)
254
255 #define PCRE_EXEC8(count, re, extra, bptr, len, start_offset, options, \
256 offsets, size_offsets) \
257 count = pcre_exec(re, extra, (char *)bptr, len, start_offset, options, \
258 offsets, size_offsets)
259
260 #define PCRE_FREE_STUDY8(extra) \
261 pcre_free_study(extra)
262
263 #define PCRE_FREE_SUBSTRING8(substring) \
264 pcre_free_substring(substring)
265
266 #define PCRE_FREE_SUBSTRING_LIST8(listptr) \
267 pcre_free_substring_list(listptr)
268
269 #define PCRE_GET_NAMED_SUBSTRING8(rc, re, bptr, offsets, count, \
270 getnamesptr, subsptr) \
271 rc = pcre_get_named_substring(re, (char *)bptr, offsets, count, \
272 (char *)getnamesptr, subsptr)
273
274 #define PCRE_GET_STRINGNUMBER8(n, rc, ptr) \
275 n = pcre_get_stringnumber(re, (char *)ptr)
276
277 #define PCRE_GET_SUBSTRING8(rc, bptr, offsets, count, i, subsptr) \
278 rc = pcre_get_substring((char *)bptr, offsets, count, i, subsptr)
279
280 #define PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr) \
281 rc = pcre_get_substring_list((const char *)bptr, offsets, count, listptr)
282
283 #define PCRE_PATTERN_TO_HOST_BYTE_ORDER8(rc, re, extra, tables) \
284 rc = pcre_pattern_to_host_byte_order(re, extra, tables)
285
286 #define PCRE_PRINTINT8(re, outfile, debug_lengths) \
287 pcre_printint(re, outfile, debug_lengths)
288
289 #define PCRE_STUDY8(extra, re, options, error) \
290 extra = pcre_study(re, options, error)
291
292 #define PCRE_JIT_STACK_ALLOC8(startsize, maxsize) \
293 pcre_jit_stack_alloc(startsize, maxsize)
294
295 #define PCRE_JIT_STACK_FREE8(stack) \
296 pcre_jit_stack_free(stack)
297
298 #define pcre8_maketables pcre_maketables
299
300 #endif /* SUPPORT_PCRE8 */
301
302 /* -----------------------------------------------------------*/
303
304 #ifdef SUPPORT_PCRE16
305
306 #define PCHARS16(lv, p, offset, len, f) \
307 lv = pchars16((PCRE_SPTR16)(p) + offset, len, f)
308
309 #define PCHARSV16(p, offset, len, f) \
310 (void)pchars16((PCRE_SPTR16)(p) + offset, len, f)
311
312 #define READ_CAPTURE_NAME16(p, cn8, cn16, cn32, re) \
313 p = read_capture_name16(p, cn16, re)
314
315 #define STRLEN16(p) ((int)strlen16((PCRE_SPTR16)p))
316
317 #define SET_PCRE_CALLOUT16(callout) \
318 pcre16_callout = (int (*)(pcre16_callout_block *))callout
319
320 #define PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata) \
321 pcre16_assign_jit_stack((pcre16_extra *)extra, \
322 (pcre16_jit_callback)callback, userdata)
323
324 #define PCRE_COMPILE16(re, pat, options, error, erroffset, tables) \
325 re = (pcre *)pcre16_compile((PCRE_SPTR16)pat, options, error, erroffset, \
326 tables)
327
328 #define PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
329 namesptr, cbuffer, size) \
330 rc = pcre16_copy_named_substring((pcre16 *)re, (PCRE_SPTR16)bptr, offsets, \
331 count, (PCRE_SPTR16)namesptr, (PCRE_UCHAR16 *)cbuffer, size/2)
332
333 #define PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size) \
334 rc = pcre16_copy_substring((PCRE_SPTR16)bptr, offsets, count, i, \
335 (PCRE_UCHAR16 *)cbuffer, size/2)
336
337 #define PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \
338 offsets, size_offsets, workspace, size_workspace) \
339 count = pcre16_dfa_exec((pcre16 *)re, (pcre16_extra *)extra, \
340 (PCRE_SPTR16)bptr, len, start_offset, options, offsets, size_offsets, \
341 workspace, size_workspace)
342
343 #define PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \
344 offsets, size_offsets) \
345 count = pcre16_exec((pcre16 *)re, (pcre16_extra *)extra, (PCRE_SPTR16)bptr, \
346 len, start_offset, options, offsets, size_offsets)
347
348 #define PCRE_FREE_STUDY16(extra) \
349 pcre16_free_study((pcre16_extra *)extra)
350
351 #define PCRE_FREE_SUBSTRING16(substring) \
352 pcre16_free_substring((PCRE_SPTR16)substring)
353
354 #define PCRE_FREE_SUBSTRING_LIST16(listptr) \
355 pcre16_free_substring_list((PCRE_SPTR16 *)listptr)
356
357 #define PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
358 getnamesptr, subsptr) \
359 rc = pcre16_get_named_substring((pcre16 *)re, (PCRE_SPTR16)bptr, offsets, \
360 count, (PCRE_SPTR16)getnamesptr, (PCRE_SPTR16 *)(void*)subsptr)
361
362 #define PCRE_GET_STRINGNUMBER16(n, rc, ptr) \
363 n = pcre16_get_stringnumber(re, (PCRE_SPTR16)ptr)
364
365 #define PCRE_GET_SUBSTRING16(rc, bptr, offsets, count, i, subsptr) \
366 rc = pcre16_get_substring((PCRE_SPTR16)bptr, offsets, count, i, \
367 (PCRE_SPTR16 *)(void*)subsptr)
368
369 #define PCRE_GET_SUBSTRING_LIST16(rc, bptr, offsets, count, listptr) \
370 rc = pcre16_get_substring_list((PCRE_SPTR16)bptr, offsets, count, \
371 (PCRE_SPTR16 **)(void*)listptr)
372
373 #define PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables) \
374 rc = pcre16_pattern_to_host_byte_order((pcre16 *)re, (pcre16_extra *)extra, \
375 tables)
376
377 #define PCRE_PRINTINT16(re, outfile, debug_lengths) \
378 pcre16_printint(re, outfile, debug_lengths)
379
380 #define PCRE_STUDY16(extra, re, options, error) \
381 extra = (pcre_extra *)pcre16_study((pcre16 *)re, options, error)
382
383 #define PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \
384 (pcre_jit_stack *)pcre16_jit_stack_alloc(startsize, maxsize)
385
386 #define PCRE_JIT_STACK_FREE16(stack) \
387 pcre16_jit_stack_free((pcre16_jit_stack *)stack)
388
389 #endif /* SUPPORT_PCRE16 */
390
391 /* -----------------------------------------------------------*/
392
393 #ifdef SUPPORT_PCRE32
394
395 #define PCHARS32(lv, p, offset, len, f) \
396 lv = pchars32((PCRE_SPTR32)(p) + offset, len, use_utf, f)
397
398 #define PCHARSV32(p, offset, len, f) \
399 (void)pchars32((PCRE_SPTR32)(p) + offset, len, use_utf, f)
400
401 #define READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re) \
402 p = read_capture_name32(p, cn32, re)
403
404 #define STRLEN32(p) ((int)strlen32((PCRE_SPTR32)p))
405
406 #define SET_PCRE_CALLOUT32(callout) \
407 pcre32_callout = (int (*)(pcre32_callout_block *))callout
408
409 #define PCRE_ASSIGN_JIT_STACK32(extra, callback, userdata) \
410 pcre32_assign_jit_stack((pcre32_extra *)extra, \
411 (pcre32_jit_callback)callback, userdata)
412
413 #define PCRE_COMPILE32(re, pat, options, error, erroffset, tables) \
414 re = (pcre *)pcre32_compile((PCRE_SPTR32)pat, options, error, erroffset, \
415 tables)
416
417 #define PCRE_COPY_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
418 namesptr, cbuffer, size) \
419 rc = pcre32_copy_named_substring((pcre32 *)re, (PCRE_SPTR32)bptr, offsets, \
420 count, (PCRE_SPTR32)namesptr, (PCRE_UCHAR32 *)cbuffer, size/2)
421
422 #define PCRE_COPY_SUBSTRING32(rc, bptr, offsets, count, i, cbuffer, size) \
423 rc = pcre32_copy_substring((PCRE_SPTR32)bptr, offsets, count, i, \
424 (PCRE_UCHAR32 *)cbuffer, size/2)
425
426 #define PCRE_DFA_EXEC32(count, re, extra, bptr, len, start_offset, options, \
427 offsets, size_offsets, workspace, size_workspace) \
428 count = pcre32_dfa_exec((pcre32 *)re, (pcre32_extra *)extra, \
429 (PCRE_SPTR32)bptr, len, start_offset, options, offsets, size_offsets, \
430 workspace, size_workspace)
431
432 #define PCRE_EXEC32(count, re, extra, bptr, len, start_offset, options, \
433 offsets, size_offsets) \
434 count = pcre32_exec((pcre32 *)re, (pcre32_extra *)extra, (PCRE_SPTR32)bptr, \
435 len, start_offset, options, offsets, size_offsets)
436
437 #define PCRE_FREE_STUDY32(extra) \
438 pcre32_free_study((pcre32_extra *)extra)
439
440 #define PCRE_FREE_SUBSTRING32(substring) \
441 pcre32_free_substring((PCRE_SPTR32)substring)
442
443 #define PCRE_FREE_SUBSTRING_LIST32(listptr) \
444 pcre32_free_substring_list((PCRE_SPTR32 *)listptr)
445
446 #define PCRE_GET_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
447 getnamesptr, subsptr) \
448 rc = pcre32_get_named_substring((pcre32 *)re, (PCRE_SPTR32)bptr, offsets, \
449 count, (PCRE_SPTR32)getnamesptr, (PCRE_SPTR32 *)(void*)subsptr)
450
451 #define PCRE_GET_STRINGNUMBER32(n, rc, ptr) \
452 n = pcre32_get_stringnumber(re, (PCRE_SPTR32)ptr)
453
454 #define PCRE_GET_SUBSTRING32(rc, bptr, offsets, count, i, subsptr) \
455 rc = pcre32_get_substring((PCRE_SPTR32)bptr, offsets, count, i, \
456 (PCRE_SPTR32 *)(void*)subsptr)
457
458 #define PCRE_GET_SUBSTRING_LIST32(rc, bptr, offsets, count, listptr) \
459 rc = pcre32_get_substring_list((PCRE_SPTR32)bptr, offsets, count, \
460 (PCRE_SPTR32 **)(void*)listptr)
461
462 #define PCRE_PATTERN_TO_HOST_BYTE_ORDER32(rc, re, extra, tables) \
463 rc = pcre32_pattern_to_host_byte_order((pcre32 *)re, (pcre32_extra *)extra, \
464 tables)
465
466 #define PCRE_PRINTINT32(re, outfile, debug_lengths) \
467 pcre32_printint(re, outfile, debug_lengths)
468
469 #define PCRE_STUDY32(extra, re, options, error) \
470 extra = (pcre_extra *)pcre32_study((pcre32 *)re, options, error)
471
472 #define PCRE_JIT_STACK_ALLOC32(startsize, maxsize) \
473 (pcre_jit_stack *)pcre32_jit_stack_alloc(startsize, maxsize)
474
475 #define PCRE_JIT_STACK_FREE32(stack) \
476 pcre32_jit_stack_free((pcre32_jit_stack *)stack)
477
478 #endif /* SUPPORT_PCRE32 */
479
480
481 /* ----- More than one mode is supported; a runtime test is needed, except for
482 pcre_config(), and the JIT stack functions, when it doesn't matter which
483 available version is called. ----- */
484
485 enum {
486 PCRE8_MODE,
487 PCRE16_MODE,
488 PCRE32_MODE
489 };
490
491 #if (defined (SUPPORT_PCRE8) + defined (SUPPORT_PCRE16) + \
492 defined (SUPPORT_PCRE32)) >= 2
493
494 #define CHAR_SIZE (1 << pcre_mode)
495
496 /* There doesn't seem to be an easy way of writing these macros that can cope
497 with the 3 pairs of bit sizes plus all three bit sizes. So just handle all the
498 cases separately. */
499
500 /* ----- All three modes supported ----- */
501
502 #if defined(SUPPORT_PCRE8) && defined(SUPPORT_PCRE16) && defined(SUPPORT_PCRE32)
503
504 #define PCHARS(lv, p, offset, len, f) \
505 if (pcre_mode == PCRE32_MODE) \
506 PCHARS32(lv, p, offset, len, f); \
507 else if (pcre_mode == PCRE16_MODE) \
508 PCHARS16(lv, p, offset, len, f); \
509 else \
510 PCHARS8(lv, p, offset, len, f)
511
512 #define PCHARSV(p, offset, len, f) \
513 if (pcre_mode == PCRE32_MODE) \
514 PCHARSV32(p, offset, len, f); \
515 else if (pcre_mode == PCRE16_MODE) \
516 PCHARSV16(p, offset, len, f); \
517 else \
518 PCHARSV8(p, offset, len, f)
519
520 #define READ_CAPTURE_NAME(p, cn8, cn16, cn32, re) \
521 if (pcre_mode == PCRE32_MODE) \
522 READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re); \
523 else if (pcre_mode == PCRE16_MODE) \
524 READ_CAPTURE_NAME16(p, cn8, cn16, cn32, re); \
525 else \
526 READ_CAPTURE_NAME8(p, cn8, cn16, cn32, re)
527
528 #define SET_PCRE_CALLOUT(callout) \
529 if (pcre_mode == PCRE32_MODE) \
530 SET_PCRE_CALLOUT32(callout); \
531 else if (pcre_mode == PCRE16_MODE) \
532 SET_PCRE_CALLOUT16(callout); \
533 else \
534 SET_PCRE_CALLOUT8(callout)
535
536 #define STRLEN(p) (pcre_mode == PCRE32_MODE ? STRLEN32(p) : pcre_mode == PCRE16_MODE ? STRLEN16(p) : STRLEN8(p))
537
538 #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \
539 if (pcre_mode == PCRE32_MODE) \
540 PCRE_ASSIGN_JIT_STACK32(extra, callback, userdata); \
541 else if (pcre_mode == PCRE16_MODE) \
542 PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata); \
543 else \
544 PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata)
545
546 #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
547 if (pcre_mode == PCRE32_MODE) \
548 PCRE_COMPILE32(re, pat, options, error, erroffset, tables); \
549 else if (pcre_mode == PCRE16_MODE) \
550 PCRE_COMPILE16(re, pat, options, error, erroffset, tables); \
551 else \
552 PCRE_COMPILE8(re, pat, options, error, erroffset, tables)
553
554 #define PCRE_CONFIG pcre_config
555
556 #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
557 namesptr, cbuffer, size) \
558 if (pcre_mode == PCRE32_MODE) \
559 PCRE_COPY_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
560 namesptr, cbuffer, size); \
561 else if (pcre_mode == PCRE16_MODE) \
562 PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
563 namesptr, cbuffer, size); \
564 else \
565 PCRE_COPY_NAMED_SUBSTRING8(rc, re, bptr, offsets, count, \
566 namesptr, cbuffer, size)
567
568 #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \
569 if (pcre_mode == PCRE32_MODE) \
570 PCRE_COPY_SUBSTRING32(rc, bptr, offsets, count, i, cbuffer, size); \
571 else if (pcre_mode == PCRE16_MODE) \
572 PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size); \
573 else \
574 PCRE_COPY_SUBSTRING8(rc, bptr, offsets, count, i, cbuffer, size)
575
576 #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \
577 offsets, size_offsets, workspace, size_workspace) \
578 if (pcre_mode == PCRE32_MODE) \
579 PCRE_DFA_EXEC32(count, re, extra, bptr, len, start_offset, options, \
580 offsets, size_offsets, workspace, size_workspace); \
581 else if (pcre_mode == PCRE16_MODE) \
582 PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \
583 offsets, size_offsets, workspace, size_workspace); \
584 else \
585 PCRE_DFA_EXEC8(count, re, extra, bptr, len, start_offset, options, \
586 offsets, size_offsets, workspace, size_workspace)
587
588 #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
589 offsets, size_offsets) \
590 if (pcre_mode == PCRE32_MODE) \
591 PCRE_EXEC32(count, re, extra, bptr, len, start_offset, options, \
592 offsets, size_offsets); \
593 else if (pcre_mode == PCRE16_MODE) \
594 PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \
595 offsets, size_offsets); \
596 else \
597 PCRE_EXEC8(count, re, extra, bptr, len, start_offset, options, \
598 offsets, size_offsets)
599
600 #define PCRE_FREE_STUDY(extra) \
601 if (pcre_mode == PCRE32_MODE) \
602 PCRE_FREE_STUDY32(extra); \
603 else if (pcre_mode == PCRE16_MODE) \
604 PCRE_FREE_STUDY16(extra); \
605 else \
606 PCRE_FREE_STUDY8(extra)
607
608 #define PCRE_FREE_SUBSTRING(substring) \
609 if (pcre_mode == PCRE32_MODE) \
610 PCRE_FREE_SUBSTRING32(substring); \
611 else if (pcre_mode == PCRE16_MODE) \
612 PCRE_FREE_SUBSTRING16(substring); \
613 else \
614 PCRE_FREE_SUBSTRING8(substring)
615
616 #define PCRE_FREE_SUBSTRING_LIST(listptr) \
617 if (pcre_mode == PCRE32_MODE) \
618 PCRE_FREE_SUBSTRING_LIST32(listptr); \
619 else if (pcre_mode == PCRE16_MODE) \
620 PCRE_FREE_SUBSTRING_LIST16(listptr); \
621 else \
622 PCRE_FREE_SUBSTRING_LIST8(listptr)
623
624 #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
625 getnamesptr, subsptr) \
626 if (pcre_mode == PCRE32_MODE) \
627 PCRE_GET_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
628 getnamesptr, subsptr); \
629 else if (pcre_mode == PCRE16_MODE) \
630 PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
631 getnamesptr, subsptr); \
632 else \
633 PCRE_GET_NAMED_SUBSTRING8(rc, re, bptr, offsets, count, \
634 getnamesptr, subsptr)
635
636 #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \
637 if (pcre_mode == PCRE32_MODE) \
638 PCRE_GET_STRINGNUMBER32(n, rc, ptr); \
639 else if (pcre_mode == PCRE16_MODE) \
640 PCRE_GET_STRINGNUMBER16(n, rc, ptr); \
641 else \
642 PCRE_GET_STRINGNUMBER8(n, rc, ptr)
643
644 #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \
645 if (pcre_mode == PCRE32_MODE) \
646 PCRE_GET_SUBSTRING32(rc, bptr, use_offsets, count, i, subsptr); \
647 else if (pcre_mode == PCRE16_MODE) \
648 PCRE_GET_SUBSTRING16(rc, bptr, use_offsets, count, i, subsptr); \
649 else \
650 PCRE_GET_SUBSTRING8(rc, bptr, use_offsets, count, i, subsptr)
651
652 #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \
653 if (pcre_mode == PCRE32_MODE) \
654 PCRE_GET_SUBSTRING_LIST32(rc, bptr, offsets, count, listptr); \
655 else if (pcre_mode == PCRE16_MODE) \
656 PCRE_GET_SUBSTRING_LIST16(rc, bptr, offsets, count, listptr); \
657 else \
658 PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr)
659
660 #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \
661 (pcre_mode == PCRE32_MODE ? \
662 PCRE_JIT_STACK_ALLOC32(startsize, maxsize) \
663 : pcre_mode == PCRE16_MODE ? \
664 PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \
665 : PCRE_JIT_STACK_ALLOC8(startsize, maxsize))
666
667 #define PCRE_JIT_STACK_FREE(stack) \
668 if (pcre_mode == PCRE32_MODE) \
669 PCRE_JIT_STACK_FREE32(stack); \
670 else if (pcre_mode == PCRE16_MODE) \
671 PCRE_JIT_STACK_FREE16(stack); \
672 else \
673 PCRE_JIT_STACK_FREE8(stack)
674
675 #define PCRE_MAKETABLES \
676 (pcre_mode == PCRE32_MODE ? pcre32_maketables() : pcre_mode == PCRE16_MODE ? pcre16_maketables() : pcre_maketables())
677
678 #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \
679 if (pcre_mode == PCRE32_MODE) \
680 PCRE_PATTERN_TO_HOST_BYTE_ORDER32(rc, re, extra, tables); \
681 else if (pcre_mode == PCRE16_MODE) \
682 PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables); \
683 else \
684 PCRE_PATTERN_TO_HOST_BYTE_ORDER8(rc, re, extra, tables)
685
686 #define PCRE_PRINTINT(re, outfile, debug_lengths) \
687 if (pcre_mode == PCRE32_MODE) \
688 PCRE_PRINTINT32(re, outfile, debug_lengths); \
689 else if (pcre_mode == PCRE16_MODE) \
690 PCRE_PRINTINT16(re, outfile, debug_lengths); \
691 else \
692 PCRE_PRINTINT8(re, outfile, debug_lengths)
693
694 #define PCRE_STUDY(extra, re, options, error) \
695 if (pcre_mode == PCRE32_MODE) \
696 PCRE_STUDY32(extra, re, options, error); \
697 else if (pcre_mode == PCRE16_MODE) \
698 PCRE_STUDY16(extra, re, options, error); \
699 else \
700 PCRE_STUDY8(extra, re, options, error)
701
702
703 /* ----- Two out of three modes are supported ----- */
704
705 #else
706
707 /* We can use some macro trickery to make a single set of definitions work in
708 the three different cases. */
709
710 /* ----- 32-bit and 16-bit but not 8-bit supported ----- */
711
712 #if defined(SUPPORT_PCRE32) && defined(SUPPORT_PCRE16)
713 #define BITONE 32
714 #define BITTWO 16
715
716 /* ----- 32-bit and 8-bit but not 16-bit supported ----- */
717
718 #elif defined(SUPPORT_PCRE32) && defined(SUPPORT_PCRE8)
719 #define BITONE 32
720 #define BITTWO 8
721
722 /* ----- 16-bit and 8-bit but not 32-bit supported ----- */
723
724 #else
725 #define BITONE 16
726 #define BITTWO 8
727 #endif
728
729 #define glue(a,b) a##b
730 #define G(a,b) glue(a,b)
731
732
733 /* ----- Common macros for two-mode cases ----- */
734
735 #define PCHARS(lv, p, offset, len, f) \
736 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
737 G(PCHARS,BITONE)(lv, p, offset, len, f); \
738 else \
739 G(PCHARS,BITTWO)(lv, p, offset, len, f)
740
741 #define PCHARSV(p, offset, len, f) \
742 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
743 G(PCHARSV,BITONE)(p, offset, len, f); \
744 else \
745 G(PCHARSV,BITTWO)(p, offset, len, f)
746
747 #define READ_CAPTURE_NAME(p, cn8, cn16, cn32, re) \
748 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
749 G(READ_CAPTURE_NAME,BITONE)(p, cn8, cn16, cn32, re); \
750 else \
751 G(READ_CAPTURE_NAME,BITTWO)(p, cn8, cn16, cn32, re)
752
753 #define SET_PCRE_CALLOUT(callout) \
754 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
755 G(SET_PCRE_CALLOUT,BITONE)(callout); \
756 else \
757 G(SET_PCRE_CALLOUT,BITTWO)(callout)
758
759 #define STRLEN(p) ((pcre_mode == G(G(PCRE,BITONE),_MODE)) ? \
760 G(STRLEN,BITONE)(p) : G(STRLEN,BITTWO)(p))
761
762 #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \
763 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
764 G(PCRE_ASSIGN_JIT_STACK,BITONE)(extra, callback, userdata); \
765 else \
766 G(PCRE_ASSIGN_JIT_STACK,BITTWO)(extra, callback, userdata)
767
768 #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
769 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
770 G(PCRE_COMPILE,BITONE)(re, pat, options, error, erroffset, tables); \
771 else \
772 G(PCRE_COMPILE,BITTWO)(re, pat, options, error, erroffset, tables)
773
774 #define PCRE_CONFIG G(G(pcre,BITONE),_config)
775
776 #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
777 namesptr, cbuffer, size) \
778 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
779 G(PCRE_COPY_NAMED_SUBSTRING,BITONE)(rc, re, bptr, offsets, count, \
780 namesptr, cbuffer, size); \
781 else \
782 G(PCRE_COPY_NAMED_SUBSTRING,BITTWO)(rc, re, bptr, offsets, count, \
783 namesptr, cbuffer, size)
784
785 #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \
786 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
787 G(PCRE_COPY_SUBSTRING,BITONE)(rc, bptr, offsets, count, i, cbuffer, size); \
788 else \
789 G(PCRE_COPY_SUBSTRING,BITTWO)(rc, bptr, offsets, count, i, cbuffer, size)
790
791 #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \
792 offsets, size_offsets, workspace, size_workspace) \
793 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
794 G(PCRE_DFA_EXEC,BITONE)(count, re, extra, bptr, len, start_offset, options, \
795 offsets, size_offsets, workspace, size_workspace); \
796 else \
797 G(PCRE_DFA_EXEC,BITTWO)(count, re, extra, bptr, len, start_offset, options, \
798 offsets, size_offsets, workspace, size_workspace)
799
800 #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
801 offsets, size_offsets) \
802 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
803 G(PCRE_EXEC,BITONE)(count, re, extra, bptr, len, start_offset, options, \
804 offsets, size_offsets); \
805 else \
806 G(PCRE_EXEC,BITTWO)(count, re, extra, bptr, len, start_offset, options, \
807 offsets, size_offsets)
808
809 #define PCRE_FREE_STUDY(extra) \
810 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
811 G(PCRE_FREE_STUDY,BITONE)(extra); \
812 else \
813 G(PCRE_FREE_STUDY,BITTWO)(extra)
814
815 #define PCRE_FREE_SUBSTRING(substring) \
816 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
817 G(PCRE_FREE_SUBSTRING,BITONE)(substring); \
818 else \
819 G(PCRE_FREE_SUBSTRING,BITTWO)(substring)
820
821 #define PCRE_FREE_SUBSTRING_LIST(listptr) \
822 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
823 G(PCRE_FREE_SUBSTRING_LIST,BITONE)(listptr); \
824 else \
825 G(PCRE_FREE_SUBSTRING_LIST,BITTWO)(listptr)
826
827 #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
828 getnamesptr, subsptr) \
829 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
830 G(PCRE_GET_NAMED_SUBSTRING,BITONE)(rc, re, bptr, offsets, count, \
831 getnamesptr, subsptr); \
832 else \
833 G(PCRE_GET_NAMED_SUBSTRING,BITTWO)(rc, re, bptr, offsets, count, \
834 getnamesptr, subsptr)
835
836 #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \
837 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
838 G(PCRE_GET_STRINGNUMBER,BITONE)(n, rc, ptr); \
839 else \
840 G(PCRE_GET_STRINGNUMBER,BITTWO)(n, rc, ptr)
841
842 #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \
843 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
844 G(PCRE_GET_SUBSTRING,BITONE)(rc, bptr, use_offsets, count, i, subsptr); \
845 else \
846 G(PCRE_GET_SUBSTRING,BITTWO)(rc, bptr, use_offsets, count, i, subsptr)
847
848 #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \
849 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
850 G(PCRE_GET_SUBSTRING_LIST,BITONE)(rc, bptr, offsets, count, listptr); \
851 else \
852 G(PCRE_GET_SUBSTRING_LIST,BITTWO)(rc, bptr, offsets, count, listptr)
853
854 #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \
855 (pcre_mode == G(G(PCRE,BITONE),_MODE)) ? \
856 G(PCRE_JIT_STACK_ALLOC,BITONE)(startsize, maxsize) \
857 : G(PCRE_JIT_STACK_ALLOC,BITTWO)(startsize, maxsize)
858
859 #define PCRE_JIT_STACK_FREE(stack) \
860 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
861 G(PCRE_JIT_STACK_FREE,BITONE)(stack); \
862 else \
863 G(PCRE_JIT_STACK_FREE,BITTWO)(stack)
864
865 #define PCRE_MAKETABLES \
866 (pcre_mode == G(G(PCRE,BITONE),_MODE)) ? \
867 G(G(pcre,BITONE),_maketables)() : G(G(pcre,BITTWO),_maketables)()
868
869 #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \
870 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
871 G(PCRE_PATTERN_TO_HOST_BYTE_ORDER,BITONE)(rc, re, extra, tables); \
872 else \
873 G(PCRE_PATTERN_TO_HOST_BYTE_ORDER,BITTWO)(rc, re, extra, tables)
874
875 #define PCRE_PRINTINT(re, outfile, debug_lengths) \
876 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
877 G(PCRE_PRINTINT,BITONE)(re, outfile, debug_lengths); \
878 else \
879 G(PCRE_PRINTINT,BITTWO)(re, outfile, debug_lengths)
880
881 #define PCRE_STUDY(extra, re, options, error) \
882 if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
883 G(PCRE_STUDY,BITONE)(extra, re, options, error); \
884 else \
885 G(PCRE_STUDY,BITTWO)(extra, re, options, error)
886
887 #endif /* Two out of three modes */
888
889 /* ----- End of cases where more than one mode is supported ----- */
890
891
892 /* ----- Only 8-bit mode is supported ----- */
893
894 #elif defined SUPPORT_PCRE8
895 #define CHAR_SIZE 1
896 #define PCHARS PCHARS8
897 #define PCHARSV PCHARSV8
898 #define READ_CAPTURE_NAME READ_CAPTURE_NAME8
899 #define SET_PCRE_CALLOUT SET_PCRE_CALLOUT8
900 #define STRLEN STRLEN8
901 #define PCRE_ASSIGN_JIT_STACK PCRE_ASSIGN_JIT_STACK8
902 #define PCRE_COMPILE PCRE_COMPILE8
903 #define PCRE_CONFIG pcre_config
904 #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING8
905 #define PCRE_COPY_SUBSTRING PCRE_COPY_SUBSTRING8
906 #define PCRE_DFA_EXEC PCRE_DFA_EXEC8
907 #define PCRE_EXEC PCRE_EXEC8
908 #define PCRE_FREE_STUDY PCRE_FREE_STUDY8
909 #define PCRE_FREE_SUBSTRING PCRE_FREE_SUBSTRING8
910 #define PCRE_FREE_SUBSTRING_LIST PCRE_FREE_SUBSTRING_LIST8
911 #define PCRE_GET_NAMED_SUBSTRING PCRE_GET_NAMED_SUBSTRING8
912 #define PCRE_GET_STRINGNUMBER PCRE_GET_STRINGNUMBER8
913 #define PCRE_GET_SUBSTRING PCRE_GET_SUBSTRING8
914 #define PCRE_GET_SUBSTRING_LIST PCRE_GET_SUBSTRING_LIST8
915 #define PCRE_JIT_STACK_ALLOC PCRE_JIT_STACK_ALLOC8
916 #define PCRE_JIT_STACK_FREE PCRE_JIT_STACK_FREE8
917 #define PCRE_MAKETABLES pcre_maketables()
918 #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER8
919 #define PCRE_PRINTINT PCRE_PRINTINT8
920 #define PCRE_STUDY PCRE_STUDY8
921
922 /* ----- Only 16-bit mode is supported ----- */
923
924 #elif defined SUPPORT_PCRE16
925 #define CHAR_SIZE 2
926 #define PCHARS PCHARS16
927 #define PCHARSV PCHARSV16
928 #define READ_CAPTURE_NAME READ_CAPTURE_NAME16
929 #define SET_PCRE_CALLOUT SET_PCRE_CALLOUT16
930 #define STRLEN STRLEN16
931 #define PCRE_ASSIGN_JIT_STACK PCRE_ASSIGN_JIT_STACK16
932 #define PCRE_COMPILE PCRE_COMPILE16
933 #define PCRE_CONFIG pcre16_config
934 #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING16
935 #define PCRE_COPY_SUBSTRING PCRE_COPY_SUBSTRING16
936 #define PCRE_DFA_EXEC PCRE_DFA_EXEC16
937 #define PCRE_EXEC PCRE_EXEC16
938 #define PCRE_FREE_STUDY PCRE_FREE_STUDY16
939 #define PCRE_FREE_SUBSTRING PCRE_FREE_SUBSTRING16
940 #define PCRE_FREE_SUBSTRING_LIST PCRE_FREE_SUBSTRING_LIST16
941 #define PCRE_GET_NAMED_SUBSTRING PCRE_GET_NAMED_SUBSTRING16
942 #define PCRE_GET_STRINGNUMBER PCRE_GET_STRINGNUMBER16
943 #define PCRE_GET_SUBSTRING PCRE_GET_SUBSTRING16
944 #define PCRE_GET_SUBSTRING_LIST PCRE_GET_SUBSTRING_LIST16
945 #define PCRE_JIT_STACK_ALLOC PCRE_JIT_STACK_ALLOC16
946 #define PCRE_JIT_STACK_FREE PCRE_JIT_STACK_FREE16
947 #define PCRE_MAKETABLES pcre16_maketables()
948 #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER16
949 #define PCRE_PRINTINT PCRE_PRINTINT16
950 #define PCRE_STUDY PCRE_STUDY16
951
952 /* ----- Only 32-bit mode is supported ----- */
953
954 #elif defined SUPPORT_PCRE32
955 #define CHAR_SIZE 4
956 #define PCHARS PCHARS32
957 #define PCHARSV PCHARSV32
958 #define READ_CAPTURE_NAME READ_CAPTURE_NAME32
959 #define SET_PCRE_CALLOUT SET_PCRE_CALLOUT32
960 #define STRLEN STRLEN32
961 #define PCRE_ASSIGN_JIT_STACK PCRE_ASSIGN_JIT_STACK32
962 #define PCRE_COMPILE PCRE_COMPILE32
963 #define PCRE_CONFIG pcre32_config
964 #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING32
965 #define PCRE_COPY_SUBSTRING PCRE_COPY_SUBSTRING32
966 #define PCRE_DFA_EXEC PCRE_DFA_EXEC32
967 #define PCRE_EXEC PCRE_EXEC32
968 #define PCRE_FREE_STUDY PCRE_FREE_STUDY32
969 #define PCRE_FREE_SUBSTRING PCRE_FREE_SUBSTRING32
970 #define PCRE_FREE_SUBSTRING_LIST PCRE_FREE_SUBSTRING_LIST32
971 #define PCRE_GET_NAMED_SUBSTRING PCRE_GET_NAMED_SUBSTRING32
972 #define PCRE_GET_STRINGNUMBER PCRE_GET_STRINGNUMBER32
973 #define PCRE_GET_SUBSTRING PCRE_GET_SUBSTRING32
974 #define PCRE_GET_SUBSTRING_LIST PCRE_GET_SUBSTRING_LIST32
975 #define PCRE_JIT_STACK_ALLOC PCRE_JIT_STACK_ALLOC32
976 #define PCRE_JIT_STACK_FREE PCRE_JIT_STACK_FREE32
977 #define PCRE_MAKETABLES pcre32_maketables()
978 #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER32
979 #define PCRE_PRINTINT PCRE_PRINTINT32
980 #define PCRE_STUDY PCRE_STUDY32
981
982 #endif
983
984 /* ----- End of mode-specific function call macros ----- */
985
986
987 /* Other parameters */
988
989 #ifndef CLOCKS_PER_SEC
990 #ifdef CLK_TCK
991 #define CLOCKS_PER_SEC CLK_TCK
992 #else
993 #define CLOCKS_PER_SEC 100
994 #endif
995 #endif
996
997 #if !defined NODFA
998 #define DFA_WS_DIMENSION 1000
999 #endif
1000
1001 /* This is the default loop count for timing. */
1002
1003 #define LOOPREPEAT 500000
1004
1005 /* Static variables */
1006
1007 static FILE *outfile;
1008 static int log_store = 0;
1009 static int callout_count;
1010 static int callout_extra;
1011 static int callout_fail_count;
1012 static int callout_fail_id;
1013 static int debug_lengths;
1014 static int first_callout;
1015 static int jit_was_used;
1016 static int locale_set = 0;
1017 static int show_malloc;
1018 static int use_utf;
1019 static size_t gotten_store;
1020 static size_t first_gotten_store = 0;
1021 static const unsigned char *last_callout_mark = NULL;
1022
1023 /* The buffers grow automatically if very long input lines are encountered. */
1024
1025 static int buffer_size = 50000;
1026 static pcre_uint8 *buffer = NULL;
1027 static pcre_uint8 *pbuffer = NULL;
1028
1029 /* Just as a safety check, make sure that COMPILE_PCRE[16|32] are *not* set. */
1030
1031 #ifdef COMPILE_PCRE16
1032 #error COMPILE_PCRE16 must not be set when compiling pcretest.c
1033 #endif
1034
1035 #ifdef COMPILE_PCRE32
1036 #error COMPILE_PCRE32 must not be set when compiling pcretest.c
1037 #endif
1038
1039 /* We need buffers for building 16/32-bit strings, and the tables of operator
1040 lengths that are used for 16/32-bit compiling, in order to swap bytes in a
1041 pattern for saving/reloading testing. Luckily, the data for these tables is
1042 defined as a macro. However, we must ensure that LINK_SIZE and IMM2_SIZE (which
1043 are used in the tables) are adjusted appropriately for the 16/32-bit world.
1044 LINK_SIZE is also used later in this program. */
1045
1046 #ifdef SUPPORT_PCRE16
1047 #undef IMM2_SIZE
1048 #define IMM2_SIZE 1
1049
1050 #if LINK_SIZE == 2
1051 #undef LINK_SIZE
1052 #define LINK_SIZE 1
1053 #elif LINK_SIZE == 3 || LINK_SIZE == 4
1054 #undef LINK_SIZE
1055 #define LINK_SIZE 2
1056 #else
1057 #error LINK_SIZE must be either 2, 3, or 4
1058 #endif
1059
1060 static int buffer16_size = 0;
1061 static pcre_uint16 *buffer16 = NULL;
1062 static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };
1063 #endif /* SUPPORT_PCRE16 */
1064
1065 #ifdef SUPPORT_PCRE32
1066 #undef IMM2_SIZE
1067 #define IMM2_SIZE 1
1068 #undef LINK_SIZE
1069 #define LINK_SIZE 1
1070
1071 static int buffer32_size = 0;
1072 static pcre_uint32 *buffer32 = NULL;
1073 static const pcre_uint32 OP_lengths32[] = { OP_LENGTHS };
1074 #endif /* SUPPORT_PCRE32 */
1075
1076 /* If we have 8-bit support, default to it; if there is also 16-or 32-bit
1077 support, it can be changed by an option. If there is no 8-bit support, there
1078 must be 16-or 32-bit support, so default it to 1. */
1079
1080 #if defined SUPPORT_PCRE8
1081 static int pcre_mode = PCRE8_MODE;
1082 #elif defined SUPPORT_PCRE16
1083 static int pcre_mode = PCRE16_MODE;
1084 #elif defined SUPPORT_PCRE32
1085 static int pcre_mode = PCRE32_MODE;
1086 #endif
1087
1088 /* JIT study options for -s+n and /S+n where '1' <= n <= '7'. */
1089
1090 static int jit_study_bits[] =
1091 {
1092 PCRE_STUDY_JIT_COMPILE,
1093 PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE,
1094 PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE,
1095 PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
1096 PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
1097 PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE + PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
1098 PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE +
1099 PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE
1100 };
1101
1102 #define PCRE_STUDY_ALLJIT (PCRE_STUDY_JIT_COMPILE | \
1103 PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE | PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE)
1104
1105 /* Textual explanations for runtime error codes */
1106
1107 static const char *errtexts[] = {
1108 NULL, /* 0 is no error */
1109 NULL, /* NOMATCH is handled specially */
1110 "NULL argument passed",
1111 "bad option value",
1112 "magic number missing",
1113 "unknown opcode - pattern overwritten?",
1114 "no more memory",
1115 NULL, /* never returned by pcre_exec() or pcre_dfa_exec() */
1116 "match limit exceeded",
1117 "callout error code",
1118 NULL, /* BADUTF8/16 is handled specially */
1119 NULL, /* BADUTF8/16 offset is handled specially */
1120 NULL, /* PARTIAL is handled specially */
1121 "not used - internal error",
1122 "internal error - pattern overwritten?",
1123 "bad count value",
1124 "item unsupported for DFA matching",
1125 "backreference condition or recursion test not supported for DFA matching",
1126 "match limit not supported for DFA matching",
1127 "workspace size exceeded in DFA matching",
1128 "too much recursion for DFA matching",
1129 "recursion limit exceeded",
1130 "not used - internal error",
1131 "invalid combination of newline options",
1132 "bad offset value",
1133 NULL, /* SHORTUTF8/16 is handled specially */
1134 "nested recursion at the same subject position",
1135 "JIT stack limit reached",
1136 "pattern compiled in wrong mode: 8-bit/16-bit error",
1137 "pattern compiled with other endianness",
1138 "invalid data in workspace for DFA restart",
1139 "bad JIT option",
1140 "bad length"
1141 };
1142
1143
1144 /*************************************************
1145 * Alternate character tables *
1146 *************************************************/
1147
1148 /* By default, the "tables" pointer when calling PCRE is set to NULL, thereby
1149 using the default tables of the library. However, the T option can be used to
1150 select alternate sets of tables, for different kinds of testing. Note also that
1151 the L (locale) option also adjusts the tables. */
1152
1153 /* This is the set of tables distributed as default with PCRE. It recognizes
1154 only ASCII characters. */
1155
1156 static const pcre_uint8 tables0[] = {
1157
1158 /* This table is a lower casing table. */
1159
1160 0, 1, 2, 3, 4, 5, 6, 7,
1161 8, 9, 10, 11, 12, 13, 14, 15,
1162 16, 17, 18, 19, 20, 21, 22, 23,
1163 24, 25, 26, 27, 28, 29, 30, 31,
1164 32, 33, 34, 35, 36, 37, 38, 39,
1165 40, 41, 42, 43, 44, 45, 46, 47,
1166 48, 49, 50, 51, 52, 53, 54, 55,
1167 56, 57, 58, 59, 60, 61, 62, 63,
1168 64, 97, 98, 99,100,101,102,103,
1169 104,105,106,107,108,109,110,111,
1170 112,113,114,115,116,117,118,119,
1171 120,121,122, 91, 92, 93, 94, 95,
1172 96, 97, 98, 99,100,101,102,103,
1173 104,105,106,107,108,109,110,111,
1174 112,113,114,115,116,117,118,119,
1175 120,121,122,123,124,125,126,127,
1176 128,129,130,131,132,133,134,135,
1177 136,137,138,139,140,141,142,143,
1178 144,145,146,147,148,149,150,151,
1179 152,153,154,155,156,157,158,159,
1180 160,161,162,163,164,165,166,167,
1181 168,169,170,171,172,173,174,175,
1182 176,177,178,179,180,181,182,183,
1183 184,185,186,187,188,189,190,191,
1184 192,193,194,195,196,197,198,199,
1185 200,201,202,203,204,205,206,207,
1186 208,209,210,211,212,213,214,215,
1187 216,217,218,219,220,221,222,223,
1188 224,225,226,227,228,229,230,231,
1189 232,233,234,235,236,237,238,239,
1190 240,241,242,243,244,245,246,247,
1191 248,249,250,251,252,253,254,255,
1192
1193 /* This table is a case flipping table. */
1194
1195 0, 1, 2, 3, 4, 5, 6, 7,
1196 8, 9, 10, 11, 12, 13, 14, 15,
1197 16, 17, 18, 19, 20, 21, 22, 23,
1198 24, 25, 26, 27, 28, 29, 30, 31,
1199 32, 33, 34, 35, 36, 37, 38, 39,
1200 40, 41, 42, 43, 44, 45, 46, 47,
1201 48, 49, 50, 51, 52, 53, 54, 55,
1202 56, 57, 58, 59, 60, 61, 62, 63,
1203 64, 97, 98, 99,100,101,102,103,
1204 104,105,106,107,108,109,110,111,
1205 112,113,114,115,116,117,118,119,
1206 120,121,122, 91, 92, 93, 94, 95,
1207 96, 65, 66, 67, 68, 69, 70, 71,
1208 72, 73, 74, 75, 76, 77, 78, 79,
1209 80, 81, 82, 83, 84, 85, 86, 87,
1210 88, 89, 90,123,124,125,126,127,
1211 128,129,130,131,132,133,134,135,
1212 136,137,138,139,140,141,142,143,
1213 144,145,146,147,148,149,150,151,
1214 152,153,154,155,156,157,158,159,
1215 160,161,162,163,164,165,166,167,
1216 168,169,170,171,172,173,174,175,
1217 176,177,178,179,180,181,182,183,
1218 184,185,186,187,188,189,190,191,
1219 192,193,194,195,196,197,198,199,
1220 200,201,202,203,204,205,206,207,
1221 208,209,210,211,212,213,214,215,
1222 216,217,218,219,220,221,222,223,
1223 224,225,226,227,228,229,230,231,
1224 232,233,234,235,236,237,238,239,
1225 240,241,242,243,244,245,246,247,
1226 248,249,250,251,252,253,254,255,
1227
1228 /* This table contains bit maps for various character classes. Each map is 32
1229 bytes long and the bits run from the least significant end of each byte. The
1230 classes that have their own maps are: space, xdigit, digit, upper, lower, word,
1231 graph, print, punct, and cntrl. Other classes are built from combinations. */
1232
1233 0x00,0x3e,0x00,0x00,0x01,0x00,0x00,0x00,
1234 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1235 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1236 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1237
1238 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03,
1239 0x7e,0x00,0x00,0x00,0x7e,0x00,0x00,0x00,
1240 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1241 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1242
1243 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03,
1244 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1245 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1246 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1247
1248 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1249 0xfe,0xff,0xff,0x07,0x00,0x00,0x00,0x00,
1250 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1251 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1252
1253 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1254 0x00,0x00,0x00,0x00,0xfe,0xff,0xff,0x07,
1255 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1256 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1257
1258 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03,
1259 0xfe,0xff,0xff,0x87,0xfe,0xff,0xff,0x07,
1260 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1261 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1262
1263 0x00,0x00,0x00,0x00,0xfe,0xff,0xff,0xff,
1264 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
1265 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1266 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1267
1268 0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
1269 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
1270 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1271 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1272
1273 0x00,0x00,0x00,0x00,0xfe,0xff,0x00,0xfc,
1274 0x01,0x00,0x00,0xf8,0x01,0x00,0x00,0x78,
1275 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1276 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1277
1278 0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
1279 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,
1280 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1281 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1282
1283 /* This table identifies various classes of character by individual bits:
1284 0x01 white space character
1285 0x02 letter
1286 0x04 decimal digit
1287 0x08 hexadecimal digit
1288 0x10 alphanumeric or '_'
1289 0x80 regular expression metacharacter or binary zero
1290 */
1291
1292 0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 0- 7 */
1293 0x00,0x01,0x01,0x00,0x01,0x01,0x00,0x00, /* 8- 15 */
1294 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 16- 23 */
1295 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 24- 31 */
1296 0x01,0x00,0x00,0x00,0x80,0x00,0x00,0x00, /* - ' */
1297 0x80,0x80,0x80,0x80,0x00,0x00,0x80,0x00, /* ( - / */
1298 0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c, /* 0 - 7 */
1299 0x1c,0x1c,0x00,0x00,0x00,0x00,0x00,0x80, /* 8 - ? */
1300 0x00,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x12, /* @ - G */
1301 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* H - O */
1302 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* P - W */
1303 0x12,0x12,0x12,0x80,0x80,0x00,0x80,0x10, /* X - _ */
1304 0x00,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x12, /* ` - g */
1305 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* h - o */
1306 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* p - w */
1307 0x12,0x12,0x12,0x80,0x80,0x00,0x00,0x00, /* x -127 */
1308 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 128-135 */
1309 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 136-143 */
1310 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 144-151 */
1311 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 152-159 */
1312 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 160-167 */
1313 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 168-175 */
1314 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 176-183 */
1315 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 184-191 */
1316 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 192-199 */
1317 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 200-207 */
1318 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 208-215 */
1319 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 216-223 */
1320 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 224-231 */
1321 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 232-239 */
1322 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 240-247 */
1323 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/* 248-255 */
1324
1325 /* This is a set of tables that came orginally from a Windows user. It seems to
1326 be at least an approximation of ISO 8859. In particular, there are characters
1327 greater than 128 that are marked as spaces, letters, etc. */
1328
1329 static const pcre_uint8 tables1[] = {
1330 0,1,2,3,4,5,6,7,
1331 8,9,10,11,12,13,14,15,
1332 16,17,18,19,20,21,22,23,
1333 24,25,26,27,28,29,30,31,
1334 32,33,34,35,36,37,38,39,
1335 40,41,42,43,44,45,46,47,
1336 48,49,50,51,52,53,54,55,
1337 56,57,58,59,60,61,62,63,
1338 64,97,98,99,100,101,102,103,
1339 104,105,106,107,108,109,110,111,
1340 112,113,114,115,116,117,118,119,
1341 120,121,122,91,92,93,94,95,
1342 96,97,98,99,100,101,102,103,
1343 104,105,106,107,108,109,110,111,
1344 112,113,114,115,116,117,118,119,
1345 120,121,122,123,124,125,126,127,
1346 128,129,130,131,132,133,134,135,
1347 136,137,138,139,140,141,142,143,
1348 144,145,146,147,148,149,150,151,
1349 152,153,154,155,156,157,158,159,
1350 160,161,162,163,164,165,166,167,
1351 168,169,170,171,172,173,174,175,
1352 176,177,178,179,180,181,182,183,
1353 184,185,186,187,188,189,190,191,
1354 224,225,226,227,228,229,230,231,
1355 232,233,234,235,236,237,238,239,
1356 240,241,242,243,244,245,246,215,
1357 248,249,250,251,252,253,254,223,
1358 224,225,226,227,228,229,230,231,
1359 232,233,234,235,236,237,238,239,
1360 240,241,242,243,244,245,246,247,
1361 248,249,250,251,252,253,254,255,
1362 0,1,2,3,4,5,6,7,
1363 8,9,10,11,12,13,14,15,
1364 16,17,18,19,20,21,22,23,
1365 24,25,26,27,28,29,30,31,
1366 32,33,34,35,36,37,38,39,
1367 40,41,42,43,44,45,46,47,
1368 48,49,50,51,52,53,54,55,
1369 56,57,58,59,60,61,62,63,
1370 64,97,98,99,100,101,102,103,
1371 104,105,106,107,108,109,110,111,
1372 112,113,114,115,116,117,118,119,
1373 120,121,122,91,92,93,94,95,
1374 96,65,66,67,68,69,70,71,
1375 72,73,74,75,76,77,78,79,
1376 80,81,82,83,84,85,86,87,
1377 88,89,90,123,124,125,126,127,
1378 128,129,130,131,132,133,134,135,
1379 136,137,138,139,140,141,142,143,
1380 144,145,146,147,148,149,150,151,
1381 152,153,154,155,156,157,158,159,
1382 160,161,162,163,164,165,166,167,
1383 168,169,170,171,172,173,174,175,
1384 176,177,178,179,180,181,182,183,
1385 184,185,186,187,188,189,190,191,
1386 224,225,226,227,228,229,230,231,
1387 232,233,234,235,236,237,238,239,
1388 240,241,242,243,244,245,246,215,
1389 248,249,250,251,252,253,254,223,
1390 192,193,194,195,196,197,198,199,
1391 200,201,202,203,204,205,206,207,
1392 208,209,210,211,212,213,214,247,
1393 216,217,218,219,220,221,222,255,
1394 0,62,0,0,1,0,0,0,
1395 0,0,0,0,0,0,0,0,
1396 32,0,0,0,1,0,0,0,
1397 0,0,0,0,0,0,0,0,
1398 0,0,0,0,0,0,255,3,
1399 126,0,0,0,126,0,0,0,
1400 0,0,0,0,0,0,0,0,
1401 0,0,0,0,0,0,0,0,
1402 0,0,0,0,0,0,255,3,
1403 0,0,0,0,0,0,0,0,
1404 0,0,0,0,0,0,12,2,
1405 0,0,0,0,0,0,0,0,
1406 0,0,0,0,0,0,0,0,
1407 254,255,255,7,0,0,0,0,
1408 0,0,0,0,0,0,0,0,
1409 255,255,127,127,0,0,0,0,
1410 0,0,0,0,0,0,0,0,
1411 0,0,0,0,254,255,255,7,
1412 0,0,0,0,0,4,32,4,
1413 0,0,0,128,255,255,127,255,
1414 0,0,0,0,0,0,255,3,
1415 254,255,255,135,254,255,255,7,
1416 0,0,0,0,0,4,44,6,
1417 255,255,127,255,255,255,127,255,
1418 0,0,0,0,254,255,255,255,
1419 255,255,255,255,255,255,255,127,
1420 0,0,0,0,254,255,255,255,
1421 255,255,255,255,255,255,255,255,
1422 0,2,0,0,255,255,255,255,
1423 255,255,255,255,255,255,255,127,
1424 0,0,0,0,255,255,255,255,
1425 255,255,255,255,255,255,255,255,
1426 0,0,0,0,254,255,0,252,
1427 1,0,0,248,1,0,0,120,
1428 0,0,0,0,254,255,255,255,
1429 0,0,128,0,0,0,128,0,
1430 255,255,255,255,0,0,0,0,
1431 0,0,0,0,0,0,0,128,
1432 255,255,255,255,0,0,0,0,
1433 0,0,0,0,0,0,0,0,
1434 128,0,0,0,0,0,0,0,
1435 0,1,1,0,1,1,0,0,
1436 0,0,0,0,0,0,0,0,
1437 0,0,0,0,0,0,0,0,
1438 1,0,0,0,128,0,0,0,
1439 128,128,128,128,0,0,128,0,
1440 28,28,28,28,28,28,28,28,
1441 28,28,0,0,0,0,0,128,
1442 0,26,26,26,26,26,26,18,
1443 18,18,18,18,18,18,18,18,
1444 18,18,18,18,18,18,18,18,
1445 18,18,18,128,128,0,128,16,
1446 0,26,26,26,26,26,26,18,
1447 18,18,18,18,18,18,18,18,
1448 18,18,18,18,18,18,18,18,
1449 18,18,18,128,128,0,0,0,
1450 0,0,0,0,0,1,0,0,
1451 0,0,0,0,0,0,0,0,
1452 0,0,0,0,0,0,0,0,
1453 0,0,0,0,0,0,0,0,
1454 1,0,0,0,0,0,0,0,
1455 0,0,18,0,0,0,0,0,
1456 0,0,20,20,0,18,0,0,
1457 0,20,18,0,0,0,0,0,
1458 18,18,18,18,18,18,18,18,
1459 18,18,18,18,18,18,18,18,
1460 18,18,18,18,18,18,18,0,
1461 18,18,18,18,18,18,18,18,
1462 18,18,18,18,18,18,18,18,
1463 18,18,18,18,18,18,18,18,
1464 18,18,18,18,18,18,18,0,
1465 18,18,18,18,18,18,18,18
1466 };
1467
1468
1469
1470
1471 #ifndef HAVE_STRERROR
1472 /*************************************************
1473 * Provide strerror() for non-ANSI libraries *
1474 *************************************************/
1475
1476 /* Some old-fashioned systems still around (e.g. SunOS4) don't have strerror()
1477 in their libraries, but can provide the same facility by this simple
1478 alternative function. */
1479
1480 extern int sys_nerr;
1481 extern char *sys_errlist[];
1482
1483 char *
1484 strerror(int n)
1485 {
1486 if (n < 0 || n >= sys_nerr) return "unknown error number";
1487 return sys_errlist[n];
1488 }
1489 #endif /* HAVE_STRERROR */
1490
1491
1492
1493 /*************************************************
1494 * Print newline configuration *
1495 *************************************************/
1496
1497 /*
1498 Arguments:
1499 rc the return code from PCRE_CONFIG_NEWLINE
1500 isc TRUE if called from "-C newline"
1501 Returns: nothing
1502 */
1503
1504 static void
1505 print_newline_config(int rc, BOOL isc)
1506 {
1507 const char *s = NULL;
1508 if (!isc) printf(" Newline sequence is ");
1509 switch(rc)
1510 {
1511 case CHAR_CR: s = "CR"; break;
1512 case CHAR_LF: s = "LF"; break;
1513 case (CHAR_CR<<8 | CHAR_LF): s = "CRLF"; break;
1514 case -1: s = "ANY"; break;
1515 case -2: s = "ANYCRLF"; break;
1516
1517 default:
1518 printf("a non-standard value: 0x%04x\n", rc);
1519 return;
1520 }
1521
1522 printf("%s\n", s);
1523 }
1524
1525
1526
1527 /*************************************************
1528 * JIT memory callback *
1529 *************************************************/
1530
1531 static pcre_jit_stack* jit_callback(void *arg)
1532 {
1533 jit_was_used = TRUE;
1534 return (pcre_jit_stack *)arg;
1535 }
1536
1537
1538 #if !defined NOUTF || defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32
1539 /*************************************************
1540 * Convert UTF-8 string to value *
1541 *************************************************/
1542
1543 /* This function takes one or more bytes that represents a UTF-8 character,
1544 and returns the value of the character.
1545
1546 Argument:
1547 utf8bytes a pointer to the byte vector
1548 vptr a pointer to an int to receive the value
1549
1550 Returns: > 0 => the number of bytes consumed
1551 -6 to 0 => malformed UTF-8 character at offset = (-return)
1552 */
1553
1554 static int
1555 utf82ord(pcre_uint8 *utf8bytes, pcre_uint32 *vptr)
1556 {
1557 pcre_uint32 c = *utf8bytes++;
1558 pcre_uint32 d = c;
1559 int i, j, s;
1560
1561 for (i = -1; i < 6; i++) /* i is number of additional bytes */
1562 {
1563 if ((d & 0x80) == 0) break;
1564 d <<= 1;
1565 }
1566
1567 if (i == -1) { *vptr = c; return 1; } /* ascii character */
1568 if (i == 0 || i == 6) return 0; /* invalid UTF-8 */
1569
1570 /* i now has a value in the range 1-5 */
1571
1572 s = 6*i;
1573 d = (c & utf8_table3[i]) << s;
1574
1575 for (j = 0; j < i; j++)
1576 {
1577 c = *utf8bytes++;
1578 if ((c & 0xc0) != 0x80) return -(j+1);
1579 s -= 6;
1580 d |= (c & 0x3f) << s;
1581 }
1582
1583 /* Check that encoding was the correct unique one */
1584
1585 for (j = 0; j < utf8_table1_size; j++)
1586 if (d <= (pcre_uint32)utf8_table1[j]) break;
1587 if (j != i) return -(i+1);
1588
1589 /* Valid value */
1590
1591 *vptr = d;
1592 return i+1;
1593 }
1594 #endif /* NOUTF || SUPPORT_PCRE16 */
1595
1596
1597
1598 #if defined SUPPORT_PCRE8 && !defined NOUTF
1599 /*************************************************
1600 * Convert character value to UTF-8 *
1601 *************************************************/
1602
1603 /* This function takes an integer value in the range 0 - 0x7fffffff
1604 and encodes it as a UTF-8 character in 0 to 6 bytes.
1605
1606 Arguments:
1607 cvalue the character value
1608 utf8bytes pointer to buffer for result - at least 6 bytes long
1609
1610 Returns: number of characters placed in the buffer
1611 */
1612
1613 static int
1614 ord2utf8(pcre_uint32 cvalue, pcre_uint8 *utf8bytes)
1615 {
1616 register int i, j;
1617 if (cvalue > 0x7fffffffu)
1618 return -1;
1619 for (i = 0; i < utf8_table1_size; i++)
1620 if (cvalue <= (pcre_uint32)utf8_table1[i]) break;
1621 utf8bytes += i;
1622 for (j = i; j > 0; j--)
1623 {
1624 *utf8bytes-- = 0x80 | (cvalue & 0x3f);
1625 cvalue >>= 6;
1626 }
1627 *utf8bytes = utf8_table2[i] | cvalue;
1628 return i + 1;
1629 }
1630 #endif
1631
1632
1633 #ifdef SUPPORT_PCRE16
1634 /*************************************************
1635 * Convert a string to 16-bit *
1636 *************************************************/
1637
1638 /* In non-UTF mode, the space needed for a 16-bit string is exactly double the
1639 8-bit size. For a UTF-8 string, the size needed for UTF-16 is no more than
1640 double, because up to 0xffff uses no more than 3 bytes in UTF-8 but possibly 4
1641 in UTF-16. Higher values use 4 bytes in UTF-8 and up to 4 bytes in UTF-16. The
1642 result is always left in buffer16.
1643
1644 Note that this function does not object to surrogate values. This is
1645 deliberate; it makes it possible to construct UTF-16 strings that are invalid,
1646 for the purpose of testing that they are correctly faulted.
1647
1648 Patterns to be converted are either plain ASCII or UTF-8; data lines are always
1649 in UTF-8 so that values greater than 255 can be handled.
1650
1651 Arguments:
1652 data TRUE if converting a data line; FALSE for a regex
1653 p points to a byte string
1654 utf true if UTF-8 (to be converted to UTF-16)
1655 len number of bytes in the string (excluding trailing zero)
1656
1657 Returns: number of 16-bit data items used (excluding trailing zero)
1658 OR -1 if a UTF-8 string is malformed
1659 OR -2 if a value > 0x10ffff is encountered
1660 OR -3 if a value > 0xffff is encountered when not in UTF mode
1661 */
1662
1663 static int
1664 to16(int data, pcre_uint8 *p, int utf, int len)
1665 {
1666 pcre_uint16 *pp;
1667
1668 if (buffer16_size < 2*len + 2)
1669 {
1670 if (buffer16 != NULL) free(buffer16);
1671 buffer16_size = 2*len + 2;
1672 buffer16 = (pcre_uint16 *)malloc(buffer16_size);
1673 if (buffer16 == NULL)
1674 {
1675 fprintf(stderr, "pcretest: malloc(%d) failed for buffer16\n", buffer16_size);
1676 exit(1);
1677 }
1678 }
1679
1680 pp = buffer16;
1681
1682 if (!utf && !data)
1683 {
1684 while (len-- > 0) *pp++ = *p++;
1685 }
1686
1687 else
1688 {
1689 pcre_uint32 c = 0;
1690 while (len > 0)
1691 {
1692 int chlen = utf82ord(p, &c);
1693 if (chlen <= 0) return -1;
1694 if (c > 0x10ffff) return -2;
1695 p += chlen;
1696 len -= chlen;
1697 if (c < 0x10000) *pp++ = c; else
1698 {
1699 if (!utf) return -3;
1700 c -= 0x10000;
1701 *pp++ = 0xD800 | (c >> 10);
1702 *pp++ = 0xDC00 | (c & 0x3ff);
1703 }
1704 }
1705 }
1706
1707 *pp = 0;
1708 return pp - buffer16;
1709 }
1710 #endif
1711
1712 #ifdef SUPPORT_PCRE32
1713 /*************************************************
1714 * Convert a string to 32-bit *
1715 *************************************************/
1716
1717 /* In non-UTF mode, the space needed for a 32-bit string is exactly four times the
1718 8-bit size. For a UTF-8 string, the size needed for UTF-32 is no more than four
1719 times, because up to 0xffff uses no more than 3 bytes in UTF-8 but possibly 4
1720 in UTF-32. Higher values use 4 bytes in UTF-8 and up to 4 bytes in UTF-32. The
1721 result is always left in buffer32.
1722
1723 Note that this function does not object to surrogate values. This is
1724 deliberate; it makes it possible to construct UTF-32 strings that are invalid,
1725 for the purpose of testing that they are correctly faulted.
1726
1727 Patterns to be converted are either plain ASCII or UTF-8; data lines are always
1728 in UTF-8 so that values greater than 255 can be handled.
1729
1730 Arguments:
1731 data TRUE if converting a data line; FALSE for a regex
1732 p points to a byte string
1733 utf true if UTF-8 (to be converted to UTF-32)
1734 len number of bytes in the string (excluding trailing zero)
1735
1736 Returns: number of 32-bit data items used (excluding trailing zero)
1737 OR -1 if a UTF-8 string is malformed
1738 OR -2 if a value > 0x10ffff is encountered
1739 OR -3 if an ill-formed value is encountered (i.e. a surrogate)
1740 */
1741
1742 static int
1743 to32(int data, pcre_uint8 *p, int utf, int len)
1744 {
1745 pcre_uint32 *pp;
1746
1747 if (buffer32_size < 4*len + 4)
1748 {
1749 if (buffer32 != NULL) free(buffer32);
1750 buffer32_size = 4*len + 4;
1751 buffer32 = (pcre_uint32 *)malloc(buffer32_size);
1752 if (buffer32 == NULL)
1753 {
1754 fprintf(stderr, "pcretest: malloc(%d) failed for buffer32\n", buffer32_size);
1755 exit(1);
1756 }
1757 }
1758
1759 pp = buffer32;
1760
1761 if (!utf && !data)
1762 {
1763 while (len-- > 0) *pp++ = *p++;
1764 }
1765
1766 else
1767 {
1768 pcre_uint32 c = 0;
1769 while (len > 0)
1770 {
1771 int chlen = utf82ord(p, &c);
1772 if (chlen <= 0) return -1;
1773 if (utf)
1774 {
1775 if (c > 0x10ffff) return -2;
1776 if (!data && (c & 0xfffff800u) == 0xd800u) return -3;
1777 }
1778
1779 p += chlen;
1780 len -= chlen;
1781 *pp++ = c;
1782 }
1783 }
1784
1785 *pp = 0;
1786 return pp - buffer32;
1787 }
1788
1789 /* Check that a 32-bit character string is valid UTF-32.
1790
1791 Arguments:
1792 string points to the string
1793 length length of string, or -1 if the string is zero-terminated
1794
1795 Returns: TRUE if the string is a valid UTF-32 string
1796 FALSE otherwise
1797 */
1798
1799 #ifdef NEVER
1800
1801 #ifdef SUPPORT_UTF
1802 static BOOL
1803 valid_utf32(pcre_uint32 *string, int length)
1804 {
1805 register pcre_uint32 *p;
1806 register pcre_uint32 c;
1807
1808 for (p = string; length-- > 0; p++)
1809 {
1810 c = *p;
1811
1812 if (c > 0x10ffffu)
1813 return FALSE;
1814
1815 /* A surrogate */
1816 if ((c & 0xfffff800u) == 0xd800u)
1817 return FALSE;
1818
1819 /* Non-character */
1820 if ((c & 0xfffeu) == 0xfffeu || (c >= 0xfdd0u && c <= 0xfdefu))
1821 return FALSE;
1822 }
1823
1824 return TRUE;
1825 }
1826 #endif /* SUPPORT_UTF */
1827
1828 #endif /* NEVER */
1829
1830
1831 #endif
1832
1833 /*************************************************
1834 * Read or extend an input line *
1835 *************************************************/
1836
1837 /* Input lines are read into buffer, but both patterns and data lines can be
1838 continued over multiple input lines. In addition, if the buffer fills up, we
1839 want to automatically expand it so as to be able to handle extremely large
1840 lines that are needed for certain stress tests. When the input buffer is
1841 expanded, the other two buffers must also be expanded likewise, and the
1842 contents of pbuffer, which are a copy of the input for callouts, must be
1843 preserved (for when expansion happens for a data line). This is not the most
1844 optimal way of handling this, but hey, this is just a test program!
1845
1846 Arguments:
1847 f the file to read
1848 start where in buffer to start (this *must* be within buffer)
1849 prompt for stdin or readline()
1850
1851 Returns: pointer to the start of new data
1852 could be a copy of start, or could be moved
1853 NULL if no data read and EOF reached
1854 */
1855
1856 static pcre_uint8 *
1857 extend_inputline(FILE *f, pcre_uint8 *start, const char *prompt)
1858 {
1859 pcre_uint8 *here = start;
1860
1861 for (;;)
1862 {
1863 size_t rlen = (size_t)(buffer_size - (here - buffer));
1864
1865 if (rlen > 1000)
1866 {
1867 int dlen;
1868
1869 /* If libreadline or libedit support is required, use readline() to read a
1870 line if the input is a terminal. Note that readline() removes the trailing
1871 newline, so we must put it back again, to be compatible with fgets(). */
1872
1873 #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
1874 if (isatty(fileno(f)))
1875 {
1876 size_t len;
1877 char *s = readline(prompt);
1878 if (s == NULL) return (here == start)? NULL : start;
1879 len = strlen(s);
1880 if (len > 0) add_history(s);
1881 if (len > rlen - 1) len = rlen - 1;
1882 memcpy(here, s, len);
1883 here[len] = '\n';
1884 here[len+1] = 0;
1885 free(s);
1886 }
1887 else
1888 #endif
1889
1890 /* Read the next line by normal means, prompting if the file is stdin. */
1891
1892 {
1893 if (f == stdin) printf("%s", prompt);
1894 if (fgets((char *)here, rlen, f) == NULL)
1895 return (here == start)? NULL : start;
1896 }
1897
1898 dlen = (int)strlen((char *)here);
1899 if (dlen > 0 && here[dlen - 1] == '\n') return start;
1900 here += dlen;
1901 }
1902
1903 else
1904 {
1905 int new_buffer_size = 2*buffer_size;
1906 pcre_uint8 *new_buffer = (pcre_uint8 *)malloc(new_buffer_size);
1907 pcre_uint8 *new_pbuffer = (pcre_uint8 *)malloc(new_buffer_size);
1908
1909 if (new_buffer == NULL || new_pbuffer == NULL)
1910 {
1911 fprintf(stderr, "pcretest: malloc(%d) failed\n", new_buffer_size);
1912 exit(1);
1913 }
1914
1915 memcpy(new_buffer, buffer, buffer_size);
1916 memcpy(new_pbuffer, pbuffer, buffer_size);
1917
1918 buffer_size = new_buffer_size;
1919
1920 start = new_buffer + (start - buffer);
1921 here = new_buffer + (here - buffer);
1922
1923 free(buffer);
1924 free(pbuffer);
1925
1926 buffer = new_buffer;
1927 pbuffer = new_pbuffer;
1928 }
1929 }
1930
1931 return NULL; /* Control never gets here */
1932 }
1933
1934
1935
1936 /*************************************************
1937 * Read number from string *
1938 *************************************************/
1939
1940 /* We don't use strtoul() because SunOS4 doesn't have it. Rather than mess
1941 around with conditional compilation, just do the job by hand. It is only used
1942 for unpicking arguments, so just keep it simple.
1943
1944 Arguments:
1945 str string to be converted
1946 endptr where to put the end pointer
1947
1948 Returns: the unsigned long
1949 */
1950
1951 static int
1952 get_value(pcre_uint8 *str, pcre_uint8 **endptr)
1953 {
1954 int result = 0;
1955 while(*str != 0 && isspace(*str)) str++;
1956 while (isdigit(*str)) result = result * 10 + (int)(*str++ - '0');
1957 *endptr = str;
1958 return(result);
1959 }
1960
1961
1962
1963 /*************************************************
1964 * Print one character *
1965 *************************************************/
1966
1967 /* Print a single character either literally, or as a hex escape. */
1968
1969 static int pchar(pcre_uint32 c, FILE *f)
1970 {
1971 int n = 0;
1972 if (PRINTOK(c))
1973 {
1974 if (f != NULL) fprintf(f, "%c", c);
1975 return 1;
1976 }
1977
1978 if (c < 0x100)
1979 {
1980 if (use_utf)
1981 {
1982 if (f != NULL) fprintf(f, "\\x{%02x}", c);
1983 return 6;
1984 }
1985 else
1986 {
1987 if (f != NULL) fprintf(f, "\\x%02x", c);
1988 return 4;
1989 }
1990 }
1991
1992 if (f != NULL) n = fprintf(f, "\\x{%02x}", c);
1993 return n >= 0 ? n : 0;
1994 }
1995
1996
1997
1998 #ifdef SUPPORT_PCRE8
1999 /*************************************************
2000 * Print 8-bit character string *
2001 *************************************************/
2002
2003 /* Must handle UTF-8 strings in utf8 mode. Yields number of characters printed.
2004 If handed a NULL file, just counts chars without printing. */
2005
2006 static int pchars(pcre_uint8 *p, int length, FILE *f)
2007 {
2008 pcre_uint32 c = 0;
2009 int yield = 0;
2010
2011 if (length < 0)
2012 length = strlen((char *)p);
2013
2014 while (length-- > 0)
2015 {
2016 #if !defined NOUTF
2017 if (use_utf)
2018 {
2019 int rc = utf82ord(p, &c);
2020 if (rc > 0 && rc <= length + 1) /* Mustn't run over the end */
2021 {
2022 length -= rc - 1;
2023 p += rc;
2024 yield += pchar(c, f);
2025 continue;
2026 }
2027 }
2028 #endif
2029 c = *p++;
2030 yield += pchar(c, f);
2031 }
2032
2033 return yield;
2034 }
2035 #endif
2036
2037
2038
2039 #ifdef SUPPORT_PCRE16
2040 /*************************************************
2041 * Find length of 0-terminated 16-bit string *
2042 *************************************************/
2043
2044 static int strlen16(PCRE_SPTR16 p)
2045 {
2046 int len = 0;
2047 while (*p++ != 0) len++;
2048 return len;
2049 }
2050 #endif /* SUPPORT_PCRE16 */
2051
2052
2053
2054 #ifdef SUPPORT_PCRE32
2055 /*************************************************
2056 * Find length of 0-terminated 32-bit string *
2057 *************************************************/
2058
2059 static int strlen32(PCRE_SPTR32 p)
2060 {
2061 int len = 0;
2062 while (*p++ != 0) len++;
2063 return len;
2064 }
2065 #endif /* SUPPORT_PCRE32 */
2066
2067
2068
2069 #ifdef SUPPORT_PCRE16
2070 /*************************************************
2071 * Print 16-bit character string *
2072 *************************************************/
2073
2074 /* Must handle UTF-16 strings in utf mode. Yields number of characters printed.
2075 If handed a NULL file, just counts chars without printing. */
2076
2077 static int pchars16(PCRE_SPTR16 p, int length, FILE *f)
2078 {
2079 int yield = 0;
2080
2081 if (length < 0)
2082 length = strlen16(p);
2083
2084 while (length-- > 0)
2085 {
2086 pcre_uint32 c = *p++ & 0xffff;
2087 #if !defined NOUTF
2088 if (use_utf && c >= 0xD800 && c < 0xDC00 && length > 0)
2089 {
2090 int d = *p & 0xffff;
2091 if (d >= 0xDC00 && d < 0xDFFF)
2092 {
2093 c = ((c & 0x3ff) << 10) + (d & 0x3ff) + 0x10000;
2094 length--;
2095 p++;
2096 }
2097 }
2098 #endif
2099 yield += pchar(c, f);
2100 }
2101
2102 return yield;
2103 }
2104 #endif /* SUPPORT_PCRE16 */
2105
2106
2107
2108 #ifdef SUPPORT_PCRE32
2109 /*************************************************
2110 * Print 32-bit character string *
2111 *************************************************/
2112
2113 /* Must handle UTF-32 strings in utf mode. Yields number of characters printed.
2114 If handed a NULL file, just counts chars without printing. */
2115
2116 static int pchars32(PCRE_SPTR32 p, int length, BOOL utf, FILE *f)
2117 {
2118 int yield = 0;
2119
2120 (void)(utf); /* Avoid compiler warning */
2121
2122 if (length < 0)
2123 length = strlen32(p);
2124
2125 while (length-- > 0)
2126 {
2127 pcre_uint32 c = *p++;
2128 yield += pchar(c, f);
2129 }
2130
2131 return yield;
2132 }
2133 #endif /* SUPPORT_PCRE32 */
2134
2135
2136
2137 #ifdef SUPPORT_PCRE8
2138 /*************************************************
2139 * Read a capture name (8-bit) and check it *
2140 *************************************************/
2141
2142 static pcre_uint8 *
2143 read_capture_name8(pcre_uint8 *p, pcre_uint8 **pp, pcre *re)
2144 {
2145 pcre_uint8 *npp = *pp;
2146 while (isalnum(*p)) *npp++ = *p++;
2147 *npp++ = 0;
2148 *npp = 0;
2149 if (pcre_get_stringnumber(re, (char *)(*pp)) < 0)
2150 {
2151 fprintf(outfile, "no parentheses with name \"");
2152 PCHARSV(*pp, 0, -1, outfile);
2153 fprintf(outfile, "\"\n");
2154 }
2155
2156 *pp = npp;
2157 return p;
2158 }
2159 #endif /* SUPPORT_PCRE8 */
2160
2161
2162
2163 #ifdef SUPPORT_PCRE16
2164 /*************************************************
2165 * Read a capture name (16-bit) and check it *
2166 *************************************************/
2167
2168 /* Note that the text being read is 8-bit. */
2169
2170 static pcre_uint8 *
2171 read_capture_name16(pcre_uint8 *p, pcre_uint16 **pp, pcre *re)
2172 {
2173 pcre_uint16 *npp = *pp;
2174 while (isalnum(*p)) *npp++ = *p++;
2175 *npp++ = 0;
2176 *npp = 0;
2177 if (pcre16_get_stringnumber((pcre16 *)re, (PCRE_SPTR16)(*pp)) < 0)
2178 {
2179 fprintf(outfile, "no parentheses with name \"");
2180 PCHARSV(*pp, 0, -1, outfile);
2181 fprintf(outfile, "\"\n");
2182 }
2183 *pp = npp;
2184 return p;
2185 }
2186 #endif /* SUPPORT_PCRE16 */
2187
2188
2189
2190 #ifdef SUPPORT_PCRE32
2191 /*************************************************
2192 * Read a capture name (32-bit) and check it *
2193 *************************************************/
2194
2195 /* Note that the text being read is 8-bit. */
2196
2197 static pcre_uint8 *
2198 read_capture_name32(pcre_uint8 *p, pcre_uint32 **pp, pcre *re)
2199 {
2200 pcre_uint32 *npp = *pp;
2201 while (isalnum(*p)) *npp++ = *p++;
2202 *npp++ = 0;
2203 *npp = 0;
2204 if (pcre32_get_stringnumber((pcre32 *)re, (PCRE_SPTR32)(*pp)) < 0)
2205 {
2206 fprintf(outfile, "no parentheses with name \"");
2207 PCHARSV(*pp, 0, -1, outfile);
2208 fprintf(outfile, "\"\n");
2209 }
2210 *pp = npp;
2211 return p;
2212 }
2213 #endif /* SUPPORT_PCRE32 */
2214
2215
2216
2217 /*************************************************
2218 * Callout function *
2219 *************************************************/
2220
2221 /* Called from PCRE as a result of the (?C) item. We print out where we are in
2222 the match. Yield zero unless more callouts than the fail count, or the callout
2223 data is not zero. */
2224
2225 static int callout(pcre_callout_block *cb)
2226 {
2227 FILE *f = (first_callout | callout_extra)? outfile : NULL;
2228 int i, pre_start, post_start, subject_length;
2229
2230 if (callout_extra)
2231 {
2232 fprintf(f, "Callout %d: last capture = %d\n",
2233 cb->callout_number, cb->capture_last);
2234
2235 for (i = 0; i < cb->capture_top * 2; i += 2)
2236 {
2237 if (cb->offset_vector[i] < 0)
2238 fprintf(f, "%2d: <unset>\n", i/2);
2239 else
2240 {
2241 fprintf(f, "%2d: ", i/2);
2242 PCHARSV(cb->subject, cb->offset_vector[i],
2243 cb->offset_vector[i+1] - cb->offset_vector[i], f);
2244 fprintf(f, "\n");
2245 }
2246 }
2247 }
2248
2249 /* Re-print the subject in canonical form, the first time or if giving full
2250 datails. On subsequent calls in the same match, we use pchars just to find the
2251 printed lengths of the substrings. */
2252
2253 if (f != NULL) fprintf(f, "--->");
2254
2255 PCHARS(pre_start, cb->subject, 0, cb->start_match, f);
2256 PCHARS(post_start, cb->subject, cb->start_match,
2257 cb->current_position - cb->start_match, f);
2258
2259 PCHARS(subject_length, cb->subject, 0, cb->subject_length, NULL);
2260
2261 PCHARSV(cb->subject, cb->current_position,
2262 cb->subject_length - cb->current_position, f);
2263
2264 if (f != NULL) fprintf(f, "\n");
2265
2266 /* Always print appropriate indicators, with callout number if not already
2267 shown. For automatic callouts, show the pattern offset. */
2268
2269 if (cb->callout_number == 255)
2270 {
2271 fprintf(outfile, "%+3d ", cb->pattern_position);
2272 if (cb->pattern_position > 99) fprintf(outfile, "\n ");
2273 }
2274 else
2275 {
2276 if (callout_extra) fprintf(outfile, " ");
2277 else fprintf(outfile, "%3d ", cb->callout_number);
2278 }
2279
2280 for (i = 0; i < pre_start; i++) fprintf(outfile, " ");
2281 fprintf(outfile, "^");
2282
2283 if (post_start > 0)
2284 {
2285 for (i = 0; i < post_start - 1; i++) fprintf(outfile, " ");
2286 fprintf(outfile, "^");
2287 }
2288
2289 for (i = 0; i < subject_length - pre_start - post_start + 4; i++)
2290 fprintf(outfile, " ");
2291
2292 fprintf(outfile, "%.*s", (cb->next_item_length == 0)? 1 : cb->next_item_length,
2293 pbuffer + cb->pattern_position);
2294
2295 fprintf(outfile, "\n");
2296 first_callout = 0;
2297
2298 if (cb->mark != last_callout_mark)
2299 {
2300 if (cb->mark == NULL)
2301 fprintf(outfile, "Latest Mark: <unset>\n");
2302 else
2303 {
2304 fprintf(outfile, "Latest Mark: ");
2305 PCHARSV(cb->mark, 0, -1, outfile);
2306 putc('\n', outfile);
2307 }
2308 last_callout_mark = cb->mark;
2309 }
2310
2311 if (cb->callout_data != NULL)
2312 {
2313 int callout_data = *((int *)(cb->callout_data));
2314 if (callout_data != 0)
2315 {
2316 fprintf(outfile, "Callout data = %d\n", callout_data);
2317 return callout_data;
2318 }
2319 }
2320
2321 return (cb->callout_number != callout_fail_id)? 0 :
2322 (++callout_count >= callout_fail_count)? 1 : 0;
2323 }
2324
2325
2326 /*************************************************
2327 * Local malloc functions *
2328 *************************************************/
2329
2330 /* Alternative malloc function, to test functionality and save the size of a
2331 compiled re, which is the first store request that pcre_compile() makes. The
2332 show_malloc variable is set only during matching. */
2333
2334 static void *new_malloc(size_t size)
2335 {
2336 void *block = malloc(size);
2337 gotten_store = size;
2338 if (first_gotten_store == 0) first_gotten_store = size;
2339 if (show_malloc)
2340 fprintf(outfile, "malloc %3d %p\n", (int)size, block);
2341 return block;
2342 }
2343
2344 static void new_free(void *block)
2345 {
2346 if (show_malloc)
2347 fprintf(outfile, "free %p\n", block);
2348 free(block);
2349 }
2350
2351 /* For recursion malloc/free, to test stacking calls */
2352
2353 static void *stack_malloc(size_t size)
2354 {
2355 void *block = malloc(size);
2356 if (show_malloc)
2357 fprintf(outfile, "stack_malloc %3d %p\n", (int)size, block);
2358 return block;
2359 }
2360
2361 static void stack_free(void *block)
2362 {
2363 if (show_malloc)
2364 fprintf(outfile, "stack_free %p\n", block);
2365 free(block);
2366 }
2367
2368
2369 /*************************************************
2370 * Call pcre_fullinfo() *
2371 *************************************************/
2372
2373 /* Get one piece of information from the pcre_fullinfo() function. When only
2374 one of 8-, 16- or 32-bit is supported, pcre_mode should always have the correct
2375 value, but the code is defensive.
2376
2377 Arguments:
2378 re compiled regex
2379 study study data
2380 option PCRE_INFO_xxx option
2381 ptr where to put the data
2382
2383 Returns: 0 when OK, < 0 on error
2384 */
2385
2386 static int
2387 new_info(pcre *re, pcre_extra *study, int option, void *ptr)
2388 {
2389 int rc;
2390
2391 if (pcre_mode == PCRE32_MODE)
2392 #ifdef SUPPORT_PCRE32
2393 rc = pcre32_fullinfo((pcre32 *)re, (pcre32_extra *)study, option, ptr);
2394 #else
2395 rc = PCRE_ERROR_BADMODE;
2396 #endif
2397 else if (pcre_mode == PCRE16_MODE)
2398 #ifdef SUPPORT_PCRE16
2399 rc = pcre16_fullinfo((pcre16 *)re, (pcre16_extra *)study, option, ptr);
2400 #else
2401 rc = PCRE_ERROR_BADMODE;
2402 #endif
2403 else
2404 #ifdef SUPPORT_PCRE8
2405 rc = pcre_fullinfo(re, study, option, ptr);
2406 #else
2407 rc = PCRE_ERROR_BADMODE;
2408 #endif
2409
2410 if (rc < 0)
2411 {
2412 fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
2413 pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "", option);
2414 if (rc == PCRE_ERROR_BADMODE)
2415 fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
2416 "%d-bit mode\n", 8 * CHAR_SIZE,
2417 8 * (REAL_PCRE_FLAGS(re) & PCRE_MODE_MASK));
2418 }
2419
2420 return rc;
2421 }
2422
2423
2424
2425 /*************************************************
2426 * Swap byte functions *
2427 *************************************************/
2428
2429 /* The following functions swap the bytes of a pcre_uint16 and pcre_uint32
2430 value, respectively.
2431
2432 Arguments:
2433 value any number
2434
2435 Returns: the byte swapped value
2436 */
2437
2438 static pcre_uint32
2439 swap_uint32(pcre_uint32 value)
2440 {
2441 return ((value & 0x000000ff) << 24) |
2442 ((value & 0x0000ff00) << 8) |
2443 ((value & 0x00ff0000) >> 8) |
2444 (value >> 24);
2445 }
2446
2447 static pcre_uint16
2448 swap_uint16(pcre_uint16 value)
2449 {
2450 return (value >> 8) | (value << 8);
2451 }
2452
2453
2454
2455 /*************************************************
2456 * Flip bytes in a compiled pattern *
2457 *************************************************/
2458
2459 /* This function is called if the 'F' option was present on a pattern that is
2460 to be written to a file. We flip the bytes of all the integer fields in the
2461 regex data block and the study block. In 16-bit mode this also flips relevant
2462 bytes in the pattern itself. This is to make it possible to test PCRE's
2463 ability to reload byte-flipped patterns, e.g. those compiled on a different
2464 architecture. */
2465
2466 #if defined SUPPORT_PCRE8 || defined SUPPORT_PCRE16
2467 static void
2468 regexflip8_or_16(pcre *ere, pcre_extra *extra)
2469 {
2470 real_pcre8_or_16 *re = (real_pcre8_or_16 *)ere;
2471 #ifdef SUPPORT_PCRE16
2472 int op;
2473 pcre_uint16 *ptr = (pcre_uint16 *)re + re->name_table_offset;
2474 int length = re->name_count * re->name_entry_size;
2475 #ifdef SUPPORT_UTF
2476 BOOL utf = (re->options & PCRE_UTF16) != 0;
2477 BOOL utf16_char = FALSE;
2478 #endif /* SUPPORT_UTF */
2479 #endif /* SUPPORT_PCRE16 */
2480
2481 /* Always flip the bytes in the main data block and study blocks. */
2482
2483 re->magic_number = REVERSED_MAGIC_NUMBER;
2484 re->size = swap_uint32(re->size);
2485 re->options = swap_uint32(re->options);
2486 re->flags = swap_uint16(re->flags);
2487 re->top_bracket = swap_uint16(re->top_bracket);
2488 re->top_backref = swap_uint16(re->top_backref);
2489 re->first_char = swap_uint16(re->first_char);
2490 re->req_char = swap_uint16(re->req_char);
2491 re->name_table_offset = swap_uint16(re->name_table_offset);
2492 re->name_entry_size = swap_uint16(re->name_entry_size);
2493 re->name_count = swap_uint16(re->name_count);
2494
2495 if (extra != NULL)
2496 {
2497 pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);
2498 rsd->size = swap_uint32(rsd->size);
2499 rsd->flags = swap_uint32(rsd->flags);
2500 rsd->minlength = swap_uint32(rsd->minlength);
2501 }
2502
2503 /* In 8-bit mode, that is all we need to do. In 16-bit mode we must swap bytes
2504 in the name table, if present, and then in the pattern itself. */
2505
2506 #ifdef SUPPORT_PCRE16
2507 if (pcre_mode != PCRE16_MODE) return;
2508
2509 while(TRUE)
2510 {
2511 /* Swap previous characters. */
2512 while (length-- > 0)
2513 {
2514 *ptr = swap_uint16(*ptr);
2515 ptr++;
2516 }
2517 #ifdef SUPPORT_UTF
2518 if (utf16_char)
2519 {
2520 if ((ptr[-1] & 0xfc00) == 0xd800)
2521 {
2522 /* We know that there is only one extra character in UTF-16. */
2523 *ptr = swap_uint16(*ptr);
2524 ptr++;
2525 }
2526 }
2527 utf16_char = FALSE;
2528 #endif /* SUPPORT_UTF */
2529
2530 /* Get next opcode. */
2531
2532 length = 0;
2533 op = *ptr;
2534 *ptr++ = swap_uint16(op);
2535
2536 switch (op)
2537 {
2538 case OP_END:
2539 return;
2540
2541 #ifdef SUPPORT_UTF
2542 case OP_CHAR:
2543 case OP_CHARI:
2544 case OP_NOT:
2545 case OP_NOTI:
2546 case OP_STAR:
2547 case OP_MINSTAR:
2548 case OP_PLUS:
2549 case OP_MINPLUS:
2550 case OP_QUERY:
2551 case OP_MINQUERY:
2552 case OP_UPTO:
2553 case OP_MINUPTO:
2554 case OP_EXACT:
2555 case OP_POSSTAR:
2556 case OP_POSPLUS:
2557 case OP_POSQUERY:
2558 case OP_POSUPTO:
2559 case OP_STARI:
2560 case OP_MINSTARI:
2561 case OP_PLUSI:
2562 case OP_MINPLUSI:
2563 case OP_QUERYI:
2564 case OP_MINQUERYI:
2565 case OP_UPTOI:
2566 case OP_MINUPTOI:
2567 case OP_EXACTI:
2568 case OP_POSSTARI:
2569 case OP_POSPLUSI:
2570 case OP_POSQUERYI:
2571 case OP_POSUPTOI:
2572 case OP_NOTSTAR:
2573 case OP_NOTMINSTAR:
2574 case OP_NOTPLUS:
2575 case OP_NOTMINPLUS:
2576 case OP_NOTQUERY:
2577 case OP_NOTMINQUERY:
2578 case OP_NOTUPTO:
2579 case OP_NOTMINUPTO:
2580 case OP_NOTEXACT:
2581 case OP_NOTPOSSTAR:
2582 case OP_NOTPOSPLUS:
2583 case OP_NOTPOSQUERY:
2584 case OP_NOTPOSUPTO:
2585 case OP_NOTSTARI:
2586 case OP_NOTMINSTARI:
2587 case OP_NOTPLUSI:
2588 case OP_NOTMINPLUSI:
2589 case OP_NOTQUERYI:
2590 case OP_NOTMINQUERYI:
2591 case OP_NOTUPTOI:
2592 case OP_NOTMINUPTOI:
2593 case OP_NOTEXACTI:
2594 case OP_NOTPOSSTARI:
2595 case OP_NOTPOSPLUSI:
2596 case OP_NOTPOSQUERYI:
2597 case OP_NOTPOSUPTOI:
2598 if (utf) utf16_char = TRUE;
2599 #endif
2600 /* Fall through. */
2601
2602 default:
2603 length = OP_lengths16[op] - 1;
2604 break;
2605
2606 case OP_CLASS:
2607 case OP_NCLASS:
2608 /* Skip the character bit map. */
2609 ptr += 32/sizeof(pcre_uint16);
2610 length = 0;
2611 break;
2612
2613 case OP_XCLASS:
2614 /* LINK_SIZE can be 1 or 2 in 16 bit mode. */
2615 if (LINK_SIZE > 1)
2616 length = (int)((((unsigned int)(ptr[0]) << 16) | (unsigned int)(ptr[1]))
2617 - (1 + LINK_SIZE + 1));
2618 else
2619 length = (int)((unsigned int)(ptr[0]) - (1 + LINK_SIZE + 1));
2620
2621 /* Reverse the size of the XCLASS instance. */
2622 *ptr = swap_uint16(*ptr);
2623 ptr++;
2624 if (LINK_SIZE > 1)
2625 {
2626 *ptr = swap_uint16(*ptr);
2627 ptr++;
2628 }
2629
2630 op = *ptr;
2631 *ptr = swap_uint16(op);
2632 ptr++;
2633 if ((op & XCL_MAP) != 0)
2634 {
2635 /* Skip the character bit map. */
2636 ptr += 32/sizeof(pcre_uint16);
2637 length -= 32/sizeof(pcre_uint16);
2638 }
2639 break;
2640 }
2641 }
2642 /* Control should never reach here in 16 bit mode. */
2643 #endif /* SUPPORT_PCRE16 */
2644 }
2645 #endif /* SUPPORT_PCRE[8|16] */
2646
2647
2648
2649 #if defined SUPPORT_PCRE32
2650 static void
2651 regexflip_32(pcre *ere, pcre_extra *extra)
2652 {
2653 real_pcre32 *re = (real_pcre32 *)ere;
2654 int op;
2655 pcre_uint32 *ptr = (pcre_uint32 *)re + re->name_table_offset;
2656 int length = re->name_count * re->name_entry_size;
2657
2658 /* Always flip the bytes in the main data block and study blocks. */
2659
2660 re->magic_number = REVERSED_MAGIC_NUMBER;
2661 re->size = swap_uint32(re->size);
2662 re->options = swap_uint32(re->options);
2663 re->flags = swap_uint16(re->flags);
2664 re->top_bracket = swap_uint16(re->top_bracket);
2665 re->top_backref = swap_uint16(re->top_backref);
2666 re->first_char = swap_uint32(re->first_char);
2667 re->req_char = swap_uint32(re->req_char);
2668 re->name_table_offset = swap_uint16(re->name_table_offset);
2669 re->name_entry_size = swap_uint16(re->name_entry_size);
2670 re->name_count = swap_uint16(re->name_count);
2671
2672 if (extra != NULL)
2673 {
2674 pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);
2675 rsd->size = swap_uint32(rsd->size);
2676 rsd->flags = swap_uint32(rsd->flags);
2677 rsd->minlength = swap_uint32(rsd->minlength);
2678 }
2679
2680 /* In 32-bit mode we must swap bytes in the name table, if present, and then in
2681 the pattern itself. */
2682
2683 while(TRUE)
2684 {
2685 /* Swap previous characters. */
2686 while (length-- > 0)
2687 {
2688 *ptr = swap_uint32(*ptr);
2689 ptr++;
2690 }
2691
2692 /* Get next opcode. */
2693
2694 length = 0;
2695 op = *ptr;
2696 *ptr++ = swap_uint32(op);
2697
2698 switch (op)
2699 {
2700 case OP_END:
2701 return;
2702
2703 default:
2704 length = OP_lengths32[op] - 1;
2705 break;
2706
2707 case OP_CLASS:
2708 case OP_NCLASS:
2709 /* Skip the character bit map. */
2710 ptr += 32/sizeof(pcre_uint32);
2711 length = 0;
2712 break;
2713
2714 case OP_XCLASS:
2715 /* LINK_SIZE can only be 1 in 32-bit mode. */
2716 length = (int)((unsigned int)(ptr[0]) - (1 + LINK_SIZE + 1));
2717
2718 /* Reverse the size of the XCLASS instance. */
2719 *ptr = swap_uint32(*ptr);
2720 ptr++;
2721
2722 op = *ptr;
2723 *ptr = swap_uint32(op);
2724 ptr++;
2725 if ((op & XCL_MAP) != 0)
2726 {
2727 /* Skip the character bit map. */
2728 ptr += 32/sizeof(pcre_uint32);
2729 length -= 32/sizeof(pcre_uint32);
2730 }
2731 break;
2732 }
2733 }
2734 /* Control should never reach here in 32 bit mode. */
2735 }
2736
2737 #endif /* SUPPORT_PCRE32 */
2738
2739
2740
2741 static void
2742 regexflip(pcre *ere, pcre_extra *extra)
2743 {
2744 #if defined SUPPORT_PCRE32
2745 if (REAL_PCRE_FLAGS(ere) & PCRE_MODE32)
2746 regexflip_32(ere, extra);
2747 #endif
2748 #if defined SUPPORT_PCRE8 || defined SUPPORT_PCRE16
2749 if (REAL_PCRE_FLAGS(ere) & (PCRE_MODE8 | PCRE_MODE16))
2750 regexflip8_or_16(ere, extra);
2751 #endif
2752 }
2753
2754
2755
2756 /*************************************************
2757 * Check match or recursion limit *
2758 *************************************************/
2759
2760 static int
2761 check_match_limit(pcre *re, pcre_extra *extra, pcre_uint8 *bptr, int len,
2762 int start_offset, int options, int *use_offsets, int use_size_offsets,
2763 int flag, unsigned long int *limit, int errnumber, const char *msg)
2764 {
2765 int count;
2766 int min = 0;
2767 int mid = 64;
2768 int max = -1;
2769
2770 extra->flags |= flag;
2771
2772 for (;;)
2773 {
2774 *limit = mid;
2775
2776 PCRE_EXEC(count, re, extra, bptr, len, start_offset, options,
2777 use_offsets, use_size_offsets);
2778
2779 if (count == errnumber)
2780 {
2781 /* fprintf(outfile, "Testing %s limit = %d\n", msg, mid); */
2782 min = mid;
2783 mid = (mid == max - 1)? max : (max > 0)? (min + max)/2 : mid*2;
2784 }
2785
2786 else if (count >= 0 || count == PCRE_ERROR_NOMATCH ||
2787 count == PCRE_ERROR_PARTIAL)
2788 {
2789 if (mid == min + 1)
2790 {
2791 fprintf(outfile, "Minimum %s limit = %d\n", msg, mid);
2792 break;
2793 }
2794 /* fprintf(outfile, "Testing %s limit = %d\n", msg, mid); */
2795 max = mid;
2796 mid = (min + mid)/2;
2797 }
2798 else break; /* Some other error */
2799 }
2800
2801 extra->flags &= ~flag;
2802 return count;
2803 }
2804
2805
2806
2807 /*************************************************
2808 * Case-independent strncmp() function *
2809 *************************************************/
2810
2811 /*
2812 Arguments:
2813 s first string
2814 t second string
2815 n number of characters to compare
2816
2817 Returns: < 0, = 0, or > 0, according to the comparison
2818 */
2819
2820 static int
2821 strncmpic(pcre_uint8 *s, pcre_uint8 *t, int n)
2822 {
2823 while (n--)
2824 {
2825 int c = tolower(*s++) - tolower(*t++);
2826 if (c) return c;
2827 }
2828 return 0;
2829 }
2830
2831
2832
2833 /*************************************************
2834 * Check newline indicator *
2835 *************************************************/
2836
2837 /* This is used both at compile and run-time to check for <xxx> escapes. Print
2838 a message and return 0 if there is no match.
2839
2840 Arguments:
2841 p points after the leading '<'
2842 f file for error message
2843
2844 Returns: appropriate PCRE_NEWLINE_xxx flags, or 0
2845 */
2846
2847 static int
2848 check_newline(pcre_uint8 *p, FILE *f)
2849 {
2850 if (strncmpic(p, (pcre_uint8 *)"cr>", 3) == 0) return PCRE_NEWLINE_CR;
2851 if (strncmpic(p, (pcre_uint8 *)"lf>", 3) == 0) return PCRE_NEWLINE_LF;
2852 if (strncmpic(p, (pcre_uint8 *)"crlf>", 5) == 0) return PCRE_NEWLINE_CRLF;
2853 if (strncmpic(p, (pcre_uint8 *)"anycrlf>", 8) == 0) return PCRE_NEWLINE_ANYCRLF;
2854 if (strncmpic(p, (pcre_uint8 *)"any>", 4) == 0) return PCRE_NEWLINE_ANY;
2855 if (strncmpic(p, (pcre_uint8 *)"bsr_anycrlf>", 12) == 0) return PCRE_BSR_ANYCRLF;
2856 if (strncmpic(p, (pcre_uint8 *)"bsr_unicode>", 12) == 0) return PCRE_BSR_UNICODE;
2857 fprintf(f, "Unknown newline type at: <%s\n", p);
2858 return 0;
2859 }
2860
2861
2862
2863 /*************************************************
2864 * Usage function *
2865 *************************************************/
2866
2867 static void
2868 usage(void)
2869 {
2870 printf("Usage: pcretest [options] [<input file> [<output file>]]\n\n");
2871 printf("Input and output default to stdin and stdout.\n");
2872 #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
2873 printf("If input is a terminal, readline() is used to read from it.\n");
2874 #else
2875 printf("This version of pcretest is not linked with readline().\n");
2876 #endif
2877 printf("\nOptions:\n");
2878 #ifdef SUPPORT_PCRE16
2879 printf(" -16 use the 16-bit library\n");
2880 #endif
2881 #ifdef SUPPORT_PCRE32
2882 printf(" -32 use the 32-bit library\n");
2883 #endif
2884 printf(" -b show compiled code\n");
2885 printf(" -C show PCRE compile-time options and exit\n");
2886 printf(" -C arg show a specific compile-time option\n");
2887 printf(" and exit with its value. The arg can be:\n");
2888 printf(" linksize internal link size [2, 3, 4]\n");
2889 printf(" pcre8 8 bit library support enabled [0, 1]\n");
2890 printf(" pcre16 16 bit library support enabled [0, 1]\n");
2891 printf(" pcre32 32 bit library support enabled [0, 1]\n");
2892 printf(" utf Unicode Transformation Format supported [0, 1]\n");
2893 printf(" ucp Unicode Properties supported [0, 1]\n");
2894 printf(" jit Just-in-time compiler supported [0, 1]\n");
2895 printf(" newline Newline type [CR, LF, CRLF, ANYCRLF, ANY, ???]\n");
2896 printf(" -d debug: show compiled code and information (-b and -i)\n");
2897 #if !defined NODFA
2898 printf(" -dfa force DFA matching for all subjects\n");
2899 #endif
2900 printf(" -help show usage information\n");
2901 printf(" -i show information about compiled patterns\n"
2902 " -M find MATCH_LIMIT minimum for each subject\n"
2903 " -m output memory used information\n"
2904 " -o <n> set size of offsets vector to <n>\n");
2905 #if !defined NOPOSIX
2906 printf(" -p use POSIX interface\n");
2907 #endif
2908 printf(" -q quiet: do not output PCRE version number at start\n");
2909 printf(" -S <n> set stack size to <n> megabytes\n");
2910 printf(" -s force each pattern to be studied at basic level\n"
2911 " -s+ force each pattern to be studied, using JIT if available\n"
2912 " -s++ ditto, verifying when JIT was actually used\n"
2913 " -s+n force each pattern to be studied, using JIT if available,\n"
2914 " where 1 <= n <= 7 selects JIT options\n"
2915 " -s++n ditto, verifying when JIT was actually used\n"
2916 " -t time compilation and execution\n");
2917 printf(" -t <n> time compilation and execution, repeating <n> times\n");
2918 printf(" -tm time execution (matching) only\n");
2919 printf(" -tm <n> time execution (matching) only, repeating <n> times\n");
2920 }
2921
2922
2923
2924 /*************************************************
2925 * Main Program *
2926 *************************************************/
2927
2928 /* Read lines from named file or stdin and write to named file or stdout; lines
2929 consist of a regular expression, in delimiters and optionally followed by
2930 options, followed by a set of test data, terminated by an empty line. */
2931
2932 int main(int argc, char **argv)
2933 {
2934 FILE *infile = stdin;
2935 const char *version;
2936 int options = 0;
2937 int study_options = 0;
2938 int default_find_match_limit = FALSE;
2939 int op = 1;
2940 int timeit = 0;
2941 int timeitm = 0;
2942 int showinfo = 0;
2943 int showstore = 0;
2944 int force_study = -1;
2945 int force_study_options = 0;
2946 int quiet = 0;
2947 int size_offsets = 45;
2948 int size_offsets_max;
2949 int *offsets = NULL;
2950 int debug = 0;
2951 int done = 0;
2952 int all_use_dfa = 0;
2953 int verify_jit = 0;
2954 int yield = 0;
2955 int stack_size;
2956 pcre_uint8 *dbuffer = NULL;
2957 size_t dbuffer_size = 1u << 14;
2958
2959 #if !defined NOPOSIX
2960 int posix = 0;
2961 #endif
2962 #if !defined NODFA
2963 int *dfa_workspace = NULL;
2964 #endif
2965
2966 pcre_jit_stack *jit_stack = NULL;
2967
2968 /* These vectors store, end-to-end, a list of zero-terminated captured
2969 substring names, each list itself being terminated by an empty name. Assume
2970 that 1024 is plenty long enough for the few names we'll be testing. It is
2971 easiest to keep separate 8-, 16- and 32-bit versions, using the 32-bit version
2972 for the actual memory, to ensure alignment. */
2973
2974 pcre_uint32 copynames[1024];
2975 pcre_uint32 getnames[1024];
2976
2977 #ifdef SUPPORT_PCRE32
2978 pcre_uint32 *cn32ptr;
2979 pcre_uint32 *gn32ptr;
2980 #endif
2981
2982 #ifdef SUPPORT_PCRE16
2983 pcre_uint16 *copynames16 = (pcre_uint16 *)copynames;
2984 pcre_uint16 *getnames16 = (pcre_uint16 *)getnames;
2985 pcre_uint16 *cn16ptr;
2986 pcre_uint16 *gn16ptr;
2987 #endif
2988
2989 #ifdef SUPPORT_PCRE8
2990 pcre_uint8 *copynames8 = (pcre_uint8 *)copynames;
2991 pcre_uint8 *getnames8 = (pcre_uint8 *)getnames;
2992 pcre_uint8 *cn8ptr;
2993 pcre_uint8 *gn8ptr;
2994 #endif
2995
2996 /* Get buffers from malloc() so that valgrind will check their misuse when
2997 debugging. They grow automatically when very long lines are read. The 16-
2998 and 32-bit buffers (buffer16, buffer32) are obtained only if needed. */
2999
3000 buffer = (pcre_uint8 *)malloc(buffer_size);
3001 pbuffer = (pcre_uint8 *)malloc(buffer_size);
3002
3003 /* The outfile variable is static so that new_malloc can use it. */
3004
3005 outfile = stdout;
3006
3007 /* The following _setmode() stuff is some Windows magic that tells its runtime
3008 library to translate CRLF into a single LF character. At least, that's what
3009 I've been told: never having used Windows I take this all on trust. Originally
3010 it set 0x8000, but then I was advised that _O_BINARY was better. */
3011
3012 #if defined(_WIN32) || defined(WIN32)
3013 _setmode( _fileno( stdout ), _O_BINARY );
3014 #endif
3015
3016 /* Get the version number: both pcre_version() and pcre16_version() give the
3017 same answer. We just need to ensure that we call one that is available. */
3018
3019 #if defined SUPPORT_PCRE8
3020 version = pcre_version();
3021 #elif defined SUPPORT_PCRE16
3022 version = pcre16_version();
3023 #elif defined SUPPORT_PCRE32
3024 version = pcre32_version();
3025 #endif
3026
3027 /* Scan options */
3028
3029 while (argc > 1 && argv[op][0] == '-')
3030 {
3031 pcre_uint8 *endptr;
3032 char *arg = argv[op];
3033
3034 if (strcmp(arg, "-m") == 0) showstore = 1;
3035 else if (strcmp(arg, "-s") == 0) force_study = 0;
3036
3037 else if (strncmp(arg, "-s+", 3) == 0)
3038 {
3039 arg += 3;
3040 if (*arg == '+') { arg++; verify_jit = TRUE; }
3041 force_study = 1;
3042 if (*arg == 0)
3043 force_study_options = jit_study_bits[6];
3044 else if (*arg >= '1' && *arg <= '7')
3045 force_study_options = jit_study_bits[*arg - '1'];
3046 else goto BAD_ARG;
3047 }
3048 else if (strcmp(arg, "-8") == 0)
3049 {
3050 #ifdef SUPPORT_PCRE8
3051 pcre_mode = PCRE8_MODE;
3052 #else
3053 printf("** This version of PCRE was built without 8-bit support\n");
3054 exit(1);
3055 #endif
3056 }
3057 else if (strcmp(arg, "-16") == 0)
3058 {
3059 #ifdef SUPPORT_PCRE16
3060 pcre_mode = PCRE16_MODE;
3061 #else
3062 printf("** This version of PCRE was built without 16-bit support\n");
3063 exit(1);
3064 #endif
3065 }
3066 else if (strcmp(arg, "-32") == 0)
3067 {
3068 #ifdef SUPPORT_PCRE32
3069 pcre_mode = PCRE32_MODE;
3070 #else
3071 printf("** This version of PCRE was built without 32-bit support\n");
3072 exit(1);
3073 #endif
3074 }
3075 else if (strcmp(arg, "-q") == 0) quiet = 1;
3076 else if (strcmp(arg, "-b") == 0) debug = 1;
3077 else if (strcmp(arg, "-i") == 0) showinfo = 1;
3078 else if (strcmp(arg, "-d") == 0) showinfo = debug = 1;
3079 else if (strcmp(arg, "-M") == 0) default_find_match_limit = TRUE;
3080 #if !defined NODFA
3081 else if (strcmp(arg, "-dfa") == 0) all_use_dfa = 1;
3082 #endif
3083 else if (strcmp(arg, "-o") == 0 && argc > 2 &&
3084 ((size_offsets = get_value((pcre_uint8 *)argv[op+1], &endptr)),
3085 *endptr == 0))
3086 {
3087 op++;
3088 argc--;
3089 }
3090 else if (strcmp(arg, "-t") == 0 || strcmp(arg, "-tm") == 0)
3091 {
3092 int both = arg[2] == 0;
3093 int temp;
3094 if (argc > 2 && (temp = get_value((pcre_uint8 *)argv[op+1], &endptr),
3095 *endptr == 0))
3096 {
3097 timeitm = temp;
3098 op++;
3099 argc--;
3100 }
3101 else timeitm = LOOPREPEAT;
3102 if (both) timeit = timeitm;
3103 }
3104 else if (strcmp(arg, "-S") == 0 && argc > 2 &&
3105 ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),
3106 *endptr == 0))
3107 {
3108 #if defined(_WIN32) || defined(WIN32) || defined(__minix) || defined(NATIVE_ZOS) || defined(__VMS)
3109 printf("PCRE: -S not supported on this OS\n");
3110 exit(1);
3111 #else
3112 int rc;
3113 struct rlimit rlim;
3114 getrlimit(RLIMIT_STACK, &rlim);
3115 rlim.rlim_cur = stack_size * 1024 * 1024;
3116 rc = setrlimit(RLIMIT_STACK, &rlim);
3117 if (rc != 0)
3118 {
3119 printf("PCRE: setrlimit() failed with error %d\n", rc);
3120 exit(1);
3121 }
3122 op++;
3123 argc--;
3124 #endif
3125 }
3126 #if !defined NOPOSIX
3127 else if (strcmp(arg, "-p") == 0) posix = 1;
3128 #endif
3129 else if (strcmp(arg, "-C") == 0)
3130 {
3131 int rc;
3132 unsigned long int lrc;
3133
3134 if (argc > 2)
3135 {
3136 if (strcmp(argv[op + 1], "linksize") == 0)
3137 {
3138 (void)PCRE_CONFIG(PCRE_CONFIG_LINK_SIZE, &rc);
3139 printf("%d\n", rc);
3140 yield = rc;
3141
3142 #ifdef __VMS
3143 vms_setsymbol("LINKSIZE",0,yield );
3144 #endif
3145 }
3146 else if (strcmp(argv[op + 1], "pcre8") == 0)
3147 {
3148 #ifdef SUPPORT_PCRE8
3149 printf("1\n");
3150 yield = 1;
3151 #else
3152 printf("0\n");
3153 yield = 0;
3154 #endif
3155 #ifdef __VMS
3156 vms_setsymbol("PCRE8",0,yield );
3157 #endif
3158 }
3159 else if (strcmp(argv[op + 1], "pcre16") == 0)
3160 {
3161 #ifdef SUPPORT_PCRE16
3162 printf("1\n");
3163 yield = 1;
3164 #else
3165 printf("0\n");
3166 yield = 0;
3167 #endif
3168 #ifdef __VMS
3169 vms_setsymbol("PCRE16",0,yield );
3170 #endif
3171 }
3172 else if (strcmp(argv[op + 1], "pcre32") == 0)
3173 {
3174 #ifdef SUPPORT_PCRE32
3175 printf("1\n");
3176 yield = 1;
3177 #else
3178 printf("0\n");
3179 yield = 0;
3180 #endif
3181 #ifdef __VMS
3182 vms_setsymbol("PCRE32",0,yield );
3183 #endif
3184 }
3185 else if (strcmp(argv[op + 1], "utf") == 0)
3186 {
3187 #ifdef SUPPORT_PCRE8
3188 if (pcre_mode == PCRE8_MODE)
3189 (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
3190 #endif
3191 #ifdef SUPPORT_PCRE16
3192 if (pcre_mode == PCRE16_MODE)
3193 (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
3194 #endif
3195 #ifdef SUPPORT_PCRE32
3196 if (pcre_mode == PCRE32_MODE)
3197 (void)pcre32_config(PCRE_CONFIG_UTF32, &rc);
3198 #endif
3199 printf("%d\n", rc);
3200 yield = rc;
3201 #ifdef __VMS
3202 vms_setsymbol("UTF",0,yield );
3203 #endif
3204 }
3205 else if (strcmp(argv[op + 1], "ucp") == 0)
3206 {
3207 (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
3208 printf("%d\n", rc);
3209 yield = rc;
3210 }
3211 else if (strcmp(argv[op + 1], "jit") == 0)
3212 {
3213 (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);
3214 printf("%d\n", rc);
3215 yield = rc;
3216 }
3217 else if (strcmp(argv[op + 1], "newline") == 0)
3218 {
3219 (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3220 print_newline_config(rc, TRUE);
3221 }
3222 else if (strcmp(argv[op + 1], "ebcdic") == 0)
3223 {
3224 #ifdef EBCDIC
3225 printf("1\n");
3226 yield = 1;
3227 #else
3228 printf("0\n");
3229 #endif
3230 }
3231 else if (strcmp(argv[op + 1], "ebcdic-nl") == 0)
3232 {
3233 #ifdef EBCDIC
3234 printf("0x%02x\n", CHAR_LF);
3235 #else
3236 printf("0\n");
3237 #endif
3238 }
3239 else
3240 {
3241 printf("Unknown -C option: %s\n", argv[op + 1]);
3242 }
3243 goto EXIT;
3244 }
3245
3246 /* No argument for -C: output all configuration information. */
3247
3248 printf("PCRE version %s\n", version);
3249 printf("Compiled with\n");
3250
3251 #ifdef EBCDIC
3252 printf(" EBCDIC code support: LF is 0x%02x\n", CHAR_LF);
3253 #endif
3254
3255 /* At least one of SUPPORT_PCRE8 and SUPPORT_PCRE16 will be set. If both
3256 are set, either both UTFs are supported or both are not supported. */
3257
3258 #ifdef SUPPORT_PCRE8
3259 printf(" 8-bit support\n");
3260 (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
3261 printf (" %sUTF-8 support\n", rc ? "" : "No ");
3262 #endif
3263 #ifdef SUPPORT_PCRE16
3264 printf(" 16-bit support\n");
3265 (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
3266 printf (" %sUTF-16 support\n", rc ? "" : "No ");
3267 #endif
3268 #ifdef SUPPORT_PCRE32
3269 printf(" 32-bit support\n");
3270 (void)pcre32_config(PCRE_CONFIG_UTF32, &rc);
3271 printf (" %sUTF-32 support\n", rc ? "" : "No ");
3272 #endif
3273
3274 (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
3275 printf(" %sUnicode properties support\n", rc? "" : "No ");
3276 (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);
3277 if (rc)
3278 {
3279 const char *arch;
3280 (void)PCRE_CONFIG(PCRE_CONFIG_JITTARGET, (void *)(&arch));
3281 printf(" Just-in-time compiler support: %s\n", arch);
3282 }
3283 else
3284 printf(" No just-in-time compiler support\n");
3285 (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3286 print_newline_config(rc, FALSE);
3287 (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);
3288 printf(" \\R matches %s\n", rc? "CR, LF, or CRLF only" :
3289 "all Unicode newlines");
3290 (void)PCRE_CONFIG(PCRE_CONFIG_LINK_SIZE, &rc);
3291 printf(" Internal link size = %d\n", rc);
3292 (void)PCRE_CONFIG(PCRE_CONFIG_POSIX_MALLOC_THRESHOLD, &rc);
3293 printf(" POSIX malloc threshold = %d\n", rc);
3294 (void)PCRE_CONFIG(PCRE_CONFIG_MATCH_LIMIT, &lrc);
3295 printf(" Default match limit = %ld\n", lrc);
3296 (void)PCRE_CONFIG(PCRE_CONFIG_MATCH_LIMIT_RECURSION, &lrc);
3297 printf(" Default recursion depth limit = %ld\n", lrc);
3298 (void)PCRE_CONFIG(PCRE_CONFIG_STACKRECURSE, &rc);
3299 printf(" Match recursion uses %s", rc? "stack" : "heap");
3300 if (showstore)
3301 {
3302 PCRE_EXEC(stack_size, NULL, NULL, NULL, -999, -999, 0, NULL, 0);
3303 printf(": %sframe size = %d bytes", rc? "approximate " : "", -stack_size);
3304 }
3305 printf("\n");
3306 goto EXIT;
3307 }
3308 else if (strcmp(arg, "-help") == 0 ||
3309 strcmp(arg, "--help") == 0)
3310 {
3311 usage();
3312 goto EXIT;
3313 }
3314 else
3315 {
3316 BAD_ARG:
3317 printf("** Unknown or malformed option %s\n", arg);
3318 usage();
3319 yield = 1;
3320 goto EXIT;
3321 }
3322 op++;
3323 argc--;
3324 }
3325
3326 /* Get the store for the offsets vector, and remember what it was */
3327
3328 size_offsets_max = size_offsets;
3329 offsets = (int *)malloc(size_offsets_max * sizeof(int));
3330 if (offsets == NULL)
3331 {
3332 printf("** Failed to get %d bytes of memory for offsets vector\n",
3333 (int)(size_offsets_max * sizeof(int)));
3334 yield = 1;
3335 goto EXIT;
3336 }
3337
3338 /* Sort out the input and output files */
3339
3340 if (argc > 1)
3341 {
3342 infile = fopen(argv[op], INPUT_MODE);
3343 if (infile == NULL)
3344 {
3345 printf("** Failed to open %s\n", argv[op]);
3346 yield = 1;
3347 goto EXIT;
3348 }
3349 }
3350
3351 if (argc > 2)
3352 {
3353 outfile = fopen(argv[op+1], OUTPUT_MODE);
3354 if (outfile == NULL)
3355 {
3356 printf("** Failed to open %s\n", argv[op+1]);
3357 yield = 1;
3358 goto EXIT;
3359 }
3360 }
3361
3362 /* Set alternative malloc function */
3363
3364 #ifdef SUPPORT_PCRE8
3365 pcre_malloc = new_malloc;
3366 pcre_free = new_free;
3367 pcre_stack_malloc = stack_malloc;
3368 pcre_stack_free = stack_free;
3369 #endif
3370
3371 #ifdef SUPPORT_PCRE16
3372 pcre16_malloc = new_malloc;
3373 pcre16_free = new_free;
3374 pcre16_stack_malloc = stack_malloc;
3375 pcre16_stack_free = stack_free;
3376 #endif
3377
3378 #ifdef SUPPORT_PCRE32
3379 pcre32_malloc = new_malloc;
3380 pcre32_free = new_free;
3381 pcre32_stack_malloc = stack_malloc;
3382 pcre32_stack_free = stack_free;
3383 #endif
3384
3385 /* Heading line unless quiet, then prompt for first regex if stdin */
3386
3387 if (!quiet) fprintf(outfile, "PCRE version %s\n\n", version);
3388
3389 /* Main loop */
3390
3391 while (!done)
3392 {
3393 pcre *re = NULL;
3394 pcre_extra *extra = NULL;
3395
3396 #if !defined NOPOSIX /* There are still compilers that require no indent */
3397 regex_t preg;
3398 int do_posix = 0;
3399 #endif
3400
3401 const char *error;
3402 pcre_uint8 *markptr;
3403 pcre_uint8 *p, *pp, *ppp;
3404 pcre_uint8 *to_file = NULL;
3405 const pcre_uint8 *tables = NULL;
3406 unsigned long int get_options;
3407 unsigned long int true_size, true_study_size = 0;
3408 size_t size, regex_gotten_store;
3409 int do_allcaps = 0;
3410 int do_mark = 0;
3411 int do_study = 0;
3412 int no_force_study = 0;
3413 int do_debug = debug;
3414 int do_G = 0;
3415 int do_g = 0;
3416 int do_showinfo = showinfo;
3417 int do_showrest = 0;
3418 int do_showcaprest = 0;
3419 int do_flip = 0;
3420 int erroroffset, len, delimiter, poffset;
3421
3422 #if !defined NODFA
3423 int dfa_matched = 0;
3424 #endif
3425
3426 use_utf = 0;
3427 debug_lengths = 1;
3428
3429 if (extend_inputline(infile, buffer, " re> ") == NULL) break;
3430 if (infile != stdin) fprintf(outfile, "%s", (char *)buffer);
3431 fflush(outfile);
3432
3433 p = buffer;
3434 while (isspace(*p)) p++;
3435 if (*p == 0) continue;
3436
3437 /* See if the pattern is to be loaded pre-compiled from a file. */
3438
3439 if (*p == '<' && strchr((char *)(p+1), '<') == NULL)
3440 {
3441 pcre_uint32 magic;
3442 pcre_uint8 sbuf[8];
3443 FILE *f;
3444
3445 p++;
3446 if (*p == '!')
3447 {
3448 do_debug = TRUE;
3449 do_showinfo = TRUE;
3450 p++;
3451 }
3452
3453 pp = p + (int)strlen((char *)p);
3454 while (isspace(pp[-1])) pp--;
3455 *pp = 0;
3456
3457 f = fopen((char *)p, "rb");
3458 if (f == NULL)
3459 {
3460 fprintf(outfile, "Failed to open %s: %s\n", p, strerror(errno));
3461 continue;
3462 }
3463
3464 first_gotten_store = 0;
3465 if (fread(sbuf, 1, 8, f) != 8) goto FAIL_READ;
3466
3467 true_size =
3468 (sbuf[0] << 24) | (sbuf[1] << 16) | (sbuf[2] << 8) | sbuf[3];
3469 true_study_size =
3470 (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];
3471
3472 re = (pcre *)new_malloc(true_size);
3473 if (re == NULL)
3474 {
3475 printf("** Failed to get %d bytes of memory for pcre object\n",
3476 (int)true_size);
3477 yield = 1;
3478 goto EXIT;
3479 }
3480 regex_gotten_store = first_gotten_store;
3481
3482 if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;
3483
3484 magic = REAL_PCRE_MAGIC(re);
3485 if (magic != MAGIC_NUMBER)
3486 {
3487 if (swap_uint32(magic) == MAGIC_NUMBER)
3488 {
3489 do_flip = 1;
3490 }
3491 else
3492 {
3493 fprintf(outfile, "Data in %s is not a compiled PCRE regex\n", p);
3494 new_free(re);
3495 fclose(f);
3496 continue;
3497 }
3498 }
3499
3500 /* We hide the byte-invert info for little and big endian tests. */
3501 fprintf(outfile, "Compiled pattern%s loaded from %s\n",
3502 do_flip && (p[-1] == '<') ? " (byte-inverted)" : "", p);
3503
3504 /* Now see if there is any following study data. */
3505
3506 if (true_study_size != 0)
3507 {
3508 pcre_study_data *psd;
3509
3510 extra = (pcre_extra *)new_malloc(sizeof(pcre_extra) + true_study_size);
3511 extra->flags = PCRE_EXTRA_STUDY_DATA;
3512
3513 psd = (pcre_study_data *)(((char *)extra) + sizeof(pcre_extra));
3514 extra->study_data = psd;
3515
3516 if (fread(psd, 1, true_study_size, f) != true_study_size)
3517 {
3518 FAIL_READ:
3519 fprintf(outfile, "Failed to read data from %s\n", p);
3520 if (extra != NULL)
3521 {
3522 PCRE_FREE_STUDY(extra);
3523 }
3524 new_free(re);
3525 fclose(f);
3526 continue;
3527 }
3528 fprintf(outfile, "Study data loaded from %s\n", p);
3529 do_study = 1; /* To get the data output if requested */
3530 }
3531 else fprintf(outfile, "No study data\n");
3532
3533 /* Flip the necessary bytes. */
3534 if (do_flip)
3535 {
3536 int rc;
3537 PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, NULL);
3538 if (rc == PCRE_ERROR_BADMODE)
3539 {
3540 pcre_uint16 flags_in_host_byte_order;
3541 if (REAL_PCRE_MAGIC(re) == MAGIC_NUMBER)
3542 flags_in_host_byte_order = REAL_PCRE_FLAGS(re);
3543 else
3544 flags_in_host_byte_order = swap_uint16(REAL_PCRE_FLAGS(re));
3545 /* Simulate the result of the function call below. */
3546 fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
3547 pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "",
3548 PCRE_INFO_OPTIONS);
3549 fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
3550 "%d-bit mode\n", 8 * CHAR_SIZE, 8 * (flags_in_host_byte_order & PCRE_MODE_MASK));
3551 new_free(re);
3552 fclose(f);
3553 continue;
3554 }
3555 }
3556
3557 /* Need to know if UTF-8 for printing data strings. */
3558
3559 if (new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options) < 0)
3560 {
3561 new_free(re);
3562 fclose(f);
3563 continue;
3564 }
3565 use_utf = (get_options & PCRE_UTF8) != 0;
3566
3567 fclose(f);
3568 goto SHOW_INFO;
3569 }
3570
3571 /* In-line pattern (the usual case). Get the delimiter and seek the end of
3572 the pattern; if it isn't complete, read more. */
3573
3574 delimiter = *p++;
3575
3576 if (isalnum(delimiter) || delimiter == '\\')
3577 {
3578 fprintf(outfile, "** Delimiter must not be alphanumeric or \\\n");
3579 goto SKIP_DATA;
3580 }
3581
3582 pp = p;
3583 poffset = (int)(p - buffer);
3584
3585 for(;;)
3586 {
3587 while (*pp != 0)
3588 {
3589 if (*pp == '\\' && pp[1] != 0) pp++;
3590 else if (*pp == delimiter) break;
3591 pp++;
3592 }
3593 if (*pp != 0) break;
3594 if ((pp = extend_inputline(infile, pp, " > ")) == NULL)
3595 {
3596 fprintf(outfile, "** Unexpected EOF\n");
3597 done = 1;
3598 goto CONTINUE;
3599 }
3600 if (infile != stdin) fprintf(outfile, "%s", (char *)pp);
3601 }
3602
3603 /* The buffer may have moved while being extended; reset the start of data
3604 pointer to the correct relative point in the buffer. */
3605
3606 p = buffer + poffset;
3607
3608 /* If the first character after the delimiter is backslash, make
3609 the pattern end with backslash. This is purely to provide a way
3610 of testing for the error message when a pattern ends with backslash. */
3611
3612 if (pp[1] == '\\') *pp++ = '\\';
3613
3614 /* Terminate the pattern at the delimiter, and save a copy of the pattern
3615 for callouts. */
3616
3617 *pp++ = 0;
3618 strcpy((char *)pbuffer, (char *)p);
3619
3620 /* Look for options after final delimiter */
3621
3622 options = 0;
3623 study_options = force_study_options;
3624 log_store = showstore; /* default from command line */
3625
3626 while (*pp != 0)
3627 {
3628 switch (*pp++)
3629 {
3630 case 'f': options |= PCRE_FIRSTLINE; break;
3631 case 'g': do_g = 1; break;
3632 case 'i': options |= PCRE_CASELESS; break;
3633 case 'm': options |= PCRE_MULTILINE; break;
3634 case 's': options |= PCRE_DOTALL; break;
3635 case 'x': options |= PCRE_EXTENDED; break;
3636
3637 case '+':
3638 if (do_showrest) do_showcaprest = 1; else do_showrest = 1;
3639 break;
3640
3641 case '=': do_allcaps = 1; break;
3642 case 'A': options |= PCRE_ANCHORED; break;
3643 case 'B': do_debug = 1; break;
3644 case 'C': options |= PCRE_AUTO_CALLOUT; break;
3645 case 'D': do_debug = do_showinfo = 1; break;
3646 case 'E': options |= PCRE_DOLLAR_ENDONLY; break;
3647 case 'F': do_flip = 1; break;
3648 case 'G': do_G = 1; break;
3649 case 'I': do_showinfo = 1; break;
3650 case 'J': options |= PCRE_DUPNAMES; break;
3651 case 'K': do_mark = 1; break;
3652 case 'M': log_store = 1; break;
3653 case 'N': options |= PCRE_NO_AUTO_CAPTURE; break;
3654
3655 #if !defined NOPOSIX
3656 case 'P': do_posix = 1; break;
3657 #endif
3658
3659 case 'S':
3660 do_study = 1;
3661 for (;;)
3662 {
3663 switch (*pp++)
3664 {
3665 case 'S':
3666 do_study = 0;
3667 no_force_study = 1;
3668 break;
3669
3670 case '!':
3671 study_options |= PCRE_STUDY_EXTRA_NEEDED;
3672 break;
3673
3674 case '+':
3675 if (*pp == '+')
3676 {
3677 verify_jit = TRUE;
3678 pp++;
3679 }
3680 if (*pp >= '1' && *pp <= '7')
3681 study_options |= jit_study_bits[*pp++ - '1'];
3682 else
3683 study_options |= jit_study_bits[6];
3684 break;
3685
3686 case '-':
3687 study_options &= ~PCRE_STUDY_ALLJIT;
3688 break;
3689
3690 default:
3691 pp--;
3692 goto ENDLOOP;
3693 }
3694 }
3695 ENDLOOP:
3696 break;
3697
3698 case 'U': options |= PCRE_UNGREEDY; break;
3699 case 'W': options |= PCRE_UCP; break;
3700 case 'X': options |= PCRE_EXTRA; break;
3701 case 'Y': options |= PCRE_NO_START_OPTIMISE; break;
3702 case 'Z': debug_lengths = 0; break;
3703 case '8': options |= PCRE_UTF8; use_utf = 1; break;
3704 case '?': options |= PCRE_NO_UTF8_CHECK; break;
3705
3706 case 'T':
3707 switch (*pp++)
3708 {
3709 case '0': tables = tables0; break;
3710 case '1': tables = tables1; break;
3711
3712 case '\r':
3713 case '\n':
3714 case ' ':
3715 case 0:
3716 fprintf(outfile, "** Missing table number after /T\n");
3717 goto SKIP_DATA;
3718
3719 default:
3720 fprintf(outfile, "** Bad table number \"%c\" after /T\n", pp[-1]);
3721 goto SKIP_DATA;
3722 }
3723 break;
3724
3725 case 'L':
3726 ppp = pp;
3727 /* The '\r' test here is so that it works on Windows. */
3728 /* The '0' test is just in case this is an unterminated line. */
3729 while (*ppp != 0 && *ppp != '\n' && *ppp != '\r' && *ppp != ' ') ppp++;
3730 *ppp = 0;
3731 if (setlocale(LC_CTYPE, (const char *)pp) == NULL)
3732 {
3733 fprintf(outfile, "** Failed to set locale \"%s\"\n", pp);
3734 goto SKIP_DATA;
3735 }
3736 locale_set = 1;
3737 tables = PCRE_MAKETABLES;
3738 pp = ppp;
3739 break;
3740
3741 case '>':
3742 to_file = pp;
3743 while (*pp != 0) pp++;
3744 while (isspace(pp[-1])) pp--;
3745 *pp = 0;
3746 break;
3747
3748 case '<':
3749 {
3750 if (strncmpic(pp, (pcre_uint8 *)"JS>", 3) == 0)
3751 {
3752 options |= PCRE_JAVASCRIPT_COMPAT;
3753 pp += 3;
3754 }
3755 else
3756 {
3757 int x = check_newline(pp, outfile);
3758 if (x == 0) goto SKIP_DATA;
3759 options |= x;
3760 while (*pp++ != '>');
3761 }
3762 }
3763 break;
3764
3765 case '\r': /* So that it works in Windows */
3766 case '\n':
3767 case ' ':
3768 break;
3769
3770 default:
3771 fprintf(outfile, "** Unknown option '%c'\n", pp[-1]);
3772 goto SKIP_DATA;
3773 }
3774 }
3775
3776 /* Handle compiling via the POSIX interface, which doesn't support the
3777 timing, showing, or debugging options, nor the ability to pass over
3778 local character tables. Neither does it have 16-bit support. */
3779
3780 #if !defined NOPOSIX
3781 if (posix || do_posix)
3782 {
3783 int rc;
3784 int cflags = 0;
3785
3786 if ((options & PCRE_CASELESS) != 0) cflags |= REG_ICASE;
3787 if ((options & PCRE_MULTILINE) != 0) cflags |= REG_NEWLINE;
3788 if ((options & PCRE_DOTALL) != 0) cflags |= REG_DOTALL;
3789 if ((options & PCRE_NO_AUTO_CAPTURE) != 0) cflags |= REG_NOSUB;
3790 if ((options & PCRE_UTF8) != 0) cflags |= REG_UTF8;
3791 if ((options & PCRE_UCP) != 0) cflags |= REG_UCP;
3792 if ((options & PCRE_UNGREEDY) != 0) cflags |= REG_UNGREEDY;
3793
3794 first_gotten_store = 0;
3795 rc = regcomp(&preg, (char *)p, cflags);
3796
3797 /* Compilation failed; go back for another re, skipping to blank line
3798 if non-interactive. */
3799
3800 if (rc != 0)
3801 {
3802 (void)regerror(rc, &preg, (char *)buffer, buffer_size);
3803 fprintf(outfile, "Failed: POSIX code %d: %s\n", rc, buffer);
3804 goto SKIP_DATA;
3805 }
3806 }
3807
3808 /* Handle compiling via the native interface */
3809
3810 else
3811 #endif /* !defined NOPOSIX */
3812
3813 {
3814 /* In 16- or 32-bit mode, convert the input. */
3815
3816 #ifdef SUPPORT_PCRE16
3817 if (pcre_mode == PCRE16_MODE)
3818 {
3819 switch(to16(FALSE, p, options & PCRE_UTF8, (int)strlen((char *)p)))
3820 {
3821 case -1:
3822 fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "
3823 "converted to UTF-16\n");
3824 goto SKIP_DATA;
3825
3826 case -2:
3827 fprintf(outfile, "**Failed: character value greater than 0x10ffff "
3828 "cannot be converted to UTF-16\n");
3829 goto SKIP_DATA;
3830
3831 case -3: /* "Impossible error" when to16 is called arg1 FALSE */
3832 fprintf(outfile, "**Failed: character value greater than 0xffff "
3833 "cannot be converted to 16-bit in non-UTF mode\n");
3834 goto SKIP_DATA;
3835
3836 default:
3837 break;
3838 }
3839 p = (pcre_uint8 *)buffer16;
3840 }
3841 #endif
3842
3843 #ifdef SUPPORT_PCRE32
3844 if (pcre_mode == PCRE32_MODE)
3845 {
3846 switch(to32(FALSE, p, options & PCRE_UTF32, (int)strlen((char *)p)))
3847 {
3848 case -1:
3849 fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "
3850 "converted to UTF-32\n");
3851 goto SKIP_DATA;
3852
3853 case -2:
3854 fprintf(outfile, "**Failed: character value greater than 0x10ffff "
3855 "cannot be converted to UTF-32\n");
3856 goto SKIP_DATA;
3857
3858 case -3:
3859 fprintf(outfile, "**Failed: character value is ill-formed UTF-32\n");
3860 goto SKIP_DATA;
3861
3862 default:
3863 break;
3864 }
3865 p = (pcre_uint8 *)buffer32;
3866 }
3867 #endif
3868
3869 /* Compile many times when timing */
3870
3871 if (timeit > 0)
3872 {
3873 register int i;
3874 clock_t time_taken;
3875 clock_t start_time = clock();
3876 for (i = 0; i < timeit; i++)
3877 {
3878 PCRE_COMPILE(re, p, options, &error, &erroroffset, tables);
3879 if (re != NULL) free(re);
3880 }
3881 time_taken = clock() - start_time;
3882 fprintf(outfile, "Compile time %.4f milliseconds\n",
3883 (((double)time_taken * 1000.0) / (double)timeit) /
3884 (double)CLOCKS_PER_SEC);
3885 }
3886
3887 first_gotten_store = 0;
3888 PCRE_COMPILE(re, p, options, &error, &erroroffset, tables);
3889
3890 /* Compilation failed; go back for another re, skipping to blank line
3891 if non-interactive. */
3892
3893 if (re == NULL)
3894 {
3895 fprintf(outfile, "Failed: %s at offset %d\n", error, erroroffset);
3896 SKIP_DATA:
3897 if (infile != stdin)
3898 {
3899 for (;;)
3900 {
3901 if (extend_inputline(infile, buffer, NULL) == NULL)
3902 {
3903 done = 1;
3904 goto CONTINUE;
3905 }
3906 len = (int)strlen((char *)buffer);
3907 while (len > 0 && isspace(buffer[len-1])) len--;
3908 if (len == 0) break;
3909 }
3910 fprintf(outfile, "\n");
3911 }
3912 goto CONTINUE;
3913 }
3914
3915 /* Compilation succeeded. It is now possible to set the UTF-8 option from
3916 within the regex; check for this so that we know how to process the data
3917 lines. */
3918
3919 if (new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options) < 0)
3920 goto SKIP_DATA;
3921 if ((get_options & PCRE_UTF8) != 0) use_utf = 1;
3922
3923 /* Extract the size for possible writing before possibly flipping it,
3924 and remember the store that was got. */
3925
3926 true_size = REAL_PCRE_SIZE(re);
3927 regex_gotten_store = first_gotten_store;
3928
3929 /* Output code size information if requested */
3930
3931 if (log_store)
3932 {
3933 int name_count, name_entry_size, real_pcre_size;
3934
3935 new_info(re, NULL, PCRE_INFO_NAMECOUNT, &name_count);
3936 new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);
3937 real_pcre_size = 0;
3938 #ifdef SUPPORT_PCRE8
3939 if (REAL_PCRE_FLAGS(re) & PCRE_MODE8)
3940 real_pcre_size = sizeof(real_pcre);
3941 #endif
3942 #ifdef SUPPORT_PCRE16
3943 if (REAL_PCRE_FLAGS(re) & PCRE_MODE16)
3944 real_pcre_size = sizeof(real_pcre16);
3945 #endif
3946 #ifdef SUPPORT_PCRE32
3947 if (REAL_PCRE_FLAGS(re) & PCRE_MODE32)
3948 real_pcre_size = sizeof(real_pcre32);
3949 #endif
3950 fprintf(outfile, "Memory allocation (code space): %d\n",
3951 (int)(first_gotten_store - real_pcre_size - name_count * name_entry_size));
3952 }
3953
3954 /* If -s or /S was present, study the regex to generate additional info to
3955 help with the matching, unless the pattern has the SS option, which
3956 suppresses the effect of /S (used for a few test patterns where studying is
3957 never sensible). */
3958
3959 if (do_study || (force_study >= 0 && !no_force_study))
3960 {
3961 if (timeit > 0)
3962 {
3963 register int i;
3964 clock_t time_taken;
3965 clock_t start_time = clock();
3966 for (i = 0; i < timeit; i++)
3967 {
3968 PCRE_STUDY(extra, re, study_options, &error);
3969 }
3970 time_taken = clock() - start_time;
3971 if (extra != NULL)
3972 {
3973 PCRE_FREE_STUDY(extra);
3974 }
3975 fprintf(outfile, " Study time %.4f milliseconds\n",
3976 (((double)time_taken * 1000.0) / (double)timeit) /
3977 (double)CLOCKS_PER_SEC);
3978 }
3979 PCRE_STUDY(extra, re, study_options, &error);
3980 if (error != NULL)
3981 fprintf(outfile, "Failed to study: %s\n", error);
3982 else if (extra != NULL)
3983 {
3984 true_study_size = ((pcre_study_data *)(extra->study_data))->size;
3985 if (log_store)
3986 {
3987 size_t jitsize;
3988 if (new_info(re, extra, PCRE_INFO_JITSIZE, &jitsize) == 0 &&
3989 jitsize != 0)
3990 fprintf(outfile, "Memory allocation (JIT code): %d\n", (int)jitsize);
3991 }
3992 }
3993 }
3994
3995 /* If /K was present, we set up for handling MARK data. */
3996
3997 if (do_mark)
3998 {
3999 if (extra == NULL)
4000 {
4001 extra = (pcre_extra *)malloc(sizeof(pcre_extra));
4002 extra->flags = 0;
4003 }
4004 extra->mark = &markptr;
4005 extra->flags |= PCRE_EXTRA_MARK;
4006 }
4007
4008 /* Extract and display information from the compiled data if required. */
4009
4010 SHOW_INFO:
4011
4012 if (do_debug)
4013 {
4014 fprintf(outfile, "------------------------------------------------------------------\n");
4015 PCRE_PRINTINT(re, outfile, debug_lengths);
4016 }
4017
4018 /* We already have the options in get_options (see above) */
4019
4020 if (do_showinfo)
4021 {
4022 unsigned long int all_options;
4023 pcre_uint32 first_char, need_char;
4024 int count, backrefmax, first_char_set, need_char_set, okpartial, jchanged,
4025 hascrorlf, maxlookbehind;
4026 int nameentrysize, namecount;
4027 const pcre_uint8 *nametable;
4028
4029 if (new_info(re, NULL, PCRE_INFO_SIZE, &size) +
4030 new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count) +
4031 new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax) +
4032 new_info(re, NULL, PCRE_INFO_FIRSTCHARACTER, &first_char) +
4033 new_info(re, NULL, PCRE_INFO_FIRSTCHARACTERFLAGS, &first_char_set) +
4034 new_info(re, NULL, PCRE_INFO_REQUIREDCHAR, &need_char) +
4035 new_info(re, NULL, PCRE_INFO_REQUIREDCHARFLAGS, &need_char_set) +
4036 new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &nameentrysize) +
4037 new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount) +
4038 new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable) +
4039 new_info(re, NULL, PCRE_INFO_OKPARTIAL, &okpartial) +
4040 new_info(re, NULL, PCRE_INFO_JCHANGED, &jchanged) +
4041 new_info(re, NULL, PCRE_INFO_HASCRORLF, &hascrorlf) +
4042 new_info(re, NULL, PCRE_INFO_MAXLOOKBEHIND, &maxlookbehind)
4043 != 0)
4044 goto SKIP_DATA;
4045
4046 if (size != regex_gotten_store) fprintf(outfile,
4047 "Size disagreement: pcre_fullinfo=%d call to malloc for %d\n",
4048 (int)size, (int)regex_gotten_store);
4049
4050 fprintf(outfile, "Capturing subpattern count = %d\n", count);
4051 if (backrefmax > 0)
4052 fprintf(outfile, "Max back reference = %d\n", backrefmax);
4053
4054 if (namecount > 0)
4055 {
4056 fprintf(outfile, "Named capturing subpatterns:\n");
4057 while (namecount-- > 0)
4058 {
4059 int imm2_size = pcre_mode == PCRE8_MODE ? 2 : 1;
4060 int length = (int)STRLEN(nametable + imm2_size);
4061 fprintf(outfile, " ");
4062 PCHARSV(nametable, imm2_size, length, outfile);
4063 while (length++ < nameentrysize - imm2_size) putc(' ', outfile);
4064 #ifdef SUPPORT_PCRE32
4065 if (pcre_mode == PCRE32_MODE)
4066 fprintf(outfile, "%3d\n", (int)(((PCRE_SPTR32)nametable)[0]));
4067 #endif
4068 #ifdef SUPPORT_PCRE16
4069 if (pcre_mode == PCRE16_MODE)
4070 fprintf(outfile, "%3d\n", (int)(((PCRE_SPTR16)nametable)[0]));
4071 #endif
4072 #ifdef SUPPORT_PCRE8
4073 if (pcre_mode == PCRE8_MODE)
4074 fprintf(outfile, "%3d\n", ((int)nametable[0] << 8) | (int)nametable[1]);
4075 #endif
4076 nametable += nameentrysize * CHAR_SIZE;
4077 }
4078 }
4079
4080 if (!okpartial) fprintf(outfile, "Partial matching not supported\n");
4081 if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");
4082
4083 all_options = REAL_PCRE_OPTIONS(re);
4084 if (do_flip) all_options = swap_uint32(all_options);
4085
4086 if (get_options == 0) fprintf(outfile, "No options\n");
4087 else fprintf(outfile, "Options:%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
4088 ((get_options & PCRE_ANCHORED) != 0)? " anchored" : "",
4089 ((get_options & PCRE_CASELESS) != 0)? " caseless" : "",
4090 ((get_options & PCRE_EXTENDED) != 0)? " extended" : "",
4091 ((get_options & PCRE_MULTILINE) != 0)? " multiline" : "",
4092 ((get_options & PCRE_FIRSTLINE) != 0)? " firstline" : "",
4093 ((get_options & PCRE_DOTALL) != 0)? " dotall" : "",
4094 ((get_options & PCRE_BSR_ANYCRLF) != 0)? " bsr_anycrlf" : "",
4095 ((get_options & PCRE_BSR_UNICODE) != 0)? " bsr_unicode" : "",
4096 ((get_options & PCRE_DOLLAR_ENDONLY) != 0)? " dollar_endonly" : "",
4097 ((get_options & PCRE_EXTRA) != 0)? " extra" : "",
4098 ((get_options & PCRE_UNGREEDY) != 0)? " ungreedy" : "",
4099 ((get_options & PCRE_NO_AUTO_CAPTURE) != 0)? " no_auto_capture" : "",
4100 ((get_options & PCRE_UTF8) != 0)? " utf" : "",
4101 ((get_options & PCRE_UCP) != 0)? " ucp" : "",
4102 ((get_options & PCRE_NO_UTF8_CHECK) != 0)? " no_utf_check" : "",
4103 ((get_options & PCRE_NO_START_OPTIMIZE) != 0)? " no_start_optimize" : "",
4104 ((get_options & PCRE_DUPNAMES) != 0)? " dupnames" : "");
4105
4106 if (jchanged) fprintf(outfile, "Duplicate name status changes\n");
4107
4108 switch (get_options & PCRE_NEWLINE_BITS)
4109 {
4110 case PCRE_NEWLINE_CR:
4111 fprintf(outfile, "Forced newline sequence: CR\n");
4112 break;
4113
4114 case PCRE_NEWLINE_LF:
4115 fprintf(outfile, "Forced newline sequence: LF\n");
4116 break;
4117
4118 case PCRE_NEWLINE_CRLF:
4119 fprintf(outfile, "Forced newline sequence: CRLF\n");
4120 break;
4121
4122 case PCRE_NEWLINE_ANYCRLF:
4123 fprintf(outfile, "Forced newline sequence: ANYCRLF\n");
4124 break;
4125
4126 case PCRE_NEWLINE_ANY:
4127 fprintf(outfile, "Forced newline sequence: ANY\n");
4128 break;
4129
4130 default:
4131 break;
4132 }
4133
4134 if (first_char_set == 2)
4135 {
4136 fprintf(outfile, "First char at start or follows newline\n");
4137 }
4138 else if (first_char_set == 1)
4139 {
4140 const char *caseless =
4141 ((REAL_PCRE_FLAGS(re) & PCRE_FCH_CASELESS) == 0)?
4142 "" : " (caseless)";
4143
4144 if (PRINTOK(first_char))
4145 fprintf(outfile, "First char = \'%c\'%s\n", first_char, caseless);
4146 else
4147 {
4148 fprintf(outfile, "First char = ");
4149 pchar(first_char, outfile);
4150 fprintf(outfile, "%s\n", caseless);
4151 }
4152 }
4153 else
4154 {
4155 fprintf(outfile, "No first char\n");
4156 }
4157
4158 if (need_char_set == 0)
4159 {
4160 fprintf(outfile, "No need char\n");
4161 }
4162 else
4163 {
4164 const char *caseless =
4165 ((REAL_PCRE_FLAGS(re) & PCRE_RCH_CASELESS) == 0)?
4166 "" : " (caseless)";
4167
4168 if (PRINTOK(need_char))
4169 fprintf(outfile, "Need char = \'%c\'%s\n", need_char, caseless);
4170 else
4171 {
4172 fprintf(outfile, "Need char = ");
4173 pchar(need_char, outfile);
4174 fprintf(outfile, "%s\n", caseless);
4175 }
4176 }
4177
4178 if (maxlookbehind > 0)
4179 fprintf(outfile, "Max lookbehind = %d\n", maxlookbehind);
4180
4181 /* Don't output study size; at present it is in any case a fixed
4182 value, but it varies, depending on the computer architecture, and
4183 so messes up the test suite. (And with the /F option, it might be
4184 flipped.) If study was forced by an external -s, don't show this
4185 information unless -i or -d was also present. This means that, except
4186 when auto-callouts are involved, the output from runs with and without
4187 -s should be identical. */
4188
4189 if (do_study || (force_study >= 0 && showinfo && !no_force_study))
4190 {
4191 if (extra == NULL)
4192 fprintf(outfile, "Study returned NULL\n");
4193 else
4194 {
4195 pcre_uint8 *start_bits = NULL;
4196 int minlength;
4197
4198 if (new_info(re, extra, PCRE_INFO_MINLENGTH, &minlength) == 0)
4199 fprintf(outfile, "Subject length lower bound = %d\n", minlength);
4200
4201 if (new_info(re, extra, PCRE_INFO_FIRSTTABLE, &start_bits) == 0)
4202 {
4203 if (start_bits == NULL)
4204 fprintf(outfile, "No set of starting bytes\n");
4205 else
4206 {
4207 int i;
4208 int c = 24;
4209 fprintf(outfile, "Starting byte set: ");
4210 for (i = 0; i < 256; i++)
4211 {
4212 if ((start_bits[i/8] & (1<<(i&7))) != 0)
4213 {
4214 if (c > 75)
4215 {
4216 fprintf(outfile, "\n ");
4217 c = 2;
4218 }
4219 if (PRINTOK(i) && i != ' ')
4220 {
4221 fprintf(outfile, "%c ", i);
4222 c += 2;
4223 }
4224 else
4225 {
4226 fprintf(outfile, "\\x%02x ", i);
4227 c += 5;
4228 }
4229 }
4230 }
4231 fprintf(outfile, "\n");
4232 }
4233 }
4234 }
4235
4236 /* Show this only if the JIT was set by /S, not by -s. */
4237
4238 if ((study_options & PCRE_STUDY_ALLJIT) != 0 &&
4239 (force_study_options & PCRE_STUDY_ALLJIT) == 0)
4240 {
4241 int jit;
4242 if (new_info(re, extra, PCRE_INFO_JIT, &jit) == 0)
4243 {
4244 if (jit)
4245 fprintf(outfile, "JIT study was successful\n");
4246 else
4247 #ifdef SUPPORT_JIT
4248 fprintf(outfile, "JIT study was not successful\n");
4249 #else
4250 fprintf(outfile, "JIT support is not available in this version of PCRE\n");
4251 #endif
4252 }
4253 }
4254 }
4255 }
4256
4257 /* If the '>' option was present, we write out the regex to a file, and
4258 that is all. The first 8 bytes of the file are the regex length and then
4259 the study length, in big-endian order. */
4260
4261 if (to_file != NULL)
4262 {
4263 FILE *f = fopen((char *)to_file, "wb");
4264 if (f == NULL)
4265 {
4266 fprintf(outfile, "Unable to open %s: %s\n", to_file, strerror(errno));
4267 }
4268 else
4269 {
4270 pcre_uint8 sbuf[8];
4271
4272 if (do_flip) regexflip(re, extra);
4273 sbuf[0] = (pcre_uint8)((true_size >> 24) & 255);
4274 sbuf[1] = (pcre_uint8)((true_size >> 16) & 255);
4275 sbuf[2] = (pcre_uint8)((true_size >> 8) & 255);
4276 sbuf[3] = (pcre_uint8)((true_size) & 255);
4277 sbuf[4] = (pcre_uint8)((true_study_size >> 24) & 255);
4278 sbuf[5] = (pcre_uint8)((true_study_size >> 16) & 255);
4279 sbuf[6] = (pcre_uint8)((true_study_size >> 8) & 255);
4280 sbuf[7] = (pcre_uint8)((true_study_size) & 255);
4281
4282 if (fwrite(sbuf, 1, 8, f) < 8 ||
4283 fwrite(re, 1, true_size, f) < true_size)
4284 {
4285 fprintf(outfile, "Write error on %s: %s\n", to_file, strerror(errno));
4286 }
4287 else
4288 {
4289 fprintf(outfile, "Compiled pattern written to %s\n", to_file);
4290
4291 /* If there is study data, write it. */
4292
4293 if (extra != NULL)
4294 {
4295 if (fwrite(extra->study_data, 1, true_study_size, f) <
4296 true_study_size)
4297 {
4298 fprintf(outfile, "Write error on %s: %s\n", to_file,
4299 strerror(errno));
4300 }
4301 else fprintf(outfile, "Study data written to %s\n", to_file);
4302 }
4303 }
4304 fclose(f);
4305 }
4306
4307 new_free(re);
4308 if (extra != NULL)
4309 {
4310 PCRE_FREE_STUDY(extra);
4311 }
4312 if (locale_set)
4313 {
4314 new_free((void *)tables);
4315 setlocale(LC_CTYPE, "C");
4316 locale_set = 0;
4317 }
4318 continue; /* With next regex */
4319 }
4320 } /* End of non-POSIX compile */
4321
4322 /* Read data lines and test them */
4323
4324 for (;;)
4325 {
4326 #ifdef SUPPORT_PCRE8
4327 pcre_uint8 *q8;
4328 #endif
4329 #ifdef SUPPORT_PCRE16
4330 pcre_uint16 *q16;
4331 #endif
4332 #ifdef SUPPORT_PCRE32
4333 pcre_uint32 *q32;
4334 #endif
4335 pcre_uint8 *bptr;
4336 int *use_offsets = offsets;
4337 int use_size_offsets = size_offsets;
4338 int callout_data = 0;
4339 int callout_data_set = 0;
4340 int count;
4341 pcre_uint32 c;
4342 int copystrings = 0;
4343 int find_match_limit = default_find_match_limit;
4344 int getstrings = 0;
4345 int getlist = 0;
4346 int gmatched = 0;
4347 int start_offset = 0;
4348 int start_offset_sign = 1;
4349 int g_notempty = 0;
4350 int use_dfa = 0;
4351
4352 *copynames = 0;
4353 *getnames = 0;
4354
4355 #ifdef SUPPORT_PCRE32
4356 cn32ptr = copynames;
4357 gn32ptr = getnames;
4358 #endif
4359 #ifdef SUPPORT_PCRE16
4360 cn16ptr = copynames16;
4361 gn16ptr = getnames16;
4362 #endif
4363 #ifdef SUPPORT_PCRE8
4364 cn8ptr = copynames8;
4365 gn8ptr = getnames8;
4366 #endif
4367
4368 SET_PCRE_CALLOUT(callout);
4369 first_callout = 1;
4370 last_callout_mark = NULL;
4371 callout_extra = 0;
4372 callout_count = 0;
4373 callout_fail_count = 999999;
4374 callout_fail_id = -1;
4375 show_malloc = 0;
4376 options = 0;
4377
4378 if (extra != NULL) extra->flags &=
4379 ~(PCRE_EXTRA_MATCH_LIMIT|PCRE_EXTRA_MATCH_LIMIT_RECURSION);
4380
4381 len = 0;
4382 for (;;)
4383 {
4384 if (extend_inputline(infile, buffer + len, "data> ") == NULL)
4385 {
4386 if (len > 0) /* Reached EOF without hitting a newline */
4387 {
4388 fprintf(outfile, "\n");
4389 break;
4390 }
4391 done = 1;
4392 goto CONTINUE;
4393 }
4394 if (infile != stdin) fprintf(outfile, "%s", (char *)buffer);
4395 len = (int)strlen((char *)buffer);
4396 if (buffer[len-1] == '\n') break;
4397 }
4398
4399 while (len > 0 && isspace(buffer[len-1])) len--;
4400 buffer[len] = 0;
4401 if (len == 0) break;
4402
4403 p = buffer;
4404 while (isspace(*p)) p++;
4405
4406 #ifndef NOUTF
4407 /* Check that the data is well-formed UTF-8 if we're in UTF mode. To create
4408 invalid input to pcre_exec, you must use \x?? or \x{} sequences. */
4409 if (use_utf)
4410 {
4411 pcre_uint8 *q;
4412 pcre_uint32 cc;
4413 int n = 1;
4414
4415 for (q = p; n > 0 && *q; q += n) n = utf82ord(q, &cc);
4416 if (n <= 0)
4417 {
4418 fprintf(outfile, "**Failed: invalid UTF-8 string cannot be used as input in UTF mode\n");
4419 goto NEXT_DATA;
4420 }
4421 }
4422 #endif
4423
4424 #ifdef SUPPORT_VALGRIND
4425 /* Mark the dbuffer as addressable but undefined again. */
4426 if (dbuffer != NULL)
4427 {
4428 VALGRIND_MAKE_MEM_UNDEFINED(dbuffer, dbuffer_size * CHAR_SIZE);
4429 }
4430 #endif
4431
4432 /* Allocate a buffer to hold the data line. len+1 is an upper bound on
4433 the number of pcre_uchar units that will be needed. */
4434 if (dbuffer == NULL || (size_t)len >= dbuffer_size)
4435 {
4436 dbuffer_size *= 2;
4437 dbuffer = (pcre_uint8 *)realloc(dbuffer, dbuffer_size * CHAR_SIZE);
4438 if (dbuffer == NULL)
4439 {
4440 fprintf(stderr, "pcretest: malloc(%d) failed\n", (int)dbuffer_size);
4441 exit(1);
4442 }
4443 }
4444
4445 #ifdef SUPPORT_PCRE8
4446 q8 = (pcre_uint8 *) dbuffer;
4447 #endif
4448 #ifdef SUPPORT_PCRE16
4449 q16 = (pcre_uint16 *) dbuffer;
4450 #endif
4451 #ifdef SUPPORT_PCRE32
4452 q32 = (pcre_uint32 *) dbuffer;
4453 #endif
4454
4455 while ((c = *p++) != 0)
4456 {
4457 int i = 0;
4458 int n = 0;
4459
4460 /* In UTF mode, input can be UTF-8, so just copy all non-backslash bytes.
4461 In non-UTF mode, allow the value of the byte to fall through to later,
4462 where values greater than 127 are turned into UTF-8 when running in
4463 16-bit or 32-bit mode. */
4464
4465 if (c != '\\')
4466 {
4467 #ifndef NOUTF
4468 if (use_utf && HASUTF8EXTRALEN(c)) { GETUTF8INC(c, p); }
4469 #endif
4470 }
4471
4472 /* Handle backslash escapes */
4473
4474 else switch ((c = *p++))
4475 {
4476 case 'a': c = 7; break;
4477 case 'b': c = '\b'; break;
4478 case 'e': c = 27; break;
4479 case 'f': c = '\f'; break;
4480 case 'n': c = '\n'; break;
4481 case 'r': c = '\r'; break;
4482 case 't': c = '\t'; break;
4483 case 'v': c = '\v'; break;
4484
4485 case '0': case '1': case '2': case '3':
4486 case '4': case '5': case '6': case '7':
4487 c -= '0';
4488 while (i++ < 2 && isdigit(*p) && *p != '8' && *p != '9')
4489 c = c * 8 + *p++ - '0';
4490 break;
4491
4492 case 'x':
4493 if (*p == '{')
4494 {
4495 pcre_uint8 *pt = p;
4496 c = 0;
4497
4498 /* We used to have "while (isxdigit(*(++pt)))" here, but it fails
4499 when isxdigit() is a macro that refers to its argument more than
4500 once. This is banned by the C Standard, but apparently happens in at
4501 least one MacOS environment. */
4502
4503 for (pt++; isxdigit(*pt); pt++)
4504 {
4505 if (++i == 9)
4506 fprintf(outfile, "** Too many hex digits in \\x{...} item; "
4507 "using only the first eight.\n");
4508 else c = c * 16 + tolower(*pt) - ((isdigit(*pt))? '0' : 'a' - 10);
4509 }
4510 if (*pt == '}')
4511 {
4512 p = pt + 1;
4513 break;
4514 }
4515 /* Not correct form for \x{...}; fall through */
4516 }
4517
4518 /* \x without {} always defines just one byte in 8-bit mode. This
4519 allows UTF-8 characters to be constructed byte by byte, and also allows
4520 invalid UTF-8 sequences to be made. Just copy the byte in UTF mode.
4521 Otherwise, pass it down to later code so that it can be turned into
4522 UTF-8 when running in 16/32-bit mode. */
4523
4524 c = 0;
4525 while (i++ < 2 && isxdigit(*p))
4526 {
4527 c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'a' - 10);
4528 p++;
4529 }
4530 #if !defined NOUTF && defined SUPPORT_PCRE8
4531 if (use_utf && (pcre_mode == PCRE8_MODE))
4532 {
4533 *q8++ = c;
4534 continue;
4535 }
4536 #endif
4537 break;
4538
4539 case 0: /* \ followed by EOF allows for an empty line */
4540 p--;
4541 continue;
4542
4543 case '>':
4544 if (*p == '-')
4545 {
4546 start_offset_sign = -1;
4547 p++;
4548 }
4549 while(isdigit(*p)) start_offset = start_offset * 10 + *p++ - '0';
4550 start_offset *= start_offset_sign;
4551 continue;
4552
4553 case 'A': /* Option setting */
4554 options |= PCRE_ANCHORED;
4555 continue;
4556
4557 case 'B':
4558 options |= PCRE_NOTBOL;
4559 continue;
4560
4561 case 'C':
4562 if (isdigit(*p)) /* Set copy string */
4563 {
4564 while(isdigit(*p)) n = n * 10 + *p++ - '0';
4565 copystrings |= 1 << n;
4566 }
4567 else if (isalnum(*p))
4568 {
4569 READ_CAPTURE_NAME(p, &cn8ptr, &cn16ptr, &cn32ptr, re);
4570 }
4571 else if (*p == '+')
4572 {
4573 callout_extra = 1;
4574 p++;
4575 }
4576 else if (*p == '-')
4577 {
4578 SET_PCRE_CALLOUT(NULL);
4579 p++;
4580 }
4581 else if (*p == '!')
4582 {
4583 callout_fail_id = 0;
4584 p++;
4585 while(isdigit(*p))
4586 callout_fail_id = callout_fail_id * 10 + *p++ - '0';
4587 callout_fail_count = 0;
4588 if (*p == '!')
4589 {
4590 p++;
4591 while(isdigit(*p))
4592 callout_fail_count = callout_fail_count * 10 + *p++ - '0';
4593 }
4594 }
4595 else if (*p == '*')
4596 {
4597 int sign = 1;
4598 callout_data = 0;
4599 if (*(++p) == '-') { sign = -1; p++; }
4600 while(isdigit(*p))
4601 callout_data = callout_data * 10 + *p++ - '0';
4602 callout_data *= sign;
4603 callout_data_set = 1;
4604 }
4605 continue;
4606
4607 #if !defined NODFA
4608 case 'D':
4609 #if !defined NOPOSIX
4610 if (posix || do_posix)
4611 printf("** Can't use dfa matching in POSIX mode: \\D ignored\n");
4612 else
4613 #endif
4614 use_dfa = 1;
4615 continue;
4616 #endif
4617
4618 #if !defined NODFA
4619 case 'F':
4620 options |= PCRE_DFA_SHORTEST;
4621 continue;
4622 #endif
4623
4624 case 'G':
4625 if (isdigit(*p))
4626 {
4627 while(isdigit(*p)) n = n * 10 + *p++ - '0';
4628 getstrings |= 1 << n;
4629 }
4630 else if (isalnum(*p))
4631 {
4632 READ_CAPTURE_NAME(p, &gn8ptr, &gn16ptr, &gn32ptr, re);
4633 }
4634 continue;
4635
4636 case 'J':
4637 while(isdigit(*p)) n = n * 10 + *p++ - '0';
4638 if (extra != NULL
4639 && (extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0
4640 && extra->executable_jit != NULL)
4641 {
4642 if (jit_stack != NULL) { PCRE_JIT_STACK_FREE(jit_stack); }
4643 jit_stack = PCRE_JIT_STACK_ALLOC(1, n * 1024);
4644 PCRE_ASSIGN_JIT_STACK(extra, jit_callback, jit_stack);
4645 }
4646 continue;
4647
4648 case 'L':
4649 getlist = 1;
4650 continue;
4651
4652 case 'M':
4653 find_match_limit = 1;
4654 continue;
4655
4656 case 'N':
4657 if ((options & PCRE_NOTEMPTY) != 0)
4658 options = (options & ~PCRE_NOTEMPTY) | PCRE_NOTEMPTY_ATSTART;
4659 else
4660 options |= PCRE_NOTEMPTY;
4661 continue;
4662
4663 case 'O':
4664 while(isdigit(*p)) n = n * 10 + *p++ - '0';
4665 if (n > size_offsets_max)
4666 {
4667 size_offsets_max = n;
4668 free(offsets);
4669 use_offsets = offsets = (int *)malloc(size_offsets_max * sizeof(int));
4670 if (offsets == NULL)
4671 {
4672 printf("** Failed to get %d bytes of memory for offsets vector\n",
4673 (int)(size_offsets_max * sizeof(int)));
4674 yield = 1;
4675 goto EXIT;
4676 }
4677 }
4678 use_size_offsets = n;
4679 if (n == 0) use_offsets = NULL; /* Ensures it can't write to it */
4680 else use_offsets = offsets + size_offsets_max - n; /* To catch overruns */
4681 continue;
4682
4683 case 'P':
4684 options |= ((options & PCRE_PARTIAL_SOFT) == 0)?
4685 PCRE_PARTIAL_SOFT : PCRE_PARTIAL_HARD;
4686 continue;
4687
4688 case 'Q':
4689 while(isdigit(*p)) n = n * 10 + *p++ - '0';
4690 if (extra == NULL)
4691 {
4692 extra = (pcre_extra *)malloc(sizeof(pcre_extra));
4693 extra->flags = 0;
4694 }
4695 extra->flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION;
4696 extra->match_limit_recursion = n;
4697 continue;
4698
4699 case 'q':
4700 while(isdigit(*p)) n = n * 10 + *p++ - '0';
4701 if (extra == NULL)
4702 {
4703 extra = (pcre_extra *)malloc(sizeof(pcre_extra));
4704 extra->flags = 0;
4705 }
4706 extra->flags |= PCRE_EXTRA_MATCH_LIMIT;
4707 extra->match_limit = n;
4708 continue;
4709
4710 #if !defined NODFA
4711 case 'R':
4712 options |= PCRE_DFA_RESTART;
4713 continue;
4714 #endif
4715
4716 case 'S':
4717 show_malloc = 1;
4718 continue;
4719
4720 case 'Y':
4721 options |= PCRE_NO_START_OPTIMIZE;
4722 continue;
4723
4724 case 'Z':
4725 options |= PCRE_NOTEOL;
4726 continue;
4727
4728 case '?':
4729 options |= PCRE_NO_UTF8_CHECK;
4730 continue;
4731
4732 case '<':
4733 {
4734 int x = check_newline(p, outfile);
4735 if (x == 0) goto NEXT_DATA;
4736 options |= x;
4737 while (*p++ != '>');
4738 }
4739 continue;
4740 }
4741
4742 /* We now have a character value in c that may be greater than 255.
4743 In 8-bit mode we convert to UTF-8 if we are in UTF mode. Values greater
4744 than 127 in UTF mode must have come from \x{...} or octal constructs
4745 because values from \x.. get this far only in non-UTF mode. */
4746
4747 #ifdef SUPPORT_PCRE8
4748 if (pcre_mode == PCRE8_MODE)
4749 {
4750 #ifndef NOUTF
4751 if (use_utf)
4752 {
4753 if (c > 0x7fffffff)
4754 {
4755 fprintf(outfile, "** Character \\x{%x} is greater than 0x7fffffff "
4756 "and so cannot be converted to UTF-8\n", c);
4757 goto NEXT_DATA;
4758 }
4759 q8 += ord2utf8(c, q8);
4760 }
4761 else
4762 #endif
4763 {
4764 if (c > 0xffu)
4765 {
4766 fprintf(outfile, "** Character \\x{%x} is greater than 255 "
4767 "and UTF-8 mode is not enabled.\n", c);
4768 fprintf(outfile, "** Truncation will probably give the wrong "
4769 "result.\n");
4770 }
4771 *q8++ = c;
4772 }
4773 }
4774 #endif
4775 #ifdef SUPPORT_PCRE16
4776 if (pcre_mode == PCRE16_MODE)
4777 {
4778 #ifndef NOUTF
4779 if (use_utf)
4780 {
4781 if (c > 0x10ffffu)
4782 {
4783 fprintf(outfile, "** Failed: character \\x{%x} is greater than "
4784 "0x10ffff and so cannot be converted to UTF-16\n", c);
4785 goto NEXT_DATA;
4786 }
4787 else if (c >= 0x10000u)
4788 {
4789 c-= 0x10000u;
4790 *q16++ = 0xD800 | (c >> 10);
4791 *q16++ = 0xDC00 | (c & 0x3ff);
4792 }
4793 else
4794 *q16++ = c;
4795 }
4796 else
4797 #endif
4798 {
4799 if (c > 0xffffu)
4800 {
4801 fprintf(outfile, "** Character \\x{%x} is greater than 0xffff "
4802 "and UTF-16 mode is not enabled.\n", c);
4803 fprintf(outfile, "** Truncation will probably give the wrong "
4804 "result.\n");
4805 }
4806
4807 *q16++ = c;
4808 }
4809 }
4810 #endif
4811 #ifdef SUPPORT_PCRE32
4812 if (pcre_mode == PCRE32_MODE)
4813 {
4814 *q32++ = c;
4815 }
4816 #endif
4817
4818 }
4819
4820 /* Reached end of subject string */
4821
4822 #ifdef SUPPORT_PCRE8
4823 if (pcre_mode == PCRE8_MODE)
4824 {
4825 *q8 = 0;
4826 len = (int)(q8 - (pcre_uint8 *)dbuffer);
4827 }
4828 #endif
4829 #ifdef SUPPORT_PCRE16
4830 if (pcre_mode == PCRE16_MODE)
4831 {
4832 *q16 = 0;
4833 len = (int)(q16 - (pcre_uint16 *)dbuffer);
4834 }
4835 #endif
4836 #ifdef SUPPORT_PCRE32
4837 if (pcre_mode == PCRE32_MODE)
4838 {
4839 *q32 = 0;
4840 len = (int)(q32 - (pcre_uint32 *)dbuffer);
4841 }
4842 #endif
4843
4844 /* If we're compiling with explicit valgrind support, Mark the data from after
4845 its end to the end of the buffer as unaddressable, so that a read over the end
4846 of the buffer will be seen by valgrind, even if it doesn't cause a crash.
4847 If we're not building with valgrind support, at least move the data to the end
4848 of the buffer so that it might at least cause a crash.
4849 If we are using the POSIX interface, we must include the terminating zero. */
4850
4851 bptr = dbuffer;
4852
4853 #if !defined NOPOSIX
4854 if (posix || do_posix)
4855 {
4856 #ifdef SUPPORT_VALGRIND
4857 VALGRIND_MAKE_MEM_NOACCESS(dbuffer + len + 1, dbuffer_size - (len + 1));
4858 #else
4859 memmove(bptr + dbuffer_size - len - 1, bptr, len + 1);
4860 bptr += dbuffer_size - len - 1;
4861 #endif
4862 }
4863 else
4864 #endif
4865 {
4866 #ifdef SUPPORT_VALGRIND
4867 VALGRIND_MAKE_MEM_NOACCESS(dbuffer + len * CHAR_SIZE, (dbuffer_size - len) * CHAR_SIZE);
4868 #else
4869 bptr = memmove(bptr + (dbuffer_size - len) * CHAR_SIZE, bptr, len * CHAR_SIZE);
4870 #endif
4871 }
4872
4873 if ((all_use_dfa || use_dfa) && find_match_limit)
4874 {
4875 printf("**Match limit not relevant for DFA matching: ignored\n");
4876 find_match_limit = 0;
4877 }
4878
4879 /* Handle matching via the POSIX interface, which does not
4880 support timing or playing with the match limit or callout data. */
4881
4882 #if !defined NOPOSIX
4883 if (posix || do_posix)
4884 {
4885 int rc;
4886 int eflags = 0;
4887 regmatch_t *pmatch = NULL;
4888 if (use_size_offsets > 0)
4889 pmatch = (regmatch_t *)malloc(sizeof(regmatch_t) * use_size_offsets);
4890 if ((options & PCRE_NOTBOL) != 0) eflags |= REG_NOTBOL;
4891 if ((options & PCRE_NOTEOL) != 0) eflags |= REG_NOTEOL;
4892 if ((options & PCRE_NOTEMPTY) != 0) eflags |= REG_NOTEMPTY;
4893
4894 rc = regexec(&preg, (const char *)bptr, use_size_offsets, pmatch, eflags);
4895
4896 if (rc != 0)
4897 {
4898 (void)regerror(rc, &preg, (char *)buffer, buffer_size);
4899 fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer);
4900 }
4901 else if ((REAL_PCRE_OPTIONS(preg.re_pcre) & PCRE_NO_AUTO_CAPTURE) != 0)
4902 {
4903 fprintf(outfile, "Matched with REG_NOSUB\n");
4904 }
4905 else
4906 {
4907 size_t i;
4908 for (i = 0; i < (size_t)use_size_offsets; i++)
4909 {
4910 if (pmatch[i].rm_so >= 0)
4911 {
4912 fprintf(outfile, "%2d: ", (int)i);
4913 PCHARSV(dbuffer, pmatch[i].rm_so,
4914 pmatch[i].rm_eo - pmatch[i].rm_so, outfile);
4915 fprintf(outfile, "\n");
4916 if (do_showcaprest || (i == 0 && do_showrest))
4917 {
4918 fprintf(outfile, "%2d+ ", (int)i);
4919 PCHARSV(dbuffer, pmatch[i].rm_eo, len - pmatch[i].rm_eo,
4920 outfile);
4921 fprintf(outfile, "\n");
4922 }
4923 }
4924 }
4925 }
4926 free(pmatch);
4927 goto NEXT_DATA;
4928 }
4929
4930 #endif /* !defined NOPOSIX */
4931
4932 /* Handle matching via the native interface - repeats for /g and /G */
4933
4934 /* Ensure that there is a JIT callback if we want to verify that JIT was
4935 actually used. If jit_stack == NULL, no stack has yet been assigned. */
4936
4937 if (verify_jit && jit_stack == NULL && extra != NULL)
4938 { PCRE_ASSIGN_JIT_STACK(extra, jit_callback, jit_stack); }
4939
4940 for (;; gmatched++) /* Loop for /g or /G */
4941 {
4942 markptr = NULL;
4943 jit_was_used = FALSE;
4944
4945 if (timeitm > 0)
4946 {
4947 register int i;
4948 clock_t time_taken;
4949 clock_t start_time = clock();
4950
4951 #if !defined NODFA
4952 if (all_use_dfa || use_dfa)
4953 {
4954 if ((options & PCRE_DFA_RESTART) != 0)
4955 {
4956 fprintf(outfile, "Timing DFA restarts is not supported\n");
4957 break;
4958 }
4959 if (dfa_workspace == NULL)
4960 dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
4961 for (i = 0; i < timeitm; i++)
4962 {
4963 PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
4964 (options | g_notempty), use_offsets, use_size_offsets,
4965 dfa_workspace, DFA_WS_DIMENSION);
4966 }
4967 }
4968 else
4969 #endif
4970
4971 for (i = 0; i < timeitm; i++)
4972 {
4973 PCRE_EXEC(count, re, extra, bptr, len, start_offset,
4974 (options | g_notempty), use_offsets, use_size_offsets);
4975 }
4976 time_taken = clock() - start_time;
4977 fprintf(outfile, "Execute time %.4f milliseconds\n",
4978 (((double)time_taken * 1000.0) / (double)timeitm) /
4979 (double)CLOCKS_PER_SEC);
4980 }
4981
4982 /* If find_match_limit is set, we want to do repeated matches with
4983 varying limits in order to find the minimum value for the match limit and
4984 for the recursion limit. The match limits are relevant only to the normal
4985 running of pcre_exec(), so disable the JIT optimization. This makes it
4986 possible to run the same set of tests with and without JIT externally
4987 requested. */
4988
4989 if (find_match_limit)
4990 {
4991 if (extra != NULL) { PCRE_FREE_STUDY(extra); }
4992 extra = (pcre_extra *)malloc(sizeof(pcre_extra));
4993 extra->flags = 0;
4994
4995 (void)check_match_limit(re, extra, bptr, len, start_offset,
4996 options|g_notempty, use_offsets, use_size_offsets,
4997 PCRE_EXTRA_MATCH_LIMIT, &(extra->match_limit),
4998 PCRE_ERROR_MATCHLIMIT, "match()");
4999
5000 count = check_match_limit(re, extra, bptr, len, start_offset,
5001 options|g_notempty, use_offsets, use_size_offsets,
5002 PCRE_EXTRA_MATCH_LIMIT_RECURSION, &(extra->match_limit_recursion),
5003 PCRE_ERROR_RECURSIONLIMIT, "match() recursion");
5004 }
5005
5006 /* If callout_data is set, use the interface with additional data */
5007
5008 else if (callout_data_set)
5009 {
5010 if (extra == NULL)
5011 {
5012 extra = (pcre_extra *)malloc(sizeof(pcre_extra));
5013 extra->flags = 0;
5014 }
5015 extra->flags |= PCRE_EXTRA_CALLOUT_DATA;
5016 extra->callout_data = &callout_data;
5017 PCRE_EXEC(count, re, extra, bptr, len, start_offset,
5018 options | g_notempty, use_offsets, use_size_offsets);
5019 extra->flags &= ~PCRE_EXTRA_CALLOUT_DATA;
5020 }
5021
5022 /* The normal case is just to do the match once, with the default
5023 value of match_limit. */
5024
5025 #if !defined NODFA
5026 else if (all_use_dfa || use_dfa)
5027 {
5028 if (dfa_workspace == NULL)
5029 dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
5030 if (dfa_matched++ == 0)
5031 dfa_workspace[0] = -1; /* To catch bad restart */
5032 PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
5033 (options | g_notempty), use_offsets, use_size_offsets, dfa_workspace,
5034 DFA_WS_DIMENSION);
5035 if (count == 0)
5036 {
5037 fprintf(outfile, "Matched, but too many subsidiary matches\n");
5038 count = use_size_offsets/2;
5039 }
5040 }
5041 #endif
5042
5043 else
5044 {
5045 PCRE_EXEC(count, re, extra, bptr, len, start_offset,
5046 options | g_notempty, use_offsets, use_size_offsets);
5047 if (count == 0)
5048 {
5049 fprintf(outfile, "Matched, but too many substrings\n");
5050 /* 2 is a special case; match can be returned */
5051 count = (use_size_offsets == 2)? 1 : use_size_offsets/3;
5052 }
5053 }
5054
5055 /* Matched */
5056
5057 if (count >= 0)
5058 {
5059 int i, maxcount;
5060 void *cnptr, *gnptr;
5061
5062 #if !defined NODFA
5063 if (all_use_dfa || use_dfa) maxcount = use_size_offsets/2; else
5064 #endif
5065 /* 2 is a special case; match can be returned */
5066 maxcount = (use_size_offsets == 2)? 1 : use_size_offsets/3;
5067
5068 /* This is a check against a lunatic return value. */
5069
5070 if (count > maxcount)
5071 {
5072 fprintf(outfile,
5073 "** PCRE error: returned count %d is too big for offset size %d\n",
5074 count, use_size_offsets);
5075 count = use_size_offsets/3;
5076 if (do_g || do_G)
5077 {
5078 fprintf(outfile, "** /%c loop abandoned\n", do_g? 'g' : 'G');
5079 do_g = do_G = FALSE; /* Break g/G loop */
5080 }
5081 }
5082
5083 /* do_allcaps requests showing of all captures in the pattern, to check
5084 unset ones at the end. */
5085
5086 if (do_allcaps)
5087 {
5088 if (new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count) < 0)
5089 goto SKIP_DATA;
5090 count++; /* Allow for full match */
5091 if (count * 2 > use_size_offsets) count = use_size_offsets/2;
5092 }
5093
5094 /* Output the captured substrings */
5095
5096 for (i = 0; i < count * 2; i += 2)
5097 {
5098 if (use_offsets[i] < 0)
5099 {
5100 if (use_offsets[i] != -1)
5101 fprintf(outfile, "ERROR: bad negative value %d for offset %d\n",
5102 use_offsets[i], i);
5103 if (use_offsets[i+1] != -1)
5104 fprintf(outfile, "ERROR: bad negative value %d for offset %d\n",
5105 use_offsets[i+1], i+1);
5106 fprintf(outfile, "%2d: <unset>\n", i/2);
5107 }
5108 else
5109 {
5110 fprintf(outfile, "%2d: ", i/2);
5111 PCHARSV(bptr, use_offsets[i],
5112 use_offsets[i+1] - use_offsets[i], outfile);
5113 if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
5114 fprintf(outfile, "\n");
5115 if (do_showcaprest || (i == 0 && do_showrest))
5116 {
5117 fprintf(outfile, "%2d+ ", i/2);
5118 PCHARSV(bptr, use_offsets[i+1], len - use_offsets[i+1],
5119 outfile);
5120 fprintf(outfile, "\n");
5121 }
5122 }
5123 }
5124
5125 if (markptr != NULL)
5126 {
5127 fprintf(outfile, "MK: ");
5128 PCHARSV(markptr, 0, -1, outfile);
5129 fprintf(outfile, "\n");
5130 }
5131
5132 for (i = 0; i < 32; i++)
5133 {
5134 if ((copystrings & (1 << i)) != 0)
5135 {
5136 int rc;
5137 char copybuffer[256];
5138 PCRE_COPY_SUBSTRING(rc, bptr, use_offsets, count, i,
5139 copybuffer, sizeof(copybuffer));
5140 if (rc < 0)
5141 fprintf(outfile, "copy substring %d failed %d\n", i, rc);
5142 else
5143 {
5144 fprintf(outfile, "%2dC ", i);
5145 PCHARSV(copybuffer, 0, rc, outfile);
5146 fprintf(outfile, " (%d)\n", rc);
5147 }
5148 }
5149 }
5150
5151 cnptr = copynames;
5152 for (;;)
5153 {
5154 int rc;
5155 char copybuffer[256];
5156
5157 #ifdef SUPPORT_PCRE32
5158 if (pcre_mode == PCRE32_MODE)
5159 {
5160 if (*(pcre_uint32 *)cnptr == 0) break;
5161 }
5162 #endif
5163 #ifdef SUPPORT_PCRE16
5164 if (pcre_mode == PCRE16_MODE)
5165 {
5166 if (*(pcre_uint16 *)cnptr == 0) break;
5167 }
5168 #endif
5169 #ifdef SUPPORT_PCRE8
5170 if (pcre_mode == PCRE8_MODE)
5171 {
5172 if (*(pcre_uint8 *)cnptr == 0) break;
5173 }
5174 #endif
5175
5176 PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,
5177 cnptr, copybuffer, sizeof(copybuffer));
5178
5179 if (rc < 0)
5180 {
5181 fprintf(outfile, "copy substring ");
5182 PCHARSV(cnptr, 0, -1, outfile);
5183 fprintf(outfile, " failed %d\n", rc);
5184 }
5185 else
5186 {
5187 fprintf(outfile, " C ");
5188 PCHARSV(copybuffer, 0, rc, outfile);
5189 fprintf(outfile, " (%d) ", rc);
5190 PCHARSV(cnptr, 0, -1, outfile);
5191 putc('\n', outfile);
5192 }
5193
5194 cnptr = (char *)cnptr + (STRLEN(cnptr) + 1) * CHAR_SIZE;
5195 }
5196
5197 for (i = 0; i < 32; i++)
5198 {
5199 if ((getstrings & (1 << i)) != 0)
5200 {
5201 int rc;
5202 const char *substring;
5203 PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, &substring);
5204 if (rc < 0)
5205 fprintf(outfile, "get substring %d failed %d\n", i, rc);
5206 else
5207 {
5208 fprintf(outfile, "%2dG ", i);
5209 PCHARSV(substring, 0, rc, outfile);
5210 fprintf(outfile, " (%d)\n", rc);
5211 PCRE_FREE_SUBSTRING(substring);
5212 }
5213 }
5214 }
5215
5216 gnptr = getnames;
5217 for (;;)
5218 {
5219 int rc;
5220 const char *substring;
5221
5222 #ifdef SUPPORT_PCRE32
5223 if (pcre_mode == PCRE32_MODE)
5224 {
5225 if (*(pcre_uint32 *)gnptr == 0) break;
5226 }
5227 #endif
5228 #ifdef SUPPORT_PCRE16
5229 if (pcre_mode == PCRE16_MODE)
5230 {
5231 if (*(pcre_uint16 *)gnptr == 0) break;
5232 }
5233 #endif
5234 #ifdef SUPPORT_PCRE8
5235 if (pcre_mode == PCRE8_MODE)
5236 {
5237 if (*(pcre_uint8 *)gnptr == 0) break;
5238 }
5239 #endif
5240
5241 PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,
5242 gnptr, &substring);
5243 if (rc < 0)
5244 {
5245 fprintf(outfile, "get substring ");
5246 PCHARSV(gnptr, 0, -1, outfile);
5247 fprintf(outfile, " failed %d\n", rc);
5248 }
5249 else
5250 {
5251 fprintf(outfile, " G ");
5252 PCHARSV(substring, 0, rc, outfile);
5253 fprintf(outfile, " (%d) ", rc);
5254 PCHARSV(gnptr, 0, -1, outfile);
5255 PCRE_FREE_SUBSTRING(substring);
5256 putc('\n', outfile);
5257 }
5258
5259 gnptr = (char *)gnptr + (STRLEN(gnptr) + 1) * CHAR_SIZE;
5260 }
5261
5262 if (getlist)
5263 {
5264 int rc;
5265 const char **stringlist;
5266 PCRE_GET_SUBSTRING_LIST(rc, bptr, use_offsets, count, &stringlist);
5267 if (rc < 0)
5268 fprintf(outfile, "get substring list failed %d\n", rc);
5269 else
5270 {
5271 for (i = 0; i < count; i++)
5272 {
5273 fprintf(outfile, "%2dL ", i);
5274 PCHARSV(stringlist[i], 0, -1, outfile);
5275 putc('\n', outfile);
5276 }
5277 if (stringlist[i] != NULL)
5278 fprintf(outfile, "string list not terminated by NULL\n");
5279 PCRE_FREE_SUBSTRING_LIST(stringlist);
5280 }
5281 }
5282 }
5283
5284 /* There was a partial match. If the bumpalong point is not the same as
5285 the first inspected character, show the offset explicitly. */
5286
5287 else if (count == PCRE_ERROR_PARTIAL)
5288 {
5289 fprintf(outfile, "Partial match");
5290 if (use_size_offsets > 2 && use_offsets[0] != use_offsets[2])
5291 fprintf(outfile, " at offset %d", use_offsets[2]);
5292 if (markptr != NULL)
5293 {
5294 fprintf(outfile, ", mark=");
5295 PCHARSV(markptr, 0, -1, outfile);
5296 }
5297 if (use_size_offsets > 1)
5298 {
5299 fprintf(outfile, ": ");
5300 PCHARSV(bptr, use_offsets[0], use_offsets[1] - use_offsets[0],
5301 outfile);
5302 }
5303 if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
5304 fprintf(outfile, "\n");
5305 break; /* Out of the /g loop */
5306 }
5307
5308 /* Failed to match. If this is a /g or /G loop and we previously set
5309 g_notempty after a null match, this is not necessarily the end. We want
5310 to advance the start offset, and continue. We won't be at the end of the
5311 string - that was checked before setting g_notempty.
5312
5313 Complication arises in the case when the newline convention is "any",
5314 "crlf", or "anycrlf". If the previous match was at the end of a line
5315 terminated by CRLF, an advance of one character just passes the \r,
5316 whereas we should prefer the longer newline sequence, as does the code in
5317 pcre_exec(). Fudge the offset value to achieve this. We check for a
5318 newline setting in the pattern; if none was set, use PCRE_CONFIG() to
5319 find the default.
5320
5321 Otherwise, in the case of UTF-8 matching, the advance must be one
5322 character, not one byte. */
5323
5324 else
5325 {
5326 if (g_notempty != 0)
5327 {
5328 int onechar = 1;
5329 unsigned int obits = REAL_PCRE_OPTIONS(re);
5330 use_offsets[0] = start_offset;
5331 if ((obits & PCRE_NEWLINE_BITS) == 0)
5332 {
5333 int d;
5334 (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &d);
5335 /* Note that these values are always the ASCII ones, even in
5336 EBCDIC environments. CR = 13, NL = 10. */
5337 obits = (d == 13)? PCRE_NEWLINE_CR :
5338 (d == 10)? PCRE_NEWLINE_LF :
5339 (d == (13<<8 | 10))? PCRE_NEWLINE_CRLF :
5340 (d == -2)? PCRE_NEWLINE_ANYCRLF :
5341 (d == -1)? PCRE_NEWLINE_ANY : 0;
5342 }
5343 if (((obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANY ||
5344 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||
5345 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)
5346 &&
5347 start_offset < len - 1 && (
5348 #ifdef SUPPORT_PCRE8
5349 (pcre_mode == PCRE8_MODE &&
5350 bptr[start_offset] == '\r' &&
5351 bptr[start_offset + 1] == '\n') ||
5352 #endif
5353 #ifdef SUPPORT_PCRE16
5354 (pcre_mode == PCRE16_MODE &&
5355 ((PCRE_SPTR16)bptr)[start_offset] == '\r' &&
5356 ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n') ||
5357 #endif
5358 #ifdef SUPPORT_PCRE32
5359 (pcre_mode == PCRE32_MODE &&
5360 ((PCRE_SPTR32)bptr)[start_offset] == '\r' &&
5361 ((PCRE_SPTR32)bptr)[start_offset + 1] == '\n') ||
5362 #endif
5363 0))
5364 onechar++;
5365 else if (use_utf)
5366 {
5367 while (start_offset + onechar < len)
5368 {
5369 if ((bptr[start_offset+onechar] & 0xc0) != 0x80) break;
5370 onechar++;
5371 }
5372 }
5373 use_offsets[1] = start_offset + onechar;
5374 }
5375 else
5376 {
5377 switch(count)
5378 {
5379 case PCRE_ERROR_NOMATCH:
5380 if (gmatched == 0)
5381 {
5382 if (markptr == NULL)
5383 {
5384 fprintf(outfile, "No match");
5385 }
5386 else
5387 {
5388 fprintf(outfile, "No match, mark = ");
5389 PCHARSV(markptr, 0, -1, outfile);
5390 }
5391 if (verify_jit && jit_was_used) fprintf(outfile, " (JIT)");
5392 putc('\n', outfile);
5393 }
5394 break;
5395
5396 case PCRE_ERROR_BADUTF8:
5397 case PCRE_ERROR_SHORTUTF8:
5398 fprintf(outfile, "Error %d (%s UTF-%d string)", count,
5399 (count == PCRE_ERROR_BADUTF8)? "bad" : "short",
5400 8 * CHAR_SIZE);
5401 if (use_size_offsets >= 2)
5402 fprintf(outfile, " offset=%d reason=%d", use_offsets[0],
5403 use_offsets[1]);
5404 fprintf(outfile, "\n");
5405 break;
5406
5407 case PCRE_ERROR_BADUTF8_OFFSET:
5408 fprintf(outfile, "Error %d (bad UTF-%d offset)\n", count,
5409 8 * CHAR_SIZE);
5410 break;
5411
5412 default:
5413 if (count < 0 &&
5414 (-count) < (int)(sizeof(errtexts)/sizeof(const char *)))
5415 fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);
5416 else
5417 fprintf(outfile, "Error %d (Unexpected value)\n", count);
5418 break;
5419 }
5420
5421 break; /* Out of the /g loop */
5422 }
5423 }
5424
5425 /* If not /g or /G we are done */
5426
5427 if (!do_g && !do_G) break;
5428
5429 /* If we have matched an empty string, first check to see if we are at
5430 the end of the subject. If so, the /g loop is over. Otherwise, mimic what
5431 Perl's /g options does. This turns out to be rather cunning. First we set
5432 PCRE_NOTEMPTY_ATSTART and PCRE_ANCHORED and try the match again at the
5433 same point. If this fails (picked up above) we advance to the next
5434 character. */
5435
5436 g_notempty = 0;
5437
5438 if (use_offsets[0] == use_offsets[1])
5439 {
5440 if (use_offsets[0] == len) break;
5441 g_notempty = PCRE_NOTEMPTY_ATSTART | PCRE_ANCHORED;
5442 }
5443
5444 /* For /g, update the start offset, leaving the rest alone */
5445
5446 if (do_g) start_offset = use_offsets[1];
5447
5448 /* For /G, update the pointer and length */
5449
5450 else
5451 {
5452 bptr += use_offsets[1] * CHAR_SIZE;
5453 len -= use_offsets[1];
5454 }
5455 } /* End of loop for /g and /G */
5456
5457 NEXT_DATA: continue;
5458 } /* End of loop for data lines */
5459
5460 CONTINUE:
5461
5462 #if !defined NOPOSIX
5463 if (posix || do_posix) regfree(&preg);
5464 #endif
5465
5466 if (re != NULL) new_free(re);
5467 if (extra != NULL)
5468 {
5469 PCRE_FREE_STUDY(extra);
5470 }
5471 if (locale_set)
5472 {
5473 new_free((void *)tables);
5474 setlocale(LC_CTYPE, "C");
5475 locale_set = 0;
5476 }
5477 if (jit_stack != NULL)
5478 {
5479 PCRE_JIT_STACK_FREE(jit_stack);
5480 jit_stack = NULL;
5481 }
5482 }
5483
5484 if (infile == stdin) fprintf(outfile, "\n");
5485
5486 EXIT:
5487
5488 if (infile != NULL && infile != stdin) fclose(infile);
5489 if (outfile != NULL && outfile != stdout) fclose(outfile);
5490
5491 free(buffer);
5492 free(dbuffer);
5493 free(pbuffer);
5494 free(offsets);
5495
5496 #ifdef SUPPORT_PCRE16
5497 if (buffer16 != NULL) free(buffer16);
5498 #endif
5499 #ifdef SUPPORT_PCRE32
5500 if (buffer32 != NULL) free(buffer32);
5501 #endif
5502
5503 #if !defined NODFA
5504 if (dfa_workspace != NULL)
5505 free(dfa_workspace);
5506 #endif
5507
5508 #if defined(__VMS)
5509 yield = SS$_NORMAL; /* Return values via DCL symbols */
5510 #endif
5511
5512 return yield;
5513 }
5514
5515 /* End of pcretest.c */

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.5