| 159 |
"class", "Ref", "Recurse", |
"class", "Ref", "Recurse", |
| 160 |
"Alt", "Ket", "KetRmax", "KetRmin", "Assert", "Assert not", |
"Alt", "Ket", "KetRmax", "KetRmin", "Assert", "Assert not", |
| 161 |
"AssertB", "AssertB not", "Reverse", "Once", "Cond", "Cref", |
"AssertB", "AssertB not", "Reverse", "Once", "Cond", "Cref", |
| 162 |
"Brazero", "Braminzero", "Bra" |
"Brazero", "Braminzero", "Branumber", "Bra" |
| 163 |
}; |
}; |
| 164 |
|
|
| 165 |
|
|
| 178 |
|
|
| 179 |
if (*code >= OP_BRA) |
if (*code >= OP_BRA) |
| 180 |
{ |
{ |
| 181 |
fprintf(outfile, "%3d Bra %d", (code[1] << 8) + code[2], *code - OP_BRA); |
if (*code - OP_BRA > EXTRACT_BASIC_MAX) |
| 182 |
|
fprintf(outfile, "%3d Bra extra", (code[1] << 8) + code[2]); |
| 183 |
|
else |
| 184 |
|
fprintf(outfile, "%3d Bra %d", (code[1] << 8) + code[2], *code - OP_BRA); |
| 185 |
code += 2; |
code += 2; |
| 186 |
} |
} |
| 187 |
|
|
| 197 |
code++; |
code++; |
| 198 |
break; |
break; |
| 199 |
|
|
|
case OP_COND: |
|
|
fprintf(outfile, "%3d Cond", (code[1] << 8) + code[2]); |
|
|
code += 2; |
|
|
break; |
|
|
|
|
|
case OP_CREF: |
|
|
fprintf(outfile, " %.2d %s", code[1], OP_names[*code]); |
|
|
code++; |
|
|
break; |
|
|
|
|
| 200 |
case OP_CHARS: |
case OP_CHARS: |
| 201 |
charlength = *(++code); |
charlength = *(++code); |
| 202 |
fprintf(outfile, "%3d ", charlength); |
fprintf(outfile, "%3d ", charlength); |
| 214 |
case OP_ASSERTBACK: |
case OP_ASSERTBACK: |
| 215 |
case OP_ASSERTBACK_NOT: |
case OP_ASSERTBACK_NOT: |
| 216 |
case OP_ONCE: |
case OP_ONCE: |
| 217 |
fprintf(outfile, "%3d %s", (code[1] << 8) + code[2], OP_names[*code]); |
case OP_COND: |
| 218 |
code += 2; |
case OP_BRANUMBER: |
|
break; |
|
|
|
|
| 219 |
case OP_REVERSE: |
case OP_REVERSE: |
| 220 |
|
case OP_CREF: |
| 221 |
fprintf(outfile, "%3d %s", (code[1] << 8) + code[2], OP_names[*code]); |
fprintf(outfile, "%3d %s", (code[1] << 8) + code[2], OP_names[*code]); |
| 222 |
code += 2; |
code += 2; |
| 223 |
break; |
break; |
| 290 |
break; |
break; |
| 291 |
|
|
| 292 |
case OP_REF: |
case OP_REF: |
| 293 |
fprintf(outfile, " \\%d", *(++code)); |
fprintf(outfile, " \\%d", (code[1] << 8) | code[2]); |
| 294 |
code++; |
code += 3; |
| 295 |
goto CLASS_REF_REPEAT; |
goto CLASS_REF_REPEAT; |
| 296 |
|
|
| 297 |
case OP_CLASS: |
case OP_CLASS: |
| 433 |
int timeit = 0; |
int timeit = 0; |
| 434 |
int showinfo = 0; |
int showinfo = 0; |
| 435 |
int showstore = 0; |
int showstore = 0; |
| 436 |
|
int size_offsets = 45; |
| 437 |
|
int size_offsets_max; |
| 438 |
|
int *offsets; |
| 439 |
|
#if !defined NOPOSIX |
| 440 |
int posix = 0; |
int posix = 0; |
| 441 |
|
#endif |
| 442 |
int debug = 0; |
int debug = 0; |
| 443 |
int done = 0; |
int done = 0; |
| 444 |
unsigned char buffer[30000]; |
unsigned char buffer[30000]; |
| 452 |
|
|
| 453 |
while (argc > 1 && argv[op][0] == '-') |
while (argc > 1 && argv[op][0] == '-') |
| 454 |
{ |
{ |
| 455 |
|
char *endptr; |
| 456 |
|
|
| 457 |
if (strcmp(argv[op], "-s") == 0 || strcmp(argv[op], "-m") == 0) |
if (strcmp(argv[op], "-s") == 0 || strcmp(argv[op], "-m") == 0) |
| 458 |
showstore = 1; |
showstore = 1; |
| 459 |
else if (strcmp(argv[op], "-t") == 0) timeit = 1; |
else if (strcmp(argv[op], "-t") == 0) timeit = 1; |
| 460 |
else if (strcmp(argv[op], "-i") == 0) showinfo = 1; |
else if (strcmp(argv[op], "-i") == 0) showinfo = 1; |
| 461 |
else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1; |
else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1; |
| 462 |
|
else if (strcmp(argv[op], "-o") == 0 && argc > 2 && |
| 463 |
|
((size_offsets = strtoul(argv[op+1], &endptr, 10)), *endptr == 0)) |
| 464 |
|
{ |
| 465 |
|
op++; |
| 466 |
|
argc--; |
| 467 |
|
} |
| 468 |
|
#if !defined NOPOSIX |
| 469 |
else if (strcmp(argv[op], "-p") == 0) posix = 1; |
else if (strcmp(argv[op], "-p") == 0) posix = 1; |
| 470 |
|
#endif |
| 471 |
else |
else |
| 472 |
{ |
{ |
| 473 |
printf("*** Unknown option %s\n", argv[op]); |
printf("** Unknown or malformed option %s\n", argv[op]); |
| 474 |
printf("Usage: pcretest [-d] [-i] [-p] [-s] [-t] [<input> [<output>]]\n"); |
printf("Usage: pcretest [-d] [-i] [-o <n>] [-p] [-s] [-t] [<input> [<output>]]\n"); |
| 475 |
printf(" -d debug: show compiled code; implies -i\n" |
printf(" -d debug: show compiled code; implies -i\n" |
| 476 |
" -i show information about compiled pattern\n" |
" -i show information about compiled pattern\n" |
| 477 |
" -p use POSIX interface\n" |
" -o <n> set size of offsets vector to <n>\n"); |
| 478 |
" -s output store information\n" |
#if !defined NOPOSIX |
| 479 |
" -t time compilation and execution\n"); |
printf(" -p use POSIX interface\n"); |
| 480 |
|
#endif |
| 481 |
|
printf(" -s output store information\n" |
| 482 |
|
" -t time compilation and execution\n"); |
| 483 |
return 1; |
return 1; |
| 484 |
} |
} |
| 485 |
op++; |
op++; |
| 486 |
argc--; |
argc--; |
| 487 |
} |
} |
| 488 |
|
|
| 489 |
|
/* Get the store for the offsets vector, and remember what it was */ |
| 490 |
|
|
| 491 |
|
size_offsets_max = size_offsets; |
| 492 |
|
offsets = malloc(size_offsets_max * sizeof(int)); |
| 493 |
|
if (offsets == NULL) |
| 494 |
|
{ |
| 495 |
|
printf("** Failed to get %d bytes of memory for offsets vector\n", |
| 496 |
|
size_offsets_max * sizeof(int)); |
| 497 |
|
return 1; |
| 498 |
|
} |
| 499 |
|
|
| 500 |
/* Sort out the input and output files */ |
/* Sort out the input and output files */ |
| 501 |
|
|
| 502 |
if (argc > 1) |
if (argc > 1) |
| 541 |
|
|
| 542 |
const char *error; |
const char *error; |
| 543 |
unsigned char *p, *pp, *ppp; |
unsigned char *p, *pp, *ppp; |
| 544 |
unsigned const char *tables = NULL; |
const unsigned char *tables = NULL; |
| 545 |
int do_study = 0; |
int do_study = 0; |
| 546 |
int do_debug = debug; |
int do_debug = debug; |
| 547 |
int do_G = 0; |
int do_G = 0; |
| 741 |
|
|
| 742 |
if (do_showinfo) |
if (do_showinfo) |
| 743 |
{ |
{ |
| 744 |
|
unsigned long int get_options; |
| 745 |
int old_first_char, old_options, old_count; |
int old_first_char, old_options, old_count; |
| 746 |
int count, backrefmax, first_char, need_char; |
int count, backrefmax, first_char, need_char; |
| 747 |
size_t size; |
size_t size; |
| 748 |
|
|
| 749 |
if (do_debug) print_internals(re); |
if (do_debug) print_internals(re); |
| 750 |
|
|
| 751 |
new_info(re, NULL, PCRE_INFO_OPTIONS, &options); |
new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options); |
| 752 |
new_info(re, NULL, PCRE_INFO_SIZE, &size); |
new_info(re, NULL, PCRE_INFO_SIZE, &size); |
| 753 |
new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count); |
new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count); |
| 754 |
new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax); |
new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax); |
| 768 |
"First char disagreement: pcre_fullinfo=%d pcre_info=%d\n", |
"First char disagreement: pcre_fullinfo=%d pcre_info=%d\n", |
| 769 |
first_char, old_first_char); |
first_char, old_first_char); |
| 770 |
|
|
| 771 |
if (old_options != options) fprintf(outfile, |
if (old_options != (int)get_options) fprintf(outfile, |
| 772 |
"Options disagreement: pcre_fullinfo=%d pcre_info=%d\n", options, |
"Options disagreement: pcre_fullinfo=%ld pcre_info=%d\n", |
| 773 |
old_options); |
get_options, old_options); |
| 774 |
} |
} |
| 775 |
|
|
| 776 |
if (size != gotten_store) fprintf(outfile, |
if (size != gotten_store) fprintf(outfile, |
| 780 |
fprintf(outfile, "Capturing subpattern count = %d\n", count); |
fprintf(outfile, "Capturing subpattern count = %d\n", count); |
| 781 |
if (backrefmax > 0) |
if (backrefmax > 0) |
| 782 |
fprintf(outfile, "Max back reference = %d\n", backrefmax); |
fprintf(outfile, "Max back reference = %d\n", backrefmax); |
| 783 |
if (options == 0) fprintf(outfile, "No options\n"); |
if (get_options == 0) fprintf(outfile, "No options\n"); |
| 784 |
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\n", |
| 785 |
((options & PCRE_ANCHORED) != 0)? " anchored" : "", |
((get_options & PCRE_ANCHORED) != 0)? " anchored" : "", |
| 786 |
((options & PCRE_CASELESS) != 0)? " caseless" : "", |
((get_options & PCRE_CASELESS) != 0)? " caseless" : "", |
| 787 |
((options & PCRE_EXTENDED) != 0)? " extended" : "", |
((get_options & PCRE_EXTENDED) != 0)? " extended" : "", |
| 788 |
((options & PCRE_MULTILINE) != 0)? " multiline" : "", |
((get_options & PCRE_MULTILINE) != 0)? " multiline" : "", |
| 789 |
((options & PCRE_DOTALL) != 0)? " dotall" : "", |
((get_options & PCRE_DOTALL) != 0)? " dotall" : "", |
| 790 |
((options & PCRE_DOLLAR_ENDONLY) != 0)? " dollar_endonly" : "", |
((get_options & PCRE_DOLLAR_ENDONLY) != 0)? " dollar_endonly" : "", |
| 791 |
((options & PCRE_EXTRA) != 0)? " extra" : "", |
((get_options & PCRE_EXTRA) != 0)? " extra" : "", |
| 792 |
((options & PCRE_UNGREEDY) != 0)? " ungreedy" : "", |
((get_options & PCRE_UNGREEDY) != 0)? " ungreedy" : "", |
| 793 |
((options & PCRE_UTF8) != 0)? " utf8" : ""); |
((get_options & PCRE_UTF8) != 0)? " utf8" : ""); |
| 794 |
|
|
| 795 |
if (((((real_pcre *)re)->options) & PCRE_ICHANGED) != 0) |
if (((((real_pcre *)re)->options) & PCRE_ICHANGED) != 0) |
| 796 |
fprintf(outfile, "Case state changes\n"); |
fprintf(outfile, "Case state changes\n"); |
| 893 |
{ |
{ |
| 894 |
unsigned char *q; |
unsigned char *q; |
| 895 |
unsigned char *bptr = dbuffer; |
unsigned char *bptr = dbuffer; |
| 896 |
|
int *use_offsets = offsets; |
| 897 |
|
int use_size_offsets = size_offsets; |
| 898 |
int count, c; |
int count, c; |
| 899 |
int copystrings = 0; |
int copystrings = 0; |
| 900 |
int getstrings = 0; |
int getstrings = 0; |
| 902 |
int gmatched = 0; |
int gmatched = 0; |
| 903 |
int start_offset = 0; |
int start_offset = 0; |
| 904 |
int g_notempty = 0; |
int g_notempty = 0; |
|
int offsets[45]; |
|
|
int size_offsets = sizeof(offsets)/sizeof(int); |
|
| 905 |
|
|
| 906 |
options = 0; |
options = 0; |
| 907 |
|
|
| 1009 |
|
|
| 1010 |
case 'O': |
case 'O': |
| 1011 |
while(isdigit(*p)) n = n * 10 + *p++ - '0'; |
while(isdigit(*p)) n = n * 10 + *p++ - '0'; |
| 1012 |
if (n <= (int)(sizeof(offsets)/sizeof(int))) size_offsets = n; |
if (n > size_offsets_max) |
| 1013 |
|
{ |
| 1014 |
|
size_offsets_max = n; |
| 1015 |
|
free(offsets); |
| 1016 |
|
use_offsets = offsets = malloc(size_offsets_max * sizeof(int)); |
| 1017 |
|
if (offsets == NULL) |
| 1018 |
|
{ |
| 1019 |
|
printf("** Failed to get %d bytes of memory for offsets vector\n", |
| 1020 |
|
size_offsets_max * sizeof(int)); |
| 1021 |
|
return 1; |
| 1022 |
|
} |
| 1023 |
|
} |
| 1024 |
|
use_size_offsets = n; |
| 1025 |
|
if (n == 0) use_offsets = NULL; |
| 1026 |
continue; |
continue; |
| 1027 |
|
|
| 1028 |
case 'Z': |
case 'Z': |
| 1042 |
{ |
{ |
| 1043 |
int rc; |
int rc; |
| 1044 |
int eflags = 0; |
int eflags = 0; |
| 1045 |
regmatch_t pmatch[sizeof(offsets)/sizeof(int)]; |
regmatch_t *pmatch = malloc(sizeof(regmatch_t) * use_size_offsets); |
| 1046 |
if ((options & PCRE_NOTBOL) != 0) eflags |= REG_NOTBOL; |
if ((options & PCRE_NOTBOL) != 0) eflags |= REG_NOTBOL; |
| 1047 |
if ((options & PCRE_NOTEOL) != 0) eflags |= REG_NOTEOL; |
if ((options & PCRE_NOTEOL) != 0) eflags |= REG_NOTEOL; |
| 1048 |
|
|
| 1049 |
rc = regexec(&preg, (const char *)bptr, size_offsets, pmatch, eflags); |
rc = regexec(&preg, (const char *)bptr, use_size_offsets, pmatch, eflags); |
| 1050 |
|
|
| 1051 |
if (rc != 0) |
if (rc != 0) |
| 1052 |
{ |
{ |
| 1056 |
else |
else |
| 1057 |
{ |
{ |
| 1058 |
size_t i; |
size_t i; |
| 1059 |
for (i = 0; i < size_offsets; i++) |
for (i = 0; i < use_size_offsets; i++) |
| 1060 |
{ |
{ |
| 1061 |
if (pmatch[i].rm_so >= 0) |
if (pmatch[i].rm_so >= 0) |
| 1062 |
{ |
{ |
| 1073 |
} |
} |
| 1074 |
} |
} |
| 1075 |
} |
} |
| 1076 |
|
free(pmatch); |
| 1077 |
} |
} |
| 1078 |
|
|
| 1079 |
/* Handle matching via the native interface - repeats for /g and /G */ |
/* Handle matching via the native interface - repeats for /g and /G */ |
| 1090 |
clock_t start_time = clock(); |
clock_t start_time = clock(); |
| 1091 |
for (i = 0; i < LOOPREPEAT; i++) |
for (i = 0; i < LOOPREPEAT; i++) |
| 1092 |
count = pcre_exec(re, extra, (char *)bptr, len, |
count = pcre_exec(re, extra, (char *)bptr, len, |
| 1093 |
start_offset, options | g_notempty, offsets, size_offsets); |
start_offset, options | g_notempty, use_offsets, use_size_offsets); |
| 1094 |
time_taken = clock() - start_time; |
time_taken = clock() - start_time; |
| 1095 |
fprintf(outfile, "Execute time %.3f milliseconds\n", |
fprintf(outfile, "Execute time %.3f milliseconds\n", |
| 1096 |
((double)time_taken * 1000.0)/ |
((double)time_taken * 1000.0)/ |
| 1098 |
} |
} |
| 1099 |
|
|
| 1100 |
count = pcre_exec(re, extra, (char *)bptr, len, |
count = pcre_exec(re, extra, (char *)bptr, len, |
| 1101 |
start_offset, options | g_notempty, offsets, size_offsets); |
start_offset, options | g_notempty, use_offsets, use_size_offsets); |
| 1102 |
|
|
| 1103 |
if (count == 0) |
if (count == 0) |
| 1104 |
{ |
{ |
| 1105 |
fprintf(outfile, "Matched, but too many substrings\n"); |
fprintf(outfile, "Matched, but too many substrings\n"); |
| 1106 |
count = size_offsets/3; |
count = use_size_offsets/3; |
| 1107 |
} |
} |
| 1108 |
|
|
| 1109 |
/* Matched */ |
/* Matched */ |
| 1113 |
int i; |
int i; |
| 1114 |
for (i = 0; i < count * 2; i += 2) |
for (i = 0; i < count * 2; i += 2) |
| 1115 |
{ |
{ |
| 1116 |
if (offsets[i] < 0) |
if (use_offsets[i] < 0) |
| 1117 |
fprintf(outfile, "%2d: <unset>\n", i/2); |
fprintf(outfile, "%2d: <unset>\n", i/2); |
| 1118 |
else |
else |
| 1119 |
{ |
{ |
| 1120 |
fprintf(outfile, "%2d: ", i/2); |
fprintf(outfile, "%2d: ", i/2); |
| 1121 |
pchars(bptr + offsets[i], offsets[i+1] - offsets[i], utf8); |
pchars(bptr + use_offsets[i], use_offsets[i+1] - use_offsets[i], utf8); |
| 1122 |
fprintf(outfile, "\n"); |
fprintf(outfile, "\n"); |
| 1123 |
if (i == 0) |
if (i == 0) |
| 1124 |
{ |
{ |
| 1125 |
if (do_showrest) |
if (do_showrest) |
| 1126 |
{ |
{ |
| 1127 |
fprintf(outfile, " 0+ "); |
fprintf(outfile, " 0+ "); |
| 1128 |
pchars(bptr + offsets[i+1], len - offsets[i+1], utf8); |
pchars(bptr + use_offsets[i+1], len - use_offsets[i+1], utf8); |
| 1129 |
fprintf(outfile, "\n"); |
fprintf(outfile, "\n"); |
| 1130 |
} |
} |
| 1131 |
} |
} |
| 1137 |
if ((copystrings & (1 << i)) != 0) |
if ((copystrings & (1 << i)) != 0) |
| 1138 |
{ |
{ |
| 1139 |
char copybuffer[16]; |
char copybuffer[16]; |
| 1140 |
int rc = pcre_copy_substring((char *)bptr, offsets, count, |
int rc = pcre_copy_substring((char *)bptr, use_offsets, count, |
| 1141 |
i, copybuffer, sizeof(copybuffer)); |
i, copybuffer, sizeof(copybuffer)); |
| 1142 |
if (rc < 0) |
if (rc < 0) |
| 1143 |
fprintf(outfile, "copy substring %d failed %d\n", i, rc); |
fprintf(outfile, "copy substring %d failed %d\n", i, rc); |
| 1151 |
if ((getstrings & (1 << i)) != 0) |
if ((getstrings & (1 << i)) != 0) |
| 1152 |
{ |
{ |
| 1153 |
const char *substring; |
const char *substring; |
| 1154 |
int rc = pcre_get_substring((char *)bptr, offsets, count, |
int rc = pcre_get_substring((char *)bptr, use_offsets, count, |
| 1155 |
i, &substring); |
i, &substring); |
| 1156 |
if (rc < 0) |
if (rc < 0) |
| 1157 |
fprintf(outfile, "get substring %d failed %d\n", i, rc); |
fprintf(outfile, "get substring %d failed %d\n", i, rc); |
| 1167 |
if (getlist) |
if (getlist) |
| 1168 |
{ |
{ |
| 1169 |
const char **stringlist; |
const char **stringlist; |
| 1170 |
int rc = pcre_get_substring_list((char *)bptr, offsets, count, |
int rc = pcre_get_substring_list((char *)bptr, use_offsets, count, |
| 1171 |
&stringlist); |
&stringlist); |
| 1172 |
if (rc < 0) |
if (rc < 0) |
| 1173 |
fprintf(outfile, "get substring list failed %d\n", rc); |
fprintf(outfile, "get substring list failed %d\n", rc); |
| 1193 |
{ |
{ |
| 1194 |
if (g_notempty != 0) |
if (g_notempty != 0) |
| 1195 |
{ |
{ |
| 1196 |
offsets[0] = start_offset; |
use_offsets[0] = start_offset; |
| 1197 |
offsets[1] = start_offset + 1; |
use_offsets[1] = start_offset + 1; |
| 1198 |
} |
} |
| 1199 |
else |
else |
| 1200 |
{ |
{ |
| 1219 |
character. */ |
character. */ |
| 1220 |
|
|
| 1221 |
g_notempty = 0; |
g_notempty = 0; |
| 1222 |
if (offsets[0] == offsets[1]) |
if (use_offsets[0] == use_offsets[1]) |
| 1223 |
{ |
{ |
| 1224 |
if (offsets[0] == len) break; |
if (use_offsets[0] == len) break; |
| 1225 |
g_notempty = PCRE_NOTEMPTY | PCRE_ANCHORED; |
g_notempty = PCRE_NOTEMPTY | PCRE_ANCHORED; |
| 1226 |
} |
} |
| 1227 |
|
|
| 1228 |
/* For /g, update the start offset, leaving the rest alone */ |
/* For /g, update the start offset, leaving the rest alone */ |
| 1229 |
|
|
| 1230 |
if (do_g) start_offset = offsets[1]; |
if (do_g) start_offset = use_offsets[1]; |
| 1231 |
|
|
| 1232 |
/* For /G, update the pointer and length */ |
/* For /G, update the pointer and length */ |
| 1233 |
|
|
| 1234 |
else |
else |
| 1235 |
{ |
{ |
| 1236 |
bptr += offsets[1]; |
bptr += use_offsets[1]; |
| 1237 |
len -= offsets[1]; |
len -= use_offsets[1]; |
| 1238 |
} |
} |
| 1239 |
} /* End of loop for /g and /G */ |
} /* End of loop for /g and /G */ |
| 1240 |
} /* End of loop for data lines */ |
} /* End of loop for data lines */ |