/[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 72 by nigel, Sat Feb 24 21:40:24 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    
# Line 338  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 346  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  /*************************************************  /*************************************************
384  *          Call pcre_fullinfo()                  *  *          Call pcre_fullinfo()                  *
# Line 442  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 499  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 937  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 1125  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;
# Line 1357  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 1426  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.72  
changed lines
  Added in v.73

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12