| 1 |
Description: Port to pcre2 |
| 2 |
This patch has been forwarded by email to <[email protected]> but UDD |
| 3 |
considers an email address as an invalid Forwarded value, so let's note this |
| 4 |
here and mark forwarded as not-needed as there is no upstream bug tracker |
| 5 |
either (Forwarded: yes and no <Bug> field would also be marked invalid). |
| 6 |
Author: Stephen Kitt <[email protected]> to reduce unnecessary noise. |
| 7 |
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=999977 |
| 8 |
Forwarded: not-needed |
| 9 |
Last-pdate: 2025-02-04 |
| 10 |
--- a/Makefile |
| 11 |
+++ b/Makefile |
| 12 |
@@ -27,7 +27,7 @@ |
| 13 |
PKG_CONFIG ?= pkg-config |
| 14 |
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 |
| 15 |
# 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 |
| 16 |
|
| 17 |
+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` |
| 18 |
# -lrt as well? |
| 19 |
ifneq ($(filter deb,$(MAKECMDGOALS)),) |
| 20 |
CFLAGS:= $(CFLAGS) -g |
| 21 |
--- a/dicts.c |
| 22 |
+++ b/dicts.c |
| 23 |
@@ -23,7 +23,8 @@ |
| 24 |
*/ |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
+#define PCRE2_CODE_UNIT_WIDTH 8 |
| 29 |
+#include <pcre2.h> |
| 30 |
#include <glib.h> // required for string conversion functions |
| 31 |
#include <glib/gstdio.h> |
| 32 |
|
| 33 |
@@ -447,13 +448,13 @@ |
| 34 |
|
| 35 |
// Add a new dictionary word with UTF-8 citation form s0 |
| 36 |
// dictionary number dn, score f. Return 1 if added, 0 if not, -2 for out of memory |
| 37 |
|
| 38 |
+static int adddictword(char*s0,int dn,pcre2_code*sre,pcre2_code*are,float f) { |
| 39 |
int c,c0,i,l0,l1,l2; |
| 40 |
uchar t[MXLE+1],u; |
| 41 |
char s1[MXLE*16+1]; |
| 42 |
char s2[MXLE+1]; |
| 43 |
struct memblk*q; |
| 44 |
|
| 45 |
+ pcre2_match_data * pcremd; |
| 46 |
|
| 47 |
l0=strlen(s0); |
| 48 |
utf8touchars(t,s0,MXLE+1); |
| 49 |
@@ -507,24 +508,28 @@ |
| 50 |
// s2 contains canonicalised form in internal character code, length l2 1<=l2<=MXLE |
| 51 |
|
| 52 |
dst_lines[dn]++; |
| 53 |
+ pcremd = pcre2_match_data_create(120, NULL); |
| 54 |
if(sre) { |
| 55 |
|
| 56 |
+ i=pcre2_match(sre,(PCRE2_SPTR)s0,l0,0,0,pcremd,NULL); |
| 57 |
DEB_DI if(i<-1) printf("PCRE error %d\n",i); |
| 58 |
if(i<0) { |
| 59 |
DEB_DV printf(" failed file filter\n"); |
| 60 |
+ pcre2_match_data_free(pcremd); |
| 61 |
return 0; // failed match |
| 62 |
} |
| 63 |
} |
| 64 |
dst_lines_f[dn]++; |
| 65 |
if(are) { |
| 66 |
|
| 67 |
+ i=pcre2_match(are,(PCRE2_SPTR)s1,l1,0,0,pcremd,NULL); |
| 68 |
DEB_DI if(i<-1) printf("PCRE error %d\n",i); |
| 69 |
if(i<0) { |
| 70 |
DEB_DV printf(" failed answer filter\n"); |
| 71 |
+ pcre2_match_data_free(pcremd); |
| 72 |
return 0; // failed match |
| 73 |
} |
| 74 |
} |
| 75 |
dst_lines_fa[dn]++; |
| 76 |
+ pcre2_match_data_free(pcremd); |
| 77 |
|
| 78 |
if(memblkp==NULL||memblkl+2+l0+1+l2+1>MEMBLK) { // allocate more memory if needed (this always happens on first pass round loop) |
| 79 |
q=(struct memblk*)malloc(sizeof(struct memblk)); |
| 80 |
@@ -574,7 +579,7 @@ |
| 81 |
} |
| 82 |
|
| 83 |
// Attempt to load a .TSD file. Return number of words >=0 on success, <0 on error. |
| 84 |
|
| 85 |
+static int loadtsd(FILE*fp,int format,int dn,pcre2_code*sre,pcre2_code*are) { |
| 86 |
int c,i,j,l,m,ml,n,u,nw; |
| 87 |
int hoff[MXLE+1]; // file offsets into Huffman coded block |
| 88 |
int dcount[MXLE+1]; // number of words of each length |
| 89 |
@@ -683,9 +688,10 @@ |
| 90 |
|
| 91 |
float f; |
| 92 |
int mode,owd,rc; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
+ pcre2_code*sre,*are; |
| 97 |
+ int pcreerr; |
| 98 |
+ PCRE2_SIZE pcreerroff; |
| 99 |
+ PCRE2_UCHAR pcreerrmsg[256]; |
| 100 |
char sfilter[SLEN+1]; |
| 101 |
char afilter[SLEN+1]; |
| 102 |
GError *error = NULL; |
| 103 |
@@ -709,18 +715,20 @@ |
| 104 |
strcpy(sfilter,dsfilters[dn]); |
| 105 |
if(!strcmp(sfilter,"")) sre=0; |
| 106 |
else { |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
+ sre=pcre2_compile((PCRE2_SPTR)sfilter,PCRE2_ZERO_TERMINATED,PCRE2_CASELESS|PCRE2_UTF|PCRE2_UCP,&pcreerr,&pcreerroff,0); |
| 111 |
+ if(sre == NULL) { |
| 112 |
+ pcre2_get_error_message(pcreerr, pcreerrmsg, sizeof pcreerrmsg); |
| 113 |
+ sprintf(t,"Dictionary %d\nBad file filter syntax: %s",dn+1,pcreerrmsg); |
| 114 |
if(!sil) reperr(t); |
| 115 |
} |
| 116 |
} |
| 117 |
strcpy(afilter,dafilters[dn]); |
| 118 |
if(!strcmp(afilter,"")) are=0; |
| 119 |
else { |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
+ are=pcre2_compile((PCRE2_SPTR)afilter,PCRE2_ZERO_TERMINATED,PCRE2_CASELESS|PCRE2_UTF|PCRE2_UCP,&pcreerr,&pcreerroff,0); |
| 124 |
+ if(are == NULL) { |
| 125 |
+ pcre2_get_error_message(pcreerr, pcreerrmsg, sizeof pcreerrmsg); |
| 126 |
+ sprintf(t,"Dictionary %d\nBad answer filter syntax: %s",dn+1,pcreerrmsg); |
| 127 |
if(!sil) reperr(t); |
| 128 |
} |
| 129 |
} |
| 130 |
@@ -834,8 +842,8 @@ |
| 131 |
|
| 132 |
exit: |
| 133 |
if(sp) g_free(sp),sp=0; |
| 134 |
|
| 135 |
|
| 136 |
+ if(sre) pcre2_code_free(sre); |
| 137 |
+ if(are) pcre2_code_free(are); |
| 138 |
g_clear_error(&error); |
| 139 |
if(!owd) if(fp) fclose(fp); |
| 140 |
if(rc<0) return rc; |