/[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 55 by nigel, Sat Feb 24 21:39:46 2007 UTC revision 59 by nigel, Sat Feb 24 21:39:54 2007 UTC
# Line 73  for (i = 0; i < sizeof(utf8_table1)/size Line 73  for (i = 0; i < sizeof(utf8_table1)/size
73    if (cvalue <= utf8_table1[i]) break;    if (cvalue <= utf8_table1[i]) break;
74  if (i >= sizeof(utf8_table1)/sizeof(int)) return 0;  if (i >= sizeof(utf8_table1)/sizeof(int)) return 0;
75  if (cvalue < 0) return -1;  if (cvalue < 0) return -1;
76  *buffer++ = utf8_table2[i] | (cvalue & utf8_table3[i]);  
77  cvalue >>= 6 - i;  buffer += i;
78  for (j = 0; j < i; j++)  for (j = i; j > 0; j--)
79    {   {
80    *buffer++ = 0x80 | (cvalue & 0x3f);   *buffer-- = 0x80 | (cvalue & 0x3f);
81    cvalue >>= 6;   cvalue >>= 6;
82    }   }
83    *buffer = utf8_table2[i] | cvalue;
84  return i + 1;  return i + 1;
85  }  }
86    
# Line 117  if (i == 0 || i == 6) return 0;        / Line 118  if (i == 0 || i == 6) return 0;        /
118    
119  /* i now has a value in the range 1-5 */  /* i now has a value in the range 1-5 */
120    
121  d = c & utf8_table3[i];  s = 6*i;
122  s = 6 - i;  d = (c & utf8_table3[i]) << s;
123    
124  for (j = 0; j < i; j++)  for (j = 0; j < i; j++)
125    {    {
126    c = *buffer++;    c = *buffer++;
127    if ((c & 0xc0) != 0x80) return -(j+1);    if ((c & 0xc0) != 0x80) return -(j+1);
128      s -= 6;
129    d |= (c & 0x3f) << s;    d |= (c & 0x3f) << s;
   s += 6;  
130    }    }
131    
132  /* Check that encoding was the correct unique one */  /* Check that encoding was the correct unique one */
# Line 460  while (argc > 1 && argv[op][0] == '-') Line 461  while (argc > 1 && argv[op][0] == '-')
461    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;    else if (strcmp(argv[op], "-i") == 0) showinfo = 1;
462    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;    else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;
463    else if (strcmp(argv[op], "-o") == 0 && argc > 2 &&    else if (strcmp(argv[op], "-o") == 0 && argc > 2 &&
464        ((size_offsets = strtoul(argv[op+1], &endptr, 10)), *endptr == 0))        ((size_offsets = (int)strtoul(argv[op+1], &endptr, 10)), *endptr == 0))
465      {      {
466      op++;      op++;
467      argc--;      argc--;
# Line 893  while (!done) Line 894  while (!done)
894      {      {
895      unsigned char *q;      unsigned char *q;
896      unsigned char *bptr = dbuffer;      unsigned char *bptr = dbuffer;
897        int *use_offsets = offsets;
898      int use_size_offsets = size_offsets;      int use_size_offsets = size_offsets;
899      int count, c;      int count, c;
900      int copystrings = 0;      int copystrings = 0;
# Line 1010  while (!done) Line 1012  while (!done)
1012          while(isdigit(*p)) n = n * 10 + *p++ - '0';          while(isdigit(*p)) n = n * 10 + *p++ - '0';
1013          if (n > size_offsets_max)          if (n > size_offsets_max)
1014            {            {
   
 if (offsets != NULL)  
   
           free(offsets);  
1015            size_offsets_max = n;            size_offsets_max = n;
1016            offsets = malloc(size_offsets_max * sizeof(int));            free(offsets);
1017              use_offsets = offsets = malloc(size_offsets_max * sizeof(int));
1018            if (offsets == NULL)            if (offsets == NULL)
1019              {              {
1020              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 1024  if (offsets != NULL) Line 1023  if (offsets != NULL)
1023              }              }
1024            }            }
1025          use_size_offsets = n;          use_size_offsets = n;
1026            if (n == 0) use_offsets = NULL;
 if (n == 0)  
   {  
   free(offsets);  
   offsets = NULL;  
   size_offsets_max = 0;  
   }  
   
1027          continue;          continue;
1028    
1029          case 'Z':          case 'Z':
# Line 1099  if (n == 0) Line 1091  if (n == 0)
1091          clock_t start_time = clock();          clock_t start_time = clock();
1092          for (i = 0; i < LOOPREPEAT; i++)          for (i = 0; i < LOOPREPEAT; i++)
1093            count = pcre_exec(re, extra, (char *)bptr, len,            count = pcre_exec(re, extra, (char *)bptr, len,
1094              start_offset, options | g_notempty, offsets, use_size_offsets);              start_offset, options | g_notempty, use_offsets, use_size_offsets);
1095          time_taken = clock() - start_time;          time_taken = clock() - start_time;
1096          fprintf(outfile, "Execute time %.3f milliseconds\n",          fprintf(outfile, "Execute time %.3f milliseconds\n",
1097            ((double)time_taken * 1000.0)/            ((double)time_taken * 1000.0)/
# Line 1107  if (n == 0) Line 1099  if (n == 0)
1099          }          }
1100    
1101        count = pcre_exec(re, extra, (char *)bptr, len,        count = pcre_exec(re, extra, (char *)bptr, len,
1102          start_offset, options | g_notempty, offsets, use_size_offsets);          start_offset, options | g_notempty, use_offsets, use_size_offsets);
1103    
1104        if (count == 0)        if (count == 0)
1105          {          {
# Line 1122  if (n == 0) Line 1114  if (n == 0)
1114          int i;          int i;
1115          for (i = 0; i < count * 2; i += 2)          for (i = 0; i < count * 2; i += 2)
1116            {            {
1117            if (offsets[i] < 0)            if (use_offsets[i] < 0)
1118              fprintf(outfile, "%2d: <unset>\n", i/2);              fprintf(outfile, "%2d: <unset>\n", i/2);
1119            else            else
1120              {              {
1121              fprintf(outfile, "%2d: ", i/2);              fprintf(outfile, "%2d: ", i/2);
1122              pchars(bptr + offsets[i], offsets[i+1] - offsets[i], utf8);              pchars(bptr + use_offsets[i], use_offsets[i+1] - use_offsets[i], utf8);
1123              fprintf(outfile, "\n");              fprintf(outfile, "\n");
1124              if (i == 0)              if (i == 0)
1125                {                {
1126                if (do_showrest)                if (do_showrest)
1127                  {                  {
1128                  fprintf(outfile, " 0+ ");                  fprintf(outfile, " 0+ ");
1129                  pchars(bptr + offsets[i+1], len - offsets[i+1], utf8);                  pchars(bptr + use_offsets[i+1], len - use_offsets[i+1], utf8);
1130                  fprintf(outfile, "\n");                  fprintf(outfile, "\n");
1131                  }                  }
1132                }                }
# Line 1146  if (n == 0) Line 1138  if (n == 0)
1138            if ((copystrings & (1 << i)) != 0)            if ((copystrings & (1 << i)) != 0)
1139              {              {
1140              char copybuffer[16];              char copybuffer[16];
1141              int rc = pcre_copy_substring((char *)bptr, offsets, count,              int rc = pcre_copy_substring((char *)bptr, use_offsets, count,
1142                i, copybuffer, sizeof(copybuffer));                i, copybuffer, sizeof(copybuffer));
1143              if (rc < 0)              if (rc < 0)
1144                fprintf(outfile, "copy substring %d failed %d\n", i, rc);                fprintf(outfile, "copy substring %d failed %d\n", i, rc);
# Line 1160  if (n == 0) Line 1152  if (n == 0)
1152            if ((getstrings & (1 << i)) != 0)            if ((getstrings & (1 << i)) != 0)
1153              {              {
1154              const char *substring;              const char *substring;
1155              int rc = pcre_get_substring((char *)bptr, offsets, count,              int rc = pcre_get_substring((char *)bptr, use_offsets, count,
1156                i, &substring);                i, &substring);
1157              if (rc < 0)              if (rc < 0)
1158                fprintf(outfile, "get substring %d failed %d\n", i, rc);                fprintf(outfile, "get substring %d failed %d\n", i, rc);
# Line 1176  if (n == 0) Line 1168  if (n == 0)
1168          if (getlist)          if (getlist)
1169            {            {
1170            const char **stringlist;            const char **stringlist;
1171            int rc = pcre_get_substring_list((char *)bptr, offsets, count,            int rc = pcre_get_substring_list((char *)bptr, use_offsets, count,
1172              &stringlist);              &stringlist);
1173            if (rc < 0)            if (rc < 0)
1174              fprintf(outfile, "get substring list failed %d\n", rc);              fprintf(outfile, "get substring list failed %d\n", rc);
# Line 1202  if (n == 0) Line 1194  if (n == 0)
1194          {          {
1195          if (g_notempty != 0)          if (g_notempty != 0)
1196            {            {
1197            offsets[0] = start_offset;            use_offsets[0] = start_offset;
1198            offsets[1] = start_offset + 1;            use_offsets[1] = start_offset + 1;
1199            }            }
1200          else          else
1201            {            {
# Line 1228  if (n == 0) Line 1220  if (n == 0)
1220        character. */        character. */
1221    
1222        g_notempty = 0;        g_notempty = 0;
1223        if (offsets[0] == offsets[1])        if (use_offsets[0] == use_offsets[1])
1224          {          {
1225          if (offsets[0] == len) break;          if (use_offsets[0] == len) break;
1226          g_notempty = PCRE_NOTEMPTY | PCRE_ANCHORED;          g_notempty = PCRE_NOTEMPTY | PCRE_ANCHORED;
1227          }          }
1228    
1229        /* For /g, update the start offset, leaving the rest alone */        /* For /g, update the start offset, leaving the rest alone */
1230    
1231        if (do_g) start_offset = offsets[1];        if (do_g) start_offset = use_offsets[1];
1232    
1233        /* For /G, update the pointer and length */        /* For /G, update the pointer and length */
1234    
1235        else        else
1236          {          {
1237          bptr += offsets[1];          bptr += use_offsets[1];
1238          len -= offsets[1];          len -= use_offsets[1];
1239          }          }
1240        }  /* End of loop for /g and /G */        }  /* End of loop for /g and /G */
1241      }    /* End of loop for data lines */      }    /* End of loop for data lines */

Legend:
Removed from v.55  
changed lines
  Added in v.59

  ViewVC Help
Powered by ViewVC 1.1.5