/[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 376 by ph10, Sun Mar 1 12:00:59 2009 UTC revision 654 by ph10, Tue Aug 2 11:00:40 2011 UTC
# Line 71  input mode under Windows. */ Line 71  input mode under Windows. */
71  #define INPUT_MODE   "r"  #define INPUT_MODE   "r"
72  #define OUTPUT_MODE  "wb"  #define OUTPUT_MODE  "wb"
73    
74  #define isatty _isatty         /* This is what Windows calls them, I'm told */  #ifndef isatty
75    #define isatty _isatty         /* This is what Windows calls them, I'm told, */
76    #endif                         /* though in some environments they seem to   */
77                                   /* be already defined, hence the #ifndefs.    */
78    #ifndef fileno
79  #define fileno _fileno  #define fileno _fileno
80    #endif
81    
82    /* A user sent this fix for Borland Builder 5 under Windows. */
83    
84    #ifdef __BORLANDC__
85    #define _setmode(handle, mode) setmode(handle, mode)
86    #endif
87    
88    /* Not Windows */
89    
90  #else  #else
91  #include <sys/time.h>          /* These two includes are needed */  #include <sys/time.h>          /* These two includes are needed */
# Line 113  external symbols to prevent clashes. */ Line 126  external symbols to prevent clashes. */
126    
127  /* We also need the pcre_printint() function for printing out compiled  /* We also need the pcre_printint() function for printing out compiled
128  patterns. This function is in a separate file so that it can be included in  patterns. This function is in a separate file so that it can be included in
129  pcre_compile.c when that module is compiled with debugging enabled.  pcre_compile.c when that module is compiled with debugging enabled. It needs to
130    know which case is being compiled. */
 The definition of the macro PRINTABLE, which determines whether to print an  
 output character as-is or as a hex value when showing compiled patterns, is  
 contained in this file. We uses it here also, in cases when the locale has not  
 been explicitly changed, so as to get consistent output from systems that  
 differ in their output from isprint() even in the "C" locale. */  
131    
132    #define COMPILING_PCRETEST
133  #include "pcre_printint.src"  #include "pcre_printint.src"
134    
135  #define PRINTHEX(c) (locale_set? isprint(c) : PRINTABLE(c))  /* The definition of the macro PRINTABLE, which determines whether to print an
136    output character as-is or as a hex value when showing compiled patterns, is
137    contained in the printint.src file. We uses it here also, in cases when the
138    locale has not been explicitly changed, so as to get consistent output from
139    systems that differ in their output from isprint() even in the "C" locale. */
140    
141    #define PRINTHEX(c) (locale_set? isprint(c) : PRINTABLE(c))
142    
143  /* It is possible to compile this test program without including support for  /* It is possible to compile this test program without including support for
144  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 175  static int locale_set = 0; Line 189  static int locale_set = 0;
189  static int show_malloc;  static int show_malloc;
190  static int use_utf8;  static int use_utf8;
191  static size_t gotten_store;  static size_t gotten_store;
192    static const unsigned char *last_callout_mark = NULL;
193    
194  /* The buffers grow automatically if very long input lines are encountered. */  /* The buffers grow automatically if very long input lines are encountered. */
195    
# Line 183  static uschar *buffer = NULL; Line 198  static uschar *buffer = NULL;
198  static uschar *dbuffer = NULL;  static uschar *dbuffer = NULL;
199  static uschar *pbuffer = NULL;  static uschar *pbuffer = NULL;
200    
201    /* Textual explanations for runtime error codes */
202    
203    static const char *errtexts[] = {
204      NULL,  /* 0 is no error */
205      NULL,  /* NOMATCH is handled specially */
206      "NULL argument passed",
207      "bad option value",
208      "magic number missing",
209      "unknown opcode - pattern overwritten?",
210      "no more memory",
211      NULL,  /* never returned by pcre_exec() or pcre_dfa_exec() */
212      "match limit exceeded",
213      "callout error code",
214      NULL,  /* BADUTF8 is handled specially */
215      "bad UTF-8 offset",
216      NULL,  /* PARTIAL is handled specially */
217      "not used - internal error",
218      "internal error - pattern overwritten?",
219      "bad count value",
220      "item unsupported for DFA matching",
221      "backreference condition or recursion test not supported for DFA matching",
222      "match limit not supported for DFA matching",
223      "workspace size exceeded in DFA matching",
224      "too much recursion for DFA matching",
225      "recursion limit exceeded",
226      "not used - internal error",
227      "invalid combination of newline options",
228      "bad offset value",
229      NULL,  /* SHORTUTF8 is handled specially */
230      "nested recursion at the same subject position"
231    };
232    
233    
234    /*************************************************
235    *         Alternate character tables             *
236    *************************************************/
237    
238    /* By default, the "tables" pointer when calling PCRE is set to NULL, thereby
239    using the default tables of the library. However, the T option can be used to
240    select alternate sets of tables, for different kinds of testing. Note also that
241    the L (locale) option also adjusts the tables. */
242    
243    /* This is the set of tables distributed as default with PCRE. It recognizes
244    only ASCII characters. */
245    
246    static const unsigned char tables0[] = {
247    
248    /* This table is a lower casing table. */
249    
250        0,  1,  2,  3,  4,  5,  6,  7,
251        8,  9, 10, 11, 12, 13, 14, 15,
252       16, 17, 18, 19, 20, 21, 22, 23,
253       24, 25, 26, 27, 28, 29, 30, 31,
254       32, 33, 34, 35, 36, 37, 38, 39,
255       40, 41, 42, 43, 44, 45, 46, 47,
256       48, 49, 50, 51, 52, 53, 54, 55,
257       56, 57, 58, 59, 60, 61, 62, 63,
258       64, 97, 98, 99,100,101,102,103,
259      104,105,106,107,108,109,110,111,
260      112,113,114,115,116,117,118,119,
261      120,121,122, 91, 92, 93, 94, 95,
262       96, 97, 98, 99,100,101,102,103,
263      104,105,106,107,108,109,110,111,
264      112,113,114,115,116,117,118,119,
265      120,121,122,123,124,125,126,127,
266      128,129,130,131,132,133,134,135,
267      136,137,138,139,140,141,142,143,
268      144,145,146,147,148,149,150,151,
269      152,153,154,155,156,157,158,159,
270      160,161,162,163,164,165,166,167,
271      168,169,170,171,172,173,174,175,
272      176,177,178,179,180,181,182,183,
273      184,185,186,187,188,189,190,191,
274      192,193,194,195,196,197,198,199,
275      200,201,202,203,204,205,206,207,
276      208,209,210,211,212,213,214,215,
277      216,217,218,219,220,221,222,223,
278      224,225,226,227,228,229,230,231,
279      232,233,234,235,236,237,238,239,
280      240,241,242,243,244,245,246,247,
281      248,249,250,251,252,253,254,255,
282    
283    /* This table is a case flipping table. */
284    
285        0,  1,  2,  3,  4,  5,  6,  7,
286        8,  9, 10, 11, 12, 13, 14, 15,
287       16, 17, 18, 19, 20, 21, 22, 23,
288       24, 25, 26, 27, 28, 29, 30, 31,
289       32, 33, 34, 35, 36, 37, 38, 39,
290       40, 41, 42, 43, 44, 45, 46, 47,
291       48, 49, 50, 51, 52, 53, 54, 55,
292       56, 57, 58, 59, 60, 61, 62, 63,
293       64, 97, 98, 99,100,101,102,103,
294      104,105,106,107,108,109,110,111,
295      112,113,114,115,116,117,118,119,
296      120,121,122, 91, 92, 93, 94, 95,
297       96, 65, 66, 67, 68, 69, 70, 71,
298       72, 73, 74, 75, 76, 77, 78, 79,
299       80, 81, 82, 83, 84, 85, 86, 87,
300       88, 89, 90,123,124,125,126,127,
301      128,129,130,131,132,133,134,135,
302      136,137,138,139,140,141,142,143,
303      144,145,146,147,148,149,150,151,
304      152,153,154,155,156,157,158,159,
305      160,161,162,163,164,165,166,167,
306      168,169,170,171,172,173,174,175,
307      176,177,178,179,180,181,182,183,
308      184,185,186,187,188,189,190,191,
309      192,193,194,195,196,197,198,199,
310      200,201,202,203,204,205,206,207,
311      208,209,210,211,212,213,214,215,
312      216,217,218,219,220,221,222,223,
313      224,225,226,227,228,229,230,231,
314      232,233,234,235,236,237,238,239,
315      240,241,242,243,244,245,246,247,
316      248,249,250,251,252,253,254,255,
317    
318    /* This table contains bit maps for various character classes. Each map is 32
319    bytes long and the bits run from the least significant end of each byte. The
320    classes that have their own maps are: space, xdigit, digit, upper, lower, word,
321    graph, print, punct, and cntrl. Other classes are built from combinations. */
322    
323      0x00,0x3e,0x00,0x00,0x01,0x00,0x00,0x00,
324      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
325      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
326      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
327    
328      0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03,
329      0x7e,0x00,0x00,0x00,0x7e,0x00,0x00,0x00,
330      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
331      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
332    
333      0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03,
334      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
335      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
336      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
337    
338      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
339      0xfe,0xff,0xff,0x07,0x00,0x00,0x00,0x00,
340      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
341      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
342    
343      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
344      0x00,0x00,0x00,0x00,0xfe,0xff,0xff,0x07,
345      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
346      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
347    
348      0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03,
349      0xfe,0xff,0xff,0x87,0xfe,0xff,0xff,0x07,
350      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
351      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
352    
353      0x00,0x00,0x00,0x00,0xfe,0xff,0xff,0xff,
354      0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
355      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
356      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
357    
358      0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
359      0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
360      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
361      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
362    
363      0x00,0x00,0x00,0x00,0xfe,0xff,0x00,0xfc,
364      0x01,0x00,0x00,0xf8,0x01,0x00,0x00,0x78,
365      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
366      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
367    
368      0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
369      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,
370      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
371      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
372    
373    /* This table identifies various classes of character by individual bits:
374      0x01   white space character
375      0x02   letter
376      0x04   decimal digit
377      0x08   hexadecimal digit
378      0x10   alphanumeric or '_'
379      0x80   regular expression metacharacter or binary zero
380    */
381    
382      0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   0-  7 */
383      0x00,0x01,0x01,0x00,0x01,0x01,0x00,0x00, /*   8- 15 */
384      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*  16- 23 */
385      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*  24- 31 */
386      0x01,0x00,0x00,0x00,0x80,0x00,0x00,0x00, /*    - '  */
387      0x80,0x80,0x80,0x80,0x00,0x00,0x80,0x00, /*  ( - /  */
388      0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c, /*  0 - 7  */
389      0x1c,0x1c,0x00,0x00,0x00,0x00,0x00,0x80, /*  8 - ?  */
390      0x00,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x12, /*  @ - G  */
391      0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /*  H - O  */
392      0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /*  P - W  */
393      0x12,0x12,0x12,0x80,0x80,0x00,0x80,0x10, /*  X - _  */
394      0x00,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x12, /*  ` - g  */
395      0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /*  h - o  */
396      0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /*  p - w  */
397      0x12,0x12,0x12,0x80,0x80,0x00,0x00,0x00, /*  x -127 */
398      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 128-135 */
399      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 136-143 */
400      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 144-151 */
401      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 152-159 */
402      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 160-167 */
403      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 168-175 */
404      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 176-183 */
405      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 184-191 */
406      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 192-199 */
407      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 200-207 */
408      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 208-215 */
409      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 216-223 */
410      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 224-231 */
411      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 232-239 */
412      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 240-247 */
413      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/* 248-255 */
414    
415    /* This is a set of tables that came orginally from a Windows user. It seems to
416    be at least an approximation of ISO 8859. In particular, there are characters
417    greater than 128 that are marked as spaces, letters, etc. */
418    
419    static const unsigned char tables1[] = {
420    0,1,2,3,4,5,6,7,
421    8,9,10,11,12,13,14,15,
422    16,17,18,19,20,21,22,23,
423    24,25,26,27,28,29,30,31,
424    32,33,34,35,36,37,38,39,
425    40,41,42,43,44,45,46,47,
426    48,49,50,51,52,53,54,55,
427    56,57,58,59,60,61,62,63,
428    64,97,98,99,100,101,102,103,
429    104,105,106,107,108,109,110,111,
430    112,113,114,115,116,117,118,119,
431    120,121,122,91,92,93,94,95,
432    96,97,98,99,100,101,102,103,
433    104,105,106,107,108,109,110,111,
434    112,113,114,115,116,117,118,119,
435    120,121,122,123,124,125,126,127,
436    128,129,130,131,132,133,134,135,
437    136,137,138,139,140,141,142,143,
438    144,145,146,147,148,149,150,151,
439    152,153,154,155,156,157,158,159,
440    160,161,162,163,164,165,166,167,
441    168,169,170,171,172,173,174,175,
442    176,177,178,179,180,181,182,183,
443    184,185,186,187,188,189,190,191,
444    224,225,226,227,228,229,230,231,
445    232,233,234,235,236,237,238,239,
446    240,241,242,243,244,245,246,215,
447    248,249,250,251,252,253,254,223,
448    224,225,226,227,228,229,230,231,
449    232,233,234,235,236,237,238,239,
450    240,241,242,243,244,245,246,247,
451    248,249,250,251,252,253,254,255,
452    0,1,2,3,4,5,6,7,
453    8,9,10,11,12,13,14,15,
454    16,17,18,19,20,21,22,23,
455    24,25,26,27,28,29,30,31,
456    32,33,34,35,36,37,38,39,
457    40,41,42,43,44,45,46,47,
458    48,49,50,51,52,53,54,55,
459    56,57,58,59,60,61,62,63,
460    64,97,98,99,100,101,102,103,
461    104,105,106,107,108,109,110,111,
462    112,113,114,115,116,117,118,119,
463    120,121,122,91,92,93,94,95,
464    96,65,66,67,68,69,70,71,
465    72,73,74,75,76,77,78,79,
466    80,81,82,83,84,85,86,87,
467    88,89,90,123,124,125,126,127,
468    128,129,130,131,132,133,134,135,
469    136,137,138,139,140,141,142,143,
470    144,145,146,147,148,149,150,151,
471    152,153,154,155,156,157,158,159,
472    160,161,162,163,164,165,166,167,
473    168,169,170,171,172,173,174,175,
474    176,177,178,179,180,181,182,183,
475    184,185,186,187,188,189,190,191,
476    224,225,226,227,228,229,230,231,
477    232,233,234,235,236,237,238,239,
478    240,241,242,243,244,245,246,215,
479    248,249,250,251,252,253,254,223,
480    192,193,194,195,196,197,198,199,
481    200,201,202,203,204,205,206,207,
482    208,209,210,211,212,213,214,247,
483    216,217,218,219,220,221,222,255,
484    0,62,0,0,1,0,0,0,
485    0,0,0,0,0,0,0,0,
486    32,0,0,0,1,0,0,0,
487    0,0,0,0,0,0,0,0,
488    0,0,0,0,0,0,255,3,
489    126,0,0,0,126,0,0,0,
490    0,0,0,0,0,0,0,0,
491    0,0,0,0,0,0,0,0,
492    0,0,0,0,0,0,255,3,
493    0,0,0,0,0,0,0,0,
494    0,0,0,0,0,0,12,2,
495    0,0,0,0,0,0,0,0,
496    0,0,0,0,0,0,0,0,
497    254,255,255,7,0,0,0,0,
498    0,0,0,0,0,0,0,0,
499    255,255,127,127,0,0,0,0,
500    0,0,0,0,0,0,0,0,
501    0,0,0,0,254,255,255,7,
502    0,0,0,0,0,4,32,4,
503    0,0,0,128,255,255,127,255,
504    0,0,0,0,0,0,255,3,
505    254,255,255,135,254,255,255,7,
506    0,0,0,0,0,4,44,6,
507    255,255,127,255,255,255,127,255,
508    0,0,0,0,254,255,255,255,
509    255,255,255,255,255,255,255,127,
510    0,0,0,0,254,255,255,255,
511    255,255,255,255,255,255,255,255,
512    0,2,0,0,255,255,255,255,
513    255,255,255,255,255,255,255,127,
514    0,0,0,0,255,255,255,255,
515    255,255,255,255,255,255,255,255,
516    0,0,0,0,254,255,0,252,
517    1,0,0,248,1,0,0,120,
518    0,0,0,0,254,255,255,255,
519    0,0,128,0,0,0,128,0,
520    255,255,255,255,0,0,0,0,
521    0,0,0,0,0,0,0,128,
522    255,255,255,255,0,0,0,0,
523    0,0,0,0,0,0,0,0,
524    128,0,0,0,0,0,0,0,
525    0,1,1,0,1,1,0,0,
526    0,0,0,0,0,0,0,0,
527    0,0,0,0,0,0,0,0,
528    1,0,0,0,128,0,0,0,
529    128,128,128,128,0,0,128,0,
530    28,28,28,28,28,28,28,28,
531    28,28,0,0,0,0,0,128,
532    0,26,26,26,26,26,26,18,
533    18,18,18,18,18,18,18,18,
534    18,18,18,18,18,18,18,18,
535    18,18,18,128,128,0,128,16,
536    0,26,26,26,26,26,26,18,
537    18,18,18,18,18,18,18,18,
538    18,18,18,18,18,18,18,18,
539    18,18,18,128,128,0,0,0,
540    0,0,0,0,0,1,0,0,
541    0,0,0,0,0,0,0,0,
542    0,0,0,0,0,0,0,0,
543    0,0,0,0,0,0,0,0,
544    1,0,0,0,0,0,0,0,
545    0,0,18,0,0,0,0,0,
546    0,0,20,20,0,18,0,0,
547    0,20,18,0,0,0,0,0,
548    18,18,18,18,18,18,18,18,
549    18,18,18,18,18,18,18,18,
550    18,18,18,18,18,18,18,0,
551    18,18,18,18,18,18,18,18,
552    18,18,18,18,18,18,18,18,
553    18,18,18,18,18,18,18,18,
554    18,18,18,18,18,18,18,0,
555    18,18,18,18,18,18,18,18
556    };
557    
558    
559    
560    
561    #ifndef HAVE_STRERROR
562    /*************************************************
563    *     Provide strerror() for non-ANSI libraries  *
564    *************************************************/
565    
566    /* Some old-fashioned systems still around (e.g. SunOS4) don't have strerror()
567    in their libraries, but can provide the same facility by this simple
568    alternative function. */
569    
570    extern int   sys_nerr;
571    extern char *sys_errlist[];
572    
573    char *
574    strerror(int n)
575    {
576    if (n < 0 || n >= sys_nerr) return "unknown error number";
577    return sys_errlist[n];
578    }
579    #endif /* HAVE_STRERROR */
580    
581    
582    
583    
584  /*************************************************  /*************************************************
# Line 215  uschar *here = start; Line 611  uschar *here = start;
611    
612  for (;;)  for (;;)
613    {    {
614    int rlen = buffer_size - (here - buffer);    int rlen = (int)(buffer_size - (here - buffer));
615    
616    if (rlen > 1000)    if (rlen > 1000)
617      {      {
# Line 245  for (;;) Line 641  for (;;)
641      /* Read the next line by normal means, prompting if the file is stdin. */      /* Read the next line by normal means, prompting if the file is stdin. */
642    
643        {        {
644        if (f == stdin) printf(prompt);        if (f == stdin) printf("%s", prompt);
645        if (fgets((char *)here, rlen,  f) == NULL)        if (fgets((char *)here, rlen,  f) == NULL)
646          return (here == start)? NULL : start;          return (here == start)? NULL : start;
647        }        }
# Line 565  fprintf(outfile, "%.*s", (cb->next_item_ Line 961  fprintf(outfile, "%.*s", (cb->next_item_
961  fprintf(outfile, "\n");  fprintf(outfile, "\n");
962  first_callout = 0;  first_callout = 0;
963    
964    if (cb->mark != last_callout_mark)
965      {
966      fprintf(outfile, "Latest Mark: %s\n",
967        (cb->mark == NULL)? "<unset>" : (char *)(cb->mark));
968      last_callout_mark = cb->mark;
969      }
970    
971  if (cb->callout_data != NULL)  if (cb->callout_data != NULL)
972    {    {
973    int callout_data = *((int *)(cb->callout_data));    int callout_data = *((int *)(cb->callout_data));
# Line 735  return 0; Line 1138  return 0;
1138  *         Check newline indicator                *  *         Check newline indicator                *
1139  *************************************************/  *************************************************/
1140    
1141  /* 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
1142  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.  
1143    
1144  Arguments:  Arguments:
1145    p           points after the leading '<'    p           points after the leading '<'
# Line 785  printf(" -dfa force DFA matching fo Line 1187  printf(" -dfa force DFA matching fo
1187  #endif  #endif
1188  printf("  -help    show usage information\n");  printf("  -help    show usage information\n");
1189  printf("  -i       show information about compiled patterns\n"  printf("  -i       show information about compiled patterns\n"
1190           "  -M       find MATCH_LIMIT minimum for each subject\n"
1191         "  -m       output memory used information\n"         "  -m       output memory used information\n"
1192         "  -o <n>   set size of offsets vector to <n>\n");         "  -o <n>   set size of offsets vector to <n>\n");
1193  #if !defined NOPOSIX  #if !defined NOPOSIX
# Line 792  printf(" -p use POSIX interface\n Line 1195  printf(" -p use POSIX interface\n
1195  #endif  #endif
1196  printf("  -q       quiet: do not output PCRE version number at start\n");  printf("  -q       quiet: do not output PCRE version number at start\n");
1197  printf("  -S <n>   set stack size to <n> megabytes\n");  printf("  -S <n>   set stack size to <n> megabytes\n");
1198  printf("  -s       output store (memory) used information\n"  printf("  -s       force each pattern to be studied\n"
1199         "  -t       time compilation and execution\n");         "  -t       time compilation and execution\n");
1200  printf("  -t <n>   time compilation and execution, repeating <n> times\n");  printf("  -t <n>   time compilation and execution, repeating <n> times\n");
1201  printf("  -tm      time execution (matching) only\n");  printf("  -tm      time execution (matching) only\n");
# Line 814  int main(int argc, char **argv) Line 1217  int main(int argc, char **argv)
1217  FILE *infile = stdin;  FILE *infile = stdin;
1218  int options = 0;  int options = 0;
1219  int study_options = 0;  int study_options = 0;
1220    int default_find_match_limit = FALSE;
1221  int op = 1;  int op = 1;
1222  int timeit = 0;  int timeit = 0;
1223  int timeitm = 0;  int timeitm = 0;
1224  int showinfo = 0;  int showinfo = 0;
1225  int showstore = 0;  int showstore = 0;
1226    int force_study = 0;
1227  int quiet = 0;  int quiet = 0;
1228  int size_offsets = 45;  int size_offsets = 45;
1229  int size_offsets_max;  int size_offsets_max;
# Line 867  while (argc > 1 && argv[op][0] == '-') Line 1272  while (argc > 1 && argv[op][0] == '-')
1272    {    {
1273    unsigned char *endptr;    unsigned char *endptr;
1274    
1275    if (strcmp(argv[op], "-s") == 0 || strcmp(argv[op], "-m") == 0)    if (strcmp(argv[op], "-m") == 0) showstore = 1;
1276      showstore = 1;    else if (strcmp(argv[op], "-s") == 0) force_study = 1;
1277    else if (strcmp(argv[op], "-q") == 0) quiet = 1;    else if (strcmp(argv[op], "-q") == 0) quiet = 1;
1278    else if (strcmp(argv[op], "-b") == 0) debug = 1;    else if (strcmp(argv[op], "-b") == 0) debug = 1;
1279    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;
1280    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;
1281      else if (strcmp(argv[op], "-M") == 0) default_find_match_limit = TRUE;
1282  #if !defined NODFA  #if !defined NODFA
1283    else if (strcmp(argv[op], "-dfa") == 0) all_use_dfa = 1;    else if (strcmp(argv[op], "-dfa") == 0) all_use_dfa = 1;
1284  #endif  #endif
# Line 901  while (argc > 1 && argv[op][0] == '-') Line 1307  while (argc > 1 && argv[op][0] == '-')
1307        ((stack_size = get_value((unsigned char *)argv[op+1], &endptr)),        ((stack_size = get_value((unsigned char *)argv[op+1], &endptr)),
1308          *endptr == 0))          *endptr == 0))
1309      {      {
1310  #if defined(_WIN32) || defined(WIN32)  #if defined(_WIN32) || defined(WIN32) || defined(__minix)
1311      printf("PCRE: -S not supported on this OS\n");      printf("PCRE: -S not supported on this OS\n");
1312      exit(1);      exit(1);
1313  #else  #else
# Line 925  while (argc > 1 && argv[op][0] == '-') Line 1331  while (argc > 1 && argv[op][0] == '-')
1331    else if (strcmp(argv[op], "-C") == 0)    else if (strcmp(argv[op], "-C") == 0)
1332      {      {
1333      int rc;      int rc;
1334      unsigned long int lrc;      unsigned long int lrc;
1335      printf("PCRE version %s\n", pcre_version());      printf("PCRE version %s\n", pcre_version());
1336      printf("Compiled with\n");      printf("Compiled with\n");
1337      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
# Line 933  while (argc > 1 && argv[op][0] == '-') Line 1339  while (argc > 1 && argv[op][0] == '-')
1339      (void)pcre_config(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);      (void)pcre_config(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
1340      printf("  %sUnicode properties support\n", rc? "" : "No ");      printf("  %sUnicode properties support\n", rc? "" : "No ");
1341      (void)pcre_config(PCRE_CONFIG_NEWLINE, &rc);      (void)pcre_config(PCRE_CONFIG_NEWLINE, &rc);
1342      printf("  Newline sequence is %s\n", (rc == '\r')? "CR" :      /* Note that these values are always the ASCII values, even
1343        (rc == '\n')? "LF" : (rc == ('\r'<<8 | '\n'))? "CRLF" :      in EBCDIC environments. CR is 13 and NL is 10. */
1344        printf("  Newline sequence is %s\n", (rc == 13)? "CR" :
1345          (rc == 10)? "LF" : (rc == (13<<8 | 10))? "CRLF" :
1346        (rc == -2)? "ANYCRLF" :        (rc == -2)? "ANYCRLF" :
1347        (rc == -1)? "ANY" : "???");        (rc == -1)? "ANY" : "???");
1348      (void)pcre_config(PCRE_CONFIG_BSR, &rc);      (void)pcre_config(PCRE_CONFIG_BSR, &rc);
# Line 1029  while (!done) Line 1437  while (!done)
1437  #endif  #endif
1438    
1439    const char *error;    const char *error;
1440      unsigned char *markptr;
1441    unsigned char *p, *pp, *ppp;    unsigned char *p, *pp, *ppp;
1442    unsigned char *to_file = NULL;    unsigned char *to_file = NULL;
1443    const unsigned char *tables = NULL;    const unsigned char *tables = NULL;
1444    unsigned long int true_size, true_study_size = 0;    unsigned long int true_size, true_study_size = 0;
1445    size_t size, regex_gotten_store;    size_t size, regex_gotten_store;
1446      int do_allcaps = 0;
1447      int do_mark = 0;
1448    int do_study = 0;    int do_study = 0;
1449      int no_force_study = 0;
1450    int do_debug = debug;    int do_debug = debug;
1451    int do_G = 0;    int do_G = 0;
1452    int do_g = 0;    int do_g = 0;
1453    int do_showinfo = showinfo;    int do_showinfo = showinfo;
1454    int do_showrest = 0;    int do_showrest = 0;
1455      int do_showcaprest = 0;
1456    int do_flip = 0;    int do_flip = 0;
1457    int erroroffset, len, delimiter, poffset;    int erroroffset, len, delimiter, poffset;
1458    
# Line 1101  while (!done) Line 1514  while (!done)
1514          }          }
1515        }        }
1516    
1517      fprintf(outfile, "Compiled regex%s loaded from %s\n",      fprintf(outfile, "Compiled pattern%s loaded from %s\n",
1518        do_flip? " (byte-inverted)" : "", p);        do_flip? " (byte-inverted)" : "", p);
1519    
1520      /* Need to know if UTF-8 for printing data strings */      /* Need to know if UTF-8 for printing data strings */
# Line 1109  while (!done) Line 1522  while (!done)
1522      new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);      new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);
1523      use_utf8 = (get_options & PCRE_UTF8) != 0;      use_utf8 = (get_options & PCRE_UTF8) != 0;
1524    
1525      /* Now see if there is any following study data */      /* Now see if there is any following study data. */
1526    
1527      if (true_study_size != 0)      if (true_study_size != 0)
1528        {        {
# Line 1151  while (!done) Line 1564  while (!done)
1564      }      }
1565    
1566    pp = p;    pp = p;
1567    poffset = p - buffer;    poffset = (int)(p - buffer);
1568    
1569    for(;;)    for(;;)
1570      {      {
# Line 1205  while (!done) Line 1618  while (!done)
1618        case 's': options |= PCRE_DOTALL; break;        case 's': options |= PCRE_DOTALL; break;
1619        case 'x': options |= PCRE_EXTENDED; break;        case 'x': options |= PCRE_EXTENDED; break;
1620    
1621        case '+': do_showrest = 1; break;        case '+':
1622          if (do_showrest) do_showcaprest = 1; else do_showrest = 1;
1623          break;
1624    
1625          case '=': do_allcaps = 1; break;
1626        case 'A': options |= PCRE_ANCHORED; break;        case 'A': options |= PCRE_ANCHORED; break;
1627        case 'B': do_debug = 1; break;        case 'B': do_debug = 1; break;
1628        case 'C': options |= PCRE_AUTO_CALLOUT; break;        case 'C': options |= PCRE_AUTO_CALLOUT; break;
# Line 1215  while (!done) Line 1632  while (!done)
1632        case 'G': do_G = 1; break;        case 'G': do_G = 1; break;
1633        case 'I': do_showinfo = 1; break;        case 'I': do_showinfo = 1; break;
1634        case 'J': options |= PCRE_DUPNAMES; break;        case 'J': options |= PCRE_DUPNAMES; break;
1635          case 'K': do_mark = 1; break;
1636        case 'M': log_store = 1; break;        case 'M': log_store = 1; break;
1637        case 'N': options |= PCRE_NO_AUTO_CAPTURE; break;        case 'N': options |= PCRE_NO_AUTO_CAPTURE; break;
1638    
# Line 1222  while (!done) Line 1640  while (!done)
1640        case 'P': do_posix = 1; break;        case 'P': do_posix = 1; break;
1641  #endif  #endif
1642    
1643        case 'S': do_study = 1; break;        case 'S':
1644          if (do_study == 0) do_study = 1; else
1645            {
1646            do_study = 0;
1647            no_force_study = 1;
1648            }
1649          break;
1650    
1651        case 'U': options |= PCRE_UNGREEDY; break;        case 'U': options |= PCRE_UNGREEDY; break;
1652          case 'W': options |= PCRE_UCP; break;
1653        case 'X': options |= PCRE_EXTRA; break;        case 'X': options |= PCRE_EXTRA; break;
1654          case 'Y': options |= PCRE_NO_START_OPTIMISE; break;
1655        case 'Z': debug_lengths = 0; break;        case 'Z': debug_lengths = 0; break;
1656        case '8': options |= PCRE_UTF8; use_utf8 = 1; break;        case '8': options |= PCRE_UTF8; use_utf8 = 1; break;
1657        case '?': options |= PCRE_NO_UTF8_CHECK; break;        case '?': options |= PCRE_NO_UTF8_CHECK; break;
1658    
1659          case 'T':
1660          switch (*pp++)
1661            {
1662            case '0': tables = tables0; break;
1663            case '1': tables = tables1; break;
1664    
1665            case '\r':
1666            case '\n':
1667            case ' ':
1668            case 0:
1669            fprintf(outfile, "** Missing table number after /T\n");
1670            goto SKIP_DATA;
1671    
1672            default:
1673            fprintf(outfile, "** Bad table number \"%c\" after /T\n", pp[-1]);
1674            goto SKIP_DATA;
1675            }
1676          break;
1677    
1678        case 'L':        case 'L':
1679        ppp = pp;        ppp = pp;
1680        /* The '\r' test here is so that it works on Windows. */        /* The '\r' test here is so that it works on Windows. */
# Line 1254  while (!done) Line 1700  while (!done)
1700    
1701        case '<':        case '<':
1702          {          {
1703          if (strncmp((char *)pp, "JS>", 3) == 0)          if (strncmpic(pp, (uschar *)"JS>", 3) == 0)
1704            {            {
1705            options |= PCRE_JAVASCRIPT_COMPAT;            options |= PCRE_JAVASCRIPT_COMPAT;
1706            pp += 3;            pp += 3;
# Line 1295  while (!done) Line 1741  while (!done)
1741      if ((options & PCRE_DOTALL) != 0) cflags |= REG_DOTALL;      if ((options & PCRE_DOTALL) != 0) cflags |= REG_DOTALL;
1742      if ((options & PCRE_NO_AUTO_CAPTURE) != 0) cflags |= REG_NOSUB;      if ((options & PCRE_NO_AUTO_CAPTURE) != 0) cflags |= REG_NOSUB;
1743      if ((options & PCRE_UTF8) != 0) cflags |= REG_UTF8;      if ((options & PCRE_UTF8) != 0) cflags |= REG_UTF8;
1744        if ((options & PCRE_UCP) != 0) cflags |= REG_UCP;
1745        if ((options & PCRE_UNGREEDY) != 0) cflags |= REG_UNGREEDY;
1746    
1747      rc = regcomp(&preg, (char *)p, cflags);      rc = regcomp(&preg, (char *)p, cflags);
1748    
# Line 1315  while (!done) Line 1763  while (!done)
1763  #endif  /* !defined NOPOSIX */  #endif  /* !defined NOPOSIX */
1764    
1765      {      {
1766        unsigned long int get_options;
1767    
1768      if (timeit > 0)      if (timeit > 0)
1769        {        {
1770        register int i;        register int i;
# Line 1358  while (!done) Line 1808  while (!done)
1808        goto CONTINUE;        goto CONTINUE;
1809        }        }
1810    
1811      /* Compilation succeeded; print data if required. There are now two      /* Compilation succeeded. It is now possible to set the UTF-8 option from
1812      info-returning functions. The old one has a limited interface and      within the regex; check for this so that we know how to process the data
1813      returns only limited data. Check that it agrees with the newer one. */      lines. */
1814    
1815        new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);
1816        if ((get_options & PCRE_UTF8) != 0) use_utf8 = 1;
1817    
1818        /* Print information if required. There are now two info-returning
1819        functions. The old one has a limited interface and returns only limited
1820        data. Check that it agrees with the newer one. */
1821    
1822      if (log_store)      if (log_store)
1823        fprintf(outfile, "Memory allocation (code space): %d\n",        fprintf(outfile, "Memory allocation (code space): %d\n",
# Line 1374  while (!done) Line 1831  while (!done)
1831      true_size = ((real_pcre *)re)->size;      true_size = ((real_pcre *)re)->size;
1832      regex_gotten_store = gotten_store;      regex_gotten_store = gotten_store;
1833    
1834      /* If /S was present, study the regexp to generate additional info to      /* If -s or /S was present, study the regex to generate additional info to
1835      help with the matching. */      help with the matching, unless the pattern has the SS option, which
1836        suppresses the effect of /S (used for a few test patterns where studying is
1837        never sensible). */
1838    
1839      if (do_study)      if (do_study || (force_study && !no_force_study))
1840        {        {
1841        if (timeit > 0)        if (timeit > 0)
1842          {          {
# Line 1399  while (!done) Line 1858  while (!done)
1858          true_study_size = ((pcre_study_data *)(extra->study_data))->size;          true_study_size = ((pcre_study_data *)(extra->study_data))->size;
1859        }        }
1860    
1861        /* If /K was present, we set up for handling MARK data. */
1862    
1863        if (do_mark)
1864          {
1865          if (extra == NULL)
1866            {
1867            extra = (pcre_extra *)malloc(sizeof(pcre_extra));
1868            extra->flags = 0;
1869            }
1870          extra->mark = &markptr;
1871          extra->flags |= PCRE_EXTRA_MARK;
1872          }
1873    
1874      /* If the 'F' option was present, we flip the bytes of all the integer      /* If the 'F' option was present, we flip the bytes of all the integer
1875      fields in the regex data block and the study block. This is to make it      fields in the regex data block and the study block. This is to make it
1876      possible to test PCRE's handling of byte-flipped patterns, e.g. those      possible to test PCRE's handling of byte-flipped patterns, e.g. those
# Line 1431  while (!done) Line 1903  while (!done)
1903          {          {
1904          pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);          pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);
1905          rsd->size = byteflip(rsd->size, sizeof(rsd->size));          rsd->size = byteflip(rsd->size, sizeof(rsd->size));
1906          rsd->options = byteflip(rsd->options, sizeof(rsd->options));          rsd->flags = byteflip(rsd->flags, sizeof(rsd->flags));
1907            rsd->minlength = byteflip(rsd->minlength, sizeof(rsd->minlength));
1908          }          }
1909        }        }
1910    
# Line 1445  while (!done) Line 1918  while (!done)
1918        pcre_printint(re, outfile, debug_lengths);        pcre_printint(re, outfile, debug_lengths);
1919        }        }
1920    
1921        /* We already have the options in get_options (see above) */
1922    
1923      if (do_showinfo)      if (do_showinfo)
1924        {        {
1925        unsigned long int get_options, all_options;        unsigned long int all_options;
1926  #if !defined NOINFOCHECK  #if !defined NOINFOCHECK
1927        int old_first_char, old_options, old_count;        int old_first_char, old_options, old_count;
1928  #endif  #endif
# Line 1456  while (!done) Line 1931  while (!done)
1931        int nameentrysize, namecount;        int nameentrysize, namecount;
1932        const uschar *nametable;        const uschar *nametable;
1933    
       new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);  
1934        new_info(re, NULL, PCRE_INFO_SIZE, &size);        new_info(re, NULL, PCRE_INFO_SIZE, &size);
1935        new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count);        new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count);
1936        new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax);        new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax);
# Line 1516  while (!done) Line 1990  while (!done)
1990        if (do_flip) all_options = byteflip(all_options, sizeof(all_options));        if (do_flip) all_options = byteflip(all_options, sizeof(all_options));
1991    
1992        if (get_options == 0) fprintf(outfile, "No options\n");        if (get_options == 0) fprintf(outfile, "No options\n");
1993          else fprintf(outfile, "Options:%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",          else fprintf(outfile, "Options:%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
1994            ((get_options & PCRE_ANCHORED) != 0)? " anchored" : "",            ((get_options & PCRE_ANCHORED) != 0)? " anchored" : "",
1995            ((get_options & PCRE_CASELESS) != 0)? " caseless" : "",            ((get_options & PCRE_CASELESS) != 0)? " caseless" : "",
1996            ((get_options & PCRE_EXTENDED) != 0)? " extended" : "",            ((get_options & PCRE_EXTENDED) != 0)? " extended" : "",
# Line 1530  while (!done) Line 2004  while (!done)
2004            ((get_options & PCRE_UNGREEDY) != 0)? " ungreedy" : "",            ((get_options & PCRE_UNGREEDY) != 0)? " ungreedy" : "",
2005            ((get_options & PCRE_NO_AUTO_CAPTURE) != 0)? " no_auto_capture" : "",            ((get_options & PCRE_NO_AUTO_CAPTURE) != 0)? " no_auto_capture" : "",
2006            ((get_options & PCRE_UTF8) != 0)? " utf8" : "",            ((get_options & PCRE_UTF8) != 0)? " utf8" : "",
2007              ((get_options & PCRE_UCP) != 0)? " ucp" : "",
2008            ((get_options & PCRE_NO_UTF8_CHECK) != 0)? " no_utf8_check" : "",            ((get_options & PCRE_NO_UTF8_CHECK) != 0)? " no_utf8_check" : "",
2009              ((get_options & PCRE_NO_START_OPTIMIZE) != 0)? " no_start_optimize" : "",
2010            ((get_options & PCRE_DUPNAMES) != 0)? " dupnames" : "");            ((get_options & PCRE_DUPNAMES) != 0)? " dupnames" : "");
2011    
2012        if (jchanged) fprintf(outfile, "Duplicate name status changes\n");        if (jchanged) fprintf(outfile, "Duplicate name status changes\n");
# Line 1598  while (!done) Line 2074  while (!done)
2074        /* Don't output study size; at present it is in any case a fixed        /* Don't output study size; at present it is in any case a fixed
2075        value, but it varies, depending on the computer architecture, and        value, but it varies, depending on the computer architecture, and
2076        so messes up the test suite. (And with the /F option, it might be        so messes up the test suite. (And with the /F option, it might be
2077        flipped.) */        flipped.) If study was forced by an external -s, don't show this
2078          information unless -i or -d was also present. This means that, except
2079          when auto-callouts are involved, the output from runs with and without
2080          -s should be identical. */
2081    
2082        if (do_study)        if (do_study || (force_study && showinfo && !no_force_study))
2083          {          {
2084          if (extra == NULL)          if (extra == NULL)
2085            fprintf(outfile, "Study returned NULL\n");            fprintf(outfile, "Study returned NULL\n");
2086          else          else
2087            {            {
2088            uschar *start_bits = NULL;            uschar *start_bits = NULL;
2089            new_info(re, extra, PCRE_INFO_FIRSTTABLE, &start_bits);            int minlength;
2090    
2091              new_info(re, extra, PCRE_INFO_MINLENGTH, &minlength);
2092              fprintf(outfile, "Subject length lower bound = %d\n", minlength);
2093    
2094              new_info(re, extra, PCRE_INFO_FIRSTTABLE, &start_bits);
2095            if (start_bits == NULL)            if (start_bits == NULL)
2096              fprintf(outfile, "No starting byte set\n");              fprintf(outfile, "No set of starting bytes\n");
2097            else            else
2098              {              {
2099              int i;              int i;
# Line 1674  while (!done) Line 2157  while (!done)
2157            }            }
2158          else          else
2159            {            {
2160            fprintf(outfile, "Compiled regex written to %s\n", to_file);            fprintf(outfile, "Compiled pattern written to %s\n", to_file);
2161    
2162              /* If there is study data, write it, but verify the writing only
2163              if the studying was requested by /S, not just by -s. */
2164    
2165            if (extra != NULL)            if (extra != NULL)
2166              {              {
2167              if (fwrite(extra->study_data, 1, true_study_size, f) <              if (fwrite(extra->study_data, 1, true_study_size, f) <
# Line 1684  while (!done) Line 2171  while (!done)
2171                  strerror(errno));                  strerror(errno));
2172                }                }
2173              else fprintf(outfile, "Study data written to %s\n", to_file);              else fprintf(outfile, "Study data written to %s\n", to_file);
   
2174              }              }
2175            }            }
2176          fclose(f);          fclose(f);
# Line 1692  while (!done) Line 2178  while (!done)
2178    
2179        new_free(re);        new_free(re);
2180        if (extra != NULL) new_free(extra);        if (extra != NULL) new_free(extra);
2181        if (tables != NULL) new_free((void *)tables);        if (locale_set)
2182            {
2183            new_free((void *)tables);
2184            setlocale(LC_CTYPE, "C");
2185            locale_set = 0;
2186            }
2187        continue;  /* With next regex */        continue;  /* With next regex */
2188        }        }
2189      }        /* End of non-POSIX compile */      }        /* End of non-POSIX compile */
# Line 1709  while (!done) Line 2200  while (!done)
2200      int callout_data_set = 0;      int callout_data_set = 0;
2201      int count, c;      int count, c;
2202      int copystrings = 0;      int copystrings = 0;
2203      int find_match_limit = 0;      int find_match_limit = default_find_match_limit;
2204      int getstrings = 0;      int getstrings = 0;
2205      int getlist = 0;      int getlist = 0;
2206      int gmatched = 0;      int gmatched = 0;
2207      int start_offset = 0;      int start_offset = 0;
2208        int start_offset_sign = 1;
2209      int g_notempty = 0;      int g_notempty = 0;
2210      int use_dfa = 0;      int use_dfa = 0;
2211    
# Line 1727  while (!done) Line 2219  while (!done)
2219    
2220      pcre_callout = callout;      pcre_callout = callout;
2221      first_callout = 1;      first_callout = 1;
2222        last_callout_mark = NULL;
2223      callout_extra = 0;      callout_extra = 0;
2224      callout_count = 0;      callout_count = 0;
2225      callout_fail_count = 999999;      callout_fail_count = 999999;
# Line 1741  while (!done) Line 2234  while (!done)
2234        {        {
2235        if (extend_inputline(infile, buffer + len, "data> ") == NULL)        if (extend_inputline(infile, buffer + len, "data> ") == NULL)
2236          {          {
2237          if (len > 0) break;          if (len > 0)    /* Reached EOF without hitting a newline */
2238              {
2239              fprintf(outfile, "\n");
2240              break;
2241              }
2242          done = 1;          done = 1;
2243          goto CONTINUE;          goto CONTINUE;
2244          }          }
# Line 1842  while (!done) Line 2339  while (!done)
2339          continue;          continue;
2340    
2341          case '>':          case '>':
2342            if (*p == '-')
2343              {
2344              start_offset_sign = -1;
2345              p++;
2346              }
2347          while(isdigit(*p)) start_offset = start_offset * 10 + *p++ - '0';          while(isdigit(*p)) start_offset = start_offset * 10 + *p++ - '0';
2348            start_offset *= start_offset_sign;
2349          continue;          continue;
2350    
2351          case 'A':  /* Option setting */          case 'A':  /* Option setting */
# Line 1915  while (!done) Line 2418  while (!done)
2418  #endif  #endif
2419            use_dfa = 1;            use_dfa = 1;
2420          continue;          continue;
2421    #endif
2422    
2423    #if !defined NODFA
2424          case 'F':          case 'F':
2425          options |= PCRE_DFA_SHORTEST;          options |= PCRE_DFA_SHORTEST;
2426          continue;          continue;
# Line 1949  while (!done) Line 2454  while (!done)
2454          continue;          continue;
2455    
2456          case 'N':          case 'N':
2457          options |= PCRE_NOTEMPTY;          if ((options & PCRE_NOTEMPTY) != 0)
2458              options = (options & ~PCRE_NOTEMPTY) | PCRE_NOTEMPTY_ATSTART;
2459            else
2460              options |= PCRE_NOTEMPTY;
2461          continue;          continue;
2462    
2463          case 'O':          case 'O':
# Line 1972  while (!done) Line 2480  while (!done)
2480          continue;          continue;
2481    
2482          case 'P':          case 'P':
2483          options |= PCRE_PARTIAL;          options |= ((options & PCRE_PARTIAL_SOFT) == 0)?
2484              PCRE_PARTIAL_SOFT : PCRE_PARTIAL_HARD;
2485          continue;          continue;
2486    
2487          case 'Q':          case 'Q':
# Line 2007  while (!done) Line 2516  while (!done)
2516          show_malloc = 1;          show_malloc = 1;
2517          continue;          continue;
2518    
2519            case 'Y':
2520            options |= PCRE_NO_START_OPTIMIZE;
2521            continue;
2522    
2523          case 'Z':          case 'Z':
2524          options |= PCRE_NOTEOL;          options |= PCRE_NOTEOL;
2525          continue;          continue;
# Line 2027  while (!done) Line 2540  while (!done)
2540        *q++ = c;        *q++ = c;
2541        }        }
2542      *q = 0;      *q = 0;
2543      len = q - dbuffer;      len = (int)(q - dbuffer);
2544    
2545      /* Move the data to the end of the buffer so that a read over the end of      /* Move the data to the end of the buffer so that a read over the end of
2546      the buffer will be seen by valgrind, even if it doesn't cause a crash. If      the buffer will be seen by valgrind, even if it doesn't cause a crash. If
# Line 2065  while (!done) Line 2578  while (!done)
2578          pmatch = (regmatch_t *)malloc(sizeof(regmatch_t) * use_size_offsets);          pmatch = (regmatch_t *)malloc(sizeof(regmatch_t) * use_size_offsets);
2579        if ((options & PCRE_NOTBOL) != 0) eflags |= REG_NOTBOL;        if ((options & PCRE_NOTBOL) != 0) eflags |= REG_NOTBOL;
2580        if ((options & PCRE_NOTEOL) != 0) eflags |= REG_NOTEOL;        if ((options & PCRE_NOTEOL) != 0) eflags |= REG_NOTEOL;
2581          if ((options & PCRE_NOTEMPTY) != 0) eflags |= REG_NOTEMPTY;
2582    
2583        rc = regexec(&preg, (const char *)bptr, use_size_offsets, pmatch, eflags);        rc = regexec(&preg, (const char *)bptr, use_size_offsets, pmatch, eflags);
2584    
# Line 2089  while (!done) Line 2603  while (!done)
2603              (void)pchars(dbuffer + pmatch[i].rm_so,              (void)pchars(dbuffer + pmatch[i].rm_so,
2604                pmatch[i].rm_eo - pmatch[i].rm_so, outfile);                pmatch[i].rm_eo - pmatch[i].rm_so, outfile);
2605              fprintf(outfile, "\n");              fprintf(outfile, "\n");
2606              if (i == 0 && do_showrest)              if (do_showcaprest || (i == 0 && do_showrest))
2607                {                {
2608                fprintf(outfile, " 0+ ");                fprintf(outfile, "%2d+ ", (int)i);
2609                (void)pchars(dbuffer + pmatch[i].rm_eo, len - pmatch[i].rm_eo,                (void)pchars(dbuffer + pmatch[i].rm_eo, len - pmatch[i].rm_eo,
2610                  outfile);                  outfile);
2611                fprintf(outfile, "\n");                fprintf(outfile, "\n");
# Line 2109  while (!done) Line 2623  while (!done)
2623    
2624      for (;; gmatched++)    /* Loop for /g or /G */      for (;; gmatched++)    /* Loop for /g or /G */
2625        {        {
2626          markptr = NULL;
2627    
2628        if (timeitm > 0)        if (timeitm > 0)
2629          {          {
2630          register int i;          register int i;
# Line 2120  while (!done) Line 2636  while (!done)
2636            {            {
2637            int workspace[1000];            int workspace[1000];
2638            for (i = 0; i < timeitm; i++)            for (i = 0; i < timeitm; i++)
2639              count = pcre_dfa_exec(re, NULL, (char *)bptr, len, start_offset,              count = pcre_dfa_exec(re, extra, (char *)bptr, len, start_offset,
2640                options | g_notempty, use_offsets, use_size_offsets, workspace,                options | g_notempty, use_offsets, use_size_offsets, workspace,
2641                sizeof(workspace)/sizeof(int));                sizeof(workspace)/sizeof(int));
2642            }            }
# Line 2183  while (!done) Line 2699  while (!done)
2699        else if (all_use_dfa || use_dfa)        else if (all_use_dfa || use_dfa)
2700          {          {
2701          int workspace[1000];          int workspace[1000];
2702          count = pcre_dfa_exec(re, NULL, (char *)bptr, len, start_offset,          count = pcre_dfa_exec(re, extra, (char *)bptr, len, start_offset,
2703            options | g_notempty, use_offsets, use_size_offsets, workspace,            options | g_notempty, use_offsets, use_size_offsets, workspace,
2704            sizeof(workspace)/sizeof(int));            sizeof(workspace)/sizeof(int));
2705          if (count == 0)          if (count == 0)
# Line 2231  while (!done) Line 2747  while (!done)
2747              }              }
2748            }            }
2749    
2750            /* do_allcaps requests showing of all captures in the pattern, to check
2751            unset ones at the end. */
2752    
2753            if (do_allcaps)
2754              {
2755              new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count);
2756              count++;   /* Allow for full match */
2757              if (count * 2 > use_size_offsets) count = use_size_offsets/2;
2758              }
2759    
2760            /* Output the captured substrings */
2761    
2762          for (i = 0; i < count * 2; i += 2)          for (i = 0; i < count * 2; i += 2)
2763            {            {
2764            if (use_offsets[i] < 0)            if (use_offsets[i] < 0)
2765                {
2766                if (use_offsets[i] != -1)
2767                  fprintf(outfile, "ERROR: bad negative value %d for offset %d\n",
2768                    use_offsets[i], i);
2769                if (use_offsets[i+1] != -1)
2770                  fprintf(outfile, "ERROR: bad negative value %d for offset %d\n",
2771                    use_offsets[i+1], i+1);
2772              fprintf(outfile, "%2d: <unset>\n", i/2);              fprintf(outfile, "%2d: <unset>\n", i/2);
2773                }
2774            else            else
2775              {              {
2776              fprintf(outfile, "%2d: ", i/2);              fprintf(outfile, "%2d: ", i/2);
2777              (void)pchars(bptr + use_offsets[i],              (void)pchars(bptr + use_offsets[i],
2778                use_offsets[i+1] - use_offsets[i], outfile);                use_offsets[i+1] - use_offsets[i], outfile);
2779              fprintf(outfile, "\n");              fprintf(outfile, "\n");
2780              if (i == 0)              if (do_showcaprest || (i == 0 && do_showrest))
2781                {                {
2782                if (do_showrest)                fprintf(outfile, "%2d+ ", i/2);
2783                  {                (void)pchars(bptr + use_offsets[i+1], len - use_offsets[i+1],
2784                  fprintf(outfile, " 0+ ");                  outfile);
2785                  (void)pchars(bptr + use_offsets[i+1], len - use_offsets[i+1],                fprintf(outfile, "\n");
                   outfile);  
                 fprintf(outfile, "\n");  
                 }  
2786                }                }
2787              }              }
2788            }            }
2789    
2790            if (markptr != NULL) fprintf(outfile, "MK: %s\n", markptr);
2791    
2792          for (i = 0; i < 32; i++)          for (i = 0; i < 32; i++)
2793            {            {
2794            if ((copystrings & (1 << i)) != 0)            if ((copystrings & (1 << i)) != 0)
# Line 2337  while (!done) Line 2872  while (!done)
2872    
2873        else if (count == PCRE_ERROR_PARTIAL)        else if (count == PCRE_ERROR_PARTIAL)
2874          {          {
2875          fprintf(outfile, "Partial match");          if (markptr == NULL) fprintf(outfile, "Partial match");
2876  #if !defined NODFA            else fprintf(outfile, "Partial match, mark=%s", markptr);
2877          if ((all_use_dfa || use_dfa) && use_size_offsets > 2)          if (use_size_offsets > 1)
2878            fprintf(outfile, ": %.*s", use_offsets[1] - use_offsets[0],            {
2879              bptr + use_offsets[0]);            fprintf(outfile, ": ");
2880  #endif            pchars(bptr + use_offsets[0], use_offsets[1] - use_offsets[0],
2881                outfile);
2882              }
2883          fprintf(outfile, "\n");          fprintf(outfile, "\n");
2884          break;  /* Out of the /g loop */          break;  /* Out of the /g loop */
2885          }          }
# Line 2352  while (!done) Line 2889  while (!done)
2889        to advance the start offset, and continue. We won't be at the end of the        to advance the start offset, and continue. We won't be at the end of the
2890        string - that was checked before setting g_notempty.        string - that was checked before setting g_notempty.
2891    
2892        Complication arises in the case when the newline option is "any" or        Complication arises in the case when the newline convention is "any",
2893        "anycrlf". If the previous match was at the end of a line terminated by        "crlf", or "anycrlf". If the previous match was at the end of a line
2894        CRLF, an advance of one character just passes the \r, whereas we should        terminated by CRLF, an advance of one character just passes the \r,
2895        prefer the longer newline sequence, as does the code in pcre_exec().        whereas we should prefer the longer newline sequence, as does the code in
2896        Fudge the offset value to achieve this.        pcre_exec(). Fudge the offset value to achieve this. We check for a
2897          newline setting in the pattern; if none was set, use pcre_config() to
2898          find the default.
2899    
2900        Otherwise, in the case of UTF-8 matching, the advance must be one        Otherwise, in the case of UTF-8 matching, the advance must be one
2901        character, not one byte. */        character, not one byte. */
# Line 2372  while (!done) Line 2911  while (!done)
2911              {              {
2912              int d;              int d;
2913              (void)pcre_config(PCRE_CONFIG_NEWLINE, &d);              (void)pcre_config(PCRE_CONFIG_NEWLINE, &d);
2914              obits = (d == '\r')? PCRE_NEWLINE_CR :              /* Note that these values are always the ASCII ones, even in
2915                      (d == '\n')? PCRE_NEWLINE_LF :              EBCDIC environments. CR = 13, NL = 10. */
2916                      (d == ('\r'<<8 | '\n'))? PCRE_NEWLINE_CRLF :              obits = (d == 13)? PCRE_NEWLINE_CR :
2917                        (d == 10)? PCRE_NEWLINE_LF :
2918                        (d == (13<<8 | 10))? PCRE_NEWLINE_CRLF :
2919                      (d == -2)? PCRE_NEWLINE_ANYCRLF :                      (d == -2)? PCRE_NEWLINE_ANYCRLF :
2920                      (d == -1)? PCRE_NEWLINE_ANY : 0;                      (d == -1)? PCRE_NEWLINE_ANY : 0;
2921              }              }
2922            if (((obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANY ||            if (((obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANY ||
2923                   (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||
2924                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)
2925                &&                &&
2926                start_offset < len - 1 &&                start_offset < len - 1 &&
# Line 2389  while (!done) Line 2931  while (!done)
2931              {              {
2932              while (start_offset + onechar < len)              while (start_offset + onechar < len)
2933                {                {
2934                int tb = bptr[start_offset+onechar];                if ((bptr[start_offset+onechar] & 0xc0) != 0x80) break;
2935                if (tb <= 127) break;                onechar++;
               tb &= 0xc0;  
               if (tb != 0 && tb != 0xc0) onechar++;  
2936                }                }
2937              }              }
2938            use_offsets[1] = start_offset + onechar;            use_offsets[1] = start_offset + onechar;
2939            }            }
2940          else          else
2941            {            {
2942            if (count == PCRE_ERROR_NOMATCH)            switch(count)
2943              {              {
2944              if (gmatched == 0) fprintf(outfile, "No match\n");              case PCRE_ERROR_NOMATCH:
2945                if (gmatched == 0)
2946                  {
2947                  if (markptr == NULL) fprintf(outfile, "No match\n");
2948                    else fprintf(outfile, "No match, mark = %s\n", markptr);
2949                  }
2950                break;
2951    
2952                case PCRE_ERROR_BADUTF8:
2953                case PCRE_ERROR_SHORTUTF8:
2954                fprintf(outfile, "Error %d (%s UTF-8 string)", count,
2955                  (count == PCRE_ERROR_BADUTF8)? "bad" : "short");
2956                if (use_size_offsets >= 2)
2957                  fprintf(outfile, " offset=%d reason=%d", use_offsets[0],
2958                    use_offsets[1]);
2959                fprintf(outfile, "\n");
2960                break;
2961    
2962                default:
2963                if (count < 0 && (-count) < sizeof(errtexts)/sizeof(const char *))
2964                  fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);
2965                else
2966                  fprintf(outfile, "Error %d (Unexpected value)\n", count);
2967                break;
2968              }              }
2969            else fprintf(outfile, "Error %d\n", count);  
2970            break;  /* Out of the /g loop */            break;  /* Out of the /g loop */
2971            }            }
2972          }          }
# Line 2413  while (!done) Line 2976  while (!done)
2976        if (!do_g && !do_G) break;        if (!do_g && !do_G) break;
2977    
2978        /* If we have matched an empty string, first check to see if we are at        /* If we have matched an empty string, first check to see if we are at
2979        the end of the subject. If so, the /g loop is over. Otherwise, mimic        the end of the subject. If so, the /g loop is over. Otherwise, mimic what
2980        what Perl's /g options does. This turns out to be rather cunning. First        Perl's /g options does. This turns out to be rather cunning. First we set
2981        we set PCRE_NOTEMPTY and PCRE_ANCHORED and try the match again at the        PCRE_NOTEMPTY_ATSTART and PCRE_ANCHORED and try the match again at the
2982        same point. If this fails (picked up above) we advance to the next        same point. If this fails (picked up above) we advance to the next
2983        character. */        character. */
2984    
# Line 2424  while (!done) Line 2987  while (!done)
2987        if (use_offsets[0] == use_offsets[1])        if (use_offsets[0] == use_offsets[1])
2988          {          {
2989          if (use_offsets[0] == len) break;          if (use_offsets[0] == len) break;
2990          g_notempty = PCRE_NOTEMPTY | PCRE_ANCHORED;          g_notempty = PCRE_NOTEMPTY_ATSTART | PCRE_ANCHORED;
2991          }          }
2992    
2993        /* For /g, update the start offset, leaving the rest alone */        /* For /g, update the start offset, leaving the rest alone */
# Line 2451  while (!done) Line 3014  while (!done)
3014    
3015    if (re != NULL) new_free(re);    if (re != NULL) new_free(re);
3016    if (extra != NULL) new_free(extra);    if (extra != NULL) new_free(extra);
3017    if (tables != NULL)    if (locale_set)
3018      {      {
3019      new_free((void *)tables);      new_free((void *)tables);
3020      setlocale(LC_CTYPE, "C");      setlocale(LC_CTYPE, "C");

Legend:
Removed from v.376  
changed lines
  Added in v.654

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12