From edbce01731c9652d0386245d5bf32af4fd43be6a Mon Sep 17 00:00:00 2001 From: Florian Zwoch Date: Mon, 28 Aug 2023 17:45:55 +0200 Subject: [PATCH] PCRE -> PCRE2 --- .github/workflows/scripts/homebrew.sh | 2 +- Makefile | 8 +- README.md | 8 +- build-linux.sh | 6 +- src/EX_browser.c | 21 ++--- src/cmd.c | 30 ++++--- src/fonts.c | 33 ++++---- src/parser.c | 24 +++--- src/parser.h | 2 +- src/sv_demo_misc.c | 76 +++++++++++------- src/sv_mod_frags.c | 29 ++++--- src/sv_sys_win.c | 44 +++++++---- src/sys_posix.c | 43 ++++++---- src/sys_win.c | 40 ++++++---- src/teamplay.h | 2 +- src/tp_triggers.c | 77 +++++++++--------- src/tp_triggers.h | 6 +- src/utils.c | 109 ++++++++++++-------------- 18 files changed, 303 insertions(+), 257 deletions(-) diff --git a/.github/workflows/scripts/homebrew.sh b/.github/workflows/scripts/homebrew.sh index 0cb16a47f..818a54c1a 100755 --- a/.github/workflows/scripts/homebrew.sh +++ b/.github/workflows/scripts/homebrew.sh @@ -10,7 +10,7 @@ set -e # dependencies to avoid installing Intel versions in the cross-compilation # case. dependencies=( - pcre + pcre2 freetype jansson libpng diff --git a/Makefile b/Makefile index 12dc8bf4c..9187cfacf 100644 --- a/Makefile +++ b/Makefile @@ -115,10 +115,10 @@ ZLIB_LIBS ?= -lz CFLAGS_c += $(ZLIB_CFLAGS) LIBS_c += $(ZLIB_LIBS) -PCRE_CFLAGS ?= $(shell pkg-config libpcre --cflags) -PCRE_LIBS ?= $(shell pkg-config libpcre --libs) -CFLAGS_c += $(PCRE_CFLAGS) -LIBS_c += $(PCRE_LIBS) +PCRE2_CFLAGS ?= $(shell pkg-config libpcre2-8 --cflags) +PCRE2_LIBS ?= $(shell pkg-config libpcre2-8 --libs) +CFLAGS_c += $(PCRE2_CFLAGS) -DPCRE2_CODE_UNIT_WIDTH=8 +LIBS_c += $(PCRE2_LIBS) EXPAT_CFLAGS ?= $(shell pkg-config expat --cflags) EXPAT_LIBS ?= $(shell pkg-config expat --libs) diff --git a/README.md b/README.md index 3712d2a74..4eec6734c 100644 --- a/README.md +++ b/README.md @@ -144,17 +144,17 @@ Make sure you have the dependencies installed: - For *Debian/Ubuntu 16.10+* ``` -sudo apt install git build-essential libsdl2-dev libjansson-dev libexpat-dev libcurl4-openssl-dev libpng-dev libjpeg-dev libsndfile-dev libspeex-dev libspeexdsp-dev libxxf86vm-dev libpcre3-dev +sudo apt install git build-essential libsdl2-dev libjansson-dev libexpat-dev libcurl4-openssl-dev libpng-dev libjpeg-dev libsndfile-dev libspeex-dev libspeexdsp-dev libxxf86vm-dev libpcre2-dev ``` - For *openSUSE Tumbleweed* ``` sudo zypper install -t pattern devel_C_C++ -sudo zypper install git pcre-devel Mesa-libGL-devel SDL2-devel libjansson-devel libexpat-devel libcurl-devel libpng16-devel libpng16-compat-devel libjpeg8-devel libjpeg-turbo libsndfile-devel speex-devel speexdsp-devel libXxf86vm-devel +sudo zypper install git pcre2-devel Mesa-libGL-devel SDL2-devel libjansson-devel libexpat-devel libcurl-devel libpng16-devel libpng16-compat-devel libjpeg8-devel libjpeg-turbo libsndfile-devel speex-devel speexdsp-devel libXxf86vm-devel ``` - For *Fedora* ``` sudo dnf group install 'C Development Tools and Libraries' -sudo dnf install git pcre-devel mesa-libEGL-devel SDL2-devel jansson-devel expat-devel libcurl-devel libpng-devel libjpeg-turbo-devel libsndfile-devel speex-devel speexdsp-devel libXxf86vm-devel +sudo dnf install git pcre2-devel mesa-libEGL-devel SDL2-devel jansson-devel expat-devel libcurl-devel libpng-devel libjpeg-turbo-devel libsndfile-devel speex-devel speexdsp-devel libXxf86vm-devel ``` Clone the git repository: @@ -197,7 +197,7 @@ Make sure you run the `brew doctor` as instructed before doing anything else. Then run: ``` -brew install sdl2 sdl2_net sdl2_image sdl2_gfx sdl2_mixer pcre jansson pkg-config speex speexdsp libsndfile +brew install sdl2 sdl2_net sdl2_image sdl2_gfx sdl2_mixer pcre2 jansson pkg-config speex speexdsp libsndfile ``` When it's done, just run `make` and it should compile without errors. diff --git a/build-linux.sh b/build-linux.sh index 29ba2d675..444a10955 100755 --- a/build-linux.sh +++ b/build-linux.sh @@ -9,10 +9,10 @@ NC='\e[0m' BUILD_LOG=/tmp/ezquake-build.log -PKGS_DEB="git build-essential libsdl2-2.0-0 libsdl2-dev libjansson-dev libexpat1-dev libcurl4-openssl-dev libpng-dev libjpeg-dev libspeex-dev libspeexdsp-dev libfreetype6-dev libsndfile1-dev libpcre3-dev libminizip-dev" -PKGS_RPM="pcre-devel mesa-libGL-devel SDL2-devel make gcc jansson-devel expat-devel libcurl-devel libpng-devel libjpeg-turbo-devel speex-devel speexdsp-devel freetype-devel libsndfile-devel libXxf86vm-devel minizip-devel" +PKGS_DEB="git build-essential libsdl2-2.0-0 libsdl2-dev libjansson-dev libexpat1-dev libcurl4-openssl-dev libpng-dev libjpeg-dev libspeex-dev libspeexdsp-dev libfreetype6-dev libsndfile1-dev libpcre2-dev libminizip-dev" +PKGS_RPM="pcre2-devel mesa-libGL-devel SDL2-devel make gcc jansson-devel expat-devel libcurl-devel libpng-devel libjpeg-turbo-devel speex-devel speexdsp-devel freetype-devel libsndfile-devel libXxf86vm-devel minizip-devel" PKGS_ARCH="base-devel libpng libjpeg-turbo sdl2 expat libcurl-compat freetype2 speex speexdsp jansson libsndfile minizip" -PKGS_VOID="base-devel SDL2-devel pcre-devel jansson-devel expat-devel libcurl-devel libpng-devel libjpeg-turbo-devel speex-devel speexdsp-devel freetype-devel libsndfile-devel libXxf86vm-devel minizip" +PKGS_VOID="base-devel SDL2-devel pcre2-devel jansson-devel expat-devel libcurl-devel libpng-devel libjpeg-turbo-devel speex-devel speexdsp-devel freetype-devel libsndfile-devel libXxf86vm-devel minizip" CPU=$(uname -m | sed -e s/i.86/i386/ -e s/amd64/x86_64/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/ -e s/alpha/axp/) diff --git a/src/EX_browser.c b/src/EX_browser.c index 9c4181ac9..01dfd03ee 100644 --- a/src/EX_browser.c +++ b/src/EX_browser.c @@ -42,7 +42,7 @@ int source_unique = 0; typedef struct info_filter_s { char name[MAX_INFO_KEY]; - pcre* regex; + pcre2_code* regex; qbool pass; qbool exec; } info_filter_t; @@ -3410,11 +3410,12 @@ static qbool SB_InfoFilter_Exec(info_filter_t* info_filters, int info_filter_cou } else { // Rule specified, check it matches the regex - int offsets[8]; - - if (pcre_exec(filter->regex, NULL, value, strlen(value), 0, 0, offsets, sizeof(offsets) / sizeof(offsets[0])) >= 0) { + pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(filter->regex, NULL); + if (pcre2_match(filter->regex, (PCRE2_SPTR)value, strlen(value), 0, 0, match_data, NULL) >= 0) { + pcre2_match_data_free (match_data); return filter->pass; } + pcre2_match_data_free (match_data); } } @@ -3436,8 +3437,8 @@ static info_filter_t* SB_InfoFilter_Parse(int* count) info_filters = Q_malloc(info_filter_count * sizeof(info_filter_t)); for (i = 0; i < info_filter_count; ++i) { char* split; - const char* error; - int error_offset; + int error; + PCRE2_SIZE error_offset; info_filter_t* filter = &info_filters[i]; // filters must be +x=y or -x=y @@ -3462,9 +3463,11 @@ static info_filter_t* SB_InfoFilter_Parse(int* count) if (split != NULL && split[1] && split[1] != '*') { // no regex is fine - filter->regex = pcre_compile(split + 1, PCRE_CASELESS, &error, &error_offset, NULL); + filter->regex = pcre2_compile((PCRE2_SPTR)(split + 1), PCRE2_ZERO_TERMINATED, PCRE2_CASELESS, &error, &error_offset, NULL); if (filter->regex == NULL) { - Con_Printf("Invalid rule definition: %s\n", error); + PCRE2_UCHAR error_str[256]; + pcre2_get_error_message(error, error_str, sizeof(error_str)); + Con_Printf("Invalid rule definition: %s\n", error_str); continue; } } @@ -3481,7 +3484,7 @@ static void SB_InfoFilter_Free(info_filter_t* info_filters, int info_filter_coun for (i = 0; i < info_filter_count; ++i) { if (info_filters[i].regex) { - pcre_free(info_filters[i].regex); + pcre2_code_free(info_filters[i].regex); } } diff --git a/src/cmd.c b/src/cmd.c index bf351a7ec..56ca4406e 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -31,6 +31,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "parser.h" #include "utils.h" #include "keys.h" +#include typedef struct { char name[MAX_MACRO_NAME]; @@ -1900,10 +1901,10 @@ static qbool is_numeric (char *c) (*c == '.' && isdigit((int)(unsigned char)c[1])) ); } -void Re_Trigger_Copy_Subpatterns (const char *s, int* offsets, int num, cvar_t *re_sub); // QW262 +void Re_Trigger_Copy_Subpatterns (const char *s, size_t* offsets, int num, cvar_t *re_sub); // QW262 extern cvar_t re_sub[10]; // QW262 -void Cmd_CatchTriggerSubpatterns(const char *s, int* offsets, int num) +void Cmd_CatchTriggerSubpatterns(const char *s, size_t* offsets, int num) { Re_Trigger_Copy_Subpatterns(s, offsets, min(num, 10), re_sub); } @@ -2043,20 +2044,24 @@ void Cmd_If_Old (void) result = (strstr(Cmd_Argv(3), Cmd_Argv(1)) ? 0 : 1); } else if (!strcmp(op, "=~") || !strcmp(op, "!~")) { - pcre* regexp; - const char *error; - int error_offset; - int rc; - int offsets[99]; + pcre2_code *regexp; + int error; + PCRE2_SIZE error_offset; + pcre2_match_data *match_data = NULL; + int rc; - regexp = pcre_compile (Cmd_Argv(3), 0, &error, &error_offset, NULL); + regexp = pcre2_compile ((PCRE2_SPTR)Cmd_Argv(3), PCRE2_ZERO_TERMINATED, 0, &error, &error_offset, NULL); if (!regexp) { - Com_Printf ("Error in regexp: %s\n", error); + PCRE2_UCHAR error_str[256]; + pcre2_get_error_message(error, error_str, sizeof(error_str)); + Com_Printf ("Error in regexp: %s\n", error_str); return; } - rc = pcre_exec (regexp, NULL, Cmd_Argv(1), strlen(Cmd_Argv(1)), - 0, 0, offsets, 99); + match_data = pcre2_match_data_create_from_pattern(regexp, NULL); + rc = pcre2_match (regexp, (PCRE2_SPTR)Cmd_Argv(1), strlen(Cmd_Argv(1)), + 0, 0, match_data, NULL); if (rc >= 0) { + PCRE2_SIZE *offsets = pcre2_get_ovector_pointer(match_data); Re_Trigger_Copy_Subpatterns (Cmd_Argv(1), offsets, min(rc, 10), re_sub); result = true; } else @@ -2065,7 +2070,8 @@ void Cmd_If_Old (void) if (op[0] != '=') result = !result; - pcre_free (regexp); + pcre2_match_data_free (match_data); + pcre2_code_free (regexp); } else { Com_Printf ("unknown operator: %s\n", op); Com_Printf ("valid operators are ==, =, !=, <>, >, <, >=, <=, isin, !isin, =~, !~\n"); diff --git a/src/fonts.c b/src/fonts.c index 6c5e13bf7..b056a89cc 100644 --- a/src/fonts.c +++ b/src/fonts.c @@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifdef EZ_FREETYPE_SUPPORT #include #include FT_FREETYPE_H -#include "pcre.h" +#include "pcre2.h" #endif #include "quakedef.h" #include "gl_model.h" @@ -449,20 +449,20 @@ void Draw_ListFonts_f(void) char path[MAX_OSPATH]; dir_t dir; int i, printed; - pcre* regexp = NULL; + pcre2_code* regexp = NULL; + pcre2_match_data *match_data = NULL; strlcpy(path, Sys_FontsDirectory(), sizeof(path)); if (Cmd_Argc() > 1) { - const char* error = NULL; - int erroffset = 0; - - regexp = pcre_compile(Cmd_Argv(1), PCRE_CASELESS, &error, &erroffset, NULL); - if (error) { - if (regexp) { - pcre_free(regexp); - } - Con_Printf("Error in regular expression: %s\n", error); + int error = 0; + PCRE2_SIZE error_offset = 0; + + regexp = pcre2_compile((PCRE2_SPTR)Cmd_Argv(1), PCRE2_ZERO_TERMINATED, PCRE2_CASELESS, &error, &error_offset, NULL); + if (!regexp) { + PCRE2_UCHAR error_str[256]; + pcre2_get_error_message(error, error_str, sizeof(error_str)); + Con_Printf("Error in regular expression: %s\n", error_str); return; } } @@ -473,19 +473,20 @@ void Draw_ListFonts_f(void) continue; } if (regexp) { - int offsets[3]; // pcre manual: must be multiple of 3 - - if (pcre_exec(regexp, NULL, dir.files[i].name, strlen(dir.files[i].name), 0, 0, offsets, sizeof(offsets) / sizeof(offsets[0])) <= 0) { + match_data = pcre2_match_data_create_from_pattern(regexp, NULL); + if (pcre2_match(regexp, (PCRE2_SPTR)dir.files[i].name, strlen(dir.files[i].name), 0, 0, match_data, NULL) <= 0) { + pcre2_match_data_free(match_data); continue; } + pcre2_match_data_free(match_data); } - + Con_Printf(" %s\n", dir.files[i].name); printed++; } if (regexp) { - pcre_free(regexp); + pcre2_code_free(regexp); } Con_Printf("Found %d/%d files in %s\n", printed, dir.numfiles, path); } diff --git a/src/parser.c b/src/parser.c index 0ec7da3be..3f2978fcf 100644 --- a/src/parser.c +++ b/src/parser.c @@ -34,7 +34,7 @@ along with this program. If not, see . #include "quakedef.h" #include "q_shared.h" #include "utils.h" -#include "pcre.h" +#include "pcre2.h" #include "parser.h" #undef Q_malloc @@ -765,22 +765,25 @@ LOCAL expr_val operator_reeq(EParser p, const expr_val e1, const expr_val e2) expr_val mask = ToString(p, e2); // this makes sense for "111 =~ 1.1", however we are doing str->double->str conversion // and it can happen that the result string won't be the same as the source - pcre* regexp; - const char *error; - int error_offset; - int rc; - int offsets[99]; + pcre2_code *regexp; + int error; + PCRE2_SIZE error_offset; + pcre2_match_data *match_data = NULL; + PCRE2_SIZE *offsets; + int rc; r.type = ET_BOOL; - regexp = pcre_compile (mask.s_val, 0, &error, &error_offset, NULL); + regexp = pcre2_compile ((PCRE2_SPTR)mask.s_val, PCRE2_ZERO_TERMINATED, 0, &error, &error_offset, NULL); if (!regexp) { SetError(p, ERR_REGEXP); return Get_Expr_Dummy(); } - rc = pcre_exec (regexp, NULL, strr.s_val, strlen(strr.s_val), - 0, 0, offsets, 99); + match_data = pcre2_match_data_create_from_pattern(regexp, NULL); + rc = pcre2_match (regexp, (PCRE2_SPTR)strr.s_val, strlen(strr.s_val), + 0, 0, match_data, NULL); if (rc >= 0) { + offsets = pcre2_get_ovector_pointer(match_data); if (p->re_patfnc) p->re_patfnc(strr.s_val, offsets, rc > 99 ? 99 : rc); r.b_val = BOOL_TRUE; @@ -790,7 +793,8 @@ LOCAL expr_val operator_reeq(EParser p, const expr_val e1, const expr_val e2) Q_free(e1.s_val); Q_free(e2.s_val); - pcre_free (regexp); + pcre2_match_data_free (match_data); + pcre2_code_free (regexp); return r; } diff --git a/src/parser.h b/src/parser.h index d1899cdcf..107103700 100644 --- a/src/parser.h +++ b/src/parser.h @@ -73,7 +73,7 @@ typedef expr_val (* variable_val_fnc) (const char* varname); /// \param[in] str source string /// \param[in] offsets array of offset pairs (start1,end1,start2,end2,...) /// \param[in] matches number of captured groups -typedef void (* subpatterns_report_fnc) (const char* str, int* offsets, int matches); +typedef void (* subpatterns_report_fnc) (const char* str, size_t* offsets, int matches); /// expression parser's extra options typedef struct { diff --git a/src/sv_demo_misc.c b/src/sv_demo_misc.c index 25aef33f8..878e6ead8 100644 --- a/src/sv_demo_misc.c +++ b/src/sv_demo_misc.c @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef CLIENTONLY #include "qwsvdef.h" #ifndef SERVERONLY -#include "pcre.h" +#include "pcre2.h" #endif #define MAX_DEMOINFO_SIZE (1024 * 200) @@ -341,9 +341,10 @@ void SV_DemoList (qbool use_regex) int i, j, n; int files[MAX_DIRFILES + 1]; - int r; - pcre *preg; - const char *errbuf; + PCRE2_SIZE error_offset; + pcre2_code *preg; + pcre2_match_data *match_data = NULL; + int error; memset(files, 0, sizeof(files)); @@ -361,26 +362,31 @@ void SV_DemoList (qbool use_regex) { if (use_regex) { - if (!(preg = pcre_compile(Q_normalizetext(Cmd_Argv(j)), PCRE_CASELESS, &errbuf, &r, NULL))) + if (!(preg = pcre2_compile((PCRE2_SPTR)Q_normalizetext(Cmd_Argv(j)), PCRE2_ZERO_TERMINATED, PCRE2_CASELESS, &error, &error_offset, NULL))) { - Con_Printf("Sys_listdir: pcre_compile(%s) error: %s at offset %d\n", - Cmd_Argv(j), errbuf, r); - pcre_free(preg); + PCRE2_UCHAR error_str[256]; + pcre2_get_error_message(error, error_str, sizeof(error_str)); + Con_Printf("Sys_listdir: pcre2_compile(%s) error: %s at offset %d\n", + Cmd_Argv(j), error_str, error_offset); + pcre2_code_free(preg); break; } - switch (r = pcre_exec(preg, NULL, list->name, - strlen(list->name), 0, 0, NULL, 0)) + match_data = pcre2_match_data_create_from_pattern(preg, NULL); + switch (error = pcre2_match(preg, (PCRE2_SPTR)list->name, + strlen(list->name), 0, 0, match_data, NULL)) { case 0: - pcre_free(preg); + pcre2_match_data_free(match_data); + pcre2_code_free(preg); continue; - case PCRE_ERROR_NOMATCH: + case PCRE2_ERROR_NOMATCH: break; default: - Con_Printf("Sys_listdir: pcre_exec(%s, %s) error code: %d\n", - Cmd_Argv(j), list->name, r); + Con_Printf("Sys_listdir: pcre2_match(%s, %s) error code: %d\n", + Cmd_Argv(j), list->name, error); } - pcre_free(preg); + pcre2_match_data_free(match_data); + pcre2_code_free(preg); break; } else @@ -502,9 +508,10 @@ char *SV_MVDName2Txt (const char *name) char s[MAX_OSPATH]; int len; - int r, ovector[OVECCOUNT]; - pcre *preg; - const char *errbuf; + PCRE2_SIZE error_offset; + pcre2_code *preg; + int error; + pcre2_match_data *match_data = NULL; if (!name) return NULL; @@ -515,29 +522,37 @@ char *SV_MVDName2Txt (const char *name) strlcpy(s, name, MAX_OSPATH); len = strlen(s); - if (!(preg = pcre_compile(sv_demoRegexp.string, PCRE_CASELESS, &errbuf, &r, NULL))) + if (!(preg = pcre2_compile((PCRE2_SPTR)sv_demoRegexp.string, PCRE2_ZERO_TERMINATED, PCRE2_CASELESS, &error, &error_offset, NULL))) { - Con_Printf("SV_MVDName2Txt: pcre_compile(%s) error: %s at offset %d\n", - sv_demoRegexp.string, errbuf, r); - pcre_free(preg); + PCRE2_UCHAR error_str[256]; + pcre2_get_error_message(error, error_str, sizeof(error_str)); + Con_Printf("SV_MVDName2Txt: pcre2_compile(%s) error: %s at offset %d\n", + sv_demoRegexp.string, error_str, error_offset); + pcre2_code_free(preg); return NULL; } - r = pcre_exec(preg, NULL, s, len, 0, 0, ovector, OVECCOUNT); - pcre_free(preg); - if (r < 0) + match_data = pcre2_match_data_create_from_pattern(preg, NULL); + error = pcre2_match(preg, (PCRE2_SPTR)s, len, 0, 0, match_data, NULL); + + if (error < 0) { - switch (r) + pcre2_match_data_free(match_data); + pcre2_code_free(preg); + + switch (error) { - case PCRE_ERROR_NOMATCH: + case PCRE2_ERROR_NOMATCH: return NULL; default: - Con_Printf("SV_MVDName2Txt: pcre_exec(%s, %s) error code: %d\n", - sv_demoRegexp.string, s, r); + Con_Printf("SV_MVDName2Txt: pcre2_match(%s, %s) error code: %d\n", + sv_demoRegexp.string, s, error); return NULL; } } else { + PCRE2_SIZE *ovector = pcre2_get_ovector_pointer(match_data); + if (ovector[0] + 5 > MAX_OSPATH) len = MAX_OSPATH - 5; else @@ -549,6 +564,9 @@ char *SV_MVDName2Txt (const char *name) s[len++] = 't'; s[len] = '\0'; + pcre2_match_data_free(match_data); + pcre2_code_free(preg); + //Con_Printf("%d) %s, %s\n", r, name, s); return va("%s", s); } diff --git a/src/sv_mod_frags.c b/src/sv_mod_frags.c index 55582661d..cb07c3dd8 100644 --- a/src/sv_mod_frags.c +++ b/src/sv_mod_frags.c @@ -30,7 +30,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef CLIENTONLY #include "qwsvdef.h" #ifndef SERVERONLY -#include "pcre.h" +#include "pcre2.h" #endif #include "sv_mod_frags.h" @@ -113,26 +113,33 @@ void sv_mod_msg_file_OnChange(cvar_t *cvar, char *value, qbool *cancel) const char **qwmsg_pcre_check(const char *str, const char *qwm_str, int str_len) { - pcre *reg; - int *ovector[32]; - const char *errbuf; - int erroffset = 0; + pcre2_code *reg; + int error; + PCRE2_SIZE error_offset = 0; const char **buf = NULL; int stringcount; + pcre2_match_data *match_data = NULL; - if (!(reg = pcre_compile(qwm_str, 0, &errbuf, &erroffset, 0))) + if (!(reg = pcre2_compile((PCRE2_SPTR)qwm_str, PCRE2_ZERO_TERMINATED, 0, &error, &error_offset, NULL))) { - Sys_Printf("WARNING: qwmsg_pcre_check: pcre_compile(%s) error %s\n", qwm_str, errbuf); + PCRE2_UCHAR error_str[256]; + pcre2_get_error_message(error, error_str, sizeof(error_str)); + Sys_Printf("WARNING: qwmsg_pcre_check: pcre2_compile(%s) error %s\n", qwm_str, error_str); return NULL; } - stringcount = pcre_exec(reg, NULL, str, str_len, 0, 0, (int *)&ovector[0], 32); - pcre_free(reg); + match_data = pcre2_match_data_create_from_pattern(reg, NULL); + stringcount = pcre2_match(reg, (PCRE2_SPTR)str, str_len, 0, 0, match_data, NULL); + if (stringcount <= 0) { + pcre2_match_data_free (match_data); + pcre2_code_free(reg); return NULL; } - pcre_get_substring_list(str, (int *)&ovector[0], stringcount, &buf); + pcre2_substring_list_get(match_data, (PCRE2_UCHAR8***)&buf, NULL); + pcre2_match_data_free (match_data); + pcre2_code_free(reg); return buf; } @@ -171,7 +178,7 @@ char *parse_mod_string(char *str) break; default: ret = NULL; } - pcre_free_substring_list(buf); + pcre2_substring_list_free((const PCRE2_UCHAR8**)buf); break; } } diff --git a/src/sv_sys_win.c b/src/sv_sys_win.c index 97486957e..838f5aa54 100644 --- a/src/sv_sys_win.c +++ b/src/sv_sys_win.c @@ -170,9 +170,10 @@ dir_t Sys_listdir (const char *path, const char *ext, int sort_type) char pathname[MAX_DEMO_NAME]; qbool all; - int r; - pcre *preg; - const char *errbuf; + PCRE2_SIZE error_offset; + pcre2_code *preg; + pcre2_match_data *match_data = NULL; + int error; memset(list, 0, sizeof(list)); memset(&dir, 0, sizeof(dir)); @@ -180,11 +181,13 @@ dir_t Sys_listdir (const char *path, const char *ext, int sort_type) dir.files = list; all = !strncmp(ext, ".*", 3); if (!all) - if (!(preg = pcre_compile(ext, PCRE_CASELESS, &errbuf, &r, NULL))) + if (!(preg = pcre2_compile((PCRE2_SPTR)ext, PCRE2_ZERO_TERMINATED, PCRE2_CASELESS, &error, &error_offset, NULL))) { - Con_Printf("Sys_listdir: pcre_compile(%s) error: %s at offset %d\n", - ext, errbuf, r); - Q_free(preg); + PCRE2_UCHAR error_str[256]; + pcre2_get_error_message(error, error_str, sizeof(error_str)); + Con_Printf("Sys_listdir: pcre2_compile(%s) error: %s at offset %d\n", + ext, error_str, error_offset); + pcre2_code_free(preg); return dir; } @@ -192,7 +195,7 @@ dir_t Sys_listdir (const char *path, const char *ext, int sort_type) if ((h = FindFirstFile (pathname , &fd)) == INVALID_HANDLE_VALUE) { if (!all) - Q_free(preg); + pcre2_code_free(preg); return dir; } @@ -202,16 +205,23 @@ dir_t Sys_listdir (const char *path, const char *ext, int sort_type) continue; if (!all) { - switch (r = pcre_exec(preg, NULL, fd.cFileName, - strlen(fd.cFileName), 0, 0, NULL, 0)) + match_data = pcre2_match_data_create_from_pattern(preg, NULL); + switch (error = pcre2_match(preg, (PCRE2_SPTR)fd.cFileName, + strlen(fd.cFileName), 0, 0, match_data, NULL)) { - case 0: break; - case PCRE_ERROR_NOMATCH: continue; + case 0: + pcre2_match_data_free(match_data); + break; + case PCRE2_ERROR_NOMATCH: + pcre2_match_data_free(match_data); + continue; default: - Con_Printf("Sys_listdir: pcre_exec(%s, %s) error code: %d\n", - ext, fd.cFileName, r); - if (!all) - Q_free(preg); + Con_Printf("Sys_listdir: pcre2_match(%s, %s) error code: %d\n", + ext, fd.cFileName, error); + if (!all) { + pcre2_match_data_free(match_data); + pcre2_code_free(preg); + } return dir; } } @@ -239,7 +249,7 @@ dir_t Sys_listdir (const char *path, const char *ext, int sort_type) FindClose (h); if (!all) - Q_free(preg); + pcre2_code_free(preg); switch (sort_type) { diff --git a/src/sys_posix.c b/src/sys_posix.c index 6fb72e7a0..d34fb3391 100644 --- a/src/sys_posix.c +++ b/src/sys_posix.c @@ -47,7 +47,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "server.h" -#include "pcre.h" +#include // BSD only defines FNDELAY: @@ -179,9 +179,10 @@ dir_t Sys_listdir (const char *path, const char *ext, int sort_type) struct dirent *oneentry; qbool all; - int r; - pcre *preg = NULL; - const char *errbuf; + PCRE2_SIZE error_offset; + pcre2_code *preg = NULL; + pcre2_match_data *match_data = NULL; + int error; memset(list, 0, sizeof(list)); memset(&dir, 0, sizeof(dir)); @@ -189,18 +190,20 @@ dir_t Sys_listdir (const char *path, const char *ext, int sort_type) dir.files = list; all = !strncmp(ext, ".*", 3); if (!all) - if (!(preg = pcre_compile(ext, PCRE_CASELESS, &errbuf, &r, NULL))) + if (!(preg = pcre2_compile((PCRE2_SPTR)ext, PCRE2_ZERO_TERMINATED, PCRE2_CASELESS, &error, &error_offset, NULL))) { - Con_Printf("Sys_listdir: pcre_compile(%s) error: %s at offset %d\n", - ext, errbuf, r); - pcre_free(preg); + PCRE2_UCHAR error_str[256]; + pcre2_get_error_message(error, error_str, sizeof(error_str)); + Con_Printf("Sys_listdir: pcre2_compile(%s) error: %s at offset %d\n", + ext, error_str, error_offset); + pcre2_code_free(preg); return dir; } if (!(d = opendir(path))) { if (!all) { - pcre_free(preg); + pcre2_code_free(preg); } return dir; } @@ -210,15 +213,21 @@ dir_t Sys_listdir (const char *path, const char *ext, int sort_type) continue; if (!all) { - switch (r = pcre_exec(preg, NULL, oneentry->d_name, - strlen(oneentry->d_name), 0, 0, NULL, 0)) + match_data = pcre2_match_data_create_from_pattern(preg, NULL); + switch (error = pcre2_match(preg, (PCRE2_SPTR)oneentry->d_name, + strlen(oneentry->d_name), 0, 0, match_data, NULL)) { - case 0: break; - case PCRE_ERROR_NOMATCH: continue; + case 0: + pcre2_match_data_free(match_data); + break; + case PCRE2_ERROR_NOMATCH: + pcre2_match_data_free(match_data); + continue; default: - Con_Printf("Sys_listdir: pcre_exec(%s, %s) error code: %d\n", - ext, oneentry->d_name, r); - pcre_free(preg); + Con_Printf("Sys_listdir: pcre2_match(%s, %s) error code: %d\n", + ext, oneentry->d_name, error); + pcre2_match_data_free(match_data); + pcre2_code_free(preg); return dir; } } @@ -244,7 +253,7 @@ dir_t Sys_listdir (const char *path, const char *ext, int sort_type) } closedir(d); if (!all) { - pcre_free(preg); + pcre2_code_free(preg); } switch (sort_type) diff --git a/src/sys_win.c b/src/sys_win.c index 1e49a0323..41924369a 100644 --- a/src/sys_win.c +++ b/src/sys_win.c @@ -30,7 +30,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include "keys.h" #include "server.h" -#include "pcre.h" +#include "pcre2.h" #include // "Starting with the Release 302 drivers, application developers can direct the @@ -342,9 +342,10 @@ dir_t Sys_listdir (const char *path, const char *ext, int sort_type) char pathname[MAX_DEMO_NAME]; qbool all; - int r; - pcre *preg = NULL; - const char *errbuf; + PCRE2_SIZE error_offset; + pcre2_code *preg = NULL; + pcre2_match_data *match_data = NULL; + int error; memset(list, 0, sizeof(list)); memset(&dir, 0, sizeof(dir)); @@ -352,10 +353,9 @@ dir_t Sys_listdir (const char *path, const char *ext, int sort_type) dir.files = list; all = !strncmp(ext, ".*", 3); if (!all) { - if (!(preg = pcre_compile(ext, PCRE_CASELESS, &errbuf, &r, NULL))) { - Con_Printf("Sys_listdir: pcre_compile(%s) error: %s at offset %d\n", - ext, errbuf, r); - pcre_free(preg); + if (!(preg = pcre2_compile((PCRE2_SPTR)ext, PCRE2_ZERO_TERMINATED, PCRE2_CASELESS, &error, &error_offset, NULL))) { + Con_Printf("Sys_listdir: pcre2_compile(%s) error: %d at offset %d\n", + ext, error, error_offset); return dir; } } @@ -364,7 +364,7 @@ dir_t Sys_listdir (const char *path, const char *ext, int sort_type) if ((h = FindFirstFile (pathname , &fd)) == INVALID_HANDLE_VALUE) { if (!all) { - pcre_free(preg); + pcre2_code_free(preg); } return dir; } @@ -375,16 +375,22 @@ dir_t Sys_listdir (const char *path, const char *ext, int sort_type) continue; if (!all) { - switch (r = pcre_exec(preg, NULL, fd.cFileName, - strlen(fd.cFileName), 0, 0, NULL, 0)) + match_data = pcre2_match_data_create_from_pattern(re, NULL); + switch (error = pcre2_match(preg, (PCRE2_SPTR)fd.cFileName, + strlen(fd.cFileName), 0, 0, match_data, NULL)) { - case 0: break; - case PCRE_ERROR_NOMATCH: continue; + case 0: + pcre2_match_data_free(match_data); + break; + case PCRE2_ERROR_NOMATCH: + pcre2_match_data_free(match_data); + continue; default: - Con_Printf("Sys_listdir: pcre_exec(%s, %s) error code: %d\n", - ext, fd.cFileName, r); + Con_Printf("Sys_listdir: pcre2_match(%s, %s) error code: %d\n", + ext, fd.cFileName, error); + pcre2_match_data_free(match_data); if (!all) { - pcre_free(preg); + pcre2_code_free(preg); } return dir; } @@ -411,7 +417,7 @@ dir_t Sys_listdir (const char *path, const char *ext, int sort_type) FindClose (h); if (!all) { - pcre_free(preg); + pcre2_code_free(preg); } switch (sort_type) diff --git a/src/teamplay.h b/src/teamplay.h index 45eae8ee5..c488e042a 100644 --- a/src/teamplay.h +++ b/src/teamplay.h @@ -24,7 +24,7 @@ Boston, MA 02111-1307, USA */ -#include +#include extern cvar_t cl_parsesay; extern cvar_t cl_nofake; diff --git a/src/tp_triggers.c b/src/tp_triggers.c index 2722e4518..90cf1bd41 100644 --- a/src/tp_triggers.c +++ b/src/tp_triggers.c @@ -412,10 +412,7 @@ pcre_trigger_t *CL_FindReTrigger (char *name) static void DeleteReTrigger (pcre_trigger_t *t) { if (t->regexp) - (pcre_free)(t->regexp); - - if (t->regexp_extra) - (pcre_free)(t->regexp_extra); + (pcre2_code_free)(t->regexp); if (t->regexpstr) Q_free(t->regexpstr); @@ -441,10 +438,9 @@ static void CL_RE_Trigger_f (void) char *name; char *regexpstr; pcre_trigger_t *trig; - pcre *re; - pcre_extra *re_extra; - const char *error; - int error_offset; + pcre2_code *re; + int error; + PCRE2_SIZE error_offset; qbool newtrigger=false; qbool re_search = false; @@ -514,24 +510,16 @@ static void CL_RE_Trigger_f (void) trig->flags = RE_PRINT_ALL | RE_ENABLED; // catch all printed messages by default } - error = NULL; - if ((re = pcre_compile(regexpstr, 0, &error, &error_offset, NULL))) { - error = NULL; - re_extra = pcre_study(re, 0, &error); - if (error) { - Com_Printf ("Regexp study error: %s\n", &error); - } else { - if (!newtrigger) { - (pcre_free)(trig->regexp); - if (trig->regexp_extra) - (pcre_free)(trig->regexp_extra); - Q_free(trig->regexpstr); - } - trig->regexpstr = Q_strdup(regexpstr); - trig->regexp = re; - trig->regexp_extra = re_extra; - return; + error = 0; + if ((re = pcre2_compile((PCRE2_SPTR)regexpstr, PCRE2_ZERO_TERMINATED, 0, &error, &error_offset, NULL))) { + error = 0; + if (!newtrigger) { + (pcre2_code_free)(trig->regexp); + Q_free(trig->regexpstr); } + trig->regexpstr = Q_strdup(regexpstr); + trig->regexp = re; + return; } else { Com_Printf ("Invalid regexp: %s\n", error); } @@ -685,7 +673,7 @@ void CL_RE_Trigger_ResetLasttime (void) trig->lasttime = 0.0; } -void Re_Trigger_Copy_Subpatterns (const char *s, int* offsets, int num, cvar_t *re_sub) +void Re_Trigger_Copy_Subpatterns (const char *s, size_t* offsets, int num, cvar_t *re_sub) { int i; char *tmp; @@ -708,8 +696,7 @@ static void CL_RE_Trigger_Match_f (void) pcre_trigger_t *rt; char *string; int result; - int offsets[99]; - + c = Cmd_Argc(); if (c != 3) { @@ -722,13 +709,16 @@ static void CL_RE_Trigger_Match_f (void) for (rt = re_triggers; rt; rt = rt->next) if (!strcmp(rt->name, tr_name)) { - result = pcre_exec (rt->regexp, rt->regexp_extra, s, strlen(s), 0, 0, offsets, 99); + pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(rt->regexp, NULL); + result = pcre2_match (rt->regexp, (PCRE2_SPTR)s, strlen(s), 0, 0, match_data, NULL); if (result >= 0) { rt->lasttime = cls.realtime; rt->counter++; + + PCRE2_SIZE *offsets = pcre2_get_ovector_pointer(match_data); Re_Trigger_Copy_Subpatterns (s, offsets, min (result,10), re_sub); - + if (!(rt->flags & RE_NOACTION)) { string = Cmd_AliasString (rt->name); if (string) { @@ -740,6 +730,7 @@ static void CL_RE_Trigger_Match_f (void) } } } + pcre2_match_data_free (match_data); return; } Com_Printf ("re_trigger \"%s\" not found\n", tr_name); @@ -753,19 +744,23 @@ qbool CL_SearchForReTriggers (const char *s, unsigned trigger_type) cmd_alias_t *trig_alias; qbool removestr = false; int result; - int offsets[99]; int len = strlen(s); + pcre2_match_data *match_data; + PCRE2_SIZE *offsets; // internal triggers - always enabled if (trigger_type < RE_PRINT_ECHO) { allow_re_triggers = true; for (irt = internal_triggers; irt; irt = irt->next) { if (irt->flags & trigger_type) { - result = pcre_exec (irt->regexp, irt->regexp_extra, s, len, 0, 0, offsets, 99); + match_data = pcre2_match_data_create_from_pattern(irt->regexp, NULL); + result = pcre2_match (irt->regexp, (PCRE2_SPTR)s, len, 0, 0, match_data, NULL); if (result >= 0) { + offsets = pcre2_get_ovector_pointer(match_data); Re_Trigger_Copy_Subpatterns (s, offsets, min(result,10), re_subi); irt->func (s); } + pcre2_match_data_free (match_data); } } if (!allow_re_triggers) @@ -796,10 +791,12 @@ qbool CL_SearchForReTriggers (const char *s, unsigned trigger_type) // probably it dont solve re_trigger timers problem // you always trigger on statusbar(TF) or wp_stats (KTPro/KTX) messages and get 0.5~1.5 accuracy for your timer { - result = pcre_exec (rt->regexp, rt->regexp_extra, s, len, 0, 0, offsets, 99); + pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(rt->regexp, NULL); + result = pcre2_match (rt->regexp, (PCRE2_SPTR)s, len, 0, 0, match_data, NULL); if (result >= 0) { rt->lasttime = cls.realtime; rt->counter++; + offsets = pcre2_get_ovector_pointer(match_data); Re_Trigger_Copy_Subpatterns (s, offsets, min(result,10), re_sub); if (!(rt->flags & RE_NOACTION)) { @@ -821,6 +818,7 @@ qbool CL_SearchForReTriggers (const char *s, unsigned trigger_type) if (rt->flags & RE_FINAL) break; } + pcre2_match_data_free (match_data); } if (removestr) @@ -833,15 +831,14 @@ qbool CL_SearchForReTriggers (const char *s, unsigned trigger_type) static void AddInternalTrigger (char* regexpstr, unsigned mask, internal_trigger_func func) { pcre_internal_trigger_t *trig; - const char *error; - int error_offset; + int error; + PCRE2_SIZE error_offset; trig = (pcre_internal_trigger_t *) Q_malloc(sizeof(pcre_internal_trigger_t)); trig->next = internal_triggers; internal_triggers = trig; - trig->regexp = pcre_compile (regexpstr, 0, &error, &error_offset, NULL); - trig->regexp_extra = pcre_study (trig->regexp, 0, &error); + trig->regexp = pcre2_compile ((PCRE2_SPTR)regexpstr, PCRE2_ZERO_TERMINATED, 0, &error, &error_offset, NULL); trig->func = func; trig->flags = mask; } @@ -916,11 +913,7 @@ void TP_ShutdownTriggers(void) for (trigger = internal_triggers; trigger; trigger = next_trigger) { next_trigger = trigger->next; if (trigger->regexp) { - (pcre_free)(trigger->regexp); - } - - if (trigger->regexp_extra) { - (pcre_free)(trigger->regexp_extra); + (pcre2_code_free)(trigger->regexp); } Q_free(trigger); diff --git a/src/tp_triggers.h b/src/tp_triggers.h index 1c0fecd0e..953e61e65 100644 --- a/src/tp_triggers.h +++ b/src/tp_triggers.h @@ -35,8 +35,7 @@ typedef struct pcre_trigger_s { char *name; char *regexpstr; struct pcre_trigger_s* next; - pcre* regexp; - pcre_extra* regexp_extra; + pcre2_code* regexp; unsigned flags; float min_interval; double lasttime; @@ -47,8 +46,7 @@ typedef void internal_trigger_func (const char *s); typedef struct pcre_internal_trigger_s { struct pcre_internal_trigger_s *next; - pcre *regexp; - pcre_extra *regexp_extra; + pcre2_code *regexp; internal_trigger_func *func; unsigned flags; } pcre_internal_trigger_t; diff --git a/src/utils.c b/src/utils.c index 3deb8f401..09eb050af 100644 --- a/src/utils.c +++ b/src/utils.c @@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "quakedef.h" -#include "pcre.h" +#include #include "hud.h" #include "utils.h" #include "qtv.h" @@ -1257,82 +1257,80 @@ int Utils_TF_TeamToColor(char *team) { qbool Utils_RegExpMatch(char *regexp, char *matchstring) { - int offsets[HUD_REGEXP_OFFSET_COUNT]; - pcre *re = NULL; - const char *error; - int erroffset = 0; + pcre2_code *re = NULL; + int error; + PCRE2_SIZE error_offset = 0; int match = 0; + pcre2_match_data *match_data = NULL; - re = pcre_compile( - regexp, // The pattern. - PCRE_CASELESS, // Case insensitive. + re = pcre2_compile( + (PCRE2_SPTR)regexp, // The pattern. + PCRE2_ZERO_TERMINATED, + PCRE2_CASELESS, // Case insensitive. &error, // Error message. - &erroffset, // Error offset. + &error_offset, // Error offset. NULL); // use default character tables. // Check for an error compiling the regexp. - if (error) { - if (re) { - pcre_free(re); - } - + if (!re) return false; - } // Check if we have a match. - if (re && (match = pcre_exec(re, NULL, matchstring, strlen(matchstring), 0, 0, offsets, HUD_REGEXP_OFFSET_COUNT)) >= 0) { - pcre_free(re); + match_data = pcre2_match_data_create_from_pattern(re, NULL); + if (re && (match = pcre2_match(re, (PCRE2_SPTR)matchstring, strlen(matchstring), 0, 0, match_data, NULL)) >= 0) { + pcre2_match_data_free(match_data); + pcre2_code_free(re); return true; } // Make sure we clean up. if (re) { - pcre_free(re); + pcre2_match_data_free(match_data); + pcre2_code_free(re); } return false; } qbool Utils_RegExpGetGroup(char *regexp, char *matchstring, const char **resultstring, int *resultlength, int group) { - int offsets[HUD_REGEXP_OFFSET_COUNT]; - pcre *re = NULL; - const char *error; - int erroffset = 0; + pcre2_code *re = NULL; + int error; + PCRE2_SIZE error_offset = 0; int match = 0; + pcre2_match_data *match_data; - re = pcre_compile( - regexp, // The pattern. - PCRE_CASELESS, // Case insensitive. + re = pcre2_compile( + (PCRE2_SPTR)regexp, // The pattern. + PCRE2_ZERO_TERMINATED, + PCRE2_CASELESS, // Case insensitive. &error, // Error message. - &erroffset, // Error offset. + &error_offset, // Error offset. NULL); // use default character tables. - if (error) { - if (re) { - pcre_free(re); - } - + if (!re) return false; - } - if (re && (match = pcre_exec(re, NULL, matchstring, strlen(matchstring), 0, 0, offsets, HUD_REGEXP_OFFSET_COUNT)) >= 0) { + match_data = pcre2_match_data_create_from_pattern(re, NULL); + if (re && (match = pcre2_match(re, (PCRE2_SPTR)matchstring, strlen(matchstring), 0, 0, match_data, NULL)) >= 0) { int substring_length = 0; - substring_length = pcre_get_substring (matchstring, offsets, match, group, resultstring); + error = pcre2_substring_get_bynumber (match_data, group, (PCRE2_UCHAR8**)resultstring, (size_t*)&substring_length); if (resultlength != NULL) { (*resultlength) = substring_length; } + pcre2_match_data_free (match_data); if (re) { - pcre_free(re); + pcre2_code_free(re); } - return (substring_length != PCRE_ERROR_NOSUBSTRING && substring_length != PCRE_ERROR_NOMEMORY); + return (error != PCRE2_ERROR_NOSUBSTRING && error != PCRE2_ERROR_NOMEMORY); } + pcre2_match_data_free (match_data); if (re) { - pcre_free(re); + pcre2_code_free(re); } return false; @@ -1342,8 +1340,7 @@ qbool Utils_RegExpGetGroup(char *regexp, char *matchstring, const char **results // QW262 --> // regexp match support for group operations in scripts int wildcard_level = 0; -pcre *wildcard_re[4]; -pcre_extra *wildcard_re_extra[4]; +pcre2_code *wildcard_re[4]; qbool IsRegexp(const char *str) { @@ -1362,25 +1359,21 @@ qbool ReSearchInit(const char* wildcard) qbool ReSearchInitEx(const char *wildcard, qbool case_sensitive) { - const char *error; - int error_offset; + int error; + PCRE2_SIZE error_offset; if (wildcard_level == 4) { Com_Printf("Error: Regexp commands nested too deep\n"); return false; } - wildcard_re[wildcard_level] = pcre_compile(wildcard, (case_sensitive ? 0 : PCRE_CASELESS), &error, &error_offset, NULL); - if (error) { - Com_Printf ("Invalid regexp: %s\n", error); + wildcard_re[wildcard_level] = pcre2_compile((PCRE2_SPTR)wildcard, PCRE2_ZERO_TERMINATED, (case_sensitive ? 0 : PCRE2_CASELESS), &error, &error_offset, NULL); + if (!wildcard_re[wildcard_level]) { + PCRE2_UCHAR error_str[256]; + pcre2_get_error_message(error, error_str, sizeof(error_str)); + Com_Printf ("Invalid regexp: %s %d\n", error_str, error_offset); return false; } - error = NULL; - wildcard_re_extra[wildcard_level] = pcre_study(wildcard_re[wildcard_level], 0, &error); - if (error) { - Com_Printf ("Regexp study error: %s\n", &error); - return false; - } wildcard_level++; return true; @@ -1389,10 +1382,11 @@ qbool ReSearchInitEx(const char *wildcard, qbool case_sensitive) qbool ReSearchMatch (const char *str) { int result; - int offsets[99]; - - result = pcre_exec(wildcard_re[wildcard_level-1], - wildcard_re_extra[wildcard_level-1], str, strlen(str), 0, 0, offsets, 99); + pcre2_match_data *match_data = NULL; + match_data = pcre2_match_data_create_from_pattern(wildcard_re[wildcard_level-1], NULL); + result = pcre2_match(wildcard_re[wildcard_level-1], + (PCRE2_SPTR)str, strlen(str), 0, 0, match_data, NULL); + pcre2_match_data_free(match_data); return (result>0) ? true : false; } @@ -1400,10 +1394,7 @@ void ReSearchDone (void) { wildcard_level--; if (wildcard_re[wildcard_level]) { - (pcre_free)(wildcard_re[wildcard_level]); - } - if (wildcard_re_extra[wildcard_level]) { - (pcre_free)(wildcard_re_extra[wildcard_level]); + (pcre2_code_free)(wildcard_re[wildcard_level]); } } // <-- QW262 @@ -1527,7 +1518,7 @@ qbool Util_GetNextWordwrapString(const char *input, char *target, int start_inde void Utils_RegExpFreeSubstring(char* substring) { if (substring) { - pcre_free_substring(substring); + pcre2_substring_free((PCRE2_UCHAR8*)substring); } }