summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzherczeg <zherczeg@2f5784b3-3f2a-0410-8824-cb99058d5e15>2011-12-26 14:27:28 +0000
committerzherczeg <zherczeg@2f5784b3-3f2a-0410-8824-cb99058d5e15>2011-12-26 14:27:28 +0000
commit1171fd96716f91c4bce421cd21aebf97b0bff6fb (patch)
tree08ef7b4ae5ea1d210938f9f178c032672cebd9e8
parent5a61c28fd404ea8390c9e4c035e0a35c782536d3 (diff)
downloadpcre-1171fd96716f91c4bce421cd21aebf97b0bff6fb.tar.gz
support for getting single compile time flags in pcretest
git-svn-id: svn://vcs.exim.org/pcre/code/branches/pcre16@824 2f5784b3-3f2a-0410-8824-cb99058d5e15
-rw-r--r--Makefile.am2
-rwxr-xr-xRunTest45
-rw-r--r--pcre_config.c13
-rw-r--r--pcre_dfa_exec.c6
-rw-r--r--pcre_study.c2
-rw-r--r--pcre_tables.c2
-rw-r--r--pcretest.c110
-rw-r--r--testdata/testinput142
-rw-r--r--testdata/testinput22
-rw-r--r--testdata/testoutput132
-rw-r--r--testdata/testoutput143
-rw-r--r--testdata/testoutput23
12 files changed, 144 insertions, 48 deletions
diff --git a/Makefile.am b/Makefile.am
index 9137b69..810c9d9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -342,12 +342,12 @@ pcretest_SOURCES += pcre16_printint.c
pcretest_LDADD += libpcre16.la
endif # WITH_PCRE16
+if WITH_PCRE8
TESTS += RunGrepTest
dist_noinst_SCRIPTS += RunGrepTest
bin_PROGRAMS += pcregrep
pcregrep_SOURCES = pcregrep.c
pcregrep_LDADD = $(LIBZ) $(LIBBZ2)
-if WITH_PCRE8
pcregrep_LDADD += libpcreposix.la
endif # WITH_PCRE8
diff --git a/RunTest b/RunTest
index f6c7f67..46a1c6b 100755
--- a/RunTest
+++ b/RunTest
@@ -77,7 +77,7 @@ while [ $# -gt 0 ] ; do
18) do18=yes;;
19) do19=yes;;
-8) arg8=yes;;
- -16) arg16=yes;;
+ -16) arg16=yes;;
valgrind) valgrind="valgrind -q --smc-check=all";;
sim) shift; sim=$1;;
*) echo "Unknown test number $1"; exit 1;;
@@ -108,57 +108,62 @@ fi
# strips only linefeeds from the output of a `backquoted` command. Hence the
# alternative patterns.
-case `$sim ./pcretest -C | $sim ./pcregrep 'Internal link size'` in
- *2|*2[[:space:]]) link_size=2;;
- *3|*3[[:space:]]) link_size=3;;
- *4|*4[[:space:]]) link_size=4;;
- *) echo "Failed to find internal link size"; exit 1;;
-esac
+$sim ./pcretest -C linksize >/dev/null
+link_size=$?
+if [ $link_size -lt 2 ] ; then
+ echo "Failed to find internal link size"
+ exit 1
+fi
+if [ $link_size -gt 4 ] ; then
+ echo "Failed to find internal link size"
+ exit 1
+fi
# Both 8-bit and 16-bit character strings may be supported, but only one
# need be.
-$sim ./pcretest -C | $sim ./pcregrep '8-bit and 16-bit support' >/dev/null
-if [ $? -eq 0 ] ; then
+$sim ./pcretest -C pcre8 >/dev/null
+support8=$?
+$sim ./pcretest -C pcre16 >/dev/null
+support16=$?
+if [ $(( $support8 + $support16 )) -eq 2 ] ; then
test8=
test16=-16
if [ "$arg8" = yes -a "$arg16" != yes ] ; then
test16=skip
- fi
+ fi
if [ "$arg16" = yes -a "$arg8" != yes ] ; then
test8=skip
- fi
+ fi
else
- $sim ./pcretest -C | $sim ./pcregrep '8-bit support' >/dev/null
- if [ $? -eq 0 ] ; then
+ if [ $support8 -ne 0 ] ; then
if [ "$arg16" = yes ] ; then
echo "Cannot run 16-bit library tests: 16-bit library not compiled"
exit 1
- fi
+ fi
test8=
test16=skip
else
if [ "$arg8" = yes ] ; then
echo "Cannot run 8-bit library tests: 8-bit library not compiled"
exit 1
- fi
+ fi
test8=skip
test16=-16
fi
fi
-
+
# UTF support always applies to both bit sizes if both are supported; we can't
# have UTF-8 support without UTF-16 support (for example).
-$sim ./pcretest -C | $sim ./pcregrep 'No UTF-(.+?) support' >/dev/null
+$sim ./pcretest -C utf >/dev/null
utf=$?
-$sim ./pcretest -C | $sim ./pcregrep 'No Unicode properties support' >/dev/null
+$sim ./pcretest -C ucp >/dev/null
ucp=$?
jitopt=
-$sim ./pcretest -C | $sim ./pcregrep 'No just-in-time compiler support' \
- >/dev/null
+$sim ./pcretest -C jit >/dev/null
jit=$?
if [ $jit -ne 0 ] ; then
jitopt=-s+
diff --git a/pcre_config.c b/pcre_config.c
index 80717de..e7dc65e 100644
--- a/pcre_config.c
+++ b/pcre_config.c
@@ -45,6 +45,9 @@ POSSIBILITY OF SUCH DAMAGE.
#include "config.h"
#endif
+/* Keep the original link size. */
+static int real_link_size = LINK_SIZE;
+
#include "pcre_internal.h"
@@ -75,26 +78,26 @@ switch (what)
case PCRE_CONFIG_UTF8:
#if defined COMPILE_PCRE16
return PCRE_ERROR_BADOPTION;
-#else
+#else
#if defined SUPPORT_UTF
*((int *)where) = 1;
#else
*((int *)where) = 0;
#endif
break;
-#endif
+#endif
case PCRE_CONFIG_UTF16:
#if defined COMPILE_PCRE8
return PCRE_ERROR_BADOPTION;
-#else
+#else
#if defined SUPPORT_UTF
*((int *)where) = 1;
#else
*((int *)where) = 0;
#endif
break;
-#endif
+#endif
case PCRE_CONFIG_UNICODE_PROPERTIES:
#ifdef SUPPORT_UCP
@@ -125,7 +128,7 @@ switch (what)
break;
case PCRE_CONFIG_LINK_SIZE:
- *((int *)where) = LINK_SIZE;
+ *((int *)where) = real_link_size;
break;
case PCRE_CONFIG_POSIX_MALLOC_THRESHOLD:
diff --git a/pcre_dfa_exec.c b/pcre_dfa_exec.c
index 970d55c..8c46bf4 100644
--- a/pcre_dfa_exec.c
+++ b/pcre_dfa_exec.c
@@ -2689,7 +2689,9 @@ for (;;)
const pcre_uchar *p = start_subject + local_offsets[rc];
const pcre_uchar *pp = start_subject + local_offsets[rc+1];
int charcount = local_offsets[rc+1] - local_offsets[rc];
+#ifdef SUPPORT_UTF
while (p < pp) if (NOT_FIRSTCHAR(*p++)) charcount--;
+#endif
if (charcount > 0)
{
ADD_NEW_DATA(-(state_offset + LINK_SIZE + 1), 0, (charcount - 1));
@@ -2786,7 +2788,9 @@ for (;;)
const pcre_uchar *p = ptr;
const pcre_uchar *pp = local_ptr;
charcount = (int)(pp - p);
+#ifdef SUPPORT_UTF
while (p < pp) if (NOT_FIRSTCHAR(*p++)) charcount--;
+#endif
ADD_NEW_DATA(-next_state_offset, 0, (charcount - 1));
}
}
@@ -2866,9 +2870,11 @@ for (;;)
}
else
{
+#ifdef SUPPORT_UTF
const pcre_uchar *p = start_subject + local_offsets[0];
const pcre_uchar *pp = start_subject + local_offsets[1];
while (p < pp) if (NOT_FIRSTCHAR(*p++)) charcount--;
+#endif
ADD_NEW_DATA(-next_state_offset, 0, (charcount - 1));
if (repeat_state_offset >= 0)
{ ADD_NEW_DATA(-repeat_state_offset, 0, (charcount - 1)); }
diff --git a/pcre_study.c b/pcre_study.c
index 41ed829..f1863b6 100644
--- a/pcre_study.c
+++ b/pcre_study.c
@@ -1499,6 +1499,8 @@ PCRE_EXP_DEFN void
pcre16_free_study(pcre_extra *extra)
#endif
{
+if (extra == NULL)
+ return;
#ifdef SUPPORT_JIT
if ((extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 &&
extra->executable_jit != NULL)
diff --git a/pcre_tables.c b/pcre_tables.c
index b8cabf3..4b27b83 100644
--- a/pcre_tables.c
+++ b/pcre_tables.c
@@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
-----------------------------------------------------------------------------
*/
+#ifndef PCRE_INCLUDED
/* This module contains some fixed tables that are used by more than one of the
PCRE code modules. The tables are also #included by the pcretest program, which
@@ -50,6 +51,7 @@ clashes with the library. */
#include "pcre_internal.h"
+#endif /* PCRE_INCLUDED */
/* Table of sizes for the fixed-length opcodes. It's defined in a macro so that
the definition is next to the definition of the opcodes in pcre_internal.h. */
diff --git a/pcretest.c b/pcretest.c
index a387717..a33ccdc 100644
--- a/pcretest.c
+++ b/pcretest.c
@@ -116,6 +116,12 @@ here before pcre_internal.h so that the PCRE_EXP_xxx macros get set
appropriately for an application, not for building PCRE. */
#include "pcre.h"
+
+#if defined SUPPORT_PCRE16 && !defined SUPPORT_PCRE8
+/* Configure internal macros to 16 bit mode. */
+#define COMPILE_PCRE16
+#endif
+
#include "pcre_internal.h"
/* The pcre_printint() function, which prints the internal form of a compiled
@@ -134,17 +140,9 @@ void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths);
to keep two copies, we include the source file here, changing the names of the
external symbols to prevent clashes. */
-#define _pcre_ucp_gentype ucp_gentype
-#define _pcre_ucp_typerange ucp_typerange
-#define _pcre_utf8_table1 utf8_table1
-#define _pcre_utf8_table1_size utf8_table1_size
-#define _pcre_utf8_table2 utf8_table2
-#define _pcre_utf8_table3 utf8_table3
-#define _pcre_utf8_table4 utf8_table4
-#define _pcre_utt utt
-#define _pcre_utt_size utt_size
-#define _pcre_utt_names utt_names
-#define _pcre_OP_lengths OP_lengths
+#define PCRE_INCLUDED
+#undef PRIV
+#define PRIV(name) name
#include "pcre_tables.c"
@@ -524,7 +522,7 @@ version is called. ----- */
/* ----- Only 16-bit mode is supported ----- */
#else
-#define CHAR_SIZE 1
+#define CHAR_SIZE 2
#define PCHARS PCHARS16
#define PCHARSV PCHARSV16
#define READ_CAPTURE_NAME READ_CAPTURE_NAME16
@@ -600,6 +598,8 @@ obtained and extended as required. */
static int buffer16_size = 0;
static pcre_uint16 *buffer16 = NULL;
+#ifdef SUPPORT_PCRE8
+
/* We need the table of operator lengths that is used for 16-bit compiling, in
order to swap bytes in a pattern for saving/reloading testing. Luckily, the
data is defined as a macro. However, we must ensure that LINK_SIZE is adjusted
@@ -620,6 +620,8 @@ COMPILE_PCRE16 is *not* set. */
#error LINK_SIZE must be either 2, 3, or 4
#endif
+#endif /* SUPPORT_PCRE8 */
+
static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };
#endif /* SUPPORT_PCRE16 */
@@ -1169,6 +1171,7 @@ if (!utf)
while (len-- > 0) *pp++ = *p++;
}
+#ifdef SUPPORT_UTF
else
{
int c = 0;
@@ -1176,7 +1179,7 @@ else
{
int chlen = utf82ord(p, &c);
if (chlen <= 0) return -1;
- if (c > 0x10ffff) return -2;
+ if (c > 0x10ffff) return -2;
p += chlen;
len -= chlen;
if (c < 0x10000) *pp++ = c; else
@@ -1187,6 +1190,7 @@ else
}
}
}
+#endif
*pp = 0;
return pp - buffer16;
@@ -2043,6 +2047,14 @@ printf(" -16 use 16-bit interface\n");
#endif
printf(" -b show compiled code (bytecode)\n");
printf(" -C show PCRE compile-time options and exit\n");
+printf(" -C arg show a specific compile-time option\n");
+printf(" and exit with its value. The arg can be:\n");
+printf(" linksize internal link size [2, 3, 4]\n");
+printf(" pcre8 8 bit library support enabled [0, 1]\n");
+printf(" pcre16 16 bit library support enabled [0, 1]\n");
+printf(" utf Unicode Transformation Format supported [0, 1]\n");
+printf(" ucp Unicode Properties supported [0, 1]\n");
+printf(" jit Just-in-time compiler supported [0, 1]\n");
printf(" -d debug: show compiled code and information (-b and -i)\n");
#if !defined NODFA
printf(" -dfa force DFA matching for all subjects\n");
@@ -2233,6 +2245,69 @@ while (argc > 1 && argv[op][0] == '-')
{
int rc;
unsigned long int lrc;
+
+ if (argc > 2)
+ {
+ if (strcmp(argv[op + 1], "linksize") == 0)
+ {
+ (void)PCRE_CONFIG(PCRE_CONFIG_LINK_SIZE, &rc);
+ printf("%d\n", rc);
+ yield = rc;
+ goto EXIT;
+ }
+ if (strcmp(argv[op + 1], "pcre8") == 0)
+ {
+#ifdef SUPPORT_PCRE8
+ printf("1\n");
+ yield = 1;
+#else
+ printf("0\n");
+ yield = 0;
+#endif
+ goto EXIT;
+ }
+ if (strcmp(argv[op + 1], "pcre16") == 0)
+ {
+#ifdef SUPPORT_PCRE16
+ printf("1\n");
+ yield = 1;
+#else
+ printf("0\n");
+ yield = 0;
+#endif
+ goto EXIT;
+ }
+ if (strcmp(argv[op + 1], "utf") == 0)
+ {
+#ifdef SUPPORT_PCRE8
+ (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
+ printf("%d\n", rc);
+ yield = rc;
+#else
+ (void)pcre16_config(PCRE_CONFIG_UTF16, &rc);
+ printf("%d\n", rc);
+ yield = rc;
+#endif
+ goto EXIT;
+ }
+ if (strcmp(argv[op + 1], "ucp") == 0)
+ {
+ (void)PCRE_CONFIG(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
+ printf("%d\n", rc);
+ yield = rc;
+ goto EXIT;
+ }
+ if (strcmp(argv[op + 1], "jit") == 0)
+ {
+ (void)PCRE_CONFIG(PCRE_CONFIG_JIT, &rc);
+ printf("%d\n", rc);
+ yield = rc;
+ goto EXIT;
+ }
+ printf("Unknown option: %s\n", argv[op + 1]);
+ goto EXIT;
+ }
+
printf("PCRE version %s\n", version);
printf("Compiled with\n");
@@ -3855,7 +3930,7 @@ while (!done)
PCRE_COPY_NAMED_SUBSTRING(rc, re, bptr, use_offsets, count,
cnptr, copybuffer, sizeof(copybuffer));
-
+
if (rc < 0)
{
fprintf(outfile, "copy substring ");
@@ -4018,9 +4093,12 @@ while (!done)
:
bptr[start_offset] == '\r'
&& bptr[start_offset + 1] == '\n')
+#elif defined SUPPORT_PCRE16
+ ((PCRE_SPTR16)bptr)[start_offset] == '\r'
+ && ((PCRE_SPTR16)bptr)[start_offset + 1] == '\n'
#else
- bptr[start_offset] == '\r' &&
- bptr[start_offset + 1] == '\n'
+ bptr[start_offset] == '\r'
+ && bptr[start_offset + 1] == '\n'
#endif
)
onechar++;
diff --git a/testdata/testinput14 b/testdata/testinput14
index 2decd01..32ae5ea 100644
--- a/testdata/testinput14
+++ b/testdata/testinput14
@@ -76,6 +76,8 @@
/\Biss\B/I+P
Mississippi
+/abc/\P
+
/-- End of POSIX tests --/
/a\Cb/
diff --git a/testdata/testinput2 b/testdata/testinput2
index f812afb..5ff06d9 100644
--- a/testdata/testinput2
+++ b/testdata/testinput2
@@ -407,8 +407,6 @@
/abc/\
-/abc/\P
-
/abc/\i
/(a)bc(d)/I
diff --git a/testdata/testoutput13 b/testdata/testoutput13
index 10fbc54..e9cbbcf 100644
--- a/testdata/testoutput13
+++ b/testdata/testoutput13
@@ -18,4 +18,4 @@ No first char
No need char
Study returned NULL
-/-- End of testinput15 --/
+/-- End of testinput13 --/
diff --git a/testdata/testoutput14 b/testdata/testoutput14
index b2cda8e..4830667 100644
--- a/testdata/testoutput14
+++ b/testdata/testoutput14
@@ -131,6 +131,9 @@ No match: POSIX code 17: match failed
0: iss
0+ issippi
+/abc/\P
+Failed: POSIX code 9: bad escape sequence at offset 4
+
/-- End of POSIX tests --/
/a\Cb/
diff --git a/testdata/testoutput2 b/testdata/testoutput2
index 43e3ac9..aac0fe3 100644
--- a/testdata/testoutput2
+++ b/testdata/testoutput2
@@ -975,9 +975,6 @@ Failed: numbers out of order in {} quantifier at offset 7
/abc/\
Failed: \ at end of pattern at offset 4
-/abc/\P
-Failed: POSIX code 9: bad escape sequence at offset 4
-
/abc/\i
Failed: \ at end of pattern at offset 4