[Pcre-svn] [816] code/branches/pcre16: 16 bit fixes

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [816] code/branches/pcre16: 16 bit fixes
Revision: 816
          http://vcs.pcre.org/viewvc?view=rev&revision=816
Author:   zherczeg
Date:     2011-12-21 23:08:51 +0000 (Wed, 21 Dec 2011)


Log Message:
-----------
16 bit fixes

Modified Paths:
--------------
    code/branches/pcre16/pcre_byte_order.c
    code/branches/pcre16/pcre_compile.c
    code/branches/pcre16/pcre_get.c
    code/branches/pcre16/pcretest.c


Modified: code/branches/pcre16/pcre_byte_order.c
===================================================================
--- code/branches/pcre16/pcre_byte_order.c    2011-12-21 17:46:58 UTC (rev 815)
+++ code/branches/pcre16/pcre_byte_order.c    2011-12-21 23:08:51 UTC (rev 816)
@@ -184,6 +184,7 @@
     case OP_END:
     return 0;


+#ifdef SUPPORT_UTF
     case OP_CHAR:
     case OP_CHARI:
     case OP_NOT:
@@ -240,9 +241,11 @@
     case OP_NOTPOSPLUSI:
     case OP_NOTPOSQUERYI:
     case OP_NOTPOSUPTOI:
-#ifdef SUPPORT_UTF    
     if (utf) utf16_char = TRUE;
-#endif     
+#endif
+    /* Fall through. */
+
+    default:
     length = PRIV(OP_lengths)[*ptr] - 1;
     break;


@@ -273,10 +276,6 @@
       length -= 32/sizeof(pcre_uchar);
       }
     break;
-
-    default:
-    length = PRIV(OP_lengths)[*ptr] - 1;
-    break;
     }
   ptr++;
   }


Modified: code/branches/pcre16/pcre_compile.c
===================================================================
--- code/branches/pcre16/pcre_compile.c    2011-12-21 17:46:58 UTC (rev 815)
+++ code/branches/pcre16/pcre_compile.c    2011-12-21 23:08:51 UTC (rev 816)
@@ -1756,7 +1756,7 @@
     cs = ce = (pcre_uchar *)cd->start_code + GET(cc, 1);  /* Start subpattern */
     do ce += GET(ce, 1); while (*ce == OP_ALT);           /* End subpattern */
     if (cc > cs && cc < ce) return -1;                    /* Recursion */
-    d = find_fixedlength(cs + 2, utf, atend, cd);
+    d = find_fixedlength(cs + IMM2_SIZE, utf, atend, cd);
     if (d < 0) return d;
     branchlength += d;
     cc += 1 + LINK_SIZE;


Modified: code/branches/pcre16/pcre_get.c
===================================================================
--- code/branches/pcre16/pcre_get.c    2011-12-21 17:46:58 UTC (rev 815)
+++ code/branches/pcre16/pcre_get.c    2011-12-21 23:08:51 UTC (rev 816)
@@ -78,6 +78,7 @@
 int top, bot;
 pcre_uchar *nametable;


+#ifdef COMPILE_PCRE8
if ((rc = pcre_fullinfo(code, NULL, PCRE_INFO_NAMECOUNT, &top)) != 0)
return rc;
if (top <= 0) return PCRE_ERROR_NOSUBSTRING;
@@ -86,7 +87,18 @@
return rc;
if ((rc = pcre_fullinfo(code, NULL, PCRE_INFO_NAMETABLE, &nametable)) != 0)
return rc;
+#endif
+#ifdef COMPILE_PCRE16
+if ((rc = pcre16_fullinfo(code, NULL, PCRE_INFO_NAMECOUNT, &top)) != 0)
+ return rc;
+if (top <= 0) return PCRE_ERROR_NOSUBSTRING;

+if ((rc = pcre16_fullinfo(code, NULL, PCRE_INFO_NAMEENTRYSIZE, &entrysize)) != 0)
+  return rc;
+if ((rc = pcre16_fullinfo(code, NULL, PCRE_INFO_NAMETABLE, &nametable)) != 0)
+  return rc;
+#endif
+
 bot = 0;
 while (top > bot)
   {
@@ -94,7 +106,7 @@
   pcre_uchar *entry = nametable + entrysize*mid;
   int c = STRCMP_UC_UC((pcre_uchar *)stringname,
     (pcre_uchar *)(entry + IMM2_SIZE));
-  if (c == 0) return (entry[0] << 8) + entry[1];
+  if (c == 0) return GET2(entry, 0);
   if (c > 0) bot = mid + 1; else top = mid;
   }


@@ -135,6 +147,7 @@
int top, bot;
pcre_uchar *nametable, *lastentry;

+#ifdef COMPILE_PCRE8
if ((rc = pcre_fullinfo(code, NULL, PCRE_INFO_NAMECOUNT, &top)) != 0)
return rc;
if (top <= 0) return PCRE_ERROR_NOSUBSTRING;
@@ -143,7 +156,18 @@
return rc;
if ((rc = pcre_fullinfo(code, NULL, PCRE_INFO_NAMETABLE, &nametable)) != 0)
return rc;
+#endif
+#ifdef COMPILE_PCRE16
+if ((rc = pcre16_fullinfo(code, NULL, PCRE_INFO_NAMECOUNT, &top)) != 0)
+ return rc;
+if (top <= 0) return PCRE_ERROR_NOSUBSTRING;

+if ((rc = pcre16_fullinfo(code, NULL, PCRE_INFO_NAMEENTRYSIZE, &entrysize)) != 0)
+ return rc;
+if ((rc = pcre16_fullinfo(code, NULL, PCRE_INFO_NAMETABLE, &nametable)) != 0)
+ return rc;
+#endif
+
lastentry = nametable + entrysize * (top - 1);
bot = 0;
while (top > bot)
@@ -228,10 +252,10 @@
if (entrysize <= 0) return entrysize;
for (entry = (pcre_uchar *)first; entry <= (pcre_uchar *)last; entry += entrysize)
{
- int n = (entry[0] << 8) + entry[1];
+ int n = GET2(entry, 0);
if (ovector[n*2] >= 0) return n;
}
-return (first[0] << 8) + first[1];
+return GET2(entry, 0);
}



Modified: code/branches/pcre16/pcretest.c
===================================================================
--- code/branches/pcre16/pcretest.c    2011-12-21 17:46:58 UTC (rev 815)
+++ code/branches/pcre16/pcretest.c    2011-12-21 23:08:51 UTC (rev 816)
@@ -188,7 +188,7 @@
 #define PCHARSV8(p, len, f) \
   (void)pchars((pcre_uint8 *)p, len, f)


-#define STRLEN8(p) (int)strlen((char *)p)
+#define STRLEN8(p) ((int)strlen((char *)p))

#define PCRE_COMPILE8(re, pat, options, error, erroffset, tables) \
re = pcre_compile((char *)pat, options, error, erroffset, tables)
@@ -240,6 +240,9 @@
#define PCRE_STUDY8(extra, re, options, error) \
extra = pcre_study(re, options, error)

+#define SET_PCRE_CALLOUT8(callout) \
+ pcre_callout = callout
+
#endif /* SUPPORT_PCRE8 */

/* -----------------------------------------------------------*/
@@ -252,7 +255,7 @@
#define PCHARSV16(p, len, f) \
(void)pchars16((PCRE_SPTR16)p, len, f)

-#define STRLEN16(p) (int)strlen16((PCRE_SPTR16)p)
+#define STRLEN16(p) ((int)strlen16((PCRE_SPTR16)p))

#define PCRE_COMPILE16(re, pat, options, error, erroffset, tables) \
re = pcre16_compile((PCRE_SPTR16)pat, options, error, erroffset, tables)
@@ -307,6 +310,9 @@
#define PCRE_STUDY16(extra, re, options, error) \
extra = pcre16_study(re, options, error)

+#define SET_PCRE_CALLOUT16(callout) \
+ pcre16_callout = callout
+
#endif /* SUPPORT_PCRE16 */


@@ -326,7 +332,7 @@
   else \
     PCHARSV8(p, len, f)


-#define STRLEN(p) use_pcre16? STRLEN16(p) : STRLEN8(p)
+#define STRLEN(p) (use_pcre16? STRLEN16(p) : STRLEN8(p))

 #define PCRE_COMPILE(re, pat, options, error, erroffset, tables) \
   if (use_pcre16) \
@@ -424,6 +430,12 @@
   else \
     PCRE_STUDY8(extra, re, options, error)


+#define SET_PCRE_CALLOUT(callout) \
+  if (use_pcre16) \
+    SET_PCRE_CALLOUT16(callout); \
+  else \
+    SET_PCRE_CALLOUT8(callout)
+
 /* ----- Only 8-bit mode is supported ----- */


 #elif defined SUPPORT_PCRE8
@@ -444,6 +456,7 @@
 #define PCRE_GET_SUBSTRING_LIST   PCRE_GET_SUBSTRING_LIST8
 #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER8
 #define PCRE_STUDY                PCRE_STUDY8
+#define SET_PCRE_CALLOUT          SET_PCRE_CALLOUT8


/* ----- Only 16-bit mode is supported ----- */

@@ -465,6 +478,7 @@
 #define PCRE_GET_SUBSTRING_LIST   PCRE_GET_SUBSTRING_LIST16
 #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER16
 #define PCRE_STUDY                PCRE_STUDY16
+#define SET_PCRE_CALLOUT          SET_PCRE_CALLOUT16
 #endif


 /* ----- End of mode-specific function call macros ----- */
@@ -1658,6 +1672,7 @@
     case OP_END:
     return;


+#ifdef SUPPORT_UTF
     case OP_CHAR:
     case OP_CHARI:
     case OP_NOT:
@@ -1714,9 +1729,11 @@
     case OP_NOTPOSPLUSI:
     case OP_NOTPOSQUERYI:
     case OP_NOTPOSUPTOI:
-#ifdef SUPPORT_UTF
     if (utf) utf16_char = TRUE;
 #endif
+    /* Fall through. */
+
+    default:
     length = OP_lengths16[op] - 1;
     break;


@@ -1754,10 +1771,6 @@
       length -= 32/sizeof(pcre_uint16);
       }
     break;
-
-    default:
-    length = OP_lengths16[op] - 1;
-    break;
     }
   }
 /* Control should never reach here in 16 bit mode. */
@@ -2671,7 +2684,7 @@
           size_t jitsize;
           new_info(re, extra, PCRE_INFO_JITSIZE, &jitsize);
           if (jitsize != 0)
-            fprintf(outfile, "Memory allocation (JIT code): %d\n", jitsize);
+            fprintf(outfile, "Memory allocation (JIT code): %d\n", (int)jitsize);
           }
         }
       }
@@ -2772,10 +2785,23 @@
         fprintf(outfile, "Named capturing subpatterns:\n");
         while (namecount-- > 0)
           {
-          fprintf(outfile, "  %s %*s%3d\n", nametable + 2,
-            nameentrysize - 3 - (int)strlen((char *)nametable + 2), "",
-            GET2(nametable, 0));
+#if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16
+          int imm2_size = use_pcre16 ? 1 : 2;
+#else
+          int imm2_size = IMM2_SIZE;
+#endif
+          int length = (int)STRLEN(nametable + imm2_size);
+          fprintf(outfile, "  ");
+          PCHARSV(nametable + imm2_size, length, outfile);
+          while (length++ < nameentrysize - imm2_size) putc(' ', outfile);
+#if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16
+          fprintf(outfile, "%3d\n", use_pcre16?
+            (int)nametable[0] : ((int)nametable[0] << 8) | (int)nametable[1]);
+          nametable += nameentrysize * (use_pcre16 ? 2 : 1);
+#else
+          fprintf(outfile, "%3d\n", GET2(nametable, 0));
           nametable += nameentrysize;
+#endif
           }
         }


@@ -3042,7 +3068,7 @@
     copynamesptr = copynames;
     getnamesptr = getnames;


-    pcre_callout = callout;
+    SET_PCRE_CALLOUT(callout);
     first_callout = 1;
     last_callout_mark = NULL;
     callout_extra = 0;
@@ -3205,14 +3231,35 @@
           }
         else if (isalnum(*p))
           {
-          pcre_uchar *npp = copynamesptr;
-          while (isalnum(*p)) *npp++ = *p++;
-          *npp++ = 0;
-          *npp = 0;
-          PCRE_GET_STRINGNUMBER(n, re, copynamesptr);
+          pcre_uchar *namestart = copynamesptr;
+#if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16
+          if (use_pcre16)
+            {
+            PCRE_SCHAR16 *npp = (PCRE_SCHAR16 *)copynamesptr;
+            while (isalnum(*p)) *npp++ = *p++;
+            *npp++ = 0;
+            *npp = 0;
+            PCRE_GET_STRINGNUMBER(n, re, copynamesptr);
+            copynamesptr = (pcre_uchar *)npp;
+            }
+          else
+            {
+#endif
+            pcre_uchar *npp = copynamesptr;
+            while (isalnum(*p)) *npp++ = *p++;
+            *npp++ = 0;
+            *npp = 0;
+            PCRE_GET_STRINGNUMBER(n, re, copynamesptr);
+            copynamesptr = npp;
+#if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16
+            }
+#endif
           if (n < 0)
-            fprintf(outfile, "no parentheses with name \"%s\"\n", copynamesptr);
-          copynamesptr = npp;
+            {
+            fprintf(outfile, "no parentheses with name \"");
+            PCHARSV(namestart, STRLEN(namestart), outfile);
+            fprintf(outfile, "\"\n");
+            }
           }
         else if (*p == '+')
           {
@@ -3221,7 +3268,7 @@
           }
         else if (*p == '-')
           {
-          pcre_callout = NULL;
+          SET_PCRE_CALLOUT(NULL);
           p++;
           }
         else if (*p == '!')
@@ -3688,8 +3735,16 @@
           }


         for (copynamesptr = copynames;
+#if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16
+             use_pcre16?
+               (*(PCRE_SCHAR16*)copynamesptr) != 0 : *copynamesptr != 0;
+             copynamesptr += (int)(STRLEN(copynamesptr) + 1) *
+               (use_pcre16? 2:1)
+#else
              *copynamesptr != 0;
-             copynamesptr += (int)strlen((char*)copynamesptr) + 1)
+             copynamesptr += (int)STRLEN(copynamesptr) + 1
+#endif
+             )
           {
           int rc;
           char copybuffer[256];
@@ -3701,7 +3756,9 @@
             {
             fprintf(outfile, "  C ");
             PCHARSV(copybuffer, rc, outfile);
-            fprintf(outfile, " (%d) %s\n", rc, copynamesptr);
+            fprintf(outfile, " (%d) ", rc);
+            PCHARSV(copynamesptr, STRLEN(copynamesptr), outfile);
+            putc('\n', outfile);
             }
           }