/[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 850 by zherczeg, Wed Jan 4 17:29:11 2012 UTC revision 852 by zherczeg, Thu Jan 5 19:18:12 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 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 288  argument, the casting might be incorrect Line 296  argument, the casting might be incorrect
296  #define SET_PCRE_CALLOUT16(callout) \  #define SET_PCRE_CALLOUT16(callout) \
297    pcre16_callout = (int (*)(pcre16_callout_block *))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_SCHAR16 *)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, \
# Line 303  argument, the casting might be incorrect Line 315  argument, the casting might be incorrect
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, (pcre16_extra *)extra, (PCRE_SPTR16)bptr, len, \    count = pcre16_dfa_exec((pcre16 *)re, (pcre16_extra *)extra, \
319      start_offset, 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, (pcre16_extra *)extra, (PCRE_SPTR16)bptr, len, \    count = pcre16_exec((pcre16 *)re, (pcre16_extra *)extra, (PCRE_SPTR16)bptr, \
325      start_offset, 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((pcre16_extra *)extra)    pcre16_free_study((pcre16_extra *)extra)
# 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 337  argument, the casting might be incorrect Line 350  argument, the casting might be incorrect
350      (PCRE_SPTR16 **)(void*)listptr)      (PCRE_SPTR16 **)(void*)listptr)
351    
352  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables) \  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER16(rc, re, extra, tables) \
353    rc = pcre16_pattern_to_host_byte_order(re, (pcre16_extra *)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 = (pcre_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())
# 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 1513  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 1702  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, (pcre16_extra *)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 1771  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 2553  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 2938  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 2946  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 3078  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 3140  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 3160  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 3563  while (!done) Line 3595  while (!done)
3595              && (extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0              && (extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0
3596              && extra->executable_jit != NULL)              && extra->executable_jit != NULL)
3597            {            {
3598            if (jit_stack != NULL) PCRE_JIT_STACK_FREE(jit_stack);            if (jit_stack != NULL) { PCRE_JIT_STACK_FREE(jit_stack); }
3599            jit_stack = PCRE_JIT_STACK_ALLOC(1, n * 1024);            jit_stack = PCRE_JIT_STACK_ALLOC(1, n * 1024);
3600            PCRE_ASSIGN_JIT_STACK(extra, jit_callback, jit_stack);            PCRE_ASSIGN_JIT_STACK(extra, jit_callback, jit_stack);
3601            }            }
# Line 3778  while (!done) Line 3810  while (!done)
3810  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3811      if (use_pcre16)      if (use_pcre16)
3812        {        {
3813        len = to16(TRUE, bptr, (((real_pcre *)re)->options) & PCRE_UTF8, len);        len = to16(TRUE, bptr, (((REAL_PCRE *)re)->options) & PCRE_UTF8, len);
3814        switch(len)        switch(len)
3815          {          {
3816          case -1:          case -1:
# Line 4158  while (!done) Line 4190  while (!done)
4190          if (g_notempty != 0)          if (g_notempty != 0)
4191            {            {
4192            int onechar = 1;            int onechar = 1;
4193            unsigned int obits = ((real_pcre *)re)->options;            unsigned int obits = ((REAL_PCRE *)re)->options;
4194            use_offsets[0] = start_offset;            use_offsets[0] = start_offset;
4195            if ((obits & PCRE_NEWLINE_BITS) == 0)            if ((obits & PCRE_NEWLINE_BITS) == 0)
4196              {              {

Legend:
Removed from v.850  
changed lines
  Added in v.852

  ViewVC Help
Powered by ViewVC 1.1.5