1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
|
Description: Port to PCRE2.
Bug-Debian: https://bugs.debian.org/1050187
Author: Yavor Doganov <yavor@gnu.org>
Forwarded: https://github.com/QW-Group/mvdsv/pull/152
Last-Update: 2023-12-14
---
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -104,18 +104,14 @@
######################################################################################################
# Check for PCRE. if found, include it; if not found, use bundled PCRE.
-find_library(PCRE_LIBRARIES pcre)
+find_library(PCRE_LIBRARIES pcre2-8)
if(PCRE_LIBRARIES)
set(PCRE_FOUND 1)
- find_path(PCRE_INCLUDE_DIR pcre.h)
+ find_path(PCRE_INCLUDE_DIR pcre2.h)
endif(PCRE_LIBRARIES)
if(NOT PCRE_FOUND)
- message(STATUS "PCRE library not found. Using bundled PCRE instead.")
- list(APPEND SRC_COMMON
- "${DIR_SRC}/pcre/get.c"
- "${DIR_SRC}/pcre/pcre.c"
- )
+ message(FATAL_ERROR "PCRE library not found.")
else()
message(STATUS "Found PCRE: ${PCRE_LIBRARIES}")
endif()
--- a/src/sv_demo_misc.c
+++ b/src/sv_demo_misc.c
@@ -22,7 +22,8 @@
#ifndef CLIENTONLY
#include "qwsvdef.h"
#ifndef SERVERONLY
-#include "pcre.h"
+#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>
#endif
#define MAX_DEMOINFO_SIZE (1024 * 200)
@@ -342,8 +343,10 @@
int files[MAX_DIRFILES + 1];
int r;
- pcre *preg;
- const char *errbuf;
+ size_t erroffset;
+ pcre2_code *preg;
+ pcre2_match_data *md;
+ PCRE2_UCHAR errbuf[120];
memset(files, 0, sizeof(files));
@@ -361,26 +364,29 @@
{
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, &r, &erroffset, NULL)))
{
- Con_Printf("Sys_listdir: pcre_compile(%s) error: %s at offset %d\n",
- Cmd_Argv(j), errbuf, r);
- pcre_free(preg);
+ pcre2_get_error_message(r, errbuf, sizeof(errbuf));
+ Con_Printf("Sys_listdir: pcre2_compile(%s) error: %s at offset %lu\n",
+ Cmd_Argv(j), errbuf, erroffset);
break;
}
- switch (r = pcre_exec(preg, NULL, list->name,
- strlen(list->name), 0, 0, NULL, 0))
+ md = pcre2_match_data_create_from_pattern(preg, NULL);
+ switch (r = pcre2_match(preg, (PCRE2_SPTR)list->name,
+ strlen(list->name), 0, 0, md, NULL))
{
case 0:
- pcre_free(preg);
+ pcre2_match_data_free(md);
+ 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",
+ Con_Printf("Sys_listdir: pcre2_match(%s, %s) error code: %d\n",
Cmd_Argv(j), list->name, r);
}
- pcre_free(preg);
+ pcre2_match_data_free(md);
+ pcre2_code_free(preg);
break;
}
else
@@ -502,9 +508,11 @@
char s[MAX_OSPATH];
int len;
- int r, ovector[OVECCOUNT];
- pcre *preg;
- const char *errbuf;
+ int r;
+ size_t erroffset, *ovector;
+ pcre2_code *preg;
+ pcre2_match_data *md;
+ PCRE2_UCHAR errbuf[120];
if (!name)
return NULL;
@@ -515,29 +523,33 @@
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, &r, &erroffset, NULL)))
{
- Con_Printf("SV_MVDName2Txt: pcre_compile(%s) error: %s at offset %d\n",
- sv_demoRegexp.string, errbuf, r);
- pcre_free(preg);
+ pcre2_get_error_message(r, errbuf, sizeof(errbuf));
+ Con_Printf("SV_MVDName2Txt: pcre2_compile(%s) error: %s at offset %lu\n",
+ sv_demoRegexp.string, errbuf, erroffset);
return NULL;
}
- r = pcre_exec(preg, NULL, s, len, 0, 0, ovector, OVECCOUNT);
- pcre_free(preg);
+ md = pcre2_match_data_create(OVECCOUNT, NULL);
+ r = pcre2_match(preg, (PCRE2_SPTR)s, len, 0, 0, md, NULL);
+ pcre2_code_free(preg);
if (r < 0)
{
switch (r)
{
- case PCRE_ERROR_NOMATCH:
+ case PCRE2_ERROR_NOMATCH:
+ pcre2_match_data_free(md);
return NULL;
default:
- Con_Printf("SV_MVDName2Txt: pcre_exec(%s, %s) error code: %d\n",
+ Con_Printf("SV_MVDName2Txt: pcre2_match(%s, %s) error code: %d\n",
sv_demoRegexp.string, s, r);
+ pcre2_match_data_free(md);
return NULL;
}
}
else
{
+ ovector = pcre2_get_ovector_pointer(md);
if (ovector[0] + 5 > MAX_OSPATH)
len = MAX_OSPATH - 5;
else
@@ -549,6 +561,7 @@
s[len++] = 't';
s[len] = '\0';
+ pcre2_match_data_free(md);
//Con_Printf("%d) %s, %s\n", r, name, s);
return va("%s", s);
}
--- a/src/sv_mod_frags.c
+++ b/src/sv_mod_frags.c
@@ -30,7 +30,8 @@
#ifndef CLIENTONLY
#include "qwsvdef.h"
#ifndef SERVERONLY
-#include "pcre.h"
+#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>
#endif
#include "sv_mod_frags.h"
@@ -113,26 +114,31 @@
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;
+ pcre2_match_data *md;
+ int errcode;
+ PCRE2_UCHAR errbuf[120];
+ size_t erroffset;
const char **buf = NULL;
int stringcount;
- if (!(reg = pcre_compile(qwm_str, 0, &errbuf, &erroffset, 0)))
+ if (!(reg = pcre2_compile((PCRE2_SPTR)qwm_str, PCRE2_ZERO_TERMINATED, 0, &errcode, &erroffset, NULL)))
{
- Sys_Printf("WARNING: qwmsg_pcre_check: pcre_compile(%s) error %s\n", qwm_str, errbuf);
+ pcre2_get_error_message(errcode, errbuf, sizeof(errbuf));
+ Sys_Printf("WARNING: qwmsg_pcre_check: pcre2_compile(%s) error %s\n", qwm_str, errbuf);
return NULL;
}
- stringcount = pcre_exec(reg, NULL, str, str_len, 0, 0, (int *)&ovector[0], 32);
- pcre_free(reg);
+ md = pcre2_match_data_create(32, NULL);
+ stringcount = pcre2_match(reg, (PCRE2_SPTR)str, str_len, 0, 0, md, NULL);
+ pcre2_code_free(reg);
if (stringcount <= 0) {
+ pcre2_match_data_free(md);
return NULL;
}
- pcre_get_substring_list(str, (int *)&ovector[0], stringcount, &buf);
+ pcre2_substring_list_get(md, (PCRE2_UCHAR ***)&buf, NULL);
+ pcre2_match_data_free(md);
return buf;
}
@@ -171,7 +177,7 @@
break;
default: ret = NULL;
}
- pcre_free_substring_list(buf);
+ pcre2_substring_list_free((PCRE2_UCHAR8 **)buf);
break;
}
}
--- a/src/qwsvdef.h
+++ b/src/qwsvdef.h
@@ -88,7 +88,8 @@
#define PCRE_STATIC
#endif
-#include "pcre/pcre.h"
+#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>
//=============================================================================
--- a/src/sv_sys_unix.c
+++ b/src/sv_sys_unix.c
@@ -121,8 +121,10 @@
qbool all;
int r;
- pcre *preg = NULL;
- const char *errbuf;
+ size_t erroffset;
+ pcre2_code *preg = NULL;
+ pcre2_match_data *md;
+ PCRE2_UCHAR errbuf[120];
memset(list, 0, sizeof(list));
memset(&dir, 0, sizeof(dir));
@@ -130,35 +132,37 @@
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, &r, &erroffset, NULL)))
{
- Con_Printf("Sys_listdir: pcre_compile(%s) error: %s at offset %d\n",
- ext, errbuf, r);
- Q_free(preg);
+ pcre2_get_error_message(r, errbuf, sizeof(errbuf));
+ Con_Printf("Sys_listdir: pcre2_compile(%s) error: %s at offset %lu\n",
+ ext, errbuf, erroffset);
return dir;
}
if (!(d = opendir(path)))
{
if (!all)
- Q_free(preg);
+ pcre2_code_free(preg);
return dir;
}
+ md = pcre2_match_data_create_from_pattern(preg, NULL);
while ((oneentry = readdir(d)))
{
if (!strncmp(oneentry->d_name, ".", 2) || !strncmp(oneentry->d_name, "..", 3))
continue;
if (!all)
{
- switch (r = pcre_exec(preg, NULL, oneentry->d_name,
- strlen(oneentry->d_name), 0, 0, NULL, 0))
+ switch (r = pcre2_match(preg, (PCRE2_SPTR)oneentry->d_name,
+ strlen(oneentry->d_name), 0, 0, md, NULL))
{
case 0: break;
- case PCRE_ERROR_NOMATCH: continue;
+ case PCRE2_ERROR_NOMATCH: continue;
default:
- Con_Printf("Sys_listdir: pcre_exec(%s, %s) error code: %d\n",
+ Con_Printf("Sys_listdir: pcre2_match(%s, %s) error code: %d\n",
ext, oneentry->d_name, r);
- Q_free(preg);
+ pcre2_match_data_free(md);
+ pcre2_code_free(preg);
return dir;
}
}
@@ -184,7 +188,7 @@
}
closedir(d);
if (!all)
- Q_free(preg);
+ pcre2_code_free(preg);
switch (sort_type)
{
@@ -197,6 +201,8 @@
break;
}
+ pcre2_match_data_free(md);
+
return dir;
}
|