From 51fdc21a48e4e576f83a778a93d3f1e52732d88a Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 18 Aug 2024 20:53:07 +0900 Subject: twin compton: use libpcre2 instead of libpcre Signed-off-by: Michele Calgaro (cherry picked from commit 2bc7176522c8cb2b154894312e2687686d7885d8) --- twin/compton-tde/CMakeLists.txt | 16 +++++------ twin/compton-tde/c2.c | 51 ++++++++++++++++----------------- twin/compton-tde/c2.h | 21 ++++---------- twin/compton-tde/common.h | 10 +++---- twin/compton-tde/compton_config.h.cmake | 10 +++---- twin/compton-tde/man/compton-tde.1.html | 4 +-- twin/compton-tde/man/compton.1 | 4 +-- 7 files changed, 51 insertions(+), 65 deletions(-) (limited to 'twin') diff --git a/twin/compton-tde/CMakeLists.txt b/twin/compton-tde/CMakeLists.txt index d432b533f..8e29dd12c 100644 --- a/twin/compton-tde/CMakeLists.txt +++ b/twin/compton-tde/CMakeLists.txt @@ -24,7 +24,7 @@ include_directories( ${XINERAMA_INCLUDE_DIRS} ${XRANDR_INCLUDE_DIRS} ${GL_INCLUDE_DIRS} - ${LIBPCRE_INCLUDE_DIRS} + ${LIBPCRE2_INCLUDE_DIRS} ) link_directories( @@ -33,7 +33,7 @@ link_directories( ${XINERAMA_LIBRARY_DIRS} ${XRANDR_LIBRARY_DIRS} ${GL_LIBRARY_DIRS} - ${LIBPCRE_LIBRARY_DIRS} + ${LIBPCRE2_LIBRARY_DIRS} ) @@ -46,8 +46,8 @@ link_directories( # WITH_OPENGL -> CONFIG_VSYNC_OPENGL # WITH_OPENGL -> CONFIG_VSYNC_OPENGL_GLSL # WITH_OPENGL -> CONFIG_VSYNC_OPENGL_FBO -# WITH_PCRE -> CONFIG_REGEX_PCRE -# WITH_PCRE -> CONFIG_REGEX_PCRE_JIT +# WITH_PCRE2 -> CONFIG_REGEX_PCRE2 +# WITH_PCRE2 -> CONFIG_REGEX_PCRE2_JIT # WITH_LIBCONFIG -> CONFIG_LIBCONFIG # # HAVE_LIBCONFIG_OLD_API -> CONFIG_LIBCONFIG_LEGACY (set up in compton_config.h) @@ -90,10 +90,10 @@ if( WITH_XRANDR ) list( APPEND compton_LIBRARIES ${XRANDR_LIBRARIES} ) endif( ) -if( WITH_PCRE ) - set( CONFIG_REGEX_PCRE ${WITH_PCRE} ) - set( CONFIG_REGEX_PCRE_JIT ${WITH_PCRE} ) - list( APPEND compton_LIBRARIES ${LIBPCRE_LIBRARIES} ) +if( WITH_PCRE2 ) + set( CONFIG_REGEX_PCRE2 ${WITH_PCRE2} ) + set( CONFIG_REGEX_PCRE2_JIT ${WITH_PCRE2} ) + list( APPEND compton_LIBRARIES ${LIBPCRE2_LIBRARIES} ) endif( ) configure_file( compton_config.h.cmake compton_config.h ) diff --git a/twin/compton-tde/c2.c b/twin/compton-tde/c2.c index 6baf1337e..147cb781d 100644 --- a/twin/compton-tde/c2.c +++ b/twin/compton-tde/c2.c @@ -785,33 +785,34 @@ c2_l_postprocess(session_t *ps, c2_l_t *pleaf) { // PCRE patterns if (C2_L_PTSTRING == pleaf->ptntype && C2_L_MPCRE == pleaf->match) { -#ifdef CONFIG_REGEX_PCRE - const char *error = NULL; - int erroffset = 0; - int options = 0; +#ifdef CONFIG_REGEX_PCRE2 + int errorCode; + PCRE2_SIZE errorOffset; + uint32_t options = 0; // Ignore case flag if (pleaf->match_ignorecase) - options |= PCRE_CASELESS; + options |= PCRE2_CASELESS; - // Compile PCRE expression - pleaf->regex_pcre = pcre_compile(pleaf->ptnstr, options, - &error, &erroffset, NULL); + // Compile PCRE2 expression + pleaf->regex_pcre = pcre2_compile((PCRE2_SPTR)pleaf->ptnstr, PCRE2_ZERO_TERMINATED, + options, &errorCode, &errorOffset, NULL); if (!pleaf->regex_pcre) - c2_error("Pattern \"%s\": PCRE regular expression parsing failed on " - "offset %d: %s", pleaf->ptnstr, erroffset, error); -#ifdef CONFIG_REGEX_PCRE_JIT - pleaf->regex_pcre_extra = pcre_study(pleaf->regex_pcre, - PCRE_STUDY_JIT_COMPILE, &error); - if (!pleaf->regex_pcre_extra) { - printf("Pattern \"%s\": PCRE regular expression study failed: %s", - pleaf->ptnstr, error); + { + PCRE2_UCHAR errorMsg[256]; + pcre2_get_error_message(errorCode, errorMsg, sizeof(errorMsg)); + c2_error("Pattern \"%s\": PCRE2 regular expression parsing failed on " + "offset %zu: %s", pleaf->ptnstr, errorOffset, errorMsg); + } +#ifdef CONFIG_REGEX_PCRE2_JIT + int jit_res = pcre2_jit_compile(pleaf->regex_pcre, PCRE2_JIT_COMPLETE); + if (jit_res < 0) + { + printf("Pattern \"%s\": PCRE2 regular expression JIT compilation failed with error code %d", + pleaf->ptnstr, jit_res); } #endif - // Free the target string - // free(pleaf->tgt); - // pleaf->tgt = NULL; #else c2_error("PCRE regular expression support not compiled in."); #endif @@ -844,9 +845,8 @@ c2_free(c2_ptr_t p) { free(pleaf->tgt); free(pleaf->ptnstr); -#ifdef CONFIG_REGEX_PCRE - pcre_free(pleaf->regex_pcre); - LPCRE_FREE_STUDY(pleaf->regex_pcre_extra); +#ifdef CONFIG_REGEX_PCRE2 + pcre2_code_free(pleaf->regex_pcre); #endif free(pleaf); } @@ -1180,10 +1180,9 @@ c2_match_once_leaf(session_t *ps, win *w, const c2_l_t *pleaf, } break; case C2_L_MPCRE: -#ifdef CONFIG_REGEX_PCRE - *pres = (pcre_exec(pleaf->regex_pcre, - pleaf->regex_pcre_extra, - tgt, strlen(tgt), 0, 0, NULL, 0) >= 0); +#ifdef CONFIG_REGEX_PCRE2 + *pres = (pcre2_match(pleaf->regex_pcre, (PCRE2_SPTR)tgt, PCRE2_ZERO_TERMINATED, + 0, 0, NULL, NULL) >= 0); #else assert(0); #endif diff --git a/twin/compton-tde/c2.h b/twin/compton-tde/c2.h index 9e04c09a8..c84836c25 100644 --- a/twin/compton-tde/c2.h +++ b/twin/compton-tde/c2.h @@ -13,18 +13,10 @@ #include #include -// libpcre -#ifdef CONFIG_REGEX_PCRE -#include - -// For compatiblity with #endif #define C2_MAX_LEVELS 10 @@ -139,9 +131,8 @@ struct _c2_l { } ptntype; char *ptnstr; long ptnint; -#ifdef CONFIG_REGEX_PCRE - pcre *regex_pcre; - pcre_extra *regex_pcre_extra; +#ifdef CONFIG_REGEX_PCRE2 + pcre2_code *regex_pcre; #endif }; diff --git a/twin/compton-tde/common.h b/twin/compton-tde/common.h index 9091fc582..d92396cdf 100644 --- a/twin/compton-tde/common.h +++ b/twin/compton-tde/common.h @@ -38,12 +38,10 @@ // #define MONITOR_REPAINT 1 // #define DEBUG_FADE 1 -// Whether to enable PCRE regular expression support in blacklists, enabled -// by default -// #define CONFIG_REGEX_PCRE 1 -// Whether to enable JIT support of libpcre. This may cause problems on PaX -// kernels. -// #define CONFIG_REGEX_PCRE_JIT 1 +// Whether to enable PCRE2 regular expression support in blacklists, enabled by default +// #define CONFIG_REGEX_PCRE2 1 +// Whether to enable JIT support of libpcre2. This may cause problems on PaX kernels. +// #define CONFIG_REGEX_PCRE2_JIT 1 // Whether to enable parsing of configuration files using libconfig. // #define CONFIG_LIBCONFIG 1 // Whether we are using a legacy version of libconfig (1.3.x). diff --git a/twin/compton-tde/compton_config.h.cmake b/twin/compton-tde/compton_config.h.cmake index bf3f22543..b534b1b80 100644 --- a/twin/compton-tde/compton_config.h.cmake +++ b/twin/compton-tde/compton_config.h.cmake @@ -1,11 +1,9 @@ #include "config.h" -// Whether to enable PCRE regular expression support in blacklists, enabled -// by default -#cmakedefine CONFIG_REGEX_PCRE 1 -// Whether to enable JIT support of libpcre. This may cause problems on PaX -// kernels. -#cmakedefine CONFIG_REGEX_PCRE_JIT 1 +// Whether to enable PCRE2 regular expression support in blacklists, enabled by default +#cmakedefine CONFIG_REGEX_PCRE2 1 +// Whether to enable JIT support of libpcre2. This may cause problems on PaX kernels. +#cmakedefine CONFIG_REGEX_PCRE2_JIT 1 // Whether to enable parsing of configuration files using libconfig. #cmakedefine CONFIG_LIBCONFIG 1 diff --git a/twin/compton-tde/man/compton-tde.1.html b/twin/compton-tde/man/compton-tde.1.html index 26d2a3b21..34243b08e 100644 --- a/twin/compton-tde/man/compton-tde.1.html +++ b/twin/compton-tde/man/compton-tde.1.html @@ -1422,7 +1422,7 @@ compton(1) Manual Page

FORMAT (optional) specifies the format of the property, 8, 16, or 32. On absence we use format X reports. Do not specify it for predefined or string targets.

TYPE is a single character representing the type of the property to match for: c for CARDINAL, a for ATOM, w for WINDOW, d for DRAWABLE, s for STRING (and any other string types, such as UTF8_STRING). Do not specify it for predefined targets.

OP QUALIFIER (optional), applicable only for equals operator, could be ? (ignore-case).

-

MATCH TYPE (optional), applicable only for equals operator, could be nothing (exact match), * (match anywhere), ^ (match from start), % (wildcard), or ~ (PCRE regular expression).

+

MATCH TYPE (optional), applicable only for equals operator, could be nothing (exact match), * (match anywhere), ^ (match from start), % (wildcard), or ~ (PCRE2 regular expression).

OPERATOR is one of = (equals), <, >, <=, =>, or nothing (exists). Exists operator checks whether a property exists on a window (but for predefined targets, exists means != 0 then).

PATTERN is either an integer or a string enclosed by single or double quotes. Python-3-style escape sequences and raw string are supported in the string format.

Supported logical operators are && (and) and || (or). && has higher precedence than ||, left-to-right associativity. Use parentheses to change precedence.

@@ -1468,7 +1468,7 @@ name = r"\x64\x64\o64"
condition = TARGET:TYPE[FLAGS]:PATTERN

TARGET is one of "n" (window name), "i" (window class instance), "g" (window general class), and "r" (window role).

-

TYPE is one of "e" (exact match), "a" (match anywhere), "s" (match from start), "w" (wildcard), and "p" (PCRE regular expressions, if compiled with the support).

+

TYPE is one of "e" (exact match), "a" (match anywhere), "s" (match from start), "w" (wildcard), and "p" (PCRE2 regular expressions, if compiled with the support).

FLAGS could be a series of flags. Currently the only defined flag is "i" (ignore case).

PATTERN is the actual pattern string.

diff --git a/twin/compton-tde/man/compton.1 b/twin/compton-tde/man/compton.1 index 964c4158d..a4e4dd7d9 100644 --- a/twin/compton-tde/man/compton.1 +++ b/twin/compton-tde/man/compton.1 @@ -659,7 +659,7 @@ With greater\-than/less\-than operators it looks like: .sp \fIOP QUALIFIER\fR (optional), applicable only for equals operator, could be ? (ignore\-case)\&. .sp -\fIMATCH TYPE\fR (optional), applicable only for equals operator, could be nothing (exact match), * (match anywhere), ^ (match from start), % (wildcard), or ~ (PCRE regular expression)\&. +\fIMATCH TYPE\fR (optional), applicable only for equals operator, could be nothing (exact match), * (match anywhere), ^ (match from start), % (wildcard), or ~ (PCRE2 regular expression)\&. .sp \fIOPERATOR\fR is one of = (equals), <, >, <=, =>, or nothing (exists)\&. Exists operator checks whether a property exists on a window (but for predefined targets, exists means != 0 then)\&. .sp @@ -720,7 +720,7 @@ condition = TARGET:TYPE[FLAGS]:PATTERN .sp \fITARGET\fR is one of "n" (window name), "i" (window class instance), "g" (window general class), and "r" (window role)\&. .sp -\fITYPE\fR is one of "e" (exact match), "a" (match anywhere), "s" (match from start), "w" (wildcard), and "p" (PCRE regular expressions, if compiled with the support)\&. +\fITYPE\fR is one of "e" (exact match), "a" (match anywhere), "s" (match from start), "w" (wildcard), and "p" (PCRE2 regular expressions, if compiled with the support)\&. .sp \fIFLAGS\fR could be a series of flags\&. Currently the only defined flag is "i" (ignore case)\&. .sp -- cgit v1.2.1