| 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 |
#include "common.h" |
| 26 |
#include "qxw.h" |
| 27 |
#include "dicts.h" |
| 28 |
#include "treatment.h" |
| 29 |
#include "gui.h" |
| 30 |
|
| 31 |
#ifdef _WIN32 |
| 32 |
#include "pfdlfcn.h" |
| 33 |
#else |
| 34 |
#include <dlfcn.h> |
| 35 |
#endif |
| 36 |
|
| 37 |
#define HTABSZ 4194304 |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
static int curans,curem,curten,curdm; |
| 42 |
|
| 43 |
int treatmode=0,treatorder[NMSG]={0,0}; |
| 44 |
char tpifname[SLEN]=""; |
| 45 |
ABM treatcstr[NMSG][MXFL]={{0},{0}}; |
| 46 |
int tambaw=0; |
| 47 |
|
| 48 |
char treatmsg [NMSG][MXLT*8+1]; |
| 49 |
uchar treatmsgU [NMSG][MXLT+1]; |
| 50 |
char treatmsgICC [NMSG][MXLT+1]; |
| 51 |
char treatmsgICCAZ [NMSG][MXLT+1]; |
| 52 |
char treatmsgICCAZ09[NMSG][MXLT+1]; |
| 53 |
uchar treatmsgUAZ [NMSG][MXLT+1]; |
| 54 |
uchar treatmsgUAZ09 [NMSG][MXLT+1]; |
| 55 |
char treatmsgAZ [NMSG][MXLT+1]; |
| 56 |
char treatmsgAZ09 [NMSG][MXLT+1]; |
| 57 |
|
| 58 |
char *treatmessage [NMSG]={"",""}; |
| 59 |
uchar*treatmessageU [NMSG]; |
| 60 |
char *treatmessageICC [NMSG]; |
| 61 |
char *treatmessageICCAZ [NMSG]; |
| 62 |
char *treatmessageICCAZ09[NMSG]; |
| 63 |
uchar*treatmessageUAZ [NMSG]; |
| 64 |
uchar*treatmessageUAZ09 [NMSG]; |
| 65 |
char *treatmessageAZ [NMSG]; |
| 66 |
char *treatmessageAZ09 [NMSG]; |
| 67 |
|
| 68 |
char msgchar[NMSG]; |
| 69 |
uchar msgcharU[NMSG]; |
| 70 |
uchar msgcharUAZ[NMSG]; |
| 71 |
uchar msgcharUAZ09[NMSG]; |
| 72 |
char msgcharICC[NMSG]; |
| 73 |
char msgcharICCAZ[NMSG]; |
| 74 |
char msgcharICCAZ09[NMSG]; |
| 75 |
char msgcharAZ[NMSG]; |
| 76 |
char msgcharAZ09[NMSG]; |
| 77 |
|
| 78 |
const char*answerICC; |
| 79 |
const uchar*answerU; |
| 80 |
|
| 81 |
int clueorderindex; |
| 82 |
int gridorderindex[MXLE]; |
| 83 |
int checking[MXLE]; |
| 84 |
int lightlength; |
| 85 |
int lightx; |
| 86 |
int lighty; |
| 87 |
int lightdir; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
static char psq[25]; |
| 93 |
static int psc[MAXICC]; |
| 94 |
|
| 95 |
static int*tfl=0; |
| 96 |
static int ctfl,ntfl; |
| 97 |
|
| 98 |
static int clts; |
| 99 |
static int hstab[HTABSZ]; |
| 100 |
static int haestab[HTABSZ]; |
| 101 |
static struct memblk*lstrings=0; |
| 102 |
static struct memblk*lmp=0; |
| 103 |
static int lml=MEMBLK; |
| 104 |
|
| 105 |
static void dohistdata(struct light*l) { |
| 106 |
int i,j,m,n; |
| 107 |
memset(l->hist,0,sizeof(l->hist)); |
| 108 |
l->lbm=0; |
| 109 |
m=0; |
| 110 |
n=strlen(l->s); |
| 111 |
if(l->tagged) n-=NMSG; |
| 112 |
for(i=0;i<n;i++) { |
| 113 |
j=(int)l->s[i]; |
| 114 |
l->hist[j]++; |
| 115 |
if(l->hist[j]>m) m=l->hist[j]; |
| 116 |
l->lbm|=ICCTOABM(j); |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
static int findlight(const char*s,int tagged,int a,int e) { |
| 122 |
unsigned int h0,h1; |
| 123 |
int f,i,u,l0; |
| 124 |
int l; |
| 125 |
int len0,len1; |
| 126 |
struct light*p; |
| 127 |
struct memblk*q; |
| 128 |
|
| 129 |
len0=strlen(s); |
| 130 |
if(tagged) len0-=NMSG; |
| 131 |
assert(len0>0); |
| 132 |
h0=0; |
| 133 |
for(i=0;i<len0;i++) h0=h0*113+s[i]; |
| 134 |
h1=h0*113+a*27+e; |
| 135 |
h0=h0%HTABSZ; |
| 136 |
h1=h1%HTABSZ; |
| 137 |
l=haestab[h1]; |
| 138 |
while(l!=-1) { |
| 139 |
if(lts[l].ans==a&<s[l].em==e&&!strcmp(s,lts[l].s)) return l; |
| 140 |
l=lts[l].hashaeslink; |
| 141 |
} |
| 142 |
if(ltotal>=clts) { |
| 143 |
clts=clts*2+5000; |
| 144 |
p=realloc(lts,clts*sizeof(struct light)); |
| 145 |
if(!p) return -1; |
| 146 |
lts=p; |
| 147 |
DEB_FL printf("lts realloc: %d\n",clts); |
| 148 |
} |
| 149 |
l=hstab[h0]; |
| 150 |
u=-1; |
| 151 |
f=0; |
| 152 |
while(l!=-1) { |
| 153 |
len1=strlen(lts[l].s); |
| 154 |
if(lts[l].tagged) len1-=NMSG; |
| 155 |
assert(len1>0); |
| 156 |
if(len0==len1&&!strncmp(s,lts[l].s,len0)) { |
| 157 |
u=lts[l].uniq; |
| 158 |
if(!strcmp(s,lts[l].s)) {f=1; break;} |
| 159 |
} |
| 160 |
l=lts[l].hashslink; |
| 161 |
} |
| 162 |
if(f==0) { |
| 163 |
l0=strlen(s)+1; |
| 164 |
if(lml+l0>MEMBLK) { |
| 165 |
DEB_FL printf("memblk alloc\n"); |
| 166 |
q=(struct memblk*)malloc(sizeof(struct memblk)); |
| 167 |
if(!q) return -1; |
| 168 |
q->next=NULL; |
| 169 |
if(lmp==NULL) lstrings=q; else lmp->next=q; |
| 170 |
lmp=q; |
| 171 |
lml=0; |
| 172 |
} |
| 173 |
if(u==-1) u=ultotal++; |
| 174 |
lts[ltotal].s=lmp->s+lml; |
| 175 |
strcpy(lmp->s+lml,s);lml+=l0; |
| 176 |
} else { |
| 177 |
lts[ltotal].s=lts[l].s; |
| 178 |
} |
| 179 |
lts[ltotal].ans=a; |
| 180 |
lts[ltotal].em=e; |
| 181 |
lts[ltotal].uniq=u; |
| 182 |
lts[ltotal].tagged=tagged; |
| 183 |
lts[ltotal].hashslink =hstab [h0]; hstab [h0]=ltotal; |
| 184 |
lts[ltotal].hashaeslink=haestab[h1]; haestab[h1]=ltotal; |
| 185 |
dohistdata(lts+ltotal); |
| 186 |
return ltotal++; |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
int iswordICC(const char*s) { return iswordindm(s,curdm); } |
| 191 |
|
| 192 |
|
| 193 |
int iswordU(const uchar*s) { |
| 194 |
int i,j,u; |
| 195 |
char s0[MXFL+1]; |
| 196 |
for(i=0,j=0;s[i]&&j<MXFL;i++) { |
| 197 |
u=uchartoICC(s[i]); |
| 198 |
if(u) s0[j++]=u; |
| 199 |
} |
| 200 |
s0[j]=0; |
| 201 |
return iswordICC(s0); |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
int isword(const char*s) { |
| 206 |
uchar s0[MXFL+1]; |
| 207 |
utf8touchars(s0,s,MXFL+1); |
| 208 |
return iswordU(s0); |
| 209 |
} |
| 210 |
|
| 211 |
int ICCtoclass(char c) { |
| 212 |
if(c<0||c>MAXICC) return -1; |
| 213 |
return icctogroup[(int)c]; |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
static int addlight(const char*s,int a,int e) { |
| 219 |
int l; |
| 220 |
int*p; |
| 221 |
char t[MXFL+1]; |
| 222 |
|
| 223 |
l=strlen(s); |
| 224 |
if(l<1) return 0; |
| 225 |
memcpy(t,s,l); |
| 226 |
if(curten) memcpy(t+l,msgcharICC,NMSG),l+=NMSG; |
| 227 |
t[l]=0; |
| 228 |
l=findlight(t,curten,a,e); |
| 229 |
if(l<0) return l; |
| 230 |
if(ntfl>=ctfl) { |
| 231 |
ctfl=ctfl*3/2+500; |
| 232 |
p=realloc(tfl,ctfl*sizeof(int)); |
| 233 |
if(!p) return -1; |
| 234 |
tfl=p; |
| 235 |
DEB_FL printf("tfl realloc: %d\n",ctfl); |
| 236 |
} |
| 237 |
tfl[ntfl++]=l; |
| 238 |
return 0; |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
int treatedanswerICC(const char*s) { |
| 244 |
char s0[MXFL+1]; |
| 245 |
int j,k,l,u; |
| 246 |
|
| 247 |
l=strlen(s); |
| 248 |
|
| 249 |
if(l!=lightlength) return 0; |
| 250 |
DEB_FL assert(l>0); |
| 251 |
if(tambaw&&!iswordICC(s)) return 0; |
| 252 |
if(curem&EM_JUM) { |
| 253 |
return addlight(s,curans,4); |
| 254 |
} |
| 255 |
if(curem&EM_FWD) { |
| 256 |
u=addlight(s,curans,0);if(u) return u; |
| 257 |
} |
| 258 |
if(curem&EM_REV) { |
| 259 |
for(j=0;j<l;j++) s0[j]=s[l-j-1]; |
| 260 |
s0[j]=0; |
| 261 |
u=addlight(s0,curans,1);if(u) return u; |
| 262 |
} |
| 263 |
if(curem&EM_CYC) { |
| 264 |
if(!(l==2&&(curem&EM_REV))) { |
| 265 |
for(k=1;k<l;k++) { |
| 266 |
for(j=0;j<l;j++) s0[j]=s[(j+k)%l]; |
| 267 |
s0[j]=0; |
| 268 |
u=addlight(s0,curans,2);if(u) return u; |
| 269 |
} |
| 270 |
} |
| 271 |
} |
| 272 |
if(curem&EM_RCY) { |
| 273 |
if(!(l==2&&(curem&EM_FWD))) { |
| 274 |
for(k=1;k<l;k++) { |
| 275 |
for(j=0;j<l;j++) s0[j]=s[(l-j-1+k)%l]; |
| 276 |
s0[j]=0; |
| 277 |
u=addlight(s0,curans,3);if(u) return u; |
| 278 |
} |
| 279 |
} |
| 280 |
} |
| 281 |
return 0; |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
int treatedanswerU(const uchar*s) { |
| 286 |
int i,j,u; |
| 287 |
char s0[MXFL+1]; |
| 288 |
for(i=0,j=0;s[i]&&j<MXFL;i++) { |
| 289 |
u=uchartoICC(s[i]); |
| 290 |
if(u) s0[j++]=u; |
| 291 |
} |
| 292 |
if(j!=lightlength) return 0; |
| 293 |
s0[j]=0; |
| 294 |
return treatedanswerICC(s0); |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
int treatedanswer(const char*s) { |
| 299 |
uchar s0[MXFL+1]; |
| 300 |
DEB_TR printf("treatedanswer(\"%s\")\n",s); |
| 301 |
utf8touchars(s0,s,MXFL+1); |
| 302 |
return treatedanswerU(s0); |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
static int inittreat(void) {int i,k; |
| 307 |
int c; |
| 308 |
|
| 309 |
switch(treatmode) { |
| 310 |
case 1: |
| 311 |
for(i=1;i<MAXICC;i++) psc[i]=-1; |
| 312 |
for(i=0;i<25;i++) psq[i]=0; |
| 313 |
for(i=0,k=0;treatmsgICC[0][i]&&k<25;i++) { |
| 314 |
c=treatmsgICC[0][i]; |
| 315 |
if(icctouchar[c]=='J'&&uchartoICC('I')!=0) c=uchartoICC('I'); |
| 316 |
if(psc[c]==-1) {psc[c]=k;psq[k]=c;k++;} |
| 317 |
} |
| 318 |
for(i=0;i<niccused&&k<25;i++) { |
| 319 |
c=iccused[i]; |
| 320 |
if(c==0) continue; |
| 321 |
if(icctouchar[c]=='J'&&uchartoICC('I')!=0) continue; |
| 322 |
if(psc[c]==-1) {psc[c]=k;psq[k]=c;k++;} |
| 323 |
} |
| 324 |
if(uchartoICC('I')!=0&&uchartoICC('J')!=0) psc[(int)uchartoICC('J')]=psc[(int)uchartoICC('I')]; |
| 325 |
DEB_TR for(i=0;i<25;i++) { |
| 326 |
printf("%s ",icctoutf8[(int)psq[i]]); |
| 327 |
if(i%5==4) printf("\n"); |
| 328 |
} |
| 329 |
return 0; |
| 330 |
case 9: |
| 331 |
for(i=0;i<NMSG;i++) { |
| 332 |
treatmessage [i]=treatmsg [i]; |
| 333 |
treatmessageU [i]=treatmsgU [i]; |
| 334 |
treatmessageICC [i]=treatmsgICC [i]; |
| 335 |
treatmessageICCAZ [i]=treatmsgICCAZ [i]; |
| 336 |
treatmessageICCAZ09[i]=treatmsgICCAZ09[i]; |
| 337 |
treatmessageUAZ [i]=treatmsgUAZ [i]; |
| 338 |
treatmessageUAZ09 [i]=treatmsgUAZ09 [i]; |
| 339 |
treatmessageAZ [i]=treatmsgAZ [i]; |
| 340 |
treatmessageAZ09 [i]=treatmsgAZ09 [i]; |
| 341 |
} |
| 342 |
break; |
| 343 |
default:break; |
| 344 |
} |
| 345 |
return 0; |
| 346 |
} |
| 347 |
|
| 348 |
static void finittreat(void) {} |
| 349 |
|
| 350 |
|
| 351 |
static void *tpih=0; |
| 352 |
static int (*treatf)(const char*)=0; |
| 353 |
|
| 354 |
|
| 355 |
char*loadtpi(void) { |
| 356 |
int (*f)(void); |
| 357 |
unloadtpi(); |
| 358 |
dlerror(); |
| 359 |
DEB_TR printf("dlopen(\"%s\")\n",tpifname); |
| 360 |
tpih=dlopen(tpifname,RTLD_LAZY); |
| 361 |
if(!tpih) return dlerror(); |
| 362 |
dlerror(); |
| 363 |
*(void**)(&f)=dlsym(tpih,"init"); |
| 364 |
if(!dlerror()) (*f)(); |
| 365 |
*(void**)(&treatf)=dlsym(tpih,"treat"); |
| 366 |
return dlerror(); |
| 367 |
} |
| 368 |
|
| 369 |
void unloadtpi(void) {void (*f)(); |
| 370 |
if(tpih) { |
| 371 |
dlerror(); |
| 372 |
*(void**)(&f)=dlsym(tpih,"finit"); |
| 373 |
if(!dlerror()) (*f)(); |
| 374 |
dlclose(tpih); |
| 375 |
} |
| 376 |
tpih=0; |
| 377 |
treatf=0; |
| 378 |
} |
| 379 |
|
| 380 |
void reloadtpi(void) { |
| 381 |
char s[300],*p; |
| 382 |
if(treatmode==TREAT_PLUGIN) { |
| 383 |
if((p=loadtpi())) { |
| 384 |
sprintf(s,"Error loading custom plug-in\n%.200s",p); |
| 385 |
reperr(s); |
| 386 |
} |
| 387 |
} |
| 388 |
else unloadtpi(); |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
static int offsetenc(int c0,int c1) { |
| 394 |
int g0,g1,n,u; |
| 395 |
g0=iccusedtogroup[c0]; |
| 396 |
g1=iccusedtogroup[c1]; |
| 397 |
if(g0<0||g0>1||g1<0||g1>1) return c0; |
| 398 |
u=iccgroupstart[g0]; |
| 399 |
n=iccgroupstart[g0+1]-u; |
| 400 |
assert(n>0); |
| 401 |
return u+(c0-u+c1-iccgroupstart[g1])%n; |
| 402 |
} |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
static int treatans(const char*s) { |
| 407 |
int c0,c1,c2,d0,d1,g,i,j,l,l0,l1,o,u; |
| 408 |
char ansutf8[MXFL*8],*p; |
| 409 |
uchar ansU[MXFL+1]; |
| 410 |
char t[MXLE+2]; |
| 411 |
l=strlen(s); |
| 412 |
|
| 413 |
for(i=0;s[i];i++) if(s[i]>=MAXICC) return 0; |
| 414 |
switch(treatmode) { |
| 415 |
case 0: |
| 416 |
return treatedanswerICC(s); |
| 417 |
case 1: |
| 418 |
if(l!=lightlength) return 0; |
| 419 |
strcpy(t,s); |
| 420 |
for(i=0;i<l-1;i+=2) { |
| 421 |
c0=s[i];c1=s[i+1]; |
| 422 |
l0=psc[c0];l1=psc[c1]; |
| 423 |
if(l0==-1||l1==-1) continue; |
| 424 |
if(l0==l1) continue; |
| 425 |
if (l0/5==l1/5) d0=psq[ l0/5 *5+(l0+1)%5],d1=psq[ l1/5 *5+(l1+1)%5]; |
| 426 |
else if(l0%5==l1%5) d0=psq[(l0/5+1)%5*5+ l0 %5],d1=psq[(l1/5+1)%5*5+ l1 %5]; |
| 427 |
else d0=psq[ l0/5 *5+ l1 %5],d1=psq[ l1/5 *5+ l0 %5]; |
| 428 |
if(d0!=0&&d1!=0) t[i]=d0,t[i+1]=d1; |
| 429 |
} |
| 430 |
return treatedanswerICC(t); |
| 431 |
case 2: |
| 432 |
if(l!=lightlength) return 0; |
| 433 |
l0=strlen(treatmsgICC[0]); |
| 434 |
strcpy(t,s); |
| 435 |
for(i=0;s[i];i++) { |
| 436 |
c0=icctousedindex[(int)s[i]]; |
| 437 |
if(c0<0) continue; |
| 438 |
g=iccusedtogroup[c0]; |
| 439 |
if(g<0||g>1) continue; |
| 440 |
j=c0-iccgroupstart[g]; |
| 441 |
if(j>=l0) continue; |
| 442 |
t[i]=treatmsgICC[0][j]; |
| 443 |
} |
| 444 |
return treatedanswerICC(t); |
| 445 |
case 3: e |
| 446 |
if(l!=lightlength) return 0; |
| 447 |
l0=strlen(treatmsgICC[0]); |
| 448 |
if(l0==0) return treatedanswerICC(s); |
| 449 |
if(niccused<1) return treatedanswerICC(s); |
| 450 |
strcpy(t,s); |
| 451 |
for(i=0;s[i];i++) { |
| 452 |
c0=icctousedindex[(int)s[i]]; |
| 453 |
c1=icctousedindex[(int)treatmsgICC[0][i%l0]]; |
| 454 |
if(c0>=0&&c1>=0) t[i]=iccused[offsetenc(c0,c1)]; |
| 455 |
} |
| 456 |
return treatedanswerICC(t); |
| 457 |
case 4: |
| 458 |
if(l!=lightlength) return 0; |
| 459 |
if(niccused<1) return treatedanswerICC(s); |
| 460 |
if(treatorder[0]==0) { |
| 461 |
l0=strlen(treatmsgICC[0]); |
| 462 |
if(l0==0) return treatedanswerICC(s); |
| 463 |
o=treatmsgICC[0][clueorderindex%l0]; |
| 464 |
} else { |
| 465 |
o=msgcharICC[0]; |
| 466 |
if(o==ICC_DASH) return treatedanswerICC(s); |
| 467 |
} |
| 468 |
c1=icctousedindex[o]; |
| 469 |
if(c1<0) return treatedanswerICC(s); |
| 470 |
strcpy(t,s); |
| 471 |
for(i=0;s[i];i++) { |
| 472 |
c0=icctousedindex[(int)s[i]]; |
| 473 |
if(c0>=0) t[i]=iccused[offsetenc(c0,c1)]; |
| 474 |
} |
| 475 |
return treatedanswerICC(t); |
| 476 |
case 10: |
| 477 |
if(l!=lightlength) return 0; |
| 478 |
c0=msgcharICC[0]; |
| 479 |
if(c0==ICC_DASH) return treatedanswerICC(s); |
| 480 |
c1=0; |
| 481 |
goto misp0; |
| 482 |
case 11: |
| 483 |
if(l!=lightlength) return 0; |
| 484 |
c1=msgcharICC[0]; |
| 485 |
if(c1==ICC_DASH) return treatedanswerICC(s); |
| 486 |
c0=0; |
| 487 |
goto misp0; |
| 488 |
case 5: |
| 489 |
if(l!=lightlength) return 0; |
| 490 |
l0=ucharslen(treatmsgU[0]); |
| 491 |
l1=ucharslen(treatmsgU[1]); |
| 492 |
c0=0; if(clueorderindex<l0) c0=uchartoICC(treatmsgU[0][clueorderindex]); |
| 493 |
c1=0; if(clueorderindex<l1) c1=uchartoICC(treatmsgU[1][clueorderindex]); |
| 494 |
if(c0==0&&c1==0) return treatedanswerICC(s); |
| 495 |
misp0: |
| 496 |
strcpy(t,s); |
| 497 |
for(i=0;s[i];i++) if(c0==0||s[i]==c0) { |
| 498 |
if(c1==0) { |
| 499 |
for(j=0;j<niccused;j++) { |
| 500 |
c2=iccused[j]; |
| 501 |
if(s[i]==c2) continue; |
| 502 |
t[i]=c2; |
| 503 |
u=treatedanswerICC(t); if(u) return u; |
| 504 |
t[i]=s[i]; |
| 505 |
} |
| 506 |
} else { |
| 507 |
if(c0==0&&s[i]==c1) continue; |
| 508 |
t[i]=c1; |
| 509 |
u=treatedanswerICC(t); if(u) return u; |
| 510 |
t[i]=s[i]; |
| 511 |
if(c0==c1) break; |
| 512 |
} |
| 513 |
} |
| 514 |
return 0; |
| 515 |
case 6: |
| 516 |
c0=msgcharICC[0]; |
| 517 |
if(c0==ICC_DASH) { |
| 518 |
if(l==lightlength) return treatedanswerICC(s); |
| 519 |
return 0; |
| 520 |
} |
| 521 |
if(l!=lightlength+1) return 0; |
| 522 |
for(i=0;s[i];i++) if(s[i]==c0) { |
| 523 |
for(j=0;j<i;j++) t[j]=s[j]; |
| 524 |
for(;s[j+1];j++) t[j]=s[j+1]; |
| 525 |
t[j]=0; |
| 526 |
u=treatedanswerICC(t); if(u) return u; |
| 527 |
while(s[i+1]==c0) i++; |
| 528 |
} |
| 529 |
return 0; |
| 530 |
case 7: |
| 531 |
c0=msgcharICC[0]; |
| 532 |
if(c0==ICC_DASH) { |
| 533 |
if(l==lightlength) return treatedanswerICC(s); |
| 534 |
return 0; |
| 535 |
} |
| 536 |
if(l<=lightlength) return 0; |
| 537 |
for(i=0,j=0;s[i];i++) if(s[i]!=c0) t[j++]=s[i]; |
| 538 |
t[j]=0; |
| 539 |
if(j!=lightlength) return 0; |
| 540 |
return treatedanswerICC(t); |
| 541 |
case 8: |
| 542 |
c0=msgcharICC[0]; |
| 543 |
if(c0==ICC_DASH) { |
| 544 |
if(l==lightlength) return treatedanswerICC(s); |
| 545 |
return 0; |
| 546 |
} |
| 547 |
if(l!=lightlength-1) return 0; |
| 548 |
for(i=0;i<=l;i++) { |
| 549 |
for(j=0;j<i;j++) t[j]=s[j]; |
| 550 |
t[j++]=c0; |
| 551 |
for(;s[j-1];j++) t[j]=s[j-1]; |
| 552 |
t[j]=0; |
| 553 |
u=treatedanswerICC(t); if(u) return u; |
| 554 |
while(s[i]==c0) i++; |
| 555 |
} |
| 556 |
return 0; |
| 557 |
case 9: |
| 558 |
answerICC=s; |
| 559 |
for(i=0,p=ansutf8;s[i];i++) strcpy(p,icctoutf8[(int)s[i]]),p+=strlen(p),ansU[i]=icctouchar[(int)s[i]]; |
| 560 |
ansU[i]=0; |
| 561 |
answerU=ansU; |
| 562 |
DEB_TR printf("ansutf8=>%s<\n",ansutf8); |
| 563 |
if(treatf) return (*treatf)(ansutf8); |
| 564 |
return 1; |
| 565 |
default:break; |
| 566 |
} |
| 567 |
return 0; |
| 568 |
} |
| 569 |
|
| 570 |
int pregetinitflist(void) { |
| 571 |
int i; |
| 572 |
struct memblk*p; |
| 573 |
while(lstrings) {p=lstrings->next;free(lstrings);lstrings=p;} lmp=0; lml=MEMBLK; |
| 574 |
FREEX(tfl);ctfl=0;ntfl=0; |
| 575 |
FREEX(lts);clts=0;ltotal=0;ultotal=0; |
| 576 |
for(i=0;i<HTABSZ;i++) hstab[i]=-1,haestab[i]=-1; |
| 577 |
if(inittreat()) return 1; |
| 578 |
return 0; |
| 579 |
} |
| 580 |
|
| 581 |
|
| 582 |
int postgetinitflist(void) { |
| 583 |
finittreat(); |
| 584 |
FREEX(tfl);ctfl=0; |
| 585 |
return 0; |
| 586 |
} |
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
int getinitflist(int**l,int*ll,struct lprop*lp,int llen) { |
| 592 |
int g,i,j,u; |
| 593 |
ABM mfl[NMSG],ml[NMSG],b; |
| 594 |
|
| 595 |
ntfl=0; |
| 596 |
curdm=lp->dmask,curem=lp->emask,curten=lp->ten; |
| 597 |
for(i=0;i<NMSG;i++) if(curdm&(1<<(MAXNDICTS+i))) { |
| 598 |
DEB_FL { |
| 599 |
printf("msgword[%d]=<",i); |
| 600 |
printICCs(msgword[i]); |
| 601 |
printf(">\n"); |
| 602 |
} |
| 603 |
u=addlight(msgword[i],-1-i,0); |
| 604 |
if(u) return u; |
| 605 |
goto ex0; |
| 606 |
} |
| 607 |
if((curem&EM_ALL)==0) curem=EM_FWD; |
| 608 |
lightlength=llen; |
| 609 |
DEB_FL printf("getinitflist(%p) llen=%d dmask=%08x emask=%08x ten=%d:\n",(void*)lp,llen,curdm,curem,curten); |
| 610 |
memset(mfl,0,sizeof(mfl)); |
| 611 |
for(i=0;i<NMSG;i++) { |
| 612 |
if(clueorderindex<(int)strlen(treatmsg [i])) msgchar [i]=treatmsg [i][clueorderindex]; else msgchar [i]='-'; |
| 613 |
if(clueorderindex< ucharslen(treatmsgU [i])) msgcharU [i]=treatmsgU [i][clueorderindex]; else msgcharU [i]='-'; |
| 614 |
if(clueorderindex< ucharslen(treatmsgUAZ [i])) msgcharUAZ [i]=treatmsgUAZ [i][clueorderindex]; else msgcharUAZ [i]='-'; |
| 615 |
if(clueorderindex< ucharslen(treatmsgUAZ09 [i])) msgcharUAZ09 [i]=treatmsgUAZ09 [i][clueorderindex]; else msgcharUAZ09 [i]='-'; |
| 616 |
if(clueorderindex<(int)strlen(treatmsgICC [i])) msgcharICC [i]=treatmsgICC [i][clueorderindex]; else msgcharICC [i]=ICC_DASH; |
| 617 |
if(clueorderindex<(int)strlen(treatmsgICCAZ [i])) msgcharICCAZ [i]=treatmsgICCAZ [i][clueorderindex]; else msgcharICCAZ [i]=ICC_DASH; |
| 618 |
if(clueorderindex<(int)strlen(treatmsgICCAZ09[i])) msgcharICCAZ09[i]=treatmsgICCAZ09[i][clueorderindex]; else msgcharICCAZ09[i]=ICC_DASH; |
| 619 |
if(clueorderindex<(int)strlen(treatmsgAZ [i])) msgcharAZ [i]=treatmsgAZ [i][clueorderindex]; else msgcharAZ [i]='-'; |
| 620 |
if(clueorderindex<(int)strlen(treatmsgAZ09 [i])) msgcharAZ09 [i]=treatmsgAZ09 [i][clueorderindex]; else msgcharAZ09 [i]='-'; |
| 621 |
if(curten&&treatorder[i]>0) { |
| 622 |
for(j=0;treatmsgICC[i][j];j++) mfl[i]|=ICCTOABM((int)treatmsgICC[i][j]); |
| 623 |
if(ntw>(int)strlen(treatmsgICC[i])) mfl[i]|=ABM_DASH; |
| 624 |
if(clueorderindex<MXFL) mfl[i]&=treatcstr[i][clueorderindex]; |
| 625 |
ml[i]=mfl[i]&~(mfl[i]-1); |
| 626 |
if(ml[i]==0) goto ex0; |
| 627 |
} |
| 628 |
} |
| 629 |
for(;;) { |
| 630 |
for(i=0;i<NMSG;i++) if(curten&&treatorder[i]>0) { |
| 631 |
j=abmtoicc(ml[i]); |
| 632 |
u=icctouchar[j]; |
| 633 |
msgcharICC[i]=j; |
| 634 |
msgcharU[i]=u; |
| 635 |
g=icctogroup[j]; |
| 636 |
if((g==0||g==1)&&u<128) msgcharAZ09[i]=u; |
| 637 |
else msgcharAZ09[i]='-'; |
| 638 |
} |
| 639 |
DEB_FL { printf(" building list with msgcharICC[]="); for(i=0;i<NMSG;i++) printf("%s",icctoutf8[(int)msgcharICC[i]]); printf("\n"); } |
| 640 |
for(i=0;i<atotal;i++) { |
| 641 |
curans=i; |
| 642 |
if((curdm&ansp[curans]->dmask)==0) continue; |
| 643 |
if(ansp[curans]->banned) continue; |
| 644 |
if(curten) u=treatans(ansp[curans]->ul); |
| 645 |
else u=treatedanswerICC(ansp[curans]->ul); |
| 646 |
if(u) return u; |
| 647 |
if(abort_flag) return -5; |
| 648 |
} |
| 649 |
for(i=0;i<NMSG;i++) if(curten&&treatorder[i]>0) { |
| 650 |
b=mfl[i]&~(ml[i]|(ml[i]-1)); |
| 651 |
b&=~(b-1); |
| 652 |
if(b) {ml[i]=b; break;} |
| 653 |
ml[i]=mfl[i]&~(mfl[i]-1); |
| 654 |
} |
| 655 |
if(i==NMSG) break; |
| 656 |
} |
| 657 |
ex0: |
| 658 |
*l=malloc(ntfl*sizeof(int)+1); |
| 659 |
if(*l==0) return 1; |
| 660 |
memcpy(*l,tfl,ntfl*sizeof(int)); |
| 661 |
*ll=ntfl; |
| 662 |
DEB_FL printf("%d entries\n",ntfl); |
| 663 |
return 0; |
| 664 |
} |