Control: tags -1 + patch

Please find attached a patch -- build-tested after adding -Wno-error
to CFLAGS due to #941101.
Description: Port to PCRE2.
Bug-Debian: https://bugs.debian.org/999975
Author: Yavor Doganov <ya...@gnu.org>
Forwarded: no
Last-Update: 2023-12-22
---

--- rdup-1.1.15.orig/configure.ac
+++ rdup-1.1.15/configure.ac
@@ -62,26 +62,28 @@
 if test "$with_libpcre_includes" != "no"; then
    CFLAGS="${CFLAGS} -I${with_libpcre_includes}"
 else
-   CFLAGS="${CFLAGS} `pcre-config --cflags`"
+   CFLAGS="${CFLAGS} `pcre2-config --cflags`"
 fi
 
 if test "$with_libpcre_libraries" != "no"; then
    LIBS="${LIBS} -L${with_libpcre_libraries}"
 else
-   LIBS="${LIBS} `pcre-config --libs`"
+   LIBS="${LIBS} `pcre2-config --libs8`"
 fi
 
 # PCRE configuration (required)
 # Verify that we have the headers
 PCRE_H=""
-AC_CHECK_HEADERS(pcre.h,, PCRE_H="no")
+AC_CHECK_HEADERS([pcre2.h], [], [PCRE_H="no"], [[
+#define PCRE2_CODE_UNIT_WIDTH 8
+]])
 if test "$PCRE_H" = "no"; then
        AC_MSG_ERROR([** No pcre library found.])
 fi
 
 # Verify that we have the library
 PCRE_L=""
-AC_CHECK_LIB(pcre, pcre_compile, ,PCRE_L="no")
+AC_CHECK_LIB([pcre2-8], [pcre2_compile_8], [], [PCRE_L="no"])
 if test "$PCRE_L" = "no"; then
        AC_MSG_ERROR([** No pcre library found.])
 fi
--- rdup-1.1.15.orig/gfunc.c
+++ rdup-1.1.15/gfunc.c
@@ -7,7 +7,8 @@
 
 #include "rdup.h"
 #include "protocol.h"
-#include <pcre.h>
+#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>
 #ifdef HAVE_LIBNETTLE
 #include <nettle/sha.h>
 #else
@@ -622,20 +623,26 @@
 gboolean gfunc_regexp(GSList * l, char *n, size_t len)
 {
        GSList *k;
-       pcre *P;
-       int ovector[REG_VECTOR];
+       pcre2_code *P;
+       pcre2_match_data *md;
 
+       md = pcre2_match_data_create(REG_VECTOR, NULL);
        for (k = g_slist_nth(l, 0); k; k = k->next) {
-               if (sig != 0)
+               if (sig != 0) {
+                       pcre2_match_data_free(md);
                        signal_abort(sig);
+               }
 
-               P = (pcre *) k->data;
+               P = (pcre2_code *) k->data;
                /* pcre_exec errors are all < 0, so >= 0 is some kind
                 * of success
                 */
-               if (pcre_exec(P, NULL, n, len, 0, 0, ovector, REG_VECTOR) >= 0)
+               if (pcre2_match(P, (PCRE2_SPTR)n, len, 0, 0, md, NULL) >= 0) {
+                       pcre2_match_data_free(md);
                        return TRUE;
+               }
        }
+       pcre2_match_data_free(md);
        return FALSE;
 }
 
--- rdup-1.1.15.orig/regexp.c
+++ rdup-1.1.15/regexp.c
@@ -6,7 +6,8 @@
  */
 
 #include "rdup.h"
-#include <pcre.h>
+#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>
 
 GSList *pregex_list = NULL;
 
@@ -18,15 +19,16 @@
 {
        FILE *fp;
        char *buf;
-       const char *errbuf;
-       int erroff;
+       PCRE2_UCHAR errbuf[120];
+       PCRE2_SIZE erroff;
+       int err;
        char delim;
        gpointer d;
        size_t l;
        size_t s;
        size_t re_length;
        ssize_t j;
-       pcre *P;
+       pcre2_code *P;
 
        if ((fp = fopen(file, "r")) == NULL) {
                msg(_("Could not open '%s\': %s"), file, strerror(errno));
@@ -45,18 +47,20 @@
                /* buf[j - 1] holds the delimeter */
                buf[j - 1] = '\0';
 
-               if ((P = pcre_compile(buf, 0, &errbuf, &erroff, NULL)) == NULL) 
{
+               if ((P = pcre2_compile((PCRE2_SPTR)buf, strlen(buf), 0, &err, 
&erroff, NULL)) == NULL) {
                        /* error */
                        fclose(fp);
+                       pcre2_get_error_message(err, errbuf, sizeof(errbuf));
                        msg(_
-                           ("Corrupt regular expression line: %zd, column %d: 
%s"),
+                           ("Corrupt regular expression line: %zd, column %zu: 
%s"),
                            l, erroff, errbuf);
                        g_free(buf);
                        return FALSE;
                } else {
-                       pcre_fullinfo(P, NULL, PCRE_INFO_SIZE, &re_length);
+                       pcre2_pattern_info(P, PCRE2_INFO_SIZE, &re_length);
                        d = g_malloc(re_length);
                        d = memcpy(d, P, re_length);
+                       pcre2_code_free(P);
                        pregex_list = g_slist_append(pregex_list, d);
                }
                l++;

Reply via email to