| 12 |
/* Use the internal info for displaying the results of pcre_study(). */ |
/* Use the internal info for displaying the results of pcre_study(). */ |
| 13 |
|
|
| 14 |
#include "internal.h" |
#include "internal.h" |
| 15 |
|
|
| 16 |
|
/* It is possible to compile this test program without including support for |
| 17 |
|
testing the POSIX interface, though this is not available via the standard |
| 18 |
|
Makefile. */ |
| 19 |
|
|
| 20 |
|
#if !defined NOPOSIX |
| 21 |
#include "pcreposix.h" |
#include "pcreposix.h" |
| 22 |
|
#endif |
| 23 |
|
|
| 24 |
#ifndef CLOCKS_PER_SEC |
#ifndef CLOCKS_PER_SEC |
| 25 |
#ifdef CLK_TCK |
#ifdef CLK_TCK |
| 55 |
}; |
}; |
| 56 |
|
|
| 57 |
|
|
| 58 |
static void print_internals(pcre *re, FILE *outfile) |
static void print_internals(pcre *re) |
| 59 |
{ |
{ |
| 60 |
unsigned char *code = ((real_pcre *)re)->code; |
unsigned char *code = ((real_pcre *)re)->code; |
| 61 |
|
|
| 373 |
{ |
{ |
| 374 |
pcre *re = NULL; |
pcre *re = NULL; |
| 375 |
pcre_extra *extra = NULL; |
pcre_extra *extra = NULL; |
| 376 |
|
|
| 377 |
|
#if !defined NOPOSIX /* There are still compilers that require no indent */ |
| 378 |
regex_t preg; |
regex_t preg; |
| 379 |
|
#endif |
| 380 |
|
|
| 381 |
const char *error; |
const char *error; |
| 382 |
unsigned char *p, *pp, *ppp; |
unsigned char *p, *pp, *ppp; |
| 383 |
unsigned const char *tables = NULL; |
unsigned const char *tables = NULL; |
| 471 |
case 'G': do_G = 1; break; |
case 'G': do_G = 1; break; |
| 472 |
case 'I': do_showinfo = 1; break; |
case 'I': do_showinfo = 1; break; |
| 473 |
case 'M': log_store = 1; break; |
case 'M': log_store = 1; break; |
| 474 |
|
|
| 475 |
|
#if !defined NOPOSIX |
| 476 |
case 'P': do_posix = 1; break; |
case 'P': do_posix = 1; break; |
| 477 |
|
#endif |
| 478 |
|
|
| 479 |
case 'S': do_study = 1; break; |
case 'S': do_study = 1; break; |
| 480 |
case 'U': options |= PCRE_UNGREEDY; break; |
case 'U': options |= PCRE_UNGREEDY; break; |
| 481 |
case 'X': options |= PCRE_EXTRA; break; |
case 'X': options |= PCRE_EXTRA; break; |
| 504 |
timing, showing, or debugging options, nor the ability to pass over |
timing, showing, or debugging options, nor the ability to pass over |
| 505 |
local character tables. */ |
local character tables. */ |
| 506 |
|
|
| 507 |
|
#if !defined NOPOSIX |
| 508 |
if (posix || do_posix) |
if (posix || do_posix) |
| 509 |
{ |
{ |
| 510 |
int rc; |
int rc; |
| 527 |
/* Handle compiling via the native interface */ |
/* Handle compiling via the native interface */ |
| 528 |
|
|
| 529 |
else |
else |
| 530 |
|
#endif /* !defined NOPOSIX */ |
| 531 |
|
|
| 532 |
{ |
{ |
| 533 |
if (timeit) |
if (timeit) |
| 534 |
{ |
{ |
| 579 |
{ |
{ |
| 580 |
int first_char, count; |
int first_char, count; |
| 581 |
|
|
| 582 |
if (do_debug) print_internals(re, outfile); |
if (do_debug) print_internals(re); |
| 583 |
|
|
| 584 |
count = pcre_info(re, &options, &first_char); |
count = pcre_info(re, &options, &first_char); |
| 585 |
if (count < 0) fprintf(outfile, |
if (count < 0) fprintf(outfile, |
| 597 |
((options & PCRE_DOLLAR_ENDONLY) != 0)? " dollar_endonly" : "", |
((options & PCRE_DOLLAR_ENDONLY) != 0)? " dollar_endonly" : "", |
| 598 |
((options & PCRE_EXTRA) != 0)? " extra" : "", |
((options & PCRE_EXTRA) != 0)? " extra" : "", |
| 599 |
((options & PCRE_UNGREEDY) != 0)? " ungreedy" : ""); |
((options & PCRE_UNGREEDY) != 0)? " ungreedy" : ""); |
| 600 |
|
|
| 601 |
|
if (((((real_pcre *)re)->options) & PCRE_ICHANGED) != 0) |
| 602 |
|
fprintf(outfile, "Case state changes\n"); |
| 603 |
|
|
| 604 |
if (first_char == -1) |
if (first_char == -1) |
| 605 |
{ |
{ |
| 606 |
fprintf(outfile, "First char at start or follows \\n\n"); |
fprintf(outfile, "First char at start or follows \\n\n"); |
| 616 |
else |
else |
| 617 |
fprintf(outfile, "First char = %d\n", first_char); |
fprintf(outfile, "First char = %d\n", first_char); |
| 618 |
} |
} |
| 619 |
|
|
| 620 |
|
if (((((real_pcre *)re)->options) & PCRE_REQCHSET) != 0) |
| 621 |
|
{ |
| 622 |
|
int req_char = ((real_pcre *)re)->req_char; |
| 623 |
|
if (isprint(req_char)) |
| 624 |
|
fprintf(outfile, "Req char = \'%c\'\n", req_char); |
| 625 |
|
else |
| 626 |
|
fprintf(outfile, "Req char = %d\n", req_char); |
| 627 |
|
} |
| 628 |
|
else fprintf(outfile, "No req char\n"); |
| 629 |
} |
} |
| 630 |
} |
} |
| 631 |
|
|
| 784 |
getlist = 1; |
getlist = 1; |
| 785 |
continue; |
continue; |
| 786 |
|
|
| 787 |
|
case 'N': |
| 788 |
|
options |= PCRE_NOTEMPTY; |
| 789 |
|
continue; |
| 790 |
|
|
| 791 |
case 'O': |
case 'O': |
| 792 |
while(isdigit(*p)) n = n * 10 + *p++ - '0'; |
while(isdigit(*p)) n = n * 10 + *p++ - '0'; |
| 793 |
if (n <= (int)(sizeof(offsets)/sizeof(int))) size_offsets = n; |
if (n <= (int)(sizeof(offsets)/sizeof(int))) size_offsets = n; |
| 805 |
/* Handle matching via the POSIX interface, which does not |
/* Handle matching via the POSIX interface, which does not |
| 806 |
support timing. */ |
support timing. */ |
| 807 |
|
|
| 808 |
|
#if !defined NOPOSIX |
| 809 |
if (posix || do_posix) |
if (posix || do_posix) |
| 810 |
{ |
{ |
| 811 |
int rc; |
int rc; |
| 814 |
if ((options & PCRE_NOTBOL) != 0) eflags |= REG_NOTBOL; |
if ((options & PCRE_NOTBOL) != 0) eflags |= REG_NOTBOL; |
| 815 |
if ((options & PCRE_NOTEOL) != 0) eflags |= REG_NOTEOL; |
if ((options & PCRE_NOTEOL) != 0) eflags |= REG_NOTEOL; |
| 816 |
|
|
| 817 |
rc = regexec(&preg, (unsigned char *)bptr, |
rc = regexec(&preg, (const char *)bptr, |
| 818 |
sizeof(pmatch)/sizeof(regmatch_t), pmatch, eflags); |
sizeof(pmatch)/sizeof(regmatch_t), pmatch, eflags); |
| 819 |
|
|
| 820 |
if (rc != 0) |
if (rc != 0) |
| 846 |
|
|
| 847 |
/* Handle matching via the native interface - repeats for /g and /G */ |
/* Handle matching via the native interface - repeats for /g and /G */ |
| 848 |
|
|
| 849 |
else for (;;) |
else |
| 850 |
|
#endif /* !defined NOPOSIX */ |
| 851 |
|
|
| 852 |
|
for (;;) |
| 853 |
{ |
{ |
| 854 |
if (timeit) |
if (timeit) |
| 855 |
{ |
{ |
| 903 |
{ |
{ |
| 904 |
if ((copystrings & (1 << i)) != 0) |
if ((copystrings & (1 << i)) != 0) |
| 905 |
{ |
{ |
| 906 |
char buffer[16]; |
char copybuffer[16]; |
| 907 |
int rc = pcre_copy_substring((char *)bptr, offsets, count, |
int rc = pcre_copy_substring((char *)bptr, offsets, count, |
| 908 |
i, buffer, sizeof(buffer)); |
i, copybuffer, sizeof(copybuffer)); |
| 909 |
if (rc < 0) |
if (rc < 0) |
| 910 |
fprintf(outfile, "copy substring %d failed %d\n", i, rc); |
fprintf(outfile, "copy substring %d failed %d\n", i, rc); |
| 911 |
else |
else |
| 912 |
fprintf(outfile, "%2dC %s (%d)\n", i, buffer, rc); |
fprintf(outfile, "%2dC %s (%d)\n", i, copybuffer, rc); |
| 913 |
} |
} |
| 914 |
} |
} |
| 915 |
|
|
| 968 |
} |
} |
| 969 |
|
|
| 970 |
CONTINUE: |
CONTINUE: |
| 971 |
|
|
| 972 |
|
#if !defined NOPOSIX |
| 973 |
if (posix || do_posix) regfree(&preg); |
if (posix || do_posix) regfree(&preg); |
| 974 |
|
#endif |
| 975 |
|
|
| 976 |
if (re != NULL) free(re); |
if (re != NULL) free(re); |
| 977 |
if (extra != NULL) free(extra); |
if (extra != NULL) free(extra); |
| 978 |
if (tables != NULL) |
if (tables != NULL) |