Control: tags -1 + patch

Please find attached a patch.
Description: Port to PCRE2.
Bug-Debian: https://bugs.debian.org/999922
Author: Yavor Doganov ya...@gnu.org>
Forwarded: no
Last-Update: 2023-12-20
---

--- xneur.orig/configure.ac
+++ xneur/configure.ac
@@ -143,7 +143,7 @@
        AC_DEFINE(WITH_DEBUG, 1, [Define if you want debug support])
 fi
 
-PKG_CHECK_MODULES(PCRE, [libpcre >= 5.0])
+PKG_CHECK_MODULES(PCRE, [libpcre2-8])
 
 AC_ARG_WITH(keylogger, [  --without-keylogger    Compile without keylogger 
function])
 if test "x$with_keylogger" != "xno"; then
--- xneur.orig/lib/misc/regexp.c
+++ xneur/lib/misc/regexp.c
@@ -21,7 +21,8 @@
 #  include "config.h"
 #endif
 
-#include <pcre.h>
+#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>
 
 #include <string.h>
 #include <stdio.h>
@@ -31,45 +32,58 @@
 
 int check_regexp_match(const char *str, const char *pattern)
 {
-       int options = PCRE_UTF8;
-       const char *error;
-       int erroffset;
+       pcre2_compile_context *ctxt;
+       uint32_t options = PCRE2_UTF;
+       int error;
+       PCRE2_SIZE erroffset;
        
        //log_message(DEBUG, "Processing word '%s' against regular expression 
'%s'", str, pattern);
        
-       const unsigned char *tables = pcre_maketables();
-       pcre *re = pcre_compile(pattern, options, &error, &erroffset, tables);
+       ctxt = pcre2_compile_context_create(NULL);
+       const uint8_t *tables = pcre2_maketables(NULL);
+       pcre2_set_character_tables(ctxt, tables);
+       pcre2_code *re = pcre2_compile((PCRE2_SPTR)pattern, strlen(pattern),
+                                      options, &error, &erroffset, ctxt);
+       pcre2_maketables_free(NULL, tables);
+       pcre2_compile_context_free(ctxt);
        if (!re)
        {
                log_message(ERROR, _("Can't compile regular expression '%s'"), 
pattern);
                return FALSE;
        }
 
-       int str_len = strlen(str);
+       PCRE2_SIZE str_len = strlen(str);
 
-       int ovector[50];
-       int count = pcre_exec(re, NULL, str, str_len, 0, 0, ovector, 50);
-       if (count <= 0 && count != PCRE_ERROR_NOMATCH)
+       pcre2_match_data *ovector;
+       ovector = pcre2_match_data_create(50, NULL);
+       int count = pcre2_match(re, (PCRE2_SPTR)str, str_len, 0, 0, ovector, 
NULL);
+       if (count <= 0 && count != PCRE2_ERROR_NOMATCH)
        {
                log_message(ERROR, _("Can't exec regular expression '%s', eror 
code %d"), pattern, count);
-               pcre_free(re);
-               pcre_free((void*)tables);
+               pcre2_code_free(re);
+               pcre2_match_data_free(ovector);
                return FALSE;
        }
 
-       pcre_free(re);
-       pcre_free((void*)tables);
+       pcre2_code_free(re);
        
-       if (count == PCRE_ERROR_NOMATCH)
+       if (count == PCRE2_ERROR_NOMATCH)
+       {
+               pcre2_match_data_free(ovector);
                return FALSE;
+       }
        
-       const char *pcre_string = NULL;
-       if(pcre_get_substring(str, ovector, count, 0, &pcre_string) < 0)
+       PCRE2_UCHAR *pcre_string;
+       if(pcre2_substring_get_bynumber(ovector, 0, &pcre_string, &str_len) < 0)
+       {
+               pcre2_match_data_free(ovector);
                return FALSE;
+       }
 
        //log_message(TRACE, _("Match word '%s' and PERL pattern '%s'"), str, 
pattern);
        
-       pcre_free_substring(pcre_string);
+       pcre2_substring_free(pcre_string);
+       pcre2_match_data_free(ovector);
                
        return TRUE;
 }

Reply via email to