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
|
Description: Port to pcre2
This patch has been forwarded by email to <qxw@quinapalus.com> but UDD
considers an email address as an invalid Forwarded value, so let's note this
here and mark forwarded as not-needed as there is no upstream bug tracker
either (Forwarded: yes and no <Bug> field would also be marked invalid).
Author: Stephen Kitt <skitt@debian.org> to reduce unnecessary noise.
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=999977
Forwarded: not-needed
Last-pdate: 2025-02-04
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,7 @@
PKG_CONFIG ?= pkg-config
CFLAGS := -Wall -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -Wno-deprecated-declarations `$(PKG_CONFIG) --cflags glib-2.0` `$(PKG_CONFIG) --cflags gtk+-2.0` -I/opt/local/include `dpkg-buildflags --get CFLAGS` `dpkg-buildflags --get CPPFLAGS` -Wpedantic -Wextra -Wno-unused-parameter
# CFLAGS := -Wall -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security `$(PKG_CONFIG) --cflags glib-2.0` `$(PKG_CONFIG) --cflags gtk+-2.0` -I/opt/local/include
-LFLAGS := -Wl,-Bsymbolic-functions -Wl,-z,relro -L/opt/local/lib `$(PKG_CONFIG) --libs glib-2.0` `$(PKG_CONFIG) --libs gtk+-2.0` -lm -ldl -lpcre -pthread -lgthread-2.0 `dpkg-buildflags --get LDFLAGS`
+LFLAGS := -Wl,-Bsymbolic-functions -Wl,-z,relro -L/opt/local/lib `$(PKG_CONFIG) --libs glib-2.0` `$(PKG_CONFIG) --libs gtk+-2.0` -lm -ldl `pcre2-config --libs8` -pthread -lgthread-2.0 `dpkg-buildflags --get LDFLAGS`
# -lrt as well?
ifneq ($(filter deb,$(MAKECMDGOALS)),)
CFLAGS:= $(CFLAGS) -g
--- a/dicts.c
+++ b/dicts.c
@@ -23,7 +23,8 @@
*/
-#include <pcre.h>
+#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>
#include <glib.h> // required for string conversion functions
#include <glib/gstdio.h>
@@ -447,13 +448,13 @@
// Add a new dictionary word with UTF-8 citation form s0
// dictionary number dn, score f. Return 1 if added, 0 if not, -2 for out of memory
-static int adddictword(char*s0,int dn,pcre*sre,pcre*are,float f) {
+static int adddictword(char*s0,int dn,pcre2_code*sre,pcre2_code*are,float f) {
int c,c0,i,l0,l1,l2;
uchar t[MXLE+1],u;
char s1[MXLE*16+1];
char s2[MXLE+1];
struct memblk*q;
- int pcreov[120];
+ pcre2_match_data * pcremd;
l0=strlen(s0);
utf8touchars(t,s0,MXLE+1);
@@ -507,24 +508,28 @@
// s2 contains canonicalised form in internal character code, length l2 1<=l2<=MXLE
dst_lines[dn]++;
+ pcremd = pcre2_match_data_create(120, NULL);
if(sre) {
- i=pcre_exec(sre,0,s0,l0,0,0,pcreov,120);
+ i=pcre2_match(sre,(PCRE2_SPTR)s0,l0,0,0,pcremd,NULL);
DEB_DI if(i<-1) printf("PCRE error %d\n",i);
if(i<0) {
DEB_DV printf(" failed file filter\n");
+ pcre2_match_data_free(pcremd);
return 0; // failed match
}
}
dst_lines_f[dn]++;
if(are) {
- i=pcre_exec(are,0,s1,l1,0,0,pcreov,120);
+ i=pcre2_match(are,(PCRE2_SPTR)s1,l1,0,0,pcremd,NULL);
DEB_DI if(i<-1) printf("PCRE error %d\n",i);
if(i<0) {
DEB_DV printf(" failed answer filter\n");
+ pcre2_match_data_free(pcremd);
return 0; // failed match
}
}
dst_lines_fa[dn]++;
+ pcre2_match_data_free(pcremd);
if(memblkp==NULL||memblkl+2+l0+1+l2+1>MEMBLK) { // allocate more memory if needed (this always happens on first pass round loop)
q=(struct memblk*)malloc(sizeof(struct memblk));
@@ -574,7 +579,7 @@
}
// Attempt to load a .TSD file. Return number of words >=0 on success, <0 on error.
-static int loadtsd(FILE*fp,int format,int dn,pcre*sre,pcre*are) {
+static int loadtsd(FILE*fp,int format,int dn,pcre2_code*sre,pcre2_code*are) {
int c,i,j,l,m,ml,n,u,nw;
int hoff[MXLE+1]; // file offsets into Huffman coded block
int dcount[MXLE+1]; // number of words of each length
@@ -683,9 +688,10 @@
float f;
int mode,owd,rc;
- pcre*sre,*are;
- const char*pcreerr;
- int pcreerroff;
+ pcre2_code*sre,*are;
+ int pcreerr;
+ PCRE2_SIZE pcreerroff;
+ PCRE2_UCHAR pcreerrmsg[256];
char sfilter[SLEN+1];
char afilter[SLEN+1];
GError *error = NULL;
@@ -709,18 +715,20 @@
strcpy(sfilter,dsfilters[dn]);
if(!strcmp(sfilter,"")) sre=0;
else {
- sre=pcre_compile(sfilter,PCRE_CASELESS|PCRE_UTF8|PCRE_UCP,&pcreerr,&pcreerroff,0);
- if(pcreerr) {
- sprintf(t,"Dictionary %d\nBad file filter syntax: %.100s",dn+1,pcreerr);
+ sre=pcre2_compile((PCRE2_SPTR)sfilter,PCRE2_ZERO_TERMINATED,PCRE2_CASELESS|PCRE2_UTF|PCRE2_UCP,&pcreerr,&pcreerroff,0);
+ if(sre == NULL) {
+ pcre2_get_error_message(pcreerr, pcreerrmsg, sizeof pcreerrmsg);
+ sprintf(t,"Dictionary %d\nBad file filter syntax: %s",dn+1,pcreerrmsg);
if(!sil) reperr(t);
}
}
strcpy(afilter,dafilters[dn]);
if(!strcmp(afilter,"")) are=0;
else {
- are=pcre_compile(afilter,PCRE_CASELESS|PCRE_UTF8|PCRE_UCP,&pcreerr,&pcreerroff,0);
- if(pcreerr) {
- sprintf(t,"Dictionary %d\nBad answer filter syntax: %.100s",dn+1,pcreerr);
+ are=pcre2_compile((PCRE2_SPTR)afilter,PCRE2_ZERO_TERMINATED,PCRE2_CASELESS|PCRE2_UTF|PCRE2_UCP,&pcreerr,&pcreerroff,0);
+ if(are == NULL) {
+ pcre2_get_error_message(pcreerr, pcreerrmsg, sizeof pcreerrmsg);
+ sprintf(t,"Dictionary %d\nBad answer filter syntax: %s",dn+1,pcreerrmsg);
if(!sil) reperr(t);
}
}
@@ -834,8 +842,8 @@
exit:
if(sp) g_free(sp),sp=0;
- if(sre) pcre_free(sre);
- if(are) pcre_free(are);
+ if(sre) pcre2_code_free(sre);
+ if(are) pcre2_code_free(are);
g_clear_error(&error);
if(!owd) if(fp) fclose(fp);
if(rc<0) return rc;
|