File kdelibs-pcre2.patch of Package kdelibs3
diff -Naru kdelibs-3.5.10_orig/configure.in kdelibs-3.5.10/configure.in
--- kdelibs-3.5.10_orig/configure.in 2025-04-26 18:12:30.902000000 +0900
+++ kdelibs-3.5.10/configure.in 2025-04-26 18:41:43.250827134 +0900
@@ -1989,12 +1989,12 @@
if test "$with_pcre" = "yes"; then
- KDE_FIND_PATH(pcre-config, PCRE_CONFIG, [${exec_prefix}/bin ${prefix}/bin], [PCRE_CONFIG="" ])
+ KDE_FIND_PATH(pcre2-config, PCRE_CONFIG, [${exec_prefix}/bin ${prefix}/bin], [PCRE_CONFIG="" ])
if test -n "$PCRE_CONFIG" && $PCRE_CONFIG --libs >/dev/null 2>&1; then
LIBPCRE=`$PCRE_CONFIG --libs-posix | sed -e "s,-L/usr/lib ,,"`
PCRECFLAGS=`$PCRE_CONFIG --cflags`
else
- LIBPCRE="-lpcre -lpcreposix"
+ LIBPCRE="-lpcre2-8 -lpcre2-posix"
PCRECFLAGS=
fi
AC_CACHE_VAL(ac_cv_have_pcreposix, [
@@ -2005,7 +2005,8 @@
ac_LDFLAGS_save="$LDFLAGS"
LDFLAGS="$LDFLAGS $all_libraries"
AC_TRY_LINK(
- [#include <pcre.h>],
+ [#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>],
[regfree(0);],
[ac_cv_have_pcreposix="yes"],
[ac_cv_have_pcreposix="no"]
diff -Naru kdelibs-3.5.10_orig/kjs/configure.in.in kdelibs-3.5.10/kjs/configure.in.in
--- kdelibs-3.5.10_orig/kjs/configure.in.in 2007-10-08 18:52:09.000000000 +0900
+++ kdelibs-3.5.10/kjs/configure.in.in 2025-04-26 18:41:20.049104497 +0900
@@ -50,12 +50,12 @@
if test "$with_pcre" = "yes"; then
- KDE_FIND_PATH(pcre-config, PCRE_CONFIG, [${exec_prefix}/bin ${prefix}/bin], [PCRE_CONFIG="" ])
+ KDE_FIND_PATH(pcre2-config, PCRE_CONFIG, [${exec_prefix}/bin ${prefix}/bin], [PCRE_CONFIG="" ])
if test -n "$PCRE_CONFIG" && $PCRE_CONFIG --libs >/dev/null 2>&1; then
LIBPCRE=`$PCRE_CONFIG --libs-posix | sed -e "s,-L/usr/lib ,,"`
PCRECFLAGS=`$PCRE_CONFIG --cflags`
else
- LIBPCRE="-lpcre -lpcreposix"
+ LIBPCRE="-lpcre2-8 -lpcre2-posix"
PCRECFLAGS=
fi
AC_CACHE_VAL(ac_cv_have_pcreposix, [
@@ -66,7 +66,8 @@
ac_LDFLAGS_save="$LDFLAGS"
LDFLAGS="$LDFLAGS $all_libraries"
AC_TRY_LINK(
- [#include <pcre.h>],
+ [#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>],
[regfree(0);],
[ac_cv_have_pcreposix="yes"],
[ac_cv_have_pcreposix="no"]
diff -Naru kdelibs-3.5.10_orig/kjs/regexp.cpp kdelibs-3.5.10/kjs/regexp.cpp
--- kdelibs-3.5.10_orig/kjs/regexp.cpp 2007-05-14 16:52:42.000000000 +0900
+++ kdelibs-3.5.10/kjs/regexp.cpp 2025-04-27 09:49:19.411482396 +0900
@@ -129,14 +129,14 @@
#ifdef HAVE_PCREPOSIX
int pcreflags = 0;
- const char *perrormsg;
- int errorOffset;
+ int errorcode;
+ PCRE2_SIZE errorOffset;
if (flgs & IgnoreCase)
- pcreflags |= PCRE_CASELESS;
+ pcreflags |= PCRE2_CASELESS;
if (flgs & Multiline)
- pcreflags |= PCRE_MULTILINE;
+ pcreflags |= PCRE2_MULTILINE;
#ifdef PCRE_CONFIG_UTF8
if (utf8Support == Supported)
@@ -147,12 +147,14 @@
// if PCRE is incapable, truncated.
prepareMatch(intern);
- pcregex = pcre_compile(buffer, pcreflags,
- &perrormsg, &errorOffset, NULL);
+ pcregex = pcre2_compile((PCRE2_SPTR)buffer, PCRE2_ZERO_TERMINATED, pcreflags,
+ &errorcode, &errorOffset, NULL);
doneMatch(); // Cleanup buffers
if (!pcregex) {
#ifndef NDEBUG
- fprintf(stderr, "KJS: pcre_compile() failed with '%s'\n", perrormsg);
+ PCRE2_UCHAR errormsg[256];
+ pcre2_get_error_message(errorcode, errormsg, sizeof(errormsg));
+ fprintf(stderr, "KJS: pcre_compile() failed with '%s' at %d\n", errormsg, errorOffset);
#endif
valid = false;
return;
@@ -198,7 +200,7 @@
doneMatch(); // Be 100% sure buffers are freed
#ifdef HAVE_PCREPOSIX
if (pcregex)
- pcre_free(pcregex);
+ pcre2_code_free(pcregex);
#else
/* TODO: is this really okay after an error ? */
regfree(&preg);
@@ -339,10 +341,13 @@
utf8Support == Supported ? PCRE_NO_UTF8_CHECK :
#endif
0;
- if (pcre_exec(pcregex, NULL, buffer, bufferSize, startPos,
- m_notEmpty ? (PCRE_NOTEMPTY | PCRE_ANCHORED | baseFlags) : baseFlags, // see man pcretest
- ovector ? *ovector : 0L, ovecsize) == PCRE_ERROR_NOMATCH)
+ pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(pcregex, NULL);
+ if (pcre2_match(pcregex, (PCRE2_SPTR)buffer, bufferSize, startPos,
+ m_notEmpty ? (PCRE2_NOTEMPTY | PCRE2_ANCHORED | baseFlags) : baseFlags, // see man pcretest
+ match_data, 0) == PCRE2_ERROR_NOMATCH)
{
+ pcre2_match_data_free(match_data);
+
// Failed to match.
if ((flgs & Global) && m_notEmpty && ovector)
{
@@ -353,19 +358,28 @@
fprintf(stderr, "No match after m_notEmpty. +1 and keep going.\n");
#endif
m_notEmpty = 0;
- if (pcre_exec(pcregex, NULL, buffer, bufferSize, nextPos, baseFlags,
- ovector ? *ovector : 0L, ovecsize) == PCRE_ERROR_NOMATCH)
+ if (pcre2_match(pcregex, (PCRE2_SPTR)buffer, bufferSize, nextPos, baseFlags,
+ match_data, 0) == PCRE2_ERROR_NOMATCH)
return UString::null;
}
else // done
return UString::null;
}
+ if (ovector) {
+ PCRE2_SIZE *ovector_src = pcre2_get_ovector_pointer(match_data);
+ int ovector_size = sizeof(ovector_src) / sizeof(PCRE2_SIZE);
+ *ovector = new int[ovector_size];
+ for (int i = 0; i < ovector_size; i++) (*ovector)[i] = (int) ovector_src[i];
+ }
+
+ pcre2_match_data_free(match_data);
+
// Got a match, proceed with it.
// But fix up the ovector if need be..
if (ovector && originalPos) {
for (unsigned c = 0; c < 2 * (nrSubPatterns + 1); ++c) {
- if ((*ovector)[c] != -1)
+ if ((*ovector)[c] != (int) -1)
(*ovector)[c] = originalPos[(*ovector)[c]];
}
}
diff -Naru kdelibs-3.5.10_orig/kjs/regexp.h kdelibs-3.5.10/kjs/regexp.h
--- kdelibs-3.5.10_orig/kjs/regexp.h 2007-05-14 16:52:42.000000000 +0900
+++ kdelibs-3.5.10/kjs/regexp.h 2025-04-27 09:37:14.693564149 +0900
@@ -27,7 +27,8 @@
#include "config.h"
#ifdef HAVE_PCREPOSIX
-#include <pcre.h>
+#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>
#else // POSIX regex - not so good...
extern "C" { // bug with some libc5 distributions
#include <regex.h>
@@ -75,7 +76,7 @@
#ifndef HAVE_PCREPOSIX
regex_t preg;
#else
- pcre *pcregex;
+ pcre2_code *pcregex;
enum UTF8SupportState {
Unknown,