/[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 27 by nigel, Sat Feb 24 21:38:49 2007 UTC revision 31 by nigel, Sat Feb 24 21:38:57 2007 UTC
# Line 274  compiled re. */ Line 274  compiled re. */
274    
275  static void *new_malloc(size_t size)  static void *new_malloc(size_t size)
276  {  {
277  if (log_store) fprintf(outfile, "Store size request: %d\n", (int)size);  if (log_store)
278      fprintf(outfile, "Memory allocation request: %d (code space %d)\n",
279        (int)size, (int)size - offsetof(real_pcre, code[0]));
280  return malloc(size);  return malloc(size);
281  }  }
282    
# Line 292  int study_options = 0; Line 294  int study_options = 0;
294  int op = 1;  int op = 1;
295  int timeit = 0;  int timeit = 0;
296  int showinfo = 0;  int showinfo = 0;
297    int showstore = 0;
298  int posix = 0;  int posix = 0;
299  int debug = 0;  int debug = 0;
300  int done = 0;  int done = 0;
# Line 306  outfile = stdout; Line 309  outfile = stdout;
309    
310  while (argc > 1 && argv[op][0] == '-')  while (argc > 1 && argv[op][0] == '-')
311    {    {
312    if (strcmp(argv[op], "-s") == 0) log_store = 1;    if (strcmp(argv[op], "-s") == 0 || strcmp(argv[op], "-m") == 0)
313        showstore = 1;
314    else if (strcmp(argv[op], "-t") == 0) timeit = 1;    else if (strcmp(argv[op], "-t") == 0) timeit = 1;
315    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;
316    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;
# Line 385  while (!done) Line 389  while (!done)
389    
390    delimiter = *p++;    delimiter = *p++;
391    
392    if (isalnum(delimiter))    if (isalnum(delimiter) || delimiter == '\\')
393      {      {
394      fprintf(outfile, "** Delimiter must not be alphameric\n");      fprintf(outfile, "** Delimiter must not be alphameric or \\\n");
395      goto SKIP_DATA;      goto SKIP_DATA;
396      }      }
397    
# Line 395  while (!done) Line 399  while (!done)
399    
400    for(;;)    for(;;)
401      {      {
402      while (*pp != 0 && *pp != delimiter) pp++;      while (*pp != 0)
403          {
404          if (*pp == '\\' && pp[1] != 0) pp++;
405            else if (*pp == delimiter) break;
406          pp++;
407          }
408      if (*pp != 0) break;      if (*pp != 0) break;
409    
410      len = sizeof(buffer) - (pp - buffer);      len = sizeof(buffer) - (pp - buffer);
# Line 415  while (!done) Line 424  while (!done)
424      if (infile != stdin) fprintf(outfile, "%s", (char *)pp);      if (infile != stdin) fprintf(outfile, "%s", (char *)pp);
425      }      }
426    
427      /* If the first character after the delimiter is backslash, make
428      the pattern end with backslash. This is purely to provide a way
429      of testing for the error message when a pattern ends with backslash. */
430    
431      if (pp[1] == '\\') *pp++ = '\\';
432    
433    /* Terminate the pattern at the delimiter */    /* Terminate the pattern at the delimiter */
434    
435    *pp++ = 0;    *pp++ = 0;
# Line 423  while (!done) Line 438  while (!done)
438    
439    options = 0;    options = 0;
440    study_options = 0;    study_options = 0;
441      log_store = showstore;  /* default from command line */
442    
443    while (*pp != 0)    while (*pp != 0)
444      {      {
445      switch (*pp++)      switch (*pp++)
# Line 436  while (!done) Line 453  while (!done)
453        case 'D': do_debug = do_showinfo = 1; break;        case 'D': do_debug = do_showinfo = 1; break;
454        case 'E': options |= PCRE_DOLLAR_ENDONLY; break;        case 'E': options |= PCRE_DOLLAR_ENDONLY; break;
455        case 'I': do_showinfo = 1; break;        case 'I': do_showinfo = 1; break;
456          case 'M': log_store = 1; break;
457        case 'P': do_posix = 1; break;        case 'P': do_posix = 1; break;
458        case 'S': do_study = 1; break;        case 'S': do_study = 1; break;
459        case 'U': options |= PCRE_UNGREEDY; break;        case 'U': options |= PCRE_UNGREEDY; break;
# Line 644  while (!done) Line 662  while (!done)
662      {      {
663      unsigned char *q;      unsigned char *q;
664      int count, c;      int count, c;
665        int copystrings = 0;
666        int getstrings = 0;
667        int getlist = 0;
668      int offsets[45];      int offsets[45];
669      int size_offsets = sizeof(offsets)/sizeof(int);      int size_offsets = sizeof(offsets)/sizeof(int);
670    
# Line 709  while (!done) Line 730  while (!done)
730          options |= PCRE_NOTBOL;          options |= PCRE_NOTBOL;
731          continue;          continue;
732    
733            case 'C':
734            while(isdigit(*p)) n = n * 10 + *p++ - '0';
735            copystrings |= 1 << n;
736            continue;
737    
738            case 'G':
739            while(isdigit(*p)) n = n * 10 + *p++ - '0';
740            getstrings |= 1 << n;
741            continue;
742    
743            case 'L':
744            getlist = 1;
745            continue;
746    
747          case 'O':          case 'O':
748          while(isdigit(*p)) n = n * 10 + *p++ - '0';          while(isdigit(*p)) n = n * 10 + *p++ - '0';
749          if (n <= (int)(sizeof(offsets)/sizeof(int))) size_offsets = n;          if (n <= (int)(sizeof(offsets)/sizeof(int))) size_offsets = n;
# Line 788  while (!done) Line 823  while (!done)
823        if (count >= 0)        if (count >= 0)
824          {          {
825          int i;          int i;
826          count *= 2;          for (i = 0; i < count * 2; i += 2)
         for (i = 0; i < count; i += 2)  
827            {            {
828            if (offsets[i] < 0)            if (offsets[i] < 0)
829              fprintf(outfile, "%2d: <unset>\n", i/2);              fprintf(outfile, "%2d: <unset>\n", i/2);
# Line 800  while (!done) Line 834  while (!done)
834              fprintf(outfile, "\n");              fprintf(outfile, "\n");
835              }              }
836            }            }
837    
838            for (i = 0; i < 32; i++)
839              {
840              if ((copystrings & (1 << i)) != 0)
841                {
842                char buffer[16];
843                int rc = pcre_copy_substring((char *)dbuffer, offsets, count,
844                  i, buffer, sizeof(buffer));
845                if (rc < 0)
846                  fprintf(outfile, "copy substring %d failed %d\n", i, rc);
847                else
848                  fprintf(outfile, "%2dC %s (%d)\n", i, buffer, rc);
849                }
850              }
851    
852            for (i = 0; i < 32; i++)
853              {
854              if ((getstrings & (1 << i)) != 0)
855                {
856                const char *substring;
857                int rc = pcre_get_substring((char *)dbuffer, offsets, count,
858                  i, &substring);
859                if (rc < 0)
860                  fprintf(outfile, "get substring %d failed %d\n", i, rc);
861                else
862                  {
863                  fprintf(outfile, "%2dG %s (%d)\n", i, substring, rc);
864                  free((void *)substring);
865                  }
866                }
867              }
868    
869            if (getlist)
870              {
871              const char **stringlist;
872              int rc = pcre_get_substring_list((char *)dbuffer, offsets, count,
873                &stringlist);
874              if (rc < 0)
875                fprintf(outfile, "get substring list failed %d\n", rc);
876              else
877                {
878                for (i = 0; i < count; i++)
879                  fprintf(outfile, "%2dL %s\n", i, stringlist[i]);
880                if (stringlist[i] != NULL)
881                  fprintf(outfile, "string list not terminated by NULL\n");
882                free((void *)stringlist);
883                }
884              }
885    
886          }          }
887        else        else
888          {          {

Legend:
Removed from v.27  
changed lines
  Added in v.31

  ViewVC Help
Powered by ViewVC 1.1.5