File: 03_port_to_pcre2.diff

package info (click to toggle)
shush 1.2.3-5.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 820 kB
  • sloc: ansic: 5,515; sh: 2,706; lex: 69; makefile: 69; yacc: 54; awk: 31
file content (178 lines) | stat: -rw-r--r-- 5,152 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
Description: Port to PCRE2.
Bug-Debian: https://bugs.debian.org/999964
Author: Yavor Doganov <yavor@gnu.org>
Forwarded: no
Last-Update: 2023-12-17
---

--- shush-1.2.3.orig/configure.ac
+++ shush-1.2.3/configure.ac
@@ -60,9 +60,19 @@
 # Checks for libraries.
 AC_SEARCH_LIBS([basename], [gen])
 if test "x$with_pcre" != "xno"; then
-   AC_SEARCH_LIBS([pcre_compile], [pcre], ,
-	AC_MSG_WARN([Perl Compatible Regular Expressions library is missing.])
-	with_pcre="no")
+   save_libs="$LIBS"
+   LIBS="$LIBS -lpcre2-8"
+   AC_MSG_CHECKING([for pcre library])
+   AC_LINK_IFELSE(
+     [AC_LANG_PROGRAM([[#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>
+]],
+                      [[pcre2_match_data_create(4, NULL);]])],
+     [AC_MSG_RESULT([yes])],
+     [AC_MSG_RESULT([no])
+      AC_MSG_WARN([Perl Compatible Regular Expressions library is missing.])
+      with_pcre="no"
+      LIBS="$save_libs"])
 fi
 AC_SEARCH_LIBS([MD5Data], [md])
 AC_SEARCH_LIBS([md5_calc], [md5])
@@ -70,7 +80,11 @@
 # Checks for header files.
 AC_CHECK_HEADERS([md5.h paths.h pthread.h])
 if test "x$with_pcre" != "xno"; then
-   AC_CHECK_HEADERS([pcre.h])
+   AC_CHECK_HEADERS([pcre2.h],
+     [AC_DEFINE([HAVE_PCRE_H], [1],
+                [Define to 1 if you have the <pcre2.h> header file.])],
+     [], [[#define PCRE2_CODE_UNIT_WIDTH 8
+     ]])
 fi
 
 # Checks for typedefs, structures, and compiler characteristics.
--- shush-1.2.3.orig/src/analyzer.c
+++ shush-1.2.3/src/analyzer.c
@@ -16,7 +16,8 @@
 #include <fcntl.h>
 #include <regex.h>
 #if defined(HAVE_PCRE_H)
-# include <pcre.h>
+# define PCRE2_CODE_UNIT_WIDTH 8
+# include <pcre2.h>
 #endif
 
 #include "analyzer.h"
@@ -40,7 +41,7 @@
     {
 	regex_t re;
 #if defined(HAVE_PCRE_H)
-	pcre *pcre;
+	pcre2_code *pcre;
 #endif
     } val;
 };
@@ -98,15 +99,19 @@
 static int
 compile_pcre(void *pcreptr, char *str)
 {
-    pcre **re;
-    const char *errmsg;
-    int erroffset;
+    pcre2_code **re;
+    int err;
+    PCRE2_SIZE erroffset;
 
     re = pcreptr;
-    *re = pcre_compile(str, 0, &errmsg, &erroffset, NULL);
+    *re = pcre2_compile((PCRE2_SPTR)str, strlen(str), 0,
+                        &err, &erroffset, NULL);
     if (*re == NULL)
       {
-	error("Bad PCRE (offset %d): %s", erroffset, errmsg);
+	PCRE2_UCHAR errmsg[120];
+
+	pcre2_get_error_message(err, errmsg, sizeof(errmsg));
+	error("Bad PCRE (offset %zu): %s", erroffset, errmsg);
 	return -1;
       }
     return 0;
@@ -501,15 +506,17 @@
 #if defined(HAVE_PCRE_H)
 	  else if (type == PCRE)
 	    {
-	      int ovector[3072];
+	      PCRE2_SIZE *ovector;
+	      pcre2_match_data *md;
 
-	      r = pcre_exec(list[condno].val.pcre, NULL, ln,
+	      md = pcre2_match_data_create(3072, NULL);
+	      r = pcre2_match(list[condno].val.pcre, (PCRE2_SPTR)ln,
 			    (lndup != NULL) ? strlen(lndup) : nl - ln,
-			    0, 0, ovector, 3072);
-	      if (r < 0 && r != PCRE_ERROR_NOMATCH)
+			    0, 0, md, NULL);
+	      if (r < 0 && r != PCRE2_ERROR_NOMATCH)
 		{
 		  /* Something bad happened */
-		  error("Fatal error during output analysis: pcre_exec() failed with code %d", r);
+		  error("Fatal error during output analysis: pcre2_match() failed with code %d", r);
 		  error("Regular expression used was: %s",
 			list[condno].expression);
 		  error("Trying to match the following line of data: %s", ln);
@@ -517,6 +524,7 @@
 		      free(lndup);
 		  else
 		      *nl = '\n';
+                  pcre2_match_data_free(md);
 		  return -1;
 		}
 	      else
@@ -527,14 +535,15 @@
 
 		      /* Matched */
 		      debug(DDATA,
-			    "Matched: #%d %d[%c] (PCRE_ERROR_NOMATCH=%d)",
-			    condno+1, r, list[condno].code, PCRE_ERROR_NOMATCH);
+			    "Matched: #%d %d[%c] (PCRE2_ERROR_NOMATCH=%d)",
+			    condno+1, r, list[condno].code, PCRE2_ERROR_NOMATCH);
 		      byteset_set(list[condno].code, 1);
 		      /* Check for substrings */
 		      i = 1;
+		      ovector = pcre2_get_ovector_pointer(md);
 		      while (i < r)
 			{
-			  if (ovector[i*2] < 0 || ovector[i*2+1] < 0)
+			  if ((int)ovector[i*2] < 0 || (int)ovector[i*2+1] < 0)
 			      continue;
 			  set_mark(marks, &mark, &max,
 				   ln - str + ovector[i*2], TOGGLE);
@@ -546,8 +555,9 @@
 		    }
 		  else
 		      debug(DVDATA,
-			    "Failed: #%d %d[%c] (PCRE_ERROR_NOMATCH=%d)",
-			    condno+1, r, list[condno].code, PCRE_ERROR_NOMATCH);
+			    "Failed: #%d %d[%c] (PCRE2_ERROR_NOMATCH=%d)",
+			    condno+1, r, list[condno].code, PCRE2_ERROR_NOMATCH);
+		  pcre2_match_data_free(md);
 		}
 	    }
 #endif
--- shush-1.2.3.orig/src/shush.c
+++ shush-1.2.3/src/shush.c
@@ -10,7 +10,8 @@
 #include <libgen.h>
 #include <time.h>
 #if defined(HAVE_PCRE_H)
-# include <pcre.h>
+# define PCRE2_CODE_UNIT_WIDTH 8
+# include <pcre2.h>
 #endif
 
 #include "version.h"
@@ -149,8 +150,11 @@
 #if !defined(HAVE_PCRE_H)
 	      printf("%s version %s\n", myname, SHUSH_VERSION);
 #else
+	      char ver[24];
+
+	      pcre2_config(PCRE2_CONFIG_VERSION, ver);
 	      printf("%s version %s (PCRE version %s)\n",
-		     myname, SHUSH_VERSION, pcre_version());
+		     myname, SHUSH_VERSION, ver);
 #endif
 	      if ((runopts & RUN_VERBOSE) != 0)
 		{