From 0641a2ef533395e53306893441828fa9f2f70721 Mon Sep 17 00:00:00 2001
From: Isaac Oscar Gariano
Date: Fri, 3 Oct 2025 16:14:18 +1000
Subject: [PATCH 1/6] Add a -c flag to pcre2test to colourise the output.
This commit makes various changes to to pcre2test to support colourising
the output, in particular, the following colour scheme is intended:
* Comments from the inputfile are in grey (but not those entered in
interactively)
* All other input is in green
* Messages related to PCRE2 api errors are in magenta
* Messages related to errors with using pcre2test itself are in red
* Timing and memory usage information is in blue
* Normal output is in your terminal's default foreground colour
* The interactive prompt is in blue
* Anything withought an explicit colour set (e.g. stuff printed by
valgrind) should be in yellow
---
src/pcre2test.c | 154 +++++++++++++++++++++++++++++++++++---------
src/pcre2test_inc.h | 42 ++++++++++--
2 files changed, 159 insertions(+), 37 deletions(-)
diff --git a/src/pcre2test.c b/src/pcre2test.c
index 787c4e54a..150c5dd78 100644
--- a/src/pcre2test.c
+++ b/src/pcre2test.c
@@ -1100,7 +1100,75 @@ is cast as needed. For long data lines it grows as necessary. */
static size_t dbuffer_size = 1u << 14; /* Initial size, bytes */
static uint8_t *dbuffer = NULL;
+/* ------------------ Colour highlighting definitions -------------------- */
+
+/* Input text that was a comment, when echoing back to the terminal */
+static int const clr_comment = 37; /* grey */
+/* Other input text that is echoed back to the terminal */
+static int const clr_input = 32; /* green */
+/* Colour of output that represents a pcre2api error */
+static int const clr_api_error = 35; /* magenta */
+/* Colour of error messages for the test script itself
+(i.e. pcr2test error, not a pcre2api error) */
+static int const clr_test_error = 31; /* red */
+/* Colour for profiling information, which doesn't have a "right" answer */
+static int const clr_profiling = 34; /* blue */
+/* Colour of normal output */
+static int const clr_output = 39; /* default foreground colour */
+/* Colour for anything not printed with an explicit colour
+(such as a valgrind errors) */
+static int const clr_unexpected = 33; /* yellow */
+
+static BOOL colour_on;
+
+/* start a block of colour (but only if colour_on) */
+static void
+colour_begin(int clr, FILE* f)
+{
+if(f != NULL && colour_on) fprintf(f, "\x1b[%dm", clr);
+}
+
+/* end a block of colour (but only if colour_on) */
+static void
+colour_end(FILE* f)
+{
+colour_begin(clr_unexpected, f);
+}
+
+/* wraps a string ltieral in blue */
+#define PROMPT(literal) (colour_on ? "\x1b[34m" literal "\x1b[m" : literal)
+
+#include
+
+/* this is the body of a variadic function that does a fprintf to the given file
+wrapped in the given colour, rerturning the result of the inner fprintf. */
+#define COLOUR_PRINTF_BODY(colour, file, fmt) \
+ { \
+ va_list args; \
+ int ret; \
+ colour_begin(colour, file); \
+ va_start(args, fmt); \
+ ret = vfprintf(file, fmt, args); \
+ va_end(args); \
+ colour_end(file); \
+ return ret; \
+ }
+
+/* cprintf is like printf, but it takes a colour and writes to outfile */
+static int
+cprintf(int colour, const char* fmt, ...) COLOUR_PRINTF_BODY(colour, outfile, fmt)
+
+/* cprintf_file is like cprintf but it takes a specific file */
+static int
+cprintf_file(FILE *file, int colour, const char* fmt, ...) COLOUR_PRINTF_BODY(colour, file, fmt)
+
+/* fatal_printf is like printf, but for printing fatal errors to stdout*/
+static int
+fatal_printf(const char* fmt, ...) COLOUR_PRINTF_BODY(clr_test_error, stderr, fmt)
+#undef COLOUR_PRINTF_BODY
+
+/* ---------------- End of colour highlighting definitions ------------------- */
/*************************************************
* Alternate character tables *
@@ -1799,7 +1867,7 @@ Returns: number of characters written
*/
static int
-pchar(uint32_t c, BOOL utf, FILE *f)
+pchar_raw(uint32_t c, BOOL utf, FILE *f)
{
int n = 0;
char tempbuffer[16];
@@ -1833,7 +1901,16 @@ if (f != NULL) n = fprintf(f, "\\x{%02x}", c);
return n >= 0 ? n : 0;
}
-
+/* like pchar but in colour */
+static int
+pchar(int clr, uint32_t c, BOOL utf, FILE *f)
+{
+int res;
+colour_begin(clr, f);
+res = pchar_raw(c, utf, f);
+colour_end(f);
+return res;
+}
/*************************************************
* Expand input buffers *
@@ -2277,9 +2354,9 @@ Returns: nothing
*/
static void
-show_controls(uint32_t controls, uint32_t controls2, const char *before)
+show_controls(int clr, uint32_t controls, uint32_t controls2, const char *before)
{
-fprintf(outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
+cprintf(clr, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
before,
((controls & CTL_AFTERTEXT) != 0)? " aftertext" : "",
((controls & CTL_ALLAFTERTEXT) != 0)? " allaftertext" : "",
@@ -2351,10 +2428,10 @@ Returns: nothing
*/
static void
-show_compile_options(uint32_t options, const char *before, const char *after)
+show_compile_options(int clr, uint32_t options, const char *before, const char *after)
{
-if (options == 0) fprintf(outfile, "%s %s", before, after);
-else fprintf(outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
+if (options == 0) cprintf(clr, "%s %s", before, after);
+else cprintf(clr, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
before,
((options & PCRE2_ALT_BSUX) != 0)? " alt_bsux" : "",
((options & PCRE2_ALT_CIRCUMFLEX) != 0)? " alt_circumflex" : "",
@@ -2406,11 +2483,11 @@ Returns: nothing
*/
static void
-show_compile_extra_options(uint32_t options, const char *before,
+show_compile_extra_options(int clr, uint32_t options, const char *before,
const char *after)
{
-if (options == 0) fprintf(outfile, "%s %s", before, after);
-else fprintf(outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
+if (options == 0) cprintf(clr, "%s %s", before, after);
+else cprintf(clr, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
before,
((options & PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK) != 0) ? " allow_lookaround_bsk" : "",
((options & PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES) != 0)? " allow_surrogate_escapes" : "",
@@ -2449,8 +2526,8 @@ Returns: nothing
static void
show_optimize_flags(uint32_t flags, const char *before, const char *after)
{
-if (flags == 0) fprintf(outfile, "%s%s", before, after);
-else fprintf(outfile, "%s%s%s%s%s%s%s",
+if (flags == 0) cprintf(clr_output, "%s%s", before, after);
+else cprintf(clr_output, "%s%s%s%s%s%s%s",
before,
((flags & PCRE2_OPTIM_AUTO_POSSESS) != 0) ? "auto_possess" : "",
((flags & PCRE2_OPTIM_AUTO_POSSESS) != 0 && (flags >> 1) != 0) ? "," : "",
@@ -2469,9 +2546,9 @@ else fprintf(outfile, "%s%s%s%s%s%s%s",
/* Called for unsupported POSIX options. */
static void
-show_match_options(uint32_t options)
+show_match_options(int clr, uint32_t options)
{
-fprintf(outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
+cprintf(clr, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
((options & PCRE2_ANCHORED) != 0)? " anchored" : "",
((options & PCRE2_COPY_MATCHED_SUBJECT) != 0)? " copy_matched_subject" : "",
((options & PCRE2_DFA_RESTART) != 0)? " dfa_restart" : "",
@@ -2893,16 +2970,16 @@ DISPATCH(, unittest_, ());
*************************************************/
static void
-print_version(FILE *f, BOOL include_mode)
+print_version(BOOL include_mode)
{
char buf[VERSION_SIZE];
config_str(PCRE2_CONFIG_VERSION, buf);
-fprintf(f, "PCRE2 version %s", buf);
+cprintf_file(stdout, clr_output, "PCRE2 version %s", buf);
if (include_mode)
{
- fprintf(f, " (%d-bit)", test_mode);
+ cprintf_file(stdout, clr_output, " (%d-bit)", test_mode);
}
-fprintf(f, "\n");
+cprintf_file(stdout, clr_output, "\n");
}
@@ -2912,11 +2989,11 @@ fprintf(f, "\n");
*************************************************/
static void
-print_unicode_version(FILE *f)
+print_unicode_version(void)
{
char buf[VERSION_SIZE];
config_str(PCRE2_CONFIG_UNICODE_VERSION, buf);
-fprintf(f, "Unicode version %s", buf);
+cprintf(clr_output, "Unicode version %s", buf);
}
@@ -2926,11 +3003,11 @@ fprintf(f, "Unicode version %s", buf);
*************************************************/
static void
-print_jit_target(FILE *f)
+print_jit_target(void)
{
char buf[VERSION_SIZE];
config_str(PCRE2_CONFIG_JITTARGET, buf);
-fputs(buf, f);
+cprintf(clr_output, "%s", buf);
}
@@ -2986,6 +3063,7 @@ printf(" -32 use the 32-bit library\n");
printf(" -ac set default pattern modifier PCRE2_AUTO_CALLOUT\n");
printf(" -AC as -ac, but also set subject 'callout_extra' modifier\n");
printf(" -b set default pattern modifier 'fullbincode'\n");
+printf(" -c show output in colour\n");
printf(" -C show PCRE2 compile-time options and exit\n");
printf(" -C arg show a specific compile-time option and exit with its\n");
printf(" value if numeric (else 0). The arg can be:\n");
@@ -3134,7 +3212,7 @@ is contributed code which the PCRE2 developers have no means of testing. */
/* No argument for -C: output all configuration information. */
-print_version(stdout, FALSE);
+print_version(FALSE);
printf("Compiled with\n");
#ifdef EBCDIC
@@ -3172,7 +3250,7 @@ if (optval != 0)
{
printf(" Just-in-time compiler support\n");
printf(" Architecture: ");
- print_jit_target(stdout);
+ print_jit_target();
printf("\n");
printf(" Can allocate executable memory: ");
@@ -3528,6 +3606,19 @@ BOOL skipping_endif = FALSE;
char *arg_subject = NULL;
char *arg_pattern = NULL;
char *arg_error = NULL;
+outfile = stdout;
+
+/* Before printing anything, check if we are being asked to print in colour */
+
+for (int i = 1; i < argc && argv[i][0] == '-' && argv[i][1] != 0; i++)
+ {
+ if (strcmp(argv[i], "-c") == 0)
+ {
+ colour_on = TRUE;
+ colour_end(stdout);
+ }
+ }
+
/* The offsets to the options and control bits fields of the pattern and data
control blocks must be the same so that common options and controls such as
@@ -3729,6 +3820,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
}
else if (strcmp(arg, "-ac") == 0) def_patctl.options |= PCRE2_AUTO_CALLOUT;
else if (strcmp(arg, "-b") == 0) def_patctl.control |= CTL_FULLBINCODE;
+ else if (strcmp(arg, "-c") == 0) /* handled above */;
else if (strcmp(arg, "-d") == 0) def_patctl.control |= CTL_DEBUG;
else if (strcmp(arg, "-dfa") == 0) def_datctl.control |= CTL_DFA;
else if (strcmp(arg, "-i") == 0) def_patctl.control |= CTL_INFO;
@@ -3792,7 +3884,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
else if (memcmp(arg, "-v", 2) == 0 ||
strcmp(arg, "--version") == 0)
{
- print_version(stdout, FALSE);
+ print_version(FALSE);
goto EXIT;
}
@@ -3924,7 +4016,7 @@ if (argc > 2)
/* Output a heading line unless quiet, then process input lines. */
-if (!quiet) print_version(outfile, TRUE);
+if (!quiet) print_version(TRUE);
#ifdef SUPPORT_PCRE2_8
preg.re_pcre2_code = NULL;
@@ -3936,11 +4028,12 @@ while (notdone)
const uint8_t *p;
int rc = PR_OK;
BOOL expectdata = have_active_pattern();
+ BOOL is_comment;
#ifdef SUPPORT_PCRE2_8
expectdata |= preg.re_pcre2_code != NULL;
#endif
- if (extend_inputline(infile, buffer, expectdata? "data> " : " re> ") == NULL)
+ if (extend_inputline(infile, buffer, expectdata? PROMPT("data> ") : PROMPT(" re> ")) == NULL)
break;
/* Pre-process input lines with #if...#endif. */
@@ -3955,9 +4048,10 @@ while (notdone)
/* Begin processing the line. */
- if (!INTERACTIVE(infile)) fprintf(outfile, "%s", (char *)buffer);
- fflush(outfile);
p = buffer;
+ is_comment = p[0] == '#' && (isspace(p[1]) || p[1] == '!' || p[1] == 0);
+ if (!INTERACTIVE(infile)) cprintf(is_comment ? clr_comment : clr_input, "%s", (char *)buffer);
+ fflush(outfile);
if (preprocess_only && *p != '#') continue;
@@ -4000,7 +4094,7 @@ while (notdone)
else if (*p == '#')
{
- if (isspace(p[1]) || p[1] == '!' || p[1] == 0) continue;
+ if (is_comment) continue;
rc = process_command();
}
diff --git a/src/pcre2test_inc.h b/src/pcre2test_inc.h
index 7bf72dccd..afb9e74e4 100644
--- a/src/pcre2test_inc.h
+++ b/src/pcre2test_inc.h
@@ -74,6 +74,7 @@ library. */
#define pcre2_strlen PCRE2_SUFFIX(pcre2_strlen_)
#define pchars PCRE2_SUFFIX(pchars_)
#define ptrunc PCRE2_SUFFIX(ptrunc_)
+#define pcre2_printint_clr PCRE2_SUFFIX(pcre2_printint_clr_)
#define config_str PCRE2_SUFFIX(config_str_)
#define check_modifier PCRE2_SUFFIX(check_modifier_)
#define decode_modifiers PCRE2_SUFFIX(decode_modifiers_)
@@ -176,12 +177,13 @@ For printing *MARK strings, a negative length is given, indicating that the
length is in the first code unit. If handed a NULL file, this function just
counts chars without printing (because pchar() does that). */
-static int pchars(PCRE2_SPTR p, ptrdiff_t length, BOOL utf, FILE *f)
+static int pchars(int clr, PCRE2_SPTR p, ptrdiff_t length, BOOL utf, FILE *f)
{
#if PCRE2_CODE_UNIT_WIDTH == 8 || PCRE2_CODE_UNIT_WIDTH == 16
PCRE2_SPTR end;
uint32_t c = 0;
int yield = 0;
+colour_begin(clr, f);
if (length < 0) length = *p++;
end = p + length;
while (length-- > 0)
@@ -193,24 +195,28 @@ while (length-- > 0)
{
length -= rc - 1;
p += rc;
- yield += pchar(c, utf, f);
+ yield += pchar_raw(c, utf, f);
continue;
}
}
c = *p++;
- yield += pchar(c, utf, f);
+ yield += pchar_raw(c, utf, f);
}
+colour_end(f);
return yield;
#else
int yield = 0;
+colour_begin(clr, f);
if (length < 0) length = *p++;
while (length-- > 0)
{
uint32_t c = *p++;
- yield += pchar(c, utf, f);
+ yield += pchar_raw(c, utf, f);
}
+
+colour_end(f);
return yield;
#endif
@@ -227,13 +233,15 @@ the offset to print from/to. If left is true, prints up to the offset,
truncated; otherwise prints from the offset to the right, truncated. */
#if PCRE2_CODE_UNIT_WIDTH == 8
-static void ptrunc_8(PCRE2_SPTR p, size_t p_len, size_t offset, BOOL left,
+static void ptrunc_8(int clr, PCRE2_SPTR p, size_t p_len, size_t offset, BOOL left,
BOOL utf, FILE *f)
{
PCRE2_SPTR start = p + offset;
PCRE2_SPTR end = p + offset;
size_t printed = 0;
+colour_begin(clr, f);
+
if (left)
{
while (start > p && printed < 10)
@@ -258,16 +266,20 @@ else
if (left && start > p) fprintf(f, "...");
for (; start < end; start++) fprintf(f, "%c", CHAR_OUTPUT(*start));
if (!left && end < p + p_len) fprintf(f, "...");
+
+colour_end(f);
}
#elif PCRE2_CODE_UNIT_WIDTH == 16
-static void ptrunc_16(PCRE2_SPTR p, size_t p_len, size_t offset, BOOL left,
+static void ptrunc_16(int clr, PCRE2_SPTR p, size_t p_len, size_t offset, BOOL left,
BOOL utf, FILE *f)
{
PCRE2_SPTR start = p + offset;
PCRE2_SPTR end = p + offset;
size_t printed = 0;
+colour_begin(clr, f);
+
if (left)
{
while (start > p && printed < 10)
@@ -306,15 +318,19 @@ while (start < end)
fputc((int)c, f);
}
if (!left && end < p + p_len) fprintf(f, "...");
+
+colour_end(f);
}
#elif PCRE2_CODE_UNIT_WIDTH == 32
-static void ptrunc_32(PCRE2_SPTR p, size_t p_len, size_t offset, BOOL left,
+static void ptrunc_32(int clr, PCRE2_SPTR p, size_t p_len, size_t offset, BOOL left,
BOOL utf, FILE *f)
{
PCRE2_SPTR start = p + offset;
PCRE2_SPTR end = p + offset;
+colour_begin(clr, f);
+
if (left)
{
start -= (offset > 10)? 10 : offset;
@@ -338,10 +354,22 @@ while (start < end)
fputc((int)c, f);
}
if (!left && end < p + p_len) fprintf(f, "...");
+
+colour_end(f);
}
#endif
+/*************************************************
+* Print 8-bit compiled pattern (in colour) *
+*************************************************/
+static void
+pcre2_printint_clr(int clr, pcre2_code *re, FILE *f, BOOL print_lengths)
+{
+ colour_begin(clr, f);
+ pcre2_printint(re, f, print_lengths);
+ colour_end(f);
+}
#if PCRE2_CODE_UNIT_WIDTH == 16
/*************************************************
From 49735a39921f3d541b7bcf0d66204465579e5a05 Mon Sep 17 00:00:00 2001
From: Isaac Oscar Gariano
Date: Fri, 3 Oct 2025 17:48:20 +1000
Subject: [PATCH 2/6] Optionally colourise all output in pcre2test.
This finishes of the work started by the previous commit.
---
src/pcre2test.c | 170 +++++-----
src/pcre2test_inc.h | 785 ++++++++++++++++++++++----------------------
2 files changed, 480 insertions(+), 475 deletions(-)
diff --git a/src/pcre2test.c b/src/pcre2test.c
index 150c5dd78..e2aa89031 100644
--- a/src/pcre2test.c
+++ b/src/pcre2test.c
@@ -1537,13 +1537,13 @@ if (show_memory && outfile != NULL)
{
if (block == NULL)
{
- fprintf(outfile, "** malloc() failed for %" SIZ_FORM "\n", size);
+ cprintf(clr_test_error, "** malloc() failed for %" SIZ_FORM "\n", size);
}
else
{
- fprintf(outfile, "malloc %5" SIZ_FORM, size);
+ cprintf(clr_profiling, "malloc %5" SIZ_FORM, size);
#ifdef DEBUG_SHOW_MALLOC_ADDRESSES
- fprintf(outfile, " %p", block); /* Not portable */
+ cprintf(clr_profiling, " %p", block); /* Not portable */
#endif
if (malloclistptr < MALLOCLISTSIZE)
{
@@ -1551,8 +1551,8 @@ if (show_memory && outfile != NULL)
malloclistlength[malloclistptr++] = size;
}
else
- fprintf(outfile, " (not remembered)");
- fprintf(outfile, "\n");
+ cprintf(clr_test_error, " (not remembered)");
+ cprintf(clr_profiling, "\n");
}
}
return block;
@@ -1567,12 +1567,12 @@ if (show_memory && outfile != NULL && block != NULL)
uint32_t i, j;
BOOL found = FALSE;
- fprintf(outfile, "free");
+ cprintf(clr_profiling, "free");
for (i = 0; i < malloclistptr; i++)
{
if (block == malloclist[i])
{
- fprintf(outfile, " %5" SIZ_FORM, malloclistlength[i]);
+ cprintf(clr_profiling, " %5" SIZ_FORM, malloclistlength[i]);
malloclistptr--;
for (j = i; j < malloclistptr; j++)
{
@@ -1583,11 +1583,11 @@ if (show_memory && outfile != NULL && block != NULL)
break;
}
}
- if (!found) fprintf(outfile, " unremembered block");
+ if (!found) cprintf(clr_profiling, " unremembered block");
#ifdef DEBUG_SHOW_MALLOC_ADDRESSES
- fprintf(outfile, " %p", block); /* Not portable */
+ cprintf(clr_profiling, " %p", block); /* Not portable */
#endif
- fprintf(outfile, "\n");
+ cprintf(clr_profiling, "\n");
}
free(block);
}
@@ -1933,7 +1933,7 @@ uint8_t *new_pbuffer8 = (uint8_t *)malloc(new_pbuffer8_size);
if (new_buffer == NULL || new_pbuffer8 == NULL)
{
- fprintf(stderr, "pcre2test: malloc(%" SIZ_FORM ") failed\n",
+ fatal_printf("pcre2test: malloc(%" SIZ_FORM ") failed\n",
new_pbuffer8_size);
exit(1);
}
@@ -1998,7 +1998,7 @@ for (;;)
dlen = strlen(s);
if (dlen > rlen - 2)
{
- fprintf(outfile, "** Interactive input exceeds buffer space\n");
+ cprintf(clr_test_error, "** Interactive input exceeds buffer space\n");
exit(1);
}
if (dlen > 0) add_history(s);
@@ -2016,7 +2016,7 @@ for (;;)
/* Read the next line by normal means, prompting if the file is a tty. */
- if (INTERACTIVE(f)) printf("%s", prompt);
+ if (INTERACTIVE(f)) cprintf(clr_profiling, "%s", prompt);
if (fgets((char *)here, rlen_trunc, f) == NULL)
return (here == start)? NULL : start;
@@ -2037,8 +2037,8 @@ for (;;)
if (dlen < (unsigned)rlen_trunc - 1 && !feof(f))
{
- fprintf(outfile, "** Binary zero encountered in input\n");
- fprintf(outfile, "** pcre2test run abandoned\n");
+ cprintf(clr_test_error, "** Binary zero encountered in input\n");
+ cprintf(clr_test_error, "** pcre2test run abandoned\n");
exit(1);
}
}
@@ -2330,7 +2330,7 @@ when 8-bit mode is supported. */
static void
prmsg(const char **msg, const char *s)
{
-fprintf(outfile, "%s %s", *msg, s);
+cprintf(clr_test_error, "%s %s", *msg, s);
*msg = "";
}
#endif /* SUPPORT_PCRE2_8 */
@@ -2594,7 +2594,7 @@ while (endf > filename && isspace((unsigned char)endf[-1])) endf--;
if (endf == filename)
{
- fprintf(outfile, "** File name expected after %s\n", name);
+ cprintf(clr_test_error, "** File name expected after %s\n", name);
return PR_ABEND;
}
@@ -2602,7 +2602,7 @@ if (endf == filename)
*fptr = fopen((const char *)filename, mode);
if (*fptr == NULL)
{
- fprintf(outfile, "** Failed to open \"%s\": %s\n", filename, strerror(errno));
+ cprintf(clr_test_error, "** Failed to open \"%s\": %s\n", filename, strerror(errno));
return PR_ABEND;
}
@@ -2766,13 +2766,13 @@ for (i = 0; i < 2*oveccount; i += 2)
PCRE2_SIZE start = ovector[i];
PCRE2_SIZE end = ovector[i+1];
- fprintf(outfile, "%2d: ", i/2);
+ cprintf(clr_output, "%2d: ", i/2);
if (start == PCRE2_UNSET && end == PCRE2_UNSET)
- fprintf(outfile, "\n");
+ cprintf(clr_api_error, "\n");
else if (start == JUNK_OFFSET && end == JUNK_OFFSET)
- fprintf(outfile, "\n");
+ cprintf(clr_output, "\n");
else
- fprintf(outfile, "%ld %ld\n", (unsigned long int)start,
+ cprintf(clr_output, "%ld %ld\n", (unsigned long int)start,
(unsigned long int)end);
}
}
@@ -3027,11 +3027,11 @@ Returns: nothing
static void
print_newline_config(uint32_t optval, BOOL isc)
{
-if (!isc) printf(" Default newline sequence is ");
+if (!isc) cprintf(clr_output, " Default newline sequence is ");
if (optval < sizeof(newlines)/sizeof(char *))
- printf("%s\n", newlines[optval]);
+ cprintf(clr_output, "%s\n", newlines[optval]);
else
- printf("a non-standard value: %d\n", optval);
+ cprintf(clr_test_error, "a non-standard value: %d\n", optval);
}
@@ -3136,7 +3136,7 @@ if (arg != NULL && arg[0] != '-')
if (i >= COPTLISTCOUNT)
{
- fprintf(stderr, "** Unknown -C option \"%s\"\n", arg);
+ fatal_printf("** Unknown -C option \"%s\"\n", arg);
return 0;
}
@@ -3144,17 +3144,17 @@ if (arg != NULL && arg[0] != '-')
{
case CONF_BSR:
(void)pcre2_config(coptlist[i].value, &optval);
- printf("%s\n", (optval == PCRE2_BSR_ANYCRLF)? "ANYCRLF" : "ANY");
+ cprintf(clr_output, "%s\n", (optval == PCRE2_BSR_ANYCRLF)? "ANYCRLF" : "ANY");
break;
case CONF_FIX:
yield = coptlist[i].value;
- printf("%d\n", yield);
+ cprintf(clr_output, "%d\n", yield);
break;
case CONF_INT:
(void)pcre2_config(coptlist[i].value, &yield);
- printf("%d\n", yield);
+ cprintf(clr_output, "%d\n", yield);
break;
case CONF_NL:
@@ -3171,7 +3171,7 @@ if (arg != NULL && arg[0] != '-')
case PCRE2_ERROR_JIT_UNSUPPORTED: yield = 2; break;
default: yield = 3; break;
}
- printf("%d\n", yield);
+ cprintf(clr_output, "%d\n", yield);
break;
}
@@ -3228,9 +3228,9 @@ printf(" Input/output for pcre2test is ASCII, not EBCDIC\n");
#endif
(void)pcre2_config(PCRE2_CONFIG_COMPILED_WIDTHS, &optval);
-if (optval & 1) printf(" 8-bit support\n");
-if (optval & 2) printf(" 16-bit support\n");
-if (optval & 4) printf(" 32-bit support\n");
+if (optval & 1) cprintf(clr_output, " 8-bit support\n");
+if (optval & 2) cprintf(clr_output, " 16-bit support\n");
+if (optval & 4) cprintf(clr_output, " 32-bit support\n");
#ifdef SUPPORT_VALGRIND
printf(" Valgrind support\n");
@@ -3239,43 +3239,43 @@ printf(" Valgrind support\n");
(void)pcre2_config(PCRE2_CONFIG_UNICODE, &optval);
if (optval != 0)
{
- printf(" UTF and UCP support (");
- print_unicode_version(stdout);
- printf(")\n");
+ cprintf(clr_output, " UTF and UCP support (");
+ print_unicode_version();
+ cprintf(clr_output, ")\n");
}
-else printf(" No Unicode support\n");
+else cprintf(clr_api_error, " No Unicode support\n");
(void)pcre2_config(PCRE2_CONFIG_JIT, &optval);
if (optval != 0)
{
- printf(" Just-in-time compiler support\n");
- printf(" Architecture: ");
+ cprintf(clr_output, " Just-in-time compiler support\n");
+ cprintf(clr_output, " Architecture: ");
print_jit_target();
- printf("\n");
+ cprintf(clr_output, "\n");
- printf(" Can allocate executable memory: ");
+ cprintf(clr_output, " Can allocate executable memory: ");
rc = jit_compile_test();
switch(rc)
{
case 0:
- printf("Yes\n");
+ cprintf(clr_output, "Yes\n");
break;
case PCRE2_ERROR_NOMEMORY:
- printf("No (so cannot work)\n");
+ cprintf(clr_api_error, "No (so cannot work)\n");
break;
default:
- printf("\n** Unexpected return %d from "
+ cprintf(clr_test_error, "\n** Unexpected return %d from "
"pcre2_jit_compile(NULL, PCRE2_JIT_TEST_ALLOC)\n", rc);
- printf("** Should not occur\n");
+ cprintf(clr_test_error, "** Should not occur\n");
yield = 1;
break;
}
}
else
{
- printf(" No just-in-time compiler support\n");
+ cprintf(clr_api_error, " No just-in-time compiler support\n");
}
(void)pcre2_config(PCRE2_CONFIG_NEWLINE, &optval);
@@ -3424,7 +3424,7 @@ for (size_t i = 0; i < PRIV(utt_size); i++)
const ucp_type_table *tt = PRIV(utt) + j;
if (tt->type != t->type || tt->value != value) continue;
if (m >= MAX_SYNONYMS)
- printf("** Too many synonyms: %s ignored\n",
+ cprintf(clr_test_error, "** Too many synonyms: %s ignored\n",
PRIV(utt_names) + tt->name_offset);
else fv[m++] = tt->name_offset;
}
@@ -3432,10 +3432,10 @@ for (size_t i = 0; i < PRIV(utt_size); i++)
fv[m] = -1;
}
-printf("-------------------------- SUPPORTED %s --------------------------\n\n",
+cprintf(clr_output, "-------------------------- SUPPORTED %s --------------------------\n\n",
wantscripts? "SCRIPTS" : "PROPERTIES");
-if (!wantscripts) printf(
+if (!wantscripts) cprintf(clr_output,
"This release of PCRE2 supports Unicode's general category properties such\n"
"as Lu (upper case letter), bi-directional properties such as Bidi_Class,\n"
"and the following binary (yes/no) properties:\n\n");
@@ -3452,9 +3452,9 @@ for (int k = 0; k < (n+1)/2; k++)
if (x < n) format_list_item(found[x], buff2, wantscripts);
else buff2[0] = 0;
- x = printf("%s", buff1);
- while (x++ < colwidth) printf(" ");
- printf("%s\n", buff2);
+ x = cprintf(clr_output, "%s", buff1);
+ while (x++ < colwidth) cprintf(clr_output, " ");
+ cprintf(clr_output, "%s\n", buff2);
}
#endif /* SUPPORT_UNICODE */
@@ -3471,11 +3471,11 @@ display_one_modifier(modstruct *m, BOOL for_pattern)
{
uint32_t c = (!for_pattern && (m->which == MOD_PND || m->which == MOD_PNDP))?
'*' : ' ';
-printf("%c%s", c, m->name);
+cprintf(clr_output, "%c%s", c, m->name);
for (size_t i = 0; i < C1MODLISTCOUNT; i++)
{
if (strcmp(m->name, c1modlist[i].fullname) == 0)
- printf(" (%c)", c1modlist[i].onechar);
+ cprintf(clr_output, " (%c)", c1modlist[i].onechar);
}
}
@@ -3527,7 +3527,7 @@ for (i = 0; i < MODLISTCOUNT; i++)
is_pattern = FALSE;
break;
- default: printf("** Unknown type for modifier \"%s\"\n", m->name);
+ default: cprintf_file(stdout, clr_test_error, "** Unknown type for modifier \"%s\"\n", m->name);
PCRE2_FALLTHROUGH /* Fall through */
case MOD_PD: /* Pattern or subject */
case MOD_PDP: /* As PD, OK for Perl-compatible test */
@@ -3561,10 +3561,10 @@ for (i = 0, j = (n+1)/2; i < (n+1)/2; i++, j++)
if (j < n)
{
size_t k = 27 - strlen(m->name) - extra[i];
- while (k-- > 0) printf(" ");
+ while (k-- > 0) cprintf(clr_output, " ");
display_one_modifier(modlist + list[j], for_pattern);
}
- printf("\n");
+ cprintf(clr_output, "\n");
}
}
@@ -3633,7 +3633,7 @@ preprocessor. */
if (PO(options) != DO(options) || PO(control) != DO(control) ||
PO(control2) != DO(control2))
{
- fprintf(stderr, "** Coding error: "
+ fatal_printf("** Coding error: "
"options and control offsets for pattern and data must be the same.\n");
return 1;
}
@@ -3727,7 +3727,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
#ifdef SUPPORT_PCRE2_8
test_mode = PCRE2TEST_MODE_8;
#else
- fprintf(stderr,
+ fatal_printf(
"** This version of PCRE2 was built without 8-bit support\n");
exit(1);
#endif
@@ -3738,7 +3738,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
#ifdef SUPPORT_PCRE2_16
test_mode = PCRE2TEST_MODE_16;
#else
- fprintf(stderr,
+ fatal_printf(
"** This version of PCRE2 was built without 16-bit support\n");
exit(1);
#endif
@@ -3749,7 +3749,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
#ifdef SUPPORT_PCRE2_32
test_mode = PCRE2TEST_MODE_32;
#else
- fprintf(stderr,
+ fatal_printf(
"** This version of PCRE2 was built without 32-bit support\n");
exit(1);
#endif
@@ -3769,7 +3769,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
((uli = strtoul(argv[op+1], &endptr, 10)), *endptr == 0))
{
#if defined(_WIN32) || defined(WIN32) || defined(__HAIKU__) || defined(NATIVE_ZOS) || defined(__VMS)
- fprintf(stderr, "pcre2test: -S is not supported on this OS\n");
+ fatal_printf("pcre2test: -S is not supported on this OS\n");
exit(1);
#else
int rc = 0;
@@ -3777,7 +3777,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
struct rlimit rlim, rlim_old;
if (uli > INT32_MAX / (1024 * 1024))
{
- fprintf(stderr, "** Argument for -S is too big\n");
+ fatal_printf("** Argument for -S is too big\n");
exit(1);
}
stack_size = (uint32_t)uli;
@@ -3786,15 +3786,15 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
rlim.rlim_cur = stack_size * 1024 * 1024;
if (rlim.rlim_max != RLIM_INFINITY && rlim.rlim_cur > rlim.rlim_max)
{
- fprintf(stderr,
+ fatal_printf(
"pcre2test: requested stack size %luMiB is greater than hard limit ",
(unsigned long int)stack_size);
if (rlim.rlim_max % (1024*1024) == 0)
- fprintf(stderr, "%luMiB\n", (unsigned long)(rlim.rlim_max/(1024*1024)));
+ fatal_printf("%luMiB\n", (unsigned long)(rlim.rlim_max/(1024*1024)));
else if (rlim.rlim_max % 1024 == 0)
- fprintf(stderr, "%luKiB\n", (unsigned long)(rlim.rlim_max/1024));
+ fatal_printf("%luKiB\n", (unsigned long)(rlim.rlim_max/1024));
else
- fprintf(stderr, "%lu bytes\n", (unsigned long)(rlim.rlim_max));
+ fatal_printf("%lu bytes\n", (unsigned long)(rlim.rlim_max));
exit(1);
}
if (rlim_old.rlim_cur != RLIM_INFINITY && rlim_old.rlim_cur <= INT32_MAX &&
@@ -3802,7 +3802,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
rc = setrlimit(RLIMIT_STACK, &rlim);
if (rc != 0)
{
- fprintf(stderr, "pcre2test: setting stack size %luMiB failed: %s\n",
+ fatal_printf("pcre2test: setting stack size %luMiB failed: %s\n",
(unsigned long int)stack_size, strerror(errno));
exit(1);
}
@@ -3831,7 +3831,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
else if (arg[4] == 'f') def_patctl.control |= CTL_JITFAST;
def_patctl.jit = JIT_DEFAULT; /* full & partial */
#ifndef SUPPORT_JIT
- fprintf(stderr, "** Warning: JIT support is not available: "
+ fatal_printf("** Warning: JIT support is not available: "
"-jit[fast|verify] calls functions that do nothing.\n");
#endif
}
@@ -3847,12 +3847,12 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
{
if (uli == 0)
{
- fprintf(stderr, "** Argument for %s must not be zero\n", arg);
+ fatal_printf("** Argument for %s must not be zero\n", arg);
exit(1);
}
if (U32OVERFLOW(uli))
{
- fprintf(stderr, "** Argument for %s is too big\n", arg);
+ fatal_printf("** Argument for %s is too big\n", arg);
exit(1);
}
timeitm = (int)uli;
@@ -3909,7 +3909,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
CHECK_VALUE_EXISTS:
if (argc <= 2)
{
- fprintf(stderr, "** Missing value for %s\n", arg);
+ fatal_printf("** Missing value for %s\n", arg);
yield = 1;
goto EXIT;
}
@@ -3921,7 +3921,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
else
{
- fprintf(stderr, "** Unknown or malformed option \"%s\"\n", arg);
+ fatal_printf("** Unknown or malformed option \"%s\"\n", arg);
usage();
yield = 1;
goto EXIT;
@@ -3946,12 +3946,12 @@ if (arg_error != NULL)
li = strtol(arg_error, &endptr, 10);
if (S32OVERFLOW(li) || (*endptr != 0 && *endptr != ','))
{
- fprintf(stderr, "** \"%s\" is not a valid error number list\n", arg_error);
+ fatal_printf("** \"%s\" is not a valid error number list\n", arg_error);
yield = 1;
goto EXIT;
}
errcode = (int)li;
- printf("Error %d: ", errcode);
+ cprintf_file(stdout, clr_api_error, "Error %d: ", errcode);
print_error_message_file(stdout, errcode, "", "\n", TRUE);
if (*endptr == 0) goto EXIT;
arg_error = endptr + 1;
@@ -3993,7 +3993,7 @@ if (argc > 1 && strcmp(argv[op], "-") != 0)
infile = fopen(argv[op], INPUT_MODE);
if (infile == NULL)
{
- printf("** Failed to open \"%s\": %s\n", argv[op], strerror(errno));
+ fatal_printf("** Failed to open \"%s\": %s\n", argv[op], strerror(errno));
yield = 1;
goto EXIT;
}
@@ -4008,7 +4008,7 @@ if (argc > 2)
outfile = fopen(argv[op+1], OUTPUT_MODE);
if (outfile == NULL)
{
- printf("** Failed to open \"%s\": %s\n", argv[op+1], strerror(errno));
+ fatal_printf("** Failed to open \"%s\": %s\n", argv[op+1], strerror(errno));
yield = 1;
goto EXIT;
}
@@ -4109,7 +4109,7 @@ while (notdone)
while (isspace(*p)) p++;
if (*p != 0)
{
- fprintf(outfile, "** Invalid pattern delimiter '%c' (x%x).\n", *buffer,
+ cprintf(clr_test_error, "** Invalid pattern delimiter '%c' (x%x).\n", *buffer,
*buffer);
rc = PR_SKIP;
}
@@ -4119,7 +4119,7 @@ while (notdone)
else if (rc == PR_ENDIF) skipping_endif = TRUE;
else if (rc == PR_ABEND)
{
- fprintf(outfile, "** pcre2test run abandoned\n");
+ cprintf(clr_test_error, "** pcre2test run abandoned\n");
yield = 1;
goto EXIT;
}
@@ -4129,28 +4129,28 @@ while (notdone)
if (skipping_endif)
{
- fprintf(outfile, "** Expected #endif\n");
+ cprintf(clr_test_error, "** Expected #endif\n");
yield = 1;
goto EXIT;
}
-if (INTERACTIVE(infile)) fprintf(outfile, "\n");
+if (INTERACTIVE(infile)) cprintf(clr_output, "\n");
if (showtotaltimes)
{
const char *pad = "";
- fprintf(outfile, "--------------------------------------\n");
+ cprintf(clr_profiling, "--------------------------------------\n");
if (timeit > 0)
{
- fprintf(outfile, "Total compile time %8.2f microseconds\n",
+ cprintf(clr_profiling, "Total compile time %8.2f microseconds\n",
((1000000 / CLOCKS_PER_SEC) * (double)total_compile_time) / timeit);
if (total_jit_compile_time > 0)
- fprintf(outfile, "Total JIT compile %8.2f microseconds\n",
+ cprintf(clr_profiling, "Total JIT compile %8.2f microseconds\n",
((1000000 / CLOCKS_PER_SEC) * (double)total_jit_compile_time) / \
timeit);
pad = " ";
}
- fprintf(outfile, "Total match time %s%8.2f microseconds\n", pad,
+ cprintf(clr_profiling, "Total match time %s%8.2f microseconds\n", pad,
((1000000 / CLOCKS_PER_SEC) * (double)total_match_time) / timeitm);
}
diff --git a/src/pcre2test_inc.h b/src/pcre2test_inc.h
index afb9e74e4..433c20188 100644
--- a/src/pcre2test_inc.h
+++ b/src/pcre2test_inc.h
@@ -420,7 +420,7 @@ if (pbuffer16_size < 2*len + 2)
pbuffer16 = (uint16_t *)malloc(pbuffer16_size);
if (pbuffer16 == NULL)
{
- fprintf(stderr, "pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer16\n",
+ fatal_printf("pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer16\n",
pbuffer16_size);
exit(1);
}
@@ -509,7 +509,7 @@ if (pbuffer32_size < 4*len + 4)
pbuffer32 = (uint32_t *)malloc(pbuffer32_size);
if (pbuffer32 == NULL)
{
- fprintf(stderr, "pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer32\n",
+ fatal_printf("pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer32\n",
pbuffer32_size);
exit(1);
}
@@ -571,7 +571,7 @@ r1 = pcre2_config(what, NULL);
r2 = pcre2_config(what, buf);
if (r1 < 0 || r1 != r2 || r1 >= VERSION_SIZE)
{
- fprintf(stderr, "pcre2test: Error in pcre2_config(%d)\n", what);
+ fatal_printf("pcre2test: Error in pcre2_config(%d)\n", what);
exit(1);
}
@@ -616,7 +616,7 @@ if (restrict_for_perl_test) switch(m->which)
break;
default:
- fprintf(outfile, "** \"%s\" is not allowed in a Perl-compatible test\n",
+ cprintf(clr_test_error, "** \"%s\" is not allowed in a Perl-compatible test\n",
m->name);
return NULL;
}
@@ -657,9 +657,9 @@ switch (m->which)
if (field == NULL)
{
if (c == 0)
- fprintf(outfile, "** \"%s\" is not valid here\n", m->name);
+ cprintf(clr_test_error, "** \"%s\" is not valid here\n", m->name);
else
- fprintf(outfile, "** /%c is not valid here\n", c);
+ cprintf(clr_test_error, "** /%c is not valid here\n", c);
return NULL;
}
@@ -747,9 +747,9 @@ for (;;)
if (!first)
{
- fprintf(outfile, "** Unrecognized modifier \"%.*s\"\n", (int)(ep-p), p);
+ cprintf(clr_test_error, "** Unrecognized modifier \"%.*s\"\n", (int)(ep-p), p);
if (ep - p == 1)
- fprintf(outfile, "** Single-character modifiers must come first\n");
+ cprintf(clr_test_error, "** Single-character modifiers must come first\n");
return FALSE;
}
@@ -762,7 +762,7 @@ for (;;)
if (i >= C1MODLISTCOUNT)
{
- fprintf(outfile, "** Unrecognized modifier '%c' in modifier string "
+ cprintf(clr_test_error, "** Unrecognized modifier '%c' in modifier string "
"\"%.*s\"\n", *p, (int)(ep-mp), mp);
return FALSE;
}
@@ -778,7 +778,7 @@ for (;;)
strlen(c1modlist[i].fullname));
if (index < 0)
{
- fprintf(outfile, "** Internal error: single-character equivalent "
+ cprintf(clr_test_error, "** Internal error: single-character equivalent "
"modifier \"%s\" not found\n", c1modlist[i].fullname);
return FALSE;
}
@@ -812,12 +812,12 @@ for (;;)
{
if (*pp++ != '=')
{
- fprintf(outfile, "** '=' expected after \"%s\"\n", m->name);
+ cprintf(clr_test_error, "** '=' expected after \"%s\"\n", m->name);
return FALSE;
}
if (off)
{
- fprintf(outfile, "** '-' is not valid for \"%s\"\n", m->name);
+ cprintf(clr_test_error, "** '-' is not valid for \"%s\"\n", m->name);
return FALSE;
}
}
@@ -826,7 +826,7 @@ for (;;)
else if (*pp != ',' && *pp != '\n' && *pp != ' ' && *pp != 0)
{
- fprintf(outfile, "** Unrecognized modifier '%.*s'\n", (int)(ep-p), p);
+ cprintf(clr_test_error, "** Unrecognized modifier '%.*s'\n", (int)(ep-p), p);
return FALSE;
}
@@ -991,7 +991,7 @@ for (;;)
field = (char *)field + sizeof(int32_t);
if (ct <= 0)
{
- fprintf(outfile, "** Too many numeric \"%s\" modifiers\n", m->name);
+ cprintf(clr_test_error, "** Too many numeric \"%s\" modifiers\n", m->name);
return FALSE;
}
}
@@ -1009,13 +1009,13 @@ for (;;)
{
if (len > MAX_NAME_SIZE)
{
- fprintf(outfile, "** Group name in \"%s\" is too long\n", m->name);
+ cprintf(clr_test_error, "** Group name in \"%s\" is too long\n", m->name);
return FALSE;
}
while (*nn != 0) nn += strlen(nn) + 1;
if (nn + len + 2 - (char *)field > LENCPYGET)
{
- fprintf(outfile, "** Too many characters in named \"%s\" modifiers\n",
+ cprintf(clr_test_error, "** Too many characters in named \"%s\" modifiers\n",
m->name);
return FALSE;
}
@@ -1030,7 +1030,7 @@ for (;;)
case MOD_STR:
if (len + 1 > m->value)
{
- fprintf(outfile, "** Overlong value for \"%s\" (max %d code units)\n",
+ cprintf(clr_test_error, "** Overlong value for \"%s\" (max %d code units)\n",
m->name, m->value - 1);
return FALSE;
}
@@ -1042,7 +1042,7 @@ for (;;)
if (*pp != ',' && *pp != '\n' && *pp != ' ' && *pp != 0)
{
- fprintf(outfile, "** Comma expected after modifier item \"%s\"\n", m->name);
+ cprintf(clr_test_error, "** Comma expected after modifier item \"%s\"\n", m->name);
return FALSE;
}
@@ -1054,7 +1054,7 @@ for (;;)
pctl->locale[0] != 0 ||
(pctl->control & NOTPOP_CONTROLS) != 0))
{
- fprintf(outfile, "** \"%s\" is not valid here\n", m->name);
+ cprintf(clr_test_error, "** \"%s\" is not valid here\n", m->name);
return FALSE;
}
}
@@ -1062,7 +1062,7 @@ for (;;)
return TRUE;
INVALID_VALUE:
-fprintf(outfile, "** Invalid value in \"%.*s\"\n", (int)(ep-p), p);
+cprintf(clr_test_error, "** Invalid value in \"%.*s\"\n", (int)(ep-p), p);
return FALSE;
}
@@ -1092,7 +1092,7 @@ rc = pcre2_pattern_info(compiled_code, what, where);
if (rc >= 0) return 0;
if (rc != PCRE2_ERROR_UNSET || !unsetok)
{
- fprintf(outfile, "Error %d from "
+ cprintf(clr_api_error, "Error %d from "
"pcre2_pattern_info_" STR(PCRE2_CODE_UNIT_WIDTH) "(%d)\n", rc, what);
}
return rc;
@@ -1120,15 +1120,15 @@ cblock_size = sizeof(pcre2_real_code);
integer overflow. */
data_size = CU2BYTES((PCRE2_SIZE)name_count * (PCRE2_SIZE)name_entry_size);
-fprintf(outfile, "Memory allocation - code size : %" SIZ_FORM "\n", size -
+cprintf(clr_profiling, "Memory allocation - code size : %" SIZ_FORM "\n", size -
cblock_size - data_size);
if (data_size != 0)
- fprintf(outfile, "Memory allocation - data size : %" SIZ_FORM "\n", data_size);
+ cprintf(clr_profiling, "Memory allocation - data size : %" SIZ_FORM "\n", data_size);
if (pat_patctl.jit != 0)
{
(void)pattern_info(PCRE2_INFO_JITSIZE, &size, FALSE);
- fprintf(outfile, "Memory allocation - JIT code : %" SIZ_FORM "\n", size);
+ cprintf(clr_profiling, "Memory allocation - JIT code : %" SIZ_FORM "\n", size);
}
}
@@ -1143,7 +1143,7 @@ show_framesize(void)
{
PCRE2_SIZE frame_size;
(void)pattern_info(PCRE2_INFO_FRAMESIZE, &frame_size, FALSE);
-fprintf(outfile, "Frame size for pcre2_match(): %" SIZ_FORM "\n", frame_size);
+cprintf(clr_profiling, "Frame size for pcre2_match(): %" SIZ_FORM "\n", frame_size);
}
@@ -1157,7 +1157,7 @@ show_heapframes_size(void)
{
PCRE2_SIZE heapframes_size;
heapframes_size = pcre2_get_match_data_heapframes_size(match_data);
-fprintf(outfile, "Heapframes size in match_data: %" SIZ_FORM "\n",
+cprintf(clr_profiling, "Heapframes size in match_data: %" SIZ_FORM "\n",
heapframes_size);
}
@@ -1177,24 +1177,24 @@ PCRE2_UCHAR buf[128];
len = pcre2_get_error_message(errorcode, buf, sizeof(buf)/sizeof(*buf));
if (len == PCRE2_ERROR_BADDATA && badcode_ok)
{
- fprintf(file, "%sPCRE2_ERROR_BADDATA (unknown error number)%s", before,
+ cprintf_file(file, clr_test_error, "%sPCRE2_ERROR_BADDATA (unknown error number)%s", before,
after);
}
else if (len < 0)
{
- fprintf(file, "\n** pcre2test internal error: cannot interpret error "
+ cprintf_file(file, clr_test_error, "\n** pcre2test internal error: cannot interpret error "
"number\n** Unexpected return (%d) from pcre2_get_error_message()\n", len);
}
else if ((unsigned)len != pcre2_strlen(buf))
{
- fprintf(file, "\n** pcre2test: unexpected length %d from pcre2_get_error_message()\n", len);
+ cprintf_file(file, clr_test_error, "\n** pcre2test: unexpected length %d from pcre2_get_error_message()\n", len);
return FALSE;
}
else
{
- fprintf(file, "%s", before);
- pchars(buf, len, FALSE, file);
- fprintf(file, "%s", after);
+ cprintf_file(file, clr_api_error, "%s", before);
+ pchars(clr_api_error, buf, len, FALSE, file);
+ cprintf_file(file, clr_api_error, "%s", after);
}
return len >= 0;
}
@@ -1229,26 +1229,26 @@ PCRE2_SIZE next_item_length = cb->next_item_length;
(void)callout_data; /* Not currently displayed */
-fprintf(outfile, "Callout ");
+cprintf(clr_output, "Callout ");
if (cb->callout_string != NULL)
{
uint32_t delimiter = cb->callout_string[-1];
- fprintf(outfile, "%c", CHAR_OUTPUT(delimiter));
- pchars(cb->callout_string, cb->callout_string_length, utf, outfile);
+ cprintf(clr_output, "%c", CHAR_OUTPUT(delimiter));
+ pchars(clr_output, cb->callout_string, cb->callout_string_length, utf, outfile);
for (i = 0; callout_start_delims[i] != 0; i++)
if (delimiter == callout_start_delims[i])
{
delimiter = callout_end_delims[i];
break;
}
- fprintf(outfile, "%c ", CHAR_OUTPUT(delimiter));
+ cprintf(clr_output, "%c ", CHAR_OUTPUT(delimiter));
}
-else fprintf(outfile, "%d ", cb->callout_number);
+else cprintf(clr_output, "%d ", cb->callout_number);
if (next_item_length == 0 && pattern_string[cb->pattern_position] != 0)
next_item_length = 1;
-pchars(pattern_string+cb->pattern_position, next_item_length, utf, outfile);
-fprintf(outfile, "\n");
+pchars(clr_output, pattern_string+cb->pattern_position, next_item_length, utf, outfile);
+cprintf(clr_output, "\n");
return 0;
}
@@ -1299,8 +1299,8 @@ if ((pat_patctl.control2 & CTL2_FRAMESIZE) != 0)
if ((pat_patctl.control & (CTL_BINCODE|CTL_FULLBINCODE)) != 0)
{
- fprintf(outfile, "------------------------------------------------------------------\n");
- pcre2_printint(compiled_code, outfile,
+ cprintf(clr_output, "------------------------------------------------------------------\n");
+ pcre2_printint_clr(clr_output, compiled_code, outfile,
(pat_patctl.control & CTL_FULLBINCODE) != 0);
}
@@ -1380,30 +1380,30 @@ if ((pat_patctl.control & CTL_INFO) != 0)
!= 0)
return PR_ABEND;
- fprintf(outfile, "Capture group count = %d\n", capture_count);
+ cprintf(clr_output, "Capture group count = %d\n", capture_count);
if (backrefmax > 0)
- fprintf(outfile, "Max back reference = %d\n", backrefmax);
+ cprintf(clr_output, "Max back reference = %d\n", backrefmax);
if (maxlookbehind > 0)
- fprintf(outfile, "Max lookbehind = %d\n", maxlookbehind);
+ cprintf(clr_output, "Max lookbehind = %d\n", maxlookbehind);
if (heap_limit_set)
- fprintf(outfile, "Heap limit = %u\n", heap_limit);
+ cprintf(clr_output, "Heap limit = %u\n", heap_limit);
if (match_limit_set)
- fprintf(outfile, "Match limit = %u\n", match_limit);
+ cprintf(clr_output, "Match limit = %u\n", match_limit);
if (depth_limit_set)
- fprintf(outfile, "Depth limit = %u\n", depth_limit);
+ cprintf(clr_output, "Depth limit = %u\n", depth_limit);
if (namecount > 0)
{
- fprintf(outfile, "Named capture groups:\n");
+ cprintf(clr_output, "Named capture groups:\n");
for (; namecount > 0; namecount--)
{
size_t length = pcre2_strlen(nametable + IMM2_SIZE);
- fprintf(outfile, " ");
+ cprintf(clr_output, " ");
/* In UTF mode the name may be a UTF string containing non-ASCII
letters and digits. We must output it as a UTF-8 string. In non-UTF mode,
@@ -1418,7 +1418,7 @@ if ((pat_patctl.control & CTL_INFO) != 0)
{
uint8_t u8buff[6];
int len = ord_to_utf8(*nameptr++, u8buff);
- fprintf(outfile, "%.*s", len, u8buff);
+ cprintf(clr_output, "%.*s", len, u8buff);
}
#endif
#if PCRE2_CODE_UNIT_WIDTH == 16
@@ -1433,29 +1433,29 @@ if ((pat_patctl.control & CTL_INFO) != 0)
if (ord_rc > 0) nameptr += ord_rc;
else c = *nameptr++;
len = ord_to_utf8(c, u8buff);
- fprintf(outfile, "%.*s", len, u8buff);
+ cprintf(clr_output, "%.*s", len, u8buff);
}
#endif
#if PCRE2_CODE_UNIT_WIDTH == 8
- fprintf(outfile, "%s", nametable + IMM2_SIZE);
+ cprintf(clr_output, "%s", nametable + IMM2_SIZE);
#endif
}
else /* Not UTF mode */
{
- pchars(nametable + IMM2_SIZE, length, FALSE, outfile);
+ pchars(clr_output, nametable + IMM2_SIZE, length, FALSE, outfile);
}
- while (length++ < nameentrysize - IMM2_SIZE) putc(' ', outfile);
+ while (length++ < nameentrysize - IMM2_SIZE) cprintf(clr_output, " ");
- fprintf(outfile, "%3d\n", GET2(nametable, 0));
+ cprintf(clr_output, "%3d\n", GET2(nametable, 0));
nametable = nametable + nameentrysize;
}
}
- if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");
- if (hasbackslashc) fprintf(outfile, "Contains \\C\n");
- if (match_empty) fprintf(outfile, "May match empty string\n");
+ if (hascrorlf) cprintf(clr_output, "Contains explicit CR or LF match\n");
+ if (hasbackslashc) cprintf(clr_output, "Contains \\C\n");
+ if (match_empty) cprintf(clr_output, "May match empty string\n");
pattern_info(PCRE2_INFO_ARGOPTIONS, &compile_options, FALSE);
pattern_info(PCRE2_INFO_ALLOPTIONS, &overall_options, FALSE);
@@ -1479,25 +1479,25 @@ if ((pat_patctl.control & CTL_INFO) != 0)
if ((compile_options|overall_options) != 0)
{
if (compile_options == overall_options)
- show_compile_options(compile_options, "Options:", "\n");
+ show_compile_options(clr_output, compile_options, "Options:", "\n");
else
{
- show_compile_options(compile_options, "Compile options:", "\n");
- show_compile_options(overall_options, "Overall options:", "\n");
+ show_compile_options(clr_output, compile_options, "Compile options:", "\n");
+ show_compile_options(clr_output, overall_options, "Overall options:", "\n");
}
}
if (extra_options != 0)
- show_compile_extra_options(extra_options, "Extra options:", "\n");
+ show_compile_extra_options(clr_output, extra_options, "Extra options:", "\n");
if (compiled_code->optimization_flags != PCRE2_OPTIMIZATION_ALL)
show_optimize_flags(compiled_code->optimization_flags, "Optimizations: ", "\n");
- if (jchanged) fprintf(outfile, "Duplicate name status changes\n");
+ if (jchanged) cprintf(clr_output, "Duplicate name status changes\n");
if ((pat_patctl.control2 & CTL2_BSR_SET) != 0 ||
(compiled_code->flags & PCRE2_BSR_SET) != 0)
- fprintf(outfile, "\\R matches %s\n", (bsr_convention == PCRE2_BSR_UNICODE)?
+ cprintf(clr_output, "\\R matches %s\n", (bsr_convention == PCRE2_BSR_UNICODE)?
"any Unicode newline" : "CR, LF, or CRLF");
if ((compiled_code->flags & PCRE2_NL_SET) != 0)
@@ -1505,27 +1505,27 @@ if ((pat_patctl.control & CTL_INFO) != 0)
switch (newline_convention)
{
case PCRE2_NEWLINE_CR:
- fprintf(outfile, "Forced newline is CR\n");
+ cprintf(clr_output, "Forced newline is CR\n");
break;
case PCRE2_NEWLINE_LF:
- fprintf(outfile, "Forced newline is LF\n");
+ cprintf(clr_output, "Forced newline is LF\n");
break;
case PCRE2_NEWLINE_CRLF:
- fprintf(outfile, "Forced newline is CRLF\n");
+ cprintf(clr_output, "Forced newline is CRLF\n");
break;
case PCRE2_NEWLINE_ANYCRLF:
- fprintf(outfile, "Forced newline is CR, LF, or CRLF\n");
+ cprintf(clr_output, "Forced newline is CR, LF, or CRLF\n");
break;
case PCRE2_NEWLINE_ANY:
- fprintf(outfile, "Forced newline is any Unicode newline\n");
+ cprintf(clr_output, "Forced newline is any Unicode newline\n");
break;
case PCRE2_NEWLINE_NUL:
- fprintf(outfile, "Forced newline is NUL\n");
+ cprintf(clr_output, "Forced newline is NUL\n");
break;
default:
@@ -1535,7 +1535,7 @@ if ((pat_patctl.control & CTL_INFO) != 0)
if (first_ctype == 2)
{
- fprintf(outfile, "First code unit at start or follows newline\n");
+ cprintf(clr_output, "First code unit at start or follows newline\n");
}
else if (first_ctype == 1)
{
@@ -1543,23 +1543,23 @@ if ((pat_patctl.control & CTL_INFO) != 0)
((compiled_code->flags & PCRE2_FIRSTCASELESS) == 0)?
"" : " (caseless)";
if (first_cunit != 0xff && PRINTABLE(first_cunit))
- fprintf(outfile, "First code unit = \'%c\'%s\n", CHAR_OUTPUT(first_cunit),
+ cprintf(clr_output, "First code unit = \'%c\'%s\n", CHAR_OUTPUT(first_cunit),
caseless);
else
{
- fprintf(outfile, "First code unit = ");
+ cprintf(clr_output, "First code unit = ");
if (first_cunit == 0xff)
- fprintf(outfile, "\\xff");
+ cprintf(clr_output, "\\xff");
else
- pchar(first_cunit, FALSE, outfile);
- fprintf(outfile, "%s\n", caseless);
+ pchar(clr_output, first_cunit, FALSE, outfile);
+ cprintf(clr_output, "%s\n", caseless);
}
}
else if (start_bits != NULL)
{
int input;
int c = 24;
- fprintf(outfile, "Starting code units:");
+ cprintf(clr_output, "Starting code units:");
for (input = 0; input < 256; input++)
{
int i = CHAR_INPUT_HEX(input);
@@ -1567,22 +1567,22 @@ if ((pat_patctl.control & CTL_INFO) != 0)
{
if (c > 75)
{
- fprintf(outfile, "\n ");
+ cprintf(clr_output, "\n ");
c = 2;
}
if (PRINTABLE(i) && i != CHAR_SPACE)
{
- fprintf(outfile, " %c", CHAR_OUTPUT(i));
+ cprintf(clr_output, " %c", CHAR_OUTPUT(i));
c += 2;
}
else
{
- fprintf(outfile, " \\x%02x", CHAR_OUTPUT_HEX(i));
+ cprintf(clr_output, " \\x%02x", CHAR_OUTPUT_HEX(i));
c += 5;
}
}
}
- fprintf(outfile, "\n");
+ cprintf(clr_output, "\n");
}
if (last_ctype != 0)
@@ -1591,33 +1591,33 @@ if ((pat_patctl.control & CTL_INFO) != 0)
((compiled_code->flags & PCRE2_LASTCASELESS) == 0)?
"" : " (caseless)";
if (PRINTABLE(last_cunit))
- fprintf(outfile, "Last code unit = \'%c\'%s\n", CHAR_OUTPUT(last_cunit),
+ cprintf(clr_output, "Last code unit = \'%c\'%s\n", CHAR_OUTPUT(last_cunit),
caseless);
else
{
- fprintf(outfile, "Last code unit = ");
- pchar(last_cunit, FALSE, outfile);
- fprintf(outfile, "%s\n", caseless);
+ cprintf(clr_output, "Last code unit = ");
+ pchar(clr_output, last_cunit, FALSE, outfile);
+ cprintf(clr_output, "%s\n", caseless);
}
}
if ((compiled_code->optimization_flags & PCRE2_OPTIM_START_OPTIMIZE) != 0)
- fprintf(outfile, "Subject length lower bound = %d\n", minlength);
+ cprintf(clr_output, "Subject length lower bound = %d\n", minlength);
if (pat_patctl.jit != 0 && (pat_patctl.control & CTL_JITVERIFY) != 0)
{
#ifdef SUPPORT_JIT
if (compiled_code->executable_jit != NULL)
- fprintf(outfile, "JIT compilation was successful\n");
+ cprintf(clr_output, "JIT compilation was successful\n");
else
{
- fprintf(outfile, "JIT compilation was not successful");
+ cprintf(clr_api_error, "JIT compilation was not successful");
if (jitrc != 0 && !print_error_message(jitrc, " (", ")"))
return PR_ABEND;
- fprintf(outfile, "\n");
+ cprintf(clr_api_error, "\n");
}
#else
- fprintf(outfile, "JIT support is not available in this version of PCRE2\n");
+ cprintf(clr_api_error, "JIT support is not available in this version of PCRE2\n");
#endif
}
}
@@ -1629,7 +1629,7 @@ rc = pcre2_callout_enumerate(compiled_code,
callout_enumerate_function_void, NULL);
if (rc != 0)
{
- fprintf(outfile, "Callout enumerate failed: error %d: ", rc);
+ cprintf(clr_test_error, "Callout enumerate failed: error %d: ", rc);
if (rc < 0 && !print_error_message(rc, "", "\n"))
return PR_ABEND;
return PR_SKIP;
@@ -1656,7 +1656,7 @@ Returns: FALSE if print_error_message() fails
static BOOL
serial_error(int rc, const char *msg)
{
-fprintf(outfile, "%s failed: error %d: ", msg, rc);
+cprintf(clr_api_error, "%s failed: error %d: ", msg, rc);
return print_error_message(rc, "", "\n");
}
@@ -1714,14 +1714,14 @@ argptr = buffer + cmdlen + 1;
if (restrict_for_perl_test && cmd != CMD_PATTERN && cmd != CMD_SUBJECT &&
cmd != CMD_IF && cmd != CMD_ENDIF)
{
- fprintf(outfile, "** #%s is not allowed after #perltest\n", cmdname);
+ cprintf(clr_test_error, "** #%s is not allowed after #perltest\n", cmdname);
return PR_ABEND;
}
switch(cmd)
{
case CMD_UNKNOWN:
- fprintf(outfile, "** Unknown command: %s", buffer);
+ cprintf(clr_test_error, "** Unknown command: %s", buffer);
break;
case CMD_FORBID_UTF:
@@ -1779,7 +1779,7 @@ switch(cmd)
case CMD_POPCOPY:
if (patstacknext <= 0)
{
- fprintf(outfile, "** Can't pop off an empty stack\n");
+ cprintf(clr_test_error, "** Can't pop off an empty stack\n");
return PR_SKIP;
}
memset(&pat_patctl, 0, sizeof(patctl)); /* Completely unset */
@@ -1809,7 +1809,7 @@ switch(cmd)
case CMD_SAVE:
if (patstacknext <= 0)
{
- fprintf(outfile, "** No stacked patterns to save\n");
+ cprintf(clr_test_error, "** No stacked patterns to save\n");
return PR_OK;
}
@@ -1834,7 +1834,7 @@ switch(cmd)
for (i = 0; i < 4; i++) fputc((serial_size >> (i*8)) & 255, f);
if (fwrite(serial, 1, serial_size, f) != serial_size)
{
- fprintf(outfile, "** Wrong return from fwrite()\n");
+ cprintf(clr_test_error, "** Wrong return from fwrite()\n");
fclose(f);
return PR_ABEND;
}
@@ -1861,7 +1861,7 @@ switch(cmd)
serial = malloc(serial_size);
if (serial == NULL)
{
- fprintf(outfile, "** Failed to get memory (size %" SIZ_FORM ") for #load\n",
+ cprintf(clr_test_error, "** Failed to get memory (size %" SIZ_FORM ") for #load\n",
serial_size);
fclose(f);
return PR_ABEND;
@@ -1872,7 +1872,7 @@ switch(cmd)
if (i != serial_size)
{
- fprintf(outfile, "** Wrong return from fread()\n");
+ cprintf(clr_test_error, "** Wrong return from fread()\n");
yield = PR_ABEND;
}
else
@@ -1886,10 +1886,10 @@ switch(cmd)
{
if (rc + patstacknext > PATSTACKSIZE)
{
- fprintf(outfile, "** Not enough space on pattern stack for %d pattern%s\n",
+ cprintf(clr_test_error, "** Not enough space on pattern stack for %d pattern%s\n",
rc, (rc == 1)? "" : "s");
rc = PATSTACKSIZE - patstacknext;
- fprintf(outfile, "** Decoding %d pattern%s\n", rc,
+ cprintf(clr_test_error, "** Decoding %d pattern%s\n", rc,
(rc == 1)? "" : "s");
}
rc = pcre2_serialize_decode(patstack + patstacknext, rc, serial,
@@ -1920,12 +1920,12 @@ switch(cmd)
if (tables3 == NULL)
{
- fprintf(outfile, "** Failed: malloc/config for #loadtables\n");
+ cprintf(clr_test_error, "** Failed: malloc/config for #loadtables\n");
yield = PR_ABEND;
}
else if (fread(tables3, 1, loadtables_length, f) != loadtables_length)
{
- fprintf(outfile, "** Wrong return from fread()\n");
+ cprintf(clr_test_error, "** Wrong return from fread()\n");
yield = PR_ABEND;
}
@@ -1935,7 +1935,7 @@ switch(cmd)
case CMD_IF:
if (inside_if)
{
- fprintf(outfile, "** Nested #if not supported\n");
+ cprintf(clr_test_error, "** Nested #if not supported\n");
return PR_ABEND;
}
@@ -1962,7 +1962,7 @@ switch(cmd)
}
if (i == COPTLISTCOUNT)
{
- fprintf(outfile, "** Unknown condition: %s\n", buffer);
+ cprintf(clr_test_error, "** Unknown condition: %s\n", buffer);
return PR_ABEND;
}
@@ -1976,7 +1976,7 @@ switch(cmd)
case CMD_ENDIF:
if (!inside_if)
{
- fprintf(outfile, "** Unexpected #endif\n");
+ cprintf(clr_test_error, "** Unexpected #endif\n");
return PR_ABEND;
}
inside_if = FALSE;
@@ -2023,7 +2023,7 @@ PCRE2_SIZE erroroffset;
if (restrict_for_perl_test && delimiter != '/')
{
- fprintf(outfile, "** The only allowed delimiter after #perltest is '/'\n");
+ cprintf(clr_test_error, "** The only allowed delimiter after #perltest is '/'\n");
return PR_ABEND;
}
@@ -2044,12 +2044,12 @@ for(;;)
p++;
}
if (*p != 0) break;
- if ((p = extend_inputline(infile, p, " > ")) == NULL)
+ if ((p = extend_inputline(infile, p, PROMPT(" > "))) == NULL)
{
- fprintf(outfile, "** Unexpected EOF\n");
+ cprintf(clr_test_error, "** Unexpected EOF\n");
return PR_ABEND;
}
- if (!INTERACTIVE(infile)) fprintf(outfile, "%s", (char *)p);
+ if (!INTERACTIVE(infile)) cprintf(clr_test_error, "%s", (char *)p);
}
/* If the first character after the delimiter is backslash, make the pattern
@@ -2078,12 +2078,12 @@ exclusive with the utf modifier. */
if ((pat_patctl.control & CTL_UTF8_INPUT) != 0)
{
#if PCRE2_CODE_UNIT_WIDTH == 8
- fprintf(outfile, "** The utf8_input modifier is not allowed in 8-bit mode\n");
+ cprintf(clr_test_error, "** The utf8_input modifier is not allowed in 8-bit mode\n");
return PR_SKIP;
#else
if (utf)
{
- fprintf(outfile, "** The utf and utf8_input modifiers are mutually exclusive\n");
+ cprintf(clr_test_error, "** The utf and utf8_input modifiers are mutually exclusive\n");
return PR_SKIP;
}
#endif
@@ -2094,7 +2094,7 @@ if ((pat_patctl.control & CTL_UTF8_INPUT) != 0)
if (pat_patctl.convert_type != CONVERT_UNSET &&
(pat_patctl.control & CTL_POSIX) != 0)
{
- fprintf(outfile, "** The convert and posix modifiers are mutually exclusive\n");
+ cprintf(clr_test_error, "** The convert and posix modifiers are mutually exclusive\n");
return PR_SKIP;
}
@@ -2106,8 +2106,8 @@ for (k = 0; k < sizeof(exclusive_pat_controls)/sizeof(uint32_t); k++)
uint32_t c = pat_patctl.control & exclusive_pat_controls[k];
if (c != 0 && c != (c & (~c+1)))
{
- show_controls(c, 0, "** Not allowed together:");
- fprintf(outfile, "\n");
+ show_controls(clr_test_error, c, 0, "** Not allowed together:");
+ cprintf(clr_test_error, "\n");
return PR_SKIP;
}
}
@@ -2145,7 +2145,7 @@ if ((pat_patctl.control & CTL_HEXPAT) != 0)
d = *pp;
if (d == 0)
{
- fprintf(outfile, "** Missing closing quote in hex pattern: "
+ cprintf(clr_test_error, "** Missing closing quote in hex pattern: "
"opening quote is at offset %" PTR_FORM ".\n", pq - buffer - 2);
return PR_SKIP;
}
@@ -2160,19 +2160,19 @@ if ((pat_patctl.control & CTL_HEXPAT) != 0)
{
if (!isxdigit(c))
{
- fprintf(outfile, "** Unexpected non-hex-digit '%c' at offset %"
+ cprintf(clr_test_error, "** Unexpected non-hex-digit '%c' at offset %"
PTR_FORM " in hex pattern: quote missing?\n", c, pp - buffer - 2);
return PR_SKIP;
}
if (*pp == 0)
{
- fprintf(outfile, "** Odd number of digits in hex pattern\n");
+ cprintf(clr_test_error, "** Odd number of digits in hex pattern\n");
return PR_SKIP;
}
d = *pp;
if (!isxdigit(d))
{
- fprintf(outfile, "** Unexpected non-hex-digit '%c' at offset %"
+ cprintf(clr_test_error, "** Unexpected non-hex-digit '%c' at offset %"
PTR_FORM " in hex pattern: quote missing?\n", d, pp - buffer - 1);
return PR_SKIP;
}
@@ -2219,7 +2219,7 @@ else if ((pat_patctl.control & CTL_EXPAND) != 0)
uli = strtoul((const char *)pe, &endptr, 10);
if (U32OVERFLOW(uli))
{
- fprintf(outfile, "** Pattern repeat count too large\n");
+ cprintf(clr_test_error, "** Pattern repeat count too large\n");
return PR_SKIP;
}
@@ -2229,7 +2229,7 @@ else if ((pat_patctl.control & CTL_EXPAND) != 0)
{
if (i == 0)
{
- fprintf(outfile, "** Zero repeat not allowed\n");
+ cprintf(clr_test_error, "** Zero repeat not allowed\n");
return PR_SKIP;
}
pc += 2;
@@ -2268,7 +2268,7 @@ else if ((pat_patctl.control & CTL_EXPAND) != 0)
patlen = pt - pbuffer8;
if ((pat_patctl.control & CTL_INFO) != 0)
- fprintf(outfile, "Expanded: %s\n", pbuffer8);
+ cprintf(clr_output, "Expanded: %s\n", pbuffer8);
}
/* Neither hex nor expanded, just copy the input verbatim. */
@@ -2284,12 +2284,12 @@ if (pat_patctl.locale[0] != 0)
{
if (pat_patctl.tables_id != 0)
{
- fprintf(outfile, "** 'Locale' and 'tables' must not both be set\n");
+ cprintf(clr_test_error, "** 'Locale' and 'tables' must not both be set\n");
return PR_SKIP;
}
if (setlocale(LC_CTYPE, (const char *)pat_patctl.locale) == NULL)
{
- fprintf(outfile, "** Failed to set locale \"%s\"\n", pat_patctl.locale);
+ cprintf(clr_test_error, "** Failed to set locale \"%s\"\n", pat_patctl.locale);
return PR_SKIP;
}
if (strcmp((const char *)pat_patctl.locale, (const char *)locale_name) != 0)
@@ -2313,7 +2313,7 @@ else switch (pat_patctl.tables_id)
case 3:
if (tables3 == NULL)
{
- fprintf(outfile, "** 'Tables = 3' is invalid: binary tables have not "
+ cprintf(clr_test_error, "** 'Tables = 3' is invalid: binary tables have not "
"been loaded\n");
return PR_SKIP;
}
@@ -2321,7 +2321,7 @@ else switch (pat_patctl.tables_id)
break;
default:
- fprintf(outfile, "** 'Tables' must specify 0, 1, 2, or 3.\n");
+ cprintf(clr_test_error, "** 'Tables' must specify 0, 1, 2, or 3.\n");
return PR_SKIP;
}
@@ -2341,7 +2341,7 @@ local character tables. Neither does it have 16-bit or 32-bit support. */
if ((pat_patctl.control & CTL_POSIX) != 0)
{
#if PCRE2_CODE_UNIT_WIDTH != 8
- fprintf(outfile, "** The POSIX interface is available only in 8-bit mode\n");
+ cprintf(clr_test_error, "** The POSIX interface is available only in 8-bit mode\n");
return PR_SKIP;
#else
@@ -2360,7 +2360,8 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
if ((pat_patctl.options & ~POSIX_SUPPORTED_COMPILE_OPTIONS) != 0)
{
show_compile_options(
- pat_patctl.options & (uint32_t)(~POSIX_SUPPORTED_COMPILE_OPTIONS),
+ clr_test_error,
+ pat_patctl.options & (uint32_t)(~POSIX_SUPPORTED_COMPILE_OPTIONS),
msg, "");
msg = "";
}
@@ -2369,7 +2370,8 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
(uint32_t)(~POSIX_SUPPORTED_COMPILE_EXTRA_OPTIONS)) != 0)
{
show_compile_extra_options(
- pat_context->extra_options &
+ clr_test_error,
+ pat_context->extra_options &
(uint32_t)(~POSIX_SUPPORTED_COMPILE_EXTRA_OPTIONS), msg, "");
msg = "";
}
@@ -2378,6 +2380,7 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
(pat_patctl.control2 & (uint32_t)(~POSIX_SUPPORTED_COMPILE_CONTROLS2)) != 0)
{
show_controls(
+ clr_test_error,
pat_patctl.control & (uint32_t)(~POSIX_SUPPORTED_COMPILE_CONTROLS),
pat_patctl.control2 & (uint32_t)(~POSIX_SUPPORTED_COMPILE_CONTROLS2),
msg);
@@ -2398,7 +2401,7 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
if (pat_context->parens_nest_limit != PARENS_NEST_DEFAULT)
prmsg(&msg, "parens_nest_limit");
- if (msg[0] == 0) fprintf(outfile, "\n");
+ if (msg[0] == 0) cprintf(clr_test_error, "\n");
/* Translate PCRE2 options to POSIX options and then compile. */
@@ -2440,16 +2443,16 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
usize = regerror(rc, &preg, regbuffer, bsize);
strsize = ((usize > bsize)? bsize : usize) - 1;
- fprintf(outfile, "Failed: POSIX code %d: ", rc);
- if (bsize > 0) pchars((PCRE2_SPTR8)regbuffer, strsize, utf, outfile);
- fputs("\n", outfile);
+ cprintf(clr_api_error, "Failed: POSIX code %d: ", rc);
+ if (bsize > 0) pchars(clr_api_error, (PCRE2_SPTR8)regbuffer, strsize, utf, outfile);
+ cprintf(clr_api_error, "\n", outfile);
if (usize > bsize)
{
- fprintf(outfile, "** regerror() message truncated\n");
+ cprintf(clr_test_error, "** regerror() message truncated\n");
}
if (bsize > 0 && strlen(regbuffer) != strsize)
{
- fprintf(outfile, "** regerror() strlen incorrect\n");
+ cprintf(clr_test_error, "** regerror() strlen incorrect\n");
return PR_ABEND;
}
return PR_SKIP;
@@ -2468,7 +2471,7 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
preg.re_match_data == NULL ||
preg.re_cflags != cflags)
{
- fprintf(outfile,
+ cprintf(clr_test_error,
"** The regcomp() function returned zero (success), but the values set\n"
"** in the preg block are not valid for PCRE2. Check that pcre2test is\n"
"** linked with PCRE2's pcre2posix module (-lpcre2-posix) and not with\n"
@@ -2488,24 +2491,24 @@ if ((pat_patctl.control & (CTL_PUSH|CTL_PUSHCOPY|CTL_PUSHTABLESCOPY)) != 0)
{
if (pat_patctl.replacement[0] != 0)
{
- fprintf(outfile, "** Replacement text is not supported with 'push'.\n");
+ cprintf(clr_test_error, "** Replacement text is not supported with 'push'.\n");
return PR_OK;
}
if ((pat_patctl.control & ~PUSH_SUPPORTED_COMPILE_CONTROLS) != 0 ||
(pat_patctl.control2 & ~PUSH_SUPPORTED_COMPILE_CONTROLS2) != 0)
{
- show_controls(pat_patctl.control & ~PUSH_SUPPORTED_COMPILE_CONTROLS,
+ show_controls(clr_test_error, pat_patctl.control & ~PUSH_SUPPORTED_COMPILE_CONTROLS,
pat_patctl.control2 & ~PUSH_SUPPORTED_COMPILE_CONTROLS2,
"** Ignored when compiled pattern is stacked with 'push':");
- fprintf(outfile, "\n");
+ cprintf(clr_test_error, "\n");
}
if ((pat_patctl.control & PUSH_COMPILE_ONLY_CONTROLS) != 0 ||
(pat_patctl.control2 & PUSH_COMPILE_ONLY_CONTROLS2) != 0)
{
- show_controls(pat_patctl.control & PUSH_COMPILE_ONLY_CONTROLS,
+ show_controls(clr_test_error, pat_patctl.control & PUSH_COMPILE_ONLY_CONTROLS,
pat_patctl.control2 & PUSH_COMPILE_ONLY_CONTROLS2,
"** Applies only to compile when pattern is stacked with 'push':");
- fprintf(outfile, "\n");
+ cprintf(clr_test_error, "\n");
}
}
@@ -2522,17 +2525,17 @@ errorcode = G(to,PCRE2_CODE_UNIT_WIDTH)(pbuffer8, utf, &patlen);
switch(errorcode)
{
case -1:
- fprintf(outfile, "** Failed: invalid UTF-8 string cannot be "
+ cprintf(clr_test_error, "** Failed: invalid UTF-8 string cannot be "
"converted to " STR(PCRE2_CODE_UNIT_WIDTH) "-bit string\n");
return PR_SKIP;
case -2:
- fprintf(outfile, "** Failed: character value greater than 0x10ffff "
+ cprintf(clr_test_error, "** Failed: character value greater than 0x10ffff "
"cannot be converted to UTF\n");
return PR_SKIP;
case -3:
- fprintf(outfile, "** Failed: character value greater than 0xffff "
+ cprintf(clr_test_error, "** Failed: character value greater than 0xffff "
"cannot be converted to 16-bit in non-UTF mode\n");
return PR_SKIP;
@@ -2568,7 +2571,7 @@ if (pat_patctl.convert_type != CONVERT_UNSET)
converted_pattern = malloc(CU2BYTES(converted_length));
if (converted_pattern == NULL)
{
- fprintf(outfile, "** Failed: malloc failed for converted pattern\n");
+ cprintf(clr_test_error, "** Failed: malloc failed for converted pattern\n");
return PR_SKIP;
}
}
@@ -2587,7 +2590,7 @@ if (pat_patctl.convert_type != CONVERT_UNSET)
rc = pcre2_set_glob_escape(con_context, CHAR_INPUT(escape));
if (rc != 0)
{
- fprintf(outfile, "** Invalid glob escape '%c'\n",
+ cprintf(clr_api_error, "** Invalid glob escape '%c'\n",
pat_patctl.convert_glob_escape);
convert_return = PR_SKIP;
goto CONVERT_FINISH;
@@ -2600,7 +2603,7 @@ if (pat_patctl.convert_type != CONVERT_UNSET)
rc = pcre2_set_glob_separator(con_context, CHAR_INPUT(separator));
if (rc != 0)
{
- fprintf(outfile, "** Invalid glob separator '%c'\n",
+ cprintf(clr_api_error, "** Invalid glob separator '%c'\n",
pat_patctl.convert_glob_separator);
convert_return = PR_SKIP;
goto CONVERT_FINISH;
@@ -2612,7 +2615,7 @@ if (pat_patctl.convert_type != CONVERT_UNSET)
if (rc != 0)
{
- fprintf(outfile, "** Pattern conversion error at offset %" SIZ_FORM ": ",
+ cprintf(clr_api_error, "** Pattern conversion error at offset %" SIZ_FORM ": ",
converted_length);
convert_return = print_error_message(rc, "", "\n")? PR_SKIP:PR_ABEND;
}
@@ -2621,15 +2624,15 @@ if (pat_patctl.convert_type != CONVERT_UNSET)
else
{
- pchars(converted_pattern, converted_length, utf, outfile);
- fprintf(outfile, "\n");
+ pchars(clr_output, converted_pattern, converted_length, utf, outfile);
+ cprintf(clr_output, "\n");
if (CU2BYTES(converted_length + 1) > pbuffer_size)
{
// TODO This seems... unfortunate? There must be some patterns that can
// expand when converted from glob to regex, but we aren't allowing for
// that here. Presumably we should expand the buffer rather than moan.
- fprintf(outfile, "** Pattern conversion is too long for the buffer\n");
+ cprintf(clr_api_error, "** Pattern conversion is too long for the buffer\n");
convert_return = PR_SKIP;
}
else
@@ -2715,7 +2718,7 @@ if (timeit > 0)
pcre2_code_free(compiled_code);
}
total_compile_time += time_taken;
- fprintf(outfile, "Compile time %8.4f microseconds\n",
+ cprintf(clr_profiling, "Compile time %8.4f microseconds\n",
((1000000 / CLOCKS_PER_SEC) * (double)time_taken) / timeit);
}
@@ -2744,7 +2747,7 @@ if (malloc_testing)
if (i < target_mallocs &&
!(compiled_code == NULL && errorcode == PCRE2_ERROR_HEAP_FAILED))
{
- fprintf(outfile, "** malloc() compile test did not fail as expected (%d)\n",
+ cprintf(clr_test_error, "** malloc() compile test did not fail as expected (%d)\n",
errorcode);
return PR_ABEND;
}
@@ -2783,20 +2786,20 @@ if (compiled_code != NULL && pat_patctl.jit != 0)
use_pat_context);
if (compiled_code == NULL)
{
- fprintf(outfile, "** Unexpected - pattern compilation not successful\n");
+ cprintf(clr_test_error, "** Unexpected - pattern compilation not successful\n");
return PR_ABEND;
}
if (jitrc != 0)
{
- fprintf(outfile, "JIT compilation was not successful");
+ cprintf(clr_test_error, "JIT compilation was not successful");
if (!print_error_message(jitrc, " (", ")\n")) return PR_ABEND;
break;
}
}
total_jit_compile_time += time_taken;
if (jitrc == 0)
- fprintf(outfile, "JIT compile %8.4f microseconds\n",
+ cprintf(clr_profiling, "JIT compile %8.4f microseconds\n",
((1000000 / CLOCKS_PER_SEC) * (double)time_taken) / timeit);
}
@@ -2815,7 +2818,7 @@ if (compiled_code != NULL && pat_patctl.jit != 0)
use_pat_context);
if (compiled_code == NULL)
{
- fprintf(outfile, "** Unexpected - pattern compilation not successful\n");
+ cprintf(clr_test_error, "** Unexpected - pattern compilation not successful\n");
return PR_ABEND;
}
@@ -2825,7 +2828,7 @@ if (compiled_code != NULL && pat_patctl.jit != 0)
if (i < target_mallocs && jitrc != PCRE2_ERROR_NOMEMORY)
{
- fprintf(outfile, "** malloc() JIT compile test did not fail as expected (%d)\n",
+ cprintf(clr_test_error, "** malloc() JIT compile test did not fail as expected (%d)\n",
jitrc);
return PR_ABEND;
}
@@ -2837,7 +2840,7 @@ if (compiled_code != NULL && pat_patctl.jit != 0)
if (jitrc != 0 && (pat_patctl.control & CTL_JITVERIFY) != 0)
{
- fprintf(outfile, "JIT compilation was not successful");
+ cprintf(clr_test_error, "JIT compilation was not successful");
if (!print_error_message(jitrc, " (", ")\n")) return PR_ABEND;
}
}
@@ -2849,7 +2852,7 @@ if (compiled_code == NULL)
{
int direction = error_direction(errorcode, erroroffset);
- fprintf(outfile, "Failed: error %d at offset %d: ", errorcode,
+ cprintf(clr_api_error, "Failed: error %d at offset %d: ", errorcode,
(int)erroroffset);
if (!print_error_message(errorcode, "", "\n")) return PR_ABEND;
@@ -2868,7 +2871,7 @@ if (compiled_code == NULL)
n = utf_to_ord(q, q_end, &cc);
if (n <= 0)
{
- fprintf(outfile, "** Erroroffset %d splits a UTF character\n", (int)erroroffset);
+ cprintf(clr_test_error, "** Erroroffset %d splits a UTF character\n", (int)erroroffset);
return PR_ABEND;
}
}
@@ -2878,9 +2881,9 @@ if (compiled_code == NULL)
if (direction < 0)
{
- fprintf(outfile, "** Error code %d not implemented in error_direction().\n", errorcode);
- fprintf(outfile, " error_direction() should usually return '1' for newly-added errors,\n");
- fprintf(outfile, " and the offset should be just to the right of the bad character.\n");
+ cprintf(clr_test_error, "** Error code %d not implemented in error_direction().\n", errorcode);
+ cprintf(clr_test_error, " error_direction() should usually return '1' for newly-added errors,\n");
+ cprintf(clr_test_error, " and the offset should be just to the right of the bad character.\n");
return PR_ABEND;
}
@@ -2889,24 +2892,24 @@ if (compiled_code == NULL)
PCRE2_SIZE full_patlen = (patlen != PCRE2_ZERO_TERMINATED)? patlen :
pcre2_strlen(pbuffer);
- fprintf(outfile, " here: ");
+ cprintf(clr_api_error, " here: ");
if (erroroffset > 0)
{
- ptrunc(pbuffer, full_patlen, erroroffset, TRUE, utf, outfile);
- fprintf(outfile, " ");
+ ptrunc(clr_api_error, pbuffer, full_patlen, erroroffset, TRUE, utf, outfile);
+ cprintf(clr_api_error, " ");
}
- fprintf(outfile, (direction == 1)? "|<--|" : (direction == 2)? "|-->|" : "|<-->|");
+ cprintf(clr_api_error, (direction == 1)? "|<--|" : (direction == 2)? "|-->|" : "|<-->|");
if (erroroffset < full_patlen)
{
- fprintf(outfile, " ");
- ptrunc(pbuffer, full_patlen, erroroffset, FALSE, utf, outfile);
+ cprintf(clr_api_error, " ");
+ ptrunc(clr_api_error, pbuffer, full_patlen, erroroffset, FALSE, utf, outfile);
}
- fprintf(outfile, "\n");
+ cprintf(clr_api_error, "\n");
}
else if (erroroffset != 0)
{
- fprintf(outfile, "** Unexpected non-zero erroroffset %d for error code %d\n",
+ cprintf(clr_api_error, "** Unexpected non-zero erroroffset %d for error code %d\n",
(int)erroroffset, errorcode);
return PR_ABEND;
}
@@ -2922,7 +2925,7 @@ if (forbid_utf != 0)
{
if ((compiled_code->flags & PCRE2_HASBKPORX) != 0)
{
- fprintf(outfile, "** \\P, \\p, and \\X are not allowed after the "
+ cprintf(clr_test_error, "** \\P, \\p, and \\X are not allowed after the "
"#forbid_utf command\n");
return PR_SKIP;
}
@@ -2958,7 +2961,7 @@ if ((pat_patctl.control & CTL_PUSH) != 0)
{
if (patstacknext >= PATSTACKSIZE)
{
- fprintf(outfile, "** Too many pushed patterns (max %d)\n", PATSTACKSIZE);
+ cprintf(clr_test_error, "** Too many pushed patterns (max %d)\n", PATSTACKSIZE);
return PR_ABEND;
}
patstack[patstacknext++] = compiled_code;
@@ -2973,7 +2976,7 @@ if ((pat_patctl.control & (CTL_PUSHCOPY|CTL_PUSHTABLESCOPY)) != 0)
{
if (patstacknext >= PATSTACKSIZE)
{
- fprintf(outfile, "** Too many pushed patterns (max %d)\n", PATSTACKSIZE);
+ cprintf(clr_test_error, "** Too many pushed patterns (max %d)\n", PATSTACKSIZE);
return PR_ABEND;
}
if ((pat_patctl.control & CTL_PUSHCOPY) != 0)
@@ -3102,7 +3105,7 @@ for (;;)
{
if ((mid & 0x80000000u) != 0)
{
- fprintf(outfile, "Can't find minimum %s limit: check pattern for "
+ cprintf(clr_api_error, "Can't find minimum %s limit: check pattern for "
"restriction\n", msg);
break;
}
@@ -3122,12 +3125,12 @@ for (;;)
if (errnumber == PCRE2_ERROR_HEAPLIMIT && mid < stack_start)
{
- fprintf(outfile, "Minimum %s limit = 0\n", msg);
+ cprintf(clr_output, "Minimum %s limit = 0\n", msg);
break;
}
if (mid == min + 1)
{
- fprintf(outfile, "Minimum %s limit = %d\n", msg, mid);
+ cprintf(clr_output, "Minimum %s limit = %d\n", msg, mid);
break;
}
max = mid;
@@ -3165,17 +3168,17 @@ BOOL utf = (compiled_code->overall_options & PCRE2_UTF) != 0;
if (outfile == NULL) goto YIELD;
-fprintf(outfile, "%2d(%d) Old %" SIZ_FORM " %" SIZ_FORM " \"",
+cprintf(clr_output, "%2d(%d) Old %" SIZ_FORM " %" SIZ_FORM " \"",
scb->subscount, scb->oveccount,
scb->ovector[0], scb->ovector[1]);
-pchars(scb->input + scb->ovector[0], scb->ovector[1] - scb->ovector[0],
+pchars(clr_output, scb->input + scb->ovector[0], scb->ovector[1] - scb->ovector[0],
utf, outfile);
-fprintf(outfile, "\" New %" SIZ_FORM " %" SIZ_FORM " \"",
+cprintf(clr_output, "\" New %" SIZ_FORM " %" SIZ_FORM " \"",
scb->output_offsets[0], scb->output_offsets[1]);
-pchars(scb->output + scb->output_offsets[0],
+pchars(clr_output, scb->output + scb->output_offsets[0],
scb->output_offsets[1] - scb->output_offsets[0], utf, outfile);
YIELD:
@@ -3183,15 +3186,15 @@ pchars(scb->output + scb->output_offsets[0],
if (scb->subscount == dat_datctl.substitute_stop)
{
yield = -1;
- if (outfile != NULL) fprintf(outfile, " STOPPED");
+ if (outfile != NULL) cprintf(clr_output, " STOPPED");
}
else if (scb->subscount == dat_datctl.substitute_skip)
{
yield = +1;
- if (outfile != NULL) fprintf(outfile, " SKIPPED");
+ if (outfile != NULL) cprintf(clr_output, " SKIPPED");
}
-if (outfile != NULL) fprintf(outfile, "\"\n");
+if (outfile != NULL) cprintf(clr_output, "\"\n");
return yield;
}
@@ -3327,15 +3330,15 @@ if ((dat_datctl.control2 & CTL2_CALLOUT_EXTRA) != 0)
switch (cb->callout_flags)
{
case PCRE2_CALLOUT_BACKTRACK:
- fprintf(f, "Backtrack\n");
+ cprintf_file(f, clr_output, "Backtrack\n");
break;
case PCRE2_CALLOUT_STARTMATCH|PCRE2_CALLOUT_BACKTRACK:
- fprintf(f, "Backtrack\nNo other matching paths\n");
+ cprintf_file(f, clr_output, "Backtrack\nNo other matching paths\n");
PCRE2_FALLTHROUGH /* Fall through */
case PCRE2_CALLOUT_STARTMATCH:
- fprintf(f, "New match attempt\n");
+ cprintf_file(f, clr_output, "New match attempt\n");
break;
default:
@@ -3351,17 +3354,17 @@ isn't a tidy way to fit it in the rest of the data. */
if (cb->callout_string != NULL)
{
uint32_t delimiter = cb->callout_string[-1];
- fprintf(outfile, "Callout (%" SIZ_FORM "): %c",
+ cprintf(clr_output, "Callout (%" SIZ_FORM "): %c",
cb->callout_string_offset, CHAR_OUTPUT(delimiter));
- pchars(cb->callout_string, cb->callout_string_length, utf, outfile);
+ pchars(clr_output, cb->callout_string, cb->callout_string_length, utf, outfile);
for (i = 0; callout_start_delims[i] != 0; i++)
if (delimiter == callout_start_delims[i])
{
delimiter = callout_end_delims[i];
break;
}
- fprintf(outfile, "%c", CHAR_OUTPUT(delimiter));
- if (!callout_capture) fprintf(outfile, "\n");
+ cprintf(clr_output, "%c", CHAR_OUTPUT(delimiter));
+ if (!callout_capture) cprintf(clr_output, "\n");
}
/* Show captured strings if required */
@@ -3369,19 +3372,19 @@ if (cb->callout_string != NULL)
if (callout_capture)
{
if (cb->callout_string == NULL)
- fprintf(outfile, "Callout %d:", cb->callout_number);
- fprintf(outfile, " last capture = %d\n", cb->capture_last);
+ cprintf(clr_output, "Callout %d:", cb->callout_number);
+ cprintf(clr_output, " last capture = %d\n", cb->capture_last);
for (i = 2; i < cb->capture_top * 2; i += 2)
{
- fprintf(outfile, "%2d: ", i/2);
+ cprintf(clr_output, "%2d: ", i/2);
if (cb->offset_vector[i] == PCRE2_UNSET)
- fprintf(outfile, "");
+ cprintf(clr_api_error, "");
else
{
- pchars(cb->subject + cb->offset_vector[i],
+ pchars(clr_output, cb->subject + cb->offset_vector[i],
cb->offset_vector[i+1] - cb->offset_vector[i], utf, f);
}
- fprintf(outfile, "\n");
+ cprintf(clr_output, "\n");
}
}
@@ -3392,11 +3395,11 @@ lengths of the substrings. */
if (callout_where)
{
- if (f != NULL) fprintf(f, "--->");
+ if (f != NULL) cprintf_file(f, clr_output, "--->");
/* The subject before the match start. */
- pre_start = pchars(cb->subject, cb->start_match, utf, f);
+ pre_start = pchars(clr_output, cb->subject, cb->start_match, utf, f);
/* If a lookbehind is involved, the current position may be earlier than the
match start. If so, use the match start instead. */
@@ -3406,19 +3409,19 @@ if (callout_where)
/* The subject between the match start and the current position. */
- post_start = pchars(cb->subject + cb->start_match,
+ post_start = pchars(clr_output, cb->subject + cb->start_match,
current_position - cb->start_match, utf, f);
/* Print from the current position to the end. */
- pchars(cb->subject + current_position, cb->subject_length - current_position,
+ pchars(clr_output, cb->subject + current_position, cb->subject_length - current_position,
utf, f);
/* Calculate the total subject printed length (no print). */
- subject_length = pchars(cb->subject, cb->subject_length, utf, NULL);
+ subject_length = pchars(clr_unexpected, cb->subject, cb->subject_length, utf, NULL);
- if (f != NULL) fprintf(f, "\n");
+ if (f != NULL) cprintf(clr_output, "\n");
/* For automatic callouts, show the pattern offset. Otherwise, for a
numerical callout whose number has not already been shown with captured
@@ -3427,37 +3430,37 @@ if (callout_where)
if (cb->callout_number == 255)
{
- fprintf(outfile, "%+3d ", (int)cb->pattern_position);
- if (cb->pattern_position > 99) fprintf(outfile, "\n ");
+ cprintf(clr_output, "%+3d ", (int)cb->pattern_position);
+ if (cb->pattern_position > 99) cprintf(clr_output, "\n ");
}
else
{
- if (callout_capture || cb->callout_string != NULL) fprintf(outfile, " ");
- else fprintf(outfile, "%3d ", cb->callout_number);
+ if (callout_capture || cb->callout_string != NULL) cprintf(clr_output, " ");
+ else cprintf(clr_output, "%3d ", cb->callout_number);
}
/* Now show position indicators */
- for (i = 0; i < pre_start; i++) fprintf(outfile, " ");
- fprintf(outfile, "^");
+ for (i = 0; i < pre_start; i++) cprintf(clr_output, " ");
+ cprintf(clr_output, "^");
if (post_start > 0)
{
- for (i = 0; i < post_start - 1; i++) fprintf(outfile, " ");
- fprintf(outfile, "^");
+ for (i = 0; i < post_start - 1; i++) cprintf(clr_output, " ");
+ cprintf(clr_output, "^");
}
for (i = 0; i < subject_length - pre_start - post_start + 4; i++)
- fprintf(outfile, " ");
+ cprintf(clr_output, " ");
if (cb->next_item_length != 0)
{
- pchars(pbuffer + cb->pattern_position, cb->next_item_length, utf, outfile);
+ pchars(clr_output, pbuffer + cb->pattern_position, cb->next_item_length, utf, outfile);
}
else
- fprintf(outfile, "End of pattern");
+ cprintf(clr_output, "End of pattern");
- fprintf(outfile, "\n");
+ cprintf(clr_output, "\n");
}
/* Show any mark info */
@@ -3465,12 +3468,14 @@ if (callout_where)
if (cb->mark != last_callout_mark)
{
if (cb->mark == NULL)
- fprintf(outfile, "Latest Mark: \n");
+ {
+ cprintf(clr_api_error, "Latest Mark: \n");
+ }
else
{
- fprintf(outfile, "Latest Mark: ");
- pchars(cb->mark - 1, -1, utf, outfile);
- putc('\n', outfile);
+ cprintf(clr_output, "Latest Mark: ");
+ pchars(clr_output, cb->mark - 1, -1, utf, outfile);
+ cprintf(clr_output, "\n");
}
}
@@ -3489,7 +3494,7 @@ if (callout_data_ptr != NULL)
int callout_data = *((int32_t *)callout_data_ptr);
if (callout_data != 0)
{
- if (outfile != NULL) fprintf(outfile, "Callout data = %d\n", callout_data);
+ if (outfile != NULL) cprintf(clr_output, "Callout data = %d\n", callout_data);
return callout_data;
}
}
@@ -3542,24 +3547,24 @@ for (i = 0; i < MAXCPYGET && dat_datctl.copy_numbers[i] >= 0; i++)
rc = pcre2_substring_copy_bynumber(match_data, n, copybuffer, &length);
if (rc < 0)
{
- fprintf(outfile, "Copy substring %d failed (%d): ", n, rc);
+ cprintf(clr_api_error, "Copy substring %d failed (%d): ", n, rc);
if (!print_error_message(rc, "", "\n")) return FALSE;
}
else
{
- fprintf(outfile, "%2dC ", n);
- pchars(copybuffer, length, utf, outfile);
- fprintf(outfile, " (%" SIZ_FORM ")\n", length);
+ cprintf(clr_output, "%2dC ", n);
+ pchars(clr_output, copybuffer, length, utf, outfile);
+ cprintf(clr_output, " (%" SIZ_FORM ")\n", length);
}
rc2 = pcre2_substring_length_bynumber(match_data, n, &length2);
if (rc2 < 0)
{
- fprintf(outfile, "Get substring %d length failed (%d): ", n, rc2);
+ cprintf(clr_api_error, "Get substring %d length failed (%d): ", n, rc2);
if (!print_error_message(rc2, "", "\n")) return FALSE;
}
else if (rc >= 0 && length2 != length)
{
- fprintf(outfile, "Mismatched substring lengths: %"
+ cprintf(clr_test_error, "Mismatched substring lengths: %"
SIZ_FORM " %" SIZ_FORM "\n", length, length2);
}
}
@@ -3594,32 +3599,32 @@ for (;;)
groupnumber = pcre2_substring_number_from_name(compiled_code, pbuffer);
if (groupnumber < 0 && groupnumber != PCRE2_ERROR_NOUNIQUESUBSTRING)
- fprintf(outfile, "Number not found for group \"%s\"\n", nptr);
+ cprintf(clr_api_error, "Number not found for group \"%s\"\n", nptr);
length = sizeof(copybuffer)/sizeof(*copybuffer);
rc = pcre2_substring_copy_byname(match_data, pbuffer, copybuffer, &length);
if (rc < 0)
{
- fprintf(outfile, "Copy substring \"%s\" failed (%d): ", nptr, rc);
+ cprintf(clr_api_error, "Copy substring \"%s\" failed (%d): ", nptr, rc);
if (!print_error_message(rc, "", "\n")) return FALSE;
}
else
{
- fprintf(outfile, " C ");
- pchars(copybuffer, length, utf, outfile);
- fprintf(outfile, " (%" SIZ_FORM ") %s", length, nptr);
- if (groupnumber >= 0) fprintf(outfile, " (group %d)\n", groupnumber);
- else fprintf(outfile, " (non-unique)\n");
+ cprintf(clr_output, " C ");
+ pchars(clr_output, copybuffer, length, utf, outfile);
+ cprintf(clr_output, " (%" SIZ_FORM ") %s", length, nptr);
+ if (groupnumber >= 0) cprintf(clr_output, " (group %d)\n", groupnumber);
+ else cprintf(clr_output, " (non-unique)\n");
}
rc2 = pcre2_substring_length_byname(match_data, pbuffer, &length2);
if (rc2 < 0)
{
- fprintf(outfile, "Get substring \"%s\" length failed (%d): ", nptr, rc2);
+ cprintf(clr_api_error, "Get substring \"%s\" length failed (%d): ", nptr, rc2);
if (!print_error_message(rc2, "", "\n")) return FALSE;
}
else if (rc >= 0 && length2 != length)
{
- fprintf(outfile, "Mismatched substring lengths: %"
+ cprintf(clr_test_error, "Mismatched substring lengths: %"
SIZ_FORM " %" SIZ_FORM "\n", length, length2);
}
nptr += namelen + 1;
@@ -3636,14 +3641,14 @@ for (i = 0; i < MAXCPYGET && dat_datctl.get_numbers[i] >= 0; i++)
rc = pcre2_substring_get_bynumber(match_data, n, &gotbuffer, &length);
if (rc < 0)
{
- fprintf(outfile, "Get substring %d failed (%d): ", n, rc);
+ cprintf(clr_api_error, "Get substring %d failed (%d): ", n, rc);
if (!print_error_message(rc, "", "\n")) return FALSE;
}
else
{
- fprintf(outfile, "%2dG ", n);
- pchars(gotbuffer, length, utf, outfile);
- fprintf(outfile, " (%" SIZ_FORM ")\n", length);
+ cprintf(clr_output, "%2dG ", n);
+ pchars(clr_output, gotbuffer, length, utf, outfile);
+ cprintf(clr_output, " (%" SIZ_FORM ")\n", length);
pcre2_substring_free(gotbuffer);
}
}
@@ -3678,21 +3683,21 @@ for (;;)
groupnumber = pcre2_substring_number_from_name(compiled_code, pbuffer);
if (groupnumber < 0 && groupnumber != PCRE2_ERROR_NOUNIQUESUBSTRING)
- fprintf(outfile, "Number not found for group \"%s\"\n", nptr);
+ cprintf(clr_api_error, "Number not found for group \"%s\"\n", nptr);
rc = pcre2_substring_get_byname(match_data, pbuffer, &gotbuffer, &length);
if (rc < 0)
{
- fprintf(outfile, "Get substring \"%s\" failed (%d): ", nptr, rc);
+ cprintf(clr_api_error, "Get substring \"%s\" failed (%d): ", nptr, rc);
if (!print_error_message(rc, "", "\n")) return FALSE;
}
else
{
- fprintf(outfile, " G ");
- pchars(gotbuffer, length, utf, outfile);
- fprintf(outfile, " (%" SIZ_FORM ") %s", length, nptr);
- if (groupnumber >= 0) fprintf(outfile, " (group %d)\n", groupnumber);
- else fprintf(outfile, " (non-unique)\n");
+ cprintf(clr_output, " G ");
+ pchars(clr_output, gotbuffer, length, utf, outfile);
+ cprintf(clr_output, " (%" SIZ_FORM ") %s", length, nptr);
+ if (groupnumber >= 0) cprintf(clr_output, " (group %d)\n", groupnumber);
+ else cprintf(clr_output, " (non-unique)\n");
pcre2_substring_free(gotbuffer);
}
nptr += namelen + 1;
@@ -3708,19 +3713,19 @@ if ((dat_datctl.control & CTL_GETALL) != 0)
rc = pcre2_substring_list_get(match_data, &stringlist, &lengths);
if (rc < 0)
{
- fprintf(outfile, "get substring list failed (%d): ", rc);
+ cprintf(clr_api_error, "get substring list failed (%d): ", rc);
if (!print_error_message(rc, "", "\n")) return FALSE;
}
else
{
for (i = 0; i < capcount; i++)
{
- fprintf(outfile, "%2dL ", i);
- pchars(stringlist[i], lengths[i], utf, outfile);
- putc('\n', outfile);
+ cprintf(clr_output, "%2dL ", i);
+ pchars(clr_output, stringlist[i], lengths[i], utf, outfile);
+ cprintf(clr_output, "\n");
}
if (stringlist[i] != NULL)
- fprintf(outfile, "string list not terminated by NULL\n");
+ cprintf(clr_test_error, "string list not terminated by NULL\n");
pcre2_substring_list_free(stringlist);
}
}
@@ -3889,7 +3894,7 @@ if (utf)
n = utf8_to_ord(ptmp, ptmp_end, &cc);
if (n <= 0)
{
- fprintf(outfile, "** Failed: invalid UTF-8 string cannot be used as input "
+ cprintf(clr_test_error, "** Failed: invalid UTF-8 string cannot be used as input "
"in UTF mode\n");
return PR_OK;
}
@@ -3918,7 +3923,7 @@ if (dbuffer == NULL || needlen >= dbuffer_size)
dbuffer = (uint8_t *)realloc(dbuffer, dbuffer_size);
if (dbuffer == NULL)
{
- fprintf(stderr, "pcre2test: realloc(%" SIZ_FORM ") failed\n", dbuffer_size);
+ fatal_printf("pcre2test: realloc(%" SIZ_FORM ") failed\n", dbuffer_size);
exit(1);
}
}
@@ -3944,14 +3949,14 @@ while ((c = *p++) != 0)
if (*p++ != '{')
{
- fprintf(outfile, "** Expected '{' after \\[....]\n");
+ cprintf(clr_test_error, "** Expected '{' after \\[....]\n");
return PR_OK;
}
li = strtol((const char *)p, &endptr, 10);
if (S32OVERFLOW(li))
{
- fprintf(outfile, "** Repeat count too large\n");
+ cprintf(clr_test_error, "** Repeat count too large\n");
return PR_OK;
}
i = (int)li;
@@ -3959,20 +3964,20 @@ while ((c = *p++) != 0)
p = (uint8_t *)endptr;
if (*p++ != '}')
{
- fprintf(outfile, "** Expected '}' after \\[...]{...\n");
+ cprintf(clr_test_error, "** Expected '}' after \\[...]{...\n");
return PR_OK;
}
if (i-- <= 0)
{
- fprintf(outfile, "** Zero or negative repeat not allowed\n");
+ cprintf(clr_test_error, "** Zero or negative repeat not allowed\n");
return PR_OK;
}
replen = (uint8_t *)q - (uint8_t *)start_rep;
if (i > 0 && replen > (SIZE_MAX - needlen) / i)
{
- fprintf(outfile, "** Expanded content too large\n");
+ cprintf(clr_test_error, "** Expanded content too large\n");
return PR_OK;
}
needlen += replen * i;
@@ -3989,7 +3994,7 @@ while ((c = *p++) != 0)
dbuffer = (uint8_t *)realloc(dbuffer, dbuffer_size);
if (dbuffer == NULL)
{
- fprintf(stderr, "pcre2test: realloc(%" SIZ_FORM ") failed\n",
+ fatal_printf("pcre2test: realloc(%" SIZ_FORM ") failed\n",
dbuffer_size);
exit(1);
}
@@ -4069,7 +4074,7 @@ while ((c = *p++) != 0)
{
if (c >= 0x20000000u)
{
- fprintf(outfile, "** \\o{ escape too large\n");
+ cprintf(clr_test_error, "** \\o{ escape too large\n");
return PR_OK;
}
else c = c * 8 + (*pt - '0');
@@ -4077,7 +4082,7 @@ while ((c = *p++) != 0)
c = CHAR_OUTPUT(CHAR_INPUT_HEX(c));
if (i == 0 || *pt != '}')
{
- fprintf(outfile, "** Malformed \\o{ escape\n");
+ cprintf(clr_test_error, "** Malformed \\o{ escape\n");
return PR_OK;
}
else p = pt + 1;
@@ -4099,7 +4104,7 @@ while ((c = *p++) != 0)
{
if (++i == 9)
{
- fprintf(outfile, "** Too many hex digits in \\x{...} item; "
+ cprintf(clr_test_error, "** Too many hex digits in \\x{...} item; "
"using only the first eight.\n");
while (isxdigit(*pt)) pt++;
break;
@@ -4109,7 +4114,7 @@ while ((c = *p++) != 0)
c = CHAR_OUTPUT(CHAR_INPUT_HEX(c));
if (i == 0 || *pt != '}')
{
- fprintf(outfile, "** Malformed \\x{ escape\n");
+ cprintf(clr_test_error, "** Malformed \\x{ escape\n");
return PR_OK;
}
else p = pt + 1;
@@ -4152,7 +4157,7 @@ while ((c = *p++) != 0)
}
}
#endif
- fprintf(outfile, "** Malformed \\N{U+ escape\n");
+ cprintf(clr_test_error, "** Malformed \\N{U+ escape\n");
return PR_OK;
case 0: /* \ followed by EOF allows for an empty line */
@@ -4165,7 +4170,7 @@ while ((c = *p++) != 0)
case '[': /* \[ introduces a replicated character sequence */
if (start_rep != NULL)
{
- fprintf(outfile, "** Nested replication is not supported\n");
+ cprintf(clr_test_error, "** Nested replication is not supported\n");
return PR_OK;
}
start_rep = q;
@@ -4174,7 +4179,7 @@ while ((c = *p++) != 0)
default:
if (isalnum(c))
{
- fprintf(outfile, "** Unrecognized escape sequence \"\\%c\"\n", c);
+ cprintf(clr_test_error, "** Unrecognized escape sequence \"\\%c\"\n", c);
return PR_OK;
}
}
@@ -4188,9 +4193,9 @@ while ((c = *p++) != 0)
{
if (c > 0xffu)
{
- fprintf(outfile, "** Character \\x{%x} is greater than 255 "
+ cprintf(clr_test_error, "** Character \\x{%x} is greater than 255 "
"and UTF-8 mode is not enabled.\n", c);
- fprintf(outfile, "** Truncation will probably give the wrong "
+ cprintf(clr_test_error, "** Truncation will probably give the wrong "
"result.\n");
}
*q++ = (uint8_t)c;
@@ -4199,12 +4204,12 @@ while ((c = *p++) != 0)
{
if (c > 0x7fffffff)
{
- fprintf(outfile, "** Character \\N{U+%x} is greater than 0x7fffffff "
+ cprintf(clr_test_error, "** Character \\N{U+%x} is greater than 0x7fffffff "
"and therefore cannot be encoded as UTF-8\n", c);
return PR_OK;
}
else if (encoding == FORCE_UTF && c > MAX_UTF_CODE_POINT)
- fprintf(outfile, "** Warning: character \\N{U+%x} is greater than "
+ cprintf(clr_test_error, "** Warning: character \\N{U+%x} is greater than "
"0x%x and should not be encoded as UTF-8\n",
c, MAX_UTF_CODE_POINT);
q += ord_to_utf8(c, q);
@@ -4218,9 +4223,9 @@ while ((c = *p++) != 0)
{
if (c > 0xffffu)
{
- fprintf(outfile, "** Character \\x{%x} is greater than 0xffff "
+ cprintf(clr_test_error, "** Character \\x{%x} is greater than 0xffff "
"and UTF-16 mode is not enabled.\n", c);
- fprintf(outfile, "** Truncation will probably give the wrong "
+ cprintf(clr_test_error, "** Truncation will probably give the wrong "
"result.\n");
}
*q++ = (uint16_t)c;
@@ -4229,7 +4234,7 @@ while ((c = *p++) != 0)
{
if (c > MAX_UTF_CODE_POINT)
{
- fprintf(outfile, "** Failed: character \\N{U+%x} is greater than "
+ cprintf(clr_test_error, "** Failed: character \\N{U+%x} is greater than "
"0x%x and therefore cannot be encoded as UTF-16\n",
c, MAX_UTF_CODE_POINT);
return PR_OK;
@@ -4243,7 +4248,7 @@ while ((c = *p++) != 0)
else
{
if (encoding == FORCE_UTF && 0xe000u > c && c >= 0xd800u)
- fprintf(outfile, "** Warning: character \\N{U+%x} is a surrogate "
+ cprintf(clr_test_error, "** Warning: character \\N{U+%x} is a surrogate "
"and should not be encoded as UTF-16\n", c);
*q++ = c;
}
@@ -4251,7 +4256,7 @@ while ((c = *p++) != 0)
#endif
#if PCRE2_CODE_UNIT_WIDTH == 32
if (encoding == FORCE_UTF && c > MAX_UTF_CODE_POINT)
- fprintf(outfile, "** Warning: character \\N{U+%x} is greater than "
+ cprintf(clr_test_error, "** Warning: character \\N{U+%x} is greater than "
"0x%x and should not be encoded as UTF-32\n",
c, MAX_UTF_CODE_POINT);
*q++ = c;
@@ -4282,8 +4287,8 @@ for (k = 0; k < sizeof(exclusive_dat_controls)/sizeof(uint32_t); k++)
c = dat_datctl.control & exclusive_dat_controls[k];
if (c != 0 && c != (c & (~c+1)))
{
- show_controls(c, 0, "** Not allowed together:");
- fprintf(outfile, "\n");
+ show_controls(clr_test_error, c, 0, "** Not allowed together:");
+ cprintf(clr_test_error, "\n");
return PR_OK;
}
}
@@ -4293,24 +4298,24 @@ if (dat_datctl.replacement[0] != 0)
if ((dat_datctl.control2 & CTL2_SUBSTITUTE_CALLOUT) != 0 &&
(dat_datctl.control & CTL_NULLCONTEXT) != 0)
{
- fprintf(outfile, "** Replacement callouts are not supported with null_context.\n");
+ cprintf(clr_test_error, "** Replacement callouts are not supported with null_context.\n");
return PR_OK;
}
if ((dat_datctl.control2 & CTL2_SUBSTITUTE_CASE_CALLOUT) != 0 &&
(dat_datctl.control & CTL_NULLCONTEXT) != 0)
{
- fprintf(outfile, "** Replacement case callouts are not supported with null_context.\n");
+ cprintf(clr_test_error, "** Replacement case callouts are not supported with null_context.\n");
return PR_OK;
}
if ((dat_datctl.control & CTL_ALLCAPTURES) != 0)
- fprintf(outfile, "** Ignored with replacement text: allcaptures\n");
+ cprintf(clr_test_error, "** Ignored with replacement text: allcaptures\n");
if (dat_datctl.substitute_subject[0] != 0 &&
(dat_datctl.control2 & CTL2_SUBSTITUTE_MATCHED) == 0)
{
- fprintf(outfile, "** substitute_subject requires substitute_matched.\n");
+ cprintf(clr_test_error, "** substitute_subject requires substitute_matched.\n");
return PR_OK;
}
}
@@ -4319,7 +4324,7 @@ else
{
if (dat_datctl.substitute_subject[0] != 0)
{
- fprintf(outfile, "** substitute_subject requires replacement text.\n");
+ cprintf(clr_test_error, "** substitute_subject requires replacement text.\n");
return PR_OK;
}
}
@@ -4329,9 +4334,9 @@ else
if ((dat_datctl.control & CTL_DFA) != 0)
{
if ((dat_datctl.control & CTL_ALLCAPTURES) != 0)
- fprintf(outfile, "** Ignored for DFA matching: allcaptures\n");
+ cprintf(clr_test_error, "** Ignored for DFA matching: allcaptures\n");
if ((dat_datctl.control2 & CTL2_HEAPFRAMES_SIZE) != 0)
- fprintf(outfile, "** Ignored for DFA matching: heapframes_size\n");
+ cprintf(clr_test_error, "** Ignored for DFA matching: heapframes_size\n");
}
/* We now have the subject in dbuffer, with len containing the byte length, and
@@ -4387,27 +4392,27 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
if ((dat_datctl.options & ~POSIX_SUPPORTED_MATCH_OPTIONS) != 0)
{
- fprintf(outfile, "%s", msg);
- show_match_options(dat_datctl.options & ~POSIX_SUPPORTED_MATCH_OPTIONS);
+ cprintf(clr_test_error, "%s", msg);
+ show_match_options(clr_test_error, dat_datctl.options & ~POSIX_SUPPORTED_MATCH_OPTIONS);
msg = "";
}
if ((dat_datctl.control & ~POSIX_SUPPORTED_MATCH_CONTROLS) != 0 ||
(dat_datctl.control2 & ~POSIX_SUPPORTED_MATCH_CONTROLS2) != 0)
{
- show_controls(dat_datctl.control & ~POSIX_SUPPORTED_MATCH_CONTROLS,
+ show_controls(clr_test_error, dat_datctl.control & ~POSIX_SUPPORTED_MATCH_CONTROLS,
dat_datctl.control2 & ~POSIX_SUPPORTED_MATCH_CONTROLS2, msg);
msg = "";
}
- if (msg[0] == 0) fprintf(outfile, "\n");
+ if (msg[0] == 0) cprintf(clr_test_error, "\n");
if (dat_datctl.oveccount > 0)
{
pmatch = (regmatch_t *)malloc(sizeof(regmatch_t) * dat_datctl.oveccount);
if (pmatch == NULL)
{
- fprintf(outfile, "** Failed to get memory for recording matching "
+ cprintf(clr_test_error, "** Failed to get memory for recording matching "
"information (size set = %du)\n", dat_datctl.oveccount);
return PR_ABEND;
}
@@ -4430,14 +4435,14 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
if (rc != 0)
{
size_t usize = regerror(rc, &preg, (char *)pbuffer8, pbuffer8_size);
- fprintf(outfile, "No match: POSIX code %d: ", rc);
- pchars((PCRE2_SPTR8)pbuffer8, usize - 1, utf, outfile);
- fputs("\n", outfile);
+ cprintf(clr_api_error, "No match: POSIX code %d: ", rc);
+ pchars(clr_api_error, (PCRE2_SPTR8)pbuffer8, usize - 1, utf, outfile);
+ cprintf(clr_api_error, "\n");
}
else if ((pat_patctl.control & CTL_POSIX_NOSUB) != 0)
- fprintf(outfile, "Matched with REG_NOSUB\n");
+ cprintf(clr_output, "Matched with REG_NOSUB\n");
else if (dat_datctl.oveccount == 0)
- fprintf(outfile, "Matched without capture\n");
+ cprintf(clr_output, "Matched without capture\n");
else
{
size_t i, j;
@@ -4449,27 +4454,27 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
PCRE2_SIZE start = pmatch[i].rm_so;
PCRE2_SIZE end = pmatch[i].rm_eo;
for (j = last_printed + 1; j < i; j++)
- fprintf(outfile, "%2d: \n", (int)j);
+ cprintf(clr_api_error, "%2d: \n", (int)j);
last_printed = i;
if (start > end)
{
start = pmatch[i].rm_eo;
end = pmatch[i].rm_so;
- fprintf(outfile, "Start of matched string is beyond its end - "
+ cprintf(clr_api_error, "Start of matched string is beyond its end - "
"displaying from end to start.\n");
}
- fprintf(outfile, "%2d: ", (int)i);
- pchars(pp + start, end - start, utf, outfile);
- fprintf(outfile, "\n");
+ cprintf(clr_output, "%2d: ", (int)i);
+ pchars(clr_output, pp + start, end - start, utf, outfile);
+ cprintf(clr_output, "\n");
if ((i == 0 && (dat_datctl.control & CTL_AFTERTEXT) != 0) ||
(dat_datctl.control & CTL_ALLAFTERTEXT) != 0)
{
- fprintf(outfile, "%2d+ ", (int)i);
+ cprintf(clr_output, "%2d+ ", (int)i);
/* Note: don't use the start/end variables here because we want to
show the text from what is reported as the end. */
- pchars(pp + pmatch[i].rm_eo, len - pmatch[i].rm_eo, utf, outfile);
- fprintf(outfile, "\n");
+ pchars(clr_output, pp + pmatch[i].rm_eo, len - pmatch[i].rm_eo, utf, outfile);
+ cprintf(clr_output, "\n");
}
}
}
@@ -4483,7 +4488,7 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
modifiers. */
if (dat_datctl.startend[0] != CFORE_UNSET)
- fprintf(outfile, "** \\=posix_startend ignored for non-POSIX matching\n");
+ cprintf(clr_test_error, "** \\=posix_startend ignored for non-POSIX matching\n");
/* ALLUSEDTEXT is not supported with JIT, but JIT is not used with DFA
matching, even if the JIT compiler was used. */
@@ -4491,7 +4496,7 @@ matching, even if the JIT compiler was used. */
if ((dat_datctl.control & (CTL_ALLUSEDTEXT|CTL_DFA)) == CTL_ALLUSEDTEXT &&
compiled_code->executable_jit != NULL)
{
- fprintf(outfile, "** Showing all consulted text is not supported by JIT: ignored\n");
+ cprintf(clr_test_error, "** Showing all consulted text is not supported by JIT: ignored\n");
dat_datctl.control &= ~CTL_ALLUSEDTEXT;
}
@@ -4513,7 +4518,7 @@ show_memory = (dat_datctl.control & CTL_MEMORY) != 0;
if (show_memory &&
(pat_patctl.control & dat_datctl.control & CTL_NULLCONTEXT) != 0)
- fprintf(outfile, "** \\=memory requires either a pattern or a subject "
+ cprintf(clr_test_error, "** \\=memory requires either a pattern or a subject "
"context: ignored\n");
/* Create and assign a JIT stack if requested. */
@@ -4583,7 +4588,7 @@ else
if (match_data == NULL)
{
- fprintf(outfile, "** Failed to get memory for recording matching "
+ cprintf(clr_test_error, "** Failed to get memory for recording matching "
"information (size requested: %d)\n", dat_datctl.oveccount);
max_oveccount = 0;
return PR_ABEND;
@@ -4612,7 +4617,7 @@ if (dat_datctl.replacement[0] != 0 &&
(dat_datctl.control & CTL_DFA) != 0 &&
(dat_datctl.control2 & CTL2_SUBSTITUTE_MATCHED) == 0)
{
- fprintf(outfile, "** Ignored for DFA matching: replace\n");
+ cprintf(clr_test_error, "** Ignored for DFA matching: replace\n");
dat_datctl.replacement[0] = 0;
}
@@ -4641,10 +4646,10 @@ if (dat_datctl.replacement[0] != 0)
for (j = 0; j < 2*oveccount; j++) ovector[j] = JUNK_OFFSET;
if (timeitm)
- fprintf(outfile, "** Timing is not supported with replace: ignored\n");
+ cprintf(clr_test_error, "** Timing is not supported with replace: ignored\n");
if ((dat_datctl.control & CTL_ALTGLOBAL) != 0)
- fprintf(outfile, "** Altglobal is not supported with replace: ignored\n");
+ cprintf(clr_test_error, "** Altglobal is not supported with replace: ignored\n");
/* Check for a test that does substitution after an initial external match.
If this is set, we run the external match, but leave the interpretation of
@@ -4705,12 +4710,12 @@ if (dat_datctl.replacement[0] != 0)
while ((c = *(++pr)) >= '0' && c <= '9') n = n * 10 + (c - '0');
if (*pr++ != ']')
{
- fprintf(outfile, "** Bad buffer size in replacement string\n");
+ cprintf(clr_test_error, "** Bad buffer size in replacement string\n");
return PR_OK;
}
if (n > nsize)
{
- fprintf(outfile, "** Replacement buffer setting (%" SIZ_FORM ") is too "
+ cprintf(clr_test_error, "** Replacement buffer setting (%" SIZ_FORM ") is too "
"large (max %" SIZ_FORM ")\n", n, nsize);
return PR_OK;
}
@@ -4743,7 +4748,7 @@ if (dat_datctl.replacement[0] != 0)
the subject. */
if (slen > ulen)
{
- fprintf(outfile, "** substitute_subject is longer than match subject buffer\n");
+ cprintf(clr_test_error, "** substitute_subject is longer than match subject buffer\n");
return PR_OK;
}
@@ -4815,7 +4820,7 @@ if (dat_datctl.replacement[0] != 0)
if (i < target_mallocs && rc != PCRE2_ERROR_NOMEMORY)
{
- fprintf(outfile, "** malloc() Substitution test did not fail as expected (%d)\n",
+ cprintf(clr_test_error, "** malloc() Substitution test did not fail as expected (%d)\n",
rc);
return PR_ABEND;
}
@@ -4824,14 +4829,14 @@ if (dat_datctl.replacement[0] != 0)
if (rc < 0)
{
- fprintf(outfile, "Failed: error %d", rc);
+ cprintf(clr_api_error, "Failed: error %d", rc);
if (rc != PCRE2_ERROR_NOMEMORY && nsize != PCRE2_UNSET)
- fprintf(outfile, " at offset %ld in replacement", (long int)nsize);
- fprintf(outfile, ": ");
+ cprintf(clr_api_error, " at offset %ld in replacement", (long int)nsize);
+ cprintf(clr_api_error, ": ");
if (!print_error_message(rc, "", "")) return PR_ABEND;
if (rc == PCRE2_ERROR_NOMEMORY &&
(xoptions & PCRE2_SUBSTITUTE_OVERFLOW_LENGTH) != 0)
- fprintf(outfile, ": %ld code units are needed", (long int)nsize);
+ cprintf(clr_api_error, ": %ld code units are needed", (long int)nsize);
if (rc != PCRE2_ERROR_NOMEMORY && nsize != PCRE2_UNSET)
{
@@ -4841,27 +4846,27 @@ if (dat_datctl.replacement[0] != 0)
PCRE2_SIZE full_rlen = (rlen != PCRE2_ZERO_TERMINATED)? rlen :
pcre2_strlen(rbptr);
- fprintf(outfile, "\n here: ");
+ cprintf(clr_api_error, "\n here: ");
if (nsize > 0)
{
- ptrunc(rbptr, full_rlen, nsize, TRUE, utf, outfile);
- fprintf(outfile, " ");
+ ptrunc(clr_api_error, rbptr, full_rlen, nsize, TRUE, utf, outfile);
+ cprintf(clr_api_error, " ");
}
- fprintf(outfile, "|<--|");
+ cprintf(clr_api_error, "|<--|");
if (nsize < full_rlen)
{
- fprintf(outfile, " ");
- ptrunc(rbptr, full_rlen, nsize, FALSE, utf, outfile);
+ cprintf(clr_api_error, " ");
+ ptrunc(clr_api_error, rbptr, full_rlen, nsize, FALSE, utf, outfile);
}
}
}
else
{
- fprintf(outfile, "%2d: ", rc);
- pchars(nbuffer, nsize, utf, outfile);
+ cprintf(clr_api_error, "%2d: ", rc);
+ pchars(clr_api_error, nbuffer, nsize, utf, outfile);
}
- fprintf(outfile, "\n");
+ cprintf(clr_output, "\n");
show_memory = FALSE;
/* Show final ovector contents and resulting heapframe size if requested. */
@@ -4909,7 +4914,7 @@ for (gmatched = 0;; gmatched++)
if ((dat_datctl.options & PCRE2_DFA_RESTART) != 0)
{
outfile = saved_outfile;
- fprintf(outfile, "** Timing DFA restarts is not supported\n");
+ cprintf(clr_test_error, "** Timing DFA restarts is not supported\n");
return PR_ABEND;
}
if (dfa_workspace == NULL)
@@ -4947,7 +4952,7 @@ for (gmatched = 0;; gmatched++)
total_match_time += (time_taken = clock() - start_time);
outfile = saved_outfile;
- fprintf(outfile, "Match time %7.4f microseconds\n",
+ cprintf(clr_profiling, "Match time %7.4f microseconds\n",
((1000000 / CLOCKS_PER_SEC) * (double)time_taken) / timeitm);
}
@@ -4977,7 +4982,7 @@ for (gmatched = 0;; gmatched++)
if (capcount == 0)
{
- fprintf(outfile, "Matched, but offsets vector is too small to show all matches\n");
+ cprintf(clr_test_error, "Matched, but offsets vector is too small to show all matches\n");
capcount = dat_datctl.oveccount;
}
}
@@ -5001,7 +5006,7 @@ for (gmatched = 0;; gmatched++)
use_dat_context, dfa_workspace, DFA_WS_DIMENSION);
if (capcount == 0)
{
- fprintf(outfile, "Matched, but offsets vector is too small to show all matches\n");
+ cprintf(clr_test_error, "Matched, but offsets vector is too small to show all matches\n");
capcount = dat_datctl.oveccount;
}
}
@@ -5015,7 +5020,7 @@ for (gmatched = 0;; gmatched++)
dat_datctl.options | g_notempty, match_data, use_dat_context);
if (capcount == 0)
{
- fprintf(outfile, "Matched, but too many substrings\n");
+ cprintf(clr_test_error, "Matched, but too many substrings\n");
capcount = dat_datctl.oveccount;
}
}
@@ -5060,7 +5065,7 @@ for (gmatched = 0;; gmatched++)
if (i < target_mallocs && capcount != PCRE2_ERROR_NOMEMORY)
{
- fprintf(outfile, "** malloc() match test did not fail as expected (%d)\n",
+ cprintf(clr_test_error, "** malloc() match test did not fail as expected (%d)\n",
capcount);
return PR_ABEND;
}
@@ -5078,7 +5083,7 @@ for (gmatched = 0;; gmatched++)
rc_nextmatch = pcre2_next_match(match_data, &tmp_offset, &tmp_options);
if (rc_nextmatch || tmp_offset != 0xcd || tmp_options != 0xcd)
{
- fprintf(outfile, "** unexpected pcre2_next_match() for rc < 0\n");
+ cprintf(clr_test_error, "** unexpected pcre2_next_match() for rc < 0\n");
return PR_ABEND;
}
}
@@ -5103,7 +5108,7 @@ for (gmatched = 0;; gmatched++)
if ((unsigned)capcount > oveccount) /* Check for lunatic return value */
{
- fprintf(outfile,
+ cprintf(clr_test_error,
"** PCRE2 error: returned count %d is too big for ovector count %d\n",
capcount, oveccount);
return PR_ABEND;
@@ -5116,15 +5121,15 @@ for (gmatched = 0;; gmatched++)
(pat_patctl.control & CTL_JITFAST) == 0)
{
if ((match_data->flags & PCRE2_MD_COPIED_SUBJECT) == 0)
- fprintf(outfile,
+ cprintf(clr_test_error,
"** PCRE2 error: flag not set after copy_matched_subject\n");
if (match_data->subject == pp)
- fprintf(outfile,
+ cprintf(clr_test_error,
"** PCRE2 error: copy_matched_subject has not copied\n");
if (memcmp(match_data->subject, pp, ulen) != 0)
- fprintf(outfile,
+ cprintf(clr_test_error,
"** PCRE2 error: copy_matched_subject mismatch\n");
}
@@ -5148,7 +5153,7 @@ for (gmatched = 0;; gmatched++)
!(dat_datctl.offset <= ovector[0] && ovector[0] <= ovector[1]) &&
pp + ovector[0] == ovecsave[0] && pp + ovector[1] == ovecsave[1])
{
- fprintf(outfile, "global repeat returned the same match as previous\n");
+ cprintf(clr_test_error, "global repeat returned the same match as previous\n");
goto NEXT_MATCH;
}
@@ -5166,7 +5171,7 @@ for (gmatched = 0;; gmatched++)
(ovector[1] == ovector[0] && ovecsave[1] != ovecsave[0] &&
pp + ovector[1] == ovecsave[1])))
{
- fprintf(outfile,
+ cprintf(clr_test_error,
"** PCRE2 error: global repeat did not make progress\n");
return PR_ABEND;
}
@@ -5202,17 +5207,17 @@ for (gmatched = 0;; gmatched++)
{
start = ovector[i+1];
end = ovector[i];
- fprintf(outfile, "Start of matched string is beyond its end - "
+ cprintf(clr_api_error, "Start of matched string is beyond its end - "
"displaying from end to start.\n");
}
- fprintf(outfile, "%2d: ", i/2);
+ cprintf(clr_output, "%2d: ", i/2);
/* Check for an unset group */
if (start == PCRE2_UNSET && end == PCRE2_UNSET)
{
- fprintf(outfile, "\n");
+ cprintf(clr_api_error, "\n");
continue;
}
@@ -5226,9 +5231,9 @@ for (gmatched = 0;; gmatched++)
if (((dat_datctl.control & CTL_DFA) != 0 ||
i >= (int)(2*maxcapcount + 2)) &&
start == JUNK_OFFSET && end == JUNK_OFFSET)
- fprintf(outfile, "\n");
+ cprintf(clr_output, "\n");
else
- fprintf(outfile, "ERROR: bad value(s) for offset(s): 0x%lx 0x%lx\n",
+ cprintf(clr_test_error, "ERROR: bad value(s) for offset(s): 0x%lx 0x%lx\n",
(unsigned long int)start, (unsigned long int)end);
continue;
}
@@ -5256,15 +5261,15 @@ for (gmatched = 0;; gmatched++)
if (showallused)
{
- lleft = pchars(pp + leftchar, start - leftchar, utf, outfile);
- lmiddle = pchars(pp + start, end - start, utf, outfile);
- lright = pchars(pp + end, rightchar - end, utf, outfile);
+ lleft = pchars(clr_output, pp + leftchar, start - leftchar, utf, outfile);
+ lmiddle = pchars(clr_output, pp + start, end - start, utf, outfile);
+ lright = pchars(clr_output, pp + end, rightchar - end, utf, outfile);
if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used)
- fprintf(outfile, " (JIT)");
- fprintf(outfile, "\n ");
- for (j = 0; j < lleft; j++) fprintf(outfile, "<");
- for (j = 0; j < lmiddle; j++) fprintf(outfile, " ");
- for (j = 0; j < lright; j++) fprintf(outfile, ">");
+ cprintf(clr_output, " (JIT)");
+ cprintf(clr_output, "\n ");
+ for (j = 0; j < lleft; j++) cprintf(clr_output, "<");
+ for (j = 0; j < lmiddle; j++) cprintf(clr_output, " ");
+ for (j = 0; j < lright; j++) cprintf(clr_output, ">");
}
/* When a pattern contains \K, the start of match position may be
@@ -5275,14 +5280,14 @@ for (gmatched = 0;; gmatched++)
{
PCRE2_SIZE startchar;
startchar = pcre2_get_startchar(match_data);
- lleft = pchars(pp + startchar, start - startchar, utf, outfile);
- pchars(pp+start, end - start, utf, outfile);
+ lleft = pchars(clr_output, pp + startchar, start - startchar, utf, outfile);
+ pchars(clr_output, pp+start, end - start, utf, outfile);
if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used)
- fprintf(outfile, " (JIT)");
+ cprintf(clr_output, " (JIT)");
if (startchar != start)
{
- fprintf(outfile, "\n ");
- for (j = 0; j < lleft; j++) fprintf(outfile, "^");
+ cprintf(clr_output, "\n ");
+ for (j = 0; j < lleft; j++) cprintf(clr_output, "^");
}
}
@@ -5290,9 +5295,9 @@ for (gmatched = 0;; gmatched++)
else
{
- pchars(pp + start, end - start, utf, outfile);
+ pchars(clr_output, pp + start, end - start, utf, outfile);
if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used)
- fprintf(outfile, " (JIT)");
+ cprintf(clr_output, " (JIT)");
}
}
@@ -5300,10 +5305,10 @@ for (gmatched = 0;; gmatched++)
else
{
- pchars(pp + start, end - start, utf, outfile);
+ pchars(clr_output, pp + start, end - start, utf, outfile);
}
- fprintf(outfile, "\n");
+ cprintf(clr_output, "\n");
/* Note: don't use the start/end variables here because we want to
show the text from what is reported as the end. */
@@ -5311,9 +5316,9 @@ for (gmatched = 0;; gmatched++)
if ((dat_datctl.control & CTL_ALLAFTERTEXT) != 0 ||
(i == 0 && (dat_datctl.control & CTL_AFTERTEXT) != 0))
{
- fprintf(outfile, "%2d+ ", i/2);
- pchars(pp + ovector[i+1], ulen - ovector[i+1], utf, outfile);
- fprintf(outfile, "\n");
+ cprintf(clr_output, "%2d+ ", i/2);
+ pchars(clr_output, pp + ovector[i+1], ulen - ovector[i+1], utf, outfile);
+ cprintf(clr_output, "\n");
}
}
@@ -5322,9 +5327,9 @@ for (gmatched = 0;; gmatched++)
if ((dat_datctl.control & CTL_MARK) != 0 &&
match_data->mark != NULL)
{
- fprintf(outfile, "MK: ");
- pchars(match_data->mark - 1, -1, utf, outfile);
- fprintf(outfile, "\n");
+ cprintf(clr_output, "MK: ");
+ pchars(clr_output, match_data->mark - 1, -1, utf, outfile);
+ cprintf(clr_output, "\n");
}
/* Process copy/get strings */
@@ -5350,33 +5355,33 @@ for (gmatched = 0;; gmatched++)
}
else leftchar = ovector[0];
- fprintf(outfile, "Partial match");
+ cprintf(clr_api_error, "Partial match");
if ((dat_datctl.control & CTL_MARK) != 0 &&
match_data->mark != NULL)
{
- fprintf(outfile, ", mark=");
- rubriclength = pchars(match_data->mark - 1, -1, utf, outfile);
+ cprintf(clr_api_error, ", mark=");
+ rubriclength = pchars(clr_api_error, match_data->mark - 1, -1, utf, outfile);
rubriclength += 7;
}
- fprintf(outfile, ": ");
+ cprintf(clr_api_error, ": ");
rubriclength += 15;
- backlength = pchars(pp + leftchar, ovector[0] - leftchar, utf, outfile);
- pchars(pp + ovector[0], ovector[1] - ovector[0], utf, outfile);
+ backlength = pchars(clr_api_error, pp + leftchar, ovector[0] - leftchar, utf, outfile);
+ pchars(clr_api_error, pp + ovector[0], ovector[1] - ovector[0], utf, outfile);
if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used)
- fprintf(outfile, " (JIT)");
- fprintf(outfile, "\n");
+ cprintf(clr_api_error, " (JIT)");
+ cprintf(clr_api_error, "\n");
if (backlength != 0)
{
- for (int i = 0; i < rubriclength; i++) fprintf(outfile, " ");
- for (int i = 0; i < backlength; i++) fprintf(outfile, "<");
- fprintf(outfile, "\n");
+ for (int i = 0; i < rubriclength; i++) cprintf(clr_api_error, " ");
+ for (int i = 0; i < backlength; i++) cprintf(clr_api_error, "<");
+ cprintf(clr_api_error, "\n");
}
if (ulen != ovector[1])
- fprintf(outfile, "** ovector[1] is not equal to the subject length: "
+ cprintf(clr_test_error, "** ovector[1] is not equal to the subject length: "
"%ld != %ld\n", (unsigned long int)ovector[1], (unsigned long int)ulen);
/* Process copy/get strings */
@@ -5401,16 +5406,16 @@ for (gmatched = 0;; gmatched++)
case PCRE2_ERROR_NOMATCH:
if (gmatched == 0)
{
- fprintf(outfile, "No match");
+ cprintf(clr_api_error, "No match");
if ((dat_datctl.control & CTL_MARK) != 0 &&
match_data->mark != NULL)
{
- fprintf(outfile, ", mark = ");
- pchars(match_data->mark - 1, -1, utf, outfile);
+ cprintf(clr_api_error, ", mark = ");
+ pchars(clr_api_error, match_data->mark - 1, -1, utf, outfile);
}
if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used)
- fprintf(outfile, " (JIT)");
- fprintf(outfile, "\n");
+ cprintf(clr_api_error, " (JIT)");
+ cprintf(clr_api_error, "\n");
/* "allvector" outputs the entire vector */
@@ -5420,21 +5425,21 @@ for (gmatched = 0;; gmatched++)
break;
case PCRE2_ERROR_BADUTFOFFSET:
- fprintf(outfile, "Error %d (bad UTF-" STR(PCRE2_CODE_UNIT_WIDTH)
+ cprintf(clr_api_error, "Error %d (bad UTF-" STR(PCRE2_CODE_UNIT_WIDTH)
" offset)\n", capcount);
break;
default:
- fprintf(outfile, "Failed: error %d: ", capcount);
+ cprintf(clr_api_error, "Failed: error %d: ", capcount);
if (!print_error_message(capcount, "", "")) return PR_ABEND;
if (capcount <= PCRE2_ERROR_UTF8_ERR1 &&
capcount >= PCRE2_ERROR_UTF32_ERR2)
{
PCRE2_SIZE startchar;
startchar = pcre2_get_startchar(match_data);
- fprintf(outfile, " at offset %" SIZ_FORM, startchar);
+ cprintf(clr_api_error, " at offset %" SIZ_FORM, startchar);
}
- fprintf(outfile, "\n");
+ cprintf(clr_api_error, "\n");
break;
}
@@ -6238,7 +6243,7 @@ free(invalid_code);
if (failure != NULL)
{
- fprintf(stderr, "pcre2test: Unit test error in %s\n", failure);
+ fatal_printf("pcre2test: Unit test error in %s\n", failure);
exit(1);
}
}
From e82dc2f753e8d08a9390f2a2048f8af2f56294dc Mon Sep 17 00:00:00 2001
From: Nicholas Wilson
Date: Fri, 10 Oct 2025 12:01:29 +0000
Subject: [PATCH 3/6] Add --colour=auto, and make some small adjustments
---
src/pcre2test.c | 384 ++++++++++-----------
src/pcre2test_inc.h | 804 ++++++++++++++++++++++----------------------
2 files changed, 590 insertions(+), 598 deletions(-)
diff --git a/src/pcre2test.c b/src/pcre2test.c
index e2aa89031..0af451152 100644
--- a/src/pcre2test.c
+++ b/src/pcre2test.c
@@ -65,6 +65,7 @@ it references only the enabled library functions. */
#include
#include
#include
+#include
#include
#include
#include
@@ -1102,73 +1103,68 @@ static uint8_t *dbuffer = NULL;
/* ------------------ Colour highlighting definitions -------------------- */
-/* Input text that was a comment, when echoing back to the terminal */
-static int const clr_comment = 37; /* grey */
-/* Other input text that is echoed back to the terminal */
-static int const clr_input = 32; /* green */
-/* Colour of output that represents a pcre2api error */
-static int const clr_api_error = 35; /* magenta */
+/* Colour of input text that was a comment, when echoing back to the terminal */
+static const int clr_comment = 37; /* grey */
+/* Colour of other input text that is echoed back to the terminal */
+static const int clr_input = 32; /* green */
+/* Colour of prompt output */
+static const int clr_prompt = 34; /* blue */
+/* Colour of output that represents a PCRE2 API error */
+static const int clr_api_error = 35; /* magenta */
/* Colour of error messages for the test script itself
-(i.e. pcr2test error, not a pcre2api error) */
-static int const clr_test_error = 31; /* red */
-/* Colour for profiling information, which doesn't have a "right" answer */
-static int const clr_profiling = 34; /* blue */
-/* Colour of normal output */
-static int const clr_output = 39; /* default foreground colour */
-/* Colour for anything not printed with an explicit colour
-(such as a valgrind errors) */
-static int const clr_unexpected = 33; /* yellow */
-
-static BOOL colour_on;
-
-/* start a block of colour (but only if colour_on) */
+(i.e. an error in the testing tool, not an API error) */
+static const int clr_test_error = 31; /* red */
+/* Colour of profiling information, which doesn't have a "right" answer */
+static const int clr_profiling = 36; /* cyan */
+/* No colour, for APIs that take a colour value */
+static const int clr_none = -1;
+
+enum { COLOUR_NEVER, COLOUR_ALWAYS, COLOUR_AUTO };
+static int colour_setting = COLOUR_AUTO;
+static int colour_last_fd = -1;
+static BOOL colour_fd_interactive = FALSE;
+
+/* Starts a block of colour (but only if colour is enabled). */
static void
colour_begin(int clr, FILE* f)
{
-if(f != NULL && colour_on) fprintf(f, "\x1b[%dm", clr);
+if (f == NULL) return;
+if (clr == clr_none) return;
+if (colour_setting == COLOUR_NEVER) return;
+if (colour_setting == COLOUR_AUTO)
+ {
+ if (fileno(f) != colour_last_fd)
+ {
+ colour_last_fd = fileno(f);
+ colour_fd_interactive = INTERACTIVE(f);
+ }
+ if (!colour_fd_interactive) return;
+ }
+fprintf(f, "\x1b[%dm", clr);
}
-/* end a block of colour (but only if colour_on) */
+/* Ends a block of colour (but only if colour is enabled). */
static void
colour_end(FILE* f)
{
-colour_begin(clr_unexpected, f);
+colour_begin(0, f);
}
-/* wraps a string ltieral in blue */
-#define PROMPT(literal) (colour_on ? "\x1b[34m" literal "\x1b[m" : literal)
-
-#include
-
-/* this is the body of a variadic function that does a fprintf to the given file
-wrapped in the given colour, rerturning the result of the inner fprintf. */
-#define COLOUR_PRINTF_BODY(colour, file, fmt) \
- { \
- va_list args; \
- int ret; \
- colour_begin(colour, file); \
- va_start(args, fmt); \
- ret = vfprintf(file, fmt, args); \
- va_end(args); \
- colour_end(file); \
- return ret; \
- }
-
-/* cprintf is like printf, but it takes a colour and writes to outfile */
+/* cfprintf is like fprintf but takes a colour to wrap its output. */
static int
-cprintf(int colour, const char* fmt, ...) COLOUR_PRINTF_BODY(colour, outfile, fmt)
-
-/* cprintf_file is like cprintf but it takes a specific file */
-static int
-cprintf_file(FILE *file, int colour, const char* fmt, ...) COLOUR_PRINTF_BODY(colour, file, fmt)
-
-/* fatal_printf is like printf, but for printing fatal errors to stdout*/
-static int
-fatal_printf(const char* fmt, ...) COLOUR_PRINTF_BODY(clr_test_error, stderr, fmt)
+cfprintf(int clr, FILE *file, const char* fmt, ...)
+{
+va_list args;
+int ret;
+va_start(args, fmt);
+colour_begin(clr, file);
+ret = vfprintf(file, fmt, args);
+va_end(args);
+colour_end(file);
+return ret;
+}
-#undef COLOUR_PRINTF_BODY
-/* ---------------- End of colour highlighting definitions ------------------- */
/*************************************************
* Alternate character tables *
@@ -1537,13 +1533,13 @@ if (show_memory && outfile != NULL)
{
if (block == NULL)
{
- cprintf(clr_test_error, "** malloc() failed for %" SIZ_FORM "\n", size);
+ cfprintf(clr_test_error, outfile, "** malloc() failed for %" SIZ_FORM "\n", size);
}
else
{
- cprintf(clr_profiling, "malloc %5" SIZ_FORM, size);
+ cfprintf(clr_profiling, outfile, "malloc %5" SIZ_FORM, size);
#ifdef DEBUG_SHOW_MALLOC_ADDRESSES
- cprintf(clr_profiling, " %p", block); /* Not portable */
+ cfprintf(clr_profiling, outfile, " %p", block); /* Not portable */
#endif
if (malloclistptr < MALLOCLISTSIZE)
{
@@ -1551,8 +1547,8 @@ if (show_memory && outfile != NULL)
malloclistlength[malloclistptr++] = size;
}
else
- cprintf(clr_test_error, " (not remembered)");
- cprintf(clr_profiling, "\n");
+ cfprintf(clr_profiling, outfile, " (not remembered)");
+ fprintf(outfile, "\n");
}
}
return block;
@@ -1567,12 +1563,12 @@ if (show_memory && outfile != NULL && block != NULL)
uint32_t i, j;
BOOL found = FALSE;
- cprintf(clr_profiling, "free");
+ cfprintf(clr_profiling, outfile, "free");
for (i = 0; i < malloclistptr; i++)
{
if (block == malloclist[i])
{
- cprintf(clr_profiling, " %5" SIZ_FORM, malloclistlength[i]);
+ cfprintf(clr_profiling, outfile, " %5" SIZ_FORM, malloclistlength[i]);
malloclistptr--;
for (j = i; j < malloclistptr; j++)
{
@@ -1583,11 +1579,11 @@ if (show_memory && outfile != NULL && block != NULL)
break;
}
}
- if (!found) cprintf(clr_profiling, " unremembered block");
+ if (!found) cfprintf(clr_profiling, outfile, " unremembered block");
#ifdef DEBUG_SHOW_MALLOC_ADDRESSES
- cprintf(clr_profiling, " %p", block); /* Not portable */
+ cfprintf(clr_profiling, outfile, " %p", block); /* Not portable */
#endif
- cprintf(clr_profiling, "\n");
+ fprintf(outfile, "\n");
}
free(block);
}
@@ -1867,7 +1863,7 @@ Returns: number of characters written
*/
static int
-pchar_raw(uint32_t c, BOOL utf, FILE *f)
+pchar(uint32_t c, BOOL utf, FILE *f)
{
int n = 0;
char tempbuffer[16];
@@ -1901,16 +1897,7 @@ if (f != NULL) n = fprintf(f, "\\x{%02x}", c);
return n >= 0 ? n : 0;
}
-/* like pchar but in colour */
-static int
-pchar(int clr, uint32_t c, BOOL utf, FILE *f)
-{
-int res;
-colour_begin(clr, f);
-res = pchar_raw(c, utf, f);
-colour_end(f);
-return res;
-}
+
/*************************************************
* Expand input buffers *
@@ -1933,7 +1920,7 @@ uint8_t *new_pbuffer8 = (uint8_t *)malloc(new_pbuffer8_size);
if (new_buffer == NULL || new_pbuffer8 == NULL)
{
- fatal_printf("pcre2test: malloc(%" SIZ_FORM ") failed\n",
+ cfprintf(clr_test_error, stderr, "pcre2test: malloc(%" SIZ_FORM ") failed\n",
new_pbuffer8_size);
exit(1);
}
@@ -1998,7 +1985,7 @@ for (;;)
dlen = strlen(s);
if (dlen > rlen - 2)
{
- cprintf(clr_test_error, "** Interactive input exceeds buffer space\n");
+ cfprintf(clr_test_error, outfile, "** Interactive input exceeds buffer space\n");
exit(1);
}
if (dlen > 0) add_history(s);
@@ -2016,7 +2003,7 @@ for (;;)
/* Read the next line by normal means, prompting if the file is a tty. */
- if (INTERACTIVE(f)) cprintf(clr_profiling, "%s", prompt);
+ if (INTERACTIVE(f)) cfprintf(clr_prompt, outfile, "%s", prompt);
if (fgets((char *)here, rlen_trunc, f) == NULL)
return (here == start)? NULL : start;
@@ -2037,8 +2024,8 @@ for (;;)
if (dlen < (unsigned)rlen_trunc - 1 && !feof(f))
{
- cprintf(clr_test_error, "** Binary zero encountered in input\n");
- cprintf(clr_test_error, "** pcre2test run abandoned\n");
+ cfprintf(clr_test_error, outfile, "** Binary zero encountered in input\n");
+ cfprintf(clr_test_error, outfile, "** pcre2test run abandoned\n");
exit(1);
}
}
@@ -2330,7 +2317,7 @@ when 8-bit mode is supported. */
static void
prmsg(const char **msg, const char *s)
{
-cprintf(clr_test_error, "%s %s", *msg, s);
+cfprintf(clr_test_error, outfile, "%s %s", *msg, s);
*msg = "";
}
#endif /* SUPPORT_PCRE2_8 */
@@ -2346,6 +2333,7 @@ Because the bits are unique, this can be used for both pattern and data control
words.
Arguments:
+ clr colour for output
controls control bits
controls2 more control bits
before text to print before
@@ -2356,7 +2344,7 @@ Returns: nothing
static void
show_controls(int clr, uint32_t controls, uint32_t controls2, const char *before)
{
-cprintf(clr, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
+cfprintf(clr, outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
before,
((controls & CTL_AFTERTEXT) != 0)? " aftertext" : "",
((controls & CTL_ALLAFTERTEXT) != 0)? " allaftertext" : "",
@@ -2420,6 +2408,7 @@ cprintf(clr, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s
/* Called from show_pattern_info() and for unsupported POSIX options.
Arguments:
+ clr colour for output
options an options word
before text to print before
after text to print after
@@ -2430,8 +2419,8 @@ Returns: nothing
static void
show_compile_options(int clr, uint32_t options, const char *before, const char *after)
{
-if (options == 0) cprintf(clr, "%s %s", before, after);
-else cprintf(clr, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
+if (options == 0) cfprintf(clr, outfile, "%s %s", before, after);
+else cfprintf(clr, outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
before,
((options & PCRE2_ALT_BSUX) != 0)? " alt_bsux" : "",
((options & PCRE2_ALT_CIRCUMFLEX) != 0)? " alt_circumflex" : "",
@@ -2475,6 +2464,7 @@ else cprintf(clr, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%
/* Called from show_pattern_info() and for unsupported POSIX options.
Arguments:
+ clr colour for output
options an options word
before text to print before
after text to print after
@@ -2486,8 +2476,8 @@ static void
show_compile_extra_options(int clr, uint32_t options, const char *before,
const char *after)
{
-if (options == 0) cprintf(clr, "%s %s", before, after);
-else cprintf(clr, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
+if (options == 0) cfprintf(clr, outfile, "%s %s", before, after);
+else cfprintf(clr, outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
before,
((options & PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK) != 0) ? " allow_lookaround_bsk" : "",
((options & PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES) != 0)? " allow_surrogate_escapes" : "",
@@ -2516,6 +2506,7 @@ else cprintf(clr, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
/*
Arguments:
+ clr colour for output
flags an options word
before text to print before
after text to print after
@@ -2524,10 +2515,10 @@ Returns: nothing
*/
static void
-show_optimize_flags(uint32_t flags, const char *before, const char *after)
+show_optimize_flags(int clr, uint32_t flags, const char *before, const char *after)
{
-if (flags == 0) cprintf(clr_output, "%s%s", before, after);
-else cprintf(clr_output, "%s%s%s%s%s%s%s",
+if (flags == 0) cfprintf(clr, outfile, "%s%s", before, after);
+else cfprintf(clr, outfile, "%s%s%s%s%s%s%s",
before,
((flags & PCRE2_OPTIM_AUTO_POSSESS) != 0) ? "auto_possess" : "",
((flags & PCRE2_OPTIM_AUTO_POSSESS) != 0 && (flags >> 1) != 0) ? "," : "",
@@ -2548,7 +2539,7 @@ else cprintf(clr_output, "%s%s%s%s%s%s%s",
static void
show_match_options(int clr, uint32_t options)
{
-cprintf(clr, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
+cfprintf(clr, outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
((options & PCRE2_ANCHORED) != 0)? " anchored" : "",
((options & PCRE2_COPY_MATCHED_SUBJECT) != 0)? " copy_matched_subject" : "",
((options & PCRE2_DFA_RESTART) != 0)? " dfa_restart" : "",
@@ -2594,7 +2585,7 @@ while (endf > filename && isspace((unsigned char)endf[-1])) endf--;
if (endf == filename)
{
- cprintf(clr_test_error, "** File name expected after %s\n", name);
+ cfprintf(clr_test_error, outfile, "** File name expected after %s\n", name);
return PR_ABEND;
}
@@ -2602,7 +2593,7 @@ if (endf == filename)
*fptr = fopen((const char *)filename, mode);
if (*fptr == NULL)
{
- cprintf(clr_test_error, "** Failed to open \"%s\": %s\n", filename, strerror(errno));
+ cfprintf(clr_test_error, outfile, "** Failed to open \"%s\": %s\n", filename, strerror(errno));
return PR_ABEND;
}
@@ -2766,13 +2757,13 @@ for (i = 0; i < 2*oveccount; i += 2)
PCRE2_SIZE start = ovector[i];
PCRE2_SIZE end = ovector[i+1];
- cprintf(clr_output, "%2d: ", i/2);
+ fprintf(outfile, "%2d: ", i/2);
if (start == PCRE2_UNSET && end == PCRE2_UNSET)
- cprintf(clr_api_error, "\n");
+ fprintf(outfile, "\n");
else if (start == JUNK_OFFSET && end == JUNK_OFFSET)
- cprintf(clr_output, "\n");
+ fprintf(outfile, "\n");
else
- cprintf(clr_output, "%ld %ld\n", (unsigned long int)start,
+ fprintf(outfile, "%ld %ld\n", (unsigned long int)start,
(unsigned long int)end);
}
}
@@ -2970,16 +2961,16 @@ DISPATCH(, unittest_, ());
*************************************************/
static void
-print_version(BOOL include_mode)
+print_version(FILE *f, BOOL include_mode)
{
char buf[VERSION_SIZE];
config_str(PCRE2_CONFIG_VERSION, buf);
-cprintf_file(stdout, clr_output, "PCRE2 version %s", buf);
+fprintf(f, "PCRE2 version %s", buf);
if (include_mode)
{
- cprintf_file(stdout, clr_output, " (%d-bit)", test_mode);
+ fprintf(f, " (%d-bit)", test_mode);
}
-cprintf_file(stdout, clr_output, "\n");
+fprintf(f, "\n");
}
@@ -2989,11 +2980,11 @@ cprintf_file(stdout, clr_output, "\n");
*************************************************/
static void
-print_unicode_version(void)
+print_unicode_version(FILE *f)
{
char buf[VERSION_SIZE];
config_str(PCRE2_CONFIG_UNICODE_VERSION, buf);
-cprintf(clr_output, "Unicode version %s", buf);
+fprintf(f, "Unicode version %s", buf);
}
@@ -3003,11 +2994,11 @@ cprintf(clr_output, "Unicode version %s", buf);
*************************************************/
static void
-print_jit_target(void)
+print_jit_target(FILE *f)
{
char buf[VERSION_SIZE];
config_str(PCRE2_CONFIG_JITTARGET, buf);
-cprintf(clr_output, "%s", buf);
+fputs(buf, f);
}
@@ -3027,11 +3018,11 @@ Returns: nothing
static void
print_newline_config(uint32_t optval, BOOL isc)
{
-if (!isc) cprintf(clr_output, " Default newline sequence is ");
+if (!isc) printf(" Default newline sequence is ");
if (optval < sizeof(newlines)/sizeof(char *))
- cprintf(clr_output, "%s\n", newlines[optval]);
+ printf("%s\n", newlines[optval]);
else
- cprintf(clr_test_error, "a non-standard value: %d\n", optval);
+ printf("a non-standard value: %d\n", optval);
}
@@ -3063,7 +3054,8 @@ printf(" -32 use the 32-bit library\n");
printf(" -ac set default pattern modifier PCRE2_AUTO_CALLOUT\n");
printf(" -AC as -ac, but also set subject 'callout_extra' modifier\n");
printf(" -b set default pattern modifier 'fullbincode'\n");
-printf(" -c show output in colour\n");
+printf(" --colo[u]r[=]\n");
+printf(" show output in colour\n");
printf(" -C show PCRE2 compile-time options and exit\n");
printf(" -C arg show a specific compile-time option and exit with its\n");
printf(" value if numeric (else 0). The arg can be:\n");
@@ -3136,7 +3128,7 @@ if (arg != NULL && arg[0] != '-')
if (i >= COPTLISTCOUNT)
{
- fatal_printf("** Unknown -C option \"%s\"\n", arg);
+ cfprintf(clr_test_error, stderr, "pcre2test: Unknown -C option \"%s\"\n", arg);
return 0;
}
@@ -3144,17 +3136,17 @@ if (arg != NULL && arg[0] != '-')
{
case CONF_BSR:
(void)pcre2_config(coptlist[i].value, &optval);
- cprintf(clr_output, "%s\n", (optval == PCRE2_BSR_ANYCRLF)? "ANYCRLF" : "ANY");
+ printf("%s\n", (optval == PCRE2_BSR_ANYCRLF)? "ANYCRLF" : "ANY");
break;
case CONF_FIX:
yield = coptlist[i].value;
- cprintf(clr_output, "%d\n", yield);
+ printf("%d\n", yield);
break;
case CONF_INT:
(void)pcre2_config(coptlist[i].value, &yield);
- cprintf(clr_output, "%d\n", yield);
+ printf("%d\n", yield);
break;
case CONF_NL:
@@ -3171,7 +3163,7 @@ if (arg != NULL && arg[0] != '-')
case PCRE2_ERROR_JIT_UNSUPPORTED: yield = 2; break;
default: yield = 3; break;
}
- cprintf(clr_output, "%d\n", yield);
+ printf("%d\n", yield);
break;
}
@@ -3212,7 +3204,7 @@ is contributed code which the PCRE2 developers have no means of testing. */
/* No argument for -C: output all configuration information. */
-print_version(FALSE);
+print_version(stdout, FALSE);
printf("Compiled with\n");
#ifdef EBCDIC
@@ -3228,9 +3220,9 @@ printf(" Input/output for pcre2test is ASCII, not EBCDIC\n");
#endif
(void)pcre2_config(PCRE2_CONFIG_COMPILED_WIDTHS, &optval);
-if (optval & 1) cprintf(clr_output, " 8-bit support\n");
-if (optval & 2) cprintf(clr_output, " 16-bit support\n");
-if (optval & 4) cprintf(clr_output, " 32-bit support\n");
+if (optval & 1) printf(" 8-bit support\n");
+if (optval & 2) printf(" 16-bit support\n");
+if (optval & 4) printf(" 32-bit support\n");
#ifdef SUPPORT_VALGRIND
printf(" Valgrind support\n");
@@ -3239,43 +3231,43 @@ printf(" Valgrind support\n");
(void)pcre2_config(PCRE2_CONFIG_UNICODE, &optval);
if (optval != 0)
{
- cprintf(clr_output, " UTF and UCP support (");
- print_unicode_version();
- cprintf(clr_output, ")\n");
+ printf(" UTF and UCP support (");
+ print_unicode_version(stdout);
+ printf(")\n");
}
-else cprintf(clr_api_error, " No Unicode support\n");
+else printf(" No Unicode support\n");
(void)pcre2_config(PCRE2_CONFIG_JIT, &optval);
if (optval != 0)
{
- cprintf(clr_output, " Just-in-time compiler support\n");
- cprintf(clr_output, " Architecture: ");
- print_jit_target();
- cprintf(clr_output, "\n");
+ printf(" Just-in-time compiler support\n");
+ printf(" Architecture: ");
+ print_jit_target(stdout);
+ printf("\n");
- cprintf(clr_output, " Can allocate executable memory: ");
+ printf(" Can allocate executable memory: ");
rc = jit_compile_test();
switch(rc)
{
case 0:
- cprintf(clr_output, "Yes\n");
+ printf("Yes\n");
break;
case PCRE2_ERROR_NOMEMORY:
- cprintf(clr_api_error, "No (so cannot work)\n");
+ printf("No (so cannot work)\n");
break;
default:
- cprintf(clr_test_error, "\n** Unexpected return %d from "
+ cfprintf(clr_test_error, stdout, "\n** Unexpected return %d from "
"pcre2_jit_compile(NULL, PCRE2_JIT_TEST_ALLOC)\n", rc);
- cprintf(clr_test_error, "** Should not occur\n");
+ cfprintf(clr_test_error, stdout, "** Should not occur\n");
yield = 1;
break;
}
}
else
{
- cprintf(clr_api_error, " No just-in-time compiler support\n");
+ printf(" No just-in-time compiler support\n");
}
(void)pcre2_config(PCRE2_CONFIG_NEWLINE, &optval);
@@ -3424,7 +3416,7 @@ for (size_t i = 0; i < PRIV(utt_size); i++)
const ucp_type_table *tt = PRIV(utt) + j;
if (tt->type != t->type || tt->value != value) continue;
if (m >= MAX_SYNONYMS)
- cprintf(clr_test_error, "** Too many synonyms: %s ignored\n",
+ cfprintf(clr_test_error, stdout, "** Too many synonyms: %s ignored\n",
PRIV(utt_names) + tt->name_offset);
else fv[m++] = tt->name_offset;
}
@@ -3432,10 +3424,10 @@ for (size_t i = 0; i < PRIV(utt_size); i++)
fv[m] = -1;
}
-cprintf(clr_output, "-------------------------- SUPPORTED %s --------------------------\n\n",
+printf("-------------------------- SUPPORTED %s --------------------------\n\n",
wantscripts? "SCRIPTS" : "PROPERTIES");
-if (!wantscripts) cprintf(clr_output,
+if (!wantscripts) printf(
"This release of PCRE2 supports Unicode's general category properties such\n"
"as Lu (upper case letter), bi-directional properties such as Bidi_Class,\n"
"and the following binary (yes/no) properties:\n\n");
@@ -3452,9 +3444,9 @@ for (int k = 0; k < (n+1)/2; k++)
if (x < n) format_list_item(found[x], buff2, wantscripts);
else buff2[0] = 0;
- x = cprintf(clr_output, "%s", buff1);
- while (x++ < colwidth) cprintf(clr_output, " ");
- cprintf(clr_output, "%s\n", buff2);
+ x = printf("%s", buff1);
+ while (x++ < colwidth) printf(" ");
+ printf("%s\n", buff2);
}
#endif /* SUPPORT_UNICODE */
@@ -3471,11 +3463,11 @@ display_one_modifier(modstruct *m, BOOL for_pattern)
{
uint32_t c = (!for_pattern && (m->which == MOD_PND || m->which == MOD_PNDP))?
'*' : ' ';
-cprintf(clr_output, "%c%s", c, m->name);
+printf("%c%s", c, m->name);
for (size_t i = 0; i < C1MODLISTCOUNT; i++)
{
if (strcmp(m->name, c1modlist[i].fullname) == 0)
- cprintf(clr_output, " (%c)", c1modlist[i].onechar);
+ printf(" (%c)", c1modlist[i].onechar);
}
}
@@ -3527,12 +3519,15 @@ for (i = 0; i < MODLISTCOUNT; i++)
is_pattern = FALSE;
break;
- default: cprintf_file(stdout, clr_test_error, "** Unknown type for modifier \"%s\"\n", m->name);
- PCRE2_FALLTHROUGH /* Fall through */
case MOD_PD: /* Pattern or subject */
case MOD_PDP: /* As PD, OK for Perl-compatible test */
is_pattern = for_pattern;
break;
+
+ default:
+ printf("** Unknown type for modifier \"%s\"\n", m->name);
+ PCRE2_DEBUG_UNREACHABLE();
+ exit(1);
}
if (for_pattern == is_pattern)
@@ -3561,10 +3556,10 @@ for (i = 0, j = (n+1)/2; i < (n+1)/2; i++, j++)
if (j < n)
{
size_t k = 27 - strlen(m->name) - extra[i];
- while (k-- > 0) cprintf(clr_output, " ");
+ while (k-- > 0) printf(" ");
display_one_modifier(modlist + list[j], for_pattern);
}
- cprintf(clr_output, "\n");
+ printf("\n");
}
}
@@ -3606,19 +3601,6 @@ BOOL skipping_endif = FALSE;
char *arg_subject = NULL;
char *arg_pattern = NULL;
char *arg_error = NULL;
-outfile = stdout;
-
-/* Before printing anything, check if we are being asked to print in colour */
-
-for (int i = 1; i < argc && argv[i][0] == '-' && argv[i][1] != 0; i++)
- {
- if (strcmp(argv[i], "-c") == 0)
- {
- colour_on = TRUE;
- colour_end(stdout);
- }
- }
-
/* The offsets to the options and control bits fields of the pattern and data
control blocks must be the same so that common options and controls such as
@@ -3633,7 +3615,7 @@ preprocessor. */
if (PO(options) != DO(options) || PO(control) != DO(control) ||
PO(control2) != DO(control2))
{
- fatal_printf("** Coding error: "
+ cfprintf(clr_test_error, stderr, "** Coding error: "
"options and control offsets for pattern and data must be the same.\n");
return 1;
}
@@ -3727,8 +3709,8 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
#ifdef SUPPORT_PCRE2_8
test_mode = PCRE2TEST_MODE_8;
#else
- fatal_printf(
- "** This version of PCRE2 was built without 8-bit support\n");
+ cfprintf(clr_test_error, stderr,
+ "pcre2test: This version of PCRE2 was built without 8-bit support\n");
exit(1);
#endif
}
@@ -3738,8 +3720,8 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
#ifdef SUPPORT_PCRE2_16
test_mode = PCRE2TEST_MODE_16;
#else
- fatal_printf(
- "** This version of PCRE2 was built without 16-bit support\n");
+ cfprintf(clr_test_error, stderr,
+ "pcre2test: This version of PCRE2 was built without 16-bit support\n");
exit(1);
#endif
}
@@ -3749,8 +3731,8 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
#ifdef SUPPORT_PCRE2_32
test_mode = PCRE2TEST_MODE_32;
#else
- fatal_printf(
- "** This version of PCRE2 was built without 32-bit support\n");
+ cfprintf(clr_test_error, stderr,
+ "pcre2test: This version of PCRE2 was built without 32-bit support\n");
exit(1);
#endif
}
@@ -3769,7 +3751,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
((uli = strtoul(argv[op+1], &endptr, 10)), *endptr == 0))
{
#if defined(_WIN32) || defined(WIN32) || defined(__HAIKU__) || defined(NATIVE_ZOS) || defined(__VMS)
- fatal_printf("pcre2test: -S is not supported on this OS\n");
+ cfprintf(clr_test_error, stderr, "pcre2test: -S is not supported on this OS\n");
exit(1);
#else
int rc = 0;
@@ -3777,7 +3759,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
struct rlimit rlim, rlim_old;
if (uli > INT32_MAX / (1024 * 1024))
{
- fatal_printf("** Argument for -S is too big\n");
+ cfprintf(clr_test_error, stderr, "pcre2test: Argument for -S is too big\n");
exit(1);
}
stack_size = (uint32_t)uli;
@@ -3786,15 +3768,15 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
rlim.rlim_cur = stack_size * 1024 * 1024;
if (rlim.rlim_max != RLIM_INFINITY && rlim.rlim_cur > rlim.rlim_max)
{
- fatal_printf(
+ cfprintf(clr_test_error, stderr,
"pcre2test: requested stack size %luMiB is greater than hard limit ",
(unsigned long int)stack_size);
if (rlim.rlim_max % (1024*1024) == 0)
- fatal_printf("%luMiB\n", (unsigned long)(rlim.rlim_max/(1024*1024)));
+ cfprintf(clr_test_error, stderr, "%luMiB\n", (unsigned long)(rlim.rlim_max/(1024*1024)));
else if (rlim.rlim_max % 1024 == 0)
- fatal_printf("%luKiB\n", (unsigned long)(rlim.rlim_max/1024));
+ cfprintf(clr_test_error, stderr, "%luKiB\n", (unsigned long)(rlim.rlim_max/1024));
else
- fatal_printf("%lu bytes\n", (unsigned long)(rlim.rlim_max));
+ cfprintf(clr_test_error, stderr, "%lu bytes\n", (unsigned long)(rlim.rlim_max));
exit(1);
}
if (rlim_old.rlim_cur != RLIM_INFINITY && rlim_old.rlim_cur <= INT32_MAX &&
@@ -3802,7 +3784,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
rc = setrlimit(RLIMIT_STACK, &rlim);
if (rc != 0)
{
- fatal_printf("pcre2test: setting stack size %luMiB failed: %s\n",
+ cfprintf(clr_test_error, stderr, "pcre2test: setting stack size %luMiB failed: %s\n",
(unsigned long int)stack_size, strerror(errno));
exit(1);
}
@@ -3820,7 +3802,6 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
}
else if (strcmp(arg, "-ac") == 0) def_patctl.options |= PCRE2_AUTO_CALLOUT;
else if (strcmp(arg, "-b") == 0) def_patctl.control |= CTL_FULLBINCODE;
- else if (strcmp(arg, "-c") == 0) /* handled above */;
else if (strcmp(arg, "-d") == 0) def_patctl.control |= CTL_DEBUG;
else if (strcmp(arg, "-dfa") == 0) def_datctl.control |= CTL_DFA;
else if (strcmp(arg, "-i") == 0) def_patctl.control |= CTL_INFO;
@@ -3831,7 +3812,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
else if (arg[4] == 'f') def_patctl.control |= CTL_JITFAST;
def_patctl.jit = JIT_DEFAULT; /* full & partial */
#ifndef SUPPORT_JIT
- fatal_printf("** Warning: JIT support is not available: "
+ cfprintf(clr_test_error, stderr, "pcre2test: Warning: JIT support is not available: "
"-jit[fast|verify] calls functions that do nothing.\n");
#endif
}
@@ -3847,12 +3828,12 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
{
if (uli == 0)
{
- fatal_printf("** Argument for %s must not be zero\n", arg);
+ cfprintf(clr_test_error, stderr, "pcre2test: Argument for %s must not be zero\n", arg);
exit(1);
}
if (U32OVERFLOW(uli))
{
- fatal_printf("** Argument for %s is too big\n", arg);
+ cfprintf(clr_test_error, stderr, "pcre2test: Argument for %s is too big\n", arg);
exit(1);
}
timeitm = (int)uli;
@@ -3884,7 +3865,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
else if (memcmp(arg, "-v", 2) == 0 ||
strcmp(arg, "--version") == 0)
{
- print_version(FALSE);
+ print_version(stdout, FALSE);
goto EXIT;
}
@@ -3909,7 +3890,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
CHECK_VALUE_EXISTS:
if (argc <= 2)
{
- fatal_printf("** Missing value for %s\n", arg);
+ cfprintf(clr_test_error, stderr, "pcre2test: Missing value for %s\n", arg);
yield = 1;
goto EXIT;
}
@@ -3917,11 +3898,31 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
argc--;
}
+ else if (strcmp(arg, "--color") == 0 || strcmp(arg, "--colour") == 0)
+ {
+ colour_setting = COLOUR_ALWAYS;
+ }
+
+ else if (strstr(arg, "--color=") == arg || strstr(arg, "--colour=") == arg)
+ {
+ char *val = strchr(arg, '=') + 1;
+ if (strcmp(val, "always") == 0) colour_setting = COLOUR_ALWAYS;
+ else if (strcmp(val, "never") == 0) colour_setting = COLOUR_NEVER;
+ else if (strcmp(val, "auto") == 0) colour_setting = COLOUR_AUTO;
+ else
+ {
+ cfprintf(clr_test_error, stderr,
+ "pcre2test: Invalid value for \"%.*s\"\n", (int)(val - 1 - arg), arg);
+ yield = 1;
+ goto EXIT;
+ }
+ }
+
/* Unrecognized option */
else
{
- fatal_printf("** Unknown or malformed option \"%s\"\n", arg);
+ cfprintf(clr_test_error, stderr, "pcre2test: Unknown or malformed option \"%s\"\n", arg);
usage();
yield = 1;
goto EXIT;
@@ -3946,12 +3947,12 @@ if (arg_error != NULL)
li = strtol(arg_error, &endptr, 10);
if (S32OVERFLOW(li) || (*endptr != 0 && *endptr != ','))
{
- fatal_printf("** \"%s\" is not a valid error number list\n", arg_error);
+ cfprintf(clr_test_error, stderr, "pcre2test: \"%s\" is not a valid error number list\n", arg_error);
yield = 1;
goto EXIT;
}
errcode = (int)li;
- cprintf_file(stdout, clr_api_error, "Error %d: ", errcode);
+ printf("Error %d: ", errcode);
print_error_message_file(stdout, errcode, "", "\n", TRUE);
if (*endptr == 0) goto EXIT;
arg_error = endptr + 1;
@@ -3993,7 +3994,7 @@ if (argc > 1 && strcmp(argv[op], "-") != 0)
infile = fopen(argv[op], INPUT_MODE);
if (infile == NULL)
{
- fatal_printf("** Failed to open \"%s\": %s\n", argv[op], strerror(errno));
+ cfprintf(clr_test_error, stderr, "pcre2test: Failed to open \"%s\": %s\n", argv[op], strerror(errno));
yield = 1;
goto EXIT;
}
@@ -4008,7 +4009,7 @@ if (argc > 2)
outfile = fopen(argv[op+1], OUTPUT_MODE);
if (outfile == NULL)
{
- fatal_printf("** Failed to open \"%s\": %s\n", argv[op+1], strerror(errno));
+ cfprintf(clr_test_error, stderr, "pcre2test: Failed to open \"%s\": %s\n", argv[op+1], strerror(errno));
yield = 1;
goto EXIT;
}
@@ -4016,7 +4017,7 @@ if (argc > 2)
/* Output a heading line unless quiet, then process input lines. */
-if (!quiet) print_version(TRUE);
+if (!quiet) print_version(outfile, TRUE);
#ifdef SUPPORT_PCRE2_8
preg.re_pcre2_code = NULL;
@@ -4033,7 +4034,7 @@ while (notdone)
expectdata |= preg.re_pcre2_code != NULL;
#endif
- if (extend_inputline(infile, buffer, expectdata? PROMPT("data> ") : PROMPT(" re> ")) == NULL)
+ if (extend_inputline(infile, buffer, expectdata? "data> " : " re> ") == NULL)
break;
/* Pre-process input lines with #if...#endif. */
@@ -4050,7 +4051,8 @@ while (notdone)
p = buffer;
is_comment = p[0] == '#' && (isspace(p[1]) || p[1] == '!' || p[1] == 0);
- if (!INTERACTIVE(infile)) cprintf(is_comment ? clr_comment : clr_input, "%s", (char *)buffer);
+ if (!INTERACTIVE(infile))
+ cfprintf(is_comment ? clr_comment : clr_input, outfile, "%s", (char *)buffer);
fflush(outfile);
if (preprocess_only && *p != '#') continue;
@@ -4109,7 +4111,7 @@ while (notdone)
while (isspace(*p)) p++;
if (*p != 0)
{
- cprintf(clr_test_error, "** Invalid pattern delimiter '%c' (x%x).\n", *buffer,
+ cfprintf(clr_test_error, outfile, "** Invalid pattern delimiter '%c' (x%x).\n", *buffer,
*buffer);
rc = PR_SKIP;
}
@@ -4119,7 +4121,7 @@ while (notdone)
else if (rc == PR_ENDIF) skipping_endif = TRUE;
else if (rc == PR_ABEND)
{
- cprintf(clr_test_error, "** pcre2test run abandoned\n");
+ cfprintf(clr_test_error, outfile, "** pcre2test run abandoned\n");
yield = 1;
goto EXIT;
}
@@ -4129,28 +4131,28 @@ while (notdone)
if (skipping_endif)
{
- cprintf(clr_test_error, "** Expected #endif\n");
+ cfprintf(clr_test_error, outfile, "** Expected #endif\n");
yield = 1;
goto EXIT;
}
-if (INTERACTIVE(infile)) cprintf(clr_output, "\n");
+if (INTERACTIVE(infile)) fprintf(outfile, "\n");
if (showtotaltimes)
{
const char *pad = "";
- cprintf(clr_profiling, "--------------------------------------\n");
+ cfprintf(clr_profiling, outfile, "--------------------------------------\n");
if (timeit > 0)
{
- cprintf(clr_profiling, "Total compile time %8.2f microseconds\n",
+ cfprintf(clr_profiling, outfile, "Total compile time %8.2f microseconds\n",
((1000000 / CLOCKS_PER_SEC) * (double)total_compile_time) / timeit);
if (total_jit_compile_time > 0)
- cprintf(clr_profiling, "Total JIT compile %8.2f microseconds\n",
+ cfprintf(clr_profiling, outfile, "Total JIT compile %8.2f microseconds\n",
((1000000 / CLOCKS_PER_SEC) * (double)total_jit_compile_time) / \
timeit);
pad = " ";
}
- cprintf(clr_profiling, "Total match time %s%8.2f microseconds\n", pad,
+ cfprintf(clr_profiling, outfile, "Total match time %s%8.2f microseconds\n", pad,
((1000000 / CLOCKS_PER_SEC) * (double)total_match_time) / timeitm);
}
diff --git a/src/pcre2test_inc.h b/src/pcre2test_inc.h
index 433c20188..ff45a5fbd 100644
--- a/src/pcre2test_inc.h
+++ b/src/pcre2test_inc.h
@@ -74,7 +74,6 @@ library. */
#define pcre2_strlen PCRE2_SUFFIX(pcre2_strlen_)
#define pchars PCRE2_SUFFIX(pchars_)
#define ptrunc PCRE2_SUFFIX(ptrunc_)
-#define pcre2_printint_clr PCRE2_SUFFIX(pcre2_printint_clr_)
#define config_str PCRE2_SUFFIX(config_str_)
#define check_modifier PCRE2_SUFFIX(check_modifier_)
#define decode_modifiers PCRE2_SUFFIX(decode_modifiers_)
@@ -183,7 +182,9 @@ static int pchars(int clr, PCRE2_SPTR p, ptrdiff_t length, BOOL utf, FILE *f)
PCRE2_SPTR end;
uint32_t c = 0;
int yield = 0;
+
colour_begin(clr, f);
+
if (length < 0) length = *p++;
end = p + length;
while (length-- > 0)
@@ -195,12 +196,12 @@ while (length-- > 0)
{
length -= rc - 1;
p += rc;
- yield += pchar_raw(c, utf, f);
+ yield += pchar(c, utf, f);
continue;
}
}
c = *p++;
- yield += pchar_raw(c, utf, f);
+ yield += pchar(c, utf, f);
}
colour_end(f);
@@ -208,12 +209,14 @@ return yield;
#else
int yield = 0;
+
colour_begin(clr, f);
+
if (length < 0) length = *p++;
while (length-- > 0)
{
uint32_t c = *p++;
- yield += pchar_raw(c, utf, f);
+ yield += pchar(c, utf, f);
}
colour_end(f);
@@ -233,8 +236,8 @@ the offset to print from/to. If left is true, prints up to the offset,
truncated; otherwise prints from the offset to the right, truncated. */
#if PCRE2_CODE_UNIT_WIDTH == 8
-static void ptrunc_8(int clr, PCRE2_SPTR p, size_t p_len, size_t offset, BOOL left,
- BOOL utf, FILE *f)
+static void ptrunc_8(int clr, PCRE2_SPTR p, size_t p_len, size_t offset,
+ BOOL left, BOOL utf, FILE *f)
{
PCRE2_SPTR start = p + offset;
PCRE2_SPTR end = p + offset;
@@ -271,8 +274,8 @@ colour_end(f);
}
#elif PCRE2_CODE_UNIT_WIDTH == 16
-static void ptrunc_16(int clr, PCRE2_SPTR p, size_t p_len, size_t offset, BOOL left,
- BOOL utf, FILE *f)
+static void ptrunc_16(int clr, PCRE2_SPTR p, size_t p_len, size_t offset,
+ BOOL left, BOOL utf, FILE *f)
{
PCRE2_SPTR start = p + offset;
PCRE2_SPTR end = p + offset;
@@ -323,8 +326,8 @@ colour_end(f);
}
#elif PCRE2_CODE_UNIT_WIDTH == 32
-static void ptrunc_32(int clr, PCRE2_SPTR p, size_t p_len, size_t offset, BOOL left,
- BOOL utf, FILE *f)
+static void ptrunc_32(int clr, PCRE2_SPTR p, size_t p_len, size_t offset,
+ BOOL left, BOOL utf, FILE *f)
{
PCRE2_SPTR start = p + offset;
PCRE2_SPTR end = p + offset;
@@ -359,18 +362,6 @@ colour_end(f);
}
#endif
-/*************************************************
-* Print 8-bit compiled pattern (in colour) *
-*************************************************/
-
-static void
-pcre2_printint_clr(int clr, pcre2_code *re, FILE *f, BOOL print_lengths)
-{
- colour_begin(clr, f);
- pcre2_printint(re, f, print_lengths);
- colour_end(f);
-}
-
#if PCRE2_CODE_UNIT_WIDTH == 16
/*************************************************
* Convert string to 16-bit *
@@ -420,7 +411,7 @@ if (pbuffer16_size < 2*len + 2)
pbuffer16 = (uint16_t *)malloc(pbuffer16_size);
if (pbuffer16 == NULL)
{
- fatal_printf("pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer16\n",
+ cfprintf(clr_test_error, stderr, "pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer16\n",
pbuffer16_size);
exit(1);
}
@@ -509,7 +500,7 @@ if (pbuffer32_size < 4*len + 4)
pbuffer32 = (uint32_t *)malloc(pbuffer32_size);
if (pbuffer32 == NULL)
{
- fatal_printf("pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer32\n",
+ cfprintf(clr_test_error, stderr, "pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer32\n",
pbuffer32_size);
exit(1);
}
@@ -571,7 +562,7 @@ r1 = pcre2_config(what, NULL);
r2 = pcre2_config(what, buf);
if (r1 < 0 || r1 != r2 || r1 >= VERSION_SIZE)
{
- fatal_printf("pcre2test: Error in pcre2_config(%d)\n", what);
+ cfprintf(clr_test_error, stderr, "pcre2test: Error in pcre2_config(%d)\n", what);
exit(1);
}
@@ -616,7 +607,7 @@ if (restrict_for_perl_test) switch(m->which)
break;
default:
- cprintf(clr_test_error, "** \"%s\" is not allowed in a Perl-compatible test\n",
+ cfprintf(clr_test_error, outfile, "** \"%s\" is not allowed in a Perl-compatible test\n",
m->name);
return NULL;
}
@@ -657,9 +648,9 @@ switch (m->which)
if (field == NULL)
{
if (c == 0)
- cprintf(clr_test_error, "** \"%s\" is not valid here\n", m->name);
+ cfprintf(clr_test_error, outfile, "** \"%s\" is not valid here\n", m->name);
else
- cprintf(clr_test_error, "** /%c is not valid here\n", c);
+ cfprintf(clr_test_error, outfile, "** /%c is not valid here\n", c);
return NULL;
}
@@ -747,9 +738,9 @@ for (;;)
if (!first)
{
- cprintf(clr_test_error, "** Unrecognized modifier \"%.*s\"\n", (int)(ep-p), p);
+ cfprintf(clr_test_error, outfile, "** Unrecognized modifier \"%.*s\"\n", (int)(ep-p), p);
if (ep - p == 1)
- cprintf(clr_test_error, "** Single-character modifiers must come first\n");
+ cfprintf(clr_test_error, outfile, "** Single-character modifiers must come first\n");
return FALSE;
}
@@ -762,7 +753,7 @@ for (;;)
if (i >= C1MODLISTCOUNT)
{
- cprintf(clr_test_error, "** Unrecognized modifier '%c' in modifier string "
+ cfprintf(clr_test_error, outfile, "** Unrecognized modifier '%c' in modifier string "
"\"%.*s\"\n", *p, (int)(ep-mp), mp);
return FALSE;
}
@@ -778,7 +769,7 @@ for (;;)
strlen(c1modlist[i].fullname));
if (index < 0)
{
- cprintf(clr_test_error, "** Internal error: single-character equivalent "
+ cfprintf(clr_test_error, outfile, "** Internal error: single-character equivalent "
"modifier \"%s\" not found\n", c1modlist[i].fullname);
return FALSE;
}
@@ -812,12 +803,12 @@ for (;;)
{
if (*pp++ != '=')
{
- cprintf(clr_test_error, "** '=' expected after \"%s\"\n", m->name);
+ cfprintf(clr_test_error, outfile, "** '=' expected after \"%s\"\n", m->name);
return FALSE;
}
if (off)
{
- cprintf(clr_test_error, "** '-' is not valid for \"%s\"\n", m->name);
+ cfprintf(clr_test_error, outfile, "** '-' is not valid for \"%s\"\n", m->name);
return FALSE;
}
}
@@ -826,7 +817,7 @@ for (;;)
else if (*pp != ',' && *pp != '\n' && *pp != ' ' && *pp != 0)
{
- cprintf(clr_test_error, "** Unrecognized modifier '%.*s'\n", (int)(ep-p), p);
+ cfprintf(clr_test_error, outfile, "** Unrecognized modifier '%.*s'\n", (int)(ep-p), p);
return FALSE;
}
@@ -991,7 +982,7 @@ for (;;)
field = (char *)field + sizeof(int32_t);
if (ct <= 0)
{
- cprintf(clr_test_error, "** Too many numeric \"%s\" modifiers\n", m->name);
+ cfprintf(clr_test_error, outfile, "** Too many numeric \"%s\" modifiers\n", m->name);
return FALSE;
}
}
@@ -1009,13 +1000,13 @@ for (;;)
{
if (len > MAX_NAME_SIZE)
{
- cprintf(clr_test_error, "** Group name in \"%s\" is too long\n", m->name);
+ cfprintf(clr_test_error, outfile, "** Group name in \"%s\" is too long\n", m->name);
return FALSE;
}
while (*nn != 0) nn += strlen(nn) + 1;
if (nn + len + 2 - (char *)field > LENCPYGET)
{
- cprintf(clr_test_error, "** Too many characters in named \"%s\" modifiers\n",
+ cfprintf(clr_test_error, outfile, "** Too many characters in named \"%s\" modifiers\n",
m->name);
return FALSE;
}
@@ -1030,7 +1021,7 @@ for (;;)
case MOD_STR:
if (len + 1 > m->value)
{
- cprintf(clr_test_error, "** Overlong value for \"%s\" (max %d code units)\n",
+ cfprintf(clr_test_error, outfile, "** Overlong value for \"%s\" (max %d code units)\n",
m->name, m->value - 1);
return FALSE;
}
@@ -1042,7 +1033,7 @@ for (;;)
if (*pp != ',' && *pp != '\n' && *pp != ' ' && *pp != 0)
{
- cprintf(clr_test_error, "** Comma expected after modifier item \"%s\"\n", m->name);
+ cfprintf(clr_test_error, outfile, "** Comma expected after modifier item \"%s\"\n", m->name);
return FALSE;
}
@@ -1054,7 +1045,7 @@ for (;;)
pctl->locale[0] != 0 ||
(pctl->control & NOTPOP_CONTROLS) != 0))
{
- cprintf(clr_test_error, "** \"%s\" is not valid here\n", m->name);
+ cfprintf(clr_test_error, outfile, "** \"%s\" is not valid here\n", m->name);
return FALSE;
}
}
@@ -1062,7 +1053,7 @@ for (;;)
return TRUE;
INVALID_VALUE:
-cprintf(clr_test_error, "** Invalid value in \"%.*s\"\n", (int)(ep-p), p);
+cfprintf(clr_test_error, outfile, "** Invalid value in \"%.*s\"\n", (int)(ep-p), p);
return FALSE;
}
@@ -1092,7 +1083,7 @@ rc = pcre2_pattern_info(compiled_code, what, where);
if (rc >= 0) return 0;
if (rc != PCRE2_ERROR_UNSET || !unsetok)
{
- cprintf(clr_api_error, "Error %d from "
+ cfprintf(clr_api_error, outfile, "Error %d from "
"pcre2_pattern_info_" STR(PCRE2_CODE_UNIT_WIDTH) "(%d)\n", rc, what);
}
return rc;
@@ -1120,15 +1111,15 @@ cblock_size = sizeof(pcre2_real_code);
integer overflow. */
data_size = CU2BYTES((PCRE2_SIZE)name_count * (PCRE2_SIZE)name_entry_size);
-cprintf(clr_profiling, "Memory allocation - code size : %" SIZ_FORM "\n", size -
+cfprintf(clr_profiling, outfile, "Memory allocation - code size : %" SIZ_FORM "\n", size -
cblock_size - data_size);
if (data_size != 0)
- cprintf(clr_profiling, "Memory allocation - data size : %" SIZ_FORM "\n", data_size);
+ cfprintf(clr_profiling, outfile, "Memory allocation - data size : %" SIZ_FORM "\n", data_size);
if (pat_patctl.jit != 0)
{
(void)pattern_info(PCRE2_INFO_JITSIZE, &size, FALSE);
- cprintf(clr_profiling, "Memory allocation - JIT code : %" SIZ_FORM "\n", size);
+ cfprintf(clr_profiling, outfile, "Memory allocation - JIT code : %" SIZ_FORM "\n", size);
}
}
@@ -1143,7 +1134,7 @@ show_framesize(void)
{
PCRE2_SIZE frame_size;
(void)pattern_info(PCRE2_INFO_FRAMESIZE, &frame_size, FALSE);
-cprintf(clr_profiling, "Frame size for pcre2_match(): %" SIZ_FORM "\n", frame_size);
+cfprintf(clr_profiling, outfile, "Frame size for pcre2_match(): %" SIZ_FORM "\n", frame_size);
}
@@ -1157,7 +1148,7 @@ show_heapframes_size(void)
{
PCRE2_SIZE heapframes_size;
heapframes_size = pcre2_get_match_data_heapframes_size(match_data);
-cprintf(clr_profiling, "Heapframes size in match_data: %" SIZ_FORM "\n",
+cfprintf(clr_profiling, outfile, "Heapframes size in match_data: %" SIZ_FORM "\n",
heapframes_size);
}
@@ -1177,24 +1168,24 @@ PCRE2_UCHAR buf[128];
len = pcre2_get_error_message(errorcode, buf, sizeof(buf)/sizeof(*buf));
if (len == PCRE2_ERROR_BADDATA && badcode_ok)
{
- cprintf_file(file, clr_test_error, "%sPCRE2_ERROR_BADDATA (unknown error number)%s", before,
+ cfprintf(clr_api_error, file, "%sPCRE2_ERROR_BADDATA (unknown error number)%s", before,
after);
}
else if (len < 0)
{
- cprintf_file(file, clr_test_error, "\n** pcre2test internal error: cannot interpret error "
+ cfprintf(clr_test_error, file, "\n** pcre2test internal error: cannot interpret error "
"number\n** Unexpected return (%d) from pcre2_get_error_message()\n", len);
}
else if ((unsigned)len != pcre2_strlen(buf))
{
- cprintf_file(file, clr_test_error, "\n** pcre2test: unexpected length %d from pcre2_get_error_message()\n", len);
+ cfprintf(clr_test_error, file, "\n** pcre2test: unexpected length %d from pcre2_get_error_message()\n", len);
return FALSE;
}
else
{
- cprintf_file(file, clr_api_error, "%s", before);
+ cfprintf(clr_api_error, file, "%s", before);
pchars(clr_api_error, buf, len, FALSE, file);
- cprintf_file(file, clr_api_error, "%s", after);
+ cfprintf(clr_api_error, file, "%s", after);
}
return len >= 0;
}
@@ -1229,26 +1220,26 @@ PCRE2_SIZE next_item_length = cb->next_item_length;
(void)callout_data; /* Not currently displayed */
-cprintf(clr_output, "Callout ");
+fprintf(outfile, "Callout ");
if (cb->callout_string != NULL)
{
uint32_t delimiter = cb->callout_string[-1];
- cprintf(clr_output, "%c", CHAR_OUTPUT(delimiter));
- pchars(clr_output, cb->callout_string, cb->callout_string_length, utf, outfile);
+ fprintf(outfile, "%c", CHAR_OUTPUT(delimiter));
+ pchars(clr_none, cb->callout_string, cb->callout_string_length, utf, outfile);
for (i = 0; callout_start_delims[i] != 0; i++)
if (delimiter == callout_start_delims[i])
{
delimiter = callout_end_delims[i];
break;
}
- cprintf(clr_output, "%c ", CHAR_OUTPUT(delimiter));
+ fprintf(outfile, "%c ", CHAR_OUTPUT(delimiter));
}
-else cprintf(clr_output, "%d ", cb->callout_number);
+else fprintf(outfile, "%d ", cb->callout_number);
if (next_item_length == 0 && pattern_string[cb->pattern_position] != 0)
next_item_length = 1;
-pchars(clr_output, pattern_string+cb->pattern_position, next_item_length, utf, outfile);
-cprintf(clr_output, "\n");
+pchars(clr_none, pattern_string+cb->pattern_position, next_item_length, utf, outfile);
+fprintf(outfile, "\n");
return 0;
}
@@ -1299,8 +1290,8 @@ if ((pat_patctl.control2 & CTL2_FRAMESIZE) != 0)
if ((pat_patctl.control & (CTL_BINCODE|CTL_FULLBINCODE)) != 0)
{
- cprintf(clr_output, "------------------------------------------------------------------\n");
- pcre2_printint_clr(clr_output, compiled_code, outfile,
+ fprintf(outfile, "------------------------------------------------------------------\n");
+ pcre2_printint(compiled_code, outfile,
(pat_patctl.control & CTL_FULLBINCODE) != 0);
}
@@ -1380,30 +1371,30 @@ if ((pat_patctl.control & CTL_INFO) != 0)
!= 0)
return PR_ABEND;
- cprintf(clr_output, "Capture group count = %d\n", capture_count);
+ fprintf(outfile, "Capture group count = %d\n", capture_count);
if (backrefmax > 0)
- cprintf(clr_output, "Max back reference = %d\n", backrefmax);
+ fprintf(outfile, "Max back reference = %d\n", backrefmax);
if (maxlookbehind > 0)
- cprintf(clr_output, "Max lookbehind = %d\n", maxlookbehind);
+ fprintf(outfile, "Max lookbehind = %d\n", maxlookbehind);
if (heap_limit_set)
- cprintf(clr_output, "Heap limit = %u\n", heap_limit);
+ fprintf(outfile, "Heap limit = %u\n", heap_limit);
if (match_limit_set)
- cprintf(clr_output, "Match limit = %u\n", match_limit);
+ fprintf(outfile, "Match limit = %u\n", match_limit);
if (depth_limit_set)
- cprintf(clr_output, "Depth limit = %u\n", depth_limit);
+ fprintf(outfile, "Depth limit = %u\n", depth_limit);
if (namecount > 0)
{
- cprintf(clr_output, "Named capture groups:\n");
+ fprintf(outfile, "Named capture groups:\n");
for (; namecount > 0; namecount--)
{
size_t length = pcre2_strlen(nametable + IMM2_SIZE);
- cprintf(clr_output, " ");
+ fprintf(outfile, " ");
/* In UTF mode the name may be a UTF string containing non-ASCII
letters and digits. We must output it as a UTF-8 string. In non-UTF mode,
@@ -1418,7 +1409,7 @@ if ((pat_patctl.control & CTL_INFO) != 0)
{
uint8_t u8buff[6];
int len = ord_to_utf8(*nameptr++, u8buff);
- cprintf(clr_output, "%.*s", len, u8buff);
+ fprintf(outfile, "%.*s", len, u8buff);
}
#endif
#if PCRE2_CODE_UNIT_WIDTH == 16
@@ -1433,29 +1424,29 @@ if ((pat_patctl.control & CTL_INFO) != 0)
if (ord_rc > 0) nameptr += ord_rc;
else c = *nameptr++;
len = ord_to_utf8(c, u8buff);
- cprintf(clr_output, "%.*s", len, u8buff);
+ fprintf(outfile, "%.*s", len, u8buff);
}
#endif
#if PCRE2_CODE_UNIT_WIDTH == 8
- cprintf(clr_output, "%s", nametable + IMM2_SIZE);
+ fprintf(outfile, "%s", nametable + IMM2_SIZE);
#endif
}
else /* Not UTF mode */
{
- pchars(clr_output, nametable + IMM2_SIZE, length, FALSE, outfile);
+ pchars(clr_none, nametable + IMM2_SIZE, length, FALSE, outfile);
}
- while (length++ < nameentrysize - IMM2_SIZE) cprintf(clr_output, " ");
+ while (length++ < nameentrysize - IMM2_SIZE) putc(' ', outfile);
- cprintf(clr_output, "%3d\n", GET2(nametable, 0));
+ fprintf(outfile, "%3d\n", GET2(nametable, 0));
nametable = nametable + nameentrysize;
}
}
- if (hascrorlf) cprintf(clr_output, "Contains explicit CR or LF match\n");
- if (hasbackslashc) cprintf(clr_output, "Contains \\C\n");
- if (match_empty) cprintf(clr_output, "May match empty string\n");
+ if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");
+ if (hasbackslashc) fprintf(outfile, "Contains \\C\n");
+ if (match_empty) fprintf(outfile, "May match empty string\n");
pattern_info(PCRE2_INFO_ARGOPTIONS, &compile_options, FALSE);
pattern_info(PCRE2_INFO_ALLOPTIONS, &overall_options, FALSE);
@@ -1479,25 +1470,25 @@ if ((pat_patctl.control & CTL_INFO) != 0)
if ((compile_options|overall_options) != 0)
{
if (compile_options == overall_options)
- show_compile_options(clr_output, compile_options, "Options:", "\n");
+ show_compile_options(clr_none, compile_options, "Options:", "\n");
else
{
- show_compile_options(clr_output, compile_options, "Compile options:", "\n");
- show_compile_options(clr_output, overall_options, "Overall options:", "\n");
+ show_compile_options(clr_none, compile_options, "Compile options:", "\n");
+ show_compile_options(clr_none, overall_options, "Overall options:", "\n");
}
}
if (extra_options != 0)
- show_compile_extra_options(clr_output, extra_options, "Extra options:", "\n");
+ show_compile_extra_options(clr_none, extra_options, "Extra options:", "\n");
if (compiled_code->optimization_flags != PCRE2_OPTIMIZATION_ALL)
- show_optimize_flags(compiled_code->optimization_flags, "Optimizations: ", "\n");
+ show_optimize_flags(clr_none, compiled_code->optimization_flags, "Optimizations: ", "\n");
- if (jchanged) cprintf(clr_output, "Duplicate name status changes\n");
+ if (jchanged) fprintf(outfile, "Duplicate name status changes\n");
if ((pat_patctl.control2 & CTL2_BSR_SET) != 0 ||
(compiled_code->flags & PCRE2_BSR_SET) != 0)
- cprintf(clr_output, "\\R matches %s\n", (bsr_convention == PCRE2_BSR_UNICODE)?
+ fprintf(outfile, "\\R matches %s\n", (bsr_convention == PCRE2_BSR_UNICODE)?
"any Unicode newline" : "CR, LF, or CRLF");
if ((compiled_code->flags & PCRE2_NL_SET) != 0)
@@ -1505,27 +1496,27 @@ if ((pat_patctl.control & CTL_INFO) != 0)
switch (newline_convention)
{
case PCRE2_NEWLINE_CR:
- cprintf(clr_output, "Forced newline is CR\n");
+ fprintf(outfile, "Forced newline is CR\n");
break;
case PCRE2_NEWLINE_LF:
- cprintf(clr_output, "Forced newline is LF\n");
+ fprintf(outfile, "Forced newline is LF\n");
break;
case PCRE2_NEWLINE_CRLF:
- cprintf(clr_output, "Forced newline is CRLF\n");
+ fprintf(outfile, "Forced newline is CRLF\n");
break;
case PCRE2_NEWLINE_ANYCRLF:
- cprintf(clr_output, "Forced newline is CR, LF, or CRLF\n");
+ fprintf(outfile, "Forced newline is CR, LF, or CRLF\n");
break;
case PCRE2_NEWLINE_ANY:
- cprintf(clr_output, "Forced newline is any Unicode newline\n");
+ fprintf(outfile, "Forced newline is any Unicode newline\n");
break;
case PCRE2_NEWLINE_NUL:
- cprintf(clr_output, "Forced newline is NUL\n");
+ fprintf(outfile, "Forced newline is NUL\n");
break;
default:
@@ -1535,7 +1526,7 @@ if ((pat_patctl.control & CTL_INFO) != 0)
if (first_ctype == 2)
{
- cprintf(clr_output, "First code unit at start or follows newline\n");
+ fprintf(outfile, "First code unit at start or follows newline\n");
}
else if (first_ctype == 1)
{
@@ -1543,23 +1534,23 @@ if ((pat_patctl.control & CTL_INFO) != 0)
((compiled_code->flags & PCRE2_FIRSTCASELESS) == 0)?
"" : " (caseless)";
if (first_cunit != 0xff && PRINTABLE(first_cunit))
- cprintf(clr_output, "First code unit = \'%c\'%s\n", CHAR_OUTPUT(first_cunit),
+ fprintf(outfile, "First code unit = \'%c\'%s\n", CHAR_OUTPUT(first_cunit),
caseless);
else
{
- cprintf(clr_output, "First code unit = ");
+ fprintf(outfile, "First code unit = ");
if (first_cunit == 0xff)
- cprintf(clr_output, "\\xff");
+ fprintf(outfile, "\\xff");
else
- pchar(clr_output, first_cunit, FALSE, outfile);
- cprintf(clr_output, "%s\n", caseless);
+ pchar(first_cunit, FALSE, outfile);
+ fprintf(outfile, "%s\n", caseless);
}
}
else if (start_bits != NULL)
{
int input;
int c = 24;
- cprintf(clr_output, "Starting code units:");
+ fprintf(outfile, "Starting code units:");
for (input = 0; input < 256; input++)
{
int i = CHAR_INPUT_HEX(input);
@@ -1567,22 +1558,22 @@ if ((pat_patctl.control & CTL_INFO) != 0)
{
if (c > 75)
{
- cprintf(clr_output, "\n ");
+ fprintf(outfile, "\n ");
c = 2;
}
if (PRINTABLE(i) && i != CHAR_SPACE)
{
- cprintf(clr_output, " %c", CHAR_OUTPUT(i));
+ fprintf(outfile, " %c", CHAR_OUTPUT(i));
c += 2;
}
else
{
- cprintf(clr_output, " \\x%02x", CHAR_OUTPUT_HEX(i));
+ fprintf(outfile, " \\x%02x", CHAR_OUTPUT_HEX(i));
c += 5;
}
}
}
- cprintf(clr_output, "\n");
+ fprintf(outfile, "\n");
}
if (last_ctype != 0)
@@ -1591,33 +1582,33 @@ if ((pat_patctl.control & CTL_INFO) != 0)
((compiled_code->flags & PCRE2_LASTCASELESS) == 0)?
"" : " (caseless)";
if (PRINTABLE(last_cunit))
- cprintf(clr_output, "Last code unit = \'%c\'%s\n", CHAR_OUTPUT(last_cunit),
+ fprintf(outfile, "Last code unit = \'%c\'%s\n", CHAR_OUTPUT(last_cunit),
caseless);
else
{
- cprintf(clr_output, "Last code unit = ");
- pchar(clr_output, last_cunit, FALSE, outfile);
- cprintf(clr_output, "%s\n", caseless);
+ fprintf(outfile, "Last code unit = ");
+ pchar(last_cunit, FALSE, outfile);
+ fprintf(outfile, "%s\n", caseless);
}
}
if ((compiled_code->optimization_flags & PCRE2_OPTIM_START_OPTIMIZE) != 0)
- cprintf(clr_output, "Subject length lower bound = %d\n", minlength);
+ fprintf(outfile, "Subject length lower bound = %d\n", minlength);
if (pat_patctl.jit != 0 && (pat_patctl.control & CTL_JITVERIFY) != 0)
{
#ifdef SUPPORT_JIT
if (compiled_code->executable_jit != NULL)
- cprintf(clr_output, "JIT compilation was successful\n");
+ fprintf(outfile, "JIT compilation was successful\n");
else
{
- cprintf(clr_api_error, "JIT compilation was not successful");
+ cfprintf(clr_api_error, outfile, "JIT compilation was not successful");
if (jitrc != 0 && !print_error_message(jitrc, " (", ")"))
return PR_ABEND;
- cprintf(clr_api_error, "\n");
+ fprintf(outfile, "\n");
}
#else
- cprintf(clr_api_error, "JIT support is not available in this version of PCRE2\n");
+ cfprintf(clr_api_error, outfile, "JIT support is not available in this version of PCRE2\n");
#endif
}
}
@@ -1629,7 +1620,7 @@ rc = pcre2_callout_enumerate(compiled_code,
callout_enumerate_function_void, NULL);
if (rc != 0)
{
- cprintf(clr_test_error, "Callout enumerate failed: error %d: ", rc);
+ cfprintf(clr_api_error, outfile, "Callout enumerate failed: error %d: ", rc);
if (rc < 0 && !print_error_message(rc, "", "\n"))
return PR_ABEND;
return PR_SKIP;
@@ -1656,7 +1647,7 @@ Returns: FALSE if print_error_message() fails
static BOOL
serial_error(int rc, const char *msg)
{
-cprintf(clr_api_error, "%s failed: error %d: ", msg, rc);
+cfprintf(clr_api_error, outfile, "%s failed: error %d: ", msg, rc);
return print_error_message(rc, "", "\n");
}
@@ -1714,14 +1705,14 @@ argptr = buffer + cmdlen + 1;
if (restrict_for_perl_test && cmd != CMD_PATTERN && cmd != CMD_SUBJECT &&
cmd != CMD_IF && cmd != CMD_ENDIF)
{
- cprintf(clr_test_error, "** #%s is not allowed after #perltest\n", cmdname);
+ cfprintf(clr_test_error, outfile, "** #%s is not allowed after #perltest\n", cmdname);
return PR_ABEND;
}
switch(cmd)
{
case CMD_UNKNOWN:
- cprintf(clr_test_error, "** Unknown command: %s", buffer);
+ cfprintf(clr_test_error, outfile, "** Unknown command: %s", buffer);
break;
case CMD_FORBID_UTF:
@@ -1779,7 +1770,7 @@ switch(cmd)
case CMD_POPCOPY:
if (patstacknext <= 0)
{
- cprintf(clr_test_error, "** Can't pop off an empty stack\n");
+ cfprintf(clr_test_error, outfile, "** Can't pop off an empty stack\n");
return PR_SKIP;
}
memset(&pat_patctl, 0, sizeof(patctl)); /* Completely unset */
@@ -1809,7 +1800,7 @@ switch(cmd)
case CMD_SAVE:
if (patstacknext <= 0)
{
- cprintf(clr_test_error, "** No stacked patterns to save\n");
+ cfprintf(clr_test_error, outfile, "** No stacked patterns to save\n");
return PR_OK;
}
@@ -1834,7 +1825,7 @@ switch(cmd)
for (i = 0; i < 4; i++) fputc((serial_size >> (i*8)) & 255, f);
if (fwrite(serial, 1, serial_size, f) != serial_size)
{
- cprintf(clr_test_error, "** Wrong return from fwrite()\n");
+ cfprintf(clr_test_error, outfile, "** Wrong return from fwrite()\n");
fclose(f);
return PR_ABEND;
}
@@ -1861,7 +1852,7 @@ switch(cmd)
serial = malloc(serial_size);
if (serial == NULL)
{
- cprintf(clr_test_error, "** Failed to get memory (size %" SIZ_FORM ") for #load\n",
+ cfprintf(clr_test_error, outfile, "** Failed to get memory (size %" SIZ_FORM ") for #load\n",
serial_size);
fclose(f);
return PR_ABEND;
@@ -1872,7 +1863,7 @@ switch(cmd)
if (i != serial_size)
{
- cprintf(clr_test_error, "** Wrong return from fread()\n");
+ cfprintf(clr_test_error, outfile, "** Wrong return from fread()\n");
yield = PR_ABEND;
}
else
@@ -1886,10 +1877,10 @@ switch(cmd)
{
if (rc + patstacknext > PATSTACKSIZE)
{
- cprintf(clr_test_error, "** Not enough space on pattern stack for %d pattern%s\n",
+ cfprintf(clr_test_error, outfile, "** Not enough space on pattern stack for %d pattern%s\n",
rc, (rc == 1)? "" : "s");
rc = PATSTACKSIZE - patstacknext;
- cprintf(clr_test_error, "** Decoding %d pattern%s\n", rc,
+ cfprintf(clr_test_error, outfile, "** Decoding %d pattern%s\n", rc,
(rc == 1)? "" : "s");
}
rc = pcre2_serialize_decode(patstack + patstacknext, rc, serial,
@@ -1920,12 +1911,12 @@ switch(cmd)
if (tables3 == NULL)
{
- cprintf(clr_test_error, "** Failed: malloc/config for #loadtables\n");
+ cfprintf(clr_test_error, outfile, "** Failed: malloc/config for #loadtables\n");
yield = PR_ABEND;
}
else if (fread(tables3, 1, loadtables_length, f) != loadtables_length)
{
- cprintf(clr_test_error, "** Wrong return from fread()\n");
+ cfprintf(clr_test_error, outfile, "** Wrong return from fread()\n");
yield = PR_ABEND;
}
@@ -1935,7 +1926,7 @@ switch(cmd)
case CMD_IF:
if (inside_if)
{
- cprintf(clr_test_error, "** Nested #if not supported\n");
+ cfprintf(clr_test_error, outfile, "** Nested #if not supported\n");
return PR_ABEND;
}
@@ -1962,7 +1953,7 @@ switch(cmd)
}
if (i == COPTLISTCOUNT)
{
- cprintf(clr_test_error, "** Unknown condition: %s\n", buffer);
+ cfprintf(clr_test_error, outfile, "** Unknown condition: %s\n", buffer);
return PR_ABEND;
}
@@ -1976,7 +1967,7 @@ switch(cmd)
case CMD_ENDIF:
if (!inside_if)
{
- cprintf(clr_test_error, "** Unexpected #endif\n");
+ cfprintf(clr_test_error, outfile, "** Unexpected #endif\n");
return PR_ABEND;
}
inside_if = FALSE;
@@ -2023,7 +2014,7 @@ PCRE2_SIZE erroroffset;
if (restrict_for_perl_test && delimiter != '/')
{
- cprintf(clr_test_error, "** The only allowed delimiter after #perltest is '/'\n");
+ cfprintf(clr_test_error, outfile, "** The only allowed delimiter after #perltest is '/'\n");
return PR_ABEND;
}
@@ -2044,12 +2035,12 @@ for(;;)
p++;
}
if (*p != 0) break;
- if ((p = extend_inputline(infile, p, PROMPT(" > "))) == NULL)
+ if ((p = extend_inputline(infile, p, " > ")) == NULL)
{
- cprintf(clr_test_error, "** Unexpected EOF\n");
+ cfprintf(clr_test_error, outfile, "** Unexpected EOF\n");
return PR_ABEND;
}
- if (!INTERACTIVE(infile)) cprintf(clr_test_error, "%s", (char *)p);
+ if (!INTERACTIVE(infile)) cfprintf(clr_input, outfile, "%s", (char *)p);
}
/* If the first character after the delimiter is backslash, make the pattern
@@ -2078,12 +2069,12 @@ exclusive with the utf modifier. */
if ((pat_patctl.control & CTL_UTF8_INPUT) != 0)
{
#if PCRE2_CODE_UNIT_WIDTH == 8
- cprintf(clr_test_error, "** The utf8_input modifier is not allowed in 8-bit mode\n");
+ cfprintf(clr_test_error, outfile, "** The utf8_input modifier is not allowed in 8-bit mode\n");
return PR_SKIP;
#else
if (utf)
{
- cprintf(clr_test_error, "** The utf and utf8_input modifiers are mutually exclusive\n");
+ cfprintf(clr_test_error, outfile, "** The utf and utf8_input modifiers are mutually exclusive\n");
return PR_SKIP;
}
#endif
@@ -2094,7 +2085,7 @@ if ((pat_patctl.control & CTL_UTF8_INPUT) != 0)
if (pat_patctl.convert_type != CONVERT_UNSET &&
(pat_patctl.control & CTL_POSIX) != 0)
{
- cprintf(clr_test_error, "** The convert and posix modifiers are mutually exclusive\n");
+ cfprintf(clr_test_error, outfile, "** The convert and posix modifiers are mutually exclusive\n");
return PR_SKIP;
}
@@ -2107,7 +2098,7 @@ for (k = 0; k < sizeof(exclusive_pat_controls)/sizeof(uint32_t); k++)
if (c != 0 && c != (c & (~c+1)))
{
show_controls(clr_test_error, c, 0, "** Not allowed together:");
- cprintf(clr_test_error, "\n");
+ fprintf(outfile, "\n");
return PR_SKIP;
}
}
@@ -2145,7 +2136,7 @@ if ((pat_patctl.control & CTL_HEXPAT) != 0)
d = *pp;
if (d == 0)
{
- cprintf(clr_test_error, "** Missing closing quote in hex pattern: "
+ cfprintf(clr_test_error, outfile, "** Missing closing quote in hex pattern: "
"opening quote is at offset %" PTR_FORM ".\n", pq - buffer - 2);
return PR_SKIP;
}
@@ -2160,19 +2151,19 @@ if ((pat_patctl.control & CTL_HEXPAT) != 0)
{
if (!isxdigit(c))
{
- cprintf(clr_test_error, "** Unexpected non-hex-digit '%c' at offset %"
+ cfprintf(clr_test_error, outfile, "** Unexpected non-hex-digit '%c' at offset %"
PTR_FORM " in hex pattern: quote missing?\n", c, pp - buffer - 2);
return PR_SKIP;
}
if (*pp == 0)
{
- cprintf(clr_test_error, "** Odd number of digits in hex pattern\n");
+ cfprintf(clr_test_error, outfile, "** Odd number of digits in hex pattern\n");
return PR_SKIP;
}
d = *pp;
if (!isxdigit(d))
{
- cprintf(clr_test_error, "** Unexpected non-hex-digit '%c' at offset %"
+ cfprintf(clr_test_error, outfile, "** Unexpected non-hex-digit '%c' at offset %"
PTR_FORM " in hex pattern: quote missing?\n", d, pp - buffer - 1);
return PR_SKIP;
}
@@ -2219,7 +2210,7 @@ else if ((pat_patctl.control & CTL_EXPAND) != 0)
uli = strtoul((const char *)pe, &endptr, 10);
if (U32OVERFLOW(uli))
{
- cprintf(clr_test_error, "** Pattern repeat count too large\n");
+ cfprintf(clr_test_error, outfile, "** Pattern repeat count too large\n");
return PR_SKIP;
}
@@ -2229,7 +2220,7 @@ else if ((pat_patctl.control & CTL_EXPAND) != 0)
{
if (i == 0)
{
- cprintf(clr_test_error, "** Zero repeat not allowed\n");
+ cfprintf(clr_test_error, outfile, "** Zero repeat not allowed\n");
return PR_SKIP;
}
pc += 2;
@@ -2268,7 +2259,7 @@ else if ((pat_patctl.control & CTL_EXPAND) != 0)
patlen = pt - pbuffer8;
if ((pat_patctl.control & CTL_INFO) != 0)
- cprintf(clr_output, "Expanded: %s\n", pbuffer8);
+ fprintf(outfile, "Expanded: %s\n", pbuffer8);
}
/* Neither hex nor expanded, just copy the input verbatim. */
@@ -2284,12 +2275,12 @@ if (pat_patctl.locale[0] != 0)
{
if (pat_patctl.tables_id != 0)
{
- cprintf(clr_test_error, "** 'Locale' and 'tables' must not both be set\n");
+ cfprintf(clr_test_error, outfile, "** 'Locale' and 'tables' must not both be set\n");
return PR_SKIP;
}
if (setlocale(LC_CTYPE, (const char *)pat_patctl.locale) == NULL)
{
- cprintf(clr_test_error, "** Failed to set locale \"%s\"\n", pat_patctl.locale);
+ cfprintf(clr_test_error, outfile, "** Failed to set locale \"%s\"\n", pat_patctl.locale);
return PR_SKIP;
}
if (strcmp((const char *)pat_patctl.locale, (const char *)locale_name) != 0)
@@ -2313,7 +2304,7 @@ else switch (pat_patctl.tables_id)
case 3:
if (tables3 == NULL)
{
- cprintf(clr_test_error, "** 'Tables = 3' is invalid: binary tables have not "
+ cfprintf(clr_test_error, outfile, "** 'Tables = 3' is invalid: binary tables have not "
"been loaded\n");
return PR_SKIP;
}
@@ -2321,7 +2312,7 @@ else switch (pat_patctl.tables_id)
break;
default:
- cprintf(clr_test_error, "** 'Tables' must specify 0, 1, 2, or 3.\n");
+ cfprintf(clr_test_error, outfile, "** 'Tables' must specify 0, 1, 2, or 3.\n");
return PR_SKIP;
}
@@ -2341,7 +2332,7 @@ local character tables. Neither does it have 16-bit or 32-bit support. */
if ((pat_patctl.control & CTL_POSIX) != 0)
{
#if PCRE2_CODE_UNIT_WIDTH != 8
- cprintf(clr_test_error, "** The POSIX interface is available only in 8-bit mode\n");
+ cfprintf(clr_test_error, outfile, "** The POSIX interface is available only in 8-bit mode\n");
return PR_SKIP;
#else
@@ -2361,8 +2352,8 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
{
show_compile_options(
clr_test_error,
- pat_patctl.options & (uint32_t)(~POSIX_SUPPORTED_COMPILE_OPTIONS),
- msg, "");
+ pat_patctl.options & (uint32_t)(~POSIX_SUPPORTED_COMPILE_OPTIONS),
+ msg, "");
msg = "";
}
@@ -2371,8 +2362,9 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
{
show_compile_extra_options(
clr_test_error,
- pat_context->extra_options &
- (uint32_t)(~POSIX_SUPPORTED_COMPILE_EXTRA_OPTIONS), msg, "");
+ pat_context->extra_options &
+ (uint32_t)(~POSIX_SUPPORTED_COMPILE_EXTRA_OPTIONS),
+ msg, "");
msg = "";
}
@@ -2401,7 +2393,7 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
if (pat_context->parens_nest_limit != PARENS_NEST_DEFAULT)
prmsg(&msg, "parens_nest_limit");
- if (msg[0] == 0) cprintf(clr_test_error, "\n");
+ if (msg[0] == 0) fprintf(outfile, "\n");
/* Translate PCRE2 options to POSIX options and then compile. */
@@ -2443,16 +2435,16 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
usize = regerror(rc, &preg, regbuffer, bsize);
strsize = ((usize > bsize)? bsize : usize) - 1;
- cprintf(clr_api_error, "Failed: POSIX code %d: ", rc);
+ cfprintf(clr_api_error, outfile, "Failed: POSIX code %d: ", rc);
if (bsize > 0) pchars(clr_api_error, (PCRE2_SPTR8)regbuffer, strsize, utf, outfile);
- cprintf(clr_api_error, "\n", outfile);
+ fputs("\n", outfile);
if (usize > bsize)
{
- cprintf(clr_test_error, "** regerror() message truncated\n");
+ cfprintf(clr_test_error, outfile, "** regerror() message truncated\n");
}
if (bsize > 0 && strlen(regbuffer) != strsize)
{
- cprintf(clr_test_error, "** regerror() strlen incorrect\n");
+ cfprintf(clr_test_error, outfile, "** regerror() strlen incorrect\n");
return PR_ABEND;
}
return PR_SKIP;
@@ -2471,7 +2463,7 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
preg.re_match_data == NULL ||
preg.re_cflags != cflags)
{
- cprintf(clr_test_error,
+ cfprintf(clr_test_error, outfile,
"** The regcomp() function returned zero (success), but the values set\n"
"** in the preg block are not valid for PCRE2. Check that pcre2test is\n"
"** linked with PCRE2's pcre2posix module (-lpcre2-posix) and not with\n"
@@ -2491,7 +2483,7 @@ if ((pat_patctl.control & (CTL_PUSH|CTL_PUSHCOPY|CTL_PUSHTABLESCOPY)) != 0)
{
if (pat_patctl.replacement[0] != 0)
{
- cprintf(clr_test_error, "** Replacement text is not supported with 'push'.\n");
+ cfprintf(clr_test_error, outfile, "** Replacement text is not supported with 'push'.\n");
return PR_OK;
}
if ((pat_patctl.control & ~PUSH_SUPPORTED_COMPILE_CONTROLS) != 0 ||
@@ -2500,7 +2492,7 @@ if ((pat_patctl.control & (CTL_PUSH|CTL_PUSHCOPY|CTL_PUSHTABLESCOPY)) != 0)
show_controls(clr_test_error, pat_patctl.control & ~PUSH_SUPPORTED_COMPILE_CONTROLS,
pat_patctl.control2 & ~PUSH_SUPPORTED_COMPILE_CONTROLS2,
"** Ignored when compiled pattern is stacked with 'push':");
- cprintf(clr_test_error, "\n");
+ fprintf(outfile, "\n");
}
if ((pat_patctl.control & PUSH_COMPILE_ONLY_CONTROLS) != 0 ||
(pat_patctl.control2 & PUSH_COMPILE_ONLY_CONTROLS2) != 0)
@@ -2508,7 +2500,7 @@ if ((pat_patctl.control & (CTL_PUSH|CTL_PUSHCOPY|CTL_PUSHTABLESCOPY)) != 0)
show_controls(clr_test_error, pat_patctl.control & PUSH_COMPILE_ONLY_CONTROLS,
pat_patctl.control2 & PUSH_COMPILE_ONLY_CONTROLS2,
"** Applies only to compile when pattern is stacked with 'push':");
- cprintf(clr_test_error, "\n");
+ fprintf(outfile, "\n");
}
}
@@ -2525,17 +2517,17 @@ errorcode = G(to,PCRE2_CODE_UNIT_WIDTH)(pbuffer8, utf, &patlen);
switch(errorcode)
{
case -1:
- cprintf(clr_test_error, "** Failed: invalid UTF-8 string cannot be "
+ cfprintf(clr_test_error, outfile, "** Failed: invalid UTF-8 string cannot be "
"converted to " STR(PCRE2_CODE_UNIT_WIDTH) "-bit string\n");
return PR_SKIP;
case -2:
- cprintf(clr_test_error, "** Failed: character value greater than 0x10ffff "
+ cfprintf(clr_test_error, outfile, "** Failed: character value greater than 0x10ffff "
"cannot be converted to UTF\n");
return PR_SKIP;
case -3:
- cprintf(clr_test_error, "** Failed: character value greater than 0xffff "
+ cfprintf(clr_test_error, outfile, "** Failed: character value greater than 0xffff "
"cannot be converted to 16-bit in non-UTF mode\n");
return PR_SKIP;
@@ -2571,7 +2563,7 @@ if (pat_patctl.convert_type != CONVERT_UNSET)
converted_pattern = malloc(CU2BYTES(converted_length));
if (converted_pattern == NULL)
{
- cprintf(clr_test_error, "** Failed: malloc failed for converted pattern\n");
+ cfprintf(clr_test_error, outfile, "** Failed: malloc failed for converted pattern\n");
return PR_SKIP;
}
}
@@ -2590,7 +2582,7 @@ if (pat_patctl.convert_type != CONVERT_UNSET)
rc = pcre2_set_glob_escape(con_context, CHAR_INPUT(escape));
if (rc != 0)
{
- cprintf(clr_api_error, "** Invalid glob escape '%c'\n",
+ cfprintf(clr_test_error, outfile, "** Invalid glob escape '%c'\n",
pat_patctl.convert_glob_escape);
convert_return = PR_SKIP;
goto CONVERT_FINISH;
@@ -2603,7 +2595,7 @@ if (pat_patctl.convert_type != CONVERT_UNSET)
rc = pcre2_set_glob_separator(con_context, CHAR_INPUT(separator));
if (rc != 0)
{
- cprintf(clr_api_error, "** Invalid glob separator '%c'\n",
+ cfprintf(clr_test_error, outfile, "** Invalid glob separator '%c'\n",
pat_patctl.convert_glob_separator);
convert_return = PR_SKIP;
goto CONVERT_FINISH;
@@ -2615,7 +2607,7 @@ if (pat_patctl.convert_type != CONVERT_UNSET)
if (rc != 0)
{
- cprintf(clr_api_error, "** Pattern conversion error at offset %" SIZ_FORM ": ",
+ cfprintf(clr_api_error, outfile, "** Pattern conversion error at offset %" SIZ_FORM ": ",
converted_length);
convert_return = print_error_message(rc, "", "\n")? PR_SKIP:PR_ABEND;
}
@@ -2624,15 +2616,15 @@ if (pat_patctl.convert_type != CONVERT_UNSET)
else
{
- pchars(clr_output, converted_pattern, converted_length, utf, outfile);
- cprintf(clr_output, "\n");
+ pchars(clr_none, converted_pattern, converted_length, utf, outfile);
+ fprintf(outfile, "\n");
if (CU2BYTES(converted_length + 1) > pbuffer_size)
{
// TODO This seems... unfortunate? There must be some patterns that can
// expand when converted from glob to regex, but we aren't allowing for
// that here. Presumably we should expand the buffer rather than moan.
- cprintf(clr_api_error, "** Pattern conversion is too long for the buffer\n");
+ cfprintf(clr_test_error, outfile, "** Pattern conversion is too long for the buffer\n");
convert_return = PR_SKIP;
}
else
@@ -2718,7 +2710,7 @@ if (timeit > 0)
pcre2_code_free(compiled_code);
}
total_compile_time += time_taken;
- cprintf(clr_profiling, "Compile time %8.4f microseconds\n",
+ cfprintf(clr_profiling, outfile, "Compile time %8.4f microseconds\n",
((1000000 / CLOCKS_PER_SEC) * (double)time_taken) / timeit);
}
@@ -2747,7 +2739,7 @@ if (malloc_testing)
if (i < target_mallocs &&
!(compiled_code == NULL && errorcode == PCRE2_ERROR_HEAP_FAILED))
{
- cprintf(clr_test_error, "** malloc() compile test did not fail as expected (%d)\n",
+ cfprintf(clr_test_error, outfile, "** malloc() compile test did not fail as expected (%d)\n",
errorcode);
return PR_ABEND;
}
@@ -2786,20 +2778,20 @@ if (compiled_code != NULL && pat_patctl.jit != 0)
use_pat_context);
if (compiled_code == NULL)
{
- cprintf(clr_test_error, "** Unexpected - pattern compilation not successful\n");
+ cfprintf(clr_test_error, outfile, "** Unexpected - pattern compilation not successful\n");
return PR_ABEND;
}
if (jitrc != 0)
{
- cprintf(clr_test_error, "JIT compilation was not successful");
+ cfprintf(clr_api_error, outfile, "JIT compilation was not successful");
if (!print_error_message(jitrc, " (", ")\n")) return PR_ABEND;
break;
}
}
total_jit_compile_time += time_taken;
if (jitrc == 0)
- cprintf(clr_profiling, "JIT compile %8.4f microseconds\n",
+ cfprintf(clr_profiling, outfile, "JIT compile %8.4f microseconds\n",
((1000000 / CLOCKS_PER_SEC) * (double)time_taken) / timeit);
}
@@ -2818,7 +2810,7 @@ if (compiled_code != NULL && pat_patctl.jit != 0)
use_pat_context);
if (compiled_code == NULL)
{
- cprintf(clr_test_error, "** Unexpected - pattern compilation not successful\n");
+ cfprintf(clr_test_error, outfile, "** Unexpected - pattern compilation not successful\n");
return PR_ABEND;
}
@@ -2828,7 +2820,7 @@ if (compiled_code != NULL && pat_patctl.jit != 0)
if (i < target_mallocs && jitrc != PCRE2_ERROR_NOMEMORY)
{
- cprintf(clr_test_error, "** malloc() JIT compile test did not fail as expected (%d)\n",
+ cfprintf(clr_test_error, outfile, "** malloc() JIT compile test did not fail as expected (%d)\n",
jitrc);
return PR_ABEND;
}
@@ -2840,7 +2832,7 @@ if (compiled_code != NULL && pat_patctl.jit != 0)
if (jitrc != 0 && (pat_patctl.control & CTL_JITVERIFY) != 0)
{
- cprintf(clr_test_error, "JIT compilation was not successful");
+ cfprintf(clr_api_error, outfile, "JIT compilation was not successful");
if (!print_error_message(jitrc, " (", ")\n")) return PR_ABEND;
}
}
@@ -2852,7 +2844,7 @@ if (compiled_code == NULL)
{
int direction = error_direction(errorcode, erroroffset);
- cprintf(clr_api_error, "Failed: error %d at offset %d: ", errorcode,
+ cfprintf(clr_api_error, outfile, "Failed: error %d at offset %d: ", errorcode,
(int)erroroffset);
if (!print_error_message(errorcode, "", "\n")) return PR_ABEND;
@@ -2871,7 +2863,7 @@ if (compiled_code == NULL)
n = utf_to_ord(q, q_end, &cc);
if (n <= 0)
{
- cprintf(clr_test_error, "** Erroroffset %d splits a UTF character\n", (int)erroroffset);
+ cfprintf(clr_test_error, outfile, "** Erroroffset %d splits a UTF character\n", (int)erroroffset);
return PR_ABEND;
}
}
@@ -2881,9 +2873,9 @@ if (compiled_code == NULL)
if (direction < 0)
{
- cprintf(clr_test_error, "** Error code %d not implemented in error_direction().\n", errorcode);
- cprintf(clr_test_error, " error_direction() should usually return '1' for newly-added errors,\n");
- cprintf(clr_test_error, " and the offset should be just to the right of the bad character.\n");
+ cfprintf(clr_test_error, outfile, "** Error code %d not implemented in error_direction().\n", errorcode);
+ cfprintf(clr_test_error, outfile, " error_direction() should usually return '1' for newly-added errors,\n");
+ cfprintf(clr_test_error, outfile, " and the offset should be just to the right of the bad character.\n");
return PR_ABEND;
}
@@ -2892,24 +2884,24 @@ if (compiled_code == NULL)
PCRE2_SIZE full_patlen = (patlen != PCRE2_ZERO_TERMINATED)? patlen :
pcre2_strlen(pbuffer);
- cprintf(clr_api_error, " here: ");
+ cfprintf(clr_api_error, outfile, " here: ");
if (erroroffset > 0)
{
- ptrunc(clr_api_error, pbuffer, full_patlen, erroroffset, TRUE, utf, outfile);
- cprintf(clr_api_error, " ");
+ ptrunc(clr_input, pbuffer, full_patlen, erroroffset, TRUE, utf, outfile);
+ fprintf(outfile, " ");
}
- cprintf(clr_api_error, (direction == 1)? "|<--|" : (direction == 2)? "|-->|" : "|<-->|");
+ cfprintf(clr_api_error, outfile, (direction == 1)? "|<--|" : (direction == 2)? "|-->|" : "|<-->|");
if (erroroffset < full_patlen)
{
- cprintf(clr_api_error, " ");
- ptrunc(clr_api_error, pbuffer, full_patlen, erroroffset, FALSE, utf, outfile);
+ fprintf(outfile, " ");
+ ptrunc(clr_input, pbuffer, full_patlen, erroroffset, FALSE, utf, outfile);
}
- cprintf(clr_api_error, "\n");
+ fprintf(outfile, "\n");
}
else if (erroroffset != 0)
{
- cprintf(clr_api_error, "** Unexpected non-zero erroroffset %d for error code %d\n",
+ cfprintf(clr_test_error, outfile, "** Unexpected non-zero erroroffset %d for error code %d\n",
(int)erroroffset, errorcode);
return PR_ABEND;
}
@@ -2925,7 +2917,7 @@ if (forbid_utf != 0)
{
if ((compiled_code->flags & PCRE2_HASBKPORX) != 0)
{
- cprintf(clr_test_error, "** \\P, \\p, and \\X are not allowed after the "
+ cfprintf(clr_test_error, outfile, "** \\P, \\p, and \\X are not allowed after the "
"#forbid_utf command\n");
return PR_SKIP;
}
@@ -2961,7 +2953,7 @@ if ((pat_patctl.control & CTL_PUSH) != 0)
{
if (patstacknext >= PATSTACKSIZE)
{
- cprintf(clr_test_error, "** Too many pushed patterns (max %d)\n", PATSTACKSIZE);
+ cfprintf(clr_test_error, outfile, "** Too many pushed patterns (max %d)\n", PATSTACKSIZE);
return PR_ABEND;
}
patstack[patstacknext++] = compiled_code;
@@ -2976,7 +2968,7 @@ if ((pat_patctl.control & (CTL_PUSHCOPY|CTL_PUSHTABLESCOPY)) != 0)
{
if (patstacknext >= PATSTACKSIZE)
{
- cprintf(clr_test_error, "** Too many pushed patterns (max %d)\n", PATSTACKSIZE);
+ cfprintf(clr_test_error, outfile, "** Too many pushed patterns (max %d)\n", PATSTACKSIZE);
return PR_ABEND;
}
if ((pat_patctl.control & CTL_PUSHCOPY) != 0)
@@ -3105,7 +3097,7 @@ for (;;)
{
if ((mid & 0x80000000u) != 0)
{
- cprintf(clr_api_error, "Can't find minimum %s limit: check pattern for "
+ cfprintf(clr_test_error, outfile, "** Can't find minimum %s limit: check pattern for "
"restriction\n", msg);
break;
}
@@ -3125,12 +3117,12 @@ for (;;)
if (errnumber == PCRE2_ERROR_HEAPLIMIT && mid < stack_start)
{
- cprintf(clr_output, "Minimum %s limit = 0\n", msg);
+ fprintf(outfile, "Minimum %s limit = 0\n", msg);
break;
}
if (mid == min + 1)
{
- cprintf(clr_output, "Minimum %s limit = %d\n", msg, mid);
+ fprintf(outfile, "Minimum %s limit = %d\n", msg, mid);
break;
}
max = mid;
@@ -3168,17 +3160,17 @@ BOOL utf = (compiled_code->overall_options & PCRE2_UTF) != 0;
if (outfile == NULL) goto YIELD;
-cprintf(clr_output, "%2d(%d) Old %" SIZ_FORM " %" SIZ_FORM " \"",
+fprintf(outfile, "%2d(%d) Old %" SIZ_FORM " %" SIZ_FORM " \"",
scb->subscount, scb->oveccount,
scb->ovector[0], scb->ovector[1]);
-pchars(clr_output, scb->input + scb->ovector[0], scb->ovector[1] - scb->ovector[0],
+pchars(clr_none, scb->input + scb->ovector[0], scb->ovector[1] - scb->ovector[0],
utf, outfile);
-cprintf(clr_output, "\" New %" SIZ_FORM " %" SIZ_FORM " \"",
+fprintf(outfile, "\" New %" SIZ_FORM " %" SIZ_FORM " \"",
scb->output_offsets[0], scb->output_offsets[1]);
-pchars(clr_output, scb->output + scb->output_offsets[0],
+pchars(clr_none, scb->output + scb->output_offsets[0],
scb->output_offsets[1] - scb->output_offsets[0], utf, outfile);
YIELD:
@@ -3186,15 +3178,15 @@ pchars(clr_output, scb->output + scb->output_offsets[0],
if (scb->subscount == dat_datctl.substitute_stop)
{
yield = -1;
- if (outfile != NULL) cprintf(clr_output, " STOPPED");
+ if (outfile != NULL) fprintf(outfile, " STOPPED");
}
else if (scb->subscount == dat_datctl.substitute_skip)
{
yield = +1;
- if (outfile != NULL) cprintf(clr_output, " SKIPPED");
+ if (outfile != NULL) fprintf(outfile, " SKIPPED");
}
-if (outfile != NULL) cprintf(clr_output, "\"\n");
+if (outfile != NULL) fprintf(outfile, "\"\n");
return yield;
}
@@ -3330,15 +3322,15 @@ if ((dat_datctl.control2 & CTL2_CALLOUT_EXTRA) != 0)
switch (cb->callout_flags)
{
case PCRE2_CALLOUT_BACKTRACK:
- cprintf_file(f, clr_output, "Backtrack\n");
+ fprintf(f, "Backtrack\n");
break;
case PCRE2_CALLOUT_STARTMATCH|PCRE2_CALLOUT_BACKTRACK:
- cprintf_file(f, clr_output, "Backtrack\nNo other matching paths\n");
+ fprintf(f, "Backtrack\nNo other matching paths\n");
PCRE2_FALLTHROUGH /* Fall through */
case PCRE2_CALLOUT_STARTMATCH:
- cprintf_file(f, clr_output, "New match attempt\n");
+ fprintf(f, "New match attempt\n");
break;
default:
@@ -3354,17 +3346,17 @@ isn't a tidy way to fit it in the rest of the data. */
if (cb->callout_string != NULL)
{
uint32_t delimiter = cb->callout_string[-1];
- cprintf(clr_output, "Callout (%" SIZ_FORM "): %c",
+ fprintf(outfile, "Callout (%" SIZ_FORM "): %c",
cb->callout_string_offset, CHAR_OUTPUT(delimiter));
- pchars(clr_output, cb->callout_string, cb->callout_string_length, utf, outfile);
+ pchars(clr_none, cb->callout_string, cb->callout_string_length, utf, outfile);
for (i = 0; callout_start_delims[i] != 0; i++)
if (delimiter == callout_start_delims[i])
{
delimiter = callout_end_delims[i];
break;
}
- cprintf(clr_output, "%c", CHAR_OUTPUT(delimiter));
- if (!callout_capture) cprintf(clr_output, "\n");
+ fprintf(outfile, "%c", CHAR_OUTPUT(delimiter));
+ if (!callout_capture) fprintf(outfile, "\n");
}
/* Show captured strings if required */
@@ -3372,19 +3364,19 @@ if (cb->callout_string != NULL)
if (callout_capture)
{
if (cb->callout_string == NULL)
- cprintf(clr_output, "Callout %d:", cb->callout_number);
- cprintf(clr_output, " last capture = %d\n", cb->capture_last);
+ fprintf(outfile, "Callout %d:", cb->callout_number);
+ fprintf(outfile, " last capture = %d\n", cb->capture_last);
for (i = 2; i < cb->capture_top * 2; i += 2)
{
- cprintf(clr_output, "%2d: ", i/2);
+ fprintf(outfile, "%2d: ", i/2);
if (cb->offset_vector[i] == PCRE2_UNSET)
- cprintf(clr_api_error, "");
+ fprintf(outfile, "");
else
{
- pchars(clr_output, cb->subject + cb->offset_vector[i],
+ pchars(clr_none, cb->subject + cb->offset_vector[i],
cb->offset_vector[i+1] - cb->offset_vector[i], utf, f);
}
- cprintf(clr_output, "\n");
+ fprintf(outfile, "\n");
}
}
@@ -3395,11 +3387,11 @@ lengths of the substrings. */
if (callout_where)
{
- if (f != NULL) cprintf_file(f, clr_output, "--->");
+ if (f != NULL) fprintf(f, "--->");
/* The subject before the match start. */
- pre_start = pchars(clr_output, cb->subject, cb->start_match, utf, f);
+ pre_start = pchars(clr_none, cb->subject, cb->start_match, utf, f);
/* If a lookbehind is involved, the current position may be earlier than the
match start. If so, use the match start instead. */
@@ -3409,19 +3401,19 @@ if (callout_where)
/* The subject between the match start and the current position. */
- post_start = pchars(clr_output, cb->subject + cb->start_match,
+ post_start = pchars(clr_none, cb->subject + cb->start_match,
current_position - cb->start_match, utf, f);
/* Print from the current position to the end. */
- pchars(clr_output, cb->subject + current_position, cb->subject_length - current_position,
+ pchars(clr_none, cb->subject + current_position, cb->subject_length - current_position,
utf, f);
/* Calculate the total subject printed length (no print). */
- subject_length = pchars(clr_unexpected, cb->subject, cb->subject_length, utf, NULL);
+ subject_length = pchars(clr_none, cb->subject, cb->subject_length, utf, NULL);
- if (f != NULL) cprintf(clr_output, "\n");
+ if (f != NULL) fprintf(f, "\n");
/* For automatic callouts, show the pattern offset. Otherwise, for a
numerical callout whose number has not already been shown with captured
@@ -3430,37 +3422,37 @@ if (callout_where)
if (cb->callout_number == 255)
{
- cprintf(clr_output, "%+3d ", (int)cb->pattern_position);
- if (cb->pattern_position > 99) cprintf(clr_output, "\n ");
+ fprintf(outfile, "%+3d ", (int)cb->pattern_position);
+ if (cb->pattern_position > 99) fprintf(outfile, "\n ");
}
else
{
- if (callout_capture || cb->callout_string != NULL) cprintf(clr_output, " ");
- else cprintf(clr_output, "%3d ", cb->callout_number);
+ if (callout_capture || cb->callout_string != NULL) fprintf(outfile, " ");
+ else fprintf(outfile, "%3d ", cb->callout_number);
}
/* Now show position indicators */
- for (i = 0; i < pre_start; i++) cprintf(clr_output, " ");
- cprintf(clr_output, "^");
+ for (i = 0; i < pre_start; i++) fprintf(outfile, " ");
+ fprintf(outfile, "^");
if (post_start > 0)
{
- for (i = 0; i < post_start - 1; i++) cprintf(clr_output, " ");
- cprintf(clr_output, "^");
+ for (i = 0; i < post_start - 1; i++) fprintf(outfile, " ");
+ fprintf(outfile, "^");
}
for (i = 0; i < subject_length - pre_start - post_start + 4; i++)
- cprintf(clr_output, " ");
+ fprintf(outfile, " ");
if (cb->next_item_length != 0)
{
- pchars(clr_output, pbuffer + cb->pattern_position, cb->next_item_length, utf, outfile);
+ pchars(clr_none, pbuffer + cb->pattern_position, cb->next_item_length, utf, outfile);
}
else
- cprintf(clr_output, "End of pattern");
+ fprintf(outfile, "End of pattern");
- cprintf(clr_output, "\n");
+ fprintf(outfile, "\n");
}
/* Show any mark info */
@@ -3468,14 +3460,12 @@ if (callout_where)
if (cb->mark != last_callout_mark)
{
if (cb->mark == NULL)
- {
- cprintf(clr_api_error, "Latest Mark: \n");
- }
+ fprintf(outfile, "Latest Mark: \n");
else
{
- cprintf(clr_output, "Latest Mark: ");
- pchars(clr_output, cb->mark - 1, -1, utf, outfile);
- cprintf(clr_output, "\n");
+ fprintf(outfile, "Latest Mark: ");
+ pchars(clr_none, cb->mark - 1, -1, utf, outfile);
+ putc('\n', outfile);
}
}
@@ -3494,7 +3484,7 @@ if (callout_data_ptr != NULL)
int callout_data = *((int32_t *)callout_data_ptr);
if (callout_data != 0)
{
- if (outfile != NULL) cprintf(clr_output, "Callout data = %d\n", callout_data);
+ if (outfile != NULL) fprintf(outfile, "Callout data = %d\n", callout_data);
return callout_data;
}
}
@@ -3547,24 +3537,24 @@ for (i = 0; i < MAXCPYGET && dat_datctl.copy_numbers[i] >= 0; i++)
rc = pcre2_substring_copy_bynumber(match_data, n, copybuffer, &length);
if (rc < 0)
{
- cprintf(clr_api_error, "Copy substring %d failed (%d): ", n, rc);
+ cfprintf(clr_api_error, outfile, "Copy substring %d failed (%d): ", n, rc);
if (!print_error_message(rc, "", "\n")) return FALSE;
}
else
{
- cprintf(clr_output, "%2dC ", n);
- pchars(clr_output, copybuffer, length, utf, outfile);
- cprintf(clr_output, " (%" SIZ_FORM ")\n", length);
+ fprintf(outfile, "%2dC ", n);
+ pchars(clr_none, copybuffer, length, utf, outfile);
+ fprintf(outfile, " (%" SIZ_FORM ")\n", length);
}
rc2 = pcre2_substring_length_bynumber(match_data, n, &length2);
if (rc2 < 0)
{
- cprintf(clr_api_error, "Get substring %d length failed (%d): ", n, rc2);
+ cfprintf(clr_api_error, outfile, "Get substring %d length failed (%d): ", n, rc2);
if (!print_error_message(rc2, "", "\n")) return FALSE;
}
else if (rc >= 0 && length2 != length)
{
- cprintf(clr_test_error, "Mismatched substring lengths: %"
+ cfprintf(clr_test_error, outfile, "** Mismatched substring lengths: %"
SIZ_FORM " %" SIZ_FORM "\n", length, length2);
}
}
@@ -3599,32 +3589,32 @@ for (;;)
groupnumber = pcre2_substring_number_from_name(compiled_code, pbuffer);
if (groupnumber < 0 && groupnumber != PCRE2_ERROR_NOUNIQUESUBSTRING)
- cprintf(clr_api_error, "Number not found for group \"%s\"\n", nptr);
+ cfprintf(clr_api_error, outfile, "Number not found for group \"%s\"\n", nptr);
length = sizeof(copybuffer)/sizeof(*copybuffer);
rc = pcre2_substring_copy_byname(match_data, pbuffer, copybuffer, &length);
if (rc < 0)
{
- cprintf(clr_api_error, "Copy substring \"%s\" failed (%d): ", nptr, rc);
+ cfprintf(clr_api_error, outfile, "Copy substring \"%s\" failed (%d): ", nptr, rc);
if (!print_error_message(rc, "", "\n")) return FALSE;
}
else
{
- cprintf(clr_output, " C ");
- pchars(clr_output, copybuffer, length, utf, outfile);
- cprintf(clr_output, " (%" SIZ_FORM ") %s", length, nptr);
- if (groupnumber >= 0) cprintf(clr_output, " (group %d)\n", groupnumber);
- else cprintf(clr_output, " (non-unique)\n");
+ fprintf(outfile, " C ");
+ pchars(clr_none, copybuffer, length, utf, outfile);
+ fprintf(outfile, " (%" SIZ_FORM ") %s", length, nptr);
+ if (groupnumber >= 0) fprintf(outfile, " (group %d)\n", groupnumber);
+ else fprintf(outfile, " (non-unique)\n");
}
rc2 = pcre2_substring_length_byname(match_data, pbuffer, &length2);
if (rc2 < 0)
{
- cprintf(clr_api_error, "Get substring \"%s\" length failed (%d): ", nptr, rc2);
+ cfprintf(clr_api_error, outfile, "Get substring \"%s\" length failed (%d): ", nptr, rc2);
if (!print_error_message(rc2, "", "\n")) return FALSE;
}
else if (rc >= 0 && length2 != length)
{
- cprintf(clr_test_error, "Mismatched substring lengths: %"
+ cfprintf(clr_test_error, outfile, "** Mismatched substring lengths: %"
SIZ_FORM " %" SIZ_FORM "\n", length, length2);
}
nptr += namelen + 1;
@@ -3641,14 +3631,14 @@ for (i = 0; i < MAXCPYGET && dat_datctl.get_numbers[i] >= 0; i++)
rc = pcre2_substring_get_bynumber(match_data, n, &gotbuffer, &length);
if (rc < 0)
{
- cprintf(clr_api_error, "Get substring %d failed (%d): ", n, rc);
+ cfprintf(clr_api_error, outfile, "Get substring %d failed (%d): ", n, rc);
if (!print_error_message(rc, "", "\n")) return FALSE;
}
else
{
- cprintf(clr_output, "%2dG ", n);
- pchars(clr_output, gotbuffer, length, utf, outfile);
- cprintf(clr_output, " (%" SIZ_FORM ")\n", length);
+ fprintf(outfile, "%2dG ", n);
+ pchars(clr_none, gotbuffer, length, utf, outfile);
+ fprintf(outfile, " (%" SIZ_FORM ")\n", length);
pcre2_substring_free(gotbuffer);
}
}
@@ -3683,21 +3673,21 @@ for (;;)
groupnumber = pcre2_substring_number_from_name(compiled_code, pbuffer);
if (groupnumber < 0 && groupnumber != PCRE2_ERROR_NOUNIQUESUBSTRING)
- cprintf(clr_api_error, "Number not found for group \"%s\"\n", nptr);
+ cfprintf(clr_api_error, outfile, "Number not found for group \"%s\"\n", nptr);
rc = pcre2_substring_get_byname(match_data, pbuffer, &gotbuffer, &length);
if (rc < 0)
{
- cprintf(clr_api_error, "Get substring \"%s\" failed (%d): ", nptr, rc);
+ cfprintf(clr_api_error, outfile, "Get substring \"%s\" failed (%d): ", nptr, rc);
if (!print_error_message(rc, "", "\n")) return FALSE;
}
else
{
- cprintf(clr_output, " G ");
- pchars(clr_output, gotbuffer, length, utf, outfile);
- cprintf(clr_output, " (%" SIZ_FORM ") %s", length, nptr);
- if (groupnumber >= 0) cprintf(clr_output, " (group %d)\n", groupnumber);
- else cprintf(clr_output, " (non-unique)\n");
+ fprintf(outfile, " G ");
+ pchars(clr_none, gotbuffer, length, utf, outfile);
+ fprintf(outfile, " (%" SIZ_FORM ") %s", length, nptr);
+ if (groupnumber >= 0) fprintf(outfile, " (group %d)\n", groupnumber);
+ else fprintf(outfile, " (non-unique)\n");
pcre2_substring_free(gotbuffer);
}
nptr += namelen + 1;
@@ -3713,19 +3703,19 @@ if ((dat_datctl.control & CTL_GETALL) != 0)
rc = pcre2_substring_list_get(match_data, &stringlist, &lengths);
if (rc < 0)
{
- cprintf(clr_api_error, "get substring list failed (%d): ", rc);
+ cfprintf(clr_api_error, outfile, "get substring list failed (%d): ", rc);
if (!print_error_message(rc, "", "\n")) return FALSE;
}
else
{
for (i = 0; i < capcount; i++)
{
- cprintf(clr_output, "%2dL ", i);
- pchars(clr_output, stringlist[i], lengths[i], utf, outfile);
- cprintf(clr_output, "\n");
+ fprintf(outfile, "%2dL ", i);
+ pchars(clr_none, stringlist[i], lengths[i], utf, outfile);
+ putc('\n', outfile);
}
if (stringlist[i] != NULL)
- cprintf(clr_test_error, "string list not terminated by NULL\n");
+ cfprintf(clr_test_error, outfile, "** string list not terminated by NULL\n");
pcre2_substring_list_free(stringlist);
}
}
@@ -3894,7 +3884,7 @@ if (utf)
n = utf8_to_ord(ptmp, ptmp_end, &cc);
if (n <= 0)
{
- cprintf(clr_test_error, "** Failed: invalid UTF-8 string cannot be used as input "
+ cfprintf(clr_test_error, outfile, "** Failed: invalid UTF-8 string cannot be used as input "
"in UTF mode\n");
return PR_OK;
}
@@ -3923,7 +3913,7 @@ if (dbuffer == NULL || needlen >= dbuffer_size)
dbuffer = (uint8_t *)realloc(dbuffer, dbuffer_size);
if (dbuffer == NULL)
{
- fatal_printf("pcre2test: realloc(%" SIZ_FORM ") failed\n", dbuffer_size);
+ cfprintf(clr_test_error, stderr, "pcre2test: realloc(%" SIZ_FORM ") failed\n", dbuffer_size);
exit(1);
}
}
@@ -3949,14 +3939,14 @@ while ((c = *p++) != 0)
if (*p++ != '{')
{
- cprintf(clr_test_error, "** Expected '{' after \\[....]\n");
+ cfprintf(clr_test_error, outfile, "** Expected '{' after \\[....]\n");
return PR_OK;
}
li = strtol((const char *)p, &endptr, 10);
if (S32OVERFLOW(li))
{
- cprintf(clr_test_error, "** Repeat count too large\n");
+ cfprintf(clr_test_error, outfile, "** Repeat count too large\n");
return PR_OK;
}
i = (int)li;
@@ -3964,20 +3954,20 @@ while ((c = *p++) != 0)
p = (uint8_t *)endptr;
if (*p++ != '}')
{
- cprintf(clr_test_error, "** Expected '}' after \\[...]{...\n");
+ cfprintf(clr_test_error, outfile, "** Expected '}' after \\[...]{...\n");
return PR_OK;
}
if (i-- <= 0)
{
- cprintf(clr_test_error, "** Zero or negative repeat not allowed\n");
+ cfprintf(clr_test_error, outfile, "** Zero or negative repeat not allowed\n");
return PR_OK;
}
replen = (uint8_t *)q - (uint8_t *)start_rep;
if (i > 0 && replen > (SIZE_MAX - needlen) / i)
{
- cprintf(clr_test_error, "** Expanded content too large\n");
+ cfprintf(clr_test_error, outfile, "** Expanded content too large\n");
return PR_OK;
}
needlen += replen * i;
@@ -3994,7 +3984,7 @@ while ((c = *p++) != 0)
dbuffer = (uint8_t *)realloc(dbuffer, dbuffer_size);
if (dbuffer == NULL)
{
- fatal_printf("pcre2test: realloc(%" SIZ_FORM ") failed\n",
+ cfprintf(clr_test_error, stderr, "pcre2test: realloc(%" SIZ_FORM ") failed\n",
dbuffer_size);
exit(1);
}
@@ -4074,7 +4064,7 @@ while ((c = *p++) != 0)
{
if (c >= 0x20000000u)
{
- cprintf(clr_test_error, "** \\o{ escape too large\n");
+ cfprintf(clr_test_error, outfile, "** \\o{ escape too large\n");
return PR_OK;
}
else c = c * 8 + (*pt - '0');
@@ -4082,7 +4072,7 @@ while ((c = *p++) != 0)
c = CHAR_OUTPUT(CHAR_INPUT_HEX(c));
if (i == 0 || *pt != '}')
{
- cprintf(clr_test_error, "** Malformed \\o{ escape\n");
+ cfprintf(clr_test_error, outfile, "** Malformed \\o{ escape\n");
return PR_OK;
}
else p = pt + 1;
@@ -4104,7 +4094,7 @@ while ((c = *p++) != 0)
{
if (++i == 9)
{
- cprintf(clr_test_error, "** Too many hex digits in \\x{...} item; "
+ cfprintf(clr_test_error, outfile, "** Too many hex digits in \\x{...} item; "
"using only the first eight.\n");
while (isxdigit(*pt)) pt++;
break;
@@ -4114,7 +4104,7 @@ while ((c = *p++) != 0)
c = CHAR_OUTPUT(CHAR_INPUT_HEX(c));
if (i == 0 || *pt != '}')
{
- cprintf(clr_test_error, "** Malformed \\x{ escape\n");
+ cfprintf(clr_test_error, outfile, "** Malformed \\x{ escape\n");
return PR_OK;
}
else p = pt + 1;
@@ -4157,7 +4147,7 @@ while ((c = *p++) != 0)
}
}
#endif
- cprintf(clr_test_error, "** Malformed \\N{U+ escape\n");
+ cfprintf(clr_test_error, outfile, "** Malformed \\N{U+ escape\n");
return PR_OK;
case 0: /* \ followed by EOF allows for an empty line */
@@ -4170,7 +4160,7 @@ while ((c = *p++) != 0)
case '[': /* \[ introduces a replicated character sequence */
if (start_rep != NULL)
{
- cprintf(clr_test_error, "** Nested replication is not supported\n");
+ cfprintf(clr_test_error, outfile, "** Nested replication is not supported\n");
return PR_OK;
}
start_rep = q;
@@ -4179,7 +4169,7 @@ while ((c = *p++) != 0)
default:
if (isalnum(c))
{
- cprintf(clr_test_error, "** Unrecognized escape sequence \"\\%c\"\n", c);
+ cfprintf(clr_test_error, outfile, "** Unrecognized escape sequence \"\\%c\"\n", c);
return PR_OK;
}
}
@@ -4193,9 +4183,9 @@ while ((c = *p++) != 0)
{
if (c > 0xffu)
{
- cprintf(clr_test_error, "** Character \\x{%x} is greater than 255 "
+ cfprintf(clr_test_error, outfile, "** Character \\x{%x} is greater than 255 "
"and UTF-8 mode is not enabled.\n", c);
- cprintf(clr_test_error, "** Truncation will probably give the wrong "
+ cfprintf(clr_test_error, outfile, "** Truncation will probably give the wrong "
"result.\n");
}
*q++ = (uint8_t)c;
@@ -4204,12 +4194,12 @@ while ((c = *p++) != 0)
{
if (c > 0x7fffffff)
{
- cprintf(clr_test_error, "** Character \\N{U+%x} is greater than 0x7fffffff "
+ cfprintf(clr_test_error, outfile, "** Character \\N{U+%x} is greater than 0x7fffffff "
"and therefore cannot be encoded as UTF-8\n", c);
return PR_OK;
}
else if (encoding == FORCE_UTF && c > MAX_UTF_CODE_POINT)
- cprintf(clr_test_error, "** Warning: character \\N{U+%x} is greater than "
+ cfprintf(clr_test_error, outfile, "** Warning: character \\N{U+%x} is greater than "
"0x%x and should not be encoded as UTF-8\n",
c, MAX_UTF_CODE_POINT);
q += ord_to_utf8(c, q);
@@ -4223,9 +4213,9 @@ while ((c = *p++) != 0)
{
if (c > 0xffffu)
{
- cprintf(clr_test_error, "** Character \\x{%x} is greater than 0xffff "
+ cfprintf(clr_test_error, outfile, "** Character \\x{%x} is greater than 0xffff "
"and UTF-16 mode is not enabled.\n", c);
- cprintf(clr_test_error, "** Truncation will probably give the wrong "
+ cfprintf(clr_test_error, outfile, "** Truncation will probably give the wrong "
"result.\n");
}
*q++ = (uint16_t)c;
@@ -4234,7 +4224,7 @@ while ((c = *p++) != 0)
{
if (c > MAX_UTF_CODE_POINT)
{
- cprintf(clr_test_error, "** Failed: character \\N{U+%x} is greater than "
+ cfprintf(clr_test_error, outfile, "** Failed: character \\N{U+%x} is greater than "
"0x%x and therefore cannot be encoded as UTF-16\n",
c, MAX_UTF_CODE_POINT);
return PR_OK;
@@ -4248,7 +4238,7 @@ while ((c = *p++) != 0)
else
{
if (encoding == FORCE_UTF && 0xe000u > c && c >= 0xd800u)
- cprintf(clr_test_error, "** Warning: character \\N{U+%x} is a surrogate "
+ cfprintf(clr_test_error, outfile, "** Warning: character \\N{U+%x} is a surrogate "
"and should not be encoded as UTF-16\n", c);
*q++ = c;
}
@@ -4256,7 +4246,7 @@ while ((c = *p++) != 0)
#endif
#if PCRE2_CODE_UNIT_WIDTH == 32
if (encoding == FORCE_UTF && c > MAX_UTF_CODE_POINT)
- cprintf(clr_test_error, "** Warning: character \\N{U+%x} is greater than "
+ cfprintf(clr_test_error, outfile, "** Warning: character \\N{U+%x} is greater than "
"0x%x and should not be encoded as UTF-32\n",
c, MAX_UTF_CODE_POINT);
*q++ = c;
@@ -4288,7 +4278,7 @@ for (k = 0; k < sizeof(exclusive_dat_controls)/sizeof(uint32_t); k++)
if (c != 0 && c != (c & (~c+1)))
{
show_controls(clr_test_error, c, 0, "** Not allowed together:");
- cprintf(clr_test_error, "\n");
+ fprintf(outfile, "\n");
return PR_OK;
}
}
@@ -4298,24 +4288,24 @@ if (dat_datctl.replacement[0] != 0)
if ((dat_datctl.control2 & CTL2_SUBSTITUTE_CALLOUT) != 0 &&
(dat_datctl.control & CTL_NULLCONTEXT) != 0)
{
- cprintf(clr_test_error, "** Replacement callouts are not supported with null_context.\n");
+ cfprintf(clr_test_error, outfile, "** Replacement callouts are not supported with null_context.\n");
return PR_OK;
}
if ((dat_datctl.control2 & CTL2_SUBSTITUTE_CASE_CALLOUT) != 0 &&
(dat_datctl.control & CTL_NULLCONTEXT) != 0)
{
- cprintf(clr_test_error, "** Replacement case callouts are not supported with null_context.\n");
+ cfprintf(clr_test_error, outfile, "** Replacement case callouts are not supported with null_context.\n");
return PR_OK;
}
if ((dat_datctl.control & CTL_ALLCAPTURES) != 0)
- cprintf(clr_test_error, "** Ignored with replacement text: allcaptures\n");
+ cfprintf(clr_test_error, outfile, "** Ignored with replacement text: allcaptures\n");
if (dat_datctl.substitute_subject[0] != 0 &&
(dat_datctl.control2 & CTL2_SUBSTITUTE_MATCHED) == 0)
{
- cprintf(clr_test_error, "** substitute_subject requires substitute_matched.\n");
+ cfprintf(clr_test_error, outfile, "** substitute_subject requires substitute_matched.\n");
return PR_OK;
}
}
@@ -4324,7 +4314,7 @@ else
{
if (dat_datctl.substitute_subject[0] != 0)
{
- cprintf(clr_test_error, "** substitute_subject requires replacement text.\n");
+ cfprintf(clr_test_error, outfile, "** substitute_subject requires replacement text.\n");
return PR_OK;
}
}
@@ -4334,9 +4324,9 @@ else
if ((dat_datctl.control & CTL_DFA) != 0)
{
if ((dat_datctl.control & CTL_ALLCAPTURES) != 0)
- cprintf(clr_test_error, "** Ignored for DFA matching: allcaptures\n");
+ cfprintf(clr_test_error, outfile, "** Ignored for DFA matching: allcaptures\n");
if ((dat_datctl.control2 & CTL2_HEAPFRAMES_SIZE) != 0)
- cprintf(clr_test_error, "** Ignored for DFA matching: heapframes_size\n");
+ cfprintf(clr_test_error, outfile, "** Ignored for DFA matching: heapframes_size\n");
}
/* We now have the subject in dbuffer, with len containing the byte length, and
@@ -4392,7 +4382,7 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
if ((dat_datctl.options & ~POSIX_SUPPORTED_MATCH_OPTIONS) != 0)
{
- cprintf(clr_test_error, "%s", msg);
+ cfprintf(clr_test_error, outfile, "%s", msg);
show_match_options(clr_test_error, dat_datctl.options & ~POSIX_SUPPORTED_MATCH_OPTIONS);
msg = "";
}
@@ -4405,14 +4395,14 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
msg = "";
}
- if (msg[0] == 0) cprintf(clr_test_error, "\n");
+ if (msg[0] == 0) fprintf(outfile, "\n");
if (dat_datctl.oveccount > 0)
{
pmatch = (regmatch_t *)malloc(sizeof(regmatch_t) * dat_datctl.oveccount);
if (pmatch == NULL)
{
- cprintf(clr_test_error, "** Failed to get memory for recording matching "
+ cfprintf(clr_test_error, outfile, "** Failed to get memory for recording matching "
"information (size set = %du)\n", dat_datctl.oveccount);
return PR_ABEND;
}
@@ -4435,14 +4425,14 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
if (rc != 0)
{
size_t usize = regerror(rc, &preg, (char *)pbuffer8, pbuffer8_size);
- cprintf(clr_api_error, "No match: POSIX code %d: ", rc);
+ cfprintf(clr_api_error, outfile, "No match: POSIX code %d: ", rc);
pchars(clr_api_error, (PCRE2_SPTR8)pbuffer8, usize - 1, utf, outfile);
- cprintf(clr_api_error, "\n");
+ fputs("\n", outfile);
}
else if ((pat_patctl.control & CTL_POSIX_NOSUB) != 0)
- cprintf(clr_output, "Matched with REG_NOSUB\n");
+ fprintf(outfile, "Matched with REG_NOSUB\n");
else if (dat_datctl.oveccount == 0)
- cprintf(clr_output, "Matched without capture\n");
+ fprintf(outfile, "Matched without capture\n");
else
{
size_t i, j;
@@ -4454,27 +4444,27 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
PCRE2_SIZE start = pmatch[i].rm_so;
PCRE2_SIZE end = pmatch[i].rm_eo;
for (j = last_printed + 1; j < i; j++)
- cprintf(clr_api_error, "%2d: \n", (int)j);
+ fprintf(outfile, "%2d: \n", (int)j);
last_printed = i;
if (start > end)
{
start = pmatch[i].rm_eo;
end = pmatch[i].rm_so;
- cprintf(clr_api_error, "Start of matched string is beyond its end - "
+ cfprintf(clr_api_error, outfile, "Start of matched string is beyond its end - "
"displaying from end to start.\n");
}
- cprintf(clr_output, "%2d: ", (int)i);
- pchars(clr_output, pp + start, end - start, utf, outfile);
- cprintf(clr_output, "\n");
+ fprintf(outfile, "%2d: ", (int)i);
+ pchars(clr_none, pp + start, end - start, utf, outfile);
+ fprintf(outfile, "\n");
if ((i == 0 && (dat_datctl.control & CTL_AFTERTEXT) != 0) ||
(dat_datctl.control & CTL_ALLAFTERTEXT) != 0)
{
- cprintf(clr_output, "%2d+ ", (int)i);
+ fprintf(outfile, "%2d+ ", (int)i);
/* Note: don't use the start/end variables here because we want to
show the text from what is reported as the end. */
- pchars(clr_output, pp + pmatch[i].rm_eo, len - pmatch[i].rm_eo, utf, outfile);
- cprintf(clr_output, "\n");
+ pchars(clr_none, pp + pmatch[i].rm_eo, len - pmatch[i].rm_eo, utf, outfile);
+ fprintf(outfile, "\n");
}
}
}
@@ -4488,7 +4478,7 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
modifiers. */
if (dat_datctl.startend[0] != CFORE_UNSET)
- cprintf(clr_test_error, "** \\=posix_startend ignored for non-POSIX matching\n");
+ cfprintf(clr_test_error, outfile, "** \\=posix_startend ignored for non-POSIX matching\n");
/* ALLUSEDTEXT is not supported with JIT, but JIT is not used with DFA
matching, even if the JIT compiler was used. */
@@ -4496,7 +4486,7 @@ matching, even if the JIT compiler was used. */
if ((dat_datctl.control & (CTL_ALLUSEDTEXT|CTL_DFA)) == CTL_ALLUSEDTEXT &&
compiled_code->executable_jit != NULL)
{
- cprintf(clr_test_error, "** Showing all consulted text is not supported by JIT: ignored\n");
+ cfprintf(clr_test_error, outfile, "** Showing all consulted text is not supported by JIT: ignored\n");
dat_datctl.control &= ~CTL_ALLUSEDTEXT;
}
@@ -4518,7 +4508,7 @@ show_memory = (dat_datctl.control & CTL_MEMORY) != 0;
if (show_memory &&
(pat_patctl.control & dat_datctl.control & CTL_NULLCONTEXT) != 0)
- cprintf(clr_test_error, "** \\=memory requires either a pattern or a subject "
+ cfprintf(clr_test_error, outfile, "** \\=memory requires either a pattern or a subject "
"context: ignored\n");
/* Create and assign a JIT stack if requested. */
@@ -4588,7 +4578,7 @@ else
if (match_data == NULL)
{
- cprintf(clr_test_error, "** Failed to get memory for recording matching "
+ cfprintf(clr_test_error, outfile, "** Failed to get memory for recording matching "
"information (size requested: %d)\n", dat_datctl.oveccount);
max_oveccount = 0;
return PR_ABEND;
@@ -4617,7 +4607,7 @@ if (dat_datctl.replacement[0] != 0 &&
(dat_datctl.control & CTL_DFA) != 0 &&
(dat_datctl.control2 & CTL2_SUBSTITUTE_MATCHED) == 0)
{
- cprintf(clr_test_error, "** Ignored for DFA matching: replace\n");
+ cfprintf(clr_test_error, outfile, "** Ignored for DFA matching: replace\n");
dat_datctl.replacement[0] = 0;
}
@@ -4646,10 +4636,10 @@ if (dat_datctl.replacement[0] != 0)
for (j = 0; j < 2*oveccount; j++) ovector[j] = JUNK_OFFSET;
if (timeitm)
- cprintf(clr_test_error, "** Timing is not supported with replace: ignored\n");
+ cfprintf(clr_test_error, outfile, "** Timing is not supported with replace: ignored\n");
if ((dat_datctl.control & CTL_ALTGLOBAL) != 0)
- cprintf(clr_test_error, "** Altglobal is not supported with replace: ignored\n");
+ cfprintf(clr_test_error, outfile, "** Altglobal is not supported with replace: ignored\n");
/* Check for a test that does substitution after an initial external match.
If this is set, we run the external match, but leave the interpretation of
@@ -4710,12 +4700,12 @@ if (dat_datctl.replacement[0] != 0)
while ((c = *(++pr)) >= '0' && c <= '9') n = n * 10 + (c - '0');
if (*pr++ != ']')
{
- cprintf(clr_test_error, "** Bad buffer size in replacement string\n");
+ cfprintf(clr_test_error, outfile, "** Bad buffer size in replacement string\n");
return PR_OK;
}
if (n > nsize)
{
- cprintf(clr_test_error, "** Replacement buffer setting (%" SIZ_FORM ") is too "
+ cfprintf(clr_test_error, outfile, "** Replacement buffer setting (%" SIZ_FORM ") is too "
"large (max %" SIZ_FORM ")\n", n, nsize);
return PR_OK;
}
@@ -4748,7 +4738,7 @@ if (dat_datctl.replacement[0] != 0)
the subject. */
if (slen > ulen)
{
- cprintf(clr_test_error, "** substitute_subject is longer than match subject buffer\n");
+ cfprintf(clr_test_error, outfile, "** substitute_subject is longer than match subject buffer\n");
return PR_OK;
}
@@ -4820,7 +4810,7 @@ if (dat_datctl.replacement[0] != 0)
if (i < target_mallocs && rc != PCRE2_ERROR_NOMEMORY)
{
- cprintf(clr_test_error, "** malloc() Substitution test did not fail as expected (%d)\n",
+ cfprintf(clr_test_error, outfile, "** malloc() Substitution test did not fail as expected (%d)\n",
rc);
return PR_ABEND;
}
@@ -4829,14 +4819,14 @@ if (dat_datctl.replacement[0] != 0)
if (rc < 0)
{
- cprintf(clr_api_error, "Failed: error %d", rc);
+ cfprintf(clr_api_error, outfile, "Failed: error %d", rc);
if (rc != PCRE2_ERROR_NOMEMORY && nsize != PCRE2_UNSET)
- cprintf(clr_api_error, " at offset %ld in replacement", (long int)nsize);
- cprintf(clr_api_error, ": ");
+ cfprintf(clr_api_error, outfile, " at offset %ld in replacement", (long int)nsize);
+ cfprintf(clr_api_error, outfile, ": ");
if (!print_error_message(rc, "", "")) return PR_ABEND;
if (rc == PCRE2_ERROR_NOMEMORY &&
(xoptions & PCRE2_SUBSTITUTE_OVERFLOW_LENGTH) != 0)
- cprintf(clr_api_error, ": %ld code units are needed", (long int)nsize);
+ cfprintf(clr_api_error, outfile, ": %ld code units are needed", (long int)nsize);
if (rc != PCRE2_ERROR_NOMEMORY && nsize != PCRE2_UNSET)
{
@@ -4846,27 +4836,27 @@ if (dat_datctl.replacement[0] != 0)
PCRE2_SIZE full_rlen = (rlen != PCRE2_ZERO_TERMINATED)? rlen :
pcre2_strlen(rbptr);
- cprintf(clr_api_error, "\n here: ");
+ cfprintf(clr_api_error, outfile, "\n here: ");
if (nsize > 0)
{
- ptrunc(clr_api_error, rbptr, full_rlen, nsize, TRUE, utf, outfile);
- cprintf(clr_api_error, " ");
+ ptrunc(clr_input, rbptr, full_rlen, nsize, TRUE, utf, outfile);
+ fprintf(outfile, " ");
}
- cprintf(clr_api_error, "|<--|");
+ cfprintf(clr_api_error, outfile, "|<--|");
if (nsize < full_rlen)
{
- cprintf(clr_api_error, " ");
- ptrunc(clr_api_error, rbptr, full_rlen, nsize, FALSE, utf, outfile);
+ fprintf(outfile, " ");
+ ptrunc(clr_input, rbptr, full_rlen, nsize, FALSE, utf, outfile);
}
}
}
else
{
- cprintf(clr_api_error, "%2d: ", rc);
+ cfprintf(clr_api_error, outfile, "%2d: ", rc);
pchars(clr_api_error, nbuffer, nsize, utf, outfile);
}
- cprintf(clr_output, "\n");
+ fprintf(outfile, "\n");
show_memory = FALSE;
/* Show final ovector contents and resulting heapframe size if requested. */
@@ -4914,7 +4904,7 @@ for (gmatched = 0;; gmatched++)
if ((dat_datctl.options & PCRE2_DFA_RESTART) != 0)
{
outfile = saved_outfile;
- cprintf(clr_test_error, "** Timing DFA restarts is not supported\n");
+ cfprintf(clr_test_error, outfile, "** Timing DFA restarts is not supported\n");
return PR_ABEND;
}
if (dfa_workspace == NULL)
@@ -4952,7 +4942,7 @@ for (gmatched = 0;; gmatched++)
total_match_time += (time_taken = clock() - start_time);
outfile = saved_outfile;
- cprintf(clr_profiling, "Match time %7.4f microseconds\n",
+ cfprintf(clr_profiling, outfile, "Match time %7.4f microseconds\n",
((1000000 / CLOCKS_PER_SEC) * (double)time_taken) / timeitm);
}
@@ -4982,7 +4972,7 @@ for (gmatched = 0;; gmatched++)
if (capcount == 0)
{
- cprintf(clr_test_error, "Matched, but offsets vector is too small to show all matches\n");
+ cfprintf(clr_api_error, outfile, "Matched, but offsets vector is too small to show all matches\n");
capcount = dat_datctl.oveccount;
}
}
@@ -5006,7 +4996,7 @@ for (gmatched = 0;; gmatched++)
use_dat_context, dfa_workspace, DFA_WS_DIMENSION);
if (capcount == 0)
{
- cprintf(clr_test_error, "Matched, but offsets vector is too small to show all matches\n");
+ cfprintf(clr_api_error, outfile, "Matched, but offsets vector is too small to show all matches\n");
capcount = dat_datctl.oveccount;
}
}
@@ -5020,7 +5010,7 @@ for (gmatched = 0;; gmatched++)
dat_datctl.options | g_notempty, match_data, use_dat_context);
if (capcount == 0)
{
- cprintf(clr_test_error, "Matched, but too many substrings\n");
+ cfprintf(clr_api_error, outfile, "Matched, but too many substrings\n");
capcount = dat_datctl.oveccount;
}
}
@@ -5065,7 +5055,7 @@ for (gmatched = 0;; gmatched++)
if (i < target_mallocs && capcount != PCRE2_ERROR_NOMEMORY)
{
- cprintf(clr_test_error, "** malloc() match test did not fail as expected (%d)\n",
+ cfprintf(clr_test_error, outfile, "** malloc() match test did not fail as expected (%d)\n",
capcount);
return PR_ABEND;
}
@@ -5083,7 +5073,7 @@ for (gmatched = 0;; gmatched++)
rc_nextmatch = pcre2_next_match(match_data, &tmp_offset, &tmp_options);
if (rc_nextmatch || tmp_offset != 0xcd || tmp_options != 0xcd)
{
- cprintf(clr_test_error, "** unexpected pcre2_next_match() for rc < 0\n");
+ cfprintf(clr_test_error, outfile, "** unexpected pcre2_next_match() for rc < 0\n");
return PR_ABEND;
}
}
@@ -5108,7 +5098,7 @@ for (gmatched = 0;; gmatched++)
if ((unsigned)capcount > oveccount) /* Check for lunatic return value */
{
- cprintf(clr_test_error,
+ cfprintf(clr_test_error, outfile,
"** PCRE2 error: returned count %d is too big for ovector count %d\n",
capcount, oveccount);
return PR_ABEND;
@@ -5121,15 +5111,15 @@ for (gmatched = 0;; gmatched++)
(pat_patctl.control & CTL_JITFAST) == 0)
{
if ((match_data->flags & PCRE2_MD_COPIED_SUBJECT) == 0)
- cprintf(clr_test_error,
+ cfprintf(clr_test_error, outfile,
"** PCRE2 error: flag not set after copy_matched_subject\n");
if (match_data->subject == pp)
- cprintf(clr_test_error,
+ cfprintf(clr_test_error, outfile,
"** PCRE2 error: copy_matched_subject has not copied\n");
if (memcmp(match_data->subject, pp, ulen) != 0)
- cprintf(clr_test_error,
+ cfprintf(clr_test_error, outfile,
"** PCRE2 error: copy_matched_subject mismatch\n");
}
@@ -5153,7 +5143,7 @@ for (gmatched = 0;; gmatched++)
!(dat_datctl.offset <= ovector[0] && ovector[0] <= ovector[1]) &&
pp + ovector[0] == ovecsave[0] && pp + ovector[1] == ovecsave[1])
{
- cprintf(clr_test_error, "global repeat returned the same match as previous\n");
+ cfprintf(clr_api_error, outfile, "global repeat returned the same match as previous\n");
goto NEXT_MATCH;
}
@@ -5171,7 +5161,7 @@ for (gmatched = 0;; gmatched++)
(ovector[1] == ovector[0] && ovecsave[1] != ovecsave[0] &&
pp + ovector[1] == ovecsave[1])))
{
- cprintf(clr_test_error,
+ cfprintf(clr_test_error, outfile,
"** PCRE2 error: global repeat did not make progress\n");
return PR_ABEND;
}
@@ -5207,17 +5197,17 @@ for (gmatched = 0;; gmatched++)
{
start = ovector[i+1];
end = ovector[i];
- cprintf(clr_api_error, "Start of matched string is beyond its end - "
+ cfprintf(clr_api_error, outfile, "Start of matched string is beyond its end - "
"displaying from end to start.\n");
}
- cprintf(clr_output, "%2d: ", i/2);
+ fprintf(outfile, "%2d: ", i/2);
/* Check for an unset group */
if (start == PCRE2_UNSET && end == PCRE2_UNSET)
{
- cprintf(clr_api_error, "\n");
+ fprintf(outfile, "\n");
continue;
}
@@ -5231,9 +5221,9 @@ for (gmatched = 0;; gmatched++)
if (((dat_datctl.control & CTL_DFA) != 0 ||
i >= (int)(2*maxcapcount + 2)) &&
start == JUNK_OFFSET && end == JUNK_OFFSET)
- cprintf(clr_output, "\n");
+ fprintf(outfile, "\n");
else
- cprintf(clr_test_error, "ERROR: bad value(s) for offset(s): 0x%lx 0x%lx\n",
+ cfprintf(clr_test_error, outfile, "** ERROR: bad value(s) for offset(s): 0x%lx 0x%lx\n",
(unsigned long int)start, (unsigned long int)end);
continue;
}
@@ -5261,15 +5251,15 @@ for (gmatched = 0;; gmatched++)
if (showallused)
{
- lleft = pchars(clr_output, pp + leftchar, start - leftchar, utf, outfile);
- lmiddle = pchars(clr_output, pp + start, end - start, utf, outfile);
- lright = pchars(clr_output, pp + end, rightchar - end, utf, outfile);
+ lleft = pchars(clr_none, pp + leftchar, start - leftchar, utf, outfile);
+ lmiddle = pchars(clr_none, pp + start, end - start, utf, outfile);
+ lright = pchars(clr_none, pp + end, rightchar - end, utf, outfile);
if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used)
- cprintf(clr_output, " (JIT)");
- cprintf(clr_output, "\n ");
- for (j = 0; j < lleft; j++) cprintf(clr_output, "<");
- for (j = 0; j < lmiddle; j++) cprintf(clr_output, " ");
- for (j = 0; j < lright; j++) cprintf(clr_output, ">");
+ fprintf(outfile, " (JIT)");
+ fprintf(outfile, "\n ");
+ for (j = 0; j < lleft; j++) fprintf(outfile, "<");
+ for (j = 0; j < lmiddle; j++) fprintf(outfile, " ");
+ for (j = 0; j < lright; j++) fprintf(outfile, ">");
}
/* When a pattern contains \K, the start of match position may be
@@ -5280,14 +5270,14 @@ for (gmatched = 0;; gmatched++)
{
PCRE2_SIZE startchar;
startchar = pcre2_get_startchar(match_data);
- lleft = pchars(clr_output, pp + startchar, start - startchar, utf, outfile);
- pchars(clr_output, pp+start, end - start, utf, outfile);
+ lleft = pchars(clr_none, pp + startchar, start - startchar, utf, outfile);
+ pchars(clr_none, pp+start, end - start, utf, outfile);
if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used)
- cprintf(clr_output, " (JIT)");
+ fprintf(outfile, " (JIT)");
if (startchar != start)
{
- cprintf(clr_output, "\n ");
- for (j = 0; j < lleft; j++) cprintf(clr_output, "^");
+ fprintf(outfile, "\n ");
+ for (j = 0; j < lleft; j++) fprintf(outfile, "^");
}
}
@@ -5295,9 +5285,9 @@ for (gmatched = 0;; gmatched++)
else
{
- pchars(clr_output, pp + start, end - start, utf, outfile);
+ pchars(clr_none, pp + start, end - start, utf, outfile);
if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used)
- cprintf(clr_output, " (JIT)");
+ fprintf(outfile, " (JIT)");
}
}
@@ -5305,10 +5295,10 @@ for (gmatched = 0;; gmatched++)
else
{
- pchars(clr_output, pp + start, end - start, utf, outfile);
+ pchars(clr_none, pp + start, end - start, utf, outfile);
}
- cprintf(clr_output, "\n");
+ fprintf(outfile, "\n");
/* Note: don't use the start/end variables here because we want to
show the text from what is reported as the end. */
@@ -5316,9 +5306,9 @@ for (gmatched = 0;; gmatched++)
if ((dat_datctl.control & CTL_ALLAFTERTEXT) != 0 ||
(i == 0 && (dat_datctl.control & CTL_AFTERTEXT) != 0))
{
- cprintf(clr_output, "%2d+ ", i/2);
- pchars(clr_output, pp + ovector[i+1], ulen - ovector[i+1], utf, outfile);
- cprintf(clr_output, "\n");
+ fprintf(outfile, "%2d+ ", i/2);
+ pchars(clr_none, pp + ovector[i+1], ulen - ovector[i+1], utf, outfile);
+ fprintf(outfile, "\n");
}
}
@@ -5327,9 +5317,9 @@ for (gmatched = 0;; gmatched++)
if ((dat_datctl.control & CTL_MARK) != 0 &&
match_data->mark != NULL)
{
- cprintf(clr_output, "MK: ");
- pchars(clr_output, match_data->mark - 1, -1, utf, outfile);
- cprintf(clr_output, "\n");
+ fprintf(outfile, "MK: ");
+ pchars(clr_none, match_data->mark - 1, -1, utf, outfile);
+ fprintf(outfile, "\n");
}
/* Process copy/get strings */
@@ -5355,33 +5345,33 @@ for (gmatched = 0;; gmatched++)
}
else leftchar = ovector[0];
- cprintf(clr_api_error, "Partial match");
+ cfprintf(clr_api_error, outfile, "Partial match");
if ((dat_datctl.control & CTL_MARK) != 0 &&
match_data->mark != NULL)
{
- cprintf(clr_api_error, ", mark=");
- rubriclength = pchars(clr_api_error, match_data->mark - 1, -1, utf, outfile);
+ fprintf(outfile, ", mark=");
+ rubriclength = pchars(clr_none, match_data->mark - 1, -1, utf, outfile);
rubriclength += 7;
}
- cprintf(clr_api_error, ": ");
+ fprintf(outfile, ": ");
rubriclength += 15;
- backlength = pchars(clr_api_error, pp + leftchar, ovector[0] - leftchar, utf, outfile);
- pchars(clr_api_error, pp + ovector[0], ovector[1] - ovector[0], utf, outfile);
+ backlength = pchars(clr_input, pp + leftchar, ovector[0] - leftchar, utf, outfile);
+ pchars(clr_input, pp + ovector[0], ovector[1] - ovector[0], utf, outfile);
if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used)
- cprintf(clr_api_error, " (JIT)");
- cprintf(clr_api_error, "\n");
+ fprintf(outfile, " (JIT)");
+ fprintf(outfile, "\n");
if (backlength != 0)
{
- for (int i = 0; i < rubriclength; i++) cprintf(clr_api_error, " ");
- for (int i = 0; i < backlength; i++) cprintf(clr_api_error, "<");
- cprintf(clr_api_error, "\n");
+ for (int i = 0; i < rubriclength; i++) fprintf(outfile, " ");
+ for (int i = 0; i < backlength; i++) fprintf(outfile, "<");
+ fprintf(outfile, "\n");
}
if (ulen != ovector[1])
- cprintf(clr_test_error, "** ovector[1] is not equal to the subject length: "
+ cfprintf(clr_test_error, outfile, "** ovector[1] is not equal to the subject length: "
"%ld != %ld\n", (unsigned long int)ovector[1], (unsigned long int)ulen);
/* Process copy/get strings */
@@ -5406,16 +5396,16 @@ for (gmatched = 0;; gmatched++)
case PCRE2_ERROR_NOMATCH:
if (gmatched == 0)
{
- cprintf(clr_api_error, "No match");
+ cfprintf(clr_api_error, outfile, "No match");
if ((dat_datctl.control & CTL_MARK) != 0 &&
match_data->mark != NULL)
{
- cprintf(clr_api_error, ", mark = ");
- pchars(clr_api_error, match_data->mark - 1, -1, utf, outfile);
+ fprintf(outfile, ", mark = ");
+ pchars(clr_none, match_data->mark - 1, -1, utf, outfile);
}
if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used)
- cprintf(clr_api_error, " (JIT)");
- cprintf(clr_api_error, "\n");
+ fprintf(outfile, " (JIT)");
+ fprintf(outfile, "\n");
/* "allvector" outputs the entire vector */
@@ -5425,21 +5415,21 @@ for (gmatched = 0;; gmatched++)
break;
case PCRE2_ERROR_BADUTFOFFSET:
- cprintf(clr_api_error, "Error %d (bad UTF-" STR(PCRE2_CODE_UNIT_WIDTH)
+ cfprintf(clr_api_error, outfile, "Error %d (bad UTF-" STR(PCRE2_CODE_UNIT_WIDTH)
" offset)\n", capcount);
break;
default:
- cprintf(clr_api_error, "Failed: error %d: ", capcount);
+ cfprintf(clr_api_error, outfile, "Failed: error %d: ", capcount);
if (!print_error_message(capcount, "", "")) return PR_ABEND;
if (capcount <= PCRE2_ERROR_UTF8_ERR1 &&
capcount >= PCRE2_ERROR_UTF32_ERR2)
{
PCRE2_SIZE startchar;
startchar = pcre2_get_startchar(match_data);
- cprintf(clr_api_error, " at offset %" SIZ_FORM, startchar);
+ cfprintf(clr_api_error, outfile, " at offset %" SIZ_FORM, startchar);
}
- cprintf(clr_api_error, "\n");
+ fprintf(outfile, "\n");
break;
}
@@ -6243,7 +6233,7 @@ free(invalid_code);
if (failure != NULL)
{
- fatal_printf("pcre2test: Unit test error in %s\n", failure);
+ cfprintf(clr_test_error, stderr, "pcre2test: Unit test error in %s\n", failure);
exit(1);
}
}
From d8337ecdc6e3ff0d3101cf2c7ea1027382c9ef55 Mon Sep 17 00:00:00 2001
From: Nicholas Wilson
Date: Fri, 10 Oct 2025 15:00:48 +0000
Subject: [PATCH 4/6] Add argument documentation to man page
---
doc/html/pcre2test.html | 6 +
doc/pcre2test.1 | 5 +
doc/pcre2test.txt | 1191 ++++++++++++++++++++-------------------
src/pcre2test.c | 4 +-
4 files changed, 611 insertions(+), 595 deletions(-)
diff --git a/doc/html/pcre2test.html b/doc/html/pcre2test.html
index 7b4492a37..769dff9a1 100644
--- a/doc/html/pcre2test.html
+++ b/doc/html/pcre2test.html
@@ -213,6 +213,12 @@
If an unknown option is given, an error message is output; the exit code is 0.
+--colo[u]r[=<always,auto,never>]
+By default, the output is coloured if the output file is a terminal (auto).
+Force or suppress output of ANSI colour escapes with always and never
+respectively.
+
+
-d
Behave as if each pattern has the debug modifier; the internal
form and information about the compiled pattern is output after compilation;
diff --git a/doc/pcre2test.1 b/doc/pcre2test.1
index 33acfd274..3cd636cf0 100644
--- a/doc/pcre2test.1
+++ b/doc/pcre2test.1
@@ -179,6 +179,11 @@ information. It returns one of the following values:
.sp
If an unknown option is given, an error message is output; the exit code is 0.
.TP 10
+\fB--colo[u]r[=]\fP
+By default, the output is coloured if the output file is a terminal (\fBauto\fP).
+Force or suppress output of ANSI colour escapes with \fBalways\fP and \fBnever\fP
+respectively.
+.TP 10
\fB-d\fP
Behave as if each pattern has the \fBdebug\fP modifier; the internal
form and information about the compiled pattern is output after compilation;
diff --git a/doc/pcre2test.txt b/doc/pcre2test.txt
index f23981336..fe31d25d4 100644
--- a/doc/pcre2test.txt
+++ b/doc/pcre2test.txt
@@ -172,61 +172,66 @@ COMMAND LINE OPTIONS
If an unknown option is given, an error message is output;
the exit code is 0.
- -d Behave as if each pattern has the debug modifier; the inter-
+ --colo[u]r[=]
+ By default, the output is coloured if the output file is a
+ terminal (auto). Force or suppress output of ANSI colour es-
+ capes with always and never respectively.
+
+ -d Behave as if each pattern has the debug modifier; the inter-
nal form and information about the compiled pattern is output
after compilation; -d is equivalent to -b -i.
-dfa Behave as if each subject line has the dfa modifier; matching
- is done using the pcre2_dfa_match() function instead of the
+ is done using the pcre2_dfa_match() function instead of the
default pcre2_match().
-E Run in "preprocess only" mode (similar to "gcc -E"). The "#if
- ... #endif" commands are processed, and all other lines are
+ ... #endif" commands are processed, and all other lines are
printed verbatim.
-error number[,number,...]
- Call pcre2_get_error_message() for each of the error numbers
- in the comma-separated list, display the resulting messages
- on the standard output, then exit with zero exit code. The
- numbers may be positive or negative. This is a convenience
+ Call pcre2_get_error_message() for each of the error numbers
+ in the comma-separated list, display the resulting messages
+ on the standard output, then exit with zero exit code. The
+ numbers may be positive or negative. This is a convenience
facility for PCRE2 maintainers.
-help Output a brief summary these options and then exit.
- -i Behave as if each pattern has the info modifier; information
+ -i Behave as if each pattern has the info modifier; information
about the compiled pattern is given after compilation.
- -jit Behave as if each pattern line has the jit modifier; after
- successful compilation, each pattern is passed to the just-
+ -jit Behave as if each pattern line has the jit modifier; after
+ successful compilation, each pattern is passed to the just-
in-time compiler, if available.
- -jitfast Behave as if each pattern line has the jitfast modifier; af-
- ter successful compilation, each pattern is passed to the
+ -jitfast Behave as if each pattern line has the jitfast modifier; af-
+ ter successful compilation, each pattern is passed to the
just-in-time compiler, if available, and each subject line is
passed directly to the JIT matcher via its "fast path".
-jitverify
- Behave as if each pattern line has the jitverify modifier;
- after successful compilation, each pattern is passed to the
- just-in-time compiler, if available, and the use of JIT for
+ Behave as if each pattern line has the jitverify modifier;
+ after successful compilation, each pattern is passed to the
+ just-in-time compiler, if available, and the use of JIT for
matching is verified.
-LM List modifiers: write a list of available pattern and subject
- modifiers to the standard output, then exit with zero exit
- code. All other options are ignored. If both -C and any -Lx
+ modifiers to the standard output, then exit with zero exit
+ code. All other options are ignored. If both -C and any -Lx
options are present, whichever is first is recognized.
- -LP List properties: write a list of recognized Unicode proper-
- ties to the standard output, then exit with zero exit code.
+ -LP List properties: write a list of recognized Unicode proper-
+ ties to the standard output, then exit with zero exit code.
All other options are ignored. If both -C and any -Lx options
are present, whichever is first is recognized.
-LS List scripts: write a list of recognized Unicode script names
- to the standard output, then exit with zero exit code. All
+ to the standard output, then exit with zero exit code. All
other options are ignored. If both -C and any -Lx options are
present, whichever is first is recognized.
- -malloc Exercise malloc() failures, by first counting the number of
+ -malloc Exercise malloc() failures, by first counting the number of
calls made to malloc during pattern compilation and matching,
then re-running the compilation and matching that many times,
exercising a failure of each malloc() call.
@@ -237,28 +242,28 @@ COMMAND LINE OPTIONS
-q Do not output the version number of pcre2test at the start of
execution.
- -S size On Unix-like systems, set the size of the run-time stack to
+ -S size On Unix-like systems, set the size of the run-time stack to
size mebibytes (units of 1024*1024 bytes).
-subject modifier-list
Behave as if each subject line contains the given modifiers.
- -t Run each compile and match many times with a timer, and out-
- put the resulting times per compile or match. When JIT is
- used, separate times are given for the initial compile and
- the JIT compile. You can control the number of iterations
- that are used for timing by following -t with a number (as a
- separate item on the command line). For example, "-t 1000"
+ -t Run each compile and match many times with a timer, and out-
+ put the resulting times per compile or match. When JIT is
+ used, separate times are given for the initial compile and
+ the JIT compile. You can control the number of iterations
+ that are used for timing by following -t with a number (as a
+ separate item on the command line). For example, "-t 1000"
iterates 1000 times. The default is to iterate 500,000 times.
-tm This is like -t except that it times only the matching phase,
not the compile phase.
- -T -TM These behave like -t and -tm, but in addition, at the end of
- a run, the total times for all compiles and matches are out-
+ -T -TM These behave like -t and -tm, but in addition, at the end of
+ a run, the total times for all compiles and matches are out-
put.
- -unittest Run a fixed set of additional tests of the PCRE2 API which
+ -unittest Run a fixed set of additional tests of the PCRE2 API which
are not driven by the test input files, and then exit.
-version Output the PCRE2 version number and then exit.
@@ -266,153 +271,153 @@ COMMAND LINE OPTIONS
DESCRIPTION
- If pcre2test is given two filename arguments, it reads from the first
+ If pcre2test is given two filename arguments, it reads from the first
and writes to the second. If the first name is "-", input is taken from
- the standard input. If pcre2test is given only one argument, it reads
+ the standard input. If pcre2test is given only one argument, it reads
from that file and writes to stdout. Otherwise, it reads from stdin and
writes to stdout.
- When pcre2test is built, a configuration option can specify that it
- should be linked with the libreadline or libedit library. When this is
- done, if the input is from a terminal, it is read using the readline()
+ When pcre2test is built, a configuration option can specify that it
+ should be linked with the libreadline or libedit library. When this is
+ done, if the input is from a terminal, it is read using the readline()
function. This provides line-editing and history facilities. The output
from the -help option states whether or not readline() will be used.
- The program handles any number of tests, each of which consists of a
- set of input lines. Each set starts with a regular expression pattern,
+ The program handles any number of tests, each of which consists of a
+ set of input lines. Each set starts with a regular expression pattern,
followed by any number of subject lines to be matched against that pat-
tern. In between sets of test data, command lines that begin with # may
appear. This file format, with some restrictions, can also be processed
- by the perltest.sh script that is distributed with PCRE2 as a means of
+ by the perltest.sh script that is distributed with PCRE2 as a means of
checking that the behaviour of PCRE2 and Perl is the same. For a speci-
- fication of perltest.sh, see the comments near its beginning. See also
+ fication of perltest.sh, see the comments near its beginning. See also
the #perltest command below.
When the input is a terminal, pcre2test prompts for each line of input,
- using "re>" to prompt for regular expression patterns, and "data>" to
- prompt for subject lines. Command lines starting with # can be entered
+ using "re>" to prompt for regular expression patterns, and "data>" to
+ prompt for subject lines. Command lines starting with # can be entered
only in response to the "re>" prompt.
- Each subject line is matched separately and independently. If you want
+ Each subject line is matched separately and independently. If you want
to do multi-line matches, you have to use the \n escape sequence (or \r
- or \r\n, etc., depending on the newline setting) in a single line of
- input to encode the newline sequences. There is no limit on the length
- of subject lines; the input buffer is automatically extended if it is
- too small. There are replication features that makes it possible to
- generate long repetitive pattern or subject lines without having to
+ or \r\n, etc., depending on the newline setting) in a single line of
+ input to encode the newline sequences. There is no limit on the length
+ of subject lines; the input buffer is automatically extended if it is
+ too small. There are replication features that makes it possible to
+ generate long repetitive pattern or subject lines without having to
supply them explicitly.
- An empty line or the end of the file signals the end of the subject
- lines for a test, at which point a new pattern or command line is ex-
+ An empty line or the end of the file signals the end of the subject
+ lines for a test, at which point a new pattern or command line is ex-
pected if there is still input to be read.
COMMAND LINES
- In between sets of test data, a line that begins with # is interpreted
+ In between sets of test data, a line that begins with # is interpreted
as a command line. If the first character is followed by white space or
- an exclamation mark, the line is treated as a comment, and ignored.
+ an exclamation mark, the line is treated as a comment, and ignored.
Otherwise, the following commands are recognized:
#forbid_utf
- Subsequent patterns automatically have the PCRE2_NEVER_UTF and
- PCRE2_NEVER_UCP options set, which locks out the use of the PCRE2_UTF
- and PCRE2_UCP options and the use of (*UTF) and (*UCP) at the start of
- patterns. This command also forces an error if a subsequent pattern
- contains any occurrences of \P, \p, or \X, which are still supported
- when PCRE2_UTF is not set, but which require Unicode property support
+ Subsequent patterns automatically have the PCRE2_NEVER_UTF and
+ PCRE2_NEVER_UCP options set, which locks out the use of the PCRE2_UTF
+ and PCRE2_UCP options and the use of (*UTF) and (*UCP) at the start of
+ patterns. This command also forces an error if a subsequent pattern
+ contains any occurrences of \P, \p, or \X, which are still supported
+ when PCRE2_UTF is not set, but which require Unicode property support
to be included in the library.
- This is a trigger guard that is used in test files to ensure that UTF
- or Unicode property tests are not accidentally added to files that are
- used when Unicode support is not included in the library. Setting
- PCRE2_NEVER_UTF and PCRE2_NEVER_UCP as a default can also be obtained
- by the use of #pattern; the difference is that #forbid_utf cannot be
- unset, and the automatic options are not displayed in pattern informa-
+ This is a trigger guard that is used in test files to ensure that UTF
+ or Unicode property tests are not accidentally added to files that are
+ used when Unicode support is not included in the library. Setting
+ PCRE2_NEVER_UTF and PCRE2_NEVER_UCP as a default can also be obtained
+ by the use of #pattern; the difference is that #forbid_utf cannot be
+ unset, and the automatic options are not displayed in pattern informa-
tion, to avoid cluttering up test output.
#load
This command is used to load a set of precompiled patterns from a file,
- as described in the section entitled "Saving and restoring compiled
+ as described in the section entitled "Saving and restoring compiled
patterns" below.
#loadtables
- This command is used to load a set of binary character tables that can
- be accessed by the tables=3 qualifier. Such tables can be created by
+ This command is used to load a set of binary character tables that can
+ be accessed by the tables=3 qualifier. Such tables can be created by
the pcre2_dftables program with the -b option.
#newline_default []
- When PCRE2 is built, a default newline convention can be specified.
- This determines which characters and/or character pairs are recognized
+ When PCRE2 is built, a default newline convention can be specified.
+ This determines which characters and/or character pairs are recognized
as indicating a newline in a pattern or subject string. The default can
- be overridden when a pattern is compiled. The standard test files con-
- tain tests of various newline conventions, but the majority of the
- tests expect a single linefeed to be recognized as a newline by de-
- fault. Without special action the tests would fail when PCRE2 is com-
+ be overridden when a pattern is compiled. The standard test files con-
+ tain tests of various newline conventions, but the majority of the
+ tests expect a single linefeed to be recognized as a newline by de-
+ fault. Without special action the tests would fail when PCRE2 is com-
piled with either CR or CRLF as the default newline.
The #newline_default command specifies a list of newline types that are
- acceptable as the default. The types must be one of CR, LF, CRLF, ANY-
+ acceptable as the default. The types must be one of CR, LF, CRLF, ANY-
CRLF, ANY, or NUL (in upper or lower case), for example:
#newline_default LF Any anyCRLF
If the default newline is in the list, this command has no effect. Oth-
- erwise, except when testing the POSIX API, a newline modifier that
+ erwise, except when testing the POSIX API, a newline modifier that
specifies the first newline convention in the list (LF in the above ex-
- ample) is added to any pattern that does not already have a newline
+ ample) is added to any pattern that does not already have a newline
modifier. If the newline list is empty, the feature is turned off. This
command is present in a number of the standard test input files.
- When the POSIX API is being tested there is no way to override the de-
+ When the POSIX API is being tested there is no way to override the de-
fault newline convention, though it is possible to set the newline con-
- vention from within the pattern. A warning is given if the posix or
- posix_nosub modifier is used when #newline_default would set a default
+ vention from within the pattern. A warning is given if the posix or
+ posix_nosub modifier is used when #newline_default would set a default
for the non-POSIX API.
#pattern
- This command sets a default modifier list that applies to all subse-
+ This command sets a default modifier list that applies to all subse-
quent patterns. Modifiers on a pattern can change these settings.
#perltest
- This line is used in test files that can also be processed by perl-
- test.sh to confirm that Perl gives the same results as PCRE2. Subse-
- quent tests are checked for the use of pcre2test features that are in-
+ This line is used in test files that can also be processed by perl-
+ test.sh to confirm that Perl gives the same results as PCRE2. Subse-
+ quent tests are checked for the use of pcre2test features that are in-
compatible with the perltest.sh script.
- Patterns must use '/' as their delimiter, and only certain modifiers
- are supported. Comment lines, #pattern commands, and #subject commands
- that set or unset "mark" are recognized and acted on. The #perltest,
- #forbid_utf, and #newline_default commands, which are needed in the
+ Patterns must use '/' as their delimiter, and only certain modifiers
+ are supported. Comment lines, #pattern commands, and #subject commands
+ that set or unset "mark" are recognized and acted on. The #perltest,
+ #forbid_utf, and #newline_default commands, which are needed in the
relevant pcre2test files, are silently ignored. All other command lines
- are ignored, but give a warning message. The #perltest command helps
- detect tests that are accidentally put in the wrong file or use the
- wrong delimiter. For more details of the perltest.sh script see the
+ are ignored, but give a warning message. The #perltest command helps
+ detect tests that are accidentally put in the wrong file or use the
+ wrong delimiter. For more details of the perltest.sh script see the
comments it contains.
#pop []
#popcopy []
- These commands are used to manipulate the stack of compiled patterns,
- as described in the section entitled "Saving and restoring compiled
+ These commands are used to manipulate the stack of compiled patterns,
+ as described in the section entitled "Saving and restoring compiled
patterns" below.
#save
- This command is used to save a set of compiled patterns to a file, as
- described in the section entitled "Saving and restoring compiled pat-
+ This command is used to save a set of compiled patterns to a file, as
+ described in the section entitled "Saving and restoring compiled pat-
terns" below.
#subject
- This command sets a default modifier list that applies to all subse-
- quent subject lines. Modifiers on a subject line can change these set-
+ This command sets a default modifier list that applies to all subse-
+ quent subject lines. Modifiers on a subject line can change these set-
tings.
#if CONDITION
@@ -421,10 +426,10 @@ COMMAND LINES
If CONDITION is true, then the command is printed, and its contents are
processed as normal, including printing the commandlines to the output.
- If CONDITION is false, then all lines between the "#if" and "#endif"
+ If CONDITION is false, then all lines between the "#if" and "#endif"
are skipped and not printed. The CONDITION can be any of the conditions
which are tested by the "-C" commandline option and which set
- pcre2test's exit code to a boolean value. The CONDITION may also be
+ pcre2test's exit code to a boolean value. The CONDITION may also be
preceded by "!".
@@ -432,47 +437,47 @@ MODIFIER SYNTAX
Modifier lists are used with both pattern and subject lines. Items in a
list are separated by commas followed by optional white space. Trailing
- white space in a modifier list is ignored. Some modifiers may be given
- for both patterns and subject lines, whereas others are valid only for
- one or the other. Each modifier has a long name, for example "an-
- chored", and some of them must be followed by an equals sign and a
- value, for example, "offset=12". Values cannot contain comma charac-
- ters, but may contain spaces. Modifiers that do not take values may be
+ white space in a modifier list is ignored. Some modifiers may be given
+ for both patterns and subject lines, whereas others are valid only for
+ one or the other. Each modifier has a long name, for example "an-
+ chored", and some of them must be followed by an equals sign and a
+ value, for example, "offset=12". Values cannot contain comma charac-
+ ters, but may contain spaces. Modifiers that do not take values may be
preceded by a minus sign to turn off a previous setting.
A few of the more common modifiers can also be specified as single let-
- ters, for example "i" for "caseless". In documentation, following the
+ ters, for example "i" for "caseless". In documentation, following the
Perl convention, these are written with a slash ("the /i modifier") for
- clarity. Abbreviated modifiers must all be concatenated in the first
- item of a modifier list. If the first item is not recognized as a long
- modifier name, it is interpreted as a sequence of these abbreviations.
+ clarity. Abbreviated modifiers must all be concatenated in the first
+ item of a modifier list. If the first item is not recognized as a long
+ modifier name, it is interpreted as a sequence of these abbreviations.
For example:
/abc/ig,newline=cr,jit=3
- This is a pattern line whose modifier list starts with two one-letter
- modifiers (/i and /g). The lower-case abbreviated modifiers are the
+ This is a pattern line whose modifier list starts with two one-letter
+ modifiers (/i and /g). The lower-case abbreviated modifiers are the
same as used in Perl.
PATTERN SYNTAX
- A pattern line must start with one of the following characters (common
+ A pattern line must start with one of the following characters (common
symbols, excluding pattern meta-characters):
/ ! " ' ` - = _ : ; , % & @ ~
- This is interpreted as the pattern's delimiter. A regular expression
- may be continued over several input lines, in which case the newline
+ This is interpreted as the pattern's delimiter. A regular expression
+ may be continued over several input lines, in which case the newline
characters are included within it. It is possible to include the delim-
- iter as a literal within the pattern by escaping it with a backslash,
+ iter as a literal within the pattern by escaping it with a backslash,
for example
/abc\/def/
- If you do this, the escape and the delimiter form part of the pattern,
+ If you do this, the escape and the delimiter form part of the pattern,
but since the delimiters are all non-alphanumeric, the inclusion of the
- backslash does not affect the pattern's interpretation. Note, however,
+ backslash does not affect the pattern's interpretation. Note, however,
that this trick does not work within \Q...\E literal bracketing because
the backslash will itself be interpreted as a literal. If the terminat-
ing delimiter is immediately followed by a backslash, for example,
@@ -480,13 +485,13 @@ PATTERN SYNTAX
/abc/\
a backslash is added to the end of the pattern. This is done to provide
- a way of testing the error condition that arises if a pattern finishes
+ a way of testing the error condition that arises if a pattern finishes
with a backslash, because
/abc\/
- is interpreted as the first line of a pattern that starts with "abc/",
- causing pcre2test to read the next line as a continuation of the regu-
+ is interpreted as the first line of a pattern that starts with "abc/",
+ causing pcre2test to read the next line as a continuation of the regu-
lar expression.
A pattern can be followed by a modifier list (details below).
@@ -495,9 +500,9 @@ PATTERN SYNTAX
SUBJECT LINE SYNTAX
Before each subject line is passed to pcre2_match(), pcre2_dfa_match(),
- or pcre2_jit_match(), leading and trailing white space is removed, and
- the line is scanned for backslash escapes, unless the subject_literal
- modifier was set for the pattern. The following provide a means of en-
+ or pcre2_jit_match(), leading and trailing white space is removed, and
+ the line is scanned for backslash escapes, unless the subject_literal
+ modifier was set for the pattern. The following provide a means of en-
coding non-printing characters in a visible way:
\a alarm (BEL, \x07)
@@ -510,7 +515,7 @@ SUBJECT LINE SYNTAX
\t tab (\x09)
\v vertical tab (\x0b)
\ddd octal number (up to 3 octal digits); represent a single
- code point unless larger than 255 with the 8-bit li-
+ code point unless larger than 255 with the 8-bit li-
brary
\o{dd...} octal number (any number of octal digits} representing a
character in UTF mode or a code point
@@ -518,28 +523,28 @@ SUBJECT LINE SYNTAX
\x{hh...} hexadecimal number (up to 8 hex digits) representing a
character in UTF mode or a code point
- Invoking \N{U+hh...} or \x{hh...} doesn't require the use of the utf
+ Invoking \N{U+hh...} or \x{hh...} doesn't require the use of the utf
modifier on the pattern. It is always recognized. There may be any num-
ber of hexadecimal digits inside the braces; invalid values provoke er-
ror messages but when using \N{U+hh...} with some invalid unicode char-
acters they will be accepted with a warning instead.
- Note that even in UTF-8 mode, \xhh (and depending of how large, \ddd)
- describe one byte rather than one character; this makes it possible to
- construct invalid UTF-8 sequences for testing purposes. On the other
+ Note that even in UTF-8 mode, \xhh (and depending of how large, \ddd)
+ describe one byte rather than one character; this makes it possible to
+ construct invalid UTF-8 sequences for testing purposes. On the other
hand, \x{hh...} is interpreted as a UTF-8 character in UTF-8 mode, only
- generating more than one byte if the value is greater than 127. To
- avoid the ambiguity it is preferred to use \N{U+hh...} when describing
- characters. When testing the 8-bit library not in UTF-8 mode, \x{hh}
+ generating more than one byte if the value is greater than 127. To
+ avoid the ambiguity it is preferred to use \N{U+hh...} when describing
+ characters. When testing the 8-bit library not in UTF-8 mode, \x{hh}
generates one byte for values that could fit on it, and causes an error
for greater values.
- When testing the 16-bit library, not in UTF-16 mode, all 4-digit
- \x{hhhh} values are accepted. This makes it possible to construct in-
+ When testing the 16-bit library, not in UTF-16 mode, all 4-digit
+ \x{hhhh} values are accepted. This makes it possible to construct in-
valid UTF-16 sequences for testing purposes.
- When testing the 32-bit library, not in UTF-32 mode, all 4 to 8-digit
- \x{...} values are accepted. This makes it possible to construct in-
+ When testing the 32-bit library, not in UTF-32 mode, all 4 to 8-digit
+ \x{...} values are accepted. This makes it possible to construct in-
valid UTF-32 sequences for testing purposes.
There is a special backslash sequence that specifies replication of one
@@ -547,31 +552,31 @@ SUBJECT LINE SYNTAX
\[]{}
- This makes it possible to test long strings without having to provide
+ This makes it possible to test long strings without having to provide
them as part of the file. For example:
\[abc]{4}
- is converted to "abcabcabcabc". This feature does not support nesting.
+ is converted to "abcabcabcabc". This feature does not support nesting.
To include a closing square bracket in the characters, code it as \x5D.
- A backslash followed by an equals sign marks the end of the subject
+ A backslash followed by an equals sign marks the end of the subject
string and the start of a modifier list. For example:
abc\=notbol,notempty
- If the subject string is empty and \= is followed by white space, the
- line is treated as a comment line, and is not used for matching. For
+ If the subject string is empty and \= is followed by white space, the
+ line is treated as a comment line, and is not used for matching. For
example:
\= This is a comment.
abc\= This is an invalid modifier list.
- A backslash followed by any other non-alphanumeric character just es-
- capes that character. A backslash followed by anything else causes an
- error. However, if the very last character in the line is a backslash
- (and there is no modifier list), it is ignored. This gives a way of
- passing an empty line as data, since a real empty line terminates the
+ A backslash followed by any other non-alphanumeric character just es-
+ capes that character. A backslash followed by anything else causes an
+ error. However, if the very last character in the line is a backslash
+ (and there is no modifier list), it is ignored. This gives a way of
+ passing an empty line as data, since a real empty line terminates the
data input.
If the subject_literal modifier is set for a pattern, all subject lines
@@ -582,19 +587,19 @@ SUBJECT LINE SYNTAX
PATTERN MODIFIERS
- There are several types of modifier that can appear in pattern lines.
+ There are several types of modifier that can appear in pattern lines.
Except where noted below, they may also be used in #pattern commands. A
- pattern's modifier list can add to or override default modifiers that
+ pattern's modifier list can add to or override default modifiers that
were set by a previous #pattern command.
Setting compilation options
- The following modifiers set options for pcre2_compile(). Most of them
- set bits in the options argument of that function, but those whose
+ The following modifiers set options for pcre2_compile(). Most of them
+ set bits in the options argument of that function, but those whose
names start with PCRE2_EXTRA are additional options that are set in the
- compile context. Some of these options have single-letter abbrevia-
- tions. There is special handling for /x: if a second x is present,
- PCRE2_EXTENDED is converted into PCRE2_EXTENDED_MORE as in Perl. A
+ compile context. Some of these options have single-letter abbrevia-
+ tions. There is special handling for /x: if a second x is present,
+ PCRE2_EXTENDED is converted into PCRE2_EXTENDED_MORE as in Perl. A
third appearance adds PCRE2_EXTENDED as well, though this makes no dif-
ference to the way pcre2_compile() behaves. See pcre2api for a descrip-
tion of the effects of these options.
@@ -650,13 +655,13 @@ PATTERN MODIFIERS
utf set PCRE2_UTF
As well as turning on the PCRE2_UTF option, the utf modifier causes all
- non-printing characters in output strings to be printed using the
- \x{hh...} notation. Otherwise, those less than 0x100 are output in hex
- without the curly brackets. Setting utf in 16-bit or 32-bit mode also
- causes pattern and subject strings to be translated to UTF-16 or
+ non-printing characters in output strings to be printed using the
+ \x{hh...} notation. Otherwise, those less than 0x100 are output in hex
+ without the curly brackets. Setting utf in 16-bit or 32-bit mode also
+ causes pattern and subject strings to be translated to UTF-16 or
UTF-32, respectively, before being passed to library functions.
- The following modifiers enable or disable performance optimizations by
+ The following modifiers enable or disable performance optimizations by
calling pcre2_set_optimize() before invoking the regex compiler.
optimization_full enable all optional optimizations
@@ -673,8 +678,8 @@ PATTERN MODIFIERS
Setting compilation controls
- The following modifiers affect the compilation process or request in-
- formation about the pattern. There are single-letter abbreviations for
+ The following modifiers affect the compilation process or request in-
+ formation about the pattern. There are single-letter abbreviations for
some that are heavily used in the test files.
/B bincode show binary code without lengths
@@ -718,35 +723,35 @@ PATTERN MODIFIERS
Newline and \R handling
- The bsr modifier specifies what \R in a pattern should match. If it is
- set to "anycrlf", \R matches CR, LF, or CRLF only. If it is set to
- "unicode", \R matches any Unicode newline sequence. The default can be
+ The bsr modifier specifies what \R in a pattern should match. If it is
+ set to "anycrlf", \R matches CR, LF, or CRLF only. If it is set to
+ "unicode", \R matches any Unicode newline sequence. The default can be
specified when PCRE2 is built; if it is not, the default is set to Uni-
code.
- The newline modifier specifies which characters are to be interpreted
+ The newline modifier specifies which characters are to be interpreted
as newlines, both in the pattern and in subject lines. The type must be
one of CR, LF, CRLF, ANYCRLF, ANY, or NUL (in upper or lower case).
Information about a pattern
- The debug modifier is a shorthand for info,fullbincode, requesting all
+ The debug modifier is a shorthand for info,fullbincode, requesting all
available information.
The bincode modifier causes a representation of the compiled code to be
- output after compilation. This information does not contain length and
+ output after compilation. This information does not contain length and
offset values, which ensures that the same output is generated for dif-
- ferent internal link sizes and different code unit widths. By using
- bincode, the same regression tests can be used in different environ-
+ ferent internal link sizes and different code unit widths. By using
+ bincode, the same regression tests can be used in different environ-
ments.
- The fullbincode modifier, by contrast, does include length and offset
- values. This is used in a few special tests that run only for specific
+ The fullbincode modifier, by contrast, does include length and offset
+ values. This is used in a few special tests that run only for specific
code unit widths and link sizes, and is also useful for one-off tests.
- The info modifier requests information about the compiled pattern
- (whether it is anchored, has a fixed first character, and so on). The
- information is obtained from the pcre2_pattern_info() function. Here
+ The info modifier requests information about the compiled pattern
+ (whether it is anchored, has a fixed first character, and so on). The
+ information is obtained from the pcre2_pattern_info() function. Here
are some typical examples:
re> /(?i)(^a|^b)/m,info
@@ -764,136 +769,136 @@ PATTERN MODIFIERS
Last code unit = 'c' (caseless)
Subject length lower bound = 3
- "Compile options" are those specified by modifiers; "overall options"
- have added options that are taken or deduced from the pattern. If both
- sets of options are the same, just a single "options" line is output;
- if there are no options, the line is omitted. "First code unit" is
- where any match must start; if there is more than one they are listed
- as "starting code units". "Last code unit" is the last literal code
- unit that must be present in any match. This is not necessarily the
- last character. These lines are omitted if no starting or ending code
- units are recorded. The subject length line is omitted when
- no_start_optimize is set because the minimum length is not calculated
+ "Compile options" are those specified by modifiers; "overall options"
+ have added options that are taken or deduced from the pattern. If both
+ sets of options are the same, just a single "options" line is output;
+ if there are no options, the line is omitted. "First code unit" is
+ where any match must start; if there is more than one they are listed
+ as "starting code units". "Last code unit" is the last literal code
+ unit that must be present in any match. This is not necessarily the
+ last character. These lines are omitted if no starting or ending code
+ units are recorded. The subject length line is omitted when
+ no_start_optimize is set because the minimum length is not calculated
when it can never be used.
- The framesize modifier shows the size, in bytes, of each storage frame
- used by pcre2_match() for handling backtracking. The size depends on
- the number of capturing parentheses in the pattern. A vector of these
- frames is used at matching time; its overall size is shown when the
+ The framesize modifier shows the size, in bytes, of each storage frame
+ used by pcre2_match() for handling backtracking. The size depends on
+ the number of capturing parentheses in the pattern. A vector of these
+ frames is used at matching time; its overall size is shown when the
heaframes_size subject modifier is set.
- The callout_info modifier requests information about all the callouts
+ The callout_info modifier requests information about all the callouts
in the pattern. A list of them is output at the end of any other infor-
mation that is requested. For each callout, either its number or string
is given, followed by the item that follows it in the pattern.
Passing a NULL context
- Normally, pcre2test passes a context block to pcre2_compile(). If the
- null_context modifier is set, however, NULL is passed. This is for
- testing that pcre2_compile() behaves correctly in this case (it uses
+ Normally, pcre2test passes a context block to pcre2_compile(). If the
+ null_context modifier is set, however, NULL is passed. This is for
+ testing that pcre2_compile() behaves correctly in this case (it uses
default values).
Passing a NULL pattern
- The null_pattern modifier is for testing the behaviour of pcre2_com-
- pile() when the pattern argument is NULL. The length value passed is
+ The null_pattern modifier is for testing the behaviour of pcre2_com-
+ pile() when the pattern argument is NULL. The length value passed is
the default PCRE2_ZERO_TERMINATED unless use_length is set. Any length
other than zero causes an error.
Specifying pattern characters in hexadecimal
- The hex modifier specifies that the characters of the pattern, except
- for substrings enclosed in single or double quotes, are to be inter-
- preted as pairs of hexadecimal digits. This feature is provided as a
+ The hex modifier specifies that the characters of the pattern, except
+ for substrings enclosed in single or double quotes, are to be inter-
+ preted as pairs of hexadecimal digits. This feature is provided as a
way of creating patterns that contain binary zeros and other non-print-
- ing characters. White space is permitted between pairs of digits. For
+ ing characters. White space is permitted between pairs of digits. For
example, this pattern contains three characters:
/ab 32 59/hex
- Parts of such a pattern are taken literally if quoted. This pattern
- contains nine characters, only two of which are specified in hexadeci-
+ Parts of such a pattern are taken literally if quoted. This pattern
+ contains nine characters, only two of which are specified in hexadeci-
mal:
/ab "literal" 32/hex
- Either single or double quotes may be used. There is no way of includ-
- ing the delimiter within a substring. The hex and expand modifiers are
+ Either single or double quotes may be used. There is no way of includ-
+ ing the delimiter within a substring. The hex and expand modifiers are
mutually exclusive.
Specifying the pattern's length
By default, patterns are passed to the compiling functions as zero-ter-
- minated strings but can be passed by length instead of being zero-ter-
- minated. The use_length modifier causes this to happen. Using a length
- happens automatically (whether or not use_length is set) when hex is
- set, because patterns specified in hexadecimal may contain binary ze-
+ minated strings but can be passed by length instead of being zero-ter-
+ minated. The use_length modifier causes this to happen. Using a length
+ happens automatically (whether or not use_length is set) when hex is
+ set, because patterns specified in hexadecimal may contain binary ze-
ros.
If hex or use_length is used with the POSIX wrapper API (see "Using the
- POSIX wrapper API" below), the REG_PEND extension is used to pass the
+ POSIX wrapper API" below), the REG_PEND extension is used to pass the
pattern's length.
Specifying a maximum for variable lookbehinds
- Variable lookbehind assertions are supported only if, for each one,
+ Variable lookbehind assertions are supported only if, for each one,
there is a maximum length (in characters) that it can match. There is a
limit on this, whose default can be set at build time, with an ultimate
- default of 255. The max_varlookbehind modifier uses the
+ default of 255. The max_varlookbehind modifier uses the
pcre2_set_max_varlookbehind() function to change the limit. Lookbehinds
- whose branches each match a fixed length are limited to 65535 charac-
+ whose branches each match a fixed length are limited to 65535 charac-
ters per branch.
Specifying wide characters in 16-bit and 32-bit modes
In 16-bit and 32-bit modes, all input is automatically treated as UTF-8
- and translated to UTF-16 or UTF-32 when the utf modifier is set. For
+ and translated to UTF-16 or UTF-32 when the utf modifier is set. For
testing the 16-bit and 32-bit libraries in non-UTF mode, the utf8_input
- modifier can be used. It is mutually exclusive with utf. Input lines
+ modifier can be used. It is mutually exclusive with utf. Input lines
are interpreted as UTF-8 as a means of specifying wide characters. More
details are given in "Input encoding" above.
Generating long repetitive patterns
- Some tests use long patterns that are very repetitive. Instead of cre-
- ating a very long input line for such a pattern, you can use a special
- repetition feature, similar to the one described for subject lines
- above. If the expand modifier is present on a pattern, parts of the
+ Some tests use long patterns that are very repetitive. Instead of cre-
+ ating a very long input line for such a pattern, you can use a special
+ repetition feature, similar to the one described for subject lines
+ above. If the expand modifier is present on a pattern, parts of the
pattern that have the form
\[]{}
are expanded before the pattern is passed to pcre2_compile(). For exam-
ple, \[AB]{6000} is expanded to "ABAB..." 6000 times. This construction
- cannot be nested. An initial "\[" sequence is recognized only if "]{"
- followed by decimal digits and "}" is found later in the pattern. If
+ cannot be nested. An initial "\[" sequence is recognized only if "]{"
+ followed by decimal digits and "}" is found later in the pattern. If
not, the characters remain in the pattern unaltered. The expand and hex
modifiers are mutually exclusive.
- If part of an expanded pattern looks like an expansion, but is really
+ If part of an expanded pattern looks like an expansion, but is really
part of the actual pattern, unwanted expansion can be avoided by giving
two values in the quantifier. For example, \[AB]{6000,6000} is not rec-
ognized as an expansion item.
- If the info modifier is set on an expanded pattern, the result of the
+ If the info modifier is set on an expanded pattern, the result of the
expansion is included in the information that is output.
JIT compilation
- Just-in-time (JIT) compiling is a heavyweight optimization that can
- greatly speed up pattern matching. See the pcre2jit documentation for
- details. JIT compiling happens, optionally, after a pattern has been
- successfully compiled into an internal form. The JIT compiler converts
+ Just-in-time (JIT) compiling is a heavyweight optimization that can
+ greatly speed up pattern matching. See the pcre2jit documentation for
+ details. JIT compiling happens, optionally, after a pattern has been
+ successfully compiled into an internal form. The JIT compiler converts
this to optimized machine code. It needs to know whether the match-time
options PCRE2_PARTIAL_HARD and PCRE2_PARTIAL_SOFT are going to be used,
- because different code is generated for the different cases. See the
- partial modifier in "Subject Modifiers" below for details of how these
+ because different code is generated for the different cases. See the
+ partial modifier in "Subject Modifiers" below for details of how these
options are specified for each match attempt.
JIT compilation is requested by the jit pattern modifier, which may op-
- tionally be followed by an equals sign and a number in the range 0 to
- 7. The three bits that make up the number specify which of the three
+ tionally be followed by an equals sign and a number in the range 0 to
+ 7. The three bits that make up the number specify which of the three
JIT operating modes are to be compiled:
1 compile JIT code for non-partial matching
@@ -910,31 +915,31 @@ PATTERN MODIFIERS
6 soft and hard partial matching only
7 all three modes
- If no number is given, 7 is assumed. The phrase "partial matching"
+ If no number is given, 7 is assumed. The phrase "partial matching"
means a call to pcre2_match() with either the PCRE2_PARTIAL_SOFT or the
- PCRE2_PARTIAL_HARD option set. Note that such a call may return a com-
+ PCRE2_PARTIAL_HARD option set. Note that such a call may return a com-
plete match; the options enable the possibility of a partial match, but
- do not require it. Note also that if you request JIT compilation only
- for partial matching (for example, jit=2) but do not set the partial
- modifier on a subject line, that match will not use JIT code because
+ do not require it. Note also that if you request JIT compilation only
+ for partial matching (for example, jit=2) but do not set the partial
+ modifier on a subject line, that match will not use JIT code because
none was compiled for non-partial matching.
- If JIT compilation is successful, the compiled JIT code will automati-
+ If JIT compilation is successful, the compiled JIT code will automati-
cally be used when an appropriate type of match is run, except when in-
- compatible run-time options are specified. For more details, see the
- pcre2jit documentation. See also the jitstack modifier below for a way
+ compatible run-time options are specified. For more details, see the
+ pcre2jit documentation. See also the jitstack modifier below for a way
of setting the size of the JIT stack.
- If the jitfast modifier is specified, matching is done using the JIT
- "fast path" interface, pcre2_jit_match(), which skips some of the san-
- ity checks that are done by pcre2_match(), and of course does not work
- when JIT is not supported. If jitfast is specified without jit, jit=7
+ If the jitfast modifier is specified, matching is done using the JIT
+ "fast path" interface, pcre2_jit_match(), which skips some of the san-
+ ity checks that are done by pcre2_match(), and of course does not work
+ when JIT is not supported. If jitfast is specified without jit, jit=7
is assumed.
- If the jitverify modifier is specified, information about the compiled
- pattern shows whether JIT compilation was or was not successful. If
- jitverify is specified without jit, jit=7 is assumed. If JIT compila-
- tion is successful when jitverify is set, the text "(JIT)" is added to
+ If the jitverify modifier is specified, information about the compiled
+ pattern shows whether JIT compilation was or was not successful. If
+ jitverify is specified without jit, jit=7 is assumed. If JIT compila-
+ tion is successful when jitverify is set, the text "(JIT)" is added to
the first output line after a match or non match when JIT-compiled code
was actually used in the match.
@@ -945,19 +950,19 @@ PATTERN MODIFIERS
/pattern/locale=fr_FR
The given locale is set, pcre2_maketables() is called to build a set of
- character tables for the locale, and this is then passed to pcre2_com-
- pile() when compiling the regular expression. The same tables are used
- when matching the following subject lines. The locale modifier applies
+ character tables for the locale, and this is then passed to pcre2_com-
+ pile() when compiling the regular expression. The same tables are used
+ when matching the following subject lines. The locale modifier applies
only to the pattern on which it appears, but can be given in a #pattern
- command if a default is needed. Setting a locale and alternate charac-
+ command if a default is needed. Setting a locale and alternate charac-
ter tables are mutually exclusive.
Showing pattern memory
The memory modifier causes the size in bytes of the memory used to hold
- the compiled pattern to be output. This does not include the size of
- the pcre2_code block; it is just the actual compiled data. If the pat-
- tern is subsequently passed to the JIT compiler, the size of the JIT
+ the compiled pattern to be output. This does not include the size of
+ the pcre2_code block; it is just the actual compiled data. If the pat-
+ tern is subsequently passed to the JIT compiler, the size of the JIT
compiled code is also output. Here is an example:
re> /a(b)c/jit,memory
@@ -967,34 +972,34 @@ PATTERN MODIFIERS
Limiting nested parentheses
- The parens_nest_limit modifier sets a limit on the depth of nested
- parentheses in a pattern. Breaching the limit causes a compilation er-
- ror. The default for the library is set when PCRE2 is built, but
- pcre2test sets its own default of 220, which is required for running
+ The parens_nest_limit modifier sets a limit on the depth of nested
+ parentheses in a pattern. Breaching the limit causes a compilation er-
+ ror. The default for the library is set when PCRE2 is built, but
+ pcre2test sets its own default of 220, which is required for running
the standard test suite.
Limiting the pattern length
- The max_pattern_length modifier sets a limit, in code units, to the
+ The max_pattern_length modifier sets a limit, in code units, to the
length of pattern that pcre2_compile() will accept. Breaching the limit
- causes a compilation error. The default is the largest number a
+ causes a compilation error. The default is the largest number a
PCRE2_SIZE variable can hold (essentially unlimited).
Limiting the size of a compiled pattern
The max_pattern_compiled_length modifier sets a limit, in bytes, to the
amount of memory used by a compiled pattern. Breaching the limit causes
- a compilation error. The default is the largest number a PCRE2_SIZE
+ a compilation error. The default is the largest number a PCRE2_SIZE
variable can hold (essentially unlimited).
Using the POSIX wrapper API
- The posix and posix_nosub modifiers cause pcre2test to call PCRE2 via
- the POSIX wrapper API rather than its native API. When posix_nosub is
- used, the POSIX option REG_NOSUB is passed to regcomp(). The POSIX
- wrapper supports only the 8-bit library. Note that it does not imply
+ The posix and posix_nosub modifiers cause pcre2test to call PCRE2 via
+ the POSIX wrapper API rather than its native API. When posix_nosub is
+ used, the POSIX option REG_NOSUB is passed to regcomp(). The POSIX
+ wrapper supports only the 8-bit library. Note that it does not imply
POSIX matching semantics; for more detail see the pcre2posix documenta-
- tion. The following pattern modifiers set options for the regcomp()
+ tion. The following pattern modifiers set options for the regcomp()
function:
caseless REG_ICASE
@@ -1004,42 +1009,42 @@ PATTERN MODIFIERS
ucp REG_UCP ) the POSIX standard
utf REG_UTF8 )
- The regerror_buffsize modifier specifies a size for the error buffer
- that is passed to regerror() in the event of a compilation error. For
+ The regerror_buffsize modifier specifies a size for the error buffer
+ that is passed to regerror() in the event of a compilation error. For
example:
/abc/posix,regerror_buffsize=20
- This provides a means of testing the behaviour of regerror() when the
- buffer is too small for the error message. If this modifier has not
+ This provides a means of testing the behaviour of regerror() when the
+ buffer is too small for the error message. If this modifier has not
been set, a large buffer is used.
- The aftertext and allaftertext subject modifiers work as described be-
+ The aftertext and allaftertext subject modifiers work as described be-
low. All other modifiers are either ignored, with a warning message, or
cause an error.
- The pattern is passed to regcomp() as a zero-terminated string by de-
+ The pattern is passed to regcomp() as a zero-terminated string by de-
fault, but if the use_length or hex modifiers are set, the REG_PEND ex-
tension is used to pass it by length.
Testing the stack guard feature
- The stackguard modifier is used to test the use of pcre2_set_com-
- pile_recursion_guard(), a function that is provided to enable stack
- availability to be checked during compilation (see the pcre2api docu-
- mentation for details). If the number specified by the modifier is
+ The stackguard modifier is used to test the use of pcre2_set_com-
+ pile_recursion_guard(), a function that is provided to enable stack
+ availability to be checked during compilation (see the pcre2api docu-
+ mentation for details). If the number specified by the modifier is
greater than zero, pcre2_set_compile_recursion_guard() is called to set
- up callback from pcre2_compile() to a local function. The argument it
- receives is the current nesting parenthesis depth; if this is greater
+ up callback from pcre2_compile() to a local function. The argument it
+ receives is the current nesting parenthesis depth; if this is greater
than the value given by the modifier, non-zero is returned, causing the
compilation to be aborted.
Using alternative character tables
- The value specified for the tables modifier must be one of the digits
+ The value specified for the tables modifier must be one of the digits
0, 1, 2, or 3. It causes a specific set of built-in character tables to
- be passed to pcre2_compile(). This is used in the PCRE2 tests to check
- behaviour with different character tables. The digit specifies the ta-
+ be passed to pcre2_compile(). This is used in the PCRE2 tests to check
+ behaviour with different character tables. The digit specifies the ta-
bles as follows:
0 do not pass any special character tables
@@ -1050,15 +1055,15 @@ PATTERN MODIFIERS
In tables 2, some characters whose codes are greater than 128 are iden-
tified as letters, digits, spaces, etc. Tables 3 can be used only after
- a #loadtables command has loaded them from a binary file. Setting al-
+ a #loadtables command has loaded them from a binary file. Setting al-
ternate character tables and a locale are mutually exclusive.
Setting certain match controls
The following modifiers are really subject modifiers, and are described
- under "Subject Modifiers" below. However, they may be included in a
- pattern's modifier list, in which case they are applied to every sub-
- ject line that is processed with that pattern. These modifiers do not
+ under "Subject Modifiers" below. However, they may be included in a
+ pattern's modifier list, in which case they are applied to every sub-
+ ject line that is processed with that pattern. These modifiers do not
affect the compilation process.
aftertext show text after match
@@ -1086,39 +1091,39 @@ PATTERN MODIFIERS
substitute_unknown_unset use PCRE2_SUBSTITUTE_UNKNOWN_UNSET
substitute_unset_empty use PCRE2_SUBSTITUTE_UNSET_EMPTY
- These modifiers may not appear in a #pattern command. If you want them
+ These modifiers may not appear in a #pattern command. If you want them
as defaults, set them in a #subject command.
Specifying literal subject lines
- If the subject_literal modifier is present on a pattern, all the sub-
+ If the subject_literal modifier is present on a pattern, all the sub-
ject lines that it matches are taken as literal strings, with no inter-
- pretation of backslashes. It is not possible to set subject modifiers
- on such lines, but any that are set as defaults by a #subject command
+ pretation of backslashes. It is not possible to set subject modifiers
+ on such lines, but any that are set as defaults by a #subject command
are recognized.
Saving a compiled pattern
- When a pattern with the push modifier is successfully compiled, it is
- pushed onto a stack of compiled patterns, and pcre2test expects the
- next line to contain a new pattern (or a command) instead of a subject
+ When a pattern with the push modifier is successfully compiled, it is
+ pushed onto a stack of compiled patterns, and pcre2test expects the
+ next line to contain a new pattern (or a command) instead of a subject
line. This facility is used when saving compiled patterns to a file, as
- described in the section entitled "Saving and restoring compiled pat-
- terns" below. If pushcopy is used instead of push, a copy of the com-
- piled pattern is stacked, leaving the original as current, ready to
- match the following input lines. This provides a way of testing the
- pcre2_code_copy() function. The push and pushcopy modifiers are in-
- compatible with compilation modifiers such as global that act at match
+ described in the section entitled "Saving and restoring compiled pat-
+ terns" below. If pushcopy is used instead of push, a copy of the com-
+ piled pattern is stacked, leaving the original as current, ready to
+ match the following input lines. This provides a way of testing the
+ pcre2_code_copy() function. The push and pushcopy modifiers are in-
+ compatible with compilation modifiers such as global that act at match
time. Any that are specified are ignored (for the stacked copy), with a
- warning message, except for replace, which causes an error. Note that
- jitverify, which is allowed, does not carry through to any subsequent
+ warning message, except for replace, which causes an error. Note that
+ jitverify, which is allowed, does not carry through to any subsequent
matching that uses a stacked pattern.
Testing foreign pattern conversion
- The experimental foreign pattern conversion functions in PCRE2 can be
- tested by setting the convert modifier. Its argument is a colon-sepa-
- rated list of options, which set the equivalent option for the
+ The experimental foreign pattern conversion functions in PCRE2 can be
+ tested by setting the convert modifier. Its argument is a colon-sepa-
+ rated list of options, which set the equivalent option for the
pcre2_pattern_convert() function:
glob PCRE2_CONVERT_GLOB
@@ -1130,19 +1135,19 @@ PATTERN MODIFIERS
The "unset" value is useful for turning off a default that has been set
by a #pattern command. When one of these options is set, the input pat-
- tern is passed to pcre2_pattern_convert(). If the conversion is suc-
- cessful, the result is reflected in the output and then passed to
+ tern is passed to pcre2_pattern_convert(). If the conversion is suc-
+ cessful, the result is reflected in the output and then passed to
pcre2_compile(). The normal utf and no_utf_check options, if set, cause
- the PCRE2_CONVERT_UTF and PCRE2_CONVERT_NO_UTF_CHECK options to be
+ the PCRE2_CONVERT_UTF and PCRE2_CONVERT_NO_UTF_CHECK options to be
passed to pcre2_pattern_convert().
By default, the conversion function is allowed to allocate a buffer for
- its output. However, if the convert_length modifier is set to a value
- greater than zero, pcre2test passes a buffer of the given length. This
+ its output. However, if the convert_length modifier is set to a value
+ greater than zero, pcre2test passes a buffer of the given length. This
makes it possible to test the length check.
- The convert_glob_escape and convert_glob_separator modifiers can be
- used to specify the escape and separator characters for glob process-
+ The convert_glob_escape and convert_glob_separator modifiers can be
+ used to specify the escape and separator characters for glob process-
ing, overriding the defaults, which are operating-system dependent.
@@ -1153,7 +1158,7 @@ SUBJECT MODIFIERS
Setting match options
- The following modifiers set options for pcre2_match() or
+ The following modifiers set options for pcre2_match() or
pcre2_dfa_match(). See pcre2api for a description of their effects.
anchored set PCRE2_ANCHORED
@@ -1171,35 +1176,35 @@ SUBJECT MODIFIERS
partial_hard (or ph) set PCRE2_PARTIAL_HARD
partial_soft (or ps) set PCRE2_PARTIAL_SOFT
- The partial matching modifiers are provided with abbreviations because
+ The partial matching modifiers are provided with abbreviations because
they appear frequently in tests.
- If the posix or posix_nosub modifier was present on the pattern, caus-
+ If the posix or posix_nosub modifier was present on the pattern, caus-
ing the POSIX wrapper API to be used, the only option-setting modifiers
that have any effect are notbol, notempty, and noteol, causing REG_NOT-
- BOL, REG_NOTEMPTY, and REG_NOTEOL, respectively, to be passed to
+ BOL, REG_NOTEMPTY, and REG_NOTEOL, respectively, to be passed to
regexec(). The other modifiers are ignored, with a warning message.
- There is one additional modifier that can be used with the POSIX wrap-
+ There is one additional modifier that can be used with the POSIX wrap-
per. It is ignored (with a warning) if used for non-POSIX matching.
posix_startend=[:]
- This causes the subject string to be passed to regexec() using the
- REG_STARTEND option, which uses offsets to specify which part of the
- string is searched. If only one number is given, the end offset is
- passed as the end of the subject string. For more detail of REG_STAR-
- TEND, see the pcre2posix documentation. If the subject string contains
- binary zeros (coded as escapes such as \x{00} because pcre2test does
+ This causes the subject string to be passed to regexec() using the
+ REG_STARTEND option, which uses offsets to specify which part of the
+ string is searched. If only one number is given, the end offset is
+ passed as the end of the subject string. For more detail of REG_STAR-
+ TEND, see the pcre2posix documentation. If the subject string contains
+ binary zeros (coded as escapes such as \x{00} because pcre2test does
not support actual binary zeros in its input), you must use posix_star-
tend to specify its length.
Setting match controls
- The following modifiers affect the matching process or request addi-
- tional information. Some of them may also be specified on a pattern
- line (see above), in which case they apply to every subject line that
- is matched against that pattern, but can be overridden by modifiers on
+ The following modifiers affect the matching process or request addi-
+ tional information. Some of them may also be specified on a pattern
+ line (see above), in which case they apply to every subject line that
+ is matched against that pattern, but can be overridden by modifiers on
the subject.
aftertext show text after match
@@ -1249,36 +1254,36 @@ SUBJECT MODIFIERS
substitute_replacement_only use PCRE2_SUBSTITUTE_REPLACEMENT_ONLY
substitute_skip= skip substitution number n
substitute_stop= skip substitution number n and greater
- substitute_subject= specify a different subject for sub-
+ substitute_subject= specify a different subject for sub-
stitution
substitute_unknown_unset use PCRE2_SUBSTITUTE_UNKNOWN_UNSET
substitute_unset_empty use PCRE2_SUBSTITUTE_UNSET_EMPTY
zero_terminate pass the subject as zero-terminated
The effects of these modifiers are described in the following sections.
- When matching via the POSIX wrapper API, the aftertext, allaftertext,
- and ovector subject modifiers work as described below. All other modi-
+ When matching via the POSIX wrapper API, the aftertext, allaftertext,
+ and ovector subject modifiers work as described below. All other modi-
fiers are either ignored, with a warning message, or cause an error.
Showing more text
- The aftertext modifier requests that as well as outputting the part of
+ The aftertext modifier requests that as well as outputting the part of
the subject string that matched the entire pattern, pcre2test should in
addition output the remainder of the subject string. This is useful for
tests where the subject contains multiple copies of the same substring.
- The allaftertext modifier requests the same action for captured sub-
+ The allaftertext modifier requests the same action for captured sub-
strings as well as the main matched substring. In each case the remain-
der is output on the following line with a plus character following the
capture number.
- The allusedtext modifier requests that all the text that was consulted
- during a successful pattern match by the interpreter should be shown,
- for both full and partial matches. This feature is not supported for
- JIT matching, and if requested with JIT it is ignored (with a warning
- message). Setting this modifier affects the output if there is a look-
- behind at the start of a match, or, for a complete match, a lookahead
+ The allusedtext modifier requests that all the text that was consulted
+ during a successful pattern match by the interpreter should be shown,
+ for both full and partial matches. This feature is not supported for
+ JIT matching, and if requested with JIT it is ignored (with a warning
+ message). Setting this modifier affects the output if there is a look-
+ behind at the start of a match, or, for a complete match, a lookahead
at the end, or if \K is used in the pattern. Characters that precede or
- follow the start and end of the actual match are indicated in the out-
+ follow the start and end of the actual match are indicated in the out-
put by '<' or '>' characters underneath them. Here is an example:
re> /(?<=pqr)abc(?=xyz)/
@@ -1289,16 +1294,16 @@ SUBJECT MODIFIERS
Partial match: pqrabcxy
<<<
- The first, complete match shows that the matched string is "abc", with
- the preceding and following strings "pqr" and "xyz" having been con-
- sulted during the match (when processing the assertions). The partial
+ The first, complete match shows that the matched string is "abc", with
+ the preceding and following strings "pqr" and "xyz" having been con-
+ sulted during the match (when processing the assertions). The partial
match can indicate only the preceding string.
- The startchar modifier requests that the starting character for the
- match be indicated, if it is different to the start of the matched
+ The startchar modifier requests that the starting character for the
+ match be indicated, if it is different to the start of the matched
string. The only time when this occurs is when \K has been processed as
part of the match. In this situation, the output for the matched string
- is displayed from the starting character instead of from the match
+ is displayed from the starting character instead of from the match
point, with circumflex characters under the earlier characters. For ex-
ample:
@@ -1307,7 +1312,7 @@ SUBJECT MODIFIERS
0: abcxyz
^^^
- Unlike allusedtext, the startchar modifier can be used with JIT. How-
+ Unlike allusedtext, the startchar modifier can be used with JIT. How-
ever, these two modifiers are mutually exclusive.
Showing the value of all capture groups
@@ -1315,100 +1320,100 @@ SUBJECT MODIFIERS
The allcaptures modifier requests that the values of all potential cap-
tured parentheses be output after a match. By default, only those up to
the highest one actually used in the match are output (corresponding to
- the return code from pcre2_match()). Groups that did not take part in
- the match are output as "". This modifier is not relevant for
- DFA matching (which does no capturing) and does not apply when replace
+ the return code from pcre2_match()). Groups that did not take part in
+ the match are output as "". This modifier is not relevant for
+ DFA matching (which does no capturing) and does not apply when replace
is specified; it is ignored, with a warning message, if present.
Showing the entire ovector, for all outcomes
The allvector modifier requests that the entire ovector be shown, what-
ever the outcome of the match. Compare allcaptures, which shows only up
- to the maximum number of capture groups for the pattern, and then only
- for a successful complete non-DFA match. This modifier, which acts af-
- ter any match result, and also for DFA matching, provides a means of
- checking that there are no unexpected modifications to ovector fields.
- Before each match attempt, the ovector is filled with a special value,
- and if this is found in both elements of a capturing pair, "" is output. After a successful match, this applies to all
- groups after the maximum capture group for the pattern. In other cases
- it applies to the entire ovector. After a partial match, the first two
- elements are the only ones that should be set. After a DFA match, the
- amount of ovector that is used depends on the number of matches that
+ to the maximum number of capture groups for the pattern, and then only
+ for a successful complete non-DFA match. This modifier, which acts af-
+ ter any match result, and also for DFA matching, provides a means of
+ checking that there are no unexpected modifications to ovector fields.
+ Before each match attempt, the ovector is filled with a special value,
+ and if this is found in both elements of a capturing pair, "" is output. After a successful match, this applies to all
+ groups after the maximum capture group for the pattern. In other cases
+ it applies to the entire ovector. After a partial match, the first two
+ elements are the only ones that should be set. After a DFA match, the
+ amount of ovector that is used depends on the number of matches that
were found.
Testing pattern callouts
- A callout function is supplied when pcre2test calls the library match-
- ing functions, unless callout_none is specified. Its behaviour can be
- controlled by various modifiers listed above whose names begin with
- callout_. Details are given in the section entitled "Callouts" below.
- Testing callouts from pcre2_substitute() is described separately in
+ A callout function is supplied when pcre2test calls the library match-
+ ing functions, unless callout_none is specified. Its behaviour can be
+ controlled by various modifiers listed above whose names begin with
+ callout_. Details are given in the section entitled "Callouts" below.
+ Testing callouts from pcre2_substitute() is described separately in
"Testing the substitution function" below.
Finding all matches in a string
Searching for all possible matches within a subject can be requested by
- the global or altglobal modifier. After finding a match, the matching
- function is called again to search the remainder of the subject. The
- difference between global and altglobal is that the former uses the
- start_offset argument to pcre2_match() or pcre2_dfa_match() to start
- searching at a new point within the entire string (which is what Perl
+ the global or altglobal modifier. After finding a match, the matching
+ function is called again to search the remainder of the subject. The
+ difference between global and altglobal is that the former uses the
+ start_offset argument to pcre2_match() or pcre2_dfa_match() to start
+ searching at a new point within the entire string (which is what Perl
does), whereas the latter passes over a shortened subject. This makes a
difference to the matching process if the pattern begins with a lookbe-
hind assertion (including \b or \B).
- If an empty string is matched, the next match is done with the
- PCRE2_NOTEMPTY_ATSTART flag set, in order to search for another, non-
- empty, match at the same point in the subject. This imitates the way
+ If an empty string is matched, the next match is done with the
+ PCRE2_NOTEMPTY_ATSTART flag set, in order to search for another, non-
+ empty, match at the same point in the subject. This imitates the way
Perl handles such cases when using the /g modifier or the split() func-
tion.
Testing substring extraction functions
- The copy and get modifiers can be used to test the pcre2_sub-
+ The copy and get modifiers can be used to test the pcre2_sub-
string_copy_xxx() and pcre2_substring_get_xxx() functions. They can be
given more than once, and each can specify a capture group name or num-
ber, for example:
abcd\=copy=1,copy=3,get=G1
- If the #subject command is used to set default copy and/or get lists,
- these can be unset by specifying a negative number to cancel all num-
+ If the #subject command is used to set default copy and/or get lists,
+ these can be unset by specifying a negative number to cancel all num-
bered groups and an empty name to cancel all named groups.
- The getall modifier tests pcre2_substring_list_get(), which extracts
+ The getall modifier tests pcre2_substring_list_get(), which extracts
all captured substrings.
- If the subject line is successfully matched, the substrings extracted
- by the convenience functions are output with C, G, or L after the
- string number instead of a colon. This is in addition to the normal
- full list. The string length (that is, the return from the extraction
+ If the subject line is successfully matched, the substrings extracted
+ by the convenience functions are output with C, G, or L after the
+ string number instead of a colon. This is in addition to the normal
+ full list. The string length (that is, the return from the extraction
function) is given in parentheses after each substring, followed by the
name when the extraction was by name.
Testing the substitution function
- If the replace modifier is set, the pcre2_substitute() function is
- called instead of one of the matching functions (or after one call of
- pcre2_match() in the case of PCRE2_SUBSTITUTE_MATCHED). Note that re-
- placement strings cannot contain commas, because a comma signifies the
- end of a modifier. This is not thought to be an issue in a test pro-
+ If the replace modifier is set, the pcre2_substitute() function is
+ called instead of one of the matching functions (or after one call of
+ pcre2_match() in the case of PCRE2_SUBSTITUTE_MATCHED). Note that re-
+ placement strings cannot contain commas, because a comma signifies the
+ end of a modifier. This is not thought to be an issue in a test pro-
gram.
- Specifying a completely empty replacement string disables this modi-
- fier. However, it is possible to specify an empty replacement by pro-
- viding a buffer length, as described below, for an otherwise empty re-
+ Specifying a completely empty replacement string disables this modi-
+ fier. However, it is possible to specify an empty replacement by pro-
+ viding a buffer length, as described below, for an otherwise empty re-
placement.
- Unlike subject strings, pcre2test does not process replacement strings
- for escape sequences. In UTF mode, a replacement string is checked to
- see if it is a valid UTF-8 string. If so, it is correctly converted to
- a UTF string of the appropriate code unit width. If it is not a valid
- UTF-8 string, the individual code units are copied directly. This pro-
+ Unlike subject strings, pcre2test does not process replacement strings
+ for escape sequences. In UTF mode, a replacement string is checked to
+ see if it is a valid UTF-8 string. If so, it is correctly converted to
+ a UTF string of the appropriate code unit width. If it is not a valid
+ UTF-8 string, the individual code units are copied directly. This pro-
vides a means of passing an invalid UTF-8 string for testing purposes.
- The following modifiers set options (in additional to the normal match
+ The following modifiers set options (in additional to the normal match
options) for pcre2_substitute():
global PCRE2_SUBSTITUTE_GLOBAL
@@ -1422,8 +1427,8 @@ SUBJECT MODIFIERS
See the pcre2api documentation for details of these options.
- After a successful substitution, the modified string is output, pre-
- ceded by the number of replacements. This may be zero if there were no
+ After a successful substitution, the modified string is output, pre-
+ ceded by the number of replacements. This may be zero if there were no
matches. Here is a simple example of a substitution test:
/abc/replace=xxx
@@ -1432,12 +1437,12 @@ SUBJECT MODIFIERS
=abc=abc=\=global
2: =xxx=xxx=
- Subject and replacement strings should be kept relatively short (fewer
- than 256 characters) for substitution tests, as fixed-size buffers are
- used. To make it easy to test for buffer overflow, if the replacement
- string starts with a number in square brackets, that number is passed
- to pcre2_substitute() as the size of the output buffer, with the re-
- placement string starting at the next character. Here is an example
+ Subject and replacement strings should be kept relatively short (fewer
+ than 256 characters) for substitution tests, as fixed-size buffers are
+ used. To make it easy to test for buffer overflow, if the replacement
+ string starts with a number in square brackets, that number is passed
+ to pcre2_substitute() as the size of the output buffer, with the re-
+ placement string starting at the next character. Here is an example
that tests the edge case:
/abc/
@@ -1447,12 +1452,12 @@ SUBJECT MODIFIERS
Failed: error -48: no more memory
The default action of pcre2_substitute() is to return PCRE2_ER-
- ROR_NOMEMORY when the output buffer is too small. However, if the
- PCRE2_SUBSTITUTE_OVERFLOW_LENGTH option is set (by using the substi-
+ ROR_NOMEMORY when the output buffer is too small. However, if the
+ PCRE2_SUBSTITUTE_OVERFLOW_LENGTH option is set (by using the substi-
tute_overflow_length modifier), pcre2_substitute() continues to go
- through the motions of matching and substituting (but not doing any
- callouts), in order to compute the size of buffer that is required.
- When this happens, pcre2test shows the required buffer length (which
+ through the motions of matching and substituting (but not doing any
+ callouts), in order to compute the size of buffer that is required.
+ When this happens, pcre2test shows the required buffer length (which
includes space for the trailing zero) as part of the error message. For
example:
@@ -1461,21 +1466,21 @@ SUBJECT MODIFIERS
Failed: error -48: no more memory: 10 code units are needed
A replacement string is ignored with POSIX and DFA matching. Specifying
- partial matching provokes an error return ("bad option value") from
+ partial matching provokes an error return ("bad option value") from
pcre2_substitute().
- The substitute_subject modifier may be used to test the use of the
+ The substitute_subject modifier may be used to test the use of the
PCRE2 API, in which a client calls pcre2_match() followed by pcre2_sub-
stitute() with PCRE2_SUBSTITUTE_MATCHED, but the client performs an un-
- expected and unsupported modification of the subject buffer in-place,
+ expected and unsupported modification of the subject buffer in-place,
in between the match and substitution.
Testing substitute callouts
If the substitute_callout modifier is set, a substitution callout func-
- tion is set up. The null_context modifier must not be set, because the
- address of the callout function is passed in a match context. When the
- callout function is called (after each substitution), details of the
+ tion is set up. The null_context modifier must not be set, because the
+ address of the callout function is passed in a match context. When the
+ callout function is called (after each substitution), details of the
input and output strings are output. For example:
/abc/g,replace=<$0>,substitute_callout
@@ -1484,19 +1489,19 @@ SUBJECT MODIFIERS
2(1) Old 6 9 "abc" New 8 13 ""
2: defpqr
- The first number on each callout line is the count of matches. The
+ The first number on each callout line is the count of matches. The
parenthesized number is the number of pairs that are set in the ovector
- (that is, one more than the number of capturing groups that were set).
+ (that is, one more than the number of capturing groups that were set).
Then are listed the offsets of the old substring, its contents, and the
same for the replacement.
- By default, the substitution callout function returns zero, which ac-
- cepts the replacement and causes matching to continue if /g was used.
- Two further modifiers can be used to test other return values. If sub-
- stitute_skip is set to a value greater than zero the callout function
- returns +1 for the match of that number, and similarly substitute_stop
- returns -1. These cause the replacement to be rejected, and -1 causes
- no further matching to take place. If either of them are set, substi-
+ By default, the substitution callout function returns zero, which ac-
+ cepts the replacement and causes matching to continue if /g was used.
+ Two further modifiers can be used to test other return values. If sub-
+ stitute_skip is set to a value greater than zero the callout function
+ returns +1 for the match of that number, and similarly substitute_stop
+ returns -1. These cause the replacement to be rejected, and -1 causes
+ no further matching to take place. If either of them are set, substi-
tute_callout is assumed. For example:
/abc/g,replace=<$0>,substitute_skip=1
@@ -1514,193 +1519,193 @@ SUBJECT MODIFIERS
Testing substitute case callouts
- If the substitute_case_callout modifier is set, a substitution case
- callout function is set up. The callout function is called for each
+ If the substitute_case_callout modifier is set, a substitution case
+ callout function is set up. The callout function is called for each
substituted chunk which is to be case-transformed.
The callout function passed is a fixed function with implementation for
- certain behaviours: inputs which shrink when case-transformed; inputs
+ certain behaviours: inputs which shrink when case-transformed; inputs
which grow; inputs with distinct upper/lower/titlecase forms. The char-
acters which are not special-cased for testing purposes are left unmod-
ified, as if they are caseless characters.
Setting the JIT stack size
- The jitstack modifier provides a way of setting the maximum stack size
- that is used by the just-in-time optimization code. It is ignored if
- JIT optimization is not being used. The value is a number of kibibytes
- (units of 1024 bytes). Setting zero reverts to the default of 32KiB.
+ The jitstack modifier provides a way of setting the maximum stack size
+ that is used by the just-in-time optimization code. It is ignored if
+ JIT optimization is not being used. The value is a number of kibibytes
+ (units of 1024 bytes). Setting zero reverts to the default of 32KiB.
Providing a stack that is larger than the default is necessary only for
- very complicated patterns. If jitstack is set non-zero on a subject
+ very complicated patterns. If jitstack is set non-zero on a subject
line it overrides any value that was set on the pattern.
Setting heap, match, and depth limits
- The heap_limit, match_limit, and depth_limit modifiers set the appro-
- priate limits in the match context. These values are ignored when the
+ The heap_limit, match_limit, and depth_limit modifiers set the appro-
+ priate limits in the match context. These values are ignored when the
find_limits or find_limits_noheap modifier is specified.
Finding minimum limits
- If the find_limits modifier is present on a subject line, pcre2test
- calls the relevant matching function several times, setting different
- values in the match context via pcre2_set_heap_limit(),
- pcre2_set_match_limit(), or pcre2_set_depth_limit() until it finds the
- smallest value for each parameter that allows the match to complete
+ If the find_limits modifier is present on a subject line, pcre2test
+ calls the relevant matching function several times, setting different
+ values in the match context via pcre2_set_heap_limit(),
+ pcre2_set_match_limit(), or pcre2_set_depth_limit() until it finds the
+ smallest value for each parameter that allows the match to complete
without a "limit exceeded" error. The match itself may succeed or fail.
An alternative modifier, find_limits_noheap, omits the heap limit. This
- is used in the standard tests, because the minimum heap limit varies
- between systems. If JIT is being used, only the match limit is rele-
+ is used in the standard tests, because the minimum heap limit varies
+ between systems. If JIT is being used, only the match limit is rele-
vant, and the other two are automatically omitted.
When using this modifier, the pattern should not contain any limit set-
- tings such as (*LIMIT_MATCH=...) within it. If such a setting is
+ tings such as (*LIMIT_MATCH=...) within it. If such a setting is
present and is lower than the minimum matching value, the minimum value
- cannot be found because pcre2_set_match_limit() etc. are only able to
+ cannot be found because pcre2_set_match_limit() etc. are only able to
reduce the value of an in-pattern limit; they cannot increase it.
- For non-DFA matching, the minimum depth_limit number is a measure of
+ For non-DFA matching, the minimum depth_limit number is a measure of
how much nested backtracking happens (that is, how deeply the pattern's
- tree is searched). In the case of DFA matching, depth_limit controls
- the depth of recursive calls of the internal function that is used for
+ tree is searched). In the case of DFA matching, depth_limit controls
+ the depth of recursive calls of the internal function that is used for
handling pattern recursion, lookaround assertions, and atomic groups.
For non-DFA matching, the match_limit number is a measure of the amount
of backtracking that takes place, and learning the minimum value can be
- instructive. For most simple matches, the number is quite small, but
- for patterns with very large numbers of matching possibilities, it can
- become large very quickly with increasing length of subject string. In
- the case of DFA matching, match_limit controls the total number of
+ instructive. For most simple matches, the number is quite small, but
+ for patterns with very large numbers of matching possibilities, it can
+ become large very quickly with increasing length of subject string. In
+ the case of DFA matching, match_limit controls the total number of
calls, both recursive and non-recursive, to the internal matching func-
tion, thus controlling the overall amount of computing resource that is
used.
- For both kinds of matching, the heap_limit number, which is in
- kibibytes (units of 1024 bytes), limits the amount of heap memory used
+ For both kinds of matching, the heap_limit number, which is in
+ kibibytes (units of 1024 bytes), limits the amount of heap memory used
for matching.
Showing MARK names
The mark modifier causes the names from backtracking control verbs that
- are returned from calls to pcre2_match() to be displayed. If a mark is
- returned for a match, non-match, or partial match, pcre2test shows it.
- For a match, it is on a line by itself, tagged with "MK:". Otherwise,
+ are returned from calls to pcre2_match() to be displayed. If a mark is
+ returned for a match, non-match, or partial match, pcre2test shows it.
+ For a match, it is on a line by itself, tagged with "MK:". Otherwise,
it is added to the non-match message.
Showing memory usage
- The memory modifier causes pcre2test to log the sizes of all heap mem-
- ory allocation and freeing calls that occur during a call to
- pcre2_match() or pcre2_dfa_match(). In the latter case, heap memory is
- used only when a match requires more internal workspace that the de-
- fault allocation on the stack, so in many cases there will be no out-
- put. No heap memory is allocated during matching with JIT. For this
+ The memory modifier causes pcre2test to log the sizes of all heap mem-
+ ory allocation and freeing calls that occur during a call to
+ pcre2_match() or pcre2_dfa_match(). In the latter case, heap memory is
+ used only when a match requires more internal workspace that the de-
+ fault allocation on the stack, so in many cases there will be no out-
+ put. No heap memory is allocated during matching with JIT. For this
modifier to work, the null_context modifier must not be set on both the
pattern and the subject, though it can be set on one or the other.
Showing the heap frame overall vector size
- The heapframes_size modifier is relevant for matches using
+ The heapframes_size modifier is relevant for matches using
pcre2_match() without JIT. After a match has run (whether successful or
- not) the size, in bytes, of the allocated heap frames vector that is
- left attached to the match data block is shown. If the matching action
- involved several calls to pcre2_match() (for example, global matching
+ not) the size, in bytes, of the allocated heap frames vector that is
+ left attached to the match data block is shown. If the matching action
+ involved several calls to pcre2_match() (for example, global matching
or for timing) only the final value is shown.
- This modifier is ignored, with a warning, for POSIX or DFA matching.
+ This modifier is ignored, with a warning, for POSIX or DFA matching.
JIT matching does not use the heap frames vector, so the size is always
- zero, unless there was a previous non-JIT match. Note that specifing a
+ zero, unless there was a previous non-JIT match. Note that specifing a
size of zero for the output vector (see below) causes pcre2test to free
its match data block (and associated heap frames vector) and allocate a
new one.
Setting a starting offset
- The offset modifier sets an offset in the subject string at which
+ The offset modifier sets an offset in the subject string at which
matching starts. Its value is a number of code units, not characters.
Setting an offset limit
- The offset_limit modifier sets a limit for unanchored matches. If a
+ The offset_limit modifier sets a limit for unanchored matches. If a
match cannot be found starting at or before this offset in the subject,
a "no match" return is given. The data value is a number of code units,
- not characters. When this modifier is used, the use_offset_limit modi-
+ not characters. When this modifier is used, the use_offset_limit modi-
fier must have been set for the pattern; if not, an error is generated.
Setting the size of the output vector
- The ovector modifier applies only to the subject line in which it ap-
+ The ovector modifier applies only to the subject line in which it ap-
pears, though of course it can also be used to set a default in a #sub-
- ject command. It specifies the number of pairs of offsets that are
+ ject command. It specifies the number of pairs of offsets that are
available for storing matching information. The default is 15.
- A value of zero is useful when testing the POSIX API because it causes
+ A value of zero is useful when testing the POSIX API because it causes
regexec() to be called with a NULL capture vector. When not testing the
- POSIX API, a value of zero is used to cause pcre2_match_data_cre-
- ate_from_pattern() to be called, in order to create a new match block
- of exactly the right size for the pattern. (It is not possible to cre-
- ate a match block with a zero-length ovector; there is always at least
+ POSIX API, a value of zero is used to cause pcre2_match_data_cre-
+ ate_from_pattern() to be called, in order to create a new match block
+ of exactly the right size for the pattern. (It is not possible to cre-
+ ate a match block with a zero-length ovector; there is always at least
one pair of offsets.) The old match data block is freed.
Passing the subject as zero-terminated
By default, the subject string is passed to a native API matching func-
tion with its correct length. In order to test the facility for passing
- a zero-terminated string, the zero_terminate modifier is provided. It
- causes the length to be passed as PCRE2_ZERO_TERMINATED. When matching
+ a zero-terminated string, the zero_terminate modifier is provided. It
+ causes the length to be passed as PCRE2_ZERO_TERMINATED. When matching
via the POSIX interface, this modifier is ignored, with a warning.
- When testing pcre2_substitute(), this modifier also has the effect of
+ When testing pcre2_substitute(), this modifier also has the effect of
passing the replacement string as zero-terminated.
Passing a NULL context, subject, or replacement
- Normally, pcre2test passes a context block to pcre2_match(),
- pcre2_dfa_match(), pcre2_jit_match() or pcre2_substitute(). If the
- null_context modifier is set, however, NULL is passed. This is for
- testing that the matching and substitution functions behave correctly
- in this case (they use default values). This modifier cannot be used
- with the find_limits, find_limits_noheap, or substitute_callout modi-
+ Normally, pcre2test passes a context block to pcre2_match(),
+ pcre2_dfa_match(), pcre2_jit_match() or pcre2_substitute(). If the
+ null_context modifier is set, however, NULL is passed. This is for
+ testing that the matching and substitution functions behave correctly
+ in this case (they use default values). This modifier cannot be used
+ with the find_limits, find_limits_noheap, or substitute_callout modi-
fiers.
- Similarly, for testing purposes, if the null_subject or null_replace-
- ment modifier is set, the subject or replacement string pointers are
+ Similarly, for testing purposes, if the null_subject or null_replace-
+ ment modifier is set, the subject or replacement string pointers are
passed as NULL, respectively, to the relevant functions.
THE ALTERNATIVE MATCHING FUNCTION
- By default, pcre2test uses the standard PCRE2 matching function,
+ By default, pcre2test uses the standard PCRE2 matching function,
pcre2_match() to match each subject line. PCRE2 also supports an alter-
- native matching function, pcre2_dfa_match(), which operates in a dif-
- ferent way, and has some restrictions. The differences between the two
+ native matching function, pcre2_dfa_match(), which operates in a dif-
+ ferent way, and has some restrictions. The differences between the two
functions are described in the pcre2matching documentation.
- If the dfa modifier is set, the alternative matching function is used.
- This function finds all possible matches at a given point in the sub-
- ject. If, however, the dfa_shortest modifier is set, processing stops
- after the first match is found. This is always the shortest possible
+ If the dfa modifier is set, the alternative matching function is used.
+ This function finds all possible matches at a given point in the sub-
+ ject. If, however, the dfa_shortest modifier is set, processing stops
+ after the first match is found. This is always the shortest possible
match.
DEFAULT OUTPUT FROM pcre2test
- This section describes the output when the normal matching function,
+ This section describes the output when the normal matching function,
pcre2_match(), is being used.
- When a match succeeds, pcre2test outputs the list of captured sub-
- strings, starting with number 0 for the string that matched the whole
+ When a match succeeds, pcre2test outputs the list of captured sub-
+ strings, starting with number 0 for the string that matched the whole
pattern. Otherwise, it outputs "No match" when the return is PCRE2_ER-
- ROR_NOMATCH, or "Partial match:" followed by the partially matching
- substring when the return is PCRE2_ERROR_PARTIAL. (Note that this is
- the entire substring that was inspected during the partial match; it
- may include characters before the actual match start if a lookbehind
+ ROR_NOMATCH, or "Partial match:" followed by the partially matching
+ substring when the return is PCRE2_ERROR_PARTIAL. (Note that this is
+ the entire substring that was inspected during the partial match; it
+ may include characters before the actual match start if a lookbehind
assertion, \K, \b, or \B was involved.)
For any other return, pcre2test outputs the PCRE2 negative error number
- and a short descriptive phrase. If the error is a failed UTF string
- check, the code unit offset of the start of the failing character is
+ and a short descriptive phrase. If the error is a failed UTF string
+ check, the code unit offset of the start of the failing character is
also output. Here is an example of an interactive pcre2test run.
$ pcre2test
@@ -1716,8 +1721,8 @@ DEFAULT OUTPUT FROM pcre2test
Unset capturing substrings that are not followed by one that is set are
not shown by pcre2test unless the allcaptures modifier is specified. In
the following example, there are two capturing substrings, but when the
- first data line is matched, the second, unset substring is not shown.
- An "internal" unset substring is shown as "", as for the second
+ first data line is matched, the second, unset substring is not shown.
+ An "internal" unset substring is shown as "", as for the second
data line.
re> /(a)|(b)/
@@ -1729,11 +1734,11 @@ DEFAULT OUTPUT FROM pcre2test
1:
2: b
- If the strings contain any non-printing characters, they are output as
- \xhh escapes if the value is less than 256 and UTF mode is not set.
+ If the strings contain any non-printing characters, they are output as
+ \xhh escapes if the value is less than 256 and UTF mode is not set.
Otherwise they are output as \x{hh...} escapes. See below for the defi-
- nition of non-printing characters. If the aftertext modifier is set,
- the output for substring 0 is followed by the rest of the subject
+ nition of non-printing characters. If the aftertext modifier is set,
+ the output for substring 0 is followed by the rest of the subject
string, identified by "0+" like this:
re> /cat/aftertext
@@ -1753,8 +1758,8 @@ DEFAULT OUTPUT FROM pcre2test
0: ipp
1: pp
- "No match" is output only if the first match attempt fails. Here is an
- example of a failure message (the offset 4 that is specified by the
+ "No match" is output only if the first match attempt fails. Here is an
+ example of a failure message (the offset 4 that is specified by the
offset modifier is past the end of the subject string):
re> /xyz/
@@ -1762,7 +1767,7 @@ DEFAULT OUTPUT FROM pcre2test
Error -24 (bad offset value)
Note that whereas patterns can be continued over several lines (a plain
- ">" prompt is used for continuations), subject lines may not. However
+ ">" prompt is used for continuations), subject lines may not. However
newlines can be included in a subject by means of the \n escape (or \r,
\r\n, etc., depending on the newline sequence setting).
@@ -1770,7 +1775,7 @@ DEFAULT OUTPUT FROM pcre2test
OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION
When the alternative matching function, pcre2_dfa_match(), is used, the
- output consists of a list of all the matches that start at the first
+ output consists of a list of all the matches that start at the first
point in the subject where there is at least one match. For example:
re> /(tang|tangerine|tan)/
@@ -1779,11 +1784,11 @@ OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION
1: tang
2: tan
- Using the normal matching function on this data finds only "tang". The
- longest matching string is always given first (and numbered zero). Af-
- ter a PCRE2_ERROR_PARTIAL return, the output is "Partial match:", fol-
+ Using the normal matching function on this data finds only "tang". The
+ longest matching string is always given first (and numbered zero). Af-
+ ter a PCRE2_ERROR_PARTIAL return, the output is "Partial match:", fol-
lowed by the partially matching substring. Note that this is the entire
- substring that was inspected during the partial match; it may include
+ substring that was inspected during the partial match; it may include
characters before the actual match start if a lookbehind assertion, \b,
or \B was involved. (\K is not supported for DFA matching.)
@@ -1799,16 +1804,16 @@ OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION
1: tan
0: tan
- The alternative matching function does not support substring capture,
- so the modifiers that are concerned with captured substrings are not
+ The alternative matching function does not support substring capture,
+ so the modifiers that are concerned with captured substrings are not
relevant.
RESTARTING AFTER A PARTIAL MATCH
- When the alternative matching function has given the PCRE2_ERROR_PAR-
+ When the alternative matching function has given the PCRE2_ERROR_PAR-
TIAL return, indicating that the subject partially matched the pattern,
- you can restart the match with additional subject data by means of the
+ you can restart the match with additional subject data by means of the
dfa_restart modifier. For example:
re> /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/
@@ -1817,37 +1822,37 @@ RESTARTING AFTER A PARTIAL MATCH
data> n05\=dfa,dfa_restart
0: n05
- For further information about partial matching, see the pcre2partial
+ For further information about partial matching, see the pcre2partial
documentation.
CALLOUTS
If the pattern contains any callout requests, pcre2test's callout func-
- tion is called during matching unless callout_none is specified. This
+ tion is called during matching unless callout_none is specified. This
works with both matching functions, and with JIT, though there are some
- differences in behaviour. The output for callouts with numerical argu-
+ differences in behaviour. The output for callouts with numerical argu-
ments and those with string arguments is slightly different.
Callouts with numerical arguments
By default, the callout function displays the callout number, the start
- and current positions in the subject text at the callout time, and the
+ and current positions in the subject text at the callout time, and the
next pattern item to be tested. For example:
--->pqrabcdef
0 ^ ^ \d
- This output indicates that callout number 0 occurred for a match at-
- tempt starting at the fourth character of the subject string, when the
- pointer was at the seventh character, and when the next pattern item
- was \d. Just one circumflex is output if the start and current posi-
+ This output indicates that callout number 0 occurred for a match at-
+ tempt starting at the fourth character of the subject string, when the
+ pointer was at the seventh character, and when the next pattern item
+ was \d. Just one circumflex is output if the start and current posi-
tions are the same, or if the current position precedes the start posi-
tion, which can happen if the callout is in a lookbehind assertion.
Callouts numbered 255 are assumed to be automatic callouts, inserted as
a result of the auto_callout pattern modifier. In this case, instead of
- showing the callout number, the offset in the pattern, preceded by a
+ showing the callout number, the offset in the pattern, preceded by a
plus, is output. For example:
re> /\d?[A-E]\*/auto_callout
@@ -1874,17 +1879,17 @@ CALLOUTS
+12 ^ ^
0: abc
- The mark changes between matching "a" and "b", but stays the same for
- the rest of the match, so nothing more is output. If, as a result of
- backtracking, the mark reverts to being unset, the text "" is
+ The mark changes between matching "a" and "b", but stays the same for
+ the rest of the match, so nothing more is output. If, as a result of
+ backtracking, the mark reverts to being unset, the text "" is
output.
Callouts with string arguments
The output for a callout with a string argument is similar, except that
- instead of outputting a callout number before the position indicators,
- the callout string and its offset in the pattern string are output be-
- fore the reflection of the subject string, and the subject string is
+ instead of outputting a callout number before the position indicators,
+ the callout string and its offset in the pattern string are output be-
+ fore the reflection of the subject string, and the subject string is
reflected for each callout. For example:
re> /^ab(?C'first')cd(?C"second")ef/
@@ -1900,26 +1905,26 @@ CALLOUTS
Callout modifiers
- The callout function in pcre2test returns zero (carry on matching) by
- default, but you can use a callout_fail modifier in a subject line to
+ The callout function in pcre2test returns zero (carry on matching) by
+ default, but you can use a callout_fail modifier in a subject line to
change this and other parameters of the callout (see below).
If the callout_capture modifier is set, the current captured groups are
output when a callout occurs. This is useful only for non-DFA matching,
- as pcre2_dfa_match() does not support capturing, so no captures are
+ as pcre2_dfa_match() does not support capturing, so no captures are
ever shown.
The normal callout output, showing the callout number or pattern offset
- (as described above) is suppressed if the callout_no_where modifier is
+ (as described above) is suppressed if the callout_no_where modifier is
set.
- When using the interpretive matching function pcre2_match() without
- JIT, setting the callout_extra modifier causes additional output from
- pcre2test's callout function to be generated. For the first callout in
- a match attempt at a new starting position in the subject, "New match
- attempt" is output. If there has been a backtrack since the last call-
+ When using the interpretive matching function pcre2_match() without
+ JIT, setting the callout_extra modifier causes additional output from
+ pcre2test's callout function to be generated. For the first callout in
+ a match attempt at a new starting position in the subject, "New match
+ attempt" is output. If there has been a backtrack since the last call-
out (or start of matching if this is the first callout), "Backtrack" is
- output, followed by "No other matching paths" if the backtrack ended
+ output, followed by "No other matching paths" if the backtrack ended
the previous match attempt. For example:
re> /(a+)b/auto_callout,no_start_optimize,no_auto_possess
@@ -1956,86 +1961,86 @@ CALLOUTS
+1 ^ a+
No match
- Notice that various optimizations must be turned off if you want all
- possible matching paths to be scanned. If no_start_optimize is not
- used, there is an immediate "no match", without any callouts, because
- the starting optimization fails to find "b" in the subject, which it
- knows must be present for any match. If no_auto_possess is not used,
- the "a+" item is turned into "a++", which reduces the number of back-
+ Notice that various optimizations must be turned off if you want all
+ possible matching paths to be scanned. If no_start_optimize is not
+ used, there is an immediate "no match", without any callouts, because
+ the starting optimization fails to find "b" in the subject, which it
+ knows must be present for any match. If no_auto_possess is not used,
+ the "a+" item is turned into "a++", which reduces the number of back-
tracks.
- The callout_extra modifier has no effect if used with the DFA matching
+ The callout_extra modifier has no effect if used with the DFA matching
function, or with JIT.
Return values from callouts
- The default return from the callout function is zero, which allows
+ The default return from the callout function is zero, which allows
matching to continue. The callout_fail modifier can be given one or two
numbers. If there is only one number, 1 is returned instead of 0 (caus-
ing matching to backtrack) when a callout of that number is reached. If
- two numbers (:) are given, 1 is returned when callout is
- reached and there have been at least callouts. The callout_error
+ two numbers (:) are given, 1 is returned when callout is
+ reached and there have been at least callouts. The callout_error
modifier is similar, except that PCRE2_ERROR_CALLOUT is returned, caus-
- ing the entire matching process to be aborted. If both these modifiers
- are set for the same callout number, callout_error takes precedence.
- Note that callouts with string arguments are always given the number
+ ing the entire matching process to be aborted. If both these modifiers
+ are set for the same callout number, callout_error takes precedence.
+ Note that callouts with string arguments are always given the number
zero.
- The callout_data modifier can be given an unsigned or a negative num-
- ber. This is set as the "user data" that is passed to the matching
- function, and passed back when the callout function is invoked. Any
- value other than zero is used as a return from pcre2test's callout
+ The callout_data modifier can be given an unsigned or a negative num-
+ ber. This is set as the "user data" that is passed to the matching
+ function, and passed back when the callout function is invoked. Any
+ value other than zero is used as a return from pcre2test's callout
function.
Inserting callouts can be helpful when using pcre2test to check compli-
- cated regular expressions. For further information about callouts, see
+ cated regular expressions. For further information about callouts, see
the pcre2callout documentation.
NON-PRINTING CHARACTERS
When pcre2test is outputting text in the compiled version of a pattern,
- bytes other than 32-126 are always treated as non-printing characters
+ bytes other than 32-126 are always treated as non-printing characters
and are therefore shown as hex escapes.
- When pcre2test is outputting text that is a matched part of a subject
- string, it behaves in the same way, unless a different locale has been
- set for the pattern (using the locale modifier). In this case, the is-
+ When pcre2test is outputting text that is a matched part of a subject
+ string, it behaves in the same way, unless a different locale has been
+ set for the pattern (using the locale modifier). In this case, the is-
print() function is used to distinguish printing and non-printing char-
acters.
SAVING AND RESTORING COMPILED PATTERNS
- It is possible to save compiled patterns on disc or elsewhere, and re-
- load them later, subject to a number of restrictions. JIT data cannot
- be saved. The host on which the patterns are reloaded must be running
+ It is possible to save compiled patterns on disc or elsewhere, and re-
+ load them later, subject to a number of restrictions. JIT data cannot
+ be saved. The host on which the patterns are reloaded must be running
the same version of PCRE2, with the same code unit width, and must also
- have the same endianness, pointer width and PCRE2_SIZE type. Before
- compiled patterns can be saved they must be serialized, that is, con-
- verted to a stream of bytes. A single byte stream may contain any num-
- ber of compiled patterns, but they must all use the same character ta-
- bles. A single copy of the tables is included in the byte stream (its
+ have the same endianness, pointer width and PCRE2_SIZE type. Before
+ compiled patterns can be saved they must be serialized, that is, con-
+ verted to a stream of bytes. A single byte stream may contain any num-
+ ber of compiled patterns, but they must all use the same character ta-
+ bles. A single copy of the tables is included in the byte stream (its
size is 1088 bytes).
- The functions whose names begin with pcre2_serialize_ are used for se-
- rializing and de-serializing. They are described in the pcre2serialize
- documentation. In this section we describe the features of pcre2test
+ The functions whose names begin with pcre2_serialize_ are used for se-
+ rializing and de-serializing. They are described in the pcre2serialize
+ documentation. In this section we describe the features of pcre2test
that can be used to test these functions.
- Note that "serialization" in PCRE2 does not convert compiled patterns
- to an abstract format like Java or .NET. It just makes a reloadable
+ Note that "serialization" in PCRE2 does not convert compiled patterns
+ to an abstract format like Java or .NET. It just makes a reloadable
byte code stream. Hence the restrictions on reloading mentioned above.
- In pcre2test, when a pattern with push modifier is successfully com-
- piled, it is pushed onto a stack of compiled patterns, and pcre2test
- expects the next line to contain a new pattern (or command) instead of
+ In pcre2test, when a pattern with push modifier is successfully com-
+ piled, it is pushed onto a stack of compiled patterns, and pcre2test
+ expects the next line to contain a new pattern (or command) instead of
a subject line. By contrast, the pushcopy modifier causes a copy of the
- compiled pattern to be stacked, leaving the original available for im-
- mediate matching. By using push and/or pushcopy, a number of patterns
- can be compiled and retained. These modifiers are incompatible with
+ compiled pattern to be stacked, leaving the original available for im-
+ mediate matching. By using push and/or pushcopy, a number of patterns
+ can be compiled and retained. These modifiers are incompatible with
posix, and control modifiers that act at match time are ignored (with a
- message) for the stacked patterns. The jitverify modifier applies only
+ message) for the stacked patterns. The jitverify modifier applies only
at compile time.
The command
@@ -2043,21 +2048,21 @@ SAVING AND RESTORING COMPILED PATTERNS
#save
causes all the stacked patterns to be serialized and the result written
- to the named file. Afterwards, all the stacked patterns are freed. The
+ to the named file. Afterwards, all the stacked patterns are freed. The
command
#load
- reads the data in the file, and then arranges for it to be de-serial-
- ized, with the resulting compiled patterns added to the pattern stack.
- The pattern on the top of the stack can be retrieved by the #pop com-
- mand, which must be followed by lines of subjects that are to be
- matched with the pattern, terminated as usual by an empty line or end
- of file. This command may be followed by a modifier list containing
- only control modifiers that act after a pattern has been compiled. In
- particular, hex, posix, posix_nosub, push, and pushcopy are not al-
- lowed, nor are any option-setting modifiers. The JIT modifiers are,
- however permitted. Here is an example that saves and reloads two pat-
+ reads the data in the file, and then arranges for it to be de-serial-
+ ized, with the resulting compiled patterns added to the pattern stack.
+ The pattern on the top of the stack can be retrieved by the #pop com-
+ mand, which must be followed by lines of subjects that are to be
+ matched with the pattern, terminated as usual by an empty line or end
+ of file. This command may be followed by a modifier list containing
+ only control modifiers that act after a pattern has been compiled. In
+ particular, hex, posix, posix_nosub, push, and pushcopy are not al-
+ lowed, nor are any option-setting modifiers. The JIT modifiers are,
+ however permitted. Here is an example that saves and reloads two pat-
terns.
/abc/push
@@ -2070,10 +2075,10 @@ SAVING AND RESTORING COMPILED PATTERNS
#pop jit,bincode
abc
- If jitverify is used with #pop, it does not automatically imply jit,
+ If jitverify is used with #pop, it does not automatically imply jit,
which is different behaviour from when it is used on a pattern.
- The #popcopy command is analogous to the pushcopy modifier in that it
+ The #popcopy command is analogous to the pushcopy modifier in that it
makes current a copy of the topmost stack pattern, leaving the original
still on the stack.
diff --git a/src/pcre2test.c b/src/pcre2test.c
index 0af451152..5896c269b 100644
--- a/src/pcre2test.c
+++ b/src/pcre2test.c
@@ -3054,8 +3054,6 @@ printf(" -32 use the 32-bit library\n");
printf(" -ac set default pattern modifier PCRE2_AUTO_CALLOUT\n");
printf(" -AC as -ac, but also set subject 'callout_extra' modifier\n");
printf(" -b set default pattern modifier 'fullbincode'\n");
-printf(" --colo[u]r[=]\n");
-printf(" show output in colour\n");
printf(" -C show PCRE2 compile-time options and exit\n");
printf(" -C arg show a specific compile-time option and exit with its\n");
printf(" value if numeric (else 0). The arg can be:\n");
@@ -3073,6 +3071,8 @@ printf(" pcre2-8 8 bit library support enabled [0, 1]\n");
printf(" pcre2-16 16 bit library support enabled [0, 1]\n");
printf(" pcre2-32 32 bit library support enabled [0, 1]\n");
printf(" unicode Unicode and UTF support enabled [0, 1]\n");
+printf(" --colo[u]r[=]\n");
+printf(" show output in colour\n");
printf(" -d set default pattern modifier 'debug'\n");
printf(" -dfa set default subject modifier 'dfa'\n");
printf(" -E preprocess input only (#if ... #endif)\n");
From acc6aa951eb7df074e09e742af7098be5ef36879 Mon Sep 17 00:00:00 2001
From: Nicholas Wilson
Date: Fri, 10 Oct 2025 15:30:31 +0000
Subject: [PATCH 5/6] Fix the readline prompt I broke
---
src/pcre2test.c | 62 +++++++++++++++++++++++++++++++++----------------
1 file changed, 42 insertions(+), 20 deletions(-)
diff --git a/src/pcre2test.c b/src/pcre2test.c
index 5896c269b..3a2496a83 100644
--- a/src/pcre2test.c
+++ b/src/pcre2test.c
@@ -1124,13 +1124,12 @@ static int colour_setting = COLOUR_AUTO;
static int colour_last_fd = -1;
static BOOL colour_fd_interactive = FALSE;
-/* Starts a block of colour (but only if colour is enabled). */
-static void
-colour_begin(int clr, FILE* f)
+static BOOL
+should_print_colour(int clr, FILE* f)
{
-if (f == NULL) return;
-if (clr == clr_none) return;
-if (colour_setting == COLOUR_NEVER) return;
+if (f == NULL) return FALSE;
+if (clr == clr_none) return FALSE;
+if (colour_setting == COLOUR_NEVER) return FALSE;
if (colour_setting == COLOUR_AUTO)
{
if (fileno(f) != colour_last_fd)
@@ -1138,9 +1137,17 @@ if (colour_setting == COLOUR_AUTO)
colour_last_fd = fileno(f);
colour_fd_interactive = INTERACTIVE(f);
}
- if (!colour_fd_interactive) return;
+ if (!colour_fd_interactive) return FALSE;
}
-fprintf(f, "\x1b[%dm", clr);
+return TRUE;
+}
+
+/* Starts a block of colour (but only if colour is enabled). */
+static void
+colour_begin(int clr, FILE* f)
+{
+if (should_print_colour(clr, f))
+ fprintf(f, "\x1b[%dm", clr);
}
/* Ends a block of colour (but only if colour is enabled). */
@@ -1980,7 +1987,15 @@ for (;;)
#if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
if (INTERACTIVE(f))
{
- char *s = readline(prompt);
+ char promptbuf[80];
+ int snprintf_rc;
+ char *s;
+ if (should_print_colour(clr_prompt, stdout) &&
+ (snprintf_rc = snprintf(promptbuf, sizeof(promptbuf), "\x1b[%dm%s\x1b[0m", clr_prompt, prompt)) > 0 &&
+ snprintf_rc < (int)sizeof(promptbuf))
+ s = readline(promptbuf);
+ else
+ s = readline(prompt);
if (s == NULL) return (here == start)? NULL : start;
dlen = strlen(s);
if (dlen > rlen - 2)
@@ -2003,7 +2018,7 @@ for (;;)
/* Read the next line by normal means, prompting if the file is a tty. */
- if (INTERACTIVE(f)) cfprintf(clr_prompt, outfile, "%s", prompt);
+ if (INTERACTIVE(f)) cfprintf(clr_prompt, stdout, "%s", prompt);
if (fgets((char *)here, rlen_trunc, f) == NULL)
return (here == start)? NULL : start;
@@ -4027,9 +4042,11 @@ preg.re_match_data = NULL;
while (notdone)
{
const uint8_t *p;
+ const uint8_t *p_notsp;
int rc = PR_OK;
BOOL expectdata = have_active_pattern();
- BOOL is_comment;
+ BOOL is_pattern_comment;
+ BOOL is_data_comment;
#ifdef SUPPORT_PCRE2_8
expectdata |= preg.re_pcre2_code != NULL;
#endif
@@ -4049,10 +4066,17 @@ while (notdone)
/* Begin processing the line. */
- p = buffer;
- is_comment = p[0] == '#' && (isspace(p[1]) || p[1] == '!' || p[1] == 0);
+ p = p_notsp = buffer;
+ while (isspace(*p_notsp)) p_notsp++;
+
+ is_pattern_comment = p[0] == '#' &&
+ (isspace(p[1]) || p[1] == '!' || p[1] == 0);
+ is_data_comment = expectdata && p_notsp[0] == '\\' && p_notsp[1] == '=' &&
+ (isspace(p_notsp[2]) || p_notsp[2] == 0);
+
if (!INTERACTIVE(infile))
- cfprintf(is_comment ? clr_comment : clr_input, outfile, "%s", (char *)buffer);
+ cfprintf((is_pattern_comment || is_data_comment)? clr_comment : clr_input,
+ outfile, "%s", (char *)buffer);
fflush(outfile);
if (preprocess_only && *p != '#') continue;
@@ -4062,8 +4086,7 @@ while (notdone)
if (expectdata || skipping)
{
- while (isspace(*p)) p++;
- if (*p == 0)
+ if (*p_notsp == 0)
{
#ifdef SUPPORT_PCRE2_8
if (preg.re_pcre2_code != NULL)
@@ -4081,7 +4104,7 @@ while (notdone)
/* Otherwise, if we are not skipping, and the line is not a data comment
line starting with "\=", process a data line. */
- else if (!skipping && !(p[0] == '\\' && p[1] == '=' && isspace(p[2])))
+ else if (!skipping && !is_data_comment)
{
rc = process_data();
}
@@ -4096,7 +4119,7 @@ while (notdone)
else if (*p == '#')
{
- if (is_comment) continue;
+ if (is_pattern_comment) continue;
rc = process_command();
}
@@ -4108,8 +4131,7 @@ while (notdone)
else
{
- while (isspace(*p)) p++;
- if (*p != 0)
+ if (*p_notsp != 0)
{
cfprintf(clr_test_error, outfile, "** Invalid pattern delimiter '%c' (x%x).\n", *buffer,
*buffer);
From 329d17260777e470a7f23e7b948cac23b2e8eb6d Mon Sep 17 00:00:00 2001
From: Nicholas Wilson
Date: Fri, 10 Oct 2025 15:35:20 +0000
Subject: [PATCH 6/6] Hide a line of output which has moved into stderr
---
RunTest | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/RunTest b/RunTest
index 8825571c8..57a03455a 100755
--- a/RunTest
+++ b/RunTest
@@ -198,7 +198,7 @@ checkresult()
checkspecial()
{
expect=${2:-0}
- $sim $valgrind $vjs $pcre2test $1 >>testSoutput
+ $sim $valgrind $vjs $pcre2test $1 >>testSoutput 2>&1
if [ $? -ne "$expect" ] ; then
echo "** pcre2test $1 failed - check testSoutput"
yield=1