summaryrefslogtreecommitdiff
path: root/pcretest.c
diff options
context:
space:
mode:
authornigel <nigel@2f5784b3-3f2a-0410-8824-cb99058d5e15>2007-02-24 21:39:21 +0000
committernigel <nigel@2f5784b3-3f2a-0410-8824-cb99058d5e15>2007-02-24 21:39:21 +0000
commit09f9da9675b33a31c605d9d1f913bc2b05522be2 (patch)
treee4e2b0bbc47b23f497e3f1b2208a9ac9a9d4ebea /pcretest.c
parent1622a3e7058dec7de74889c69595693ac0c64187 (diff)
downloadpcre-09f9da9675b33a31c605d9d1f913bc2b05522be2.tar.gz
Load pcre-3.0 into code/trunk.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@43 2f5784b3-3f2a-0410-8824-cb99058d5e15
Diffstat (limited to 'pcretest.c')
-rw-r--r--pcretest.c142
1 files changed, 93 insertions, 49 deletions
diff --git a/pcretest.c b/pcretest.c
index 8e2fe4f..b9e36e2 100644
--- a/pcretest.c
+++ b/pcretest.c
@@ -34,6 +34,7 @@ Makefile. */
static FILE *outfile;
static int log_store = 0;
+static size_t gotten_store;
@@ -48,7 +49,7 @@ static const char *OP_names[] = {
"*", "*?", "+", "+?", "?", "??", "{", "{", "{",
"*", "*?", "+", "+?", "?", "??", "{", "{", "{",
"*", "*?", "+", "+?", "?", "??", "{", "{",
- "class", "Ref",
+ "class", "Ref", "Recurse",
"Alt", "Ket", "KetRmax", "KetRmin", "Assert", "Assert not",
"AssertB", "AssertB not", "Reverse", "Once", "Cond", "Cref",
"Brazero", "Braminzero", "Bra"
@@ -281,6 +282,7 @@ compiled re. */
static void *new_malloc(size_t size)
{
+gotten_store = size;
if (log_store)
fprintf(outfile, "Memory allocation (code space): %d\n",
(int)((int)size - offsetof(real_pcre, code[0])));
@@ -289,6 +291,19 @@ return malloc(size);
+
+/* Get one piece of information from the pcre_fullinfo() function */
+
+static void new_info(pcre *re, pcre_extra *study, int option, void *ptr)
+{
+int rc;
+if ((rc = pcre_fullinfo(re, study, option, ptr)) < 0)
+ fprintf(outfile, "Error %d from pcre_fullinfo(%d)\n", rc, option);
+}
+
+
+
+
/* Read lines from named file or stdin and write to named file or stdout; lines
consist of a regular expression, in delimiters and optionally followed by
options, followed by a set of test data, terminated by an empty line. */
@@ -573,59 +588,90 @@ while (!done)
goto CONTINUE;
}
- /* Compilation succeeded; print data if required */
+ /* Compilation succeeded; print data if required. There are now two
+ info-returning functions. The old one has a limited interface and
+ returns only limited data. Check that it agrees with the newer one. */
if (do_showinfo)
{
- int first_char, count;
+ int old_first_char, old_options, old_count;
+ int count, backrefmax, first_char, need_char;
+ size_t size;
if (do_debug) print_internals(re);
- count = pcre_info(re, &options, &first_char);
+ new_info(re, NULL, PCRE_INFO_OPTIONS, &options);
+ new_info(re, NULL, PCRE_INFO_SIZE, &size);
+ new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count);
+ new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax);
+ new_info(re, NULL, PCRE_INFO_FIRSTCHAR, &first_char);
+ new_info(re, NULL, PCRE_INFO_LASTLITERAL, &need_char);
+
+ old_count = pcre_info(re, &old_options, &old_first_char);
if (count < 0) fprintf(outfile,
- "Error %d while reading info\n", count);
+ "Error %d from pcre_info()\n", count);
else
{
- fprintf(outfile, "Identifying subpattern count = %d\n", count);
- if (options == 0) fprintf(outfile, "No options\n");
- else fprintf(outfile, "Options:%s%s%s%s%s%s%s%s\n",
- ((options & PCRE_ANCHORED) != 0)? " anchored" : "",
- ((options & PCRE_CASELESS) != 0)? " caseless" : "",
- ((options & PCRE_EXTENDED) != 0)? " extended" : "",
- ((options & PCRE_MULTILINE) != 0)? " multiline" : "",
- ((options & PCRE_DOTALL) != 0)? " dotall" : "",
- ((options & PCRE_DOLLAR_ENDONLY) != 0)? " dollar_endonly" : "",
- ((options & PCRE_EXTRA) != 0)? " extra" : "",
- ((options & PCRE_UNGREEDY) != 0)? " ungreedy" : "");
-
- if (((((real_pcre *)re)->options) & PCRE_ICHANGED) != 0)
- fprintf(outfile, "Case state changes\n");
-
- if (first_char == -1)
- {
- fprintf(outfile, "First char at start or follows \\n\n");
- }
- else if (first_char < 0)
- {
- fprintf(outfile, "No first char\n");
- }
+ if (old_count != count) fprintf(outfile,
+ "Count disagreement: pcre_fullinfo=%d pcre_info=%d\n", count,
+ old_count);
+
+ if (old_first_char != first_char) fprintf(outfile,
+ "First char disagreement: pcre_fullinfo=%d pcre_info=%d\n",
+ first_char, old_first_char);
+
+ if (old_options != options) fprintf(outfile,
+ "Options disagreement: pcre_fullinfo=%d pcre_info=%d\n", options,
+ old_options);
+ }
+
+ if (size != gotten_store) fprintf(outfile,
+ "Size disagreement: pcre_fullinfo=%d call to malloc for %d\n",
+ size, gotten_store);
+
+ fprintf(outfile, "Capturing subpattern count = %d\n", count);
+ if (backrefmax > 0)
+ fprintf(outfile, "Max back reference = %d\n", backrefmax);
+ if (options == 0) fprintf(outfile, "No options\n");
+ else fprintf(outfile, "Options:%s%s%s%s%s%s%s%s\n",
+ ((options & PCRE_ANCHORED) != 0)? " anchored" : "",
+ ((options & PCRE_CASELESS) != 0)? " caseless" : "",
+ ((options & PCRE_EXTENDED) != 0)? " extended" : "",
+ ((options & PCRE_MULTILINE) != 0)? " multiline" : "",
+ ((options & PCRE_DOTALL) != 0)? " dotall" : "",
+ ((options & PCRE_DOLLAR_ENDONLY) != 0)? " dollar_endonly" : "",
+ ((options & PCRE_EXTRA) != 0)? " extra" : "",
+ ((options & PCRE_UNGREEDY) != 0)? " ungreedy" : "");
+
+ if (((((real_pcre *)re)->options) & PCRE_ICHANGED) != 0)
+ fprintf(outfile, "Case state changes\n");
+
+ if (first_char == -1)
+ {
+ fprintf(outfile, "First char at start or follows \\n\n");
+ }
+ else if (first_char < 0)
+ {
+ fprintf(outfile, "No first char\n");
+ }
+ else
+ {
+ if (isprint(first_char))
+ fprintf(outfile, "First char = \'%c\'\n", first_char);
else
- {
- if (isprint(first_char))
- fprintf(outfile, "First char = \'%c\'\n", first_char);
- else
- fprintf(outfile, "First char = %d\n", first_char);
- }
+ fprintf(outfile, "First char = %d\n", first_char);
+ }
- if (((((real_pcre *)re)->options) & PCRE_REQCHSET) != 0)
- {
- int req_char = ((real_pcre *)re)->req_char;
- if (isprint(req_char))
- fprintf(outfile, "Req char = \'%c\'\n", req_char);
- else
- fprintf(outfile, "Req char = %d\n", req_char);
- }
- else fprintf(outfile, "No req char\n");
+ if (need_char < 0)
+ {
+ fprintf(outfile, "No need char\n");
+ }
+ else
+ {
+ if (isprint(need_char))
+ fprintf(outfile, "Need char = \'%c\'\n", need_char);
+ else
+ fprintf(outfile, "Need char = %d\n", need_char);
}
}
@@ -654,13 +700,11 @@ while (!done)
else if (extra == NULL)
fprintf(outfile, "Study returned NULL\n");
- /* This looks at internal information. A bit kludgy to do it this
- way, but it is useful for testing. */
-
else if (do_showinfo)
{
- real_pcre_extra *xx = (real_pcre_extra *)extra;
- if ((xx->options & PCRE_STUDY_MAPPED) == 0)
+ uschar *start_bits = NULL;
+ new_info(re, extra, PCRE_INFO_FIRSTTABLE, &start_bits);
+ if (start_bits == NULL)
fprintf(outfile, "No starting character set\n");
else
{
@@ -669,7 +713,7 @@ while (!done)
fprintf(outfile, "Starting character set: ");
for (i = 0; i < 256; i++)
{
- if ((xx->start_bits[i/8] & (1<<(i%8))) != 0)
+ if ((start_bits[i/8] & (1<<(i%8))) != 0)
{
if (c > 75)
{