| 275 |
static void *new_malloc(size_t size) |
static void *new_malloc(size_t size) |
| 276 |
{ |
{ |
| 277 |
if (log_store) |
if (log_store) |
| 278 |
fprintf(outfile, "Memory allocation request: %d (code space %d)\n", |
fprintf(outfile, "Memory allocation (code space): %d\n", |
| 279 |
(int)size, (int)size - offsetof(real_pcre, code[0])); |
(int)((int)size - offsetof(real_pcre, code[0]))); |
| 280 |
return malloc(size); |
return malloc(size); |
| 281 |
} |
} |
| 282 |
|
|
| 372 |
unsigned const char *tables = NULL; |
unsigned const char *tables = NULL; |
| 373 |
int do_study = 0; |
int do_study = 0; |
| 374 |
int do_debug = debug; |
int do_debug = debug; |
| 375 |
|
int do_G = 0; |
| 376 |
|
int do_g = 0; |
| 377 |
int do_showinfo = showinfo; |
int do_showinfo = showinfo; |
| 378 |
|
int do_showrest = 0; |
| 379 |
int do_posix = 0; |
int do_posix = 0; |
| 380 |
int erroroffset, len, delimiter; |
int erroroffset, len, delimiter; |
| 381 |
|
|
| 447 |
{ |
{ |
| 448 |
switch (*pp++) |
switch (*pp++) |
| 449 |
{ |
{ |
| 450 |
|
case 'g': do_g = 1; break; |
| 451 |
case 'i': options |= PCRE_CASELESS; break; |
case 'i': options |= PCRE_CASELESS; break; |
| 452 |
case 'm': options |= PCRE_MULTILINE; break; |
case 'm': options |= PCRE_MULTILINE; break; |
| 453 |
case 's': options |= PCRE_DOTALL; break; |
case 's': options |= PCRE_DOTALL; break; |
| 454 |
case 'x': options |= PCRE_EXTENDED; break; |
case 'x': options |= PCRE_EXTENDED; break; |
| 455 |
|
|
| 456 |
|
case '+': do_showrest = 1; break; |
| 457 |
case 'A': options |= PCRE_ANCHORED; break; |
case 'A': options |= PCRE_ANCHORED; break; |
| 458 |
case 'D': do_debug = do_showinfo = 1; break; |
case 'D': do_debug = do_showinfo = 1; break; |
| 459 |
case 'E': options |= PCRE_DOLLAR_ENDONLY; break; |
case 'E': options |= PCRE_DOLLAR_ENDONLY; break; |
| 460 |
|
case 'G': do_G = 1; break; |
| 461 |
case 'I': do_showinfo = 1; break; |
case 'I': do_showinfo = 1; break; |
| 462 |
case 'M': log_store = 1; break; |
case 'M': log_store = 1; break; |
| 463 |
case 'P': do_posix = 1; break; |
case 'P': do_posix = 1; break; |
| 667 |
for (;;) |
for (;;) |
| 668 |
{ |
{ |
| 669 |
unsigned char *q; |
unsigned char *q; |
| 670 |
|
unsigned char *bptr = dbuffer; |
| 671 |
int count, c; |
int count, c; |
| 672 |
int copystrings = 0; |
int copystrings = 0; |
| 673 |
int getstrings = 0; |
int getstrings = 0; |
| 674 |
int getlist = 0; |
int getlist = 0; |
| 675 |
|
int start_offset = 0; |
| 676 |
int offsets[45]; |
int offsets[45]; |
| 677 |
int size_offsets = sizeof(offsets)/sizeof(int); |
int size_offsets = sizeof(offsets)/sizeof(int); |
| 678 |
|
|
| 679 |
options = 0; |
options = 0; |
| 680 |
|
|
| 681 |
if (infile == stdin) printf(" data> "); |
if (infile == stdin) printf("data> "); |
| 682 |
if (fgets((char *)buffer, sizeof(buffer), infile) == NULL) |
if (fgets((char *)buffer, sizeof(buffer), infile) == NULL) |
| 683 |
{ |
{ |
| 684 |
done = 1; |
done = 1; |
| 777 |
if ((options & PCRE_NOTBOL) != 0) eflags |= REG_NOTBOL; |
if ((options & PCRE_NOTBOL) != 0) eflags |= REG_NOTBOL; |
| 778 |
if ((options & PCRE_NOTEOL) != 0) eflags |= REG_NOTEOL; |
if ((options & PCRE_NOTEOL) != 0) eflags |= REG_NOTEOL; |
| 779 |
|
|
| 780 |
rc = regexec(&preg, (char *)dbuffer, sizeof(pmatch)/sizeof(regmatch_t), |
rc = regexec(&preg, (unsigned char *)bptr, |
| 781 |
pmatch, eflags); |
sizeof(pmatch)/sizeof(regmatch_t), pmatch, eflags); |
| 782 |
|
|
| 783 |
if (rc != 0) |
if (rc != 0) |
| 784 |
{ |
{ |
| 796 |
pchars(dbuffer + pmatch[i].rm_so, |
pchars(dbuffer + pmatch[i].rm_so, |
| 797 |
pmatch[i].rm_eo - pmatch[i].rm_so); |
pmatch[i].rm_eo - pmatch[i].rm_so); |
| 798 |
fprintf(outfile, "\n"); |
fprintf(outfile, "\n"); |
| 799 |
|
if (i == 0 && do_showrest) |
| 800 |
|
{ |
| 801 |
|
fprintf(outfile, " 0+ "); |
| 802 |
|
pchars(dbuffer + pmatch[i].rm_eo, len - pmatch[i].rm_eo); |
| 803 |
|
fprintf(outfile, "\n"); |
| 804 |
|
} |
| 805 |
} |
} |
| 806 |
} |
} |
| 807 |
} |
} |
| 808 |
} |
} |
| 809 |
|
|
| 810 |
/* Handle matching via the native interface */ |
/* Handle matching via the native interface - repeats for /g and /G */ |
| 811 |
|
|
| 812 |
else |
else for (;;) |
| 813 |
{ |
{ |
| 814 |
if (timeit) |
if (timeit) |
| 815 |
{ |
{ |
| 817 |
clock_t time_taken; |
clock_t time_taken; |
| 818 |
clock_t start_time = clock(); |
clock_t start_time = clock(); |
| 819 |
for (i = 0; i < LOOPREPEAT; i++) |
for (i = 0; i < LOOPREPEAT; i++) |
| 820 |
count = pcre_exec(re, extra, (char *)dbuffer, len, options, offsets, |
count = pcre_exec(re, extra, (char *)bptr, len, |
| 821 |
size_offsets); |
(do_g? start_offset : 0), options, offsets, size_offsets); |
| 822 |
time_taken = clock() - start_time; |
time_taken = clock() - start_time; |
| 823 |
fprintf(outfile, "Execute time %.3f milliseconds\n", |
fprintf(outfile, "Execute time %.3f milliseconds\n", |
| 824 |
((double)time_taken * 1000.0)/ |
((double)time_taken * 1000.0)/ |
| 825 |
((double)LOOPREPEAT * (double)CLOCKS_PER_SEC)); |
((double)LOOPREPEAT * (double)CLOCKS_PER_SEC)); |
| 826 |
} |
} |
| 827 |
|
|
| 828 |
count = pcre_exec(re, extra, (char *)dbuffer, len, options, offsets, |
count = pcre_exec(re, extra, (char *)bptr, len, |
| 829 |
size_offsets); |
(do_g? start_offset : 0), options, offsets, size_offsets); |
| 830 |
|
|
| 831 |
if (count == 0) |
if (count == 0) |
| 832 |
{ |
{ |
| 844 |
else |
else |
| 845 |
{ |
{ |
| 846 |
fprintf(outfile, "%2d: ", i/2); |
fprintf(outfile, "%2d: ", i/2); |
| 847 |
pchars(dbuffer + offsets[i], offsets[i+1] - offsets[i]); |
pchars(bptr + offsets[i], offsets[i+1] - offsets[i]); |
| 848 |
fprintf(outfile, "\n"); |
fprintf(outfile, "\n"); |
| 849 |
|
if (i == 0) |
| 850 |
|
{ |
| 851 |
|
start_offset = offsets[1]; |
| 852 |
|
if (do_showrest) |
| 853 |
|
{ |
| 854 |
|
fprintf(outfile, " 0+ "); |
| 855 |
|
pchars(bptr + offsets[i+1], len - offsets[i+1]); |
| 856 |
|
fprintf(outfile, "\n"); |
| 857 |
|
} |
| 858 |
|
} |
| 859 |
} |
} |
| 860 |
} |
} |
| 861 |
|
|
| 864 |
if ((copystrings & (1 << i)) != 0) |
if ((copystrings & (1 << i)) != 0) |
| 865 |
{ |
{ |
| 866 |
char buffer[16]; |
char buffer[16]; |
| 867 |
int rc = pcre_copy_substring((char *)dbuffer, offsets, count, |
int rc = pcre_copy_substring((char *)bptr, offsets, count, |
| 868 |
i, buffer, sizeof(buffer)); |
i, buffer, sizeof(buffer)); |
| 869 |
if (rc < 0) |
if (rc < 0) |
| 870 |
fprintf(outfile, "copy substring %d failed %d\n", i, rc); |
fprintf(outfile, "copy substring %d failed %d\n", i, rc); |
| 878 |
if ((getstrings & (1 << i)) != 0) |
if ((getstrings & (1 << i)) != 0) |
| 879 |
{ |
{ |
| 880 |
const char *substring; |
const char *substring; |
| 881 |
int rc = pcre_get_substring((char *)dbuffer, offsets, count, |
int rc = pcre_get_substring((char *)bptr, offsets, count, |
| 882 |
i, &substring); |
i, &substring); |
| 883 |
if (rc < 0) |
if (rc < 0) |
| 884 |
fprintf(outfile, "get substring %d failed %d\n", i, rc); |
fprintf(outfile, "get substring %d failed %d\n", i, rc); |
| 893 |
if (getlist) |
if (getlist) |
| 894 |
{ |
{ |
| 895 |
const char **stringlist; |
const char **stringlist; |
| 896 |
int rc = pcre_get_substring_list((char *)dbuffer, offsets, count, |
int rc = pcre_get_substring_list((char *)bptr, offsets, count, |
| 897 |
&stringlist); |
&stringlist); |
| 898 |
if (rc < 0) |
if (rc < 0) |
| 899 |
fprintf(outfile, "get substring list failed %d\n", rc); |
fprintf(outfile, "get substring list failed %d\n", rc); |
| 910 |
} |
} |
| 911 |
else |
else |
| 912 |
{ |
{ |
| 913 |
if (count == -1) fprintf(outfile, "No match\n"); |
if (start_offset == 0) |
| 914 |
else fprintf(outfile, "Error %d\n", count); |
{ |
| 915 |
|
if (count == -1) fprintf(outfile, "No match\n"); |
| 916 |
|
else fprintf(outfile, "Error %d\n", count); |
| 917 |
|
} |
| 918 |
|
start_offset = -1; |
| 919 |
|
} |
| 920 |
|
|
| 921 |
|
if ((!do_g && !do_G) || start_offset <= 0) break; |
| 922 |
|
if (do_G) |
| 923 |
|
{ |
| 924 |
|
bptr += start_offset; |
| 925 |
|
len -= start_offset; |
| 926 |
} |
} |
| 927 |
} |
} |
| 928 |
} |
} |