/[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 1046 by ph10, Tue Sep 25 16:27:58 2012 UTC revision 1055 by chpe, Tue Oct 16 15:53:30 2012 UTC
# Line 134  appropriately for an application, not fo Line 134  appropriately for an application, not fo
134    
135  #include "pcre.h"  #include "pcre.h"
136    
137  #if defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE8  #if defined SUPPORT_PCRE32 && !defined SUPPORT_PCRE8 && !defined SUPPORT_PCRE16
138    /* Configure internal macros to 32 bit mode. */
139    #define COMPILE_PCRE32
140    #endif
141    #if defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE8 && !defined SUPPORT_PCRE32
142  /* Configure internal macros to 16 bit mode. */  /* Configure internal macros to 16 bit mode. */
143  #define COMPILE_PCRE16  #define COMPILE_PCRE16
144  #endif  #endif
145    #if defined SUPPORT_PCRE8 && !defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE32
146    /* Configure internal macros to 16 bit mode. */
147    #define COMPILE_PCRE8
148    #endif
149    
150  #include "pcre_internal.h"  #include "pcre_internal.h"
151    
# Line 152  void pcre_printint(pcre *external_re, FI Line 160  void pcre_printint(pcre *external_re, FI
160  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
161  void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths);  void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths);
162  #endif  #endif
163    #ifdef SUPPORT_PCRE32
164    void pcre32_printint(pcre *external_re, FILE *f, BOOL print_lengths);
165    #endif
166    
167  /* We need access to some of the data tables that PCRE uses. So as not to have  /* We need access to some of the data tables that PCRE uses. So as not to have
168  to keep two copies, we include the source files here, changing the names of the  to keep two copies, we include the source files here, changing the names of the
# Line 176  that differ in their output from isprint Line 187  that differ in their output from isprint
187    
188  #define PRINTOK(c) (locale_set? isprint(c) : PRINTABLE(c))  #define PRINTOK(c) (locale_set? isprint(c) : PRINTABLE(c))
189    
190  /* Posix support is disabled in 16 bit only mode. */  /* Posix support is disabled in 16 or 32 bit only mode. */
191  #if defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE8 && !defined NOPOSIX  #if !defined SUPPORT_PCRE8 && !defined NOPOSIX
192  #define NOPOSIX  #define NOPOSIX
193  #endif  #endif
194    
# Line 222  argument, the casting might be incorrect Line 233  argument, the casting might be incorrect
233  #define PCHARSV8(p, offset, len, f) \  #define PCHARSV8(p, offset, len, f) \
234    (void)pchars((pcre_uint8 *)(p) + offset, len, f)    (void)pchars((pcre_uint8 *)(p) + offset, len, f)
235    
236  #define READ_CAPTURE_NAME8(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME8(p, cn8, cn16, cn32, re) \
237    p = read_capture_name8(p, cn8, re)    p = read_capture_name8(p, cn8, re)
238    
239  #define STRLEN8(p) ((int)strlen((char *)p))  #define STRLEN8(p) ((int)strlen((char *)p))
# Line 304  argument, the casting might be incorrect Line 315  argument, the casting might be incorrect
315  #define PCHARSV16(p, offset, len, f) \  #define PCHARSV16(p, offset, len, f) \
316    (void)pchars16((PCRE_SPTR16)(p) + offset, len, f)    (void)pchars16((PCRE_SPTR16)(p) + offset, len, f)
317    
318  #define READ_CAPTURE_NAME16(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME16(p, cn8, cn16, cn32, re) \
319    p = read_capture_name16(p, cn16, re)    p = read_capture_name16(p, cn16, re)
320    
321  #define STRLEN16(p) ((int)strlen16((PCRE_SPTR16)p))  #define STRLEN16(p) ((int)strlen16((PCRE_SPTR16)p))
# Line 383  argument, the casting might be incorrect Line 394  argument, the casting might be incorrect
394    
395  #endif /* SUPPORT_PCRE16 */  #endif /* SUPPORT_PCRE16 */
396    
397    /* -----------------------------------------------------------*/
398    
399    #ifdef SUPPORT_PCRE32
400    
401    #define PCHARS32(lv, p, offset, len, f) \
402      lv = pchars32((PCRE_SPTR32)(p) + offset, len, f)
403    
404    #define PCHARSV32(p, offset, len, f) \
405      (void)pchars32((PCRE_SPTR32)(p) + offset, len, f)
406    
407    #define READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re) \
408      p = read_capture_name32(p, cn32, re)
409    
410    #define STRLEN32(p) ((int)strlen32((PCRE_SPTR32)p))
411    
412    #define SET_PCRE_CALLOUT32(callout) \
413      pcre32_callout = (int (*)(pcre32_callout_block *))callout
414    
415    #define PCRE_ASSIGN_JIT_STACK32(extra, callback, userdata) \
416      pcre32_assign_jit_stack((pcre32_extra *)extra, \
417        (pcre32_jit_callback)callback, userdata)
418    
419    #define PCRE_COMPILE32(re, pat, options, error, erroffset, tables) \
420      re = (pcre *)pcre32_compile((PCRE_SPTR32)pat, options, error, erroffset, \
421        tables)
422    
423    #define PCRE_COPY_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
424        namesptr, cbuffer, size) \
425      rc = pcre32_copy_named_substring((pcre32 *)re, (PCRE_SPTR32)bptr, offsets, \
426        count, (PCRE_SPTR32)namesptr, (PCRE_UCHAR32 *)cbuffer, size/2)
427    
428    #define PCRE_COPY_SUBSTRING32(rc, bptr, offsets, count, i, cbuffer, size) \
429      rc = pcre32_copy_substring((PCRE_SPTR32)bptr, offsets, count, i, \
430        (PCRE_UCHAR32 *)cbuffer, size/2)
431    
432    #define PCRE_DFA_EXEC32(count, re, extra, bptr, len, start_offset, options, \
433        offsets, size_offsets, workspace, size_workspace) \
434      count = pcre32_dfa_exec((pcre32 *)re, (pcre32_extra *)extra, \
435        (PCRE_SPTR32)bptr, len, start_offset, options, offsets, size_offsets, \
436        workspace, size_workspace)
437    
438    #define PCRE_EXEC32(count, re, extra, bptr, len, start_offset, options, \
439        offsets, size_offsets) \
440      count = pcre32_exec((pcre32 *)re, (pcre32_extra *)extra, (PCRE_SPTR32)bptr, \
441        len, start_offset, options, offsets, size_offsets)
442    
443    #define PCRE_FREE_STUDY32(extra) \
444      pcre32_free_study((pcre32_extra *)extra)
445    
446    #define PCRE_FREE_SUBSTRING32(substring) \
447      pcre32_free_substring((PCRE_SPTR32)substring)
448    
449    #define PCRE_FREE_SUBSTRING_LIST32(listptr) \
450      pcre32_free_substring_list((PCRE_SPTR32 *)listptr)
451    
452    #define PCRE_GET_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
453        getnamesptr, subsptr) \
454      rc = pcre32_get_named_substring((pcre32 *)re, (PCRE_SPTR32)bptr, offsets, \
455        count, (PCRE_SPTR32)getnamesptr, (PCRE_SPTR32 *)(void*)subsptr)
456    
457    #define PCRE_GET_STRINGNUMBER32(n, rc, ptr) \
458      n = pcre32_get_stringnumber(re, (PCRE_SPTR32)ptr)
459    
460    #define PCRE_GET_SUBSTRING32(rc, bptr, offsets, count, i, subsptr) \
461      rc = pcre32_get_substring((PCRE_SPTR32)bptr, offsets, count, i, \
462        (PCRE_SPTR32 *)(void*)subsptr)
463    
464    #define PCRE_GET_SUBSTRING_LIST32(rc, bptr, offsets, count, listptr) \
465      rc = pcre32_get_substring_list((PCRE_SPTR32)bptr, offsets, count, \
466        (PCRE_SPTR32 **)(void*)listptr)
467    
468    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER32(rc, re, extra, tables) \
469      rc = pcre32_pattern_to_host_byte_order((pcre32 *)re, (pcre32_extra *)extra, \
470        tables)
471    
472    #define PCRE_PRINTINT32(re, outfile, debug_lengths) \
473      pcre32_printint(re, outfile, debug_lengths)
474    
475    #define PCRE_STUDY32(extra, re, options, error) \
476      extra = (pcre_extra *)pcre32_study((pcre32 *)re, options, error)
477    
478    #define PCRE_JIT_STACK_ALLOC32(startsize, maxsize) \
479      (pcre_jit_stack *)pcre32_jit_stack_alloc(startsize, maxsize)
480    
481    #define PCRE_JIT_STACK_FREE32(stack) \
482      pcre32_jit_stack_free((pcre32_jit_stack *)stack)
483    
484    #endif /* SUPPORT_PCRE32 */
485    
486    
487  /* ----- Both modes are supported; a runtime test is needed, except for  /* ----- Both modes are supported; a runtime test is needed, except for
488  pcre_config(), and the JIT stack functions, when it doesn't matter which  pcre_config(), and the JIT stack functions, when it doesn't matter which
489  version is called. ----- */  version is called. ----- */
490    
491  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  enum {
492      PCRE8_MODE,
493      PCRE16_MODE,
494      PCRE32_MODE
495    };
496    
497    #if (defined (SUPPORT_PCRE8) + defined (SUPPORT_PCRE16) + defined (SUPPORT_PCRE32)) >= 2
498    
499  #define CHAR_SIZE (use_pcre16? 2:1)  #define CHAR_SIZE (1 << pcre_mode)
500    
501  #define PCHARS(lv, p, offset, len, f) \  #define PCHARS(lv, p, offset, len, f) \
502    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
503        PCHARS32(lv, p, offset, len, f); \
504      else if (pcre_mode == PCRE16_MODE) \
505      PCHARS16(lv, p, offset, len, f); \      PCHARS16(lv, p, offset, len, f); \
506    else \    else \
507      PCHARS8(lv, p, offset, len, f)      PCHARS8(lv, p, offset, len, f)
508    
509  #define PCHARSV(p, offset, len, f) \  #define PCHARSV(p, offset, len, f) \
510    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
511        PCHARSV32(p, offset, len, f); \
512      else if (pcre_mode == PCRE16_MODE) \
513      PCHARSV16(p, offset, len, f); \      PCHARSV16(p, offset, len, f); \
514    else \    else \
515      PCHARSV8(p, offset, len, f)      PCHARSV8(p, offset, len, f)
516    
517  #define READ_CAPTURE_NAME(p, cn8, cn16, re) \  #define READ_CAPTURE_NAME(p, cn8, cn16, cn32, re) \
518    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
519      READ_CAPTURE_NAME16(p, cn8, cn16, re); \      READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re); \
520      else if (pcre_mode == PCRE16_MODE) \
521        READ_CAPTURE_NAME16(p, cn8, cn16, cn32, re); \
522    else \    else \
523      READ_CAPTURE_NAME8(p, cn8, cn16, re)      READ_CAPTURE_NAME8(p, cn8, cn16, cn32, re)
524    
525  #define SET_PCRE_CALLOUT(callout) \  #define SET_PCRE_CALLOUT(callout) \
526    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
527        SET_PCRE_CALLOUT32(callout); \
528      else if (pcre_mode == PCRE16_MODE) \
529      SET_PCRE_CALLOUT16(callout); \      SET_PCRE_CALLOUT16(callout); \
530    else \    else \
531      SET_PCRE_CALLOUT8(callout)      SET_PCRE_CALLOUT8(callout)
532    
533  #define STRLEN(p) (use_pcre16? STRLEN16(p) : STRLEN8(p))  #define STRLEN(p) (pcre_mode == PCRE32_MODE ? STRLEN32(p) : pcre_mode == PCRE16_MODE ? STRLEN16(p) : STRLEN8(p))
534    
535  #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \  #define PCRE_ASSIGN_JIT_STACK(extra, callback, userdata) \
536    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
537        PCRE_ASSIGN_JIT_STACK32(extra, callback, userdata); \
538      else if (pcre_mode == PCRE16_MODE) \
539      PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata); \      PCRE_ASSIGN_JIT_STACK16(extra, callback, userdata); \
540    else \    else \
541      PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata)      PCRE_ASSIGN_JIT_STACK8(extra, callback, userdata)
542    
543  #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \  #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
544    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
545        PCRE_COMPILE32(re, pat, options, error, erroffset, tables); \
546      else if (pcre_mode == PCRE16_MODE) \
547      PCRE_COMPILE16(re, pat, options, error, erroffset, tables); \      PCRE_COMPILE16(re, pat, options, error, erroffset, tables); \
548    else \    else \
549      PCRE_COMPILE8(re, pat, options, error, erroffset, tables)      PCRE_COMPILE8(re, pat, options, error, erroffset, tables)
# Line 434  version is called. ----- */ Line 552  version is called. ----- */
552    
553  #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \  #define PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
554      namesptr, cbuffer, size) \      namesptr, cbuffer, size) \
555    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
556        PCRE_COPY_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
557          namesptr, cbuffer, size); \
558      else if (pcre_mode == PCRE16_MODE) \
559      PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \      PCRE_COPY_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
560        namesptr, cbuffer, size); \        namesptr, cbuffer, size); \
561    else \    else \
# Line 442  version is called. ----- */ Line 563  version is called. ----- */
563        namesptr, cbuffer, size)        namesptr, cbuffer, size)
564    
565  #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \  #define PCRE_COPY_SUBSTRING(rc, bptr, offsets, count, i, cbuffer, size) \
566    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
567        PCRE_COPY_SUBSTRING32(rc, bptr, offsets, count, i, cbuffer, size); \
568      else if (pcre_mode == PCRE16_MODE) \
569      PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size); \      PCRE_COPY_SUBSTRING16(rc, bptr, offsets, count, i, cbuffer, size); \
570    else \    else \
571      PCRE_COPY_SUBSTRING8(rc, bptr, offsets, count, i, cbuffer, size)      PCRE_COPY_SUBSTRING8(rc, bptr, offsets, count, i, cbuffer, size)
572    
573  #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \
574      offsets, size_offsets, workspace, size_workspace) \      offsets, size_offsets, workspace, size_workspace) \
575    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
576        PCRE_DFA_EXEC32(count, re, extra, bptr, len, start_offset, options, \
577          offsets, size_offsets, workspace, size_workspace); \
578      else if (pcre_mode == PCRE16_MODE) \
579      PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \      PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \
580        offsets, size_offsets, workspace, size_workspace); \        offsets, size_offsets, workspace, size_workspace); \
581    else \    else \
# Line 458  version is called. ----- */ Line 584  version is called. ----- */
584    
585  #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
586      offsets, size_offsets) \      offsets, size_offsets) \
587    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
588        PCRE_EXEC32(count, re, extra, bptr, len, start_offset, options, \
589          offsets, size_offsets); \
590      else if (pcre_mode == PCRE16_MODE) \
591      PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \      PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \
592        offsets, size_offsets); \        offsets, size_offsets); \
593    else \    else \
# Line 466  version is called. ----- */ Line 595  version is called. ----- */
595        offsets, size_offsets)        offsets, size_offsets)
596    
597  #define PCRE_FREE_STUDY(extra) \  #define PCRE_FREE_STUDY(extra) \
598    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
599        PCRE_FREE_STUDY32(extra); \
600      else if (pcre_mode == PCRE16_MODE) \
601      PCRE_FREE_STUDY16(extra); \      PCRE_FREE_STUDY16(extra); \
602    else \    else \
603      PCRE_FREE_STUDY8(extra)      PCRE_FREE_STUDY8(extra)
604    
605  #define PCRE_FREE_SUBSTRING(substring) \  #define PCRE_FREE_SUBSTRING(substring) \
606    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
607        PCRE_FREE_SUBSTRING32(substring); \
608      else if (pcre_mode == PCRE16_MODE) \
609      PCRE_FREE_SUBSTRING16(substring); \      PCRE_FREE_SUBSTRING16(substring); \
610    else \    else \
611      PCRE_FREE_SUBSTRING8(substring)      PCRE_FREE_SUBSTRING8(substring)
612    
613  #define PCRE_FREE_SUBSTRING_LIST(listptr) \  #define PCRE_FREE_SUBSTRING_LIST(listptr) \
614    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
615        PCRE_FREE_SUBSTRING_LIST32(listptr); \
616      else if (pcre_mode == PCRE16_MODE) \
617      PCRE_FREE_SUBSTRING_LIST16(listptr); \      PCRE_FREE_SUBSTRING_LIST16(listptr); \
618    else \    else \
619      PCRE_FREE_SUBSTRING_LIST8(listptr)      PCRE_FREE_SUBSTRING_LIST8(listptr)
620    
621  #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \  #define PCRE_GET_NAMED_SUBSTRING(rc, re, bptr, offsets, count, \
622      getnamesptr, subsptr) \      getnamesptr, subsptr) \
623    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
624        PCRE_GET_NAMED_SUBSTRING32(rc, re, bptr, offsets, count, \
625          getnamesptr, subsptr); \
626      else if (pcre_mode == PCRE16_MODE) \
627      PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \      PCRE_GET_NAMED_SUBSTRING16(rc, re, bptr, offsets, count, \
628        getnamesptr, subsptr); \        getnamesptr, subsptr); \
629    else \    else \
# Line 493  version is called. ----- */ Line 631  version is called. ----- */
631        getnamesptr, subsptr)        getnamesptr, subsptr)
632    
633  #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \  #define PCRE_GET_STRINGNUMBER(n, rc, ptr) \
634    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
635        PCRE_GET_STRINGNUMBER32(n, rc, ptr); \
636      else if (pcre_mode == PCRE16_MODE) \
637      PCRE_GET_STRINGNUMBER16(n, rc, ptr); \      PCRE_GET_STRINGNUMBER16(n, rc, ptr); \
638    else \    else \
639      PCRE_GET_STRINGNUMBER8(n, rc, ptr)      PCRE_GET_STRINGNUMBER8(n, rc, ptr)
640    
641  #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \  #define PCRE_GET_SUBSTRING(rc, bptr, use_offsets, count, i, subsptr) \
642    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
643        PCRE_GET_SUBSTRING32(rc, bptr, use_offsets, count, i, subsptr); \
644      else if (pcre_mode == PCRE16_MODE) \
645      PCRE_GET_SUBSTRING16(rc, bptr, use_offsets, count, i, subsptr); \      PCRE_GET_SUBSTRING16(rc, bptr, use_offsets, count, i, subsptr); \
646    else \    else \
647      PCRE_GET_SUBSTRING8(rc, bptr, use_offsets, count, i, subsptr)      PCRE_GET_SUBSTRING8(rc, bptr, use_offsets, count, i, subsptr)
648    
649  #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \  #define PCRE_GET_SUBSTRING_LIST(rc, bptr, offsets, count, listptr) \
650    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
651        PCRE_GET_SUBSTRING_LIST32(rc, bptr, offsets, count, listptr); \
652      else if (pcre_mode == PCRE16_MODE) \
653      PCRE_GET_SUBSTRING_LIST16(rc, bptr, offsets, count, listptr); \      PCRE_GET_SUBSTRING_LIST16(rc, bptr, offsets, count, listptr); \
654    else \    else \
655      PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr)      PCRE_GET_SUBSTRING_LIST8(rc, bptr, offsets, count, listptr)
656    
657  #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \  #define PCRE_JIT_STACK_ALLOC(startsize, maxsize) \
658    (use_pcre16 ? \    (pcre_mode == PCRE32_MODE ? \
659       PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \       PCRE_JIT_STACK_ALLOC32(startsize, maxsize) \
660      :PCRE_JIT_STACK_ALLOC8(startsize, maxsize))      : pcre_mode == PCRE16_MODE ? \
661          PCRE_JIT_STACK_ALLOC16(startsize, maxsize) \
662          : PCRE_JIT_STACK_ALLOC8(startsize, maxsize))
663    
664  #define PCRE_JIT_STACK_FREE(stack) \  #define PCRE_JIT_STACK_FREE(stack) \
665    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
666        PCRE_JIT_STACK_FREE32(stack); \
667      else if (pcre_mode == PCRE16_MODE) \
668      PCRE_JIT_STACK_FREE16(stack); \      PCRE_JIT_STACK_FREE16(stack); \
669    else \    else \
670      PCRE_JIT_STACK_FREE8(stack)      PCRE_JIT_STACK_FREE8(stack)
671    
672  #define PCRE_MAKETABLES \  #define PCRE_MAKETABLES \
673    (use_pcre16? pcre16_maketables() : pcre_maketables())    (pcre_mode == PCRE32_MODE ? pcre32_maketables() : pcre_mode == PCRE16_MODE ? pcre16_maketables() : pcre_maketables())
674    
675  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(rc, re, extra, tables) \
676    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
677        PCRE_PATTERN_TO_HOST_BYTE_ORDER32(rc, re, extra, tables); \
678      else if (pcre_mode == PCRE16_MODE) \
679      PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables); \      PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables); \
680    else \    else \
681      PCRE_PATTERN_TO_HOST_BYTE_ORDER8(rc, re, extra, tables)      PCRE_PATTERN_TO_HOST_BYTE_ORDER8(rc, re, extra, tables)
682    
683  #define PCRE_PRINTINT(re, outfile, debug_lengths) \  #define PCRE_PRINTINT(re, outfile, debug_lengths) \
684    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
685        PCRE_PRINTINT32(re, outfile, debug_lengths); \
686      else if (pcre_mode == PCRE16_MODE) \
687      PCRE_PRINTINT16(re, outfile, debug_lengths); \      PCRE_PRINTINT16(re, outfile, debug_lengths); \
688    else \    else \
689      PCRE_PRINTINT8(re, outfile, debug_lengths)      PCRE_PRINTINT8(re, outfile, debug_lengths)
690    
691  #define PCRE_STUDY(extra, re, options, error) \  #define PCRE_STUDY(extra, re, options, error) \
692    if (use_pcre16) \    if (pcre_mode == PCRE32_MODE) \
693        PCRE_STUDY32(extra, re, options, error); \
694      else if (pcre_mode == PCRE16_MODE) \
695      PCRE_STUDY16(extra, re, options, error); \      PCRE_STUDY16(extra, re, options, error); \
696    else \    else \
697      PCRE_STUDY8(extra, re, options, error)      PCRE_STUDY8(extra, re, options, error)
# Line 574  version is called. ----- */ Line 728  version is called. ----- */
728    
729  /* ----- Only 16-bit mode is supported ----- */  /* ----- Only 16-bit mode is supported ----- */
730    
731  #else  #elif defined SUPPORT_PCRE16
732  #define CHAR_SIZE                 2  #define CHAR_SIZE                 2
733  #define PCHARS                    PCHARS16  #define PCHARS                    PCHARS16
734  #define PCHARSV                   PCHARSV16  #define PCHARSV                   PCHARSV16
# Line 601  version is called. ----- */ Line 755  version is called. ----- */
755  #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
756  #define PCRE_PRINTINT             PCRE_PRINTINT16  #define PCRE_PRINTINT             PCRE_PRINTINT16
757  #define PCRE_STUDY                PCRE_STUDY16  #define PCRE_STUDY                PCRE_STUDY16
758    
759    /* ----- Only 32-bit mode is supported ----- */
760    
761    #elif defined SUPPORT_PCRE32
762    #define CHAR_SIZE                 4
763    #define PCHARS                    PCHARS32
764    #define PCHARSV                   PCHARSV32
765    #define READ_CAPTURE_NAME         READ_CAPTURE_NAME32
766    #define SET_PCRE_CALLOUT          SET_PCRE_CALLOUT32
767    #define STRLEN                    STRLEN32
768    #define PCRE_ASSIGN_JIT_STACK     PCRE_ASSIGN_JIT_STACK32
769    #define PCRE_COMPILE              PCRE_COMPILE32
770    #define PCRE_CONFIG               pcre32_config
771    #define PCRE_COPY_NAMED_SUBSTRING PCRE_COPY_NAMED_SUBSTRING32
772    #define PCRE_COPY_SUBSTRING       PCRE_COPY_SUBSTRING32
773    #define PCRE_DFA_EXEC             PCRE_DFA_EXEC32
774    #define PCRE_EXEC                 PCRE_EXEC32
775    #define PCRE_FREE_STUDY           PCRE_FREE_STUDY32
776    #define PCRE_FREE_SUBSTRING       PCRE_FREE_SUBSTRING32
777    #define PCRE_FREE_SUBSTRING_LIST  PCRE_FREE_SUBSTRING_LIST32
778    #define PCRE_GET_NAMED_SUBSTRING  PCRE_GET_NAMED_SUBSTRING32
779    #define PCRE_GET_STRINGNUMBER     PCRE_GET_STRINGNUMBER32
780    #define PCRE_GET_SUBSTRING        PCRE_GET_SUBSTRING32
781    #define PCRE_GET_SUBSTRING_LIST   PCRE_GET_SUBSTRING_LIST32
782    #define PCRE_JIT_STACK_ALLOC      PCRE_JIT_STACK_ALLOC32
783    #define PCRE_JIT_STACK_FREE       PCRE_JIT_STACK_FREE32
784    #define PCRE_MAKETABLES           pcre32_maketables()
785    #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER32
786    #define PCRE_PRINTINT             PCRE_PRINTINT32
787    #define PCRE_STUDY                PCRE_STUDY32
788    
789  #endif  #endif
790    
791  /* ----- End of mode-specific function call macros ----- */  /* ----- End of mode-specific function call macros ----- */
# Line 652  static pcre_uint8 *pbuffer = NULL; Line 837  static pcre_uint8 *pbuffer = NULL;
837  /* Another buffer is needed translation to 16-bit character strings. It will  /* Another buffer is needed translation to 16-bit character strings. It will
838  obtained and extended as required. */  obtained and extended as required. */
839    
840  #ifdef SUPPORT_PCRE16  #if defined SUPPORT_PCRE8 && (defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32)
 static int buffer16_size = 0;  
 static pcre_uint16 *buffer16 = NULL;  
   
 #ifdef SUPPORT_PCRE8  
841    
842  /* We need the table of operator lengths that is used for 16-bit compiling, in  /* We need the table of operator lengths that is used for 16/32-bit compiling, in
843  order to swap bytes in a pattern for saving/reloading testing. Luckily, the  order to swap bytes in a pattern for saving/reloading testing. Luckily, the
844  data is defined as a macro. However, we must ensure that LINK_SIZE is adjusted  data is defined as a macro. However, we must ensure that LINK_SIZE is adjusted
845  appropriately for the 16-bit world. Just as a safety check, make sure that  appropriately for the 16/32-bit world. Just as a safety check, make sure that
846  COMPILE_PCRE16 is *not* set. */  COMPILE_PCRE[16|32] is *not* set. */
847    
848  #ifdef COMPILE_PCRE16  #ifdef COMPILE_PCRE16
849  #error COMPILE_PCRE16 must not be set when compiling pcretest.c  #error COMPILE_PCRE16 must not be set when compiling pcretest.c
850  #endif  #endif
851    
852    #ifdef COMPILE_PCRE32
853    #error COMPILE_PCRE32 must not be set when compiling pcretest.c
854    #endif
855    
856  #if LINK_SIZE == 2  #if LINK_SIZE == 2
857  #undef LINK_SIZE  #undef LINK_SIZE
858  #define LINK_SIZE 1  #define LINK_SIZE 1
# Line 681  COMPILE_PCRE16 is *not* set. */ Line 866  COMPILE_PCRE16 is *not* set. */
866  #undef IMM2_SIZE  #undef IMM2_SIZE
867  #define IMM2_SIZE 1  #define IMM2_SIZE 1
868    
869  #endif /* SUPPORT_PCRE8 */  #endif /* SUPPORT_PCRE8 && (SUPPORT_PCRE16 || SUPPORT_PCRE32) */
870    
871    #ifdef SUPPORT_PCRE16
872    static int buffer16_size = 0;
873    static pcre_uint16 *buffer16 = NULL;
874  static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };  static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };
875  #endif  /* SUPPORT_PCRE16 */  #endif  /* SUPPORT_PCRE16 */
876    
877  /* If we have 8-bit support, default use_pcre16 to false; if there is also  #ifdef SUPPORT_PCRE32
878  16-bit support, it can be changed by an option. If there is no 8-bit support,  static int buffer32_size = 0;
879  there must be 16-bit support, so default it to 1. */  static pcre_uint32 *buffer32 = NULL;
880    static const pcre_uint32 OP_lengths32[] = { OP_LENGTHS };
881    #endif  /* SUPPORT_PCRE32 */
882    
883    /* If we have 8-bit support, default to it; if there is also
884    16-or 32-bit support, it can be changed by an option. If there is no 8-bit support,
885    there must be 16-or 32-bit support, so default it to 1. */
886    
887  #ifdef SUPPORT_PCRE8  #if defined SUPPORT_PCRE8
888  static int use_pcre16 = 0;  static int pcre_mode = PCRE8_MODE;
889  #else  #elif defined SUPPORT_PCRE16
890  static int use_pcre16 = 1;  static int pcre_mode = PCRE16_MODE;
891    #elif defined SUPPORT_PCRE32
892    static int pcre_mode = PCRE32_MODE;
893  #endif  #endif
894    
895  /* JIT study options for -s+n and /S+n where '1' <= n <= '7'. */  /* JIT study options for -s+n and /S+n where '1' <= n <= '7'. */
# Line 1144  return (pcre_jit_stack *)arg; Line 1340  return (pcre_jit_stack *)arg;
1340  }  }
1341    
1342    
1343  #if !defined NOUTF || defined SUPPORT_PCRE16  #if !defined NOUTF || defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32
1344  /*************************************************  /*************************************************
1345  *            Convert UTF-8 string to value       *  *            Convert UTF-8 string to value       *
1346  *************************************************/  *************************************************/
# Line 1204  return i+1; Line 1400  return i+1;
1400    
1401    
1402    
1403  #if !defined NOUTF || defined SUPPORT_PCRE16  #if !defined NOUTF || defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32
1404  /*************************************************  /*************************************************
1405  *       Convert character value to UTF-8         *  *       Convert character value to UTF-8         *
1406  *************************************************/  *************************************************/
# Line 1316  return pp - buffer16; Line 1512  return pp - buffer16;
1512  }  }
1513  #endif  #endif
1514    
1515    #ifdef SUPPORT_PCRE32
1516    /*************************************************
1517    *         Convert a string to 32-bit             *
1518    *************************************************/
1519    
1520    /* In non-UTF mode, the space needed for a 32-bit string is exactly four times the
1521    8-bit size. For a UTF-8 string, the size needed for UTF-32 is no more than four
1522    times, because up to 0xffff uses no more than 3 bytes in UTF-8 but possibly 4
1523    in UTF-32. Higher values use 4 bytes in UTF-8 and up to 4 bytes in UTF-32. The
1524    result is always left in buffer32.
1525    
1526    Note that this function does not object to surrogate values. This is
1527    deliberate; it makes it possible to construct UTF-32 strings that are invalid,
1528    for the purpose of testing that they are correctly faulted.
1529    
1530    Patterns to be converted are either plain ASCII or UTF-8; data lines are always
1531    in UTF-8 so that values greater than 255 can be handled.
1532    
1533    Arguments:
1534      data       TRUE if converting a data line; FALSE for a regex
1535      p          points to a byte string
1536      utf        true if UTF-8 (to be converted to UTF-32)
1537      len        number of bytes in the string (excluding trailing zero)
1538    
1539    Returns:     number of 32-bit data items used (excluding trailing zero)
1540                 OR -1 if a UTF-8 string is malformed
1541                 OR -2 if a value > 0x10ffff is encountered
1542                 OR -3 if an ill-formed value is encountered (i.e. a surrogate)
1543    */
1544    
1545    static int
1546    to32(int data, pcre_uint8 *p, int utf, int len)
1547    {
1548    pcre_uint32 *pp;
1549    
1550    if (buffer32_size < 4*len + 4)
1551      {
1552      if (buffer32 != NULL) free(buffer32);
1553      buffer32_size = 4*len + 4;
1554      buffer32 = (pcre_uint32 *)malloc(buffer32_size);
1555      if (buffer32 == NULL)
1556        {
1557        fprintf(stderr, "pcretest: malloc(%d) failed for buffer32\n", buffer32_size);
1558        exit(1);
1559        }
1560      }
1561    
1562    pp = buffer32;
1563    
1564    if (!utf && !data)
1565      {
1566      while (len-- > 0) *pp++ = *p++;
1567      }
1568    
1569    else
1570      {
1571      int c = 0;
1572      while (len > 0)
1573        {
1574        int chlen = utf82ord(p, &c);
1575        if (chlen <= 0) return -1;
1576        if (utf)
1577          {
1578          if (c > 0x10ffff) return -2;
1579          if (!data && (c & 0xfffff800u) == 0xd800u) return -3;
1580          }
1581    
1582        p += chlen;
1583        len -= chlen;
1584        *pp++ = c;
1585        }
1586      }
1587    
1588    *pp = 0;
1589    return pp - buffer32;
1590    }
1591    #endif
1592    
1593  /*************************************************  /*************************************************
1594  *        Read or extend an input line            *  *        Read or extend an input line            *
# Line 1542  return len; Line 1815  return len;
1815  #endif  /* SUPPORT_PCRE16 */  #endif  /* SUPPORT_PCRE16 */
1816    
1817    
1818    
1819    #ifdef SUPPORT_PCRE32
1820    /*************************************************
1821    *    Find length of 0-terminated 32-bit string   *
1822    *************************************************/
1823    
1824    static int strlen32(PCRE_SPTR32 p)
1825    {
1826    int len = 0;
1827    while (*p++ != 0) len++;
1828    return len;
1829    }
1830    #endif  /* SUPPORT_PCRE32 */
1831    
1832    
1833    
1834  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
1835  /*************************************************  /*************************************************
1836  *           Print 16-bit character string        *  *           Print 16-bit character string        *
# Line 1581  return yield; Line 1870  return yield;
1870    
1871    
1872    
1873    #ifdef SUPPORT_PCRE32
1874    /*************************************************
1875    *           Print 32-bit character string        *
1876    *************************************************/
1877    
1878    /* Must handle UTF-32 strings in utf mode. Yields number of characters printed.
1879    If handed a NULL file, just counts chars without printing. */
1880    
1881    static int pchars32(PCRE_SPTR32 p, int length, FILE *f)
1882    {
1883    int yield = 0;
1884    
1885    if (length < 0)
1886      length = strlen32(p);
1887    
1888    while (length-- > 0)
1889      {
1890      int c = *p++;
1891      yield += pchar(c, f);
1892      }
1893    
1894    return yield;
1895    }
1896    #endif  /* SUPPORT_PCRE32 */
1897    
1898    
1899    
1900  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
1901  /*************************************************  /*************************************************
1902  *     Read a capture name (8-bit) and check it   *  *     Read a capture name (8-bit) and check it   *
# Line 1634  return p; Line 1950  return p;
1950    
1951    
1952    
1953    #ifdef SUPPORT_PCRE32
1954    /*************************************************
1955    *     Read a capture name (32-bit) and check it  *
1956    *************************************************/
1957    
1958    /* Note that the text being read is 8-bit. */
1959    
1960    static pcre_uint8 *
1961    read_capture_name32(pcre_uint8 *p, pcre_uint32 **pp, pcre *re)
1962    {
1963    pcre_uint32 *npp = *pp;
1964    while (isalnum(*p)) *npp++ = *p++;
1965    *npp++ = 0;
1966    *npp = 0;
1967    if (pcre32_get_stringnumber((pcre32 *)re, (PCRE_SPTR32)(*pp)) < 0)
1968      {
1969      fprintf(outfile, "no parentheses with name \"");
1970      PCHARSV(*pp, 0, -1, outfile);
1971      fprintf(outfile, "\"\n");
1972      }
1973    *pp = npp;
1974    return p;
1975    }
1976    #endif  /* SUPPORT_PCRE32 */
1977    
1978    
1979    
1980  /*************************************************  /*************************************************
1981  *              Callout function                  *  *              Callout function                  *
1982  *************************************************/  *************************************************/
# Line 1791  free(block); Line 2134  free(block);
2134  *************************************************/  *************************************************/
2135    
2136  /* Get one piece of information from the pcre_fullinfo() function. When only  /* Get one piece of information from the pcre_fullinfo() function. When only
2137  one of 8-bit or 16-bit is supported, use_pcre16 should always have the correct  one of 8-, 16- or 32-bit is supported, pcre_mode should always have the correct
2138  value, but the code is defensive.  value, but the code is defensive.
2139    
2140  Arguments:  Arguments:
# Line 1808  new_info(pcre *re, pcre_extra *study, in Line 2151  new_info(pcre *re, pcre_extra *study, in
2151  {  {
2152  int rc;  int rc;
2153    
2154  if (use_pcre16)  if (pcre_mode == PCRE32_MODE)
2155    #ifdef SUPPORT_PCRE32
2156      rc = pcre32_fullinfo((pcre32 *)re, (pcre32_extra *)study, option, ptr);
2157    #else
2158      rc = PCRE_ERROR_BADMODE;
2159    #endif
2160    else if (pcre_mode == PCRE16_MODE)
2161  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2162    rc = pcre16_fullinfo((pcre16 *)re, (pcre16_extra *)study, option, ptr);    rc = pcre16_fullinfo((pcre16 *)re, (pcre16_extra *)study, option, ptr);
2163  #else  #else
# Line 1824  else Line 2173  else
2173  if (rc < 0)  if (rc < 0)
2174    {    {
2175    fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,    fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
2176      use_pcre16? "16" : "", option);      pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "", option);
2177    if (rc == PCRE_ERROR_BADMODE)    if (rc == PCRE_ERROR_BADMODE)
2178      fprintf(outfile, "Running in %s-bit mode but pattern was compiled in "      fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
2179        "%s-bit mode\n", use_pcre16? "16":"8", use_pcre16? "8":"16");        "%d-bit mode\n", 8 * CHAR_SIZE,
2180          8 * (REAL_PCRE_FLAGS(re) & PCRE_MODE_MASK));
2181    }    }
2182    
2183  return rc;  return rc;
# Line 1876  bytes in the pattern itself. This is to Line 2226  bytes in the pattern itself. This is to
2226  ability to reload byte-flipped patterns, e.g. those compiled on a different  ability to reload byte-flipped patterns, e.g. those compiled on a different
2227  architecture. */  architecture. */
2228    
2229    #if defined SUPPORT_PCRE8 || defined SUPPORT_PCRE16
2230  static void  static void
2231  regexflip(pcre *ere, pcre_extra *extra)  regexflip8_or_16(pcre *ere, pcre_extra *extra)
2232  {  {
2233  REAL_PCRE *re = (REAL_PCRE *)ere;  real_pcre8_or_16 *re = (real_pcre8_or_16 *)ere;
2234  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2235  int op;  int op;
2236  pcre_uint16 *ptr = (pcre_uint16 *)re + re->name_table_offset;  pcre_uint16 *ptr = (pcre_uint16 *)re + re->name_table_offset;
# Line 1916  if (extra != NULL) Line 2267  if (extra != NULL)
2267  in the name table, if present, and then in the pattern itself. */  in the name table, if present, and then in the pattern itself. */
2268    
2269  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2270  if (!use_pcre16) return;  if (pcre_mode != PCRE16_MODE) return;
2271    
2272  while(TRUE)  while(TRUE)
2273    {    {
# Line 2054  while(TRUE) Line 2405  while(TRUE)
2405  /* Control should never reach here in 16 bit mode. */  /* Control should never reach here in 16 bit mode. */
2406  #endif /* SUPPORT_PCRE16 */  #endif /* SUPPORT_PCRE16 */
2407  }  }
2408    #endif /* SUPPORT_PCRE[8|16] */
2409    
2410    
2411    
2412    #if defined SUPPORT_PCRE32
2413    static void
2414    regexflip_32(pcre *ere, pcre_extra *extra)
2415    {
2416    real_pcre32 *re = (real_pcre32 *)ere;
2417    int op;
2418    pcre_uint32 *ptr = (pcre_uint32 *)re + re->name_table_offset;
2419    int length = re->name_count * re->name_entry_size;
2420    #ifdef SUPPORT_UTF
2421    BOOL utf = (re->options & PCRE_UTF32) != 0;
2422    #endif /* SUPPORT_UTF */
2423    
2424    /* Always flip the bytes in the main data block and study blocks. */
2425    
2426    re->magic_number = REVERSED_MAGIC_NUMBER;
2427    re->size = swap_uint32(re->size);
2428    re->options = swap_uint32(re->options);
2429    re->flags = swap_uint16(re->flags);
2430    re->top_bracket = swap_uint16(re->top_bracket);
2431    re->top_backref = swap_uint16(re->top_backref);
2432    re->first_char = swap_uint32(re->first_char);
2433    re->req_char = swap_uint32(re->req_char);
2434    re->name_table_offset = swap_uint16(re->name_table_offset);
2435    re->name_entry_size = swap_uint16(re->name_entry_size);
2436    re->name_count = swap_uint16(re->name_count);
2437    
2438    if (extra != NULL)
2439      {
2440      pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);
2441      rsd->size = swap_uint32(rsd->size);
2442      rsd->flags = swap_uint32(rsd->flags);
2443      rsd->minlength = swap_uint32(rsd->minlength);
2444      }
2445    
2446    /* In 32-bit mode we must swap bytes
2447    in the name table, if present, and then in the pattern itself. */
2448    
2449    while(TRUE)
2450      {
2451      /* Swap previous characters. */
2452      while (length-- > 0)
2453        {
2454        *ptr = swap_uint32(*ptr);
2455        ptr++;
2456        }
2457    
2458      /* Get next opcode. */
2459    
2460      length = 0;
2461      op = *ptr;
2462      *ptr++ = swap_uint32(op);
2463    
2464      switch (op)
2465        {
2466        case OP_END:
2467        return;
2468    
2469        default:
2470        length = OP_lengths32[op] - 1;
2471        break;
2472    
2473        case OP_CLASS:
2474        case OP_NCLASS:
2475        /* Skip the character bit map. */
2476        ptr += 32/sizeof(pcre_uint32);
2477        length = 0;
2478        break;
2479    
2480        case OP_XCLASS:
2481        /* LINK_SIZE can only be 1 in 32-bit mode. */
2482        length = (int)((unsigned int)(ptr[0]) - (1 + LINK_SIZE + 1));
2483    
2484        /* Reverse the size of the XCLASS instance. */
2485        *ptr = swap_uint32(*ptr);
2486        ptr++;
2487    
2488        op = *ptr;
2489        *ptr = swap_uint32(op);
2490        ptr++;
2491        if ((op & XCL_MAP) != 0)
2492          {
2493          /* Skip the character bit map. */
2494          ptr += 32/sizeof(pcre_uint32);
2495          length -= 32/sizeof(pcre_uint32);
2496          }
2497        break;
2498        }
2499      }
2500    /* Control should never reach here in 32 bit mode. */
2501    }
2502    
2503    #endif /* SUPPORT_PCRE32 */
2504    
2505    
2506    
2507    static void
2508    regexflip(pcre *ere, pcre_extra *extra)
2509    {
2510    #if defined SUPPORT_PCRE32
2511      if (REAL_PCRE_FLAGS(ere) & PCRE_MODE32)
2512        regexflip_32(ere, extra);
2513    #endif
2514    #if defined SUPPORT_PCRE8 || defined SUPPORT_PCRE16
2515      if (REAL_PCRE_FLAGS(ere) & (PCRE_MODE8 | PCRE_MODE16))
2516        regexflip8_or_16(ere, extra);
2517    #endif
2518    }
2519    
2520    
2521    
# Line 2182  printf("\nOptions:\n"); Line 2644  printf("\nOptions:\n");
2644  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2645  printf("  -16      use the 16-bit library\n");  printf("  -16      use the 16-bit library\n");
2646  #endif  #endif
2647    #ifdef SUPPORT_PCRE32
2648    printf("  -32      use the 32-bit library\n");
2649    #endif
2650  printf("  -b       show compiled code\n");  printf("  -b       show compiled code\n");
2651  printf("  -C       show PCRE compile-time options and exit\n");  printf("  -C       show PCRE compile-time options and exit\n");
2652  printf("  -C arg   show a specific compile-time option\n");  printf("  -C arg   show a specific compile-time option\n");
# Line 2189  printf("           and exit with its val Line 2654  printf("           and exit with its val
2654  printf("     linksize     internal link size [2, 3, 4]\n");  printf("     linksize     internal link size [2, 3, 4]\n");
2655  printf("     pcre8        8 bit library support enabled [0, 1]\n");  printf("     pcre8        8 bit library support enabled [0, 1]\n");
2656  printf("     pcre16       16 bit library support enabled [0, 1]\n");  printf("     pcre16       16 bit library support enabled [0, 1]\n");
2657    printf("     pcre32       32 bit library support enabled [0, 1]\n");
2658  printf("     utf          Unicode Transformation Format supported [0, 1]\n");  printf("     utf          Unicode Transformation Format supported [0, 1]\n");
2659  printf("     ucp          Unicode Properties supported [0, 1]\n");  printf("     ucp          Unicode Properties supported [0, 1]\n");
2660  printf("     jit          Just-in-time compiler supported [0, 1]\n");  printf("     jit          Just-in-time compiler supported [0, 1]\n");
# Line 2266  pcre_jit_stack *jit_stack = NULL; Line 2732  pcre_jit_stack *jit_stack = NULL;
2732  /* These vectors store, end-to-end, a list of zero-terminated captured  /* These vectors store, end-to-end, a list of zero-terminated captured
2733  substring names, each list itself being terminated by an empty name. Assume  substring names, each list itself being terminated by an empty name. Assume
2734  that 1024 is plenty long enough for the few names we'll be testing. It is  that 1024 is plenty long enough for the few names we'll be testing. It is
2735  easiest to keep separate 8-bit and 16-bit versions, using the 16-bit version  easiest to keep separate 8-, 16- and 32-bit versions, using the 32-bit version
2736  for the actual memory, to ensure alignment. */  for the actual memory, to ensure alignment. */
2737    
2738  pcre_uint16 copynames[1024];  pcre_uint32 copynames[1024];
2739  pcre_uint16 getnames[1024];  pcre_uint32 getnames[1024];
2740    
2741    #ifdef SUPPORT_PCRE32
2742    pcre_uint32 *cn32ptr;
2743    pcre_uint32 *gn32ptr;
2744    #endif
2745    
2746  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2747    pcre_uint16 *copynames16 = (pcre_uint16 *)copynames;
2748    pcre_uint16 *getnames16 = (pcre_uint16 *)getnames;
2749  pcre_uint16 *cn16ptr;  pcre_uint16 *cn16ptr;
2750  pcre_uint16 *gn16ptr;  pcre_uint16 *gn16ptr;
2751  #endif  #endif
# Line 2285  pcre_uint8 *gn8ptr; Line 2758  pcre_uint8 *gn8ptr;
2758  #endif  #endif
2759    
2760  /* Get buffers from malloc() so that valgrind will check their misuse when  /* Get buffers from malloc() so that valgrind will check their misuse when
2761  debugging. They grow automatically when very long lines are read. The 16-bit  debugging. They grow automatically when very long lines are read. The 16-
2762  buffer (buffer16) is obtained only if needed. */  and 32-bit buffers (buffer16, buffer32) are obtained only if needed. */
2763    
2764  buffer = (pcre_uint8 *)malloc(buffer_size);  buffer = (pcre_uint8 *)malloc(buffer_size);
2765  dbuffer = (pcre_uint8 *)malloc(buffer_size);  dbuffer = (pcre_uint8 *)malloc(buffer_size);
# Line 2308  _setmode( _fileno( stdout ), _O_BINARY ) Line 2781  _setmode( _fileno( stdout ), _O_BINARY )
2781  /* Get the version number: both pcre_version() and pcre16_version() give the  /* Get the version number: both pcre_version() and pcre16_version() give the
2782  same answer. We just need to ensure that we call one that is available. */  same answer. We just need to ensure that we call one that is available. */
2783    
2784  #ifdef SUPPORT_PCRE8  #if defined SUPPORT_PCRE8
2785  version = pcre_version();  version = pcre_version();
2786  #else  #elif defined SUPPORT_PCRE16
2787  version = pcre16_version();  version = pcre16_version();
2788    #elif defined SUPPORT_PCRE32
2789    version = pcre32_version();
2790  #endif  #endif
2791    
2792  /* Scan options */  /* Scan options */
# Line 2338  while (argc > 1 && argv[op][0] == '-') Line 2813  while (argc > 1 && argv[op][0] == '-')
2813    else if (strcmp(arg, "-16") == 0)    else if (strcmp(arg, "-16") == 0)
2814      {      {
2815  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2816      use_pcre16 = 1;      pcre_mode = PCRE16_MODE;
2817  #else  #else
2818      printf("** This version of PCRE was built without 16-bit support\n");      printf("** This version of PCRE was built without 16-bit support\n");
2819      exit(1);      exit(1);
2820  #endif  #endif
2821      }      }
2822      else if (strcmp(arg, "-32") == 0)
2823        {
2824    #ifdef SUPPORT_PCRE32
2825        pcre_mode = PCRE32_MODE;
2826    #else
2827        printf("** This version of PCRE was built without 32-bit support\n");
2828        exit(1);
2829    #endif
2830        }
2831    else if (strcmp(arg, "-q") == 0) quiet = 1;    else if (strcmp(arg, "-q") == 0) quiet = 1;
2832    else if (strcmp(arg, "-b") == 0) debug = 1;    else if (strcmp(arg, "-b") == 0) debug = 1;
2833    else if (strcmp(arg, "-i") == 0) showinfo = 1;    else if (strcmp(arg, "-i") == 0) showinfo = 1;
# Line 2431  while (argc > 1 && argv[op][0] == '-') Line 2915  while (argc > 1 && argv[op][0] == '-')
2915          yield = 0;          yield = 0;
2916  #endif  #endif
2917          }          }
2918        else if (strcmp(argv[op + 1], "utf") == 0)        else if (strcmp(argv[op + 1], "pcre32") == 0)
2919          {          {
2920  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE32
2921          (void)pcre_config(PCRE_CONFIG_UTF8, &rc);          printf("1\n");
2922          printf("%d\n", rc);          yield = 1;
         yield = rc;  
2923  #else  #else
2924          (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);          printf("0\n");
2925            yield = 0;
2926    #endif
2927            goto EXIT;
2928            }
2929          if (strcmp(argv[op + 1], "utf") == 0)
2930            {
2931    #ifdef SUPPORT_PCRE8
2932            if (pcre_mode == PCRE8_MODE)
2933              (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
2934    #endif
2935    #ifdef SUPPORT_PCRE16
2936            if (pcre_mode == PCRE16_MODE)
2937              (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
2938    #endif
2939    #ifdef SUPPORT_PCRE32
2940            if (pcre_mode == PCRE32_MODE)
2941              (void)pcre32_config(PCRE_CONFIG_UTF32, &rc);
2942    #endif
2943          printf("%d\n", rc);          printf("%d\n", rc);
2944          yield = rc;          yield = rc;
2945  #endif          goto EXIT;
2946          }          }
2947        else if (strcmp(argv[op + 1], "ucp") == 0)        else if (strcmp(argv[op + 1], "ucp") == 0)
2948          {          {
# Line 2496  while (argc > 1 && argv[op][0] == '-') Line 2997  while (argc > 1 && argv[op][0] == '-')
2997  /* At least one of SUPPORT_PCRE8 and SUPPORT_PCRE16 will be set. If both  /* At least one of SUPPORT_PCRE8 and SUPPORT_PCRE16 will be set. If both
2998  are set, either both UTFs are supported or both are not supported. */  are set, either both UTFs are supported or both are not supported. */
2999    
3000  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE8
3001      printf("  8-bit and 16-bit support\n");      printf("  8-bit support\n");
     (void)pcre_config(PCRE_CONFIG_UTF8, &rc);  
     if (rc)  
       printf("  UTF-8 and UTF-16 support\n");  
     else  
       printf("  No UTF-8 or UTF-16 support\n");  
 #elif defined SUPPORT_PCRE8  
     printf("  8-bit support only\n");  
3002      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
3003      printf("  %sUTF-8 support\n", rc? "" : "No ");        printf ("  %sUTF-8 support\n", rc ? "" : "No ");
3004  #else  #endif
3005      printf("  16-bit support only\n");  #ifdef SUPPORT_PCRE16
3006        printf("  16-bit support\n");
3007      (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);      (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
3008      printf("  %sUTF-16 support\n", rc? "" : "No ");      printf ("  %sUTF-16 support\n", rc ? "" : "No ");
3009    #endif
3010    #ifdef SUPPORT_PCRE32
3011        printf("  32-bit support\n");
3012        (void)pcre32_config(PCRE_CONFIG_UTF32, &rc);
3013        printf ("  %sUTF-32 support\n", rc ? "" : "No ");
3014  #endif  #endif
3015    
3016      (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);      (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
# Line 2617  pcre16_stack_malloc = stack_malloc; Line 3117  pcre16_stack_malloc = stack_malloc;
3117  pcre16_stack_free = stack_free;  pcre16_stack_free = stack_free;
3118  #endif  #endif
3119    
3120    #ifdef SUPPORT_PCRE32
3121    pcre32_malloc = new_malloc;
3122    pcre32_free = new_free;
3123    pcre32_stack_malloc = stack_malloc;
3124    pcre32_stack_free = stack_free;
3125    #endif
3126    
3127  /* Heading line unless quiet, then prompt for first regex if stdin */  /* Heading line unless quiet, then prompt for first regex if stdin */
3128    
3129  if (!quiet) fprintf(outfile, "PCRE version %s\n\n", version);  if (!quiet) fprintf(outfile, "PCRE version %s\n\n", version);
# Line 2716  while (!done) Line 3223  while (!done)
3223    
3224      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;      if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;
3225    
3226      magic = ((REAL_PCRE *)re)->magic_number;      magic = REAL_PCRE_MAGIC(re);
3227      if (magic != MAGIC_NUMBER)      if (magic != MAGIC_NUMBER)
3228        {        {
3229        if (swap_uint32(magic) == MAGIC_NUMBER)        if (swap_uint32(magic) == MAGIC_NUMBER)
# Line 2774  while (!done) Line 3281  while (!done)
3281          {          {
3282          /* Simulate the result of the function call below. */          /* Simulate the result of the function call below. */
3283          fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,          fprintf(outfile, "Error %d from pcre%s_fullinfo(%d)\n", rc,
3284            use_pcre16? "16" : "", PCRE_INFO_OPTIONS);            pcre_mode == PCRE32_MODE ? "32" : pcre_mode == PCRE16_MODE ? "16" : "",
3285          fprintf(outfile, "Running in %s-bit mode but pattern was compiled in "            PCRE_INFO_OPTIONS);
3286            "%s-bit mode\n", use_pcre16? "16":"8", use_pcre16? "8":"16");          fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
3287              "%d-bit mode\n", 8 * CHAR_SIZE,
3288              8 * (REAL_PCRE_FLAGS(re) & PCRE_MODE_MASK));
3289          new_free(re);          new_free(re);
3290          fclose(f);          fclose(f);
3291          continue;          continue;
# Line 3040  while (!done) Line 3549  while (!done)
3549  #endif  /* !defined NOPOSIX */  #endif  /* !defined NOPOSIX */
3550    
3551      {      {
3552      /* In 16-bit mode, convert the input. */      /* In 16- or 32-bit mode, convert the input. */
3553    
3554  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3555      if (use_pcre16)      if (pcre_mode == PCRE16_MODE)
3556        {        {
3557        switch(to16(FALSE, p, options & PCRE_UTF8, (int)strlen((char *)p)))        switch(to16(FALSE, p, options & PCRE_UTF8, (int)strlen((char *)p)))
3558          {          {
# Line 3069  while (!done) Line 3578  while (!done)
3578        }        }
3579  #endif  #endif
3580    
3581    #ifdef SUPPORT_PCRE32
3582        if (pcre_mode == PCRE32_MODE)
3583          {
3584          switch(to32(FALSE, p, options & PCRE_UTF32, (int)strlen((char *)p)))
3585            {
3586            case -1:
3587            fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "
3588              "converted to UTF-32\n");
3589            goto SKIP_DATA;
3590    
3591            case -2:
3592            fprintf(outfile, "**Failed: character value greater than 0x10ffff "
3593              "cannot be converted to UTF-32\n");
3594            goto SKIP_DATA;
3595    
3596            case -3:
3597            fprintf(outfile, "**Failed: character value is ill-formed UTF-32\n");
3598            goto SKIP_DATA;
3599    
3600            default:
3601            break;
3602            }
3603          p = (pcre_uint8 *)buffer32;
3604          }
3605    #endif
3606    
3607      /* Compile many times when timing */      /* Compile many times when timing */
3608    
3609      if (timeit > 0)      if (timeit > 0)
# Line 3126  while (!done) Line 3661  while (!done)
3661      /* Extract the size for possible writing before possibly flipping it,      /* Extract the size for possible writing before possibly flipping it,
3662      and remember the store that was got. */      and remember the store that was got. */
3663    
3664      true_size = ((REAL_PCRE *)re)->size;      true_size = REAL_PCRE_SIZE(re);
3665      regex_gotten_store = first_gotten_store;      regex_gotten_store = first_gotten_store;
3666    
3667      /* Output code size information if requested */      /* Output code size information if requested */
3668    
3669      if (log_store)      if (log_store)
3670          {
3671          int name_count, name_entry_size, real_pcre_size;
3672    
3673          new_info(re, NULL, PCRE_INFO_NAMECOUNT, &name_count);
3674          new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);
3675    #ifdef SUPPORT_PCRE8
3676          if (REAL_PCRE_FLAGS(re) & PCRE_MODE8)
3677            real_pcre_size = sizeof(real_pcre);
3678    #endif
3679    #ifdef SUPPORT_PCRE16
3680          if (REAL_PCRE_FLAGS(re) & PCRE_MODE16)
3681            real_pcre_size = sizeof(real_pcre16);
3682    #endif
3683    #ifdef SUPPORT_PCRE32
3684          if (REAL_PCRE_FLAGS(re) & PCRE_MODE32)
3685            real_pcre_size = sizeof(real_pcre32);
3686    #endif
3687        fprintf(outfile, "Memory allocation (code space): %d\n",        fprintf(outfile, "Memory allocation (code space): %d\n",
3688          (int)(first_gotten_store -          (int)(first_gotten_store - real_pcre_size - name_count * name_entry_size));
3689                sizeof(REAL_PCRE) -        }
               ((REAL_PCRE *)re)->name_count * ((REAL_PCRE *)re)->name_entry_size));  
3690    
3691      /* 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
3692      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 3239  while (!done) Line 3790  while (!done)
3790          fprintf(outfile, "Named capturing subpatterns:\n");          fprintf(outfile, "Named capturing subpatterns:\n");
3791          while (namecount-- > 0)          while (namecount-- > 0)
3792            {            {
3793  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16            int imm2_size = pcre_mode == PCRE8_MODE ? 2 : 1;
           int imm2_size = use_pcre16 ? 1 : 2;  
 #else  
           int imm2_size = IMM2_SIZE;  
 #endif  
3794            int length = (int)STRLEN(nametable + imm2_size);            int length = (int)STRLEN(nametable + imm2_size);
3795            fprintf(outfile, "  ");            fprintf(outfile, "  ");
3796            PCHARSV(nametable, imm2_size, length, outfile);            PCHARSV(nametable, imm2_size, length, outfile);
3797            while (length++ < nameentrysize - imm2_size) putc(' ', outfile);            while (length++ < nameentrysize - imm2_size) putc(' ', outfile);
3798  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE32
3799            fprintf(outfile, "%3d\n", use_pcre16?            if (pcre_mode == PCRE32_MODE)
3800               (int)(((PCRE_SPTR16)nametable)[0])              fprintf(outfile, "%3d\n", (int)(((PCRE_SPTR32)nametable)[0]));
             :((int)nametable[0] << 8) | (int)nametable[1]);  
           nametable += nameentrysize * (use_pcre16 ? 2 : 1);  
 #else  
           fprintf(outfile, "%3d\n", GET2(nametable, 0));  
 #ifdef SUPPORT_PCRE8  
           nametable += nameentrysize;  
 #else  
           nametable += nameentrysize * 2;  
3801  #endif  #endif
3802    #ifdef SUPPORT_PCRE16
3803              if (pcre_mode == PCRE16_MODE)
3804                fprintf(outfile, "%3d\n", (int)(((PCRE_SPTR16)nametable)[0]));
3805    #endif
3806    #ifdef SUPPORT_PCRE8
3807              if (pcre_mode == PCRE8_MODE)
3808                fprintf(outfile, "%3d\n", ((int)nametable[0] << 8) | (int)nametable[1]);
3809  #endif  #endif
3810              nametable += nameentrysize * CHAR_SIZE;
3811            }            }
3812          }          }
3813    
3814        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");        if (!okpartial) fprintf(outfile, "Partial matching not supported\n");
3815        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");
3816    
3817        all_options = ((REAL_PCRE *)re)->options;        all_options = REAL_PCRE_OPTIONS(re);
3818        if (do_flip) all_options = swap_uint32(all_options);        if (do_flip) all_options = swap_uint32(all_options);
3819    
3820        if (get_options == 0) fprintf(outfile, "No options\n");        if (get_options == 0) fprintf(outfile, "No options\n");
# Line 3329  while (!done) Line 3876  while (!done)
3876        else        else
3877          {          {
3878          const char *caseless =          const char *caseless =
3879            ((((REAL_PCRE *)re)->flags & PCRE_FCH_CASELESS) == 0)?            ((REAL_PCRE_FLAGS(re) & PCRE_FCH_CASELESS) == 0)?
3880            "" : " (caseless)";            "" : " (caseless)";
3881    
3882          if (PRINTOK(first_char))          if (PRINTOK(first_char))
# Line 3349  while (!done) Line 3896  while (!done)
3896        else        else
3897          {          {
3898          const char *caseless =          const char *caseless =
3899            ((((REAL_PCRE *)re)->flags & PCRE_RCH_CASELESS) == 0)?            ((REAL_PCRE_FLAGS(re) & PCRE_RCH_CASELESS) == 0)?
3900            "" : " (caseless)";            "" : " (caseless)";
3901    
3902          if (PRINTOK(need_char))          if (PRINTOK(need_char))
# Line 3530  while (!done) Line 4077  while (!done)
4077      *copynames = 0;      *copynames = 0;
4078      *getnames = 0;      *getnames = 0;
4079    
4080    #ifdef SUPPORT_PCRE32
4081        cn32ptr = copynames;
4082        gn32ptr = getnames;
4083    #endif
4084  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
4085      cn16ptr = copynames;      cn16ptr = copynames16;
4086      gn16ptr = getnames;      gn16ptr = getnames16;
4087  #endif  #endif
4088  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
4089      cn8ptr = copynames8;      cn8ptr = copynames8;
# Line 3647  while (!done) Line 4198  while (!done)
4198          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
4199          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.
4200          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
4201          UTF-8 when running in 16-bit mode. */          UTF-8 when running in 16/32-bit mode. */
4202    
4203          c = 0;          c = 0;
4204          while (i++ < 2 && isxdigit(*p))          while (i++ < 2 && isxdigit(*p))
# Line 3692  while (!done) Line 4243  while (!done)
4243            }            }
4244          else if (isalnum(*p))          else if (isalnum(*p))
4245            {            {
4246            READ_CAPTURE_NAME(p, &cn8ptr, &cn16ptr, re);            READ_CAPTURE_NAME(p, &cn8ptr, &cn16ptr, &cn32ptr, re);
4247            }            }
4248          else if (*p == '+')          else if (*p == '+')
4249            {            {
# Line 3755  while (!done) Line 4306  while (!done)
4306            }            }
4307          else if (isalnum(*p))          else if (isalnum(*p))
4308            {            {
4309            READ_CAPTURE_NAME(p, &gn8ptr, &gn16ptr, re);            READ_CAPTURE_NAME(p, &gn8ptr, &gn16ptr, &gn32ptr, re);
4310            }            }
4311          continue;          continue;
4312    
# Line 3872  while (!done) Line 4423  while (!done)
4423        mode must have come from \x{...} or octal constructs because values from        mode must have come from \x{...} or octal constructs because values from
4424        \x.. get this far only in non-UTF mode. */        \x.. get this far only in non-UTF mode. */
4425    
4426  #if !defined NOUTF || defined SUPPORT_PCRE16  #if !defined NOUTF || defined SUPPORT_PCRE16 || defined SUPPORT_PCRE32
4427        if (use_pcre16 || use_utf)        if (pcre_mode != PCRE8_MODE || use_utf)
4428          {          {
4429          pcre_uint8 buff8[8];          pcre_uint8 buff8[8];
4430          int ii, utn;          int ii, utn;
# Line 3944  while (!done) Line 4495  while (!done)
4495          (void)regerror(rc, &preg, (char *)buffer, buffer_size);          (void)regerror(rc, &preg, (char *)buffer, buffer_size);
4496          fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer);          fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer);
4497          }          }
4498        else if ((((const pcre *)preg.re_pcre)->options & PCRE_NO_AUTO_CAPTURE)        else if ((REAL_PCRE_OPTIONS(preg.re_pcre) & PCRE_NO_AUTO_CAPTURE) != 0)
               != 0)  
4499          {          {
4500          fprintf(outfile, "Matched with REG_NOSUB\n");          fprintf(outfile, "Matched with REG_NOSUB\n");
4501          }          }
# Line 3979  while (!done) Line 4529  while (!done)
4529      /* Handle matching via the native interface - repeats for /g and /G */      /* Handle matching via the native interface - repeats for /g and /G */
4530    
4531  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
4532      if (use_pcre16)      if (pcre_mode == PCRE16_MODE)
4533        {        {
4534        len = to16(TRUE, bptr, (((REAL_PCRE *)re)->options) & PCRE_UTF8, len);        len = to16(TRUE, bptr, REAL_PCRE_OPTIONS(re) & PCRE_UTF8, len);
4535        switch(len)        switch(len)
4536          {          {
4537          case -1:          case -1:
# Line 4006  while (!done) Line 4556  while (!done)
4556        }        }
4557  #endif  #endif
4558    
4559    #ifdef SUPPORT_PCRE32
4560        if (pcre_mode == PCRE32_MODE)
4561          {
4562          len = to32(TRUE, bptr, REAL_PCRE_OPTIONS(re) & PCRE_UTF32, len);
4563          switch(len)
4564            {
4565            case -1:
4566            fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "
4567              "converted to UTF-32\n");
4568            goto NEXT_DATA;
4569    
4570            case -2:
4571            fprintf(outfile, "**Failed: character value greater than 0x10ffff "
4572              "cannot be converted to UTF-32\n");
4573            goto NEXT_DATA;
4574    
4575            case -3:
4576            fprintf(outfile, "**Failed: character value is ill-formed UTF-32\n");
4577            goto NEXT_DATA;
4578    
4579            default:
4580            break;
4581            }
4582          bptr = (pcre_uint8 *)buffer32;
4583          }
4584    #endif
4585    
4586      /* Ensure that there is a JIT callback if we want to verify that JIT was      /* Ensure that there is a JIT callback if we want to verify that JIT was
4587      actually used. If jit_stack == NULL, no stack has yet been assigned. */      actually used. If jit_stack == NULL, no stack has yet been assigned. */
4588    
# Line 4227  while (!done) Line 4804  while (!done)
4804            int rc;            int rc;
4805            char copybuffer[256];            char copybuffer[256];
4806    
4807            if (use_pcre16)            if (pcre_mode == PCRE16_MODE)
4808              {              {
4809              if (*(pcre_uint16 *)cnptr == 0) break;              if (*(pcre_uint16 *)cnptr == 0) break;
4810              }              }
# Line 4282  while (!done) Line 4859  while (!done)
4859            int rc;            int rc;
4860            const char *substring;            const char *substring;
4861    
4862            if (use_pcre16)            if (pcre_mode == PCRE16_MODE)
4863              {              {
4864              if (*(pcre_uint16 *)gnptr == 0) break;              if (*(pcre_uint16 *)gnptr == 0) break;
4865              }              }
# Line 4376  while (!done) Line 4953  while (!done)
4953          if (g_notempty != 0)          if (g_notempty != 0)
4954            {            {
4955            int onechar = 1;            int onechar = 1;
4956            unsigned int obits = ((REAL_PCRE *)re)->options;            unsigned int obits = REAL_PCRE_OPTIONS(re);
4957            use_offsets[0] = start_offset;            use_offsets[0] = start_offset;
4958            if ((obits & PCRE_NEWLINE_BITS) == 0)            if ((obits & PCRE_NEWLINE_BITS) == 0)
4959              {              {
# Line 4394  while (!done) Line 4971  while (!done)
4971                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||
4972                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)
4973                &&                &&
4974                start_offset < len - 1 &&                start_offset < len - 1 && (
4975  #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16  #ifdef SUPPORT_PCRE8
4976                (use_pcre16?                (pcre_mode == PCRE8_MODE &&
4977                     ((PCRE_SPTR16)bptr)[start_offset] == '\r'                 bptr[start_offset] == '\r' &&
4978                  && ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n'                 bptr[start_offset + 1] == '\n') ||
               :  
                    bptr[start_offset] == '\r'  
                 && bptr[start_offset + 1] == '\n')  
 #elif defined SUPPORT_PCRE16  
                  ((PCRE_SPTR16)bptr)[start_offset] == '\r'  
               && ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n'  
 #else  
                  bptr[start_offset] == '\r'  
               && bptr[start_offset + 1] == '\n'  
4979  #endif  #endif
4980                )  #ifdef SUPPORT_PCRE16
4981                  (pcre_mode == PCRE16_MODE &&
4982                   ((PCRE_SPTR16)bptr)[start_offset] == '\r' &&
4983                   ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n') ||
4984    #endif
4985    #ifdef SUPPORT_PCRE32
4986                  (pcre_mode == PCRE32_MODE &&
4987                   ((PCRE_SPTR32)bptr)[start_offset] == '\r' &&
4988                   ((PCRE_SPTR32)bptr)[start_offset + 1] == '\n') ||
4989    #endif
4990                  0))
4991              onechar++;              onechar++;
4992            else if (use_utf)            else if (use_utf)
4993              {              {
# Line 4444  while (!done) Line 5022  while (!done)
5022    
5023              case PCRE_ERROR_BADUTF8:              case PCRE_ERROR_BADUTF8:
5024              case PCRE_ERROR_SHORTUTF8:              case PCRE_ERROR_SHORTUTF8:
5025              fprintf(outfile, "Error %d (%s UTF-%s string)", count,              fprintf(outfile, "Error %d (%s UTF-%d string)", count,
5026                (count == PCRE_ERROR_BADUTF8)? "bad" : "short",                (count == PCRE_ERROR_BADUTF8)? "bad" : "short",
5027                use_pcre16? "16" : "8");                8 * CHAR_SIZE);
5028              if (use_size_offsets >= 2)              if (use_size_offsets >= 2)
5029                fprintf(outfile, " offset=%d reason=%d", use_offsets[0],                fprintf(outfile, " offset=%d reason=%d", use_offsets[0],
5030                  use_offsets[1]);                  use_offsets[1]);
# Line 4454  while (!done) Line 5032  while (!done)
5032              break;              break;
5033    
5034              case PCRE_ERROR_BADUTF8_OFFSET:              case PCRE_ERROR_BADUTF8_OFFSET:
5035              fprintf(outfile, "Error %d (bad UTF-%s offset)\n", count,              fprintf(outfile, "Error %d (bad UTF-%d offset)\n", count,
5036                use_pcre16? "16" : "8");                8 * CHAR_SIZE);
5037              break;              break;
5038    
5039              default:              default:
# Line 4545  free(offsets); Line 5123  free(offsets);
5123  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
5124  if (buffer16 != NULL) free(buffer16);  if (buffer16 != NULL) free(buffer16);
5125  #endif  #endif
5126    #ifdef SUPPORT_PCRE32
5127    if (buffer32 != NULL) free(buffer32);
5128    #endif
5129    
5130  #if !defined NODFA  #if !defined NODFA
5131  if (dfa_workspace != NULL)  if (dfa_workspace != NULL)

Legend:
Removed from v.1046  
changed lines
  Added in v.1055

  ViewVC Help
Powered by ViewVC 1.1.5