/[pcre]/code/branches/pcre16/pcretest.c
ViewVC logotype

Diff of /code/branches/pcre16/pcretest.c

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

revision 813 by ph10, Tue Dec 20 14:03:16 2011 UTC revision 814 by ph10, Wed Dec 21 12:05:24 2011 UTC
# Line 191  use these in the definitions of generic Line 191  use these in the definitions of generic
191  #define PCRE_COMPILE8(re, pat, options, error, erroffset, tables) \  #define PCRE_COMPILE8(re, pat, options, error, erroffset, tables) \
192    re = pcre_compile((char *)pat, options, error, erroffset, tables)    re = pcre_compile((char *)pat, options, error, erroffset, tables)
193    
194    #define PCRE_DFA_EXEC8(count, re, extra, bptr, len, start_offset, options, \
195        offsets, size_offsets, workspace, size_workspace) \
196      count = pcre_dfa_exec(re, extra, (char *)bptr, len, start_offset, options, \
197        offsets, size_offsets, workspace, size_workspace)
198    
199  #define PCRE_EXEC8(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_EXEC8(count, re, extra, bptr, len, start_offset, options, \
200      offsets, size_offsets) \      offsets, size_offsets) \
201    count = pcre_exec(re, extra, (char *)bptr, len, start_offset, options, \    count = pcre_exec(re, extra, (char *)bptr, len, start_offset, options, \
# Line 219  use these in the definitions of generic Line 224  use these in the definitions of generic
224  #define PCRE_COMPILE16(re, pat, options, error, erroffset, tables) \  #define PCRE_COMPILE16(re, pat, options, error, erroffset, tables) \
225    re = pcre16_compile((PCRE_SPTR16)pat, options, error, erroffset, tables)    re = pcre16_compile((PCRE_SPTR16)pat, options, error, erroffset, tables)
226    
227  #define PCRE_FREE_STUDY16(extra) \  #define PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \
228    pcre16_free_study(extra)      offsets, size_offsets, workspace, size_workspace) \
229      count = pcre16_dfa_exec(re, extra, (PCRE_SPTR16)bptr, len, start_offset, \
230        options, offsets, size_offsets, workspace, size_workspace)
231    
232  #define PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \
233      offsets, size_offsets) \      offsets, size_offsets) \
234    count = pcre16_exec(re, extra, (PCRE_SPTR16)bptr, len, start_offset, \    count = pcre16_exec(re, extra, (PCRE_SPTR16)bptr, len, start_offset, \
235      options, offsets, size_offsets)      options, offsets, size_offsets)
236    
237    #define PCRE_FREE_STUDY16(extra) \
238      pcre16_free_study(extra)
239    
240  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER16(re, extra, tables) \  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER16(re, extra, tables) \
241    pcre16_pattern_to_host_byte_order(re, extra, tables)    pcre16_pattern_to_host_byte_order(re, extra, tables)
242    
# Line 258  use these in the definitions of generic Line 268  use these in the definitions of generic
268    else \    else \
269      PCRE_COMPILE8(re, pat, options, error, erroffset, tables)      PCRE_COMPILE8(re, pat, options, error, erroffset, tables)
270    
271  #define PCRE_FREE_STUDY(extra) \  #define PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset, options, \
272        offsets, size_offsets, workspace, size_workspace) \
273    if (use_pcre16) \    if (use_pcre16) \
274      PCRE_FREE_STUDY16(extra); \      PCRE_DFA_EXEC16(count, re, extra, bptr, len, start_offset, options, \
275          offsets, size_offsets, workspace, size_workspace); \
276    else \    else \
277      PCRE_FREE_STUDY8(extra)      PCRE_DFA_EXEC8(count, re, extra, bptr, len, start_offset, options, \
278          offsets, size_offsets, workspace, size_workspace)
279    
280  #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
281      offsets, size_offsets) \      offsets, size_offsets) \
# Line 273  use these in the definitions of generic Line 286  use these in the definitions of generic
286      PCRE_EXEC8(count, re, extra, bptr, len, start_offset, options, \      PCRE_EXEC8(count, re, extra, bptr, len, start_offset, options, \
287        offsets, size_offsets)        offsets, size_offsets)
288    
289    #define PCRE_FREE_STUDY(extra) \
290      if (use_pcre16) \
291        PCRE_FREE_STUDY16(extra); \
292      else \
293        PCRE_FREE_STUDY8(extra)
294    
295  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(re, extra, tables) \  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(re, extra, tables) \
296    if (use_pcre16) \    if (use_pcre16) \
297      PCRE_PATTERN_TO_HOST_BYTE_ORDER16(re, extra, tables); \      PCRE_PATTERN_TO_HOST_BYTE_ORDER16(re, extra, tables); \
# Line 291  use these in the definitions of generic Line 310  use these in the definitions of generic
310  #define PCHARS           PCHARS8  #define PCHARS           PCHARS8
311  #define PCHARSV          PCHARSV8  #define PCHARSV          PCHARSV8
312  #define PCRE_COMPILE     PCRE_COMPILE8  #define PCRE_COMPILE     PCRE_COMPILE8
313    #define PCRE_DFA_EXEC    PCRE_DFA_EXEC8
314  #define PCRE_EXEC        PCRE_EXEC8  #define PCRE_EXEC        PCRE_EXEC8
315  #define PCRE_FREE_STUDY  PCRE_FREE_STUDY8  #define PCRE_FREE_STUDY  PCRE_FREE_STUDY8
316  #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
# Line 302  use these in the definitions of generic Line 322  use these in the definitions of generic
322  #define PCHARS           PCHARS16  #define PCHARS           PCHARS16
323  #define PCHARSV          PCHARSV16  #define PCHARSV          PCHARSV16
324  #define PCRE_COMPILE     PCRE_COMPILE16  #define PCRE_COMPILE     PCRE_COMPILE16
325    #define PCRE_DFA_EXEC    PCRE_DFA_EXEC16
326  #define PCRE_EXEC        PCRE_EXEC16  #define PCRE_EXEC        PCRE_EXEC16
327  #define PCRE_FREE_STUDY  PCRE_FREE_STUDY16  #define PCRE_FREE_STUDY  PCRE_FREE_STUDY16
328  #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
# Line 349  static pcre_uint8 *buffer = NULL; Line 370  static pcre_uint8 *buffer = NULL;
370  static pcre_uint8 *dbuffer = NULL;  static pcre_uint8 *dbuffer = NULL;
371  static pcre_uint8 *pbuffer = NULL;  static pcre_uint8 *pbuffer = NULL;
372    
373  /* Another buffer is needed translation to 16-bit character strings. It will  /* Another buffer is needed translation to 16-bit character strings. It will
374  obtained and extended as required. */  obtained and extended as required. */
375    
376  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
377  static int buffer16_size = 0;  static int buffer16_size = 0;
378  static pcre_uint16 *buffer16 = NULL;  static pcre_uint16 *buffer16 = NULL;
379    
380  /* 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-bit compiling, in
381  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
382  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
383  appropriately for the 16-bit world. Just as a safety check, make sure that  appropriately for the 16-bit world. Just as a safety check, make sure that
# Line 1404  return (value >> 8) | (value << 8); Line 1425  return (value >> 8) | (value << 8);
1425  *        Flip bytes in a compiled pattern        *  *        Flip bytes in a compiled pattern        *
1426  *************************************************/  *************************************************/
1427    
1428  /* This function is called if the 'F' option was present on a pattern that is  /* This function is called if the 'F' option was present on a pattern that is
1429  to be written to a file. We flip the bytes of all the integer fields in the  to be written to a file. We flip the bytes of all the integer fields in the
1430  regex data block and the study block. In 16-bit mode this also flips relevant  regex data block and the study block. In 16-bit mode this also flips relevant
1431  bytes in the pattern itself. This is to make it possible to test PCRE's  bytes in the pattern itself. This is to make it possible to test PCRE's
# Line 1447  if (extra != NULL) Line 1468  if (extra != NULL)
1468    rsd->flags = swap_uint32(rsd->flags);    rsd->flags = swap_uint32(rsd->flags);
1469    rsd->minlength = swap_uint32(rsd->minlength);    rsd->minlength = swap_uint32(rsd->minlength);
1470    }    }
1471    
1472  /* In 8-bit mode, that is all we need to do. In 16-bit mode we must swap bytes  /* In 8-bit mode, that is all we need to do. In 16-bit mode we must swap bytes
1473  in the name table, if present, and then in the pattern itself. */  in the name table, if present, and then in the pattern itself. */
1474    
1475  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
1476  if (!use_pcre16) return;  if (!use_pcre16) return;
# Line 1465  while(TRUE) Line 1486  while(TRUE)
1486  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1487    if (utf16_char)    if (utf16_char)
1488      {      {
1489      if ((ptr[-1] & 0xfc00) == 0xd800)      if ((ptr[-1] & 0xfc00) == 0xd800)
1490        {        {
1491        /* We know that there is only one extra character in UTF-16. */        /* We know that there is only one extra character in UTF-16. */
1492        *ptr = swap_uint16(*ptr);        *ptr = swap_uint16(*ptr);
# Line 1476  while(TRUE) Line 1497  while(TRUE)
1497  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
1498    
1499    /* Get next opcode. */    /* Get next opcode. */
1500    
1501    length = 0;    length = 0;
1502    op = *ptr;    op = *ptr;
1503    *ptr++ = swap_uint16(op);    *ptr++ = swap_uint16(op);
1504    
1505    switch (op)    switch (op)
1506      {      {
1507      case OP_END:      case OP_END:
# Line 1542  while(TRUE) Line 1563  while(TRUE)
1563      case OP_NOTPOSPLUSI:      case OP_NOTPOSPLUSI:
1564      case OP_NOTPOSQUERYI:      case OP_NOTPOSQUERYI:
1565      case OP_NOTPOSUPTOI:      case OP_NOTPOSUPTOI:
1566  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1567      if (utf) utf16_char = TRUE;      if (utf) utf16_char = TRUE;
1568  #endif  #endif
1569      length = OP_lengths16[op] - 1;      length = OP_lengths16[op] - 1;
1570      break;      break;
1571    
# Line 1566  while(TRUE) Line 1587  while(TRUE)
1587        *ptr = swap_uint16(*ptr);        *ptr = swap_uint16(*ptr);
1588        }        }
1589      ptr++;      ptr++;
1590    
1591      if (LINK_SIZE > 1)      if (LINK_SIZE > 1)
1592        length = ((ptr[-LINK_SIZE] << 16) | ptr[-LINK_SIZE + 1]) -        length = ((ptr[-LINK_SIZE] << 16) | ptr[-LINK_SIZE + 1]) -
1593          (1 + LINK_SIZE + 1);          (1 + LINK_SIZE + 1);
1594      else      else
1595        length = ptr[-LINK_SIZE] - (1 + LINK_SIZE + 1);        length = ptr[-LINK_SIZE] - (1 + LINK_SIZE + 1);
1596    
1597      op = *ptr;      op = *ptr;
1598      *ptr = swap_uint16(op);      *ptr = swap_uint16(op);
1599      if ((op & XCL_MAP) != 0)      if ((op & XCL_MAP) != 0)
# Line 1590  while(TRUE) Line 1611  while(TRUE)
1611    }    }
1612  /* Control should never reach here in 16 bit mode. */  /* Control should never reach here in 16 bit mode. */
1613  #endif /* SUPPORT_PCRE16 */  #endif /* SUPPORT_PCRE16 */
1614  }  }
1615    
1616    
1617    
# Line 2688  while (!done) Line 2709  while (!done)
2709          if (PRINTOK(need_char))          if (PRINTOK(need_char))
2710            fprintf(outfile, "Need char = \'%c\'%s\n", need_char, caseless);            fprintf(outfile, "Need char = \'%c\'%s\n", need_char, caseless);
2711          else          else
2712            fprintf(outfile, "Need char = %d%s\n", need_char, caseless);            {
2713              fprintf(outfile, "Need char = ");
2714              pchar(need_char, outfile);
2715              fprintf(outfile, "%s\n", caseless);
2716              }
2717          }          }
2718    
2719        /* Don't output study size; at present it is in any case a fixed        /* Don't output study size; at present it is in any case a fixed
# Line 2776  while (!done) Line 2801  while (!done)
2801        else        else
2802          {          {
2803          pcre_uint8 sbuf[8];          pcre_uint8 sbuf[8];
2804    
2805          if (do_flip) regexflip(re, extra);          if (do_flip) regexflip(re, extra);
2806          sbuf[0] = (pcre_uint8)((true_size >> 24) & 255);          sbuf[0] = (pcre_uint8)((true_size >> 24) & 255);
2807          sbuf[1] = (pcre_uint8)((true_size >> 16) & 255);          sbuf[1] = (pcre_uint8)((true_size >> 16) & 255);
# Line 2958  while (!done) Line 2983  while (!done)
2983              else              else
2984               {               {
2985               if (c > 255)               if (c > 255)
2986                 fprintf(outfile, "** Character \\x{%x} is greater than 255 and "                 {
2987                   "UTF-8 mode is not enabled.\n"                 if (use_pcre16)
2988                   "** Truncation will probably give the wrong result.\n", c);                   fprintf(outfile, "** Character \\x{%x} is greater than 255.\n"
2989                       "** Because its input is first processed as 8-bit, pcretest "
2990                       "does not\n** support such characters in 16-bit mode when "
2991                       "UTF-16 is not set.\n", c);
2992                   else
2993                     fprintf(outfile, "** Character \\x{%x} is greater than 255 "
2994                       "and UTF-8 mode is not enabled.\n", c);
2995    
2996                   fprintf(outfile, "** Truncation will probably give the wrong "
2997                     "result.\n");
2998                   }
2999               }               }
3000              p = pt + 1;              p = pt + 1;
3001              break;              break;
# Line 3307  while (!done) Line 3342  while (!done)
3342            {            {
3343            int workspace[1000];            int workspace[1000];
3344            for (i = 0; i < timeitm; i++)            for (i = 0; i < timeitm; i++)
3345              count = pcre_dfa_exec(re, extra, (char *)bptr, len, start_offset,              {
3346                options | g_notempty, use_offsets, use_size_offsets, workspace,              PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
3347                sizeof(workspace)/sizeof(int));                (options | g_notempty), use_offsets, use_size_offsets, workspace,
3348                  (sizeof(workspace)/sizeof(int)));
3349                }
3350            }            }
3351          else          else
3352  #endif  #endif
3353    
3354          for (i = 0; i < timeitm; i++)          for (i = 0; i < timeitm; i++)
3355            {            {
3356            PCRE_EXEC(count, re, extra, bptr, len,            PCRE_EXEC(count, re, extra, bptr, len, start_offset,
3357              start_offset, options | g_notempty, use_offsets, use_size_offsets);              (options | g_notempty), use_offsets, use_size_offsets);
3358            }            }
3359          time_taken = clock() - start_time;          time_taken = clock() - start_time;
3360          fprintf(outfile, "Execute time %.4f milliseconds\n",          fprintf(outfile, "Execute time %.4f milliseconds\n",
# Line 3375  while (!done) Line 3412  while (!done)
3412        else if (all_use_dfa || use_dfa)        else if (all_use_dfa || use_dfa)
3413          {          {
3414          int workspace[1000];          int workspace[1000];
3415          count = pcre_dfa_exec(re, extra, (char *)bptr, len, start_offset,          PCRE_DFA_EXEC(count, re, extra, bptr, len, start_offset,
3416            options | g_notempty, use_offsets, use_size_offsets, workspace,            (options | g_notempty), use_offsets, use_size_offsets, workspace,
3417            sizeof(workspace)/sizeof(int));            (sizeof(workspace)/sizeof(int)));
3418          if (count == 0)          if (count == 0)
3419            {            {
3420            fprintf(outfile, "Matched, but too many subsidiary matches\n");            fprintf(outfile, "Matched, but too many subsidiary matches\n");
# Line 3463  while (!done) Line 3500  while (!done)
3500              }              }
3501            }            }
3502    
3503          if (markptr != NULL) fprintf(outfile, "MK: %s\n", markptr);          if (markptr != NULL)
3504              {
3505              int mplen;
3506              if (use_pcre16)
3507                {
3508                pcre_uint16 *mp = (pcre_uint16 *)markptr;
3509                mplen = 0;
3510                while (*mp++ != 0) mplen++;
3511                }
3512              else mplen = (int)strlen((char *)markptr);
3513              fprintf(outfile, "MK: ");
3514              PCHARSV(markptr, mplen, outfile);
3515              fprintf(outfile, "\n");
3516              }
3517    
3518          for (i = 0; i < 32; i++)          for (i = 0; i < 32; i++)
3519            {            {

Legend:
Removed from v.813  
changed lines
  Added in v.814

  ViewVC Help
Powered by ViewVC 1.1.5