Control: tags -1 + patch Please find attached a patch.
Description: Port to PCRE2. Bug-Debian: https://bugs.debian.org/999964 Author: Yavor Doganov <ya...@gnu.org> Forwarded: no Last-Update: 2023-12-17 ---
--- shush-1.2.3.orig/configure.ac +++ shush-1.2.3/configure.ac @@ -60,9 +60,19 @@ # Checks for libraries. AC_SEARCH_LIBS([basename], [gen]) if test "x$with_pcre" != "xno"; then - AC_SEARCH_LIBS([pcre_compile], [pcre], , - AC_MSG_WARN([Perl Compatible Regular Expressions library is missing.]) - with_pcre="no") + save_libs="$LIBS" + LIBS="$LIBS -lpcre2-8" + AC_MSG_CHECKING([for pcre library]) + AC_LINK_IFELSE( + [AC_LANG_PROGRAM([[#define PCRE2_CODE_UNIT_WIDTH 8 +#include <pcre2.h> +]], + [[pcre2_match_data_create(4, NULL);]])], + [AC_MSG_RESULT([yes])], + [AC_MSG_RESULT([no]) + AC_MSG_WARN([Perl Compatible Regular Expressions library is missing.]) + with_pcre="no" + LIBS="$save_libs"]) fi AC_SEARCH_LIBS([MD5Data], [md]) AC_SEARCH_LIBS([md5_calc], [md5]) @@ -70,7 +80,11 @@ # Checks for header files. AC_CHECK_HEADERS([md5.h paths.h pthread.h]) if test "x$with_pcre" != "xno"; then - AC_CHECK_HEADERS([pcre.h]) + AC_CHECK_HEADERS([pcre2.h], + [AC_DEFINE([HAVE_PCRE_H], [1], + [Define to 1 if you have the <pcre2.h> header file.])], + [], [[#define PCRE2_CODE_UNIT_WIDTH 8 + ]]) fi # Checks for typedefs, structures, and compiler characteristics. --- shush-1.2.3.orig/src/analyzer.c +++ shush-1.2.3/src/analyzer.c @@ -16,7 +16,8 @@ #include <fcntl.h> #include <regex.h> #if defined(HAVE_PCRE_H) -# include <pcre.h> +# define PCRE2_CODE_UNIT_WIDTH 8 +# include <pcre2.h> #endif #include "analyzer.h" @@ -40,7 +41,7 @@ { regex_t re; #if defined(HAVE_PCRE_H) - pcre *pcre; + pcre2_code *pcre; #endif } val; }; @@ -98,15 +99,19 @@ static int compile_pcre(void *pcreptr, char *str) { - pcre **re; - const char *errmsg; - int erroffset; + pcre2_code **re; + int err; + PCRE2_SIZE erroffset; re = pcreptr; - *re = pcre_compile(str, 0, &errmsg, &erroffset, NULL); + *re = pcre2_compile((PCRE2_SPTR)str, strlen(str), 0, + &err, &erroffset, NULL); if (*re == NULL) { - error("Bad PCRE (offset %d): %s", erroffset, errmsg); + PCRE2_UCHAR errmsg[120]; + + pcre2_get_error_message(err, errmsg, sizeof(errmsg)); + error("Bad PCRE (offset %zu): %s", erroffset, errmsg); return -1; } return 0; @@ -501,15 +506,17 @@ #if defined(HAVE_PCRE_H) else if (type == PCRE) { - int ovector[3072]; + PCRE2_SIZE *ovector; + pcre2_match_data *md; - r = pcre_exec(list[condno].val.pcre, NULL, ln, + md = pcre2_match_data_create(3072, NULL); + r = pcre2_match(list[condno].val.pcre, (PCRE2_SPTR)ln, (lndup != NULL) ? strlen(lndup) : nl - ln, - 0, 0, ovector, 3072); - if (r < 0 && r != PCRE_ERROR_NOMATCH) + 0, 0, md, NULL); + if (r < 0 && r != PCRE2_ERROR_NOMATCH) { /* Something bad happened */ - error("Fatal error during output analysis: pcre_exec() failed with code %d", r); + error("Fatal error during output analysis: pcre2_match() failed with code %d", r); error("Regular expression used was: %s", list[condno].expression); error("Trying to match the following line of data: %s", ln); @@ -517,6 +524,7 @@ free(lndup); else *nl = '\n'; + pcre2_match_data_free(md); return -1; } else @@ -527,14 +535,15 @@ /* Matched */ debug(DDATA, - "Matched: #%d %d[%c] (PCRE_ERROR_NOMATCH=%d)", - condno+1, r, list[condno].code, PCRE_ERROR_NOMATCH); + "Matched: #%d %d[%c] (PCRE2_ERROR_NOMATCH=%d)", + condno+1, r, list[condno].code, PCRE2_ERROR_NOMATCH); byteset_set(list[condno].code, 1); /* Check for substrings */ i = 1; + ovector = pcre2_get_ovector_pointer(md); while (i < r) { - if (ovector[i*2] < 0 || ovector[i*2+1] < 0) + if ((int)ovector[i*2] < 0 || (int)ovector[i*2+1] < 0) continue; set_mark(marks, &mark, &max, ln - str + ovector[i*2], TOGGLE); @@ -546,8 +555,9 @@ } else debug(DVDATA, - "Failed: #%d %d[%c] (PCRE_ERROR_NOMATCH=%d)", - condno+1, r, list[condno].code, PCRE_ERROR_NOMATCH); + "Failed: #%d %d[%c] (PCRE2_ERROR_NOMATCH=%d)", + condno+1, r, list[condno].code, PCRE2_ERROR_NOMATCH); + pcre2_match_data_free(md); } } #endif --- shush-1.2.3.orig/src/shush.c +++ shush-1.2.3/src/shush.c @@ -10,7 +10,8 @@ #include <libgen.h> #include <time.h> #if defined(HAVE_PCRE_H) -# include <pcre.h> +# define PCRE2_CODE_UNIT_WIDTH 8 +# include <pcre2.h> #endif #include "version.h" @@ -149,8 +150,11 @@ #if !defined(HAVE_PCRE_H) printf("%s version %s\n", myname, SHUSH_VERSION); #else + char ver[24]; + + pcre2_config(PCRE2_CONFIG_VERSION, ver); printf("%s version %s (PCRE version %s)\n", - myname, SHUSH_VERSION, pcre_version()); + myname, SHUSH_VERSION, ver); #endif if ((runopts & RUN_VERBOSE) != 0) {