/[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 69 by nigel, Sat Feb 24 21:40:18 2007 UTC revision 73 by nigel, Sat Feb 24 21:40:30 2007 UTC
# Line 38  Makefile. */ Line 38  Makefile. */
38  #define LOOPREPEAT 50000  #define LOOPREPEAT 50000
39    
40  #define BUFFER_SIZE 30000  #define BUFFER_SIZE 30000
41  #define DBUFFER_SIZE 1024  #define DBUFFER_SIZE BUFFER_SIZE
42    
43    
44  static FILE *outfile;  static FILE *outfile;
# Line 48  static int callout_extra; Line 48  static int callout_extra;
48  static int callout_fail_count;  static int callout_fail_count;
49  static int callout_fail_id;  static int callout_fail_id;
50  static int first_callout;  static int first_callout;
51    static int show_malloc;
52  static int use_utf8;  static int use_utf8;
53  static size_t gotten_store;  static size_t gotten_store;
54    
55    
   
56  static const int utf8_table1[] = {  static const int utf8_table1[] = {
57    0x0000007f, 0x000007ff, 0x0000ffff, 0x001fffff, 0x03ffffff, 0x7fffffff};    0x0000007f, 0x000007ff, 0x0000ffff, 0x001fffff, 0x03ffffff, 0x7fffffff};
58    
# Line 321  if (post_start > 0) Line 321  if (post_start > 0)
321    }    }
322    
323  fprintf(outfile, "\n");  fprintf(outfile, "\n");
   
324  first_callout = 0;  first_callout = 0;
325    
326  if ((int)(cb->callout_data) != 0)  if (cb->callout_data != NULL)
327    {    {
328    fprintf(outfile, "Callout data = %d\n", (int)(cb->callout_data));    int callout_data = *((int *)(cb->callout_data));
329    return (int)(cb->callout_data);    if (callout_data != 0)
330        {
331        fprintf(outfile, "Callout data = %d\n", callout_data);
332        return callout_data;
333        }
334    }    }
335    
336  return (cb->callout_number != callout_fail_id)? 0 :  return (cb->callout_number != callout_fail_id)? 0 :
# Line 336  return (cb->callout_number != callout_fa Line 339  return (cb->callout_number != callout_fa
339    
340    
341  /*************************************************  /*************************************************
342  *            Local malloc function               *  *            Local malloc functions              *
343  *************************************************/  *************************************************/
344    
345  /* Alternative malloc function, to test functionality and show the size of the  /* Alternative malloc function, to test functionality and show the size of the
# Line 344  compiled re. */ Line 347  compiled re. */
347    
348  static void *new_malloc(size_t size)  static void *new_malloc(size_t size)
349  {  {
350    void *block = malloc(size);
351  gotten_store = size;  gotten_store = size;
352  return malloc(size);  if (show_malloc)
353      fprintf(outfile, "malloc       %3d %p\n", size, block);
354    return block;
355    }
356    
357    static void new_free(void *block)
358    {
359    if (show_malloc)
360      fprintf(outfile, "free             %p\n", block);
361    free(block);
362    }
363    
364    
365    /* For recursion malloc/free, to test stacking calls */
366    
367    static void *stack_malloc(size_t size)
368    {
369    void *block = malloc(size);
370    if (show_malloc)
371      fprintf(outfile, "stack_malloc %3d %p\n", size, block);
372    return block;
373  }  }
374    
375    static void stack_free(void *block)
376    {
377    if (show_malloc)
378      fprintf(outfile, "stack_free       %p\n", block);
379    free(block);
380    }
381    
382    
383  /*************************************************  /*************************************************
# Line 397  unsigned char *dbuffer; Line 427  unsigned char *dbuffer;
427  /* Get buffers from malloc() so that Electric Fence will check their misuse  /* Get buffers from malloc() so that Electric Fence will check their misuse
428  when I am debugging. */  when I am debugging. */
429    
430  buffer = malloc(BUFFER_SIZE);  buffer = (unsigned char *)malloc(BUFFER_SIZE);
431  dbuffer = malloc(DBUFFER_SIZE);  dbuffer = (unsigned char *)malloc(DBUFFER_SIZE);
432    
433  /* Static so that new_malloc can use it. */  /* Static so that new_malloc can use it. */
434    
# Line 440  while (argc > 1 && argv[op][0] == '-') Line 470  while (argc > 1 && argv[op][0] == '-')
470      printf("  POSIX malloc threshold = %d\n", rc);      printf("  POSIX malloc threshold = %d\n", rc);
471      (void)pcre_config(PCRE_CONFIG_MATCH_LIMIT, &rc);      (void)pcre_config(PCRE_CONFIG_MATCH_LIMIT, &rc);
472      printf("  Default match limit = %d\n", rc);      printf("  Default match limit = %d\n", rc);
473        (void)pcre_config(PCRE_CONFIG_STACKRECURSE, &rc);
474        printf("  Match recursion uses %s\n", rc? "stack" : "heap");
475      exit(0);      exit(0);
476      }      }
477    else    else
# Line 464  while (argc > 1 && argv[op][0] == '-') Line 496  while (argc > 1 && argv[op][0] == '-')
496  /* Get the store for the offsets vector, and remember what it was */  /* Get the store for the offsets vector, and remember what it was */
497    
498  size_offsets_max = size_offsets;  size_offsets_max = size_offsets;
499  offsets = malloc(size_offsets_max * sizeof(int));  offsets = (int *)malloc(size_offsets_max * sizeof(int));
500  if (offsets == NULL)  if (offsets == NULL)
501    {    {
502    printf("** Failed to get %d bytes of memory for offsets vector\n",    printf("** Failed to get %d bytes of memory for offsets vector\n",
# Line 497  if (argc > 2) Line 529  if (argc > 2)
529  /* Set alternative malloc function */  /* Set alternative malloc function */
530    
531  pcre_malloc = new_malloc;  pcre_malloc = new_malloc;
532    pcre_free = new_free;
533    pcre_stack_malloc = stack_malloc;
534    pcre_stack_free = stack_free;
535    
536  /* Heading line, then prompt for first regex if stdin */  /* Heading line, then prompt for first regex if stdin */
537    
# Line 619  while (!done) Line 654  while (!done)
654        case 'U': options |= PCRE_UNGREEDY; break;        case 'U': options |= PCRE_UNGREEDY; break;
655        case 'X': options |= PCRE_EXTRA; break;        case 'X': options |= PCRE_EXTRA; break;
656        case '8': options |= PCRE_UTF8; use_utf8 = 1; break;        case '8': options |= PCRE_UTF8; use_utf8 = 1; break;
657          case '?': options |= PCRE_NO_UTF8_CHECK; break;
658    
659        case 'L':        case 'L':
660        ppp = pp;        ppp = pp;
# Line 787  while (!done) Line 823  while (!done)
823          }          }
824    
825        if (get_options == 0) fprintf(outfile, "No options\n");        if (get_options == 0) fprintf(outfile, "No options\n");
826          else fprintf(outfile, "Options:%s%s%s%s%s%s%s%s%s\n",          else fprintf(outfile, "Options:%s%s%s%s%s%s%s%s%s%s\n",
827            ((get_options & PCRE_ANCHORED) != 0)? " anchored" : "",            ((get_options & PCRE_ANCHORED) != 0)? " anchored" : "",
828            ((get_options & PCRE_CASELESS) != 0)? " caseless" : "",            ((get_options & PCRE_CASELESS) != 0)? " caseless" : "",
829            ((get_options & PCRE_EXTENDED) != 0)? " extended" : "",            ((get_options & PCRE_EXTENDED) != 0)? " extended" : "",
# Line 796  while (!done) Line 832  while (!done)
832            ((get_options & PCRE_DOLLAR_ENDONLY) != 0)? " dollar_endonly" : "",            ((get_options & PCRE_DOLLAR_ENDONLY) != 0)? " dollar_endonly" : "",
833            ((get_options & PCRE_EXTRA) != 0)? " extra" : "",            ((get_options & PCRE_EXTRA) != 0)? " extra" : "",
834            ((get_options & PCRE_UNGREEDY) != 0)? " ungreedy" : "",            ((get_options & PCRE_UNGREEDY) != 0)? " ungreedy" : "",
835            ((get_options & PCRE_UTF8) != 0)? " utf8" : "");            ((get_options & PCRE_UTF8) != 0)? " utf8" : "",
836              ((get_options & PCRE_NO_UTF8_CHECK) != 0)? " no_utf8_check" : "");
837    
838        if (((((real_pcre *)re)->options) & PCRE_ICHANGED) != 0)        if (((((real_pcre *)re)->options) & PCRE_ICHANGED) != 0)
839          fprintf(outfile, "Case state changes\n");          fprintf(outfile, "Case state changes\n");
# Line 861  while (!done) Line 898  while (!done)
898        else if (extra == NULL)        else if (extra == NULL)
899          fprintf(outfile, "Study returned NULL\n");          fprintf(outfile, "Study returned NULL\n");
900    
901          /* Don't output study size; at present it is in any case a fixed
902          value, but it varies, depending on the computer architecture, and
903          so messes up the test suite. */
904    
905        else if (do_showinfo)        else if (do_showinfo)
906          {          {
907          size_t size;          size_t size;
908          uschar *start_bits = NULL;          uschar *start_bits = NULL;
909          new_info(re, extra, PCRE_INFO_STUDYSIZE, &size);          new_info(re, extra, PCRE_INFO_STUDYSIZE, &size);
910          new_info(re, extra, PCRE_INFO_FIRSTTABLE, &start_bits);          new_info(re, extra, PCRE_INFO_FIRSTTABLE, &start_bits);
911          fprintf(outfile, "Study size = %d\n", size);          /* fprintf(outfile, "Study size = %d\n", size); */
912          if (start_bits == NULL)          if (start_bits == NULL)
913            fprintf(outfile, "No starting character set\n");            fprintf(outfile, "No starting character set\n");
914          else          else
# Line 929  while (!done) Line 970  while (!done)
970      callout_count = 0;      callout_count = 0;
971      callout_fail_count = 999999;      callout_fail_count = 999999;
972      callout_fail_id = -1;      callout_fail_id = -1;
973        show_malloc = 0;
974    
975      if (infile == stdin) printf("data> ");      if (infile == stdin) printf("data> ");
976      if (fgets((char *)buffer, BUFFER_SIZE, infile) == NULL)      if (fgets((char *)buffer, BUFFER_SIZE, infile) == NULL)
# Line 1105  while (!done) Line 1147  while (!done)
1147            {            {
1148            size_offsets_max = n;            size_offsets_max = n;
1149            free(offsets);            free(offsets);
1150            use_offsets = offsets = malloc(size_offsets_max * sizeof(int));            use_offsets = offsets = (int *)malloc(size_offsets_max * sizeof(int));
1151            if (offsets == NULL)            if (offsets == NULL)
1152              {              {
1153              printf("** Failed to get %d bytes of memory for offsets vector\n",              printf("** Failed to get %d bytes of memory for offsets vector\n",
# Line 1117  while (!done) Line 1159  while (!done)
1159          if (n == 0) use_offsets = NULL;   /* Ensures it can't write to it */          if (n == 0) use_offsets = NULL;   /* Ensures it can't write to it */
1160          continue;          continue;
1161    
1162            case 'S':
1163            show_malloc = 1;
1164            continue;
1165    
1166          case 'Z':          case 'Z':
1167          options |= PCRE_NOTEOL;          options |= PCRE_NOTEOL;
1168          continue;          continue;
1169    
1170            case '?':
1171            options |= PCRE_NO_UTF8_CHECK;
1172            continue;
1173          }          }
1174        *q++ = c;        *q++ = c;
1175        }        }
# Line 1136  while (!done) Line 1186  while (!done)
1186        int eflags = 0;        int eflags = 0;
1187        regmatch_t *pmatch = NULL;        regmatch_t *pmatch = NULL;
1188        if (use_size_offsets > 0)        if (use_size_offsets > 0)
1189          pmatch = malloc(sizeof(regmatch_t) * use_size_offsets);          pmatch = (regmatch_t *)malloc(sizeof(regmatch_t) * use_size_offsets);
1190        if ((options & PCRE_NOTBOL) != 0) eflags |= REG_NOTBOL;        if ((options & PCRE_NOTBOL) != 0) eflags |= REG_NOTBOL;
1191        if ((options & PCRE_NOTEOL) != 0) eflags |= REG_NOTEOL;        if ((options & PCRE_NOTEOL) != 0) eflags |= REG_NOTEOL;
1192    
# Line 1203  while (!done) Line 1253  while (!done)
1253    
1254          if (extra == NULL)          if (extra == NULL)
1255            {            {
1256            extra = malloc(sizeof(pcre_extra));            extra = (pcre_extra *)malloc(sizeof(pcre_extra));
1257            extra->flags = 0;            extra->flags = 0;
1258            }            }
1259          extra->flags |= PCRE_EXTRA_MATCH_LIMIT;          extra->flags |= PCRE_EXTRA_MATCH_LIMIT;
# Line 1242  while (!done) Line 1292  while (!done)
1292          {          {
1293          if (extra == NULL)          if (extra == NULL)
1294            {            {
1295            extra = malloc(sizeof(pcre_extra));            extra = (pcre_extra *)malloc(sizeof(pcre_extra));
1296            extra->flags = 0;            extra->flags = 0;
1297            }            }
1298          extra->flags |= PCRE_EXTRA_CALLOUT_DATA;          extra->flags |= PCRE_EXTRA_CALLOUT_DATA;
1299          extra->callout_data = (void *)callout_data;          extra->callout_data = &callout_data;
1300          count = pcre_exec(re, extra, (char *)bptr, len, start_offset,          count = pcre_exec(re, extra, (char *)bptr, len, start_offset,
1301            options | g_notempty, use_offsets, use_size_offsets);            options | g_notempty, use_offsets, use_size_offsets);
1302          extra->flags &= ~PCRE_EXTRA_CALLOUT_DATA;          extra->flags &= ~PCRE_EXTRA_CALLOUT_DATA;
# Line 1345  while (!done) Line 1395  while (!done)
1395    
1396        /* Failed to match. If this is a /g or /G loop and we previously set        /* Failed to match. If this is a /g or /G loop and we previously set
1397        g_notempty after a null match, this is not necessarily the end.        g_notempty after a null match, this is not necessarily the end.
1398        We want to advance the start offset, and continue. Fudge the offset        We want to advance the start offset, and continue. In the case of UTF-8
1399        values to achieve this. We won't be at the end of the string - that        matching, the advance must be one character, not one byte. Fudge the
1400        was checked before setting g_notempty. */        offset values to achieve this. We won't be at the end of the string -
1401          that was checked before setting g_notempty. */
1402    
1403        else        else
1404          {          {
1405          if (g_notempty != 0)          if (g_notempty != 0)
1406            {            {
1407              int onechar = 1;
1408            use_offsets[0] = start_offset;            use_offsets[0] = start_offset;
1409            use_offsets[1] = start_offset + 1;            if (use_utf8)
1410                {
1411                while (start_offset + onechar < len)
1412                  {
1413                  int tb = bptr[start_offset+onechar];
1414                  if (tb <= 127) break;
1415                  tb &= 0xc0;
1416                  if (tb != 0 && tb != 0xc0) onechar++;
1417                  }
1418                }
1419              use_offsets[1] = start_offset + onechar;
1420            }            }
1421          else          else
1422            {            {
1423            if (gmatched == 0)   /* Error if no previous matches */            if (count == PCRE_ERROR_NOMATCH)
1424              {              {
1425              if (count == -1) fprintf(outfile, "No match\n");              if (gmatched == 0) fprintf(outfile, "No match\n");
               else fprintf(outfile, "Error %d\n", count);  
1426              }              }
1427              else fprintf(outfile, "Error %d\n", count);
1428            break;  /* Out of the /g loop */            break;  /* Out of the /g loop */
1429            }            }
1430          }          }
# Line 1414  while (!done) Line 1476  while (!done)
1476      }      }
1477    }    }
1478    
1479  fprintf(outfile, "\n");  if (infile == stdin) fprintf(outfile, "\n");
1480  return 0;  return 0;
1481  }  }
1482    

Legend:
Removed from v.69  
changed lines
  Added in v.73

  ViewVC Help
Powered by ViewVC 1.1.5