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

Diff of /code/trunk/pcretest.c

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

revision 255 by ph10, Wed Sep 19 08:50:04 2007 UTC revision 1140 by ph10, Fri Oct 19 13:41:32 2012 UTC
# Line 4  Line 4 
4    
5  /* This program was hacked up as a tester for PCRE. I really should have  /* 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  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.  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  Redistribution and use in source and binary forms, with or without
# Line 35  POSSIBILITY OF SUCH DAMAGE. Line 36  POSSIBILITY OF SUCH DAMAGE.
36  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
37  */  */
38    
39    /* This program now supports the testing of both the 8-bit and 16-bit PCRE
40    libraries in a single program. This is different from the modules such as
41    pcre_compile.c in the library itself, which are compiled separately for each
42    mode. If both modes are enabled, for example, pcre_compile.c is compiled twice
43    (the second time with COMPILE_PCRE16 defined). By contrast, pcretest.c is
44    compiled only once. Therefore, it must not make use of any of the macros from
45    pcre_internal.h that depend on COMPILE_PCRE8 or COMPILE_PCRE16. It does,
46    however, make use of SUPPORT_PCRE8 and SUPPORT_PCRE16 to ensure that it calls
47    only supported library functions. */
48    
49  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
50  #include "config.h"  #include "config.h"
# Line 48  POSSIBILITY OF SUCH DAMAGE. Line 58  POSSIBILITY OF SUCH DAMAGE.
58  #include <locale.h>  #include <locale.h>
59  #include <errno.h>  #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  /* 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  input and output without "b"; then I was told that "b" was needed in some
# Line 63  input mode under Windows. */ Line 93  input mode under Windows. */
93  #define INPUT_MODE   "r"  #define INPUT_MODE   "r"
94  #define OUTPUT_MODE  "wb"  #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  #else
113  #include <sys/time.h>          /* These two includes are needed */  #include <sys/time.h>          /* These two includes are needed */
114  #include <sys/resource.h>      /* for setrlimit(). */  #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"  #define INPUT_MODE   "rb"
120  #define OUTPUT_MODE  "wb"  #define OUTPUT_MODE  "wb"
121  #endif  #endif
122    #endif
123    
124    #define PRIV(name) name
125    
126  /* We have to include pcre_internal.h because we need the internal info for  /* We have to include pcre_internal.h because we need the internal info for
127  displaying the results of pcre_study() and we also need to know about the  displaying the results of pcre_study() and we also need to know about the
# Line 81  here before pcre_internal.h so that the Line 133  here before pcre_internal.h so that the
133  appropriately for an application, not for building PCRE. */  appropriately for an application, not for building PCRE. */
134    
135  #include "pcre.h"  #include "pcre.h"
136    
137    #if defined SUPPORT_PCRE32 && !defined SUPPORT_PCRE8 && !defined SUPPORT_PCRE16
138    /* Configure internal macros to 32 bit mode. */
139    #define COMPILE_PCRE32
140    #endif
141    #if defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE8 && !defined SUPPORT_PCRE32
142    /* Configure internal macros to 16 bit mode. */
143    #define COMPILE_PCRE16
144    #endif
145    #if defined SUPPORT_PCRE8 && !defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE32
146    /* Configure internal macros to 16 bit mode. */
147    #define COMPILE_PCRE8
148    #endif
149    
150  #include "pcre_internal.h"  #include "pcre_internal.h"
151    
152  /* We need access to the data tables that PCRE uses. So as not to have to keep  /* The pcre_printint() function, which prints the internal form of a compiled
153  two copies, we include the source file here, changing the names of the external  regex, is held in a separate file so that (a) it can be compiled in either
154  symbols to prevent clashes. */  8-, 16- or 32-bit mode, and (b) it can be #included directly in pcre_compile.c
155    when that is compiled in debug mode. */
 #define _pcre_utf8_table1      utf8_table1  
 #define _pcre_utf8_table1_size utf8_table1_size  
 #define _pcre_utf8_table2      utf8_table2  
 #define _pcre_utf8_table3      utf8_table3  
 #define _pcre_utf8_table4      utf8_table4  
 #define _pcre_utt              utt  
 #define _pcre_utt_size         utt_size  
 #define _pcre_utt_names        utt_names  
 #define _pcre_OP_lengths       OP_lengths  
156    
157  #include "pcre_tables.c"  #ifdef SUPPORT_PCRE8
158    void pcre_printint(pcre *external_re, FILE *f, BOOL print_lengths);
159    #endif
160    #ifdef SUPPORT_PCRE16
161    void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths);
162    #endif
163    #ifdef SUPPORT_PCRE32
164    void pcre32_printint(pcre *external_re, FILE *f, BOOL print_lengths);
165    #endif
166    
167  /* We also need the pcre_printint() function for printing out compiled  /* We need access to some of the data tables that PCRE uses. So as not to have
168  patterns. This function is in a separate file so that it can be included in  to keep two copies, we include the source files here, changing the names of the
169  pcre_compile.c when that module is compiled with debugging enabled.  external symbols to prevent clashes. */
170    
171  The definition of the macro PRINTABLE, which determines whether to print an  #define PCRE_INCLUDED
172    
173    #include "pcre_tables.c"
174    #include "pcre_ucd.c"
175    
176    /* The definition of the macro PRINTABLE, which determines whether to print an
177  output character as-is or as a hex value when showing compiled patterns, is  output character as-is or as a hex value when showing compiled patterns, is
178  contained in this file. We uses it here also, in cases when the locale has not  the same as in the printint.src file. We uses it here in cases when the locale
179  been explicitly changed, so as to get consistent output from systems that  has not been explicitly changed, so as to get consistent output from systems
180  differ in their output from isprint() even in the "C" locale. */  that differ in their output from isprint() even in the "C" locale. */
181    
182  #include "pcre_printint.src"  #ifdef EBCDIC
183    #define PRINTABLE(c) ((c) >= 64 && (c) < 255)
184    #else
185    #define PRINTABLE(c) ((c) >= 32 && (c) < 127)
186    #endif
187    
188  #define PRINTHEX(c) (locale_set? isprint(c) : PRINTABLE(c))  #define PRINTOK(c) (locale_set? isprint(c) : PRINTABLE(c))
189    
190    /* Posix support is disabled in 16 or 32 bit only mode. */
191    #if !defined SUPPORT_PCRE8 && !defined NOPOSIX
192    #define NOPOSIX
193    #endif
194    
195  /* It is possible to compile this test program without including support for  /* It is possible to compile this test program without including support for
196  testing the POSIX interface, though this is not available via the standard  testing the POSIX interface, though this is not available via the standard
# Line 122  Makefile. */ Line 200  Makefile. */
200  #include "pcreposix.h"  #include "pcreposix.h"
201  #endif  #endif
202    
203  /* It is also possible, for the benefit of the version currently imported into  /* It is also possible, originally for the benefit of a version that was
204  Exim, to build pcretest without support for UTF8 (define NOUTF8), without the  imported into Exim, to build pcretest without support for UTF8 or UTF16 (define
205  interface to the DFA matcher (NODFA), and without the doublecheck of the old  NOUTF), without the interface to the DFA matcher (NODFA). In fact, we
206  "info" function (define NOINFOCHECK). In fact, we automatically cut out the  automatically cut out the UTF support if PCRE is built without it. */
207  UTF8 support if PCRE is built without it. */  
208    #ifndef SUPPORT_UTF
209  #ifndef SUPPORT_UTF8  #ifndef NOUTF
210  #ifndef NOUTF8  #define NOUTF
211  #define NOUTF8  #endif
212    #endif
213    
214    /* To make the code a bit tidier for 8/16/32-bit support, we define macros
215    for all the pcre[16]_xxx functions (except pcre16_fullinfo, which is called
216    only from one place and is handled differently). I couldn't dream up any way of
217    using a single macro to do this in a generic way, because of the many different
218    argument requirements. We know that at least one of SUPPORT_PCRE8 and
219    SUPPORT_PCRE16 must be set. First define macros for each individual mode; then
220    use these in the definitions of generic macros.
221    
222    **** Special note about the PCHARSxxx macros: the address of the string to be
223    printed is always given as two arguments: a base address followed by an offset.
224    The base address is cast to the correct data size for 8 or 16 bit data; the
225    offset is in units of this size. If the string were given as base+offset in one
226    argument, the casting might be incorrectly applied. */
227    
228    #ifdef SUPPORT_PCRE8
229    
230    #define PCHARS8(lv, p, offset, len, f) \
231      lv = pchars((pcre_uint8 *)(p) + offset, len, f)
232    
233    #define PCHARSV8(p, offset, len, f) \
234      (void)pchars((pcre_uint8 *)(p) + offset, len, f)
235    
236    #define READ_CAPTURE_NAME8(p, cn8, cn16, cn32, re) \
237      p = read_capture_name8(p, cn8, re)
238    
239    #define STRLEN8(p) ((int)strlen((char *)p))
240    
241    #define SET_PCRE_CALLOUT8(callout) \
242      pcre_callout = callout
243    
244    #define PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata) \
245       pcre_assign_jit_stack(extra, callback, userdata)
246    
247    #define PCRE_COMPILE8(re, pat, options, error, erroffset, tables) \
248      re = pcre_compile((char *)pat, options, error, erroffset, tables)
249    
250    #define PCRE_COPY_NAMED_SUBSTRING8(rc, re, bptr, offsets, count, \
251        namesptr, cbuffer, size) \
252      rc = pcre_copy_named_substring(re, (char *)bptr, offsets, count, \
253        (char *)namesptr, cbuffer, size)
254    
255    #define PCRE_COPY_SUBSTRING8(rc, bptr, offsets, count, i, cbuffer, size) \
256      rc = pcre_copy_substring((char *)bptr, offsets, count, i, cbuffer, size)
257    
258    #define PCRE_DFA_EXEC8(count, re, extra, bptr, len, start_offset, options, \
259        offsets, size_offsets, workspace, size_workspace) \
260      count = pcre_dfa_exec(re, extra, (char *)bptr, len, start_offset, options, \
261        offsets, size_offsets, workspace, size_workspace)
262    
263    #define PCRE_EXEC8(count, re, extra, bptr, len, start_offset, options, \
264        offsets, size_offsets) \
265      count = pcre_exec(re, extra, (char *)bptr, len, start_offset, options, \
266        offsets, size_offsets)
267    
268    #define PCRE_FREE_STUDY8(extra) \
269      pcre_free_study(extra)
270    
271    #define PCRE_FREE_SUBSTRING8(substring) \
272      pcre_free_substring(substring)
273    
274    #define PCRE_FREE_SUBSTRING_LIST8(listptr) \
275      pcre_free_substring_list(listptr)
276    
277    #define PCRE_GET_NAMED_SUBSTRING8(rc, re, bptr, offsets, count, \
278        getnamesptr, subsptr) \
279      rc = pcre_get_named_substring(re, (char *)bptr, offsets, count, \
280        (char *)getnamesptr, subsptr)
281    
282    #define PCRE_GET_STRINGNUMBER8(n, rc, ptr) \
283      n = pcre_get_stringnumber(re, (char *)ptr)
284    
285    #define PCRE_GET_SUBSTRING8(rc, bptr, offsets, count, i, subsptr) \
286      rc = pcre_get_substring((char *)bptr, offsets, count, i, subsptr)
287    
288    #define PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr) \
289      rc = pcre_get_substring_list((const char *)bptr, offsets, count, listptr)
290    
291    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER8(rc, re, extra, tables) \
292      rc = pcre_pattern_to_host_byte_order(re, extra, tables)
293    
294    #define PCRE_PRINTINT8(re, outfile, debug_lengths) \
295      pcre_printint(re, outfile, debug_lengths)
296    
297    #define PCRE_STUDY8(extra, re, options, error) \
298      extra = pcre_study(re, options, error)
299    
300    #define PCRE_JIT_STACK_ALLOC8(startsize, maxsize) \
301      pcre_jit_stack_alloc(startsize, maxsize)
302    
303    #define PCRE_JIT_STACK_FREE8(stack) \
304      pcre_jit_stack_free(stack)
305    
306    #define pcre8_maketables pcre_maketables
307    
308    #endif /* SUPPORT_PCRE8 */
309    
310    /* -----------------------------------------------------------*/
311    
312    #ifdef SUPPORT_PCRE16
313    
314    #define PCHARS16(lv, p, offset, len, f) \
315      lv = pchars16((PCRE_SPTR16)(p) + offset, len, f)
316    
317    #define PCHARSV16(p, offset, len, f) \
318      (void)pchars16((PCRE_SPTR16)(p) + offset, len, f)
319    
320    #define READ_CAPTURE_NAME16(p, cn8, cn16, cn32, re) \
321      p = read_capture_name16(p, cn16, re)
322    
323    #define STRLEN16(p) ((int)strlen16((PCRE_SPTR16)p))
324    
325    #define SET_PCRE_CALLOUT16(callout) \
326      pcre16_callout = (int (*)(pcre16_callout_block *))callout
327    
328    #define PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata) \
329      pcre16_assign_jit_stack((pcre16_extra *)extra, \
330        (pcre16_jit_callback)callback, userdata)
331    
332    #define PCRE_COMPILE16(re, pat, options, error, erroffset, tables) \
333      re = (pcre *)pcre16_compile((PCRE_SPTR16)pat, options, error, erroffset, \
334        tables)
335    
336    #define PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
337        namesptr, cbuffer, size) \
338      rc = pcre16_copy_named_substring((pcre16 *)re, (PCRE_SPTR16)bptr, offsets, \
339        count, (PCRE_SPTR16)namesptr, (PCRE_UCHAR16 *)cbuffer, size/2)
340    
341    #define PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size) \
342      rc = pcre16_copy_substring((PCRE_SPTR16)bptr, offsets, count, i, \
343        (PCRE_UCHAR16 *)cbuffer, size/2)
344    
345    #define PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \
346        offsets, size_offsets, workspace, size_workspace) \
347      count = pcre16_dfa_exec((pcre16 *)re, (pcre16_extra *)extra, \
348        (PCRE_SPTR16)bptr, len, start_offset, options, offsets, size_offsets, \
349        workspace, size_workspace)
350    
351    #define PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \
352        offsets, size_offsets) \
353      count = pcre16_exec((pcre16 *)re, (pcre16_extra *)extra, (PCRE_SPTR16)bptr, \
354        len, start_offset, options, offsets, size_offsets)
355    
356    #define PCRE_FREE_STUDY16(extra) \
357      pcre16_free_study((pcre16_extra *)extra)
358    
359    #define PCRE_FREE_SUBSTRING16(substring) \
360      pcre16_free_substring((PCRE_SPTR16)substring)
361    
362    #define PCRE_FREE_SUBSTRING_LIST16(listptr) \
363      pcre16_free_substring_list((PCRE_SPTR16 *)listptr)
364    
365    #define PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
366        getnamesptr, subsptr) \
367      rc = pcre16_get_named_substring((pcre16 *)re, (PCRE_SPTR16)bptr, offsets, \
368        count, (PCRE_SPTR16)getnamesptr, (PCRE_SPTR16 *)(void*)subsptr)
369    
370    #define PCRE_GET_STRINGNUMBER16(n, rc, ptr) \
371      n = pcre16_get_stringnumber(re, (PCRE_SPTR16)ptr)
372    
373    #define PCRE_GET_SUBSTRING16(rc, bptr, offsets, count, i, subsptr) \
374      rc = pcre16_get_substring((PCRE_SPTR16)bptr, offsets, count, i, \
375        (PCRE_SPTR16 *)(void*)subsptr)
376    
377    #define PCRE_GET_SUBSTRING_LIST16(rc, bptr, offsets, count, listptr) \
378      rc = pcre16_get_substring_list((PCRE_SPTR16)bptr, offsets, count, \
379        (PCRE_SPTR16 **)(void*)listptr)
380    
381    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables) \
382      rc = pcre16_pattern_to_host_byte_order((pcre16 *)re, (pcre16_extra *)extra, \
383        tables)
384    
385    #define PCRE_PRINTINT16(re, outfile, debug_lengths) \
386      pcre16_printint(re, outfile, debug_lengths)
387    
388    #define PCRE_STUDY16(extra, re, options, error) \
389      extra = (pcre_extra *)pcre16_study((pcre16 *)re, options, error)
390    
391    #define PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \
392      (pcre_jit_stack *)pcre16_jit_stack_alloc(startsize, maxsize)
393    
394    #define PCRE_JIT_STACK_FREE16(stack) \
395      pcre16_jit_stack_free((pcre16_jit_stack *)stack)
396    
397    #endif /* SUPPORT_PCRE16 */
398    
399    /* -----------------------------------------------------------*/
400    
401    #ifdef SUPPORT_PCRE32
402    
403    #define PCHARS32(lv, p, offset, len, f) \
404      lv = pchars32((PCRE_SPTR32)(p) + offset, len, use_utf, f)
405    
406    #define PCHARSV32(p, offset, len, f)                \
407      (void)pchars32((PCRE_SPTR32)(p) + offset, len, use_utf, f)
408    
409    #define READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re) \
410      p = read_capture_name32(p, cn32, re)
411    
412    #define STRLEN32(p) ((int)strlen32((PCRE_SPTR32)p))
413    
414    #define SET_PCRE_CALLOUT32(callout) \
415      pcre32_callout = (int (*)(pcre32_callout_block *))callout
416    
417    #define PCRE_ASSIGN_JIT_STACK32(extra, callback, userdata) \
418      pcre32_assign_jit_stack((pcre32_extra *)extra, \
419        (pcre32_jit_callback)callback, userdata)
420    
421    #define PCRE_COMPILE32(re, pat, options, error, erroffset, tables) \
422      re = (pcre *)pcre32_compile((PCRE_SPTR32)pat, options, error, erroffset, \
423        tables)
424    
425    #define PCRE_COPY_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
426        namesptr, cbuffer, size) \
427      rc = pcre32_copy_named_substring((pcre32 *)re, (PCRE_SPTR32)bptr, offsets, \
428        count, (PCRE_SPTR32)namesptr, (PCRE_UCHAR32 *)cbuffer, size/2)
429    
430    #define PCRE_COPY_SUBSTRING32(rc, bptr, offsets, count, i, cbuffer, size) \
431      rc = pcre32_copy_substring((PCRE_SPTR32)bptr, offsets, count, i, \
432        (PCRE_UCHAR32 *)cbuffer, size/2)
433    
434    #define PCRE_DFA_EXEC32(count, re, extra, bptr, len, start_offset, options, \
435        offsets, size_offsets, workspace, size_workspace) \
436      count = pcre32_dfa_exec((pcre32 *)re, (pcre32_extra *)extra, \
437        (PCRE_SPTR32)bptr, len, start_offset, options, offsets, size_offsets, \
438        workspace, size_workspace)
439    
440    #define PCRE_EXEC32(count, re, extra, bptr, len, start_offset, options, \
441        offsets, size_offsets) \
442      count = pcre32_exec((pcre32 *)re, (pcre32_extra *)extra, (PCRE_SPTR32)bptr, \
443        len, start_offset, options, offsets, size_offsets)
444    
445    #define PCRE_FREE_STUDY32(extra) \
446      pcre32_free_study((pcre32_extra *)extra)
447    
448    #define PCRE_FREE_SUBSTRING32(substring) \
449      pcre32_free_substring((PCRE_SPTR32)substring)
450    
451    #define PCRE_FREE_SUBSTRING_LIST32(listptr) \
452      pcre32_free_substring_list((PCRE_SPTR32 *)listptr)
453    
454    #define PCRE_GET_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
455        getnamesptr, subsptr) \
456      rc = pcre32_get_named_substring((pcre32 *)re, (PCRE_SPTR32)bptr, offsets, \
457        count, (PCRE_SPTR32)getnamesptr, (PCRE_SPTR32 *)(void*)subsptr)
458    
459    #define PCRE_GET_STRINGNUMBER32(n, rc, ptr) \
460      n = pcre32_get_stringnumber(re, (PCRE_SPTR32)ptr)
461    
462    #define PCRE_GET_SUBSTRING32(rc, bptr, offsets, count, i, subsptr) \
463      rc = pcre32_get_substring((PCRE_SPTR32)bptr, offsets, count, i, \
464        (PCRE_SPTR32 *)(void*)subsptr)
465    
466    #define PCRE_GET_SUBSTRING_LIST32(rc, bptr, offsets, count, listptr) \
467      rc = pcre32_get_substring_list((PCRE_SPTR32)bptr, offsets, count, \
468        (PCRE_SPTR32 **)(void*)listptr)
469    
470    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER32(rc, re, extra, tables) \
471      rc = pcre32_pattern_to_host_byte_order((pcre32 *)re, (pcre32_extra *)extra, \
472        tables)
473    
474    #define PCRE_PRINTINT32(re, outfile, debug_lengths) \
475      pcre32_printint(re, outfile, debug_lengths)
476    
477    #define PCRE_STUDY32(extra, re, options, error) \
478      extra = (pcre_extra *)pcre32_study((pcre32 *)re, options, error)
479    
480    #define PCRE_JIT_STACK_ALLOC32(startsize, maxsize) \
481      (pcre_jit_stack *)pcre32_jit_stack_alloc(startsize, maxsize)
482    
483    #define PCRE_JIT_STACK_FREE32(stack) \
484      pcre32_jit_stack_free((pcre32_jit_stack *)stack)
485    
486    #endif /* SUPPORT_PCRE32 */
487    
488    
489    /* ----- More than one mode is supported; a runtime test is needed, except for
490    pcre_config(), and the JIT stack functions, when it doesn't matter which
491    available version is called. ----- */
492    
493    enum {
494      PCRE8_MODE,
495      PCRE16_MODE,
496      PCRE32_MODE
497    };
498    
499    #if (defined (SUPPORT_PCRE8) + defined (SUPPORT_PCRE16) + \
500         defined (SUPPORT_PCRE32)) >= 2
501    
502    #define CHAR_SIZE (1 << pcre_mode)
503    
504    /* There doesn't seem to be an easy way of writing these macros that can cope
505    with the 3 pairs of bit sizes plus all three bit sizes. So just handle all the
506    cases separately. */
507    
508    /* ----- All three modes supported ----- */
509    
510    #if defined(SUPPORT_PCRE8) && defined(SUPPORT_PCRE16) && defined(SUPPORT_PCRE32)
511    
512    #define PCHARS(lv, p, offset, len, f) \
513      if (pcre_mode == PCRE32_MODE) \
514        PCHARS32(lv, p, offset, len, f); \
515      else if (pcre_mode == PCRE16_MODE) \
516        PCHARS16(lv, p, offset, len, f); \
517      else \
518        PCHARS8(lv, p, offset, len, f)
519    
520    #define PCHARSV(p, offset, len, f) \
521      if (pcre_mode == PCRE32_MODE) \
522        PCHARSV32(p, offset, len, f); \
523      else if (pcre_mode == PCRE16_MODE) \
524        PCHARSV16(p, offset, len, f); \
525      else \
526        PCHARSV8(p, offset, len, f)
527    
528    #define READ_CAPTURE_NAME(p, cn8, cn16, cn32, re) \
529      if (pcre_mode == PCRE32_MODE) \
530        READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re); \
531      else if (pcre_mode == PCRE16_MODE) \
532        READ_CAPTURE_NAME16(p, cn8, cn16, cn32, re); \
533      else \
534        READ_CAPTURE_NAME8(p, cn8, cn16, cn32, re)
535    
536    #define SET_PCRE_CALLOUT(callout) \
537      if (pcre_mode == PCRE32_MODE) \
538        SET_PCRE_CALLOUT32(callout); \
539      else if (pcre_mode == PCRE16_MODE) \
540        SET_PCRE_CALLOUT16(callout); \
541      else \
542        SET_PCRE_CALLOUT8(callout)
543    
544    #define STRLEN(p) (pcre_mode == PCRE32_MODE ? STRLEN32(p) : pcre_mode == PCRE16_MODE ? STRLEN16(p) : STRLEN8(p))
545    
546    #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \
547      if (pcre_mode == PCRE32_MODE) \
548        PCRE_ASSIGN_JIT_STACK32(extra, callback, userdata); \
549      else if (pcre_mode == PCRE16_MODE) \
550        PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata); \
551      else \
552        PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata)
553    
554    #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
555      if (pcre_mode == PCRE32_MODE) \
556        PCRE_COMPILE32(re, pat, options, error, erroffset, tables); \
557      else if (pcre_mode == PCRE16_MODE) \
558        PCRE_COMPILE16(re, pat, options, error, erroffset, tables); \
559      else \
560        PCRE_COMPILE8(re, pat, options, error, erroffset, tables)
561    
562    #define PCRE_CONFIG pcre_config
563    
564    #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
565        namesptr, cbuffer, size) \
566      if (pcre_mode == PCRE32_MODE) \
567        PCRE_COPY_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
568          namesptr, cbuffer, size); \
569      else if (pcre_mode == PCRE16_MODE) \
570        PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
571          namesptr, cbuffer, size); \
572      else \
573        PCRE_COPY_NAMED_SUBSTRING8(rc, re, bptr, offsets, count, \
574          namesptr, cbuffer, size)
575    
576    #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \
577      if (pcre_mode == PCRE32_MODE) \
578        PCRE_COPY_SUBSTRING32(rc, bptr, offsets, count, i, cbuffer, size); \
579      else if (pcre_mode == PCRE16_MODE) \
580        PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size); \
581      else \
582        PCRE_COPY_SUBSTRING8(rc, bptr, offsets, count, i, cbuffer, size)
583    
584    #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \
585        offsets, size_offsets, workspace, size_workspace) \
586      if (pcre_mode == PCRE32_MODE) \
587        PCRE_DFA_EXEC32(count, re, extra, bptr, len, start_offset, options, \
588          offsets, size_offsets, workspace, size_workspace); \
589      else if (pcre_mode == PCRE16_MODE) \
590        PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \
591          offsets, size_offsets, workspace, size_workspace); \
592      else \
593        PCRE_DFA_EXEC8(count, re, extra, bptr, len, start_offset, options, \
594          offsets, size_offsets, workspace, size_workspace)
595    
596    #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
597        offsets, size_offsets) \
598      if (pcre_mode == PCRE32_MODE) \
599        PCRE_EXEC32(count, re, extra, bptr, len, start_offset, options, \
600          offsets, size_offsets); \
601      else if (pcre_mode == PCRE16_MODE) \
602        PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \
603          offsets, size_offsets); \
604      else \
605        PCRE_EXEC8(count, re, extra, bptr, len, start_offset, options, \
606          offsets, size_offsets)
607    
608    #define PCRE_FREE_STUDY(extra) \
609      if (pcre_mode == PCRE32_MODE) \
610        PCRE_FREE_STUDY32(extra); \
611      else if (pcre_mode == PCRE16_MODE) \
612        PCRE_FREE_STUDY16(extra); \
613      else \
614        PCRE_FREE_STUDY8(extra)
615    
616    #define PCRE_FREE_SUBSTRING(substring) \
617      if (pcre_mode == PCRE32_MODE) \
618        PCRE_FREE_SUBSTRING32(substring); \
619      else if (pcre_mode == PCRE16_MODE) \
620        PCRE_FREE_SUBSTRING16(substring); \
621      else \
622        PCRE_FREE_SUBSTRING8(substring)
623    
624    #define PCRE_FREE_SUBSTRING_LIST(listptr) \
625      if (pcre_mode == PCRE32_MODE) \
626        PCRE_FREE_SUBSTRING_LIST32(listptr); \
627      else if (pcre_mode == PCRE16_MODE) \
628        PCRE_FREE_SUBSTRING_LIST16(listptr); \
629      else \
630        PCRE_FREE_SUBSTRING_LIST8(listptr)
631    
632    #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
633        getnamesptr, subsptr) \
634      if (pcre_mode == PCRE32_MODE) \
635        PCRE_GET_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
636          getnamesptr, subsptr); \
637      else if (pcre_mode == PCRE16_MODE) \
638        PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
639          getnamesptr, subsptr); \
640      else \
641        PCRE_GET_NAMED_SUBSTRING8(rc, re, bptr, offsets, count, \
642          getnamesptr, subsptr)
643    
644    #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \
645      if (pcre_mode == PCRE32_MODE) \
646        PCRE_GET_STRINGNUMBER32(n, rc, ptr); \
647      else if (pcre_mode == PCRE16_MODE) \
648        PCRE_GET_STRINGNUMBER16(n, rc, ptr); \
649      else \
650        PCRE_GET_STRINGNUMBER8(n, rc, ptr)
651    
652    #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \
653      if (pcre_mode == PCRE32_MODE) \
654        PCRE_GET_SUBSTRING32(rc, bptr, use_offsets, count, i, subsptr); \
655      else if (pcre_mode == PCRE16_MODE) \
656        PCRE_GET_SUBSTRING16(rc, bptr, use_offsets, count, i, subsptr); \
657      else \
658        PCRE_GET_SUBSTRING8(rc, bptr, use_offsets, count, i, subsptr)
659    
660    #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \
661      if (pcre_mode == PCRE32_MODE) \
662        PCRE_GET_SUBSTRING_LIST32(rc, bptr, offsets, count, listptr); \
663      else if (pcre_mode == PCRE16_MODE) \
664        PCRE_GET_SUBSTRING_LIST16(rc, bptr, offsets, count, listptr); \
665      else \
666        PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr)
667    
668    #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \
669      (pcre_mode == PCRE32_MODE ? \
670         PCRE_JIT_STACK_ALLOC32(startsize, maxsize) \
671        : pcre_mode == PCRE16_MODE ? \
672          PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \
673          : PCRE_JIT_STACK_ALLOC8(startsize, maxsize))
674    
675    #define PCRE_JIT_STACK_FREE(stack) \
676      if (pcre_mode == PCRE32_MODE) \
677        PCRE_JIT_STACK_FREE32(stack); \
678      else if (pcre_mode == PCRE16_MODE) \
679        PCRE_JIT_STACK_FREE16(stack); \
680      else \
681        PCRE_JIT_STACK_FREE8(stack)
682    
683    #define PCRE_MAKETABLES \
684      (pcre_mode == PCRE32_MODE ? pcre32_maketables() : pcre_mode == PCRE16_MODE ? pcre16_maketables() : pcre_maketables())
685    
686    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \
687      if (pcre_mode == PCRE32_MODE) \
688        PCRE_PATTERN_TO_HOST_BYTE_ORDER32(rc, re, extra, tables); \
689      else if (pcre_mode == PCRE16_MODE) \
690        PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables); \
691      else \
692        PCRE_PATTERN_TO_HOST_BYTE_ORDER8(rc, re, extra, tables)
693    
694    #define PCRE_PRINTINT(re, outfile, debug_lengths) \
695      if (pcre_mode == PCRE32_MODE) \
696        PCRE_PRINTINT32(re, outfile, debug_lengths); \
697      else if (pcre_mode == PCRE16_MODE) \
698        PCRE_PRINTINT16(re, outfile, debug_lengths); \
699      else \
700        PCRE_PRINTINT8(re, outfile, debug_lengths)
701    
702    #define PCRE_STUDY(extra, re, options, error) \
703      if (pcre_mode == PCRE32_MODE) \
704        PCRE_STUDY32(extra, re, options, error); \
705      else if (pcre_mode == PCRE16_MODE) \
706        PCRE_STUDY16(extra, re, options, error); \
707      else \
708        PCRE_STUDY8(extra, re, options, error)
709    
710    
711    /* ----- Two out of three modes are supported ----- */
712    
713    #else
714    
715    /* We can use some macro trickery to make a single set of definitions work in
716    the three different cases. */
717    
718    /* ----- 32-bit and 16-bit but not 8-bit supported ----- */
719    
720    #if defined(SUPPORT_PCRE32) && defined(SUPPORT_PCRE16)
721    #define BITONE 32
722    #define BITTWO 16
723    
724    /* ----- 32-bit and 8-bit but not 16-bit supported ----- */
725    
726    #elif defined(SUPPORT_PCRE32) && defined(SUPPORT_PCRE8)
727    #define BITONE 32
728    #define BITTWO 8
729    
730    /* ----- 16-bit and 8-bit but not 32-bit supported ----- */
731    
732    #else
733    #define BITONE 16
734    #define BITTWO 8
735  #endif  #endif
736    
737    #define glue(a,b) a##b
738    #define G(a,b) glue(a,b)
739    
740    
741    /* ----- Common macros for two-mode cases ----- */
742    
743    #define PCHARS(lv, p, offset, len, f) \
744      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
745        G(PCHARS,BITONE)(lv, p, offset, len, f); \
746      else \
747        G(PCHARS,BITTWO)(lv, p, offset, len, f)
748    
749    #define PCHARSV(p, offset, len, f) \
750      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
751        G(PCHARSV,BITONE)(p, offset, len, f); \
752      else \
753        G(PCHARSV,BITTWO)(p, offset, len, f)
754    
755    #define READ_CAPTURE_NAME(p, cn8, cn16, cn32, re) \
756      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
757        G(READ_CAPTURE_NAME,BITONE)(p, cn8, cn16, cn32, re); \
758      else \
759        G(READ_CAPTURE_NAME,BITTWO)(p, cn8, cn16, cn32, re)
760    
761    #define SET_PCRE_CALLOUT(callout) \
762      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
763        G(SET_PCRE_CALLOUT,BITONE)(callout); \
764      else \
765        G(SET_PCRE_CALLOUT,BITTWO)(callout)
766    
767    #define STRLEN(p) ((pcre_mode == G(G(PCRE,BITONE),_MODE)) ? \
768      G(STRLEN,BITONE)(p) : G(STRLEN,BITTWO)(p))
769    
770    #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \
771      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
772        G(PCRE_ASSIGN_JIT_STACK,BITONE)(extra, callback, userdata); \
773      else \
774        G(PCRE_ASSIGN_JIT_STACK,BITTWO)(extra, callback, userdata)
775    
776    #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
777      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
778        G(PCRE_COMPILE,BITONE)(re, pat, options, error, erroffset, tables); \
779      else \
780        G(PCRE_COMPILE,BITTWO)(re, pat, options, error, erroffset, tables)
781    
782    #define PCRE_CONFIG G(G(pcre,BITONE),_config)
783    
784    #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
785        namesptr, cbuffer, size) \
786      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
787        G(PCRE_COPY_NAMED_SUBSTRING,BITONE)(rc, re, bptr, offsets, count, \
788          namesptr, cbuffer, size); \
789      else \
790        G(PCRE_COPY_NAMED_SUBSTRING,BITTWO)(rc, re, bptr, offsets, count, \
791          namesptr, cbuffer, size)
792    
793    #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \
794      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
795        G(PCRE_COPY_SUBSTRING,BITONE)(rc, bptr, offsets, count, i, cbuffer, size); \
796      else \
797        G(PCRE_COPY_SUBSTRING,BITTWO)(rc, bptr, offsets, count, i, cbuffer, size)
798    
799    #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \
800        offsets, size_offsets, workspace, size_workspace) \
801      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
802        G(PCRE_DFA_EXEC,BITONE)(count, re, extra, bptr, len, start_offset, options, \
803          offsets, size_offsets, workspace, size_workspace); \
804      else \
805        G(PCRE_DFA_EXEC,BITTWO)(count, re, extra, bptr, len, start_offset, options, \
806          offsets, size_offsets, workspace, size_workspace)
807    
808    #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
809        offsets, size_offsets) \
810      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
811        G(PCRE_EXEC,BITONE)(count, re, extra, bptr, len, start_offset, options, \
812          offsets, size_offsets); \
813      else \
814        G(PCRE_EXEC,BITTWO)(count, re, extra, bptr, len, start_offset, options, \
815          offsets, size_offsets)
816    
817    #define PCRE_FREE_STUDY(extra) \
818      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
819        G(PCRE_FREE_STUDY,BITONE)(extra); \
820      else \
821        G(PCRE_FREE_STUDY,BITTWO)(extra)
822    
823    #define PCRE_FREE_SUBSTRING(substring) \
824      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
825        G(PCRE_FREE_SUBSTRING,BITONE)(substring); \
826      else \
827        G(PCRE_FREE_SUBSTRING,BITTWO)(substring)
828    
829    #define PCRE_FREE_SUBSTRING_LIST(listptr) \
830      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
831        G(PCRE_FREE_SUBSTRING_LIST,BITONE)(listptr); \
832      else \
833        G(PCRE_FREE_SUBSTRING_LIST,BITTWO)(listptr)
834    
835    #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
836        getnamesptr, subsptr) \
837      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
838        G(PCRE_GET_NAMED_SUBSTRING,BITONE)(rc, re, bptr, offsets, count, \
839          getnamesptr, subsptr); \
840      else \
841        G(PCRE_GET_NAMED_SUBSTRING,BITTWO)(rc, re, bptr, offsets, count, \
842          getnamesptr, subsptr)
843    
844    #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \
845      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
846        G(PCRE_GET_STRINGNUMBER,BITONE)(n, rc, ptr); \
847      else \
848        G(PCRE_GET_STRINGNUMBER,BITTWO)(n, rc, ptr)
849    
850    #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \
851      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
852        G(PCRE_GET_SUBSTRING,BITONE)(rc, bptr, use_offsets, count, i, subsptr); \
853      else \
854        G(PCRE_GET_SUBSTRING,BITTWO)(rc, bptr, use_offsets, count, i, subsptr)
855    
856    #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \
857      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
858        G(PCRE_GET_SUBSTRING_LIST,BITONE)(rc, bptr, offsets, count, listptr); \
859      else \
860        G(PCRE_GET_SUBSTRING_LIST,BITTWO)(rc, bptr, offsets, count, listptr)
861    
862    #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \
863      (pcre_mode == G(G(PCRE,BITONE),_MODE)) ? \
864         G(PCRE_JIT_STACK_ALLOC,BITONE)(startsize, maxsize) \
865        : G(PCRE_JIT_STACK_ALLOC,BITTWO)(startsize, maxsize)
866    
867    #define PCRE_JIT_STACK_FREE(stack) \
868      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
869        G(PCRE_JIT_STACK_FREE,BITONE)(stack); \
870      else \
871        G(PCRE_JIT_STACK_FREE,BITTWO)(stack)
872    
873    #define PCRE_MAKETABLES \
874      (pcre_mode == G(G(PCRE,BITONE),_MODE)) ? \
875        G(G(pcre,BITONE),_maketables)() : G(G(pcre,BITTWO),_maketables)()
876    
877    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \
878      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
879        G(PCRE_PATTERN_TO_HOST_BYTE_ORDER,BITONE)(rc, re, extra, tables); \
880      else \
881        G(PCRE_PATTERN_TO_HOST_BYTE_ORDER,BITTWO)(rc, re, extra, tables)
882    
883    #define PCRE_PRINTINT(re, outfile, debug_lengths) \
884      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
885        G(PCRE_PRINTINT,BITONE)(re, outfile, debug_lengths); \
886      else \
887        G(PCRE_PRINTINT,BITTWO)(re, outfile, debug_lengths)
888    
889    #define PCRE_STUDY(extra, re, options, error) \
890      if (pcre_mode == G(G(PCRE,BITONE),_MODE)) \
891        G(PCRE_STUDY,BITONE)(extra, re, options, error); \
892      else \
893        G(PCRE_STUDY,BITTWO)(extra, re, options, error)
894    
895    #endif  /* Two out of three modes */
896    
897    /* ----- End of cases where more than one mode is supported ----- */
898    
899    
900    /* ----- Only 8-bit mode is supported ----- */
901    
902    #elif defined SUPPORT_PCRE8
903    #define CHAR_SIZE                 1
904    #define PCHARS                    PCHARS8
905    #define PCHARSV                   PCHARSV8
906    #define READ_CAPTURE_NAME         READ_CAPTURE_NAME8
907    #define SET_PCRE_CALLOUT          SET_PCRE_CALLOUT8
908    #define STRLEN                    STRLEN8
909    #define PCRE_ASSIGN_JIT_STACK     PCRE_ASSIGN_JIT_STACK8
910    #define PCRE_COMPILE              PCRE_COMPILE8
911    #define PCRE_CONFIG               pcre_config
912    #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING8
913    #define PCRE_COPY_SUBSTRING       PCRE_COPY_SUBSTRING8
914    #define PCRE_DFA_EXEC             PCRE_DFA_EXEC8
915    #define PCRE_EXEC                 PCRE_EXEC8
916    #define PCRE_FREE_STUDY           PCRE_FREE_STUDY8
917    #define PCRE_FREE_SUBSTRING       PCRE_FREE_SUBSTRING8
918    #define PCRE_FREE_SUBSTRING_LIST  PCRE_FREE_SUBSTRING_LIST8
919    #define PCRE_GET_NAMED_SUBSTRING  PCRE_GET_NAMED_SUBSTRING8
920    #define PCRE_GET_STRINGNUMBER     PCRE_GET_STRINGNUMBER8
921    #define PCRE_GET_SUBSTRING        PCRE_GET_SUBSTRING8
922    #define PCRE_GET_SUBSTRING_LIST   PCRE_GET_SUBSTRING_LIST8
923    #define PCRE_JIT_STACK_ALLOC      PCRE_JIT_STACK_ALLOC8
924    #define PCRE_JIT_STACK_FREE       PCRE_JIT_STACK_FREE8
925    #define PCRE_MAKETABLES           pcre_maketables()
926    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER8
927    #define PCRE_PRINTINT             PCRE_PRINTINT8
928    #define PCRE_STUDY                PCRE_STUDY8
929    
930    /* ----- Only 16-bit mode is supported ----- */
931    
932    #elif defined SUPPORT_PCRE16
933    #define CHAR_SIZE                 2
934    #define PCHARS                    PCHARS16
935    #define PCHARSV                   PCHARSV16
936    #define READ_CAPTURE_NAME         READ_CAPTURE_NAME16
937    #define SET_PCRE_CALLOUT          SET_PCRE_CALLOUT16
938    #define STRLEN                    STRLEN16
939    #define PCRE_ASSIGN_JIT_STACK     PCRE_ASSIGN_JIT_STACK16
940    #define PCRE_COMPILE              PCRE_COMPILE16
941    #define PCRE_CONFIG               pcre16_config
942    #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING16
943    #define PCRE_COPY_SUBSTRING       PCRE_COPY_SUBSTRING16
944    #define PCRE_DFA_EXEC             PCRE_DFA_EXEC16
945    #define PCRE_EXEC                 PCRE_EXEC16
946    #define PCRE_FREE_STUDY           PCRE_FREE_STUDY16
947    #define PCRE_FREE_SUBSTRING       PCRE_FREE_SUBSTRING16
948    #define PCRE_FREE_SUBSTRING_LIST  PCRE_FREE_SUBSTRING_LIST16
949    #define PCRE_GET_NAMED_SUBSTRING  PCRE_GET_NAMED_SUBSTRING16
950    #define PCRE_GET_STRINGNUMBER     PCRE_GET_STRINGNUMBER16
951    #define PCRE_GET_SUBSTRING        PCRE_GET_SUBSTRING16
952    #define PCRE_GET_SUBSTRING_LIST   PCRE_GET_SUBSTRING_LIST16
953    #define PCRE_JIT_STACK_ALLOC      PCRE_JIT_STACK_ALLOC16
954    #define PCRE_JIT_STACK_FREE       PCRE_JIT_STACK_FREE16
955    #define PCRE_MAKETABLES           pcre16_maketables()
956    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER16
957    #define PCRE_PRINTINT             PCRE_PRINTINT16
958    #define PCRE_STUDY                PCRE_STUDY16
959    
960    /* ----- Only 32-bit mode is supported ----- */
961    
962    #elif defined SUPPORT_PCRE32
963    #define CHAR_SIZE                 4
964    #define PCHARS                    PCHARS32
965    #define PCHARSV                   PCHARSV32
966    #define READ_CAPTURE_NAME         READ_CAPTURE_NAME32
967    #define SET_PCRE_CALLOUT          SET_PCRE_CALLOUT32
968    #define STRLEN                    STRLEN32
969    #define PCRE_ASSIGN_JIT_STACK     PCRE_ASSIGN_JIT_STACK32
970    #define PCRE_COMPILE              PCRE_COMPILE32
971    #define PCRE_CONFIG               pcre32_config
972    #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING32
973    #define PCRE_COPY_SUBSTRING       PCRE_COPY_SUBSTRING32
974    #define PCRE_DFA_EXEC             PCRE_DFA_EXEC32
975    #define PCRE_EXEC                 PCRE_EXEC32
976    #define PCRE_FREE_STUDY           PCRE_FREE_STUDY32
977    #define PCRE_FREE_SUBSTRING       PCRE_FREE_SUBSTRING32
978    #define PCRE_FREE_SUBSTRING_LIST  PCRE_FREE_SUBSTRING_LIST32
979    #define PCRE_GET_NAMED_SUBSTRING  PCRE_GET_NAMED_SUBSTRING32
980    #define PCRE_GET_STRINGNUMBER     PCRE_GET_STRINGNUMBER32
981    #define PCRE_GET_SUBSTRING        PCRE_GET_SUBSTRING32
982    #define PCRE_GET_SUBSTRING_LIST   PCRE_GET_SUBSTRING_LIST32
983    #define PCRE_JIT_STACK_ALLOC      PCRE_JIT_STACK_ALLOC32
984    #define PCRE_JIT_STACK_FREE       PCRE_JIT_STACK_FREE32
985    #define PCRE_MAKETABLES           pcre32_maketables()
986    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER32
987    #define PCRE_PRINTINT             PCRE_PRINTINT32
988    #define PCRE_STUDY                PCRE_STUDY32
989    
990  #endif  #endif
991    
992    /* ----- End of mode-specific function call macros ----- */
993    
994    
995  /* Other parameters */  /* Other parameters */
996    
# Line 145  UTF8 support if PCRE is built without it Line 1002  UTF8 support if PCRE is built without it
1002  #endif  #endif
1003  #endif  #endif
1004    
1005    #if !defined NODFA
1006    #define DFA_WS_DIMENSION 1000
1007    #endif
1008    
1009  /* This is the default loop count for timing. */  /* This is the default loop count for timing. */
1010    
1011  #define LOOPREPEAT 500000  #define LOOPREPEAT 500000
# Line 159  static int callout_fail_count; Line 1020  static int callout_fail_count;
1020  static int callout_fail_id;  static int callout_fail_id;
1021  static int debug_lengths;  static int debug_lengths;
1022  static int first_callout;  static int first_callout;
1023    static int jit_was_used;
1024  static int locale_set = 0;  static int locale_set = 0;
1025  static int show_malloc;  static int show_malloc;
1026  static int use_utf8;  static int use_utf;
1027  static size_t gotten_store;  static size_t gotten_store;
1028    static size_t first_gotten_store = 0;
1029    static const unsigned char *last_callout_mark = NULL;
1030    
1031  /* The buffers grow automatically if very long input lines are encountered. */  /* The buffers grow automatically if very long input lines are encountered. */
1032    
1033  static int buffer_size = 50000;  static int buffer_size = 50000;
1034  static uschar *buffer = NULL;  static pcre_uint8 *buffer = NULL;
1035  static uschar *dbuffer = NULL;  static pcre_uint8 *pbuffer = NULL;
 static uschar *pbuffer = NULL;  
1036    
1037    /* Another buffer is needed translation to 16/32-bit character strings. It will
1038    obtained and extended as required. */
1039    
1040    #if defined SUPPORT_PCRE8 && (defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32)
1041    
1042  /*************************************************  /* We need the table of operator lengths that is used for 16/32-bit compiling,
1043  *        Read or extend an input line            *  in order to swap bytes in a pattern for saving/reloading testing. Luckily, the
1044  *************************************************/  data is defined as a macro. However, we must ensure that LINK_SIZE is adjusted
1045    appropriately for the 16/32-bit world. Just as a safety check, make sure that
1046    COMPILE_PCRE[16|32] is *not* set. */
1047    
1048  /* Input lines are read into buffer, but both patterns and data lines can be  #ifdef COMPILE_PCRE16
1049  continued over multiple input lines. In addition, if the buffer fills up, we  #error COMPILE_PCRE16 must not be set when compiling pcretest.c
1050  want to automatically expand it so as to be able to handle extremely large  #endif
 lines that are needed for certain stress tests. When the input buffer is  
 expanded, the other two buffers must also be expanded likewise, and the  
 contents of pbuffer, which are a copy of the input for callouts, must be  
 preserved (for when expansion happens for a data line). This is not the most  
 optimal way of handling this, but hey, this is just a test program!  
1051    
1052  Arguments:  #ifdef COMPILE_PCRE32
1053    f            the file to read  #error COMPILE_PCRE32 must not be set when compiling pcretest.c
1054    start        where in buffer to start (this *must* be within buffer)  #endif
1055    
1056  Returns:       pointer to the start of new data  #if LINK_SIZE == 2
1057                 could be a copy of start, or could be moved  #undef LINK_SIZE
1058                 NULL if no data read and EOF reached  #define LINK_SIZE 1
1059  */  #elif LINK_SIZE == 3 || LINK_SIZE == 4
1060    #undef LINK_SIZE
1061    #define LINK_SIZE 2
1062    #else
1063    #error LINK_SIZE must be either 2, 3, or 4
1064    #endif
1065    
1066  static uschar *  #undef IMM2_SIZE
1067  extend_inputline(FILE *f, uschar *start)  #define IMM2_SIZE 1
 {  
 uschar *here = start;  
1068    
1069  for (;;)  #endif /* SUPPORT_PCRE8 && (SUPPORT_PCRE16 || SUPPORT_PCRE32) */
   {  
   int rlen = buffer_size - (here - buffer);  
1070    
   if (rlen > 1000)  
     {  
     int dlen;  
     if (fgets((char *)here, rlen,  f) == NULL)  
       return (here == start)? NULL : start;  
     dlen = (int)strlen((char *)here);  
     if (dlen > 0 && here[dlen - 1] == '\n') return start;  
     here += dlen;  
     }  
1071    
1072    else  #ifdef SUPPORT_PCRE16
1073      {  static int buffer16_size = 0;
1074      int new_buffer_size = 2*buffer_size;  static pcre_uint16 *buffer16 = NULL;
1075      uschar *new_buffer = (unsigned char *)malloc(new_buffer_size);  static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };
1076      uschar *new_dbuffer = (unsigned char *)malloc(new_buffer_size);  #endif  /* SUPPORT_PCRE16 */
1077      uschar *new_pbuffer = (unsigned char *)malloc(new_buffer_size);  
1078    #ifdef SUPPORT_PCRE32
1079    static int buffer32_size = 0;
1080    static pcre_uint32 *buffer32 = NULL;
1081    static const pcre_uint32 OP_lengths32[] = { OP_LENGTHS };
1082    #endif  /* SUPPORT_PCRE32 */
1083    
1084    /* If we have 8-bit support, default to it; if there is also 16-or 32-bit
1085    support, it can be changed by an option. If there is no 8-bit support, there
1086    must be 16-or 32-bit support, so default it to 1. */
1087    
1088    #if defined SUPPORT_PCRE8
1089    static int pcre_mode = PCRE8_MODE;
1090    #elif defined SUPPORT_PCRE16
1091    static int pcre_mode = PCRE16_MODE;
1092    #elif defined SUPPORT_PCRE32
1093    static int pcre_mode = PCRE32_MODE;
1094    #endif
1095    
1096      if (new_buffer == NULL || new_dbuffer == NULL || new_pbuffer == NULL)  /* JIT study options for -s+n and /S+n where '1' <= n <= '7'. */
       {  
       fprintf(stderr, "pcretest: malloc(%d) failed\n", new_buffer_size);  
       exit(1);  
       }  
1097    
1098      memcpy(new_buffer, buffer, buffer_size);  static int jit_study_bits[] =
1099      memcpy(new_pbuffer, pbuffer, buffer_size);    {
1100      PCRE_STUDY_JIT_COMPILE,
1101      PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE,
1102      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE,
1103      PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
1104      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
1105      PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE + PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE,
1106      PCRE_STUDY_JIT_COMPILE + PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE +
1107        PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE
1108    };
1109    
1110    #define PCRE_STUDY_ALLJIT (PCRE_STUDY_JIT_COMPILE | \
1111      PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE | PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE)
1112    
1113    /* Textual explanations for runtime error codes */
1114    
1115    static const char *errtexts[] = {
1116      NULL,  /* 0 is no error */
1117      NULL,  /* NOMATCH is handled specially */
1118      "NULL argument passed",
1119      "bad option value",
1120      "magic number missing",
1121      "unknown opcode - pattern overwritten?",
1122      "no more memory",
1123      NULL,  /* never returned by pcre_exec() or pcre_dfa_exec() */
1124      "match limit exceeded",
1125      "callout error code",
1126      NULL,  /* BADUTF8/16 is handled specially */
1127      NULL,  /* BADUTF8/16 offset is handled specially */
1128      NULL,  /* PARTIAL is handled specially */
1129      "not used - internal error",
1130      "internal error - pattern overwritten?",
1131      "bad count value",
1132      "item unsupported for DFA matching",
1133      "backreference condition or recursion test not supported for DFA matching",
1134      "match limit not supported for DFA matching",
1135      "workspace size exceeded in DFA matching",
1136      "too much recursion for DFA matching",
1137      "recursion limit exceeded",
1138      "not used - internal error",
1139      "invalid combination of newline options",
1140      "bad offset value",
1141      NULL,  /* SHORTUTF8/16 is handled specially */
1142      "nested recursion at the same subject position",
1143      "JIT stack limit reached",
1144      "pattern compiled in wrong mode: 8-bit/16-bit error",
1145      "pattern compiled with other endianness",
1146      "invalid data in workspace for DFA restart"
1147    };
1148    
     buffer_size = new_buffer_size;  
1149    
1150      start = new_buffer + (start - buffer);  /*************************************************
1151      here = new_buffer + (here - buffer);  *         Alternate character tables             *
1152    *************************************************/
1153    
1154      free(buffer);  /* By default, the "tables" pointer when calling PCRE is set to NULL, thereby
1155      free(dbuffer);  using the default tables of the library. However, the T option can be used to
1156      free(pbuffer);  select alternate sets of tables, for different kinds of testing. Note also that
1157    the L (locale) option also adjusts the tables. */
1158    
1159    /* This is the set of tables distributed as default with PCRE. It recognizes
1160    only ASCII characters. */
1161    
1162    static const pcre_uint8 tables0[] = {
1163    
1164    /* This table is a lower casing table. */
1165    
1166        0,  1,  2,  3,  4,  5,  6,  7,
1167        8,  9, 10, 11, 12, 13, 14, 15,
1168       16, 17, 18, 19, 20, 21, 22, 23,
1169       24, 25, 26, 27, 28, 29, 30, 31,
1170       32, 33, 34, 35, 36, 37, 38, 39,
1171       40, 41, 42, 43, 44, 45, 46, 47,
1172       48, 49, 50, 51, 52, 53, 54, 55,
1173       56, 57, 58, 59, 60, 61, 62, 63,
1174       64, 97, 98, 99,100,101,102,103,
1175      104,105,106,107,108,109,110,111,
1176      112,113,114,115,116,117,118,119,
1177      120,121,122, 91, 92, 93, 94, 95,
1178       96, 97, 98, 99,100,101,102,103,
1179      104,105,106,107,108,109,110,111,
1180      112,113,114,115,116,117,118,119,
1181      120,121,122,123,124,125,126,127,
1182      128,129,130,131,132,133,134,135,
1183      136,137,138,139,140,141,142,143,
1184      144,145,146,147,148,149,150,151,
1185      152,153,154,155,156,157,158,159,
1186      160,161,162,163,164,165,166,167,
1187      168,169,170,171,172,173,174,175,
1188      176,177,178,179,180,181,182,183,
1189      184,185,186,187,188,189,190,191,
1190      192,193,194,195,196,197,198,199,
1191      200,201,202,203,204,205,206,207,
1192      208,209,210,211,212,213,214,215,
1193      216,217,218,219,220,221,222,223,
1194      224,225,226,227,228,229,230,231,
1195      232,233,234,235,236,237,238,239,
1196      240,241,242,243,244,245,246,247,
1197      248,249,250,251,252,253,254,255,
1198    
1199    /* This table is a case flipping table. */
1200    
1201        0,  1,  2,  3,  4,  5,  6,  7,
1202        8,  9, 10, 11, 12, 13, 14, 15,
1203       16, 17, 18, 19, 20, 21, 22, 23,
1204       24, 25, 26, 27, 28, 29, 30, 31,
1205       32, 33, 34, 35, 36, 37, 38, 39,
1206       40, 41, 42, 43, 44, 45, 46, 47,
1207       48, 49, 50, 51, 52, 53, 54, 55,
1208       56, 57, 58, 59, 60, 61, 62, 63,
1209       64, 97, 98, 99,100,101,102,103,
1210      104,105,106,107,108,109,110,111,
1211      112,113,114,115,116,117,118,119,
1212      120,121,122, 91, 92, 93, 94, 95,
1213       96, 65, 66, 67, 68, 69, 70, 71,
1214       72, 73, 74, 75, 76, 77, 78, 79,
1215       80, 81, 82, 83, 84, 85, 86, 87,
1216       88, 89, 90,123,124,125,126,127,
1217      128,129,130,131,132,133,134,135,
1218      136,137,138,139,140,141,142,143,
1219      144,145,146,147,148,149,150,151,
1220      152,153,154,155,156,157,158,159,
1221      160,161,162,163,164,165,166,167,
1222      168,169,170,171,172,173,174,175,
1223      176,177,178,179,180,181,182,183,
1224      184,185,186,187,188,189,190,191,
1225      192,193,194,195,196,197,198,199,
1226      200,201,202,203,204,205,206,207,
1227      208,209,210,211,212,213,214,215,
1228      216,217,218,219,220,221,222,223,
1229      224,225,226,227,228,229,230,231,
1230      232,233,234,235,236,237,238,239,
1231      240,241,242,243,244,245,246,247,
1232      248,249,250,251,252,253,254,255,
1233    
1234    /* This table contains bit maps for various character classes. Each map is 32
1235    bytes long and the bits run from the least significant end of each byte. The
1236    classes that have their own maps are: space, xdigit, digit, upper, lower, word,
1237    graph, print, punct, and cntrl. Other classes are built from combinations. */
1238    
1239      0x00,0x3e,0x00,0x00,0x01,0x00,0x00,0x00,
1240      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1241      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1242      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1243    
1244      0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03,
1245      0x7e,0x00,0x00,0x00,0x7e,0x00,0x00,0x00,
1246      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1247      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1248    
1249      0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03,
1250      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1251      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1252      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1253    
1254      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1255      0xfe,0xff,0xff,0x07,0x00,0x00,0x00,0x00,
1256      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1257      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1258    
1259      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1260      0x00,0x00,0x00,0x00,0xfe,0xff,0xff,0x07,
1261      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1262      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1263    
1264      0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03,
1265      0xfe,0xff,0xff,0x87,0xfe,0xff,0xff,0x07,
1266      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1267      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1268    
1269      0x00,0x00,0x00,0x00,0xfe,0xff,0xff,0xff,
1270      0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
1271      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1272      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1273    
1274      0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
1275      0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
1276      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1277      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1278    
1279      0x00,0x00,0x00,0x00,0xfe,0xff,0x00,0xfc,
1280      0x01,0x00,0x00,0xf8,0x01,0x00,0x00,0x78,
1281      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1282      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1283    
1284      0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
1285      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,
1286      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1287      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1288    
1289    /* This table identifies various classes of character by individual bits:
1290      0x01   white space character
1291      0x02   letter
1292      0x04   decimal digit
1293      0x08   hexadecimal digit
1294      0x10   alphanumeric or '_'
1295      0x80   regular expression metacharacter or binary zero
1296    */
1297    
1298      0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   0-  7 */
1299      0x00,0x01,0x01,0x00,0x01,0x01,0x00,0x00, /*   8- 15 */
1300      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*  16- 23 */
1301      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*  24- 31 */
1302      0x01,0x00,0x00,0x00,0x80,0x00,0x00,0x00, /*    - '  */
1303      0x80,0x80,0x80,0x80,0x00,0x00,0x80,0x00, /*  ( - /  */
1304      0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c, /*  0 - 7  */
1305      0x1c,0x1c,0x00,0x00,0x00,0x00,0x00,0x80, /*  8 - ?  */
1306      0x00,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x12, /*  @ - G  */
1307      0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /*  H - O  */
1308      0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /*  P - W  */
1309      0x12,0x12,0x12,0x80,0x80,0x00,0x80,0x10, /*  X - _  */
1310      0x00,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x12, /*  ` - g  */
1311      0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /*  h - o  */
1312      0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /*  p - w  */
1313      0x12,0x12,0x12,0x80,0x80,0x00,0x00,0x00, /*  x -127 */
1314      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 128-135 */
1315      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 136-143 */
1316      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 144-151 */
1317      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 152-159 */
1318      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 160-167 */
1319      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 168-175 */
1320      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 176-183 */
1321      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 184-191 */
1322      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 192-199 */
1323      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 200-207 */
1324      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 208-215 */
1325      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 216-223 */
1326      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 224-231 */
1327      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 232-239 */
1328      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 240-247 */
1329      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/* 248-255 */
1330    
1331    /* This is a set of tables that came orginally from a Windows user. It seems to
1332    be at least an approximation of ISO 8859. In particular, there are characters
1333    greater than 128 that are marked as spaces, letters, etc. */
1334    
1335    static const pcre_uint8 tables1[] = {
1336    0,1,2,3,4,5,6,7,
1337    8,9,10,11,12,13,14,15,
1338    16,17,18,19,20,21,22,23,
1339    24,25,26,27,28,29,30,31,
1340    32,33,34,35,36,37,38,39,
1341    40,41,42,43,44,45,46,47,
1342    48,49,50,51,52,53,54,55,
1343    56,57,58,59,60,61,62,63,
1344    64,97,98,99,100,101,102,103,
1345    104,105,106,107,108,109,110,111,
1346    112,113,114,115,116,117,118,119,
1347    120,121,122,91,92,93,94,95,
1348    96,97,98,99,100,101,102,103,
1349    104,105,106,107,108,109,110,111,
1350    112,113,114,115,116,117,118,119,
1351    120,121,122,123,124,125,126,127,
1352    128,129,130,131,132,133,134,135,
1353    136,137,138,139,140,141,142,143,
1354    144,145,146,147,148,149,150,151,
1355    152,153,154,155,156,157,158,159,
1356    160,161,162,163,164,165,166,167,
1357    168,169,170,171,172,173,174,175,
1358    176,177,178,179,180,181,182,183,
1359    184,185,186,187,188,189,190,191,
1360    224,225,226,227,228,229,230,231,
1361    232,233,234,235,236,237,238,239,
1362    240,241,242,243,244,245,246,215,
1363    248,249,250,251,252,253,254,223,
1364    224,225,226,227,228,229,230,231,
1365    232,233,234,235,236,237,238,239,
1366    240,241,242,243,244,245,246,247,
1367    248,249,250,251,252,253,254,255,
1368    0,1,2,3,4,5,6,7,
1369    8,9,10,11,12,13,14,15,
1370    16,17,18,19,20,21,22,23,
1371    24,25,26,27,28,29,30,31,
1372    32,33,34,35,36,37,38,39,
1373    40,41,42,43,44,45,46,47,
1374    48,49,50,51,52,53,54,55,
1375    56,57,58,59,60,61,62,63,
1376    64,97,98,99,100,101,102,103,
1377    104,105,106,107,108,109,110,111,
1378    112,113,114,115,116,117,118,119,
1379    120,121,122,91,92,93,94,95,
1380    96,65,66,67,68,69,70,71,
1381    72,73,74,75,76,77,78,79,
1382    80,81,82,83,84,85,86,87,
1383    88,89,90,123,124,125,126,127,
1384    128,129,130,131,132,133,134,135,
1385    136,137,138,139,140,141,142,143,
1386    144,145,146,147,148,149,150,151,
1387    152,153,154,155,156,157,158,159,
1388    160,161,162,163,164,165,166,167,
1389    168,169,170,171,172,173,174,175,
1390    176,177,178,179,180,181,182,183,
1391    184,185,186,187,188,189,190,191,
1392    224,225,226,227,228,229,230,231,
1393    232,233,234,235,236,237,238,239,
1394    240,241,242,243,244,245,246,215,
1395    248,249,250,251,252,253,254,223,
1396    192,193,194,195,196,197,198,199,
1397    200,201,202,203,204,205,206,207,
1398    208,209,210,211,212,213,214,247,
1399    216,217,218,219,220,221,222,255,
1400    0,62,0,0,1,0,0,0,
1401    0,0,0,0,0,0,0,0,
1402    32,0,0,0,1,0,0,0,
1403    0,0,0,0,0,0,0,0,
1404    0,0,0,0,0,0,255,3,
1405    126,0,0,0,126,0,0,0,
1406    0,0,0,0,0,0,0,0,
1407    0,0,0,0,0,0,0,0,
1408    0,0,0,0,0,0,255,3,
1409    0,0,0,0,0,0,0,0,
1410    0,0,0,0,0,0,12,2,
1411    0,0,0,0,0,0,0,0,
1412    0,0,0,0,0,0,0,0,
1413    254,255,255,7,0,0,0,0,
1414    0,0,0,0,0,0,0,0,
1415    255,255,127,127,0,0,0,0,
1416    0,0,0,0,0,0,0,0,
1417    0,0,0,0,254,255,255,7,
1418    0,0,0,0,0,4,32,4,
1419    0,0,0,128,255,255,127,255,
1420    0,0,0,0,0,0,255,3,
1421    254,255,255,135,254,255,255,7,
1422    0,0,0,0,0,4,44,6,
1423    255,255,127,255,255,255,127,255,
1424    0,0,0,0,254,255,255,255,
1425    255,255,255,255,255,255,255,127,
1426    0,0,0,0,254,255,255,255,
1427    255,255,255,255,255,255,255,255,
1428    0,2,0,0,255,255,255,255,
1429    255,255,255,255,255,255,255,127,
1430    0,0,0,0,255,255,255,255,
1431    255,255,255,255,255,255,255,255,
1432    0,0,0,0,254,255,0,252,
1433    1,0,0,248,1,0,0,120,
1434    0,0,0,0,254,255,255,255,
1435    0,0,128,0,0,0,128,0,
1436    255,255,255,255,0,0,0,0,
1437    0,0,0,0,0,0,0,128,
1438    255,255,255,255,0,0,0,0,
1439    0,0,0,0,0,0,0,0,
1440    128,0,0,0,0,0,0,0,
1441    0,1,1,0,1,1,0,0,
1442    0,0,0,0,0,0,0,0,
1443    0,0,0,0,0,0,0,0,
1444    1,0,0,0,128,0,0,0,
1445    128,128,128,128,0,0,128,0,
1446    28,28,28,28,28,28,28,28,
1447    28,28,0,0,0,0,0,128,
1448    0,26,26,26,26,26,26,18,
1449    18,18,18,18,18,18,18,18,
1450    18,18,18,18,18,18,18,18,
1451    18,18,18,128,128,0,128,16,
1452    0,26,26,26,26,26,26,18,
1453    18,18,18,18,18,18,18,18,
1454    18,18,18,18,18,18,18,18,
1455    18,18,18,128,128,0,0,0,
1456    0,0,0,0,0,1,0,0,
1457    0,0,0,0,0,0,0,0,
1458    0,0,0,0,0,0,0,0,
1459    0,0,0,0,0,0,0,0,
1460    1,0,0,0,0,0,0,0,
1461    0,0,18,0,0,0,0,0,
1462    0,0,20,20,0,18,0,0,
1463    0,20,18,0,0,0,0,0,
1464    18,18,18,18,18,18,18,18,
1465    18,18,18,18,18,18,18,18,
1466    18,18,18,18,18,18,18,0,
1467    18,18,18,18,18,18,18,18,
1468    18,18,18,18,18,18,18,18,
1469    18,18,18,18,18,18,18,18,
1470    18,18,18,18,18,18,18,0,
1471    18,18,18,18,18,18,18,18
1472    };
1473    
     buffer = new_buffer;  
     dbuffer = new_dbuffer;  
     pbuffer = new_pbuffer;  
     }  
   }  
1474    
 return NULL;  /* Control never gets here */  
 }  
1475    
1476    
1477    #ifndef HAVE_STRERROR
1478    /*************************************************
1479    *     Provide strerror() for non-ANSI libraries  *
1480    *************************************************/
1481    
1482    /* Some old-fashioned systems still around (e.g. SunOS4) don't have strerror()
1483    in their libraries, but can provide the same facility by this simple
1484    alternative function. */
1485    
1486    extern int   sys_nerr;
1487    extern char *sys_errlist[];
1488    
1489    char *
1490    strerror(int n)
1491    {
1492    if (n < 0 || n >= sys_nerr) return "unknown error number";
1493    return sys_errlist[n];
1494    }
1495    #endif /* HAVE_STRERROR */
1496    
1497    
1498    
1499  /*************************************************  /*************************************************
1500  *          Read number from string               *  *       Print newline configuration              *
1501  *************************************************/  *************************************************/
1502    
1503  /* We don't use strtoul() because SunOS4 doesn't have it. Rather than mess  /*
 around with conditional compilation, just do the job by hand. It is only used  
 for unpicking arguments, so just keep it simple.  
   
1504  Arguments:  Arguments:
1505    str           string to be converted    rc         the return code from PCRE_CONFIG_NEWLINE
1506    endptr        where to put the end pointer    isc        TRUE if called from "-C newline"
1507    Returns:     nothing
 Returns:        the unsigned long  
1508  */  */
1509    
1510  static int  static void
1511  get_value(unsigned char *str, unsigned char **endptr)  print_newline_config(int rc, BOOL isc)
1512  {  {
1513  int result = 0;  const char *s = NULL;
1514  while(*str != 0 && isspace(*str)) str++;  if (!isc) printf("  Newline sequence is ");
1515  while (isdigit(*str)) result = result * 10 + (int)(*str++ - '0');  switch(rc)
1516  *endptr = str;    {
1517  return(result);    case CHAR_CR: s = "CR"; break;
1518      case CHAR_LF: s = "LF"; break;
1519      case (CHAR_CR<<8 | CHAR_LF): s = "CRLF"; break;
1520      case -1: s = "ANY"; break;
1521      case -2: s = "ANYCRLF"; break;
1522    
1523      default:
1524      printf("a non-standard value: 0x%04x\n", rc);
1525      return;
1526      }
1527    
1528    printf("%s\n", s);
1529  }  }
1530    
1531    
1532    
1533    /*************************************************
1534    *         JIT memory callback                    *
1535    *************************************************/
1536    
1537    static pcre_jit_stack* jit_callback(void *arg)
1538    {
1539    jit_was_used = TRUE;
1540    return (pcre_jit_stack *)arg;
1541    }
1542    
1543    
1544    #if !defined NOUTF || defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32
1545  /*************************************************  /*************************************************
1546  *            Convert UTF-8 string to value       *  *            Convert UTF-8 string to value       *
1547  *************************************************/  *************************************************/
# Line 297  Returns:      >  0 => the number of byte Line 1557  Returns:      >  0 => the number of byte
1557                -6 to 0 => malformed UTF-8 character at offset = (-return)                -6 to 0 => malformed UTF-8 character at offset = (-return)
1558  */  */
1559    
 #if !defined NOUTF8  
   
1560  static int  static int
1561  utf82ord(unsigned char *utf8bytes, int *vptr)  utf82ord(pcre_uint8 *utf8bytes, pcre_uint32 *vptr)
1562  {  {
1563  int c = *utf8bytes++;  pcre_uint32 c = *utf8bytes++;
1564  int d = c;  pcre_uint32 d = c;
1565  int i, j, s;  int i, j, s;
1566    
1567  for (i = -1; i < 6; i++)               /* i is number of additional bytes */  for (i = -1; i < 6; i++)               /* i is number of additional bytes */
# Line 331  for (j = 0; j < i; j++) Line 1589  for (j = 0; j < i; j++)
1589  /* Check that encoding was the correct unique one */  /* Check that encoding was the correct unique one */
1590    
1591  for (j = 0; j < utf8_table1_size; j++)  for (j = 0; j < utf8_table1_size; j++)
1592    if (d <= utf8_table1[j]) break;    if (d <= (pcre_uint32)utf8_table1[j]) break;
1593  if (j != i) return -(i+1);  if (j != i) return -(i+1);
1594    
1595  /* Valid value */  /* Valid value */
# Line 339  if (j != i) return -(i+1); Line 1597  if (j != i) return -(i+1);
1597  *vptr = d;  *vptr = d;
1598  return i+1;  return i+1;
1599  }  }
1600    #endif /* NOUTF || SUPPORT_PCRE16 */
 #endif  
1601    
1602    
1603    
1604    #if defined SUPPORT_PCRE8 && !defined NOUTF
1605  /*************************************************  /*************************************************
1606  *       Convert character value to UTF-8         *  *       Convert character value to UTF-8         *
1607  *************************************************/  *************************************************/
# Line 358  Arguments: Line 1616  Arguments:
1616  Returns:     number of characters placed in the buffer  Returns:     number of characters placed in the buffer
1617  */  */
1618    
 #if !defined NOUTF8  
   
1619  static int  static int
1620  ord2utf8(int cvalue, uschar *utf8bytes)  ord2utf8(pcre_uint32 cvalue, pcre_uint8 *utf8bytes)
1621  {  {
1622  register int i, j;  register int i, j;
1623    if (cvalue > 0x7fffffffu)
1624      return -1;
1625  for (i = 0; i < utf8_table1_size; i++)  for (i = 0; i < utf8_table1_size; i++)
1626    if (cvalue <= utf8_table1[i]) break;    if (cvalue <= (pcre_uint32)utf8_table1[i]) break;
1627  utf8bytes += i;  utf8bytes += i;
1628  for (j = i; j > 0; j--)  for (j = i; j > 0; j--)
1629   {   {
# Line 375  for (j = i; j > 0; j--) Line 1633  for (j = i; j > 0; j--)
1633  *utf8bytes = utf8_table2[i] | cvalue;  *utf8bytes = utf8_table2[i] | cvalue;
1634  return i + 1;  return i + 1;
1635  }  }
   
1636  #endif  #endif
1637    
1638    
1639    #ifdef SUPPORT_PCRE16
1640  /*************************************************  /*************************************************
1641  *             Print character string             *  *         Convert a string to 16-bit             *
1642  *************************************************/  *************************************************/
1643    
1644  /* Character string printing function. Must handle UTF-8 strings in utf8  /* In non-UTF mode, the space needed for a 16-bit string is exactly double the
1645  mode. Yields number of characters printed. If handed a NULL file, just counts  8-bit size. For a UTF-8 string, the size needed for UTF-16 is no more than
1646  chars without printing. */  double, because up to 0xffff uses no more than 3 bytes in UTF-8 but possibly 4
1647    in UTF-16. Higher values use 4 bytes in UTF-8 and up to 4 bytes in UTF-16. The
1648    result is always left in buffer16.
1649    
1650    Note that this function does not object to surrogate values. This is
1651    deliberate; it makes it possible to construct UTF-16 strings that are invalid,
1652    for the purpose of testing that they are correctly faulted.
1653    
1654    Patterns to be converted are either plain ASCII or UTF-8; data lines are always
1655    in UTF-8 so that values greater than 255 can be handled.
1656    
1657    Arguments:
1658      data       TRUE if converting a data line; FALSE for a regex
1659      p          points to a byte string
1660      utf        true if UTF-8 (to be converted to UTF-16)
1661      len        number of bytes in the string (excluding trailing zero)
1662    
1663    Returns:     number of 16-bit data items used (excluding trailing zero)
1664                 OR -1 if a UTF-8 string is malformed
1665                 OR -2 if a value > 0x10ffff is encountered
1666                 OR -3 if a value > 0xffff is encountered when not in UTF mode
1667    */
1668    
1669  static int pchars(unsigned char *p, int length, FILE *f)  static int
1670    to16(int data, pcre_uint8 *p, int utf, int len)
1671  {  {
1672  int c = 0;  pcre_uint16 *pp;
 int yield = 0;  
1673    
1674  while (length-- > 0)  if (buffer16_size < 2*len + 2)
1675    {    {
1676  #if !defined NOUTF8    if (buffer16 != NULL) free(buffer16);
1677    if (use_utf8)    buffer16_size = 2*len + 2;
1678      buffer16 = (pcre_uint16 *)malloc(buffer16_size);
1679      if (buffer16 == NULL)
1680      {      {
1681      int rc = utf82ord(p, &c);      fprintf(stderr, "pcretest: malloc(%d) failed for buffer16\n", buffer16_size);
1682        exit(1);
     if (rc > 0 && rc <= length + 1)   /* Mustn't run over the end */  
       {  
       length -= rc - 1;  
       p += rc;  
       if (PRINTHEX(c))  
         {  
         if (f != NULL) fprintf(f, "%c", c);  
         yield++;  
         }  
       else  
         {  
         int n = 4;  
         if (f != NULL) fprintf(f, "\\x{%02x}", c);  
         yield += (n <= 0x000000ff)? 2 :  
                  (n <= 0x00000fff)? 3 :  
                  (n <= 0x0000ffff)? 4 :  
                  (n <= 0x000fffff)? 5 : 6;  
         }  
       continue;  
       }  
1683      }      }
1684  #endif    }
1685    
1686     /* Not UTF-8, or malformed UTF-8  */  pp = buffer16;
1687    
1688    c = *p++;  if (!utf && !data)
1689    if (PRINTHEX(c))    {
1690      {    while (len-- > 0) *pp++ = *p++;
1691      if (f != NULL) fprintf(f, "%c", c);    }
1692      yield++;  
1693      }  else
1694    else    {
1695      pcre_uint32 c = 0;
1696      while (len > 0)
1697      {      {
1698      if (f != NULL) fprintf(f, "\\x%02x", c);      int chlen = utf82ord(p, &c);
1699      yield += 4;      if (chlen <= 0) return -1;
1700        if (c > 0x10ffff) return -2;
1701        p += chlen;
1702        len -= chlen;
1703        if (c < 0x10000) *pp++ = c; else
1704          {
1705          if (!utf) return -3;
1706          c -= 0x10000;
1707          *pp++ = 0xD800 | (c >> 10);
1708          *pp++ = 0xDC00 | (c & 0x3ff);
1709          }
1710      }      }
1711    }    }
1712    
1713  return yield;  *pp = 0;
1714    return pp - buffer16;
1715  }  }
1716    #endif
1717    
1718    #ifdef SUPPORT_PCRE32
   
1719  /*************************************************  /*************************************************
1720  *              Callout function                  *  *         Convert a string to 32-bit             *
1721  *************************************************/  *************************************************/
1722    
1723  /* Called from PCRE as a result of the (?C) item. We print out where we are in  /* In non-UTF mode, the space needed for a 32-bit string is exactly four times the
1724  the match. Yield zero unless more callouts than the fail count, or the callout  8-bit size. For a UTF-8 string, the size needed for UTF-32 is no more than four
1725  data is not zero. */  times, because up to 0xffff uses no more than 3 bytes in UTF-8 but possibly 4
1726    in UTF-32. Higher values use 4 bytes in UTF-8 and up to 4 bytes in UTF-32. The
1727    result is always left in buffer32.
1728    
1729    Note that this function does not object to surrogate values. This is
1730    deliberate; it makes it possible to construct UTF-32 strings that are invalid,
1731    for the purpose of testing that they are correctly faulted.
1732    
1733  static int callout(pcre_callout_block *cb)  Patterns to be converted are either plain ASCII or UTF-8; data lines are always
1734    in UTF-8 so that values greater than 255 can be handled.
1735    
1736    Arguments:
1737      data       TRUE if converting a data line; FALSE for a regex
1738      p          points to a byte string
1739      utf        true if UTF-8 (to be converted to UTF-32)
1740      len        number of bytes in the string (excluding trailing zero)
1741    
1742    Returns:     number of 32-bit data items used (excluding trailing zero)
1743                 OR -1 if a UTF-8 string is malformed
1744                 OR -2 if a value > 0x10ffff is encountered
1745                 OR -3 if an ill-formed value is encountered (i.e. a surrogate)
1746    */
1747    
1748    static int
1749    to32(int data, pcre_uint8 *p, int utf, int len)
1750  {  {
1751  FILE *f = (first_callout | callout_extra)? outfile : NULL;  pcre_uint32 *pp;
 int i, pre_start, post_start, subject_length;  
1752    
1753  if (callout_extra)  if (buffer32_size < 4*len + 4)
1754    {    {
1755    fprintf(f, "Callout %d: last capture = %d\n",    if (buffer32 != NULL) free(buffer32);
1756      cb->callout_number, cb->capture_last);    buffer32_size = 4*len + 4;
1757      buffer32 = (pcre_uint32 *)malloc(buffer32_size);
1758      if (buffer32 == NULL)
1759        {
1760        fprintf(stderr, "pcretest: malloc(%d) failed for buffer32\n", buffer32_size);
1761        exit(1);
1762        }
1763      }
1764    
1765    for (i = 0; i < cb->capture_top * 2; i += 2)  pp = buffer32;
1766    
1767    if (!utf && !data)
1768      {
1769      while (len-- > 0) *pp++ = *p++;
1770      }
1771    
1772    else
1773      {
1774      pcre_uint32 c = 0;
1775      while (len > 0)
1776      {      {
1777      if (cb->offset_vector[i] < 0)      int chlen = utf82ord(p, &c);
1778        fprintf(f, "%2d: <unset>\n", i/2);      if (chlen <= 0) return -1;
1779      else      if (utf)
1780        {        {
1781        fprintf(f, "%2d: ", i/2);        if (c > 0x10ffff) return -2;
1782        (void)pchars((unsigned char *)cb->subject + cb->offset_vector[i],        if (!data && (c & 0xfffff800u) == 0xd800u) return -3;
         cb->offset_vector[i+1] - cb->offset_vector[i], f);  
       fprintf(f, "\n");  
1783        }        }
1784    
1785        p += chlen;
1786        len -= chlen;
1787        *pp++ = c;
1788      }      }
1789    }    }
1790    
1791  /* Re-print the subject in canonical form, the first time or if giving full  *pp = 0;
1792  datails. On subsequent calls in the same match, we use pchars just to find the  return pp - buffer32;
1793  printed lengths of the substrings. */  }
   
 if (f != NULL) fprintf(f, "--->");  
   
 pre_start = pchars((unsigned char *)cb->subject, cb->start_match, f);  
 post_start = pchars((unsigned char *)(cb->subject + cb->start_match),  
   cb->current_position - cb->start_match, f);  
1794    
1795  subject_length = pchars((unsigned char *)cb->subject, cb->subject_length, NULL);  /* Check that a 32-bit character string is valid UTF-32.
1796    
1797  (void)pchars((unsigned char *)(cb->subject + cb->current_position),  Arguments:
1798    cb->subject_length - cb->current_position, f);    string       points to the string
1799      length       length of string, or -1 if the string is zero-terminated
1800    
1801  if (f != NULL) fprintf(f, "\n");  Returns:       TRUE  if the string is a valid UTF-32 string
1802                   FALSE otherwise
1803    */
1804    
1805  /* Always print appropriate indicators, with callout number if not already  #ifdef SUPPORT_UTF
1806  shown. For automatic callouts, show the pattern offset. */  static BOOL
1807    valid_utf32(pcre_uint32 *string, int length)
1808    {
1809    register pcre_uint32 *p;
1810    register pcre_uint32 c;
1811    
1812  if (cb->callout_number == 255)  for (p = string; length-- > 0; p++)
   {  
   fprintf(outfile, "%+3d ", cb->pattern_position);  
   if (cb->pattern_position > 99) fprintf(outfile, "\n    ");  
   }  
 else  
1813    {    {
1814    if (callout_extra) fprintf(outfile, "    ");    c = *p;
     else fprintf(outfile, "%3d ", cb->callout_number);  
   }  
1815    
1816  for (i = 0; i < pre_start; i++) fprintf(outfile, " ");    if (c > 0x10ffffu)
1817  fprintf(outfile, "^");      return FALSE;
1818    
1819  if (post_start > 0)    /* A surrogate */
1820    {    if ((c & 0xfffff800u) == 0xd800u)
1821    for (i = 0; i < post_start - 1; i++) fprintf(outfile, " ");      return FALSE;
1822    fprintf(outfile, "^");  
1823      /* Non-character */
1824      if ((c & 0xfffeu) == 0xfffeu || (c >= 0xfdd0u && c <= 0xfdefu))
1825        return FALSE;
1826    }    }
1827    
1828  for (i = 0; i < subject_length - pre_start - post_start + 4; i++)  return TRUE;
1829    fprintf(outfile, " ");  }
1830    #endif /* SUPPORT_UTF */
1831    
1832  fprintf(outfile, "%.*s", (cb->next_item_length == 0)? 1 : cb->next_item_length,  #endif
1833    pbuffer + cb->pattern_position);  
1834    /*************************************************
1835    *        Read or extend an input line            *
1836    *************************************************/
1837    
1838    /* Input lines are read into buffer, but both patterns and data lines can be
1839    continued over multiple input lines. In addition, if the buffer fills up, we
1840    want to automatically expand it so as to be able to handle extremely large
1841    lines that are needed for certain stress tests. When the input buffer is
1842    expanded, the other two buffers must also be expanded likewise, and the
1843    contents of pbuffer, which are a copy of the input for callouts, must be
1844    preserved (for when expansion happens for a data line). This is not the most
1845    optimal way of handling this, but hey, this is just a test program!
1846    
1847    Arguments:
1848      f            the file to read
1849      start        where in buffer to start (this *must* be within buffer)
1850      prompt       for stdin or readline()
1851    
1852    Returns:       pointer to the start of new data
1853                   could be a copy of start, or could be moved
1854                   NULL if no data read and EOF reached
1855    */
1856    
1857    static pcre_uint8 *
1858    extend_inputline(FILE *f, pcre_uint8 *start, const char *prompt)
1859    {
1860    pcre_uint8 *here = start;
1861    
1862    for (;;)
1863      {
1864      size_t rlen = (size_t)(buffer_size - (here - buffer));
1865    
1866      if (rlen > 1000)
1867        {
1868        int dlen;
1869    
1870        /* If libreadline or libedit support is required, use readline() to read a
1871        line if the input is a terminal. Note that readline() removes the trailing
1872        newline, so we must put it back again, to be compatible with fgets(). */
1873    
1874    #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
1875        if (isatty(fileno(f)))
1876          {
1877          size_t len;
1878          char *s = readline(prompt);
1879          if (s == NULL) return (here == start)? NULL : start;
1880          len = strlen(s);
1881          if (len > 0) add_history(s);
1882          if (len > rlen - 1) len = rlen - 1;
1883          memcpy(here, s, len);
1884          here[len] = '\n';
1885          here[len+1] = 0;
1886          free(s);
1887          }
1888        else
1889    #endif
1890    
1891        /* Read the next line by normal means, prompting if the file is stdin. */
1892    
1893          {
1894          if (f == stdin) printf("%s", prompt);
1895          if (fgets((char *)here, rlen,  f) == NULL)
1896            return (here == start)? NULL : start;
1897          }
1898    
1899        dlen = (int)strlen((char *)here);
1900        if (dlen > 0 && here[dlen - 1] == '\n') return start;
1901        here += dlen;
1902        }
1903    
1904      else
1905        {
1906        int new_buffer_size = 2*buffer_size;
1907        pcre_uint8 *new_buffer = (pcre_uint8 *)malloc(new_buffer_size);
1908        pcre_uint8 *new_pbuffer = (pcre_uint8 *)malloc(new_buffer_size);
1909    
1910        if (new_buffer == NULL || new_pbuffer == NULL)
1911          {
1912          fprintf(stderr, "pcretest: malloc(%d) failed\n", new_buffer_size);
1913          exit(1);
1914          }
1915    
1916        memcpy(new_buffer, buffer, buffer_size);
1917        memcpy(new_pbuffer, pbuffer, buffer_size);
1918    
1919        buffer_size = new_buffer_size;
1920    
1921        start = new_buffer + (start - buffer);
1922        here = new_buffer + (here - buffer);
1923    
1924        free(buffer);
1925        free(pbuffer);
1926    
1927        buffer = new_buffer;
1928        pbuffer = new_pbuffer;
1929        }
1930      }
1931    
1932    return NULL;  /* Control never gets here */
1933    }
1934    
1935    
1936    
1937    /*************************************************
1938    *          Read number from string               *
1939    *************************************************/
1940    
1941    /* We don't use strtoul() because SunOS4 doesn't have it. Rather than mess
1942    around with conditional compilation, just do the job by hand. It is only used
1943    for unpicking arguments, so just keep it simple.
1944    
1945    Arguments:
1946      str           string to be converted
1947      endptr        where to put the end pointer
1948    
1949    Returns:        the unsigned long
1950    */
1951    
1952    static int
1953    get_value(pcre_uint8 *str, pcre_uint8 **endptr)
1954    {
1955    int result = 0;
1956    while(*str != 0 && isspace(*str)) str++;
1957    while (isdigit(*str)) result = result * 10 + (int)(*str++ - '0');
1958    *endptr = str;
1959    return(result);
1960    }
1961    
1962    
1963    
1964    /*************************************************
1965    *             Print one character                *
1966    *************************************************/
1967    
1968    /* Print a single character either literally, or as a hex escape. */
1969    
1970    static int pchar(pcre_uint32 c, FILE *f)
1971    {
1972    int n = 0;
1973    if (PRINTOK(c))
1974      {
1975      if (f != NULL) fprintf(f, "%c", c);
1976      return 1;
1977      }
1978    
1979    if (c < 0x100)
1980      {
1981      if (use_utf)
1982        {
1983        if (f != NULL) fprintf(f, "\\x{%02x}", c);
1984        return 6;
1985        }
1986      else
1987        {
1988        if (f != NULL) fprintf(f, "\\x%02x", c);
1989        return 4;
1990        }
1991      }
1992    
1993    if (f != NULL) n = fprintf(f, "\\x{%02x}", c);
1994    return n >= 0 ? n : 0;
1995    }
1996    
1997    
1998    
1999    #ifdef SUPPORT_PCRE8
2000    /*************************************************
2001    *         Print 8-bit character string           *
2002    *************************************************/
2003    
2004    /* Must handle UTF-8 strings in utf8 mode. Yields number of characters printed.
2005    If handed a NULL file, just counts chars without printing. */
2006    
2007    static int pchars(pcre_uint8 *p, int length, FILE *f)
2008    {
2009    pcre_uint32 c = 0;
2010    int yield = 0;
2011    
2012    if (length < 0)
2013      length = strlen((char *)p);
2014    
2015    while (length-- > 0)
2016      {
2017    #if !defined NOUTF
2018      if (use_utf)
2019        {
2020        int rc = utf82ord(p, &c);
2021        if (rc > 0 && rc <= length + 1)   /* Mustn't run over the end */
2022          {
2023          length -= rc - 1;
2024          p += rc;
2025          yield += pchar(c, f);
2026          continue;
2027          }
2028        }
2029    #endif
2030      c = *p++;
2031      yield += pchar(c, f);
2032      }
2033    
2034    return yield;
2035    }
2036    #endif
2037    
2038    
2039    
2040    #ifdef SUPPORT_PCRE16
2041    /*************************************************
2042    *    Find length of 0-terminated 16-bit string   *
2043    *************************************************/
2044    
2045    static int strlen16(PCRE_SPTR16 p)
2046    {
2047    int len = 0;
2048    while (*p++ != 0) len++;
2049    return len;
2050    }
2051    #endif  /* SUPPORT_PCRE16 */
2052    
2053    
2054    
2055    #ifdef SUPPORT_PCRE32
2056    /*************************************************
2057    *    Find length of 0-terminated 32-bit string   *
2058    *************************************************/
2059    
2060    static int strlen32(PCRE_SPTR32 p)
2061    {
2062    int len = 0;
2063    while (*p++ != 0) len++;
2064    return len;
2065    }
2066    #endif  /* SUPPORT_PCRE32 */
2067    
2068    
2069    
2070    #ifdef SUPPORT_PCRE16
2071    /*************************************************
2072    *           Print 16-bit character string        *
2073    *************************************************/
2074    
2075    /* Must handle UTF-16 strings in utf mode. Yields number of characters printed.
2076    If handed a NULL file, just counts chars without printing. */
2077    
2078    static int pchars16(PCRE_SPTR16 p, int length, FILE *f)
2079    {
2080    int yield = 0;
2081    
2082    if (length < 0)
2083      length = strlen16(p);
2084    
2085    while (length-- > 0)
2086      {
2087      pcre_uint32 c = *p++ & 0xffff;
2088    #if !defined NOUTF
2089      if (use_utf && c >= 0xD800 && c < 0xDC00 && length > 0)
2090        {
2091        int d = *p & 0xffff;
2092        if (d >= 0xDC00 && d < 0xDFFF)
2093          {
2094          c = ((c & 0x3ff) << 10) + (d & 0x3ff) + 0x10000;
2095          length--;
2096          p++;
2097          }
2098        }
2099    #endif
2100      yield += pchar(c, f);
2101      }
2102    
2103    return yield;
2104    }
2105    #endif  /* SUPPORT_PCRE16 */
2106    
2107    
2108    
2109    #ifdef SUPPORT_PCRE32
2110    /*************************************************
2111    *           Print 32-bit character string        *
2112    *************************************************/
2113    
2114    /* Must handle UTF-32 strings in utf mode. Yields number of characters printed.
2115    If handed a NULL file, just counts chars without printing. */
2116    
2117    #define UTF32_MASK (0x1fffffu)
2118    
2119    static int pchars32(PCRE_SPTR32 p, int length, BOOL utf, FILE *f)
2120    {
2121    int yield = 0;
2122    
2123    if (length < 0)
2124      length = strlen32(p);
2125    
2126    while (length-- > 0)
2127      {
2128      pcre_uint32 c = *p++;
2129      if (utf) c &= UTF32_MASK;
2130      yield += pchar(c, f);
2131      }
2132    
2133    return yield;
2134    }
2135    #endif  /* SUPPORT_PCRE32 */
2136    
2137    
2138    
2139    #ifdef SUPPORT_PCRE8
2140    /*************************************************
2141    *     Read a capture name (8-bit) and check it   *
2142    *************************************************/
2143    
2144    static pcre_uint8 *
2145    read_capture_name8(pcre_uint8 *p, pcre_uint8 **pp, pcre *re)
2146    {
2147    pcre_uint8 *npp = *pp;
2148    while (isalnum(*p)) *npp++ = *p++;
2149    *npp++ = 0;
2150    *npp = 0;
2151    if (pcre_get_stringnumber(re, (char *)(*pp)) < 0)
2152      {
2153      fprintf(outfile, "no parentheses with name \"");
2154      PCHARSV(*pp, 0, -1, outfile);
2155      fprintf(outfile, "\"\n");
2156      }
2157    
2158    *pp = npp;
2159    return p;
2160    }
2161    #endif  /* SUPPORT_PCRE8 */
2162    
2163    
2164    
2165    #ifdef SUPPORT_PCRE16
2166    /*************************************************
2167    *     Read a capture name (16-bit) and check it  *
2168    *************************************************/
2169    
2170    /* Note that the text being read is 8-bit. */
2171    
2172    static pcre_uint8 *
2173    read_capture_name16(pcre_uint8 *p, pcre_uint16 **pp, pcre *re)
2174    {
2175    pcre_uint16 *npp = *pp;
2176    while (isalnum(*p)) *npp++ = *p++;
2177    *npp++ = 0;
2178    *npp = 0;
2179    if (pcre16_get_stringnumber((pcre16 *)re, (PCRE_SPTR16)(*pp)) < 0)
2180      {
2181      fprintf(outfile, "no parentheses with name \"");
2182      PCHARSV(*pp, 0, -1, outfile);
2183      fprintf(outfile, "\"\n");
2184      }
2185    *pp = npp;
2186    return p;
2187    }
2188    #endif  /* SUPPORT_PCRE16 */
2189    
2190    
2191    
2192    #ifdef SUPPORT_PCRE32
2193    /*************************************************
2194    *     Read a capture name (32-bit) and check it  *
2195    *************************************************/
2196    
2197    /* Note that the text being read is 8-bit. */
2198    
2199    static pcre_uint8 *
2200    read_capture_name32(pcre_uint8 *p, pcre_uint32 **pp, pcre *re)
2201    {
2202    pcre_uint32 *npp = *pp;
2203    while (isalnum(*p)) *npp++ = *p++;
2204    *npp++ = 0;
2205    *npp = 0;
2206    if (pcre32_get_stringnumber((pcre32 *)re, (PCRE_SPTR32)(*pp)) < 0)
2207      {
2208      fprintf(outfile, "no parentheses with name \"");
2209      PCHARSV(*pp, 0, -1, outfile);
2210      fprintf(outfile, "\"\n");
2211      }
2212    *pp = npp;
2213    return p;
2214    }
2215    #endif  /* SUPPORT_PCRE32 */
2216    
2217    
2218    
2219    /*************************************************
2220    *              Callout function                  *
2221    *************************************************/
2222    
2223    /* Called from PCRE as a result of the (?C) item. We print out where we are in
2224    the match. Yield zero unless more callouts than the fail count, or the callout
2225    data is not zero. */
2226    
2227    static int callout(pcre_callout_block *cb)
2228    {
2229    FILE *f = (first_callout | callout_extra)? outfile : NULL;
2230    int i, pre_start, post_start, subject_length;
2231    
2232    if (callout_extra)
2233      {
2234      fprintf(f, "Callout %d: last capture = %d\n",
2235        cb->callout_number, cb->capture_last);
2236    
2237      for (i = 0; i < cb->capture_top * 2; i += 2)
2238        {
2239        if (cb->offset_vector[i] < 0)
2240          fprintf(f, "%2d: <unset>\n", i/2);
2241        else
2242          {
2243          fprintf(f, "%2d: ", i/2);
2244          PCHARSV(cb->subject, cb->offset_vector[i],
2245            cb->offset_vector[i+1] - cb->offset_vector[i], f);
2246          fprintf(f, "\n");
2247          }
2248        }
2249      }
2250    
2251    /* Re-print the subject in canonical form, the first time or if giving full
2252    datails. On subsequent calls in the same match, we use pchars just to find the
2253    printed lengths of the substrings. */
2254    
2255    if (f != NULL) fprintf(f, "--->");
2256    
2257    PCHARS(pre_start, cb->subject, 0, cb->start_match, f);
2258    PCHARS(post_start, cb->subject, cb->start_match,
2259      cb->current_position - cb->start_match, f);
2260    
2261    PCHARS(subject_length, cb->subject, 0, cb->subject_length, NULL);
2262    
2263    PCHARSV(cb->subject, cb->current_position,
2264      cb->subject_length - cb->current_position, f);
2265    
2266    if (f != NULL) fprintf(f, "\n");
2267    
2268    /* Always print appropriate indicators, with callout number if not already
2269    shown. For automatic callouts, show the pattern offset. */
2270    
2271    if (cb->callout_number == 255)
2272      {
2273      fprintf(outfile, "%+3d ", cb->pattern_position);
2274      if (cb->pattern_position > 99) fprintf(outfile, "\n    ");
2275      }
2276    else
2277      {
2278      if (callout_extra) fprintf(outfile, "    ");
2279        else fprintf(outfile, "%3d ", cb->callout_number);
2280      }
2281    
2282    for (i = 0; i < pre_start; i++) fprintf(outfile, " ");
2283    fprintf(outfile, "^");
2284    
2285    if (post_start > 0)
2286      {
2287      for (i = 0; i < post_start - 1; i++) fprintf(outfile, " ");
2288      fprintf(outfile, "^");
2289      }
2290    
2291    for (i = 0; i < subject_length - pre_start - post_start + 4; i++)
2292      fprintf(outfile, " ");
2293    
2294    fprintf(outfile, "%.*s", (cb->next_item_length == 0)? 1 : cb->next_item_length,
2295      pbuffer + cb->pattern_position);
2296    
2297  fprintf(outfile, "\n");  fprintf(outfile, "\n");
2298  first_callout = 0;  first_callout = 0;
2299    
2300    if (cb->mark != last_callout_mark)
2301      {
2302      if (cb->mark == NULL)
2303        fprintf(outfile, "Latest Mark: <unset>\n");
2304      else
2305        {
2306        fprintf(outfile, "Latest Mark: ");
2307        PCHARSV(cb->mark, 0, -1, outfile);
2308        putc('\n', outfile);
2309        }
2310      last_callout_mark = cb->mark;
2311      }
2312    
2313  if (cb->callout_data != NULL)  if (cb->callout_data != NULL)
2314    {    {
2315    int callout_data = *((int *)(cb->callout_data));    int callout_data = *((int *)(cb->callout_data));
# Line 543  return (cb->callout_number != callout_fa Line 2329  return (cb->callout_number != callout_fa
2329  *            Local malloc functions              *  *            Local malloc functions              *
2330  *************************************************/  *************************************************/
2331    
2332  /* Alternative malloc function, to test functionality and show the size of the  /* Alternative malloc function, to test functionality and save the size of a
2333  compiled re. */  compiled re, which is the first store request that pcre_compile() makes. The
2334    show_malloc variable is set only during matching. */
2335    
2336  static void *new_malloc(size_t size)  static void *new_malloc(size_t size)
2337  {  {
2338  void *block = malloc(size);  void *block = malloc(size);
2339  gotten_store = size;  gotten_store = size;
2340    if (first_gotten_store == 0) first_gotten_store = size;
2341  if (show_malloc)  if (show_malloc)
2342    fprintf(outfile, "malloc       %3d %p\n", (int)size, block);    fprintf(outfile, "malloc       %3d %p\n", (int)size, block);
2343  return block;  return block;
# Line 562  if (show_malloc) Line 2350  if (show_malloc)
2350  free(block);  free(block);
2351  }  }
2352    
   
2353  /* For recursion malloc/free, to test stacking calls */  /* For recursion malloc/free, to test stacking calls */
2354    
2355  static void *stack_malloc(size_t size)  static void *stack_malloc(size_t size)
# Line 581  free(block); Line 2368  free(block);
2368  }  }
2369    
2370    
2371  /*************************************************  /*************************************************
2372  *          Call pcre_fullinfo()                  *  *          Call pcre_fullinfo()                  *
2373  *************************************************/  *************************************************/
2374    
2375    /* Get one piece of information from the pcre_fullinfo() function. When only
2376    one of 8-, 16- or 32-bit is supported, pcre_mode should always have the correct
2377    value, but the code is defensive.
2378    
2379    Arguments:
2380      re        compiled regex
2381      study     study data
2382      option    PCRE_INFO_xxx option
2383      ptr       where to put the data
2384    
2385    Returns:    0 when OK, < 0 on error
2386    */
2387    
2388    static int
2389    new_info(pcre *re, pcre_extra *study, int option, void *ptr)
2390    {
2391    int rc;
2392    
2393    if (pcre_mode == PCRE32_MODE)
2394    #ifdef SUPPORT_PCRE32
2395      rc = pcre32_fullinfo((pcre32 *)re, (pcre32_extra *)study, option, ptr);
2396    #else
2397      rc = PCRE_ERROR_BADMODE;
2398    #endif
2399    else if (pcre_mode == PCRE16_MODE)
2400    #ifdef SUPPORT_PCRE16
2401      rc = pcre16_fullinfo((pcre16 *)re, (pcre16_extra *)study, option, ptr);
2402    #else
2403      rc = PCRE_ERROR_BADMODE;
2404    #endif
2405    else
2406    #ifdef SUPPORT_PCRE8
2407      rc = pcre_fullinfo(re, study, option, ptr);
2408    #else
2409      rc = PCRE_ERROR_BADMODE;
2410    #endif
2411    
2412    if (rc < 0)
2413      {
2414      fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
2415        pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "", option);
2416      if (rc == PCRE_ERROR_BADMODE)
2417        fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
2418          "%d-bit mode\n", 8 * CHAR_SIZE,
2419          8 * (REAL_PCRE_FLAGS(re) & PCRE_MODE_MASK));
2420      }
2421    
2422    return rc;
2423    }
2424    
2425    
2426    
2427    /*************************************************
2428    *             Swap byte functions                *
2429    *************************************************/
2430    
2431    /* The following functions swap the bytes of a pcre_uint16 and pcre_uint32
2432    value, respectively.
2433    
2434    Arguments:
2435      value        any number
2436    
2437    Returns:       the byte swapped value
2438    */
2439    
2440    static pcre_uint32
2441    swap_uint32(pcre_uint32 value)
2442    {
2443    return ((value & 0x000000ff) << 24) |
2444           ((value & 0x0000ff00) <<  8) |
2445           ((value & 0x00ff0000) >>  8) |
2446           (value >> 24);
2447    }
2448    
2449    static pcre_uint16
2450    swap_uint16(pcre_uint16 value)
2451    {
2452    return (value >> 8) | (value << 8);
2453    }
2454    
2455    
2456    
2457    /*************************************************
2458    *        Flip bytes in a compiled pattern        *
2459    *************************************************/
2460    
2461    /* This function is called if the 'F' option was present on a pattern that is
2462    to be written to a file. We flip the bytes of all the integer fields in the
2463    regex data block and the study block. In 16-bit mode this also flips relevant
2464    bytes in the pattern itself. This is to make it possible to test PCRE's
2465    ability to reload byte-flipped patterns, e.g. those compiled on a different
2466    architecture. */
2467    
2468    #if defined SUPPORT_PCRE8 || defined SUPPORT_PCRE16
2469    static void
2470    regexflip8_or_16(pcre *ere, pcre_extra *extra)
2471    {
2472    real_pcre8_or_16 *re = (real_pcre8_or_16 *)ere;
2473    #ifdef SUPPORT_PCRE16
2474    int op;
2475    pcre_uint16 *ptr = (pcre_uint16 *)re + re->name_table_offset;
2476    int length = re->name_count * re->name_entry_size;
2477    #ifdef SUPPORT_UTF
2478    BOOL utf = (re->options & PCRE_UTF16) != 0;
2479    BOOL utf16_char = FALSE;
2480    #endif /* SUPPORT_UTF */
2481    #endif /* SUPPORT_PCRE16 */
2482    
2483    /* Always flip the bytes in the main data block and study blocks. */
2484    
2485    re->magic_number = REVERSED_MAGIC_NUMBER;
2486    re->size = swap_uint32(re->size);
2487    re->options = swap_uint32(re->options);
2488    re->flags = swap_uint16(re->flags);
2489    re->top_bracket = swap_uint16(re->top_bracket);
2490    re->top_backref = swap_uint16(re->top_backref);
2491    re->first_char = swap_uint16(re->first_char);
2492    re->req_char = swap_uint16(re->req_char);
2493    re->name_table_offset = swap_uint16(re->name_table_offset);
2494    re->name_entry_size = swap_uint16(re->name_entry_size);
2495    re->name_count = swap_uint16(re->name_count);
2496    
2497    if (extra != NULL)
2498      {
2499      pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);
2500      rsd->size = swap_uint32(rsd->size);
2501      rsd->flags = swap_uint32(rsd->flags);
2502      rsd->minlength = swap_uint32(rsd->minlength);
2503      }
2504    
2505    /* In 8-bit mode, that is all we need to do. In 16-bit mode we must swap bytes
2506    in the name table, if present, and then in the pattern itself. */
2507    
2508    #ifdef SUPPORT_PCRE16
2509    if (pcre_mode != PCRE16_MODE) return;
2510    
2511    while(TRUE)
2512      {
2513      /* Swap previous characters. */
2514      while (length-- > 0)
2515        {
2516        *ptr = swap_uint16(*ptr);
2517        ptr++;
2518        }
2519    #ifdef SUPPORT_UTF
2520      if (utf16_char)
2521        {
2522        if ((ptr[-1] & 0xfc00) == 0xd800)
2523          {
2524          /* We know that there is only one extra character in UTF-16. */
2525          *ptr = swap_uint16(*ptr);
2526          ptr++;
2527          }
2528        }
2529      utf16_char = FALSE;
2530    #endif /* SUPPORT_UTF */
2531    
2532      /* Get next opcode. */
2533    
2534      length = 0;
2535      op = *ptr;
2536      *ptr++ = swap_uint16(op);
2537    
2538      switch (op)
2539        {
2540        case OP_END:
2541        return;
2542    
2543    #ifdef SUPPORT_UTF
2544        case OP_CHAR:
2545        case OP_CHARI:
2546        case OP_NOT:
2547        case OP_NOTI:
2548        case OP_STAR:
2549        case OP_MINSTAR:
2550        case OP_PLUS:
2551        case OP_MINPLUS:
2552        case OP_QUERY:
2553        case OP_MINQUERY:
2554        case OP_UPTO:
2555        case OP_MINUPTO:
2556        case OP_EXACT:
2557        case OP_POSSTAR:
2558        case OP_POSPLUS:
2559        case OP_POSQUERY:
2560        case OP_POSUPTO:
2561        case OP_STARI:
2562        case OP_MINSTARI:
2563        case OP_PLUSI:
2564        case OP_MINPLUSI:
2565        case OP_QUERYI:
2566        case OP_MINQUERYI:
2567        case OP_UPTOI:
2568        case OP_MINUPTOI:
2569        case OP_EXACTI:
2570        case OP_POSSTARI:
2571        case OP_POSPLUSI:
2572        case OP_POSQUERYI:
2573        case OP_POSUPTOI:
2574        case OP_NOTSTAR:
2575        case OP_NOTMINSTAR:
2576        case OP_NOTPLUS:
2577        case OP_NOTMINPLUS:
2578        case OP_NOTQUERY:
2579        case OP_NOTMINQUERY:
2580        case OP_NOTUPTO:
2581        case OP_NOTMINUPTO:
2582        case OP_NOTEXACT:
2583        case OP_NOTPOSSTAR:
2584        case OP_NOTPOSPLUS:
2585        case OP_NOTPOSQUERY:
2586        case OP_NOTPOSUPTO:
2587        case OP_NOTSTARI:
2588        case OP_NOTMINSTARI:
2589        case OP_NOTPLUSI:
2590        case OP_NOTMINPLUSI:
2591        case OP_NOTQUERYI:
2592        case OP_NOTMINQUERYI:
2593        case OP_NOTUPTOI:
2594        case OP_NOTMINUPTOI:
2595        case OP_NOTEXACTI:
2596        case OP_NOTPOSSTARI:
2597        case OP_NOTPOSPLUSI:
2598        case OP_NOTPOSQUERYI:
2599        case OP_NOTPOSUPTOI:
2600        if (utf) utf16_char = TRUE;
2601    #endif
2602        /* Fall through. */
2603    
2604        default:
2605        length = OP_lengths16[op] - 1;
2606        break;
2607    
2608        case OP_CLASS:
2609        case OP_NCLASS:
2610        /* Skip the character bit map. */
2611        ptr += 32/sizeof(pcre_uint16);
2612        length = 0;
2613        break;
2614    
2615        case OP_XCLASS:
2616        /* LINK_SIZE can be 1 or 2 in 16 bit mode. */
2617        if (LINK_SIZE > 1)
2618          length = (int)((((unsigned int)(ptr[0]) << 16) | (unsigned int)(ptr[1]))
2619            - (1 + LINK_SIZE + 1));
2620        else
2621          length = (int)((unsigned int)(ptr[0]) - (1 + LINK_SIZE + 1));
2622    
2623        /* Reverse the size of the XCLASS instance. */
2624        *ptr = swap_uint16(*ptr);
2625        ptr++;
2626        if (LINK_SIZE > 1)
2627          {
2628          *ptr = swap_uint16(*ptr);
2629          ptr++;
2630          }
2631    
2632        op = *ptr;
2633        *ptr = swap_uint16(op);
2634        ptr++;
2635        if ((op & XCL_MAP) != 0)
2636          {
2637          /* Skip the character bit map. */
2638          ptr += 32/sizeof(pcre_uint16);
2639          length -= 32/sizeof(pcre_uint16);
2640          }
2641        break;
2642        }
2643      }
2644    /* Control should never reach here in 16 bit mode. */
2645    #endif /* SUPPORT_PCRE16 */
2646    }
2647    #endif /* SUPPORT_PCRE[8|16] */
2648    
2649    
2650    
2651    #if defined SUPPORT_PCRE32
2652    static void
2653    regexflip_32(pcre *ere, pcre_extra *extra)
2654    {
2655    real_pcre32 *re = (real_pcre32 *)ere;
2656    int op;
2657    pcre_uint32 *ptr = (pcre_uint32 *)re + re->name_table_offset;
2658    int length = re->name_count * re->name_entry_size;
2659    
2660    /* Always flip the bytes in the main data block and study blocks. */
2661    
2662    re->magic_number = REVERSED_MAGIC_NUMBER;
2663    re->size = swap_uint32(re->size);
2664    re->options = swap_uint32(re->options);
2665    re->flags = swap_uint16(re->flags);
2666    re->top_bracket = swap_uint16(re->top_bracket);
2667    re->top_backref = swap_uint16(re->top_backref);
2668    re->first_char = swap_uint32(re->first_char);
2669    re->req_char = swap_uint32(re->req_char);
2670    re->name_table_offset = swap_uint16(re->name_table_offset);
2671    re->name_entry_size = swap_uint16(re->name_entry_size);
2672    re->name_count = swap_uint16(re->name_count);
2673    
2674    if (extra != NULL)
2675      {
2676      pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);
2677      rsd->size = swap_uint32(rsd->size);
2678      rsd->flags = swap_uint32(rsd->flags);
2679      rsd->minlength = swap_uint32(rsd->minlength);
2680      }
2681    
2682    /* In 32-bit mode we must swap bytes in the name table, if present, and then in
2683    the pattern itself. */
2684    
2685    while(TRUE)
2686      {
2687      /* Swap previous characters. */
2688      while (length-- > 0)
2689        {
2690        *ptr = swap_uint32(*ptr);
2691        ptr++;
2692        }
2693    
2694  /* Get one piece of information from the pcre_fullinfo() function */    /* Get next opcode. */
2695    
2696  static void new_info(pcre *re, pcre_extra *study, int option, void *ptr)    length = 0;
2697  {    op = *ptr;
2698  int rc;    *ptr++ = swap_uint32(op);
2699  if ((rc = pcre_fullinfo(re, study, option, ptr)) < 0)  
2700    fprintf(outfile, "Error %d from pcre_fullinfo(%d)\n", rc, option);    switch (op)
2701        {
2702        case OP_END:
2703        return;
2704    
2705        default:
2706        length = OP_lengths32[op] - 1;
2707        break;
2708    
2709        case OP_CLASS:
2710        case OP_NCLASS:
2711        /* Skip the character bit map. */
2712        ptr += 32/sizeof(pcre_uint32);
2713        length = 0;
2714        break;
2715    
2716        case OP_XCLASS:
2717        /* LINK_SIZE can only be 1 in 32-bit mode. */
2718        length = (int)((unsigned int)(ptr[0]) - (1 + LINK_SIZE + 1));
2719    
2720        /* Reverse the size of the XCLASS instance. */
2721        *ptr = swap_uint32(*ptr);
2722        ptr++;
2723    
2724        op = *ptr;
2725        *ptr = swap_uint32(op);
2726        ptr++;
2727        if ((op & XCL_MAP) != 0)
2728          {
2729          /* Skip the character bit map. */
2730          ptr += 32/sizeof(pcre_uint32);
2731          length -= 32/sizeof(pcre_uint32);
2732          }
2733        break;
2734        }
2735      }
2736    /* Control should never reach here in 32 bit mode. */
2737  }  }
2738    
2739    #endif /* SUPPORT_PCRE32 */
2740    
2741    
 /*************************************************  
 *         Byte flipping function                 *  
 *************************************************/  
2742    
2743  static unsigned long int  static void
2744  byteflip(unsigned long int value, int n)  regexflip(pcre *ere, pcre_extra *extra)
2745  {  {
2746  if (n == 2) return ((value & 0x00ff) << 8) | ((value & 0xff00) >> 8);  #if defined SUPPORT_PCRE32
2747  return ((value & 0x000000ff) << 24) |    if (REAL_PCRE_FLAGS(ere) & PCRE_MODE32)
2748         ((value & 0x0000ff00) <<  8) |      regexflip_32(ere, extra);
2749         ((value & 0x00ff0000) >>  8) |  #endif
2750         ((value & 0xff000000) >> 24);  #if defined SUPPORT_PCRE8 || defined SUPPORT_PCRE16
2751      if (REAL_PCRE_FLAGS(ere) & (PCRE_MODE8 | PCRE_MODE16))
2752        regexflip8_or_16(ere, extra);
2753    #endif
2754  }  }
2755    
2756    
2757    
   
2758  /*************************************************  /*************************************************
2759  *        Check match or recursion limit          *  *        Check match or recursion limit          *
2760  *************************************************/  *************************************************/
2761    
2762  static int  static int
2763  check_match_limit(pcre *re, pcre_extra *extra, uschar *bptr, int len,  check_match_limit(pcre *re, pcre_extra *extra, pcre_uint8 *bptr, int len,
2764    int start_offset, int options, int *use_offsets, int use_size_offsets,    int start_offset, int options, int *use_offsets, int use_size_offsets,
2765    int flag, unsigned long int *limit, int errnumber, const char *msg)    int flag, unsigned long int *limit, int errnumber, const char *msg)
2766  {  {
# Line 633  for (;;) Line 2775  for (;;)
2775    {    {
2776    *limit = mid;    *limit = mid;
2777    
2778    count = pcre_exec(re, extra, (char *)bptr, len, start_offset, options,    PCRE_EXEC(count, re, extra, bptr, len, start_offset, options,
2779      use_offsets, use_size_offsets);      use_offsets, use_size_offsets);
2780    
2781    if (count == errnumber)    if (count == errnumber)
# Line 678  Returns:    < 0, = 0, or > 0, according Line 2820  Returns:    < 0, = 0, or > 0, according
2820  */  */
2821    
2822  static int  static int
2823  strncmpic(uschar *s, uschar *t, int n)  strncmpic(pcre_uint8 *s, pcre_uint8 *t, int n)
2824  {  {
2825  while (n--)  while (n--)
2826    {    {
# Line 694  return 0; Line 2836  return 0;
2836  *         Check newline indicator                *  *         Check newline indicator                *
2837  *************************************************/  *************************************************/
2838    
2839  /* This is used both at compile and run-time to check for <xxx> escapes, where  /* This is used both at compile and run-time to check for <xxx> escapes. Print
2840  xxx is LF, CR, CRLF, ANYCRLF, or ANY. Print a message and return 0 if there is  a message and return 0 if there is no match.
 no match.  
2841    
2842  Arguments:  Arguments:
2843    p           points after the leading '<'    p           points after the leading '<'
# Line 706  Returns:      appropriate PCRE_NEWLINE_x Line 2847  Returns:      appropriate PCRE_NEWLINE_x
2847  */  */
2848    
2849  static int  static int
2850  check_newline(uschar *p, FILE *f)  check_newline(pcre_uint8 *p, FILE *f)
2851  {  {
2852  if (strncmpic(p, (uschar *)"cr>", 3) == 0) return PCRE_NEWLINE_CR;  if (strncmpic(p, (pcre_uint8 *)"cr>", 3) == 0) return PCRE_NEWLINE_CR;
2853  if (strncmpic(p, (uschar *)"lf>", 3) == 0) return PCRE_NEWLINE_LF;  if (strncmpic(p, (pcre_uint8 *)"lf>", 3) == 0) return PCRE_NEWLINE_LF;
2854  if (strncmpic(p, (uschar *)"crlf>", 5) == 0) return PCRE_NEWLINE_CRLF;  if (strncmpic(p, (pcre_uint8 *)"crlf>", 5) == 0) return PCRE_NEWLINE_CRLF;
2855  if (strncmpic(p, (uschar *)"anycrlf>", 8) == 0) return PCRE_NEWLINE_ANYCRLF;  if (strncmpic(p, (pcre_uint8 *)"anycrlf>", 8) == 0) return PCRE_NEWLINE_ANYCRLF;
2856  if (strncmpic(p, (uschar *)"any>", 4) == 0) return PCRE_NEWLINE_ANY;  if (strncmpic(p, (pcre_uint8 *)"any>", 4) == 0) return PCRE_NEWLINE_ANY;
2857  if (strncmpic(p, (uschar *)"bsr_anycrlf>", 12) == 0) return PCRE_BSR_ANYCRLF;  if (strncmpic(p, (pcre_uint8 *)"bsr_anycrlf>", 12) == 0) return PCRE_BSR_ANYCRLF;
2858  if (strncmpic(p, (uschar *)"bsr_unicode>", 12) == 0) return PCRE_BSR_UNICODE;  if (strncmpic(p, (pcre_uint8 *)"bsr_unicode>", 12) == 0) return PCRE_BSR_UNICODE;
2859  fprintf(f, "Unknown newline type at: <%s\n", p);  fprintf(f, "Unknown newline type at: <%s\n", p);
2860  return 0;  return 0;
2861  }  }
# Line 728  return 0; Line 2869  return 0;
2869  static void  static void
2870  usage(void)  usage(void)
2871  {  {
2872  printf("Usage:     pcretest [options] [<input> [<output>]]\n");  printf("Usage:     pcretest [options] [<input file> [<output file>]]\n\n");
2873  printf("  -b       show compiled code (bytecode)\n");  printf("Input and output default to stdin and stdout.\n");
2874    #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
2875    printf("If input is a terminal, readline() is used to read from it.\n");
2876    #else
2877    printf("This version of pcretest is not linked with readline().\n");
2878    #endif
2879    printf("\nOptions:\n");
2880    #ifdef SUPPORT_PCRE16
2881    printf("  -16      use the 16-bit library\n");
2882    #endif
2883    #ifdef SUPPORT_PCRE32
2884    printf("  -32      use the 32-bit library\n");
2885    #endif
2886    printf("  -b       show compiled code\n");
2887  printf("  -C       show PCRE compile-time options and exit\n");  printf("  -C       show PCRE compile-time options and exit\n");
2888    printf("  -C arg   show a specific compile-time option\n");
2889    printf("           and exit with its value. The arg can be:\n");
2890    printf("     linksize     internal link size [2, 3, 4]\n");
2891    printf("     pcre8        8 bit library support enabled [0, 1]\n");
2892    printf("     pcre16       16 bit library support enabled [0, 1]\n");
2893    printf("     pcre32       32 bit library support enabled [0, 1]\n");
2894    printf("     utf          Unicode Transformation Format supported [0, 1]\n");
2895    printf("     ucp          Unicode Properties supported [0, 1]\n");
2896    printf("     jit          Just-in-time compiler supported [0, 1]\n");
2897    printf("     newline      Newline type [CR, LF, CRLF, ANYCRLF, ANY, ???]\n");
2898  printf("  -d       debug: show compiled code and information (-b and -i)\n");  printf("  -d       debug: show compiled code and information (-b and -i)\n");
2899  #if !defined NODFA  #if !defined NODFA
2900  printf("  -dfa     force DFA matching for all subjects\n");  printf("  -dfa     force DFA matching for all subjects\n");
2901  #endif  #endif
2902  printf("  -help    show usage information\n");  printf("  -help    show usage information\n");
2903  printf("  -i       show information about compiled patterns\n"  printf("  -i       show information about compiled patterns\n"
2904           "  -M       find MATCH_LIMIT minimum for each subject\n"
2905         "  -m       output memory used information\n"         "  -m       output memory used information\n"
2906         "  -o <n>   set size of offsets vector to <n>\n");         "  -o <n>   set size of offsets vector to <n>\n");
2907  #if !defined NOPOSIX  #if !defined NOPOSIX
# Line 744  printf("  -p       use POSIX interface\n Line 2909  printf("  -p       use POSIX interface\n
2909  #endif  #endif
2910  printf("  -q       quiet: do not output PCRE version number at start\n");  printf("  -q       quiet: do not output PCRE version number at start\n");
2911  printf("  -S <n>   set stack size to <n> megabytes\n");  printf("  -S <n>   set stack size to <n> megabytes\n");
2912  printf("  -s       output store (memory) used information\n"  printf("  -s       force each pattern to be studied at basic level\n"
2913           "  -s+      force each pattern to be studied, using JIT if available\n"
2914           "  -s++     ditto, verifying when JIT was actually used\n"
2915           "  -s+n     force each pattern to be studied, using JIT if available,\n"
2916           "             where 1 <= n <= 7 selects JIT options\n"
2917           "  -s++n    ditto, verifying when JIT was actually used\n"
2918         "  -t       time compilation and execution\n");         "  -t       time compilation and execution\n");
2919  printf("  -t <n>   time compilation and execution, repeating <n> times\n");  printf("  -t <n>   time compilation and execution, repeating <n> times\n");
2920  printf("  -tm      time execution (matching) only\n");  printf("  -tm      time execution (matching) only\n");
# Line 764  options, followed by a set of test data, Line 2934  options, followed by a set of test data,
2934  int main(int argc, char **argv)  int main(int argc, char **argv)
2935  {  {
2936  FILE *infile = stdin;  FILE *infile = stdin;
2937    const char *version;
2938  int options = 0;  int options = 0;
2939  int study_options = 0;  int study_options = 0;
2940    int default_find_match_limit = FALSE;
2941  int op = 1;  int op = 1;
2942  int timeit = 0;  int timeit = 0;
2943  int timeitm = 0;  int timeitm = 0;
2944  int showinfo = 0;  int showinfo = 0;
2945  int showstore = 0;  int showstore = 0;
2946    int force_study = -1;
2947    int force_study_options = 0;
2948  int quiet = 0;  int quiet = 0;
2949  int size_offsets = 45;  int size_offsets = 45;
2950  int size_offsets_max;  int size_offsets_max;
2951  int *offsets = NULL;  int *offsets = NULL;
 #if !defined NOPOSIX  
 int posix = 0;  
 #endif  
2952  int debug = 0;  int debug = 0;
2953  int done = 0;  int done = 0;
2954  int all_use_dfa = 0;  int all_use_dfa = 0;
2955    int verify_jit = 0;
2956  int yield = 0;  int yield = 0;
2957    #ifdef SUPPORT_PCRE32
2958    int mask_utf32 = 0;
2959    #endif
2960  int stack_size;  int stack_size;
2961    pcre_uint8 *dbuffer = NULL;
2962    size_t dbuffer_size = 1u << 14;
2963    
2964    #if !defined NOPOSIX
2965    int posix = 0;
2966    #endif
2967    #if !defined NODFA
2968    int *dfa_workspace = NULL;
2969    #endif
2970    
2971    pcre_jit_stack *jit_stack = NULL;
2972    
2973  /* These vectors store, end-to-end, a list of captured substring names. Assume  /* These vectors store, end-to-end, a list of zero-terminated captured
2974  that 1024 is plenty long enough for the few names we'll be testing. */  substring names, each list itself being terminated by an empty name. Assume
2975    that 1024 is plenty long enough for the few names we'll be testing. It is
2976    easiest to keep separate 8-, 16- and 32-bit versions, using the 32-bit version
2977    for the actual memory, to ensure alignment. */
2978    
2979    pcre_uint32 copynames[1024];
2980    pcre_uint32 getnames[1024];
2981    
2982    #ifdef SUPPORT_PCRE32
2983    pcre_uint32 *cn32ptr;
2984    pcre_uint32 *gn32ptr;
2985    #endif
2986    
2987  uschar copynames[1024];  #ifdef SUPPORT_PCRE16
2988  uschar getnames[1024];  pcre_uint16 *copynames16 = (pcre_uint16 *)copynames;
2989    pcre_uint16 *getnames16 = (pcre_uint16 *)getnames;
2990    pcre_uint16 *cn16ptr;
2991    pcre_uint16 *gn16ptr;
2992    #endif
2993    
2994  uschar *copynamesptr;  #ifdef SUPPORT_PCRE8
2995  uschar *getnamesptr;  pcre_uint8 *copynames8 = (pcre_uint8 *)copynames;
2996    pcre_uint8 *getnames8 = (pcre_uint8 *)getnames;
2997    pcre_uint8 *cn8ptr;
2998    pcre_uint8 *gn8ptr;
2999    #endif
3000    
3001  /* Get buffers from malloc() so that Electric Fence will check their misuse  /* Get buffers from malloc() so that valgrind will check their misuse when
3002  when I am debugging. They grow automatically when very long lines are read. */  debugging. They grow automatically when very long lines are read. The 16-
3003    and 32-bit buffers (buffer16, buffer32) are obtained only if needed. */
3004    
3005  buffer = (unsigned char *)malloc(buffer_size);  buffer = (pcre_uint8 *)malloc(buffer_size);
3006  dbuffer = (unsigned char *)malloc(buffer_size);  pbuffer = (pcre_uint8 *)malloc(buffer_size);
 pbuffer = (unsigned char *)malloc(buffer_size);  
3007    
3008  /* The outfile variable is static so that new_malloc can use it. */  /* The outfile variable is static so that new_malloc can use it. */
3009    
# Line 813  it set 0x8000, but then I was advised th Line 3018  it set 0x8000, but then I was advised th
3018  _setmode( _fileno( stdout ), _O_BINARY );  _setmode( _fileno( stdout ), _O_BINARY );
3019  #endif  #endif
3020    
3021    /* Get the version number: both pcre_version() and pcre16_version() give the
3022    same answer. We just need to ensure that we call one that is available. */
3023    
3024    #if defined SUPPORT_PCRE8
3025    version = pcre_version();
3026    #elif defined SUPPORT_PCRE16
3027    version = pcre16_version();
3028    #elif defined SUPPORT_PCRE32
3029    version = pcre32_version();
3030    #endif
3031    
3032  /* Scan options */  /* Scan options */
3033    
3034  while (argc > 1 && argv[op][0] == '-')  while (argc > 1 && argv[op][0] == '-')
3035    {    {
3036    unsigned char *endptr;    pcre_uint8 *endptr;
3037      char *arg = argv[op];
3038    
3039    if (strcmp(argv[op], "-s") == 0 || strcmp(argv[op], "-m") == 0)    if (strcmp(arg, "-m") == 0) showstore = 1;
3040      showstore = 1;    else if (strcmp(arg, "-s") == 0) force_study = 0;
3041    else if (strcmp(argv[op], "-q") == 0) quiet = 1;  
3042    else if (strcmp(argv[op], "-b") == 0) debug = 1;    else if (strncmp(arg, "-s+", 3) == 0)
3043    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;      {
3044    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;      arg += 3;
3045        if (*arg == '+') { arg++; verify_jit = TRUE; }
3046        force_study = 1;
3047        if (*arg == 0)
3048          force_study_options = jit_study_bits[6];
3049        else if (*arg >= '1' && *arg <= '7')
3050          force_study_options = jit_study_bits[*arg - '1'];
3051        else goto BAD_ARG;
3052        }
3053      else if (strcmp(arg, "-8") == 0)
3054        {
3055    #ifdef SUPPORT_PCRE8
3056        pcre_mode = PCRE8_MODE;
3057    #else
3058        printf("** This version of PCRE was built without 8-bit support\n");
3059        exit(1);
3060    #endif
3061        }
3062      else if (strcmp(arg, "-16") == 0)
3063        {
3064    #ifdef SUPPORT_PCRE16
3065        pcre_mode = PCRE16_MODE;
3066    #else
3067        printf("** This version of PCRE was built without 16-bit support\n");
3068        exit(1);
3069    #endif
3070        }
3071      else if (strcmp(arg, "-32") == 0 || strcmp(arg, "-32+") == 0)
3072        {
3073    #ifdef SUPPORT_PCRE32
3074        pcre_mode = PCRE32_MODE;
3075        mask_utf32 = (strcmp(arg, "-32+") == 0);
3076    #else
3077        printf("** This version of PCRE was built without 32-bit support\n");
3078        exit(1);
3079    #endif
3080        }
3081      else if (strcmp(arg, "-q") == 0) quiet = 1;
3082      else if (strcmp(arg, "-b") == 0) debug = 1;
3083      else if (strcmp(arg, "-i") == 0) showinfo = 1;
3084      else if (strcmp(arg, "-d") == 0) showinfo = debug = 1;
3085      else if (strcmp(arg, "-M") == 0) default_find_match_limit = TRUE;
3086  #if !defined NODFA  #if !defined NODFA
3087    else if (strcmp(argv[op], "-dfa") == 0) all_use_dfa = 1;    else if (strcmp(arg, "-dfa") == 0) all_use_dfa = 1;
3088  #endif  #endif
3089    else if (strcmp(argv[op], "-o") == 0 && argc > 2 &&    else if (strcmp(arg, "-o") == 0 && argc > 2 &&
3090        ((size_offsets = get_value((unsigned char *)argv[op+1], &endptr)),        ((size_offsets = get_value((pcre_uint8 *)argv[op+1], &endptr)),
3091          *endptr == 0))          *endptr == 0))
3092      {      {
3093      op++;      op++;
3094      argc--;      argc--;
3095      }      }
3096    else if (strcmp(argv[op], "-t") == 0 || strcmp(argv[op], "-tm") == 0)    else if (strcmp(arg, "-t") == 0 || strcmp(arg, "-tm") == 0)
3097      {      {
3098      int both = argv[op][2] == 0;      int both = arg[2] == 0;
3099      int temp;      int temp;
3100      if (argc > 2 && (temp = get_value((unsigned char *)argv[op+1], &endptr),      if (argc > 2 && (temp = get_value((pcre_uint8 *)argv[op+1], &endptr),
3101                       *endptr == 0))                       *endptr == 0))
3102        {        {
3103        timeitm = temp;        timeitm = temp;
# Line 849  while (argc > 1 && argv[op][0] == '-') Line 3107  while (argc > 1 && argv[op][0] == '-')
3107      else timeitm = LOOPREPEAT;      else timeitm = LOOPREPEAT;
3108      if (both) timeit = timeitm;      if (both) timeit = timeitm;
3109      }      }
3110    else if (strcmp(argv[op], "-S") == 0 && argc > 2 &&    else if (strcmp(arg, "-S") == 0 && argc > 2 &&
3111        ((stack_size = get_value((unsigned char *)argv[op+1], &endptr)),        ((stack_size = get_value((pcre_uint8 *)argv[op+1], &endptr)),
3112          *endptr == 0))          *endptr == 0))
3113      {      {
3114  #if defined(_WIN32) || defined(WIN32)  #if defined(_WIN32) || defined(WIN32) || defined(__minix) || defined(NATIVE_ZOS)
3115      printf("PCRE: -S not supported on this OS\n");      printf("PCRE: -S not supported on this OS\n");
3116      exit(1);      exit(1);
3117  #else  #else
# Line 872  while (argc > 1 && argv[op][0] == '-') Line 3130  while (argc > 1 && argv[op][0] == '-')
3130  #endif  #endif
3131      }      }
3132  #if !defined NOPOSIX  #if !defined NOPOSIX
3133    else if (strcmp(argv[op], "-p") == 0) posix = 1;    else if (strcmp(arg, "-p") == 0) posix = 1;
3134  #endif  #endif
3135    else if (strcmp(argv[op], "-C") == 0)    else if (strcmp(arg, "-C") == 0)
3136      {      {
3137      int rc;      int rc;
3138      printf("PCRE version %s\n", pcre_version());      unsigned long int lrc;
3139    
3140        if (argc > 2)
3141          {
3142          if (strcmp(argv[op + 1], "linksize") == 0)
3143            {
3144            (void)PCRE_CONFIG(PCRE_CONFIG_LINK_SIZE, &rc);
3145            printf("%d\n", rc);
3146            yield = rc;
3147            }
3148          else if (strcmp(argv[op + 1], "pcre8") == 0)
3149            {
3150    #ifdef SUPPORT_PCRE8
3151            printf("1\n");
3152            yield = 1;
3153    #else
3154            printf("0\n");
3155            yield = 0;
3156    #endif
3157            }
3158          else if (strcmp(argv[op + 1], "pcre16") == 0)
3159            {
3160    #ifdef SUPPORT_PCRE16
3161            printf("1\n");
3162            yield = 1;
3163    #else
3164            printf("0\n");
3165            yield = 0;
3166    #endif
3167            }
3168          else if (strcmp(argv[op + 1], "pcre32") == 0)
3169            {
3170    #ifdef SUPPORT_PCRE32
3171            printf("1\n");
3172            yield = 1;
3173    #else
3174            printf("0\n");
3175            yield = 0;
3176    #endif
3177            goto EXIT;
3178            }
3179          if (strcmp(argv[op + 1], "utf") == 0)
3180            {
3181    #ifdef SUPPORT_PCRE8
3182            if (pcre_mode == PCRE8_MODE)
3183              (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
3184    #endif
3185    #ifdef SUPPORT_PCRE16
3186            if (pcre_mode == PCRE16_MODE)
3187              (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
3188    #endif
3189    #ifdef SUPPORT_PCRE32
3190            if (pcre_mode == PCRE32_MODE)
3191              (void)pcre32_config(PCRE_CONFIG_UTF32, &rc);
3192    #endif
3193            printf("%d\n", rc);
3194            yield = rc;
3195            goto EXIT;
3196            }
3197          else if (strcmp(argv[op + 1], "ucp") == 0)
3198            {
3199            (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
3200            printf("%d\n", rc);
3201            yield = rc;
3202            }
3203          else if (strcmp(argv[op + 1], "jit") == 0)
3204            {
3205            (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);
3206            printf("%d\n", rc);
3207            yield = rc;
3208            }
3209          else if (strcmp(argv[op + 1], "newline") == 0)
3210            {
3211            (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3212            print_newline_config(rc, TRUE);
3213            }
3214          else if (strcmp(argv[op + 1], "ebcdic") == 0)
3215            {
3216    #ifdef EBCDIC
3217            printf("1\n");
3218            yield = 1;
3219    #else
3220            printf("0\n");
3221    #endif
3222            }
3223          else if (strcmp(argv[op + 1], "ebcdic-nl") == 0)
3224            {
3225    #ifdef EBCDIC
3226            printf("0x%02x\n", CHAR_LF);
3227    #else
3228            printf("0\n");
3229    #endif
3230            }
3231          else
3232            {
3233            printf("Unknown -C option: %s\n", argv[op + 1]);
3234            }
3235          goto EXIT;
3236          }
3237    
3238        /* No argument for -C: output all configuration information. */
3239    
3240        printf("PCRE version %s\n", version);
3241      printf("Compiled with\n");      printf("Compiled with\n");
3242    
3243    #ifdef EBCDIC
3244        printf("  EBCDIC code support: LF is 0x%02x\n", CHAR_LF);
3245    #endif
3246    
3247    /* At least one of SUPPORT_PCRE8 and SUPPORT_PCRE16 will be set. If both
3248    are set, either both UTFs are supported or both are not supported. */
3249    
3250    #ifdef SUPPORT_PCRE8
3251        printf("  8-bit support\n");
3252      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
3253      printf("  %sUTF-8 support\n", rc? "" : "No ");        printf ("  %sUTF-8 support\n", rc ? "" : "No ");
3254      (void)pcre_config(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);  #endif
3255    #ifdef SUPPORT_PCRE16
3256        printf("  16-bit support\n");
3257        (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
3258        printf ("  %sUTF-16 support\n", rc ? "" : "No ");
3259    #endif
3260    #ifdef SUPPORT_PCRE32
3261        printf("  32-bit support\n");
3262        (void)pcre32_config(PCRE_CONFIG_UTF32, &rc);
3263        printf ("  %sUTF-32 support\n", rc ? "" : "No ");
3264    #endif
3265    
3266        (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
3267      printf("  %sUnicode properties support\n", rc? "" : "No ");      printf("  %sUnicode properties support\n", rc? "" : "No ");
3268      (void)pcre_config(PCRE_CONFIG_NEWLINE, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);
3269      printf("  Newline sequence is %s\n", (rc == '\r')? "CR" :      if (rc)
3270        (rc == '\n')? "LF" : (rc == ('\r'<<8 | '\n'))? "CRLF" :        {
3271        (rc == -2)? "ANYCRLF" :        const char *arch;
3272        (rc == -1)? "ANY" : "???");        (void)PCRE_CONFIG(PCRE_CONFIG_JITTARGET, (void *)(&arch));
3273      (void)pcre_config(PCRE_CONFIG_BSR, &rc);        printf("  Just-in-time compiler support: %s\n", arch);
3274          }
3275        else
3276          printf("  No just-in-time compiler support\n");
3277        (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
3278        print_newline_config(rc, FALSE);
3279        (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);
3280      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :      printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :
3281                                       "all Unicode newlines");                                       "all Unicode newlines");
3282      (void)pcre_config(PCRE_CONFIG_LINK_SIZE, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_LINK_SIZE, &rc);
3283      printf("  Internal link size = %d\n", rc);      printf("  Internal link size = %d\n", rc);
3284      (void)pcre_config(PCRE_CONFIG_POSIX_MALLOC_THRESHOLD, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_POSIX_MALLOC_THRESHOLD, &rc);
3285      printf("  POSIX malloc threshold = %d\n", rc);      printf("  POSIX malloc threshold = %d\n", rc);
3286      (void)pcre_config(PCRE_CONFIG_MATCH_LIMIT, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_MATCH_LIMIT, &lrc);
3287      printf("  Default match limit = %d\n", rc);      printf("  Default match limit = %ld\n", lrc);
3288      (void)pcre_config(PCRE_CONFIG_MATCH_LIMIT_RECURSION, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_MATCH_LIMIT_RECURSION, &lrc);
3289      printf("  Default recursion depth limit = %d\n", rc);      printf("  Default recursion depth limit = %ld\n", lrc);
3290      (void)pcre_config(PCRE_CONFIG_STACKRECURSE, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_STACKRECURSE, &rc);
3291      printf("  Match recursion uses %s\n", rc? "stack" : "heap");      printf("  Match recursion uses %s", rc? "stack" : "heap");
3292        if (showstore)
3293          {
3294          PCRE_EXEC(stack_size, NULL, NULL, NULL, -999, -999, 0, NULL, 0);
3295          printf(": %sframe size = %d bytes", rc? "approximate " : "", -stack_size);
3296          }
3297        printf("\n");
3298      goto EXIT;      goto EXIT;
3299      }      }
3300    else if (strcmp(argv[op], "-help") == 0 ||    else if (strcmp(arg, "-help") == 0 ||
3301             strcmp(argv[op], "--help") == 0)             strcmp(arg, "--help") == 0)
3302      {      {
3303      usage();      usage();
3304      goto EXIT;      goto EXIT;
3305      }      }
3306    else    else
3307      {      {
3308      printf("** Unknown or malformed option %s\n", argv[op]);      BAD_ARG:
3309        printf("** Unknown or malformed option %s\n", arg);
3310      usage();      usage();
3311      yield = 1;      yield = 1;
3312      goto EXIT;      goto EXIT;
# Line 958  if (argc > 2) Line 3353  if (argc > 2)
3353    
3354  /* Set alternative malloc function */  /* Set alternative malloc function */
3355    
3356    #ifdef SUPPORT_PCRE8
3357  pcre_malloc = new_malloc;  pcre_malloc = new_malloc;
3358  pcre_free = new_free;  pcre_free = new_free;
3359  pcre_stack_malloc = stack_malloc;  pcre_stack_malloc = stack_malloc;
3360  pcre_stack_free = stack_free;  pcre_stack_free = stack_free;
3361    #endif
3362    
3363    #ifdef SUPPORT_PCRE16
3364    pcre16_malloc = new_malloc;
3365    pcre16_free = new_free;
3366    pcre16_stack_malloc = stack_malloc;
3367    pcre16_stack_free = stack_free;
3368    #endif
3369    
3370    #ifdef SUPPORT_PCRE32
3371    pcre32_malloc = new_malloc;
3372    pcre32_free = new_free;
3373    pcre32_stack_malloc = stack_malloc;
3374    pcre32_stack_free = stack_free;
3375    #endif
3376    
3377  /* Heading line unless quiet, then prompt for first regex if stdin */  /* Heading line unless quiet, then prompt for first regex if stdin */
3378    
3379  if (!quiet) fprintf(outfile, "PCRE version %s\n\n", pcre_version());  if (!quiet) fprintf(outfile, "PCRE version %s\n\n", version);
3380    
3381  /* Main loop */  /* Main loop */
3382    
# Line 980  while (!done) Line 3391  while (!done)
3391  #endif  #endif
3392    
3393    const char *error;    const char *error;
3394    unsigned char *p, *pp, *ppp;    pcre_uint8 *markptr;
3395    unsigned char *to_file = NULL;    pcre_uint8 *p, *pp, *ppp;
3396    const unsigned char *tables = NULL;    pcre_uint8 *to_file = NULL;
3397      const pcre_uint8 *tables = NULL;
3398      unsigned long int get_options;
3399    unsigned long int true_size, true_study_size = 0;    unsigned long int true_size, true_study_size = 0;
3400    size_t size, regex_gotten_store;    size_t size, regex_gotten_store;
3401      int do_allcaps = 0;
3402      int do_mark = 0;
3403    int do_study = 0;    int do_study = 0;
3404      int no_force_study = 0;
3405    int do_debug = debug;    int do_debug = debug;
3406    int do_G = 0;    int do_G = 0;
3407    int do_g = 0;    int do_g = 0;
3408    int do_showinfo = showinfo;    int do_showinfo = showinfo;
3409    int do_showrest = 0;    int do_showrest = 0;
3410      int do_showcaprest = 0;
3411    int do_flip = 0;    int do_flip = 0;
3412    int erroroffset, len, delimiter, poffset;    int erroroffset, len, delimiter, poffset;
3413    
3414    use_utf8 = 0;  #if !defined NODFA
3415      int dfa_matched = 0;
3416    #endif
3417    
3418      use_utf = 0;
3419    debug_lengths = 1;    debug_lengths = 1;
3420    
3421    if (infile == stdin) printf("  re> ");    if (extend_inputline(infile, buffer, "  re> ") == NULL) break;
   if (extend_inputline(infile, buffer) == NULL) break;  
3422    if (infile != stdin) fprintf(outfile, "%s", (char *)buffer);    if (infile != stdin) fprintf(outfile, "%s", (char *)buffer);
3423    fflush(outfile);    fflush(outfile);
3424    
# Line 1010  while (!done) Line 3430  while (!done)
3430    
3431    if (*p == '<' && strchr((char *)(p+1), '<') == NULL)    if (*p == '<' && strchr((char *)(p+1), '<') == NULL)
3432      {      {
3433      unsigned long int magic, get_options;      pcre_uint32 magic;
3434      uschar sbuf[8];      pcre_uint8 sbuf[8];
3435      FILE *f;      FILE *f;
3436    
3437      p++;      p++;
3438        if (*p == '!')
3439          {
3440          do_debug = TRUE;
3441          do_showinfo = TRUE;
3442          p++;
3443          }
3444    
3445      pp = p + (int)strlen((char *)p);      pp = p + (int)strlen((char *)p);
3446      while (isspace(pp[-1])) pp--;      while (isspace(pp[-1])) pp--;
3447      *pp = 0;      *pp = 0;
# Line 1026  while (!done) Line 3453  while (!done)
3453        continue;        continue;
3454        }        }
3455    
3456        first_gotten_store = 0;
3457      if (fread(sbuf, 1, 8, f) != 8) goto FAIL_READ;      if (fread(sbuf, 1, 8, f) != 8) goto FAIL_READ;
3458    
3459      true_size =      true_size =
# Line 1033  while (!done) Line 3461  while (!done)
3461      true_study_size =      true_study_size =
3462        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];
3463    
3464      re = (real_pcre *)new_malloc(true_size);      re = (pcre *)new_malloc(true_size);
3465      regex_gotten_store = gotten_store;      if (re == NULL)
3466          {
3467          printf("** Failed to get %d bytes of memory for pcre object\n",
3468            (int)true_size);
3469          yield = 1;
3470          goto EXIT;
3471          }
3472        regex_gotten_store = first_gotten_store;
3473    
3474      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;
3475    
3476      magic = ((real_pcre *)re)->magic_number;      magic = REAL_PCRE_MAGIC(re);
3477      if (magic != MAGIC_NUMBER)      if (magic != MAGIC_NUMBER)
3478        {        {
3479        if (byteflip(magic, sizeof(magic)) == MAGIC_NUMBER)        if (swap_uint32(magic) == MAGIC_NUMBER)
3480          {          {
3481          do_flip = 1;          do_flip = 1;
3482          }          }
3483        else        else
3484          {          {
3485          fprintf(outfile, "Data in %s is not a compiled PCRE regex\n", p);          fprintf(outfile, "Data in %s is not a compiled PCRE regex\n", p);
3486            new_free(re);
3487          fclose(f);          fclose(f);
3488          continue;          continue;
3489          }          }
3490        }        }
3491    
3492      fprintf(outfile, "Compiled regex%s loaded from %s\n",      /* We hide the byte-invert info for little and big endian tests. */
3493        do_flip? " (byte-inverted)" : "", p);      fprintf(outfile, "Compiled pattern%s loaded from %s\n",
3494          do_flip && (p[-1] == '<') ? " (byte-inverted)" : "", p);
     /* Need to know if UTF-8 for printing data strings */  
3495    
3496      new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);      /* Now see if there is any following study data. */
     use_utf8 = (get_options & PCRE_UTF8) != 0;  
   
     /* Now see if there is any following study data */  
3497    
3498      if (true_study_size != 0)      if (true_study_size != 0)
3499        {        {
# Line 1077  while (!done) Line 3509  while (!done)
3509          {          {
3510          FAIL_READ:          FAIL_READ:
3511          fprintf(outfile, "Failed to read data from %s\n", p);          fprintf(outfile, "Failed to read data from %s\n", p);
3512          if (extra != NULL) new_free(extra);          if (extra != NULL)
3513          if (re != NULL) new_free(re);            {
3514              PCRE_FREE_STUDY(extra);
3515              }
3516            new_free(re);
3517          fclose(f);          fclose(f);
3518          continue;          continue;
3519          }          }
# Line 1087  while (!done) Line 3522  while (!done)
3522        }        }
3523      else fprintf(outfile, "No study data\n");      else fprintf(outfile, "No study data\n");
3524    
3525        /* Flip the necessary bytes. */
3526        if (do_flip)
3527          {
3528          int rc;
3529          PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, NULL);
3530          if (rc == PCRE_ERROR_BADMODE)
3531            {
3532            /* Simulate the result of the function call below. */
3533            fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
3534              pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "",
3535              PCRE_INFO_OPTIONS);
3536            fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
3537              "%d-bit mode\n", 8 * CHAR_SIZE,
3538              8 * (REAL_PCRE_FLAGS(re) & PCRE_MODE_MASK));
3539            new_free(re);
3540            fclose(f);
3541            continue;
3542            }
3543          }
3544    
3545        /* Need to know if UTF-8 for printing data strings. */
3546    
3547        if (new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options) < 0)
3548          {
3549          new_free(re);
3550          fclose(f);
3551          continue;
3552          }
3553        use_utf = (get_options & PCRE_UTF8) != 0;
3554    
3555      fclose(f);      fclose(f);
3556      goto SHOW_INFO;      goto SHOW_INFO;
3557      }      }
3558    
3559    /* In-line pattern (the usual case). Get the delimiter and seek the end of    /* In-line pattern (the usual case). Get the delimiter and seek the end of
3560    the pattern; if is isn't complete, read more. */    the pattern; if it isn't complete, read more. */
3561    
3562    delimiter = *p++;    delimiter = *p++;
3563    
3564    if (isalnum(delimiter) || delimiter == '\\')    if (isalnum(delimiter) || delimiter == '\\')
3565      {      {
3566      fprintf(outfile, "** Delimiter must not be alphameric or \\\n");      fprintf(outfile, "** Delimiter must not be alphanumeric or \\\n");
3567      goto SKIP_DATA;      goto SKIP_DATA;
3568      }      }
3569    
3570    pp = p;    pp = p;
3571    poffset = p - buffer;    poffset = (int)(p - buffer);
3572    
3573    for(;;)    for(;;)
3574      {      {
# Line 1114  while (!done) Line 3579  while (!done)
3579        pp++;        pp++;
3580        }        }
3581      if (*pp != 0) break;      if (*pp != 0) break;
3582      if (infile == stdin) printf("    > ");      if ((pp = extend_inputline(infile, pp, "    > ")) == NULL)
     if ((pp = extend_inputline(infile, pp)) == NULL)  
3583        {        {
3584        fprintf(outfile, "** Unexpected EOF\n");        fprintf(outfile, "** Unexpected EOF\n");
3585        done = 1;        done = 1;
# Line 1144  while (!done) Line 3608  while (!done)
3608    /* Look for options after final delimiter */    /* Look for options after final delimiter */
3609    
3610    options = 0;    options = 0;
3611    study_options = 0;    study_options = force_study_options;
3612    log_store = showstore;  /* default from command line */    log_store = showstore;  /* default from command line */
3613    
3614    while (*pp != 0)    while (*pp != 0)
# Line 1158  while (!done) Line 3622  while (!done)
3622        case 's': options |= PCRE_DOTALL; break;        case 's': options |= PCRE_DOTALL; break;
3623        case 'x': options |= PCRE_EXTENDED; break;        case 'x': options |= PCRE_EXTENDED; break;
3624    
3625        case '+': do_showrest = 1; break;        case '+':
3626          if (do_showrest) do_showcaprest = 1; else do_showrest = 1;
3627          break;
3628    
3629          case '=': do_allcaps = 1; break;
3630        case 'A': options |= PCRE_ANCHORED; break;        case 'A': options |= PCRE_ANCHORED; break;
3631        case 'B': do_debug = 1; break;        case 'B': do_debug = 1; break;
3632        case 'C': options |= PCRE_AUTO_CALLOUT; break;        case 'C': options |= PCRE_AUTO_CALLOUT; break;
# Line 1168  while (!done) Line 3636  while (!done)
3636        case 'G': do_G = 1; break;        case 'G': do_G = 1; break;
3637        case 'I': do_showinfo = 1; break;        case 'I': do_showinfo = 1; break;
3638        case 'J': options |= PCRE_DUPNAMES; break;        case 'J': options |= PCRE_DUPNAMES; break;
3639          case 'K': do_mark = 1; break;
3640        case 'M': log_store = 1; break;        case 'M': log_store = 1; break;
3641        case 'N': options |= PCRE_NO_AUTO_CAPTURE; break;        case 'N': options |= PCRE_NO_AUTO_CAPTURE; break;
3642    
# Line 1175  while (!done) Line 3644  while (!done)
3644        case 'P': do_posix = 1; break;        case 'P': do_posix = 1; break;
3645  #endif  #endif
3646    
3647        case 'S': do_study = 1; break;        case 'S':
3648          do_study = 1;
3649          for (;;)
3650            {
3651            switch (*pp++)
3652              {
3653              case 'S':
3654              do_study = 0;
3655              no_force_study = 1;
3656              break;
3657    
3658              case '!':
3659              study_options |= PCRE_STUDY_EXTRA_NEEDED;
3660              break;
3661    
3662              case '+':
3663              if (*pp == '+')
3664                {
3665                verify_jit = TRUE;
3666                pp++;
3667                }
3668              if (*pp >= '1' && *pp <= '7')
3669                study_options |= jit_study_bits[*pp++ - '1'];
3670              else
3671                study_options |= jit_study_bits[6];
3672              break;
3673    
3674              case '-':
3675              study_options &= ~PCRE_STUDY_ALLJIT;
3676              break;
3677    
3678              default:
3679              pp--;
3680              goto ENDLOOP;
3681              }
3682            }
3683          ENDLOOP:
3684          break;
3685    
3686        case 'U': options |= PCRE_UNGREEDY; break;        case 'U': options |= PCRE_UNGREEDY; break;
3687          case 'W': options |= PCRE_UCP; break;
3688        case 'X': options |= PCRE_EXTRA; break;        case 'X': options |= PCRE_EXTRA; break;
3689          case 'Y': options |= PCRE_NO_START_OPTIMISE; break;
3690        case 'Z': debug_lengths = 0; break;        case 'Z': debug_lengths = 0; break;
3691        case '8': options |= PCRE_UTF8; use_utf8 = 1; break;        case '8': options |= PCRE_UTF8; use_utf = 1; break;
3692        case '?': options |= PCRE_NO_UTF8_CHECK; break;        case '?': options |= PCRE_NO_UTF8_CHECK; break;
3693    
3694          case 'T':
3695          switch (*pp++)
3696            {
3697            case '0': tables = tables0; break;
3698            case '1': tables = tables1; break;
3699    
3700            case '\r':
3701            case '\n':
3702            case ' ':
3703            case 0:
3704            fprintf(outfile, "** Missing table number after /T\n");
3705            goto SKIP_DATA;
3706    
3707            default:
3708            fprintf(outfile, "** Bad table number \"%c\" after /T\n", pp[-1]);
3709            goto SKIP_DATA;
3710            }
3711          break;
3712    
3713        case 'L':        case 'L':
3714        ppp = pp;        ppp = pp;
3715        /* The '\r' test here is so that it works on Windows. */        /* The '\r' test here is so that it works on Windows. */
# Line 1194  while (!done) Line 3722  while (!done)
3722          goto SKIP_DATA;          goto SKIP_DATA;
3723          }          }
3724        locale_set = 1;        locale_set = 1;
3725        tables = pcre_maketables();        tables = PCRE_MAKETABLES;
3726        pp = ppp;        pp = ppp;
3727        break;        break;
3728    
# Line 1207  while (!done) Line 3735  while (!done)
3735    
3736        case '<':        case '<':
3737          {          {
3738          int x = check_newline(pp, outfile);          if (strncmpic(pp, (pcre_uint8 *)"JS>", 3) == 0)
3739          if (x == 0) goto SKIP_DATA;            {
3740          options |= x;            options |= PCRE_JAVASCRIPT_COMPAT;
3741          while (*pp++ != '>');            pp += 3;
3742              }
3743            else
3744              {
3745              int x = check_newline(pp, outfile);
3746              if (x == 0) goto SKIP_DATA;
3747              options |= x;
3748              while (*pp++ != '>');
3749              }
3750          }          }
3751        break;        break;
3752    
# Line 1227  while (!done) Line 3763  while (!done)
3763    
3764    /* Handle compiling via the POSIX interface, which doesn't support the    /* Handle compiling via the POSIX interface, which doesn't support the<