File: use-pcre2.patch

package info (click to toggle)
tintin%2B%2B 2.02.20-1
  • links: PTS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 8,720 kB
  • sloc: ansic: 59,028; makefile: 52
file content (481 lines) | stat: -rw-r--r-- 13,248 bytes parent folder | download
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
regular expressions now use libpcre2-dev
--- a/src/configure.in
+++ b/src/configure.in
@@ -69,8 +69,10 @@
 AC_CHECK_HEADERS([arpa/inet.h ctype.h fcntl.h net/errno.h netdb.h netinet/in.h param.h pthread.h socks.h stdlib.h string.h strings.h sys/ioctl.h sys/param.h sys/ptem.h sys/socket.h sys/termio.h sys/time.h time.h unistd.h util.h pty.h stropts.h]) 
 AC_CHECK_HEADERS([zlib.h],,
 	[AC_MSG_ERROR([zlib header file not found, is the development part present])])
-AC_CHECK_HEADERS([pcre.h],,
-	[AC_MSG_ERROR([pcre header file not found, is the development part present])])
+AC_DEFINE([PCRE2_CODE_UNIT_WIDTH],8,[Define pcre2 unit size])
+AC_CHECK_HEADERS([pcre2.h],,
+	[AC_CHECK_HEADERS([pcre.h],,
+		[AC_MSG_ERROR([pcre header file not found, is the development part present])])])
 AC_CHECK_HEADERS([gnutls/gnutls.h],
 	[AC_DEFINE([HAVE_GNUTLS_H],,
 	[Define to 1 if you have <gnutls/gnutls.h>.])],
@@ -104,8 +106,9 @@
 AC_CHECK_LIB(nsl, gethostbyname)
 AC_CHECK_LIB(socket, rresvport)
 AC_CHECK_LIB(util, forkpty)
-AC_CHECK_LIB(pcre, pcre_compile,,
-	[AC_MSG_ERROR([pcre runtime library not working, is it AND the corresponding development (header) file installed])])
+AC_CHECK_LIB(pcre2-8, pcre2_compile_8,,
+ 	[AC_CHECK_LIB(pcre, pcre_compile,,
+ 	 	[AC_MSG_ERROR([pcre runtime library not working, is it AND the corresponding development (header) file installed])])])
 AC_CHECK_LIB(gnutls, gnutls_init)
 AC_CHECK_LIB(m, sqrt)
 
--- a/src/configure
+++ b/src/configure
@@ -3436,7 +3436,19 @@
 
 done
 
-for ac_header in pcre.h
+
+$as_echo "#define PCRE2_CODE_UNIT_WIDTH 8" >>confdefs.h
+
+for ac_header in pcre2.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "pcre2.h" "ac_cv_header_pcre2_h" "$ac_includes_default"
+if test "x$ac_cv_header_pcre2_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_PCRE2_H 1
+_ACEOF
+
+else
+  for ac_header in pcre.h
 do :
   ac_fn_c_check_header_mongrel "$LINENO" "pcre.h" "ac_cv_header_pcre_h" "$ac_includes_default"
 if test "x$ac_cv_header_pcre_h" = xyes; then :
@@ -3450,6 +3462,10 @@
 
 done
 
+fi
+
+done
+
 for ac_header in gnutls/gnutls.h
 do :
   ac_fn_c_check_header_mongrel "$LINENO" "gnutls/gnutls.h" "ac_cv_header_gnutls_gnutls_h" "$ac_includes_default"
@@ -4458,7 +4474,51 @@
 
 fi
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pcre_compile in -lpcre" >&5
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pcre2_compile_8 in -lpcre2-8" >&5
+$as_echo_n "checking for pcre2_compile_8 in -lpcre2-8... " >&6; }
+if ${ac_cv_lib_pcre2_8_pcre2_compile_8+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lpcre2-8  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char pcre2_compile_8 ();
+int
+main ()
+{
+return pcre2_compile_8 ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_pcre2_8_pcre2_compile_8=yes
+else
+  ac_cv_lib_pcre2_8_pcre2_compile_8=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pcre2_8_pcre2_compile_8" >&5
+$as_echo "$ac_cv_lib_pcre2_8_pcre2_compile_8" >&6; }
+if test "x$ac_cv_lib_pcre2_8_pcre2_compile_8" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBPCRE2_8 1
+_ACEOF
+
+  LIBS="-lpcre2-8 $LIBS"
+
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pcre_compile in -lpcre" >&5
 $as_echo_n "checking for pcre_compile in -lpcre... " >&6; }
 if ${ac_cv_lib_pcre_pcre_compile+:} false; then :
   $as_echo_n "(cached) " >&6
@@ -4505,6 +4565,8 @@
   as_fn_error $? "pcre runtime library not working, is it AND the corresponding development (header) file installed" "$LINENO" 5
 fi
 
+fi
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gnutls_init in -lgnutls" >&5
 $as_echo_n "checking for gnutls_init in -lgnutls... " >&6; }
 if ${ac_cv_lib_gnutls_gnutls_init+:} false; then :
--- a/src/tintin.h
+++ b/src/tintin.h
@@ -31,7 +31,6 @@
 #include <zlib.h>
 #include <ctype.h>
 #include <termios.h>
-#include <pcre.h>
 #include <errno.h>
 #include <math.h>
 #include <stdarg.h>
@@ -105,6 +104,12 @@
 	#define SO_PEERCRED 17
 #endif
 
+#ifdef HAVE_PCRE2_H
+#include <pcre2.h>
+#else
+#include <pcre.h>
+#endif
+
 #ifndef __TINTIN_H__
 #define __TINTIN_H__
 
@@ -1053,7 +1058,11 @@
 	unsigned int            shots;
 	union
 	{
+#ifdef HAVE_PCRE2_H
+ 		pcre2_code        * regex;      // act, alias, gag, highlight, substitute
+#else
 		pcre              * regex;      // act, alias, gag, highlight, substitute
+#endif
 		char              * data;       // class
 		struct room_data  * room;       // terrain
 		long long           val64;      // delay, tick, path
@@ -1502,14 +1511,22 @@
 	int                     max;
 	unsigned short          stamp;
 	char                  * arg;
-	pcre                  * name;
 	int                     exit_size;
 	long long               exit_dirs;
 	char                  * exit_list;
+#ifdef HAVE_PCRE2_H
+	pcre2_code            * name;
+	pcre2_code            * desc;
+	pcre2_code            * area;
+	pcre2_code            * note;
+	pcre2_code            * terrain;
+#else
+	pcre                  * name;
 	pcre                  * desc;
 	pcre                  * area;
 	pcre                  * note;
 	pcre                  * terrain;
+#endif
 	long long               flag;
 	long long               galf;
 	char                  * id;
@@ -2916,12 +2933,19 @@
 extern int substitute(struct session *ses, char *string, char *result, int flags);
 extern int match(struct session *ses, char *str, char *exp, int flags);
 extern int find(struct session *ses, char *str, char *exp, int sub, int flag);
-extern int regexp_compare(struct session *ses, pcre *regex, char *str, char *exp, int option, int flag);
 extern int check_one_regexp(struct session *ses, struct listnode *node, char *line, char *original, int option);
 extern int tintin_regexp_check(struct session *ses, char *exp);
+#ifdef HAVE_PCRE2_H
+extern int regexp_compare(struct session *ses, pcre2_code *regex, char *str, char *exp, int option, int flag);
+extern int tintin_regexp(struct session *ses, pcre2_code *pcre, char *str, char *exp, int option, int flag);
+extern pcre2_code *regexp_compile(struct session *ses, char *exp, int option);
+extern pcre2_code *tintin_regexp_compile(struct session *ses, struct listnode *node, char *exp, int option);
+#else
+extern int regexp_compare(struct session *ses, pcre *regex, char *str, char *exp, int option, int flag);
 extern int tintin_regexp(struct session *ses, pcre *pcre, char *str, char *exp, int option, int flag);
 extern pcre *regexp_compile(struct session *ses, char *exp, int option);
 extern pcre *tintin_regexp_compile(struct session *ses, struct listnode *node, char *exp, int option);
+#endif
 extern void  tintin_macro_compile(char *input, char *output);
 
 #endif
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -82,6 +82,9 @@
 /* Define to 1 if you have the <param.h> header file. */
 #undef HAVE_PARAM_H
 
+/* Define to 1 if you have the <pcre2.h> header file. */
+#undef HAVE_PCRE2_H
+
 /* Define to 1 if you have the `popen' function. */
 #undef HAVE_POPEN
 
@@ -229,6 +232,9 @@
 /* Define to the version of this package. */
 #undef PACKAGE_VERSION
 
+/* Define pcre2 unit size */
+#undef PCRE2_CODE_UNIT_WIDTH
+
 /* Define as the return type of signal handlers (`int' or `void'). */
 #undef RETSIGTYPE
 
--- a/src/trigger.c
+++ b/src/trigger.c
@@ -164,7 +164,11 @@
 	{
 		node = root->list[root->update];
 
+#ifdef HAVE_PCRE2_H
+		if (check_one_regexp(ses, node, line, line, PCRE2_ANCHORED))
+#else
 		if (check_one_regexp(ses, node, line, line, PCRE_ANCHORED))
+#endif
 		{
 			i = strlen(node->arg1);
 
--- a/src/mapper.c
+++ b/src/mapper.c
@@ -3725,7 +3725,11 @@
 	{
 		strcat(buf, "$");
 
+#ifdef HAVE_PCRE2_H
+		ses->map->search->name = tintin_regexp_compile(ses, NULL, buf, PCRE2_ANCHORED);
+#else
 		ses->map->search->name = tintin_regexp_compile(ses, NULL, buf, PCRE_ANCHORED);
+#endif
 	}
 	else
 	{
@@ -3809,7 +3813,11 @@
 	{
 		strcat(buf, "$");
 
+#ifdef HAVE_PCRE2_H
+		ses->map->search->desc = tintin_regexp_compile(ses, NULL, buf, PCRE2_ANCHORED|PCRE2_DOLLAR_ENDONLY|PCRE2_DOTALL);
+#else
 		ses->map->search->desc = tintin_regexp_compile(ses, NULL, buf, PCRE_ANCHORED|PCRE_DOLLAR_ENDONLY|PCRE_DOTALL);
+#endif
 	}
 	else
 	{
@@ -3829,7 +3837,11 @@
 	{
 		strcat(buf, "$");
 
+#ifdef HAVE_PCRE2_H
+		ses->map->search->area = tintin_regexp_compile(ses, NULL, buf, PCRE2_ANCHORED);
+#else
 		ses->map->search->area = tintin_regexp_compile(ses, NULL, buf, PCRE_ANCHORED);
+#endif
 	}
 	else
 	{
@@ -3849,7 +3861,11 @@
 	{
 		strcat(buf, "$");
 
+#ifdef HAVE_PCRE2_H
+		ses->map->search->note = tintin_regexp_compile(ses, NULL, buf, PCRE2_ANCHORED);
+#else
 		ses->map->search->note = tintin_regexp_compile(ses, NULL, buf, PCRE_ANCHORED);
+#endif
 	}
 	else
 	{
@@ -3869,7 +3885,11 @@
 	{
 		strcat(buf, "$");
 
+#ifdef HAVE_PCRE2_H
+		ses->map->search->terrain = tintin_regexp_compile(ses, NULL, buf, PCRE2_ANCHORED);
+#else
 		ses->map->search->terrain = tintin_regexp_compile(ses, NULL, buf, PCRE_ANCHORED);
+#endif
 	}
 	else
 	{
--- a/src/data.c
+++ b/src/data.c
@@ -92,7 +92,11 @@
 			switch (type)
 			{
 				case LIST_ALIAS:
+#ifdef HAVE_PCRE2_H
+					node->regex = tintin_regexp_compile(ses, node, node->arg1, PCRE2_ANCHORED);
+#else
 					node->regex = tintin_regexp_compile(ses, node, node->arg1, PCRE_ANCHORED);
+#endif
 					break;
 
 				case LIST_ACTION:
@@ -176,7 +180,11 @@
 	switch (root->type)
 	{
 		case LIST_ALIAS:
+#ifdef HAVE_PCRE2_H
+			node->regex = tintin_regexp_compile(root->ses, node, node->arg1, PCRE2_ANCHORED);
+#else
 			node->regex = tintin_regexp_compile(root->ses, node, node->arg1, PCRE_ANCHORED);
+#endif
 			break;
 
 		case LIST_ACTION:
@@ -361,7 +369,11 @@
 	{
 		if (node->regex)
 		{
+#ifdef HAVE_PCRE2_H
+			pcre2_code_free(node->regex);
+#else
 			free(node->regex);
+#endif
 		}
 	}
 
--- a/src/regex.c
+++ b/src/regex.c
@@ -24,7 +24,6 @@
 ******************************************************************************/
 
 #include <sys/types.h>
-#include <pcre.h>
 
 #include "tintin.h"
 
@@ -90,10 +89,21 @@
 	return ses;
 }
 
+#ifdef HAVE_PCRE2_H
+int regexp_compare(struct session *ses, pcre2_code *nodepcre, char *str, char *exp, int option, int flag)
+#else
 int regexp_compare(struct session *ses, pcre *nodepcre, char *str, char *exp, int option, int flag)
+#endif
 {
+#ifdef HAVE_PCRE2_H
+	pcre2_code *regex;
+	pcre2_match_data *matchdata;
+	PCRE2_SIZE *match = NULL;
+#else
 	pcre *regex;
-	int i, j, matches, match[303];
+	int match[303];
+#endif
+	int i, j, matches;
 
 	if (nodepcre == NULL)
 	{
@@ -109,6 +119,30 @@
 		return FALSE;
 	}
 
+#ifdef HAVE_PCRE2_H
+	matchdata = pcre2_match_data_create_from_pattern(regex, NULL);
+	if (matchdata == NULL)
+	{
+		if (nodepcre == NULL)
+		{
+			pcre2_code_free(regex);
+		}
+		return FALSE;
+	}
+
+	matches = pcre2_match(regex, (PCRE2_SPTR)str, strlen(str), 0, 0, matchdata, NULL);
+	match = pcre2_get_ovector_pointer(matchdata); // freeing matchdata frees match too
+
+	if ((matches <= 0) || (match == NULL))
+	{
+        pcre2_match_data_free(matchdata);
+		if (nodepcre == NULL)
+		{
+			pcre2_code_free(regex);
+		}
+		return FALSE;
+	}
+#else
 	matches = pcre_exec(regex, NULL, str, strlen(str), 0, 0, match, 303);
 
 	if (matches <= 0)
@@ -119,6 +153,7 @@
 		}
 		return FALSE;
 	}
+#endif
 
 	// REGEX_FLAG_FIX handles %1 to %99 usage. Backward compatibility.
 
@@ -181,14 +216,36 @@
 			break;
 	}
 
+#ifdef HAVE_PCRE2_H
+    pcre2_match_data_free(matchdata);
+	if (nodepcre == NULL)
+	{
+		pcre2_code_free(regex);
+	}
+#else
 	if (nodepcre == NULL)
 	{
 		free(regex);
 	}
+#endif
 
 	return TRUE;
 }
 
+#ifdef HAVE_PCRE2_H
+pcre2_code *regexp_compile(struct session *ses, char *exp, int option)
+{
+	int error;
+	size_t i;
+/*
+	if (HAS_BIT(ses->charset, CHARSET_FLAG_UTF8))
+	{
+		option |= PCRE2_UTF8|PCRE2_NO_UTF8_CHECK;
+	}
+*/
+	return pcre2_compile((PCRE2_SPTR)exp, PCRE2_ZERO_TERMINATED, option, &error, &i, NULL);
+}
+#else
 pcre *regexp_compile(struct session *ses, char *exp, int option)
 {
 	const char *error;
@@ -201,6 +258,7 @@
 */
 	return pcre_compile(exp, option, &error, &i, NULL);
 }
+#endif
 
 
 
@@ -455,7 +513,11 @@
 	return FALSE;
 }
 
+#ifdef HAVE_PCRE2_H
+int tintin_regexp(struct session *ses, pcre2_code *nodepcre, char *str, char *exp, int option, int flag)
+#else
 int tintin_regexp(struct session *ses, pcre *nodepcre, char *str, char *exp, int option, int flag)
+#endif
 {
 	char out[BUFFER_SIZE], *pti, *pto;
 	int arg = 1, var = 1, fix = 0;
@@ -816,7 +878,11 @@
 	return regexp_compare(ses, nodepcre, str, out, option, flag + fix);
 }
 
+#ifdef HAVE_PCRE2_H
+pcre2_code *tintin_regexp_compile(struct session *ses, struct listnode *node, char *exp, int option)
+#else
 pcre *tintin_regexp_compile(struct session *ses, struct listnode *node, char *exp, int option)
+#endif
 {
 	char out[BUFFER_SIZE], *pti, *pto;