22 |
#endif |
#endif |
23 |
#endif |
#endif |
24 |
|
|
25 |
#define LOOPREPEAT 10000 |
#define LOOPREPEAT 20000 |
26 |
|
|
27 |
|
|
28 |
static FILE *outfile; |
static FILE *outfile; |
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 |
|
|
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; |
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; |
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 |
|
|
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); |
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; |
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++) |
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; |
517 |
if (re != NULL) free(re); |
if (re != NULL) free(re); |
518 |
} |
} |
519 |
time_taken = clock() - start_time; |
time_taken = clock() - start_time; |
520 |
fprintf(outfile, "Compile time %.2f milliseconds\n", |
fprintf(outfile, "Compile time %.3f milliseconds\n", |
521 |
((double)time_taken)/(4 * CLOCKS_PER_SEC)); |
((double)time_taken * 1000.0) / |
522 |
|
((double)LOOPREPEAT * (double)CLOCKS_PER_SEC)); |
523 |
} |
} |
524 |
|
|
525 |
re = pcre_compile((char *)p, options, &error, &erroroffset, tables); |
re = pcre_compile((char *)p, options, &error, &erroroffset, tables); |
605 |
extra = pcre_study(re, study_options, &error); |
extra = pcre_study(re, study_options, &error); |
606 |
time_taken = clock() - start_time; |
time_taken = clock() - start_time; |
607 |
if (extra != NULL) free(extra); |
if (extra != NULL) free(extra); |
608 |
fprintf(outfile, " Study time %.2f milliseconds\n", |
fprintf(outfile, " Study time %.3f milliseconds\n", |
609 |
((double)time_taken)/(4 * CLOCKS_PER_SEC)); |
((double)time_taken * 1000.0)/ |
610 |
|
((double)LOOPREPEAT * (double)CLOCKS_PER_SEC)); |
611 |
} |
} |
612 |
|
|
613 |
extra = pcre_study(re, study_options, &error); |
extra = pcre_study(re, study_options, &error); |
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 |
|
|
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; |
802 |
register int i; |
register int i; |
803 |
clock_t time_taken; |
clock_t time_taken; |
804 |
clock_t start_time = clock(); |
clock_t start_time = clock(); |
805 |
for (i = 0; i < 4000; i++) |
for (i = 0; i < LOOPREPEAT; i++) |
806 |
count = pcre_exec(re, extra, (char *)dbuffer, len, options, offsets, |
count = pcre_exec(re, extra, (char *)dbuffer, len, options, offsets, |
807 |
size_offsets); |
size_offsets); |
808 |
time_taken = clock() - start_time; |
time_taken = clock() - start_time; |
809 |
fprintf(outfile, "Execute time %.2f milliseconds\n", |
fprintf(outfile, "Execute time %.3f milliseconds\n", |
810 |
((double)time_taken)/(4 * CLOCKS_PER_SEC)); |
((double)time_taken * 1000.0)/ |
811 |
|
((double)LOOPREPEAT * (double)CLOCKS_PER_SEC)); |
812 |
} |
} |
813 |
|
|
814 |
count = pcre_exec(re, extra, (char *)dbuffer, len, options, offsets, |
count = pcre_exec(re, extra, (char *)dbuffer, len, options, offsets, |
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); |
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 |
{ |
{ |