Control: tags -1 + patch

The patch available at the forwarded URL that Adrian Bunk added some
time ago looks decent to me -- I have build-tested it and include it
here in a form that can be directly dropped in debian/patches.
Description: Port to PCRE2.
Bug-Debian: https://bugs.debian.org/1000047
Author: Milan Crha
Forwarded: no
Last-Update: 2023-12-09
---

--- libsynthesis-3.4.0.47.5+syncevolution-1.5.3.orig/configure.in
+++ libsynthesis-3.4.0.47.5+syncevolution-1.5.3/configure.in
@@ -70,9 +70,9 @@
               [enable_regex=$enableval],
               [enable_regex="yes"])
 if test "$enable_regex" == "yes"; then
-    PKG_CHECK_MODULES(PCRE, libpcre,
+    PKG_CHECK_MODULES(PCRE, libpcre2-8,
                       [HAVE_PCRE=1],
-                      [AC_ERROR([libpcre not found, required for 
--enable-regex])])
+                      [AC_ERROR([libpcre2 not found, required for 
--enable-regex])])
     HAVE_PCRE=1
 else
     HAVE_PCRE=0
--- 
libsynthesis-3.4.0.47.5+syncevolution-1.5.3.orig/src/sysync/scriptcontext.cpp
+++ libsynthesis-3.4.0.47.5+syncevolution-1.5.3/src/sysync/scriptcontext.cpp
@@ -24,7 +24,8 @@
 #include "vtimezone.h" // for SETTIMEZONE
 #include "mimediritemtype.h" // for AlldayCount/MakeAllday
 #ifdef REGEX_SUPPORT
-  #include "pcre.h" // for RegEx functions
+  #define PCRE2_CODE_UNIT_WIDTH 8
+  #include "pcre2.h" // for RegEx functions
 #endif
 
 #include <stdio.h>
@@ -1323,7 +1324,7 @@
   // Returns:          > 0 => success; value is the number of elements filled 
in
   //                   = 0 => success, but offsets is not big enough
   //                    -1 => failed to match
-  //                    -2 => PCRE_ERROR_NULL => did not compile, error 
reported to aDbgLogger
+  //                    -2 => PCRE2_ERROR_NULL => did not compile, error 
reported to aDbgLogger
   //                  < -2 => some kind of unexpected problem
   static int run_pcre(cAppCharP aRegEx, cAppCharP aSubject, stringSize 
aSubjLen, stringSize aSubjStart, int *aOutVec, int aOVSize, TDebugLogger 
*aDbgLogger)
   {
@@ -1351,11 +1352,11 @@
             cAppCharP o = p++;
             while (*o) {
               switch (*o) {
-                case 'i' : options |= PCRE_CASELESS; break;
-                case 'm' : options |= PCRE_MULTILINE; break;
-                case 's' : options |= PCRE_DOTALL; break;
-                case 'x' : options |= PCRE_EXTENDED; break;
-                case 'U' : options |= PCRE_UNGREEDY; break;
+                case 'i' : options |= PCRE2_CASELESS; break;
+                case 'm' : options |= PCRE2_MULTILINE; break;
+                case 's' : options |= PCRE2_DOTALL; break;
+                case 'x' : options |= PCRE2_EXTENDED; break;
+                case 'U' : options |= PCRE2_UNGREEDY; break;
               }
               o++;
             }
@@ -1369,23 +1370,43 @@
       } // while chars in regex
     } // if regex with delimiter
     // - compile regex
-    pcre *regex;
-    cAppCharP errMsg=NULL;
-    int errOffs=0;
-    regex = pcre_compile(aRegEx, options | PCRE_UTF8, &errMsg, &errOffs, NULL);
+    pcre2_code *regex;
+    int errNum=0;
+    size_t errOffs=0;
+    regex = pcre2_compile((PCRE2_SPTR) aRegEx, options | PCRE2_UTF | 
PCRE2_ZERO_TERMINATED, 0, &errNum, &errOffs, NULL);
     if (regex==NULL) {
+      PCRE2_UCHAR buffer[256] = { 0 };
+      pcre2_get_error_message(errNum, buffer, sizeof(buffer));
       // error, display it in log if script logging is on
       PLOGDEBUGPRINTFX(aDbgLogger,DBG_SCRIPTS+DBG_ERROR,(
         "RegEx error at pattern pos %d: %s ",
-        errOffs,
-        errMsg ? errMsg : "<unknown>"
+        (int) errOffs,
+        *buffer ? (const char *) buffer : "<unknown>"
       ));
-      return PCRE_ERROR_NULL; // -2, regexp did not compile
+      return PCRE2_ERROR_NULL; // -2, regexp did not compile
     }
     else {
+      pcre2_match_data *match_data;
       // regExp is ok and can be executed against subject
-      int r = pcre_exec(regex, NULL, aSubject, aSubjLen, aSubjStart, 0, 
aOutVec, aOVSize);
-      pcre_free(regex);
+      match_data = pcre2_match_data_create_from_pattern(regex, NULL);
+      int r = pcre2_match(regex, (PCRE2_SPTR) aSubject, aSubjLen, 0, 0, 
match_data, NULL);
+      if (r > 0 && aOutVec != NULL) {
+        PCRE2_SIZE *ovector;
+       ovector = pcre2_get_ovector_pointer(match_data);
+       if (ovector[0] > ovector[1]) {
+          aOutVec[0] = ovector[1];
+         r = 1;
+        } else {
+           int ii;
+           for (ii = 0; ii < r && ii < aOVSize; ii++) {
+              aOutVec[ii] = (int) ovector[ii];
+           }
+           if (r > ii)
+              r = ii;
+        }
+      }
+      pcre2_match_data_free(match_data);
+      pcre2_code_free(regex);
       return r;
     }
   } // run_pcre

Reply via email to