/[pcre]/code/tags/pcre-4.4/pcretest.c
ViewVC logotype

Diff of /code/tags/pcre-4.4/pcretest.c

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

revision 28 by nigel, Sat Feb 24 21:38:49 2007 UTC revision 29 by nigel, Sat Feb 24 21:38:53 2007 UTC
# Line 385  while (!done) Line 385  while (!done)
385    
386    delimiter = *p++;    delimiter = *p++;
387    
388    if (isalnum(delimiter))    if (isalnum(delimiter) || delimiter == '\\')
389      {      {
390      fprintf(outfile, "** Delimiter must not be alphameric\n");      fprintf(outfile, "** Delimiter must not be alphameric or \\\n");
391      goto SKIP_DATA;      goto SKIP_DATA;
392      }      }
393    
# Line 395  while (!done) Line 395  while (!done)
395    
396    for(;;)    for(;;)
397      {      {
398      while (*pp != 0 && *pp != delimiter) pp++;      while (*pp != 0)
399          {
400          if (*pp == '\\' && pp[1] != 0) pp++;
401            else if (*pp == delimiter) break;
402          pp++;
403          }
404      if (*pp != 0) break;      if (*pp != 0) break;
405    
406      len = sizeof(buffer) - (pp - buffer);      len = sizeof(buffer) - (pp - buffer);
# Line 415  while (!done) Line 420  while (!done)
420      if (infile != stdin) fprintf(outfile, "%s", (char *)pp);      if (infile != stdin) fprintf(outfile, "%s", (char *)pp);
421      }      }
422    
423      /* If the first character after the delimiter is backslash, make
424      the pattern end with backslash. This is purely to provide a way
425      of testing for the error message when a pattern ends with backslash. */
426    
427      if (pp[1] == '\\') *pp++ = '\\';
428    
429    /* Terminate the pattern at the delimiter */    /* Terminate the pattern at the delimiter */
430    
431    *pp++ = 0;    *pp++ = 0;
# Line 644  while (!done) Line 655  while (!done)
655      {      {
656      unsigned char *q;      unsigned char *q;
657      int count, c;      int count, c;
658        int copystrings = 0;
659        int getstrings = 0;
660        int getlist = 0;
661      int offsets[45];      int offsets[45];
662      int size_offsets = sizeof(offsets)/sizeof(int);      int size_offsets = sizeof(offsets)/sizeof(int);
663    
# Line 709  while (!done) Line 723  while (!done)
723          options |= PCRE_NOTBOL;          options |= PCRE_NOTBOL;
724          continue;          continue;
725    
726            case 'C':
727            while(isdigit(*p)) n = n * 10 + *p++ - '0';
728            copystrings |= 1 << n;
729            continue;
730    
731            case 'G':
732            while(isdigit(*p)) n = n * 10 + *p++ - '0';
733            getstrings |= 1 << n;
734            continue;
735    
736            case 'L':
737            getlist = 1;
738            continue;
739    
740          case 'O':          case 'O':
741          while(isdigit(*p)) n = n * 10 + *p++ - '0';          while(isdigit(*p)) n = n * 10 + *p++ - '0';
742          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 816  while (!done)
816        if (count >= 0)        if (count >= 0)
817          {          {
818          int i;          int i;
819          count *= 2;          for (i = 0; i < count * 2; i += 2)
         for (i = 0; i < count; i += 2)  
820            {            {
821            if (offsets[i] < 0)            if (offsets[i] < 0)
822              fprintf(outfile, "%2d: <unset>\n", i/2);              fprintf(outfile, "%2d: <unset>\n", i/2);
# Line 800  while (!done) Line 827  while (!done)
827              fprintf(outfile, "\n");              fprintf(outfile, "\n");
828              }              }
829            }            }
830    
831            for (i = 0; i < 32; i++)
832              {
833              if ((copystrings & (1 << i)) != 0)
834                {
835                char buffer[16];
836                int rc = pcre_copy_substring((char *)dbuffer, offsets, count,
837                  i, buffer, sizeof(buffer));
838                if (rc < 0)
839                  fprintf(outfile, "copy substring %d failed %d\n", i, rc);
840                else
841                  fprintf(outfile, "%2dC %s (%d)\n", i, buffer, rc);
842                }
843              }
844    
845            for (i = 0; i < 32; i++)
846              {
847              if ((getstrings & (1 << i)) != 0)
848                {
849                const char *substring;
850                int rc = pcre_get_substring((char *)dbuffer, offsets, count,
851                  i, &substring);
852                if (rc < 0)
853                  fprintf(outfile, "get substring %d failed %d\n", i, rc);
854                else
855                  {
856                  fprintf(outfile, "%2dG %s (%d)\n", i, substring, rc);
857                  free((void *)substring);
858                  }
859                }
860              }
861    
862            if (getlist)
863              {
864              const char **stringlist;
865              int rc = pcre_get_substring_list((char *)dbuffer, offsets, count,
866                &stringlist);
867              if (rc < 0)
868                fprintf(outfile, "get substring list failed %d\n", rc);
869              else
870                {
871                for (i = 0; i < count; i++)
872                  fprintf(outfile, "%2dL %s\n", i, stringlist[i]);
873                if (stringlist[i] != NULL)
874                  fprintf(outfile, "string list not terminated by NULL\n");
875                free((void *)stringlist);
876                }
877              }
878    
879          }          }
880        else        else
881          {          {

Legend:
Removed from v.28  
changed lines
  Added in v.29

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12