[Pcre-svn] [824] code/branches/pcre16: support for getting s…

Startseite
Nachricht löschen
Autor: Subversion repository
Datum:  
To: pcre-svn
Betreff: [Pcre-svn] [824] code/branches/pcre16: support for getting single compile time flags in pcretest
Revision: 824
          http://vcs.pcre.org/viewvc?view=rev&revision=824
Author:   zherczeg
Date:     2011-12-26 14:27:28 +0000 (Mon, 26 Dec 2011)


Log Message:
-----------
support for getting single compile time flags in pcretest

Modified Paths:
--------------
    code/branches/pcre16/Makefile.am
    code/branches/pcre16/RunTest
    code/branches/pcre16/pcre_config.c
    code/branches/pcre16/pcre_dfa_exec.c
    code/branches/pcre16/pcre_study.c
    code/branches/pcre16/pcre_tables.c
    code/branches/pcre16/pcretest.c
    code/branches/pcre16/testdata/testinput14
    code/branches/pcre16/testdata/testinput2
    code/branches/pcre16/testdata/testoutput13
    code/branches/pcre16/testdata/testoutput14
    code/branches/pcre16/testdata/testoutput2


Modified: code/branches/pcre16/Makefile.am
===================================================================
--- code/branches/pcre16/Makefile.am    2011-12-24 17:43:22 UTC (rev 823)
+++ code/branches/pcre16/Makefile.am    2011-12-26 14:27:28 UTC (rev 824)
@@ -342,12 +342,12 @@
 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


Modified: code/branches/pcre16/RunTest
===================================================================
--- code/branches/pcre16/RunTest    2011-12-24 17:43:22 UTC (rev 823)
+++ code/branches/pcre16/RunTest    2011-12-26 14:27:28 UTC (rev 824)
@@ -77,7 +77,7 @@
    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 @@
 # 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+

Modified: code/branches/pcre16/pcre_config.c
===================================================================
--- code/branches/pcre16/pcre_config.c    2011-12-24 17:43:22 UTC (rev 823)
+++ code/branches/pcre16/pcre_config.c    2011-12-26 14:27:28 UTC (rev 824)
@@ -45,6 +45,9 @@
 #include "config.h"
 #endif


+/* Keep the original link size. */
+static int real_link_size = LINK_SIZE;
+
#include "pcre_internal.h"


@@ -75,26 +78,26 @@
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 @@
break;

case PCRE_CONFIG_LINK_SIZE:
- *((int *)where) = LINK_SIZE;
+ *((int *)where) = real_link_size;
break;

case PCRE_CONFIG_POSIX_MALLOC_THRESHOLD:

Modified: code/branches/pcre16/pcre_dfa_exec.c
===================================================================
--- code/branches/pcre16/pcre_dfa_exec.c    2011-12-24 17:43:22 UTC (rev 823)
+++ code/branches/pcre16/pcre_dfa_exec.c    2011-12-26 14:27:28 UTC (rev 824)
@@ -2689,7 +2689,9 @@
             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 @@
             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 @@
             }
           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)); }


Modified: code/branches/pcre16/pcre_study.c
===================================================================
--- code/branches/pcre16/pcre_study.c    2011-12-24 17:43:22 UTC (rev 823)
+++ code/branches/pcre16/pcre_study.c    2011-12-26 14:27:28 UTC (rev 824)
@@ -1499,6 +1499,8 @@
 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)


Modified: code/branches/pcre16/pcre_tables.c
===================================================================
--- code/branches/pcre16/pcre_tables.c    2011-12-24 17:43:22 UTC (rev 823)
+++ code/branches/pcre16/pcre_tables.c    2011-12-26 14:27:28 UTC (rev 824)
@@ -37,6 +37,7 @@
 -----------------------------------------------------------------------------
 */


+#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 @@

#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. */

Modified: code/branches/pcre16/pcretest.c
===================================================================
--- code/branches/pcre16/pcretest.c    2011-12-24 17:43:22 UTC (rev 823)
+++ code/branches/pcre16/pcretest.c    2011-12-26 14:27:28 UTC (rev 824)
@@ -116,6 +116,12 @@
 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 @@
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 @@
/* ----- 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 @@
 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 @@
#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 @@
while (len-- > 0) *pp++ = *p++;
}

+#ifdef SUPPORT_UTF
 else
   {
   int c = 0;
@@ -1176,7 +1179,7 @@
     {
     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 @@
       }
     }
   }
+#endif


 *pp = 0;
 return pp - buffer16;
@@ -2043,6 +2047,14 @@
 #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 @@
     {
     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 @@

           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 @@
               :
                    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++;


Modified: code/branches/pcre16/testdata/testinput14
===================================================================
--- code/branches/pcre16/testdata/testinput14    2011-12-24 17:43:22 UTC (rev 823)
+++ code/branches/pcre16/testdata/testinput14    2011-12-26 14:27:28 UTC (rev 824)
@@ -76,6 +76,8 @@
 /\Biss\B/I+P
     Mississippi


+/abc/\P
+
/-- End of POSIX tests --/

/a\Cb/

Modified: code/branches/pcre16/testdata/testinput2
===================================================================
--- code/branches/pcre16/testdata/testinput2    2011-12-24 17:43:22 UTC (rev 823)
+++ code/branches/pcre16/testdata/testinput2    2011-12-26 14:27:28 UTC (rev 824)
@@ -407,8 +407,6 @@


/abc/\

-/abc/\P
-
/abc/\i

/(a)bc(d)/I

Modified: code/branches/pcre16/testdata/testoutput13
===================================================================
--- code/branches/pcre16/testdata/testoutput13    2011-12-24 17:43:22 UTC (rev 823)
+++ code/branches/pcre16/testdata/testoutput13    2011-12-26 14:27:28 UTC (rev 824)
@@ -18,4 +18,4 @@
 No need char
 Study returned NULL


-/-- End of testinput15 --/
+/-- End of testinput13 --/

Modified: code/branches/pcre16/testdata/testoutput14
===================================================================
--- code/branches/pcre16/testdata/testoutput14    2011-12-24 17:43:22 UTC (rev 823)
+++ code/branches/pcre16/testdata/testoutput14    2011-12-26 14:27:28 UTC (rev 824)
@@ -131,6 +131,9 @@
  0: iss
  0+ issippi


+/abc/\P
+Failed: POSIX code 9: bad escape sequence at offset 4     
+
 /-- End of POSIX tests --/ 


/a\Cb/

Modified: code/branches/pcre16/testdata/testoutput2
===================================================================
--- code/branches/pcre16/testdata/testoutput2    2011-12-24 17:43:22 UTC (rev 823)
+++ code/branches/pcre16/testdata/testoutput2    2011-12-26 14:27:28 UTC (rev 824)
@@ -975,9 +975,6 @@
 /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