/[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 836 by ph10, Wed Dec 28 17:16:11 2011 UTC revision 862 by ph10, Wed Jan 11 16:07:32 2012 UTC
# Line 209  argument, the casting might be incorrect Line 209  argument, the casting might be incorrect
209  #define READ_CAPTURE_NAME8(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME8(p, cn8, cn16, re) \
210    p = read_capture_name8(p, cn8, re)    p = read_capture_name8(p, cn8, re)
211    
212    #define STRLEN8(p) ((int)strlen((char *)p))
213    
214  #define SET_PCRE_CALLOUT8(callout) \  #define SET_PCRE_CALLOUT8(callout) \
215    pcre_callout = callout    pcre_callout = callout
216    
217  #define STRLEN8(p) ((int)strlen((char *)p))  #define PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata) \
218       pcre_assign_jit_stack(extra, callback, userdata)
219    
220  #define PCRE_COMPILE8(re, pat, options, error, erroffset, tables) \  #define PCRE_COMPILE8(re, pat, options, error, erroffset, tables) \
221    re = pcre_compile((char *)pat, options, error, erroffset, tables)    re = pcre_compile((char *)pat, options, error, erroffset, tables)
# Line 259  argument, the casting might be incorrect Line 261  argument, the casting might be incorrect
261  #define PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr) \  #define PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr) \
262    rc = pcre_get_substring_list((const char *)bptr, offsets, count, listptr)    rc = pcre_get_substring_list((const char *)bptr, offsets, count, listptr)
263    
264  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER8(re, extra, tables) \  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER8(rc, re, extra, tables) \
265    pcre_pattern_to_host_byte_order(re, extra, tables)    rc = pcre_pattern_to_host_byte_order(re, extra, tables)
266    
267  #define PCRE_PRINTINT8(re, outfile, debug_lengths) \  #define PCRE_PRINTINT8(re, outfile, debug_lengths) \
268    pcre_printint(re, outfile, debug_lengths)    pcre_printint(re, outfile, debug_lengths)
# Line 268  argument, the casting might be incorrect Line 270  argument, the casting might be incorrect
270  #define PCRE_STUDY8(extra, re, options, error) \  #define PCRE_STUDY8(extra, re, options, error) \
271    extra = pcre_study(re, options, error)    extra = pcre_study(re, options, error)
272    
273    #define PCRE_JIT_STACK_ALLOC8(startsize, maxsize) \
274      pcre_jit_stack_alloc(startsize, maxsize)
275    
276    #define PCRE_JIT_STACK_FREE8(stack) \
277      pcre_jit_stack_free(stack)
278    
279  #endif /* SUPPORT_PCRE8 */  #endif /* SUPPORT_PCRE8 */
280    
281  /* -----------------------------------------------------------*/  /* -----------------------------------------------------------*/
# Line 286  argument, the casting might be incorrect Line 294  argument, the casting might be incorrect
294  #define STRLEN16(p) ((int)strlen16((PCRE_SPTR16)p))  #define STRLEN16(p) ((int)strlen16((PCRE_SPTR16)p))
295    
296  #define SET_PCRE_CALLOUT16(callout) \  #define SET_PCRE_CALLOUT16(callout) \
297    pcre16_callout = callout    pcre16_callout = (int (*)(pcre16_callout_block *))callout
298    
299    #define PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata) \
300      pcre16_assign_jit_stack((pcre16_extra *)extra, \
301        (pcre16_jit_callback)callback, userdata)
302    
303  #define PCRE_COMPILE16(re, pat, options, error, erroffset, tables) \  #define PCRE_COMPILE16(re, pat, options, error, erroffset, tables) \
304    re = pcre16_compile((PCRE_SPTR16)pat, options, error, erroffset, tables)    re = (pcre *)pcre16_compile((PCRE_SPTR16)pat, options, error, erroffset, \
305        tables)
306    
307  #define PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \  #define PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
308      namesptr, cbuffer, size) \      namesptr, cbuffer, size) \
309    rc = pcre16_copy_named_substring(re, (PCRE_SPTR16)bptr, offsets, count, \    rc = pcre16_copy_named_substring((pcre16 *)re, (PCRE_SPTR16)bptr, offsets, \
310      (PCRE_SPTR16)namesptr, (PCRE_SCHAR16 *)cbuffer, size/2)      count, (PCRE_SPTR16)namesptr, (PCRE_UCHAR16 *)cbuffer, size/2)
311    
312  #define PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size) \  #define PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size) \
313    rc = pcre16_copy_substring((PCRE_SPTR16)bptr, offsets, count, i, \    rc = pcre16_copy_substring((PCRE_SPTR16)bptr, offsets, count, i, \
314      (PCRE_SCHAR16 *)cbuffer, size/2)      (PCRE_UCHAR16 *)cbuffer, size/2)
315    
316  #define PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \
317      offsets, size_offsets, workspace, size_workspace) \      offsets, size_offsets, workspace, size_workspace) \
318    count = pcre16_dfa_exec(re, extra, (PCRE_SPTR16)bptr, len, start_offset, \    count = pcre16_dfa_exec((pcre16 *)re, (pcre16_extra *)extra, \
319      options, offsets, size_offsets, workspace, size_workspace)      (PCRE_SPTR16)bptr, len, start_offset, options, offsets, size_offsets, \
320        workspace, size_workspace)
321    
322  #define PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \
323      offsets, size_offsets) \      offsets, size_offsets) \
324    count = pcre16_exec(re, extra, (PCRE_SPTR16)bptr, len, start_offset, \    count = pcre16_exec((pcre16 *)re, (pcre16_extra *)extra, (PCRE_SPTR16)bptr, \
325      options, offsets, size_offsets)      len, start_offset, options, offsets, size_offsets)
326    
327  #define PCRE_FREE_STUDY16(extra) \  #define PCRE_FREE_STUDY16(extra) \
328    pcre16_free_study(extra)    pcre16_free_study((pcre16_extra *)extra)
329    
330  #define PCRE_FREE_SUBSTRING16(substring) \  #define PCRE_FREE_SUBSTRING16(substring) \
331    pcre16_free_substring((PCRE_SPTR16)substring)    pcre16_free_substring((PCRE_SPTR16)substring)
# Line 322  argument, the casting might be incorrect Line 335  argument, the casting might be incorrect
335    
336  #define PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \  #define PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
337      getnamesptr, subsptr) \      getnamesptr, subsptr) \
338    rc = pcre16_get_named_substring(re, (PCRE_SPTR16)bptr, offsets, count, \    rc = pcre16_get_named_substring((pcre16 *)re, (PCRE_SPTR16)bptr, offsets, \
339      (PCRE_SPTR16)getnamesptr, (PCRE_SPTR16 *)(void*)subsptr)      count, (PCRE_SPTR16)getnamesptr, (PCRE_SPTR16 *)(void*)subsptr)
340    
341  #define PCRE_GET_STRINGNUMBER16(n, rc, ptr) \  #define PCRE_GET_STRINGNUMBER16(n, rc, ptr) \
342    n = pcre16_get_stringnumber(re, (PCRE_SPTR16)ptr)    n = pcre16_get_stringnumber(re, (PCRE_SPTR16)ptr)
# Line 336  argument, the casting might be incorrect Line 349  argument, the casting might be incorrect
349    rc = pcre16_get_substring_list((PCRE_SPTR16)bptr, offsets, count, \    rc = pcre16_get_substring_list((PCRE_SPTR16)bptr, offsets, count, \
350      (PCRE_SPTR16 **)(void*)listptr)      (PCRE_SPTR16 **)(void*)listptr)
351    
352  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER16(re, extra, tables) \  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables) \
353    pcre16_pattern_to_host_byte_order(re, extra, tables)    rc = pcre16_pattern_to_host_byte_order((pcre16 *)re, (pcre16_extra *)extra, \
354        tables)
355    
356  #define PCRE_PRINTINT16(re, outfile, debug_lengths) \  #define PCRE_PRINTINT16(re, outfile, debug_lengths) \
357    pcre16_printint(re, outfile, debug_lengths)    pcre16_printint(re, outfile, debug_lengths)
358    
359  #define PCRE_STUDY16(extra, re, options, error) \  #define PCRE_STUDY16(extra, re, options, error) \
360    extra = pcre16_study(re, options, error)    extra = (pcre_extra *)pcre16_study((pcre16 *)re, options, error)
361    
362    #define PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \
363      (pcre_jit_stack *)pcre16_jit_stack_alloc(startsize, maxsize)
364    
365    #define PCRE_JIT_STACK_FREE16(stack) \
366      pcre16_jit_stack_free((pcre16_jit_stack *)stack)
367    
368  #endif /* SUPPORT_PCRE16 */  #endif /* SUPPORT_PCRE16 */
369    
# Line 382  version is called. ----- */ Line 402  version is called. ----- */
402    
403  #define STRLEN(p) (use_pcre16? STRLEN16(p) : STRLEN8(p))  #define STRLEN(p) (use_pcre16? STRLEN16(p) : STRLEN8(p))
404    
405  #define PCRE_ASSIGN_JIT_STACK pcre_assign_jit_stack  #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \
406      if (use_pcre16) \
407        PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata); \
408      else \
409        PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata)
410    
411  #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \  #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
412    if (use_pcre16) \    if (use_pcre16) \
# Line 470  version is called. ----- */ Line 494  version is called. ----- */
494    else \    else \
495      PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr)      PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr)
496    
497  #define PCRE_JIT_STACK_ALLOC pcre_jit_stack_alloc  #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \
498  #define PCRE_JIT_STACK_FREE pcre_jit_stack_free    (use_pcre16 ? \
499         PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \
500        :PCRE_JIT_STACK_ALLOC8(startsize, maxsize))
501    
502    #define PCRE_JIT_STACK_FREE(stack) \
503      if (use_pcre16) \
504        PCRE_JIT_STACK_FREE16(stack); \
505      else \
506        PCRE_JIT_STACK_FREE8(stack)
507    
508  #define PCRE_MAKETABLES \  #define PCRE_MAKETABLES \
509    (use_pcre16? pcre16_maketables() : pcre_maketables())    (use_pcre16? pcre16_maketables() : pcre_maketables())
510    
511  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(re, extra, tables) \  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \
512    if (use_pcre16) \    if (use_pcre16) \
513      PCRE_PATTERN_TO_HOST_BYTE_ORDER16(re, extra, tables); \      PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables); \
514    else \    else \
515      PCRE_PATTERN_TO_HOST_BYTE_ORDER8(re, extra, tables)      PCRE_PATTERN_TO_HOST_BYTE_ORDER8(rc, re, extra, tables)
516    
517  #define PCRE_PRINTINT(re, outfile, debug_lengths) \  #define PCRE_PRINTINT(re, outfile, debug_lengths) \
518    if (use_pcre16) \    if (use_pcre16) \
# Line 503  version is called. ----- */ Line 535  version is called. ----- */
535  #define READ_CAPTURE_NAME         READ_CAPTURE_NAME8  #define READ_CAPTURE_NAME         READ_CAPTURE_NAME8
536  #define SET_PCRE_CALLOUT          SET_PCRE_CALLOUT8  #define SET_PCRE_CALLOUT          SET_PCRE_CALLOUT8
537  #define STRLEN                    STRLEN8  #define STRLEN                    STRLEN8
538  #define PCRE_ASSIGN_JIT_STACK     pcre_assign_jit_stack  #define PCRE_ASSIGN_JIT_STACK     PCRE_ASSIGN_JIT_STACK8
539  #define PCRE_COMPILE              PCRE_COMPILE8  #define PCRE_COMPILE              PCRE_COMPILE8
540  #define PCRE_CONFIG               pcre_config  #define PCRE_CONFIG               pcre_config
541  #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING8  #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING8
# Line 517  version is called. ----- */ Line 549  version is called. ----- */
549  #define PCRE_GET_STRINGNUMBER     PCRE_GET_STRINGNUMBER8  #define PCRE_GET_STRINGNUMBER     PCRE_GET_STRINGNUMBER8
550  #define PCRE_GET_SUBSTRING        PCRE_GET_SUBSTRING8  #define PCRE_GET_SUBSTRING        PCRE_GET_SUBSTRING8
551  #define PCRE_GET_SUBSTRING_LIST   PCRE_GET_SUBSTRING_LIST8  #define PCRE_GET_SUBSTRING_LIST   PCRE_GET_SUBSTRING_LIST8
552  #define PCRE_JIT_STACK_ALLOC      pcre_jit_stack_alloc  #define PCRE_JIT_STACK_ALLOC      PCRE_JIT_STACK_ALLOC8
553  #define PCRE_JIT_STACK_FREE       pcre_jit_stack_free  #define PCRE_JIT_STACK_FREE       PCRE_JIT_STACK_FREE8
554  #define PCRE_MAKETABLES           pcre_maketables()  #define PCRE_MAKETABLES           pcre_maketables()
555  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER8  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER8
556  #define PCRE_PRINTINT             PCRE_PRINTINT8  #define PCRE_PRINTINT             PCRE_PRINTINT8
# Line 533  version is called. ----- */ Line 565  version is called. ----- */
565  #define READ_CAPTURE_NAME         READ_CAPTURE_NAME16  #define READ_CAPTURE_NAME         READ_CAPTURE_NAME16
566  #define SET_PCRE_CALLOUT          SET_PCRE_CALLOUT16  #define SET_PCRE_CALLOUT          SET_PCRE_CALLOUT16
567  #define STRLEN                    STRLEN16  #define STRLEN                    STRLEN16
568  #define PCRE_ASSIGN_JIT_STACK     pcre16_assign_jit_stack  #define PCRE_ASSIGN_JIT_STACK     PCRE_ASSIGN_JIT_STACK16
569  #define PCRE_COMPILE              PCRE_COMPILE16  #define PCRE_COMPILE              PCRE_COMPILE16
570  #define PCRE_CONFIG               pcre16_config  #define PCRE_CONFIG               pcre16_config
571  #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING16  #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING16
# Line 547  version is called. ----- */ Line 579  version is called. ----- */
579  #define PCRE_GET_STRINGNUMBER     PCRE_GET_STRINGNUMBER16  #define PCRE_GET_STRINGNUMBER     PCRE_GET_STRINGNUMBER16
580  #define PCRE_GET_SUBSTRING        PCRE_GET_SUBSTRING16  #define PCRE_GET_SUBSTRING        PCRE_GET_SUBSTRING16
581  #define PCRE_GET_SUBSTRING_LIST   PCRE_GET_SUBSTRING_LIST16  #define PCRE_GET_SUBSTRING_LIST   PCRE_GET_SUBSTRING_LIST16
582  #define PCRE_JIT_STACK_ALLOC      pcre16_jit_stack_alloc  #define PCRE_JIT_STACK_ALLOC      PCRE_JIT_STACK_ALLOC16
583  #define PCRE_JIT_STACK_FREE       pcre16_jit_stack_free  #define PCRE_JIT_STACK_FREE       PCRE_JIT_STACK_FREE16
584  #define PCRE_MAKETABLES           pcre16_maketables()  #define PCRE_MAKETABLES           pcre16_maketables()
585  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER16  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER16
586  #define PCRE_PRINTINT             PCRE_PRINTINT16  #define PCRE_PRINTINT             PCRE_PRINTINT16
# Line 625  COMPILE_PCRE16 is *not* set. */ Line 657  COMPILE_PCRE16 is *not* set. */
657  #error LINK_SIZE must be either 2, 3, or 4  #error LINK_SIZE must be either 2, 3, or 4
658  #endif  #endif
659    
660    #undef IMM2_SIZE
661    #define IMM2_SIZE 1
662    
663  #endif /* SUPPORT_PCRE8 */  #endif /* SUPPORT_PCRE8 */
664    
665  static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };  static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };
# Line 1123  for (j = i; j > 0; j--) Line 1158  for (j = i; j > 0; j--)
1158  *utf8bytes = utf8_table2[i] | cvalue;  *utf8bytes = utf8_table2[i] | cvalue;
1159  return i + 1;  return i + 1;
1160  }  }
1161  #endif /* NOUTF || SUPPORT_PCRE16 */  #endif
   
1162    
1163    
1164  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
# Line 1142  Note that this function does not object Line 1176  Note that this function does not object
1176  deliberate; it makes it possible to construct UTF-16 strings that are invalid,  deliberate; it makes it possible to construct UTF-16 strings that are invalid,
1177  for the purpose of testing that they are correctly faulted.  for the purpose of testing that they are correctly faulted.
1178    
1179  Patterns to be converted are either plain ASCII or UTF-8; data lines are always  Patterns to be converted are either plain ASCII or UTF-8; data lines are always
1180  in UTF-8 so that values greater than 255 can be handled.  in UTF-8 so that values greater than 255 can be handled.
1181    
1182  Arguments:  Arguments:
# Line 1154  Arguments: Line 1188  Arguments:
1188  Returns:     number of 16-bit data items used (excluding trailing zero)  Returns:     number of 16-bit data items used (excluding trailing zero)
1189               OR -1 if a UTF-8 string is malformed               OR -1 if a UTF-8 string is malformed
1190               OR -2 if a value > 0x10ffff is encountered               OR -2 if a value > 0x10ffff is encountered
1191               OR -3 if a value > 0xffff is encountered when not in UTF mode               OR -3 if a value > 0xffff is encountered when not in UTF mode
1192  */  */
1193    
1194  static int  static int
# Line 1511  pcre_uint16 *npp = *pp; Line 1545  pcre_uint16 *npp = *pp;
1545  while (isalnum(*p)) *npp++ = *p++;  while (isalnum(*p)) *npp++ = *p++;
1546  *npp++ = 0;  *npp++ = 0;
1547  *npp = 0;  *npp = 0;
1548  if (pcre16_get_stringnumber(re, (PCRE_SPTR16)(*pp)) < 0)  if (pcre16_get_stringnumber((pcre16 *)re, (PCRE_SPTR16)(*pp)) < 0)
1549    {    {
1550    fprintf(outfile, "no parentheses with name \"");    fprintf(outfile, "no parentheses with name \"");
1551    PCHARSV(*pp, 0, -1, outfile);    PCHARSV(*pp, 0, -1, outfile);
# Line 1700  int rc; Line 1734  int rc;
1734    
1735  if (use_pcre16)  if (use_pcre16)
1736  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
1737    rc = pcre16_fullinfo(re, study, option, ptr);    rc = pcre16_fullinfo((pcre16 *)re, (pcre16_extra *)study, option, ptr);
1738  #else  #else
1739    rc = PCRE_ERROR_BADMODE;    rc = PCRE_ERROR_BADMODE;
1740  #endif  #endif
# Line 1769  architecture. */ Line 1803  architecture. */
1803  static void  static void
1804  regexflip(pcre *ere, pcre_extra *extra)  regexflip(pcre *ere, pcre_extra *extra)
1805  {  {
1806  real_pcre *re = (real_pcre *)ere;  REAL_PCRE *re = (REAL_PCRE *)ere;
1807  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
1808  int op;  int op;
1809  pcre_uint16 *ptr = (pcre_uint16 *)re + re->name_table_offset;  pcre_uint16 *ptr = (pcre_uint16 *)re + re->name_table_offset;
# Line 1913  while(TRUE) Line 1947  while(TRUE)
1947      break;      break;
1948    
1949      case OP_XCLASS:      case OP_XCLASS:
1950        /* LINK_SIZE can be 1 or 2 in 16 bit mode. */
1951        if (LINK_SIZE > 1)
1952          length = (int)((((unsigned int)(ptr[0]) << 16) | (unsigned int)(ptr[1]))
1953            - (1 + LINK_SIZE + 1));
1954        else
1955          length = (int)((unsigned int)(ptr[0]) - (1 + LINK_SIZE + 1));
1956    
1957      /* Reverse the size of the XCLASS instance. */      /* Reverse the size of the XCLASS instance. */
     ptr++;  
1958      *ptr = swap_uint16(*ptr);      *ptr = swap_uint16(*ptr);
1959        ptr++;
1960      if (LINK_SIZE > 1)      if (LINK_SIZE > 1)
1961        {        {
       /* LINK_SIZE can be 1 or 2 in 16 bit mode. */  
       ptr++;  
1962        *ptr = swap_uint16(*ptr);        *ptr = swap_uint16(*ptr);
1963          ptr++;
1964        }        }
     ptr++;  
   
     if (LINK_SIZE > 1)  
       length = ((ptr[-LINK_SIZE] << 16) | ptr[-LINK_SIZE + 1]) -  
         (1 + LINK_SIZE + 1);  
     else  
       length = ptr[-LINK_SIZE] - (1 + LINK_SIZE + 1);  
1965    
1966      op = *ptr;      op = *ptr;
1967      *ptr = swap_uint16(op);      *ptr = swap_uint16(op);
1968        ptr++;
1969      if ((op & XCL_MAP) != 0)      if ((op & XCL_MAP) != 0)
1970        {        {
1971        /* Skip the character bit map. */        /* Skip the character bit map. */
# Line 2070  printf("This version of pcretest is not Line 2104  printf("This version of pcretest is not
2104  #endif  #endif
2105  printf("\nOptions:\n");  printf("\nOptions:\n");
2106  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2107  printf("  -16      use 16-bit interface\n");  printf("  -16      use the 16-bit library\n");
2108  #endif  #endif
2109  printf("  -b       show compiled code (bytecode)\n");  printf("  -b       show compiled code\n");
2110  printf("  -C       show PCRE compile-time options and exit\n");  printf("  -C       show PCRE compile-time options and exit\n");
2111  printf("  -C arg   show a specific compile-time option\n");  printf("  -C arg   show a specific compile-time option\n");
2112  printf("           and exit with its value. The arg can be:\n");  printf("           and exit with its value. The arg can be:\n");
# Line 2082  printf("     pcre16       16 bit library Line 2116  printf("     pcre16       16 bit library
2116  printf("     utf          Unicode Transformation Format supported [0, 1]\n");  printf("     utf          Unicode Transformation Format supported [0, 1]\n");
2117  printf("     ucp          Unicode Properties supported [0, 1]\n");  printf("     ucp          Unicode Properties supported [0, 1]\n");
2118  printf("     jit          Just-in-time compiler supported [0, 1]\n");  printf("     jit          Just-in-time compiler supported [0, 1]\n");
2119    printf("     newline      Newline type [CR, LF, CRLF, ANYCRLF, ANY, ???]\n");
2120  printf("  -d       debug: show compiled code and information (-b and -i)\n");  printf("  -d       debug: show compiled code and information (-b and -i)\n");
2121  #if !defined NODFA  #if !defined NODFA
2122  printf("  -dfa     force DFA matching for all subjects\n");  printf("  -dfa     force DFA matching for all subjects\n");
# Line 2331  while (argc > 1 && argv[op][0] == '-') Line 2366  while (argc > 1 && argv[op][0] == '-')
2366          yield = rc;          yield = rc;
2367          goto EXIT;          goto EXIT;
2368          }          }
2369        printf("Unknown option: %s\n", argv[op + 1]);        if (strcmp(argv[op + 1], "newline") == 0)
2370            {
2371            (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
2372            /* Note that these values are always the ASCII values, even
2373            in EBCDIC environments. CR is 13 and NL is 10. */
2374            printf("%s\n", (rc == 13)? "CR" :
2375              (rc == 10)? "LF" : (rc == (13<<8 | 10))? "CRLF" :
2376              (rc == -2)? "ANYCRLF" :
2377              (rc == -1)? "ANY" : "???");
2378            goto EXIT;
2379            }
2380          printf("Unknown -C option: %s\n", argv[op + 1]);
2381        goto EXIT;        goto EXIT;
2382        }        }
2383    
# Line 2477  while (!done) Line 2523  while (!done)
2523    pcre_uint8 *p, *pp, *ppp;    pcre_uint8 *p, *pp, *ppp;
2524    pcre_uint8 *to_file = NULL;    pcre_uint8 *to_file = NULL;
2525    const pcre_uint8 *tables = NULL;    const pcre_uint8 *tables = NULL;
2526      unsigned long int get_options;
2527    unsigned long int true_size, true_study_size = 0;    unsigned long int true_size, true_study_size = 0;
2528    size_t size, regex_gotten_store;    size_t size, regex_gotten_store;
2529    int do_allcaps = 0;    int do_allcaps = 0;
# Line 2507  while (!done) Line 2554  while (!done)
2554    
2555    if (*p == '<' && strchr((char *)(p+1), '<') == NULL)    if (*p == '<' && strchr((char *)(p+1), '<') == NULL)
2556      {      {
2557      unsigned long int magic, get_options;      pcre_uint32 magic;
2558      pcre_uint8 sbuf[8];      pcre_uint8 sbuf[8];
2559      FILE *f;      FILE *f;
2560    
2561      p++;      p++;
2562        if (*p == '!')
2563          {
2564          do_debug = TRUE;
2565          do_showinfo = TRUE;
2566          p++;
2567          }
2568    
2569      pp = p + (int)strlen((char *)p);      pp = p + (int)strlen((char *)p);
2570      while (isspace(pp[-1])) pp--;      while (isspace(pp[-1])) pp--;
2571      *pp = 0;      *pp = 0;
# Line 2523  while (!done) Line 2577  while (!done)
2577        continue;        continue;
2578        }        }
2579    
2580        first_gotten_store = 0;
2581      if (fread(sbuf, 1, 8, f) != 8) goto FAIL_READ;      if (fread(sbuf, 1, 8, f) != 8) goto FAIL_READ;
2582    
2583      true_size =      true_size =
# Line 2530  while (!done) Line 2585  while (!done)
2585      true_study_size =      true_study_size =
2586        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];        (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];
2587    
2588      re = (real_pcre *)new_malloc(true_size);      re = (pcre *)new_malloc(true_size);
2589      regex_gotten_store = first_gotten_store;      regex_gotten_store = first_gotten_store;
2590    
2591      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;
2592    
2593      magic = ((real_pcre *)re)->magic_number;      magic = ((REAL_PCRE *)re)->magic_number;
2594      if (magic != MAGIC_NUMBER)      if (magic != MAGIC_NUMBER)
2595        {        {
2596        if (swap_uint32(magic) == MAGIC_NUMBER)        if (swap_uint32(magic) == MAGIC_NUMBER)
# Line 2550  while (!done) Line 2605  while (!done)
2605          }          }
2606        }        }
2607    
2608        /* We hide the byte-invert info for little and big endian tests. */
2609      fprintf(outfile, "Compiled pattern%s loaded from %s\n",      fprintf(outfile, "Compiled pattern%s loaded from %s\n",
2610        do_flip? " (byte-inverted)" : "", p);        do_flip && (p[-1] == '<') ? " (byte-inverted)" : "", p);
2611    
2612      /* Now see if there is any following study data. */      /* Now see if there is any following study data. */
2613    
# Line 2585  while (!done) Line 2641  while (!done)
2641      /* Flip the necessary bytes. */      /* Flip the necessary bytes. */
2642      if (do_flip)      if (do_flip)
2643        {        {
2644        PCRE_PATTERN_TO_HOST_BYTE_ORDER(re, extra, NULL);        int rc;
2645          PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, NULL);
2646          if (rc == PCRE_ERROR_BADMODE)
2647            {
2648            /* Simulate the result of the function call below. */
2649            fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
2650              use_pcre16? "16" : "", PCRE_INFO_OPTIONS);
2651            fprintf(outfile, "Running in %s-bit mode but pattern was compiled in "
2652              "%s-bit mode\n", use_pcre16? "16":"8", use_pcre16? "8":"16");
2653            continue;
2654            }
2655        }        }
2656    
2657      /* Need to know if UTF-8 for printing data strings. */      /* Need to know if UTF-8 for printing data strings. */
# Line 2818  while (!done) Line 2884  while (!done)
2884  #endif  /* !defined NOPOSIX */  #endif  /* !defined NOPOSIX */
2885    
2886      {      {
     unsigned long int get_options;  
   
2887      /* In 16-bit mode, convert the input. */      /* In 16-bit mode, convert the input. */
2888    
2889  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
# Line 2836  while (!done) Line 2900  while (!done)
2900          fprintf(outfile, "**Failed: character value greater than 0x10ffff "          fprintf(outfile, "**Failed: character value greater than 0x10ffff "
2901            "cannot be converted to UTF-16\n");            "cannot be converted to UTF-16\n");
2902          goto SKIP_DATA;          goto SKIP_DATA;
2903    
2904          case -3: /* "Impossible error" when to16 is called arg1 FALSE */          case -3: /* "Impossible error" when to16 is called arg1 FALSE */
2905          fprintf(outfile, "**Failed: character value greater than 0xffff "          fprintf(outfile, "**Failed: character value greater than 0xffff "
2906            "cannot be converted to 16-bit in non-UTF mode\n");            "cannot be converted to 16-bit in non-UTF mode\n");
2907          goto SKIP_DATA;          goto SKIP_DATA;
2908    
2909          default:          default:
2910          break;          break;
# Line 2906  while (!done) Line 2970  while (!done)
2970      /* Extract the size for possible writing before possibly flipping it,      /* Extract the size for possible writing before possibly flipping it,
2971      and remember the store that was got. */      and remember the store that was got. */
2972    
2973      true_size = ((real_pcre *)re)->size;      true_size = ((REAL_PCRE *)re)->size;
2974      regex_gotten_store = first_gotten_store;      regex_gotten_store = first_gotten_store;
2975    
2976      /* Output code size information if requested */      /* Output code size information if requested */
# Line 2914  while (!done) Line 2978  while (!done)
2978      if (log_store)      if (log_store)
2979        fprintf(outfile, "Memory allocation (code space): %d\n",        fprintf(outfile, "Memory allocation (code space): %d\n",
2980          (int)(first_gotten_store -          (int)(first_gotten_store -
2981                sizeof(real_pcre) -                sizeof(REAL_PCRE) -
2982                ((real_pcre *)re)->name_count * ((real_pcre *)re)->name_entry_size));                ((REAL_PCRE *)re)->name_count * ((REAL_PCRE *)re)->name_entry_size));
2983    
2984      /* If -s or /S was present, study the regex to generate additional info to      /* If -s or /S was present, study the regex to generate additional info to
2985      help with the matching, unless the pattern has the SS option, which      help with the matching, unless the pattern has the SS option, which
# Line 3046  while (!done) Line 3110  while (!done)
3110        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");
3111        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");
3112    
3113        all_options = ((real_pcre *)re)->options;        all_options = ((REAL_PCRE *)re)->options;
3114        if (do_flip) all_options = swap_uint32(all_options);        if (do_flip) all_options = swap_uint32(all_options);
3115    
3116        if (get_options == 0) fprintf(outfile, "No options\n");        if (get_options == 0) fprintf(outfile, "No options\n");
# Line 3108  while (!done) Line 3172  while (!done)
3172        else        else
3173          {          {
3174          const char *caseless =          const char *caseless =
3175            ((((real_pcre *)re)->flags & PCRE_FCH_CASELESS) == 0)?            ((((REAL_PCRE *)re)->flags & PCRE_FCH_CASELESS) == 0)?
3176            "" : " (caseless)";            "" : " (caseless)";
3177    
3178          if (PRINTOK(first_char))          if (PRINTOK(first_char))
# Line 3128  while (!done) Line 3192  while (!done)
3192        else        else
3193          {          {
3194          const char *caseless =          const char *caseless =
3195            ((((real_pcre *)re)->flags & PCRE_RCH_CASELESS) == 0)?            ((((REAL_PCRE *)re)->flags & PCRE_RCH_CASELESS) == 0)?
3196            "" : " (caseless)";            "" : " (caseless)";
3197    
3198          if (PRINTOK(need_char))          if (PRINTOK(need_char))
# Line 3353  while (!done) Line 3417  while (!done)
3417        {        {
3418        int i = 0;        int i = 0;
3419        int n = 0;        int n = 0;
3420    
3421        /* In UTF mode, input can be UTF-8, so just copy all non-backslash bytes.        /* In UTF mode, input can be UTF-8, so just copy all non-backslash bytes.
3422        In non-UTF mode, allow the value of the byte to fall through to later,        In non-UTF mode, allow the value of the byte to fall through to later,
3423        where values greater than 127 are turned into UTF-8 when running in        where values greater than 127 are turned into UTF-8 when running in
3424        16-bit mode. */        16-bit mode. */
3425    
3426        if (c != '\\')        if (c != '\\')
3427          {          {
3428          if (use_utf)          if (use_utf)
3429            {            {
3430            *q++ = c;            *q++ = c;
3431            continue;            continue;
3432            }            }
3433          }          }
3434    
3435        /* Handle backslash escapes */        /* Handle backslash escapes */
3436    
3437        else switch ((c = *p++))        else switch ((c = *p++))
3438          {          {
3439          case 'a': c =    7; break;          case 'a': c =    7; break;
# Line 3400  while (!done) Line 3464  while (!done)
3464            least one MacOS environment. */            least one MacOS environment. */
3465    
3466            for (pt++; isxdigit(*pt); pt++)            for (pt++; isxdigit(*pt); pt++)
3467              c = c * 16 + tolower(*pt) - ((isdigit(*pt))? '0' : 'a' - 10);              {
3468                if (++i == 9)
3469                  fprintf(outfile, "** Too many hex digits in \\x{...} item; "
3470                                   "using only the first eight.\n");
3471                else c = c * 16 + tolower(*pt) - ((isdigit(*pt))? '0' : 'a' - 10);
3472                }
3473            if (*pt == '}')            if (*pt == '}')
3474              {              {
3475              p = pt + 1;              p = pt + 1;
# Line 3409  while (!done) Line 3478  while (!done)
3478            /* Not correct form for \x{...}; fall through */            /* Not correct form for \x{...}; fall through */
3479            }            }
3480    
3481          /* \x without {} always defines just one byte in 8-bit mode. This          /* \x without {} always defines just one byte in 8-bit mode. This
3482          allows UTF-8 characters to be constructed byte by byte, and also allows          allows UTF-8 characters to be constructed byte by byte, and also allows
3483          invalid UTF-8 sequences to be made. Just copy the byte in UTF mode.          invalid UTF-8 sequences to be made. Just copy the byte in UTF mode.
3484          Otherwise, pass it down to later code so that it can be turned into          Otherwise, pass it down to later code so that it can be turned into
3485          UTF-8 when running in 16-bit mode. */          UTF-8 when running in 16-bit mode. */
3486    
3487          c = 0;          c = 0;
# Line 3422  while (!done) Line 3491  while (!done)
3491            p++;            p++;
3492            }            }
3493          if (use_utf)          if (use_utf)
3494            {            {
3495            *q++ = c;            *q++ = c;
3496            continue;            continue;
3497            }            }
3498          break;          break;
3499    
3500          case 0:   /* \ followed by EOF allows for an empty line */          case 0:   /* \ followed by EOF allows for an empty line */
# Line 3531  while (!done) Line 3600  while (!done)
3600              && (extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0              && (extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0
3601              && extra->executable_jit != NULL)              && extra->executable_jit != NULL)
3602            {            {
3603            if (jit_stack != NULL) PCRE_JIT_STACK_FREE(jit_stack);            if (jit_stack != NULL) { PCRE_JIT_STACK_FREE(jit_stack); }
3604            jit_stack = PCRE_JIT_STACK_ALLOC(1, n * 1024);            jit_stack = PCRE_JIT_STACK_ALLOC(1, n * 1024);
3605            PCRE_ASSIGN_JIT_STACK(extra, jit_callback, jit_stack);            PCRE_ASSIGN_JIT_STACK(extra, jit_callback, jit_stack);
3606            }            }
# Line 3630  while (!done) Line 3699  while (!done)
3699          continue;          continue;
3700          }          }
3701    
3702        /* We now have a character value in c that may be greater than 255. In        /* We now have a character value in c that may be greater than 255. In
3703        16-bit mode, we always convert characters to UTF-8 so that values greater        16-bit mode, we always convert characters to UTF-8 so that values greater
3704        than 255 can be passed to non-UTF 16-bit strings. In 8-bit mode we        than 255 can be passed to non-UTF 16-bit strings. In 8-bit mode we
3705        convert to UTF-8 if we are in UTF mode. Values greater than 127 in UTF        convert to UTF-8 if we are in UTF mode. Values greater than 127 in UTF
3706        mode must have come from \x{...} or octal constructs because values from        mode must have come from \x{...} or octal constructs because values from
3707        \x.. get this far only in non-UTF mode. */        \x.. get this far only in non-UTF mode. */
3708    
3709    #if !defined NOUTF || defined SUPPORT_PCRE16
3710        if (use_pcre16 || use_utf)        if (use_pcre16 || use_utf)
3711          {          {
3712          pcre_uint8 buff8[8];          pcre_uint8 buff8[8];
# Line 3645  while (!done) Line 3715  while (!done)
3715          for (ii = 0; ii < utn; ii++) *q++ = buff8[ii];          for (ii = 0; ii < utn; ii++) *q++ = buff8[ii];
3716          }          }
3717        else        else
3718    #endif
3719          {          {
3720          if (c > 255)          if (c > 255)
3721            {            {
# Line 3656  while (!done) Line 3727  while (!done)
3727          *q++ = c;          *q++ = c;
3728          }          }
3729        }        }
3730    
3731      /* Reached end of subject string */      /* Reached end of subject string */
3732    
3733      *q = 0;      *q = 0;
3734      len = (int)(q - dbuffer);      len = (int)(q - dbuffer);
3735    
# Line 3744  while (!done) Line 3815  while (!done)
3815  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3816      if (use_pcre16)      if (use_pcre16)
3817        {        {
3818        len = to16(TRUE, bptr, (((real_pcre *)re)->options) & PCRE_UTF8, len);        len = to16(TRUE, bptr, (((REAL_PCRE *)re)->options) & PCRE_UTF8, len);
3819        switch(len)        switch(len)
3820          {          {
3821          case -1:          case -1:
# Line 3760  while (!done) Line 3831  while (!done)
3831          case -3:          case -3:
3832          fprintf(outfile, "**Failed: character value greater than 0xffff "          fprintf(outfile, "**Failed: character value greater than 0xffff "
3833            "cannot be converted to 16-bit in non-UTF mode\n");            "cannot be converted to 16-bit in non-UTF mode\n");
3834          goto NEXT_DATA;          goto NEXT_DATA;
3835    
3836          default:          default:
3837          break;          break;
# Line 4124  while (!done) Line 4195  while (!done)
4195          if (g_notempty != 0)          if (g_notempty != 0)
4196            {            {
4197            int onechar = 1;            int onechar = 1;
4198            unsigned int obits = ((real_pcre *)re)->options;            unsigned int obits = ((REAL_PCRE *)re)->options;
4199            use_offsets[0] = start_offset;            use_offsets[0] = start_offset;
4200            if ((obits & PCRE_NEWLINE_BITS) == 0)            if ((obits & PCRE_NEWLINE_BITS) == 0)
4201              {              {

Legend:
Removed from v.836  
changed lines
  Added in v.862

  ViewVC Help
Powered by ViewVC 1.1.5