| 1 |
#ifdef RCSID |
| 2 |
static char RCSid[] = |
| 3 |
"$Header: d:/cvsroot/tads/TADS2/VOC.C,v 1.4 1999/07/11 00:46:31 MJRoberts Exp $"; |
| 4 |
#endif |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include <ctype.h> |
| 25 |
#include <string.h> |
| 26 |
|
| 27 |
#include "os.h" |
| 28 |
#include "std.h" |
| 29 |
#include "mch.h" |
| 30 |
#include "mcm.h" |
| 31 |
#include "voc.h" |
| 32 |
#include "prp.h" |
| 33 |
#include "obj.h" |
| 34 |
#include "err.h" |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
voccxdef *main_voc_ctx = 0; |
| 43 |
|
| 44 |
|
| 45 |
#ifdef VOCW_IN_CACHE |
| 46 |
vocwdef *vocwget(voccxdef *ctx, uint idx) |
| 47 |
{ |
| 48 |
uint pg; |
| 49 |
|
| 50 |
if (idx == VOCCXW_NONE) |
| 51 |
return 0; |
| 52 |
|
| 53 |
|
| 54 |
pg = idx/VOCWPGSIZ; |
| 55 |
|
| 56 |
|
| 57 |
if (pg != ctx->voccxwplck) |
| 58 |
{ |
| 59 |
|
| 60 |
if (ctx->voccxwplck != MCMONINV) |
| 61 |
mcmunlck(ctx->voccxmem, ctx->voccxwp[ctx->voccxwplck]); |
| 62 |
|
| 63 |
|
| 64 |
ctx->voccxwpgptr = (vocwdef *)mcmlck(ctx->voccxmem, |
| 65 |
ctx->voccxwp[pg]); |
| 66 |
ctx->voccxwplck = pg; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
return ctx->voccxwpgptr + (idx % VOCWPGSIZ); |
| 71 |
} |
| 72 |
#endif |
| 73 |
|
| 74 |
|
| 75 |
uint vochsh(uchar *t, int len) |
| 76 |
{ |
| 77 |
uint ret = 0; |
| 78 |
|
| 79 |
if (len > 6) len = 6; |
| 80 |
for ( ; len ; --len, ++t) |
| 81 |
ret = (ret + (uint)(vocisupper(*t) ? tolower(*t) : *t)) |
| 82 |
& (VOCHASHSIZ - 1); |
| 83 |
return(ret); |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
static void voccpy(uchar *dst, uchar *src, int len) |
| 88 |
{ |
| 89 |
for ( ; len ; --len, ++dst, ++src) |
| 90 |
*dst = vocisupper(*src) ? tolower(*src) : *src; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
static void vocwset(voccxdef *ctx, vocdef *v, prpnum p, objnum objn, |
| 95 |
int classflg) |
| 96 |
{ |
| 97 |
vocwdef *vw; |
| 98 |
uint inx; |
| 99 |
vocwdef *vw2; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
for (inx = v->vocwlst, vw = vocwget(ctx, inx) ; vw ; |
| 106 |
inx = vw->vocwnxt, vw = vocwget(ctx, inx)) |
| 107 |
{ |
| 108 |
|
| 109 |
if ((vw->vocwflg & VOCFDEL) |
| 110 |
&& vw->vocwobj == objn && vw->vocwtyp == p) |
| 111 |
{ |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
vw->vocwflg &= ~VOCFDEL; |
| 119 |
|
| 120 |
|
| 121 |
return; |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
for (inx = v->vocwlst, vw = vocwget(ctx, inx) ; vw ; |
| 127 |
inx = vw->vocwnxt, vw = vocwget(ctx, inx)) |
| 128 |
{ |
| 129 |
if (vw->vocwobj == objn && vw->vocwtyp == p |
| 130 |
&& (vw->vocwflg & VOCFCLASS) == (classflg & VOCFCLASS)) |
| 131 |
{ |
| 132 |
|
| 133 |
return; |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
if (ctx->voccxwfre != VOCCXW_NONE) |
| 139 |
{ |
| 140 |
inx = ctx->voccxwfre; |
| 141 |
vw = vocwget(ctx, inx); |
| 142 |
ctx->voccxwfre = vw->vocwnxt; |
| 143 |
} |
| 144 |
else |
| 145 |
{ |
| 146 |
|
| 147 |
if ((ctx->voccxwalocnt % VOCWPGSIZ) == 0) |
| 148 |
{ |
| 149 |
int pg = ctx->voccxwalocnt / VOCWPGSIZ; |
| 150 |
|
| 151 |
|
| 152 |
if (pg >= VOCWPGMAX) errsig(ctx->voccxerr, ERR_VOCMNPG); |
| 153 |
|
| 154 |
|
| 155 |
#ifdef VOCW_IN_CACHE |
| 156 |
mcmalo(ctx->voccxmem, (ushort)(VOCWPGSIZ * sizeof(vocwdef)), |
| 157 |
&ctx->voccxwp[pg]); |
| 158 |
mcmunlck(ctx->voccxmem, ctx->voccxwp[pg]); |
| 159 |
#else |
| 160 |
ctx->voccxwp[pg] = |
| 161 |
(vocwdef *)mchalo(ctx->voccxerr, |
| 162 |
(VOCWPGSIZ * sizeof(vocwdef)), |
| 163 |
"vocwset"); |
| 164 |
#endif |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
inx = ctx->voccxwalocnt++; |
| 169 |
vw = vocwget(ctx, inx); |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
vw->vocwnxt = v->vocwlst; |
| 174 |
v->vocwlst = inx; |
| 175 |
|
| 176 |
|
| 177 |
vw->vocwtyp = (uchar)p; |
| 178 |
vw->vocwobj = objn; |
| 179 |
vw->vocwflg = classflg; |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
if (p == PRP_VERB && (ctx->voccxflg & VOCCXFVWARN) |
| 186 |
&& (vw->vocwflg & VOCFCLASS) == 0) |
| 187 |
{ |
| 188 |
for (vw2 = vocwget(ctx, v->vocwlst) ; vw2 ; |
| 189 |
vw2 = vocwget(ctx, vw2->vocwnxt)) |
| 190 |
{ |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
if (vw2 != vw |
| 196 |
&& (vw2->vocwflg & VOCFCLASS) == 0 |
| 197 |
&& vw2->vocwtyp == PRP_VERB) |
| 198 |
{ |
| 199 |
if (v->vocln2 != 0) |
| 200 |
errlog2(ctx->voccxerr, ERR_VOCREVB, |
| 201 |
ERRTSTR, |
| 202 |
errstr(ctx->voccxerr, |
| 203 |
(char *)v->voctxt, v->voclen), |
| 204 |
ERRTSTR, |
| 205 |
errstr(ctx->voccxerr, |
| 206 |
(char *)v->voctxt + v->voclen, v->vocln2)); |
| 207 |
else |
| 208 |
errlog1(ctx->voccxerr, ERR_VOCREVB, |
| 209 |
ERRTSTR, |
| 210 |
errstr(ctx->voccxerr, |
| 211 |
(char *)v->voctxt, v->voclen)); |
| 212 |
break; |
| 213 |
} |
| 214 |
} |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
static void vocset(voccxdef *ctx, vocdef *v, prpnum p, objnum objn, |
| 220 |
int classflg, uchar *wrdtxt, int len, |
| 221 |
uchar *wrd2, int len2) |
| 222 |
{ |
| 223 |
uint hshval = vochsh(wrdtxt, len); |
| 224 |
|
| 225 |
v->vocnxt = ctx->voccxhsh[hshval]; |
| 226 |
ctx->voccxhsh[hshval] = v; |
| 227 |
|
| 228 |
v->voclen = len; |
| 229 |
v->vocln2 = len2; |
| 230 |
voccpy(v->voctxt, wrdtxt, len); |
| 231 |
if (wrd2) voccpy(v->voctxt + len, wrd2, len2); |
| 232 |
|
| 233 |
|
| 234 |
vocwset(ctx, v, p, objn, classflg); |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
void vocadd2(voccxdef *ctx, prpnum p, objnum objn, int classflg, |
| 239 |
uchar *wrdtxt, int len, uchar *wrd2, int len2) |
| 240 |
{ |
| 241 |
vocdef *v; |
| 242 |
vocdef *prv; |
| 243 |
uint need; |
| 244 |
uint hshval; |
| 245 |
|
| 246 |
|
| 247 |
if (len == 0 && len2 == 0) |
| 248 |
return; |
| 249 |
|
| 250 |
|
| 251 |
hshval = vochsh(wrdtxt, len); |
| 252 |
for (v = ctx->voccxhsh[hshval] ; v ; v = v->vocnxt) |
| 253 |
{ |
| 254 |
|
| 255 |
if (v->voclen == len && !memcmp(wrdtxt, v->voctxt, (size_t)len) |
| 256 |
&& ((!wrd2 && v->vocln2 == 0) |
| 257 |
|| (v->vocln2 == len2 && |
| 258 |
!memcmp(wrd2, v->voctxt + len, (size_t)len2)))) |
| 259 |
{ |
| 260 |
vocwset(ctx, v, p, objn, classflg); |
| 261 |
return; |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
for (prv = (vocdef *)0, v = ctx->voccxfre ; v ; prv = v, v = v->vocnxt) |
| 267 |
if (v->voclen == len + len2) break; |
| 268 |
|
| 269 |
if (v) |
| 270 |
{ |
| 271 |
|
| 272 |
if (prv) prv->vocnxt = v->vocnxt; |
| 273 |
else ctx->voccxfre = v->vocnxt; |
| 274 |
|
| 275 |
|
| 276 |
v->vocwlst = VOCCXW_NONE; |
| 277 |
vocset(ctx, v, p, objn, classflg, wrdtxt, len, wrd2, len2); |
| 278 |
return; |
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
need = sizeof(vocdef) + len + len2 - 1; |
| 283 |
if (ctx->voccxrem < need) |
| 284 |
{ |
| 285 |
|
| 286 |
ctx->voccxpool = mchalo(ctx->voccxerr, VOCPGSIZ, "vocadd2"); |
| 287 |
ctx->voccxrem = VOCPGSIZ; |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
v = (vocdef *)ctx->voccxpool; |
| 292 |
need = osrndsz(need); |
| 293 |
ctx->voccxpool += need; |
| 294 |
if (ctx->voccxrem > need) ctx->voccxrem -= need; |
| 295 |
else ctx->voccxrem = 0; |
| 296 |
|
| 297 |
|
| 298 |
v->vocwlst = VOCCXW_NONE; |
| 299 |
vocset(ctx, v, p, objn, classflg, wrdtxt, len, wrd2, len2); |
| 300 |
} |
| 301 |
|
| 302 |
static void voc_parse_words(char **wrdtxt, int *len, char **wrd2, int *len2) |
| 303 |
{ |
| 304 |
|
| 305 |
*len = osrp2(*wrdtxt) - 2; |
| 306 |
*wrdtxt += 2; |
| 307 |
|
| 308 |
|
| 309 |
for (*wrd2 = *wrdtxt, *len2 = *len ; *len2 && !vocisspace(**wrd2) ; |
| 310 |
++*wrd2, --*len2) ; |
| 311 |
if (*len2) |
| 312 |
{ |
| 313 |
*len -= *len2; |
| 314 |
while (*len2 && vocisspace(**wrd2)) ++*wrd2, --*len2; |
| 315 |
} |
| 316 |
else |
| 317 |
{ |
| 318 |
|
| 319 |
*wrd2 = (char *)0; |
| 320 |
} |
| 321 |
} |
| 322 |
|
| 323 |
void vocadd(voccxdef *ctx, prpnum p, objnum objn, int classflg, char *wrdtxt) |
| 324 |
{ |
| 325 |
int len; |
| 326 |
char *wrd2; |
| 327 |
int len2; |
| 328 |
|
| 329 |
voc_parse_words(&wrdtxt, &len, &wrd2, &len2); |
| 330 |
vocadd2(ctx, p, objn, classflg, (uchar *)wrdtxt, len, (uchar *)wrd2, len2); |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
void vocialo(voccxdef *ctx, objnum obj) |
| 335 |
{ |
| 336 |
if (!ctx->voccxinh[obj >> 8]) |
| 337 |
{ |
| 338 |
ctx->voccxinh[obj >> 8] = |
| 339 |
(vocidef **)mchalo(ctx->voccxerr, |
| 340 |
(256 * sizeof(vocidef *)), "vocialo"); |
| 341 |
memset(ctx->voccxinh[obj >> 8], 0, (size_t)(256 * sizeof(vocidef *))); |
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
|
| 346 |
void vociadd(voccxdef *ctx, objnum obj, objnum loc, |
| 347 |
int numsc, objnum *sc, int flags) |
| 348 |
{ |
| 349 |
vocidef *v; |
| 350 |
vocidef *min; |
| 351 |
vocidef *prv; |
| 352 |
vocidef *minprv; |
| 353 |
|
| 354 |
|
| 355 |
vocialo(ctx, obj); |
| 356 |
|
| 357 |
|
| 358 |
for (prv = (vocidef *)0, min = (vocidef *)0, v = ctx->voccxifr ; v ; |
| 359 |
prv = v, v = v->vocinxt) |
| 360 |
{ |
| 361 |
if (v->vocinsc == numsc) |
| 362 |
{ |
| 363 |
min = v; |
| 364 |
minprv = prv; |
| 365 |
break; |
| 366 |
} |
| 367 |
else if (v->vocinsc > numsc) |
| 368 |
{ |
| 369 |
if (!min || v->vocinsc < min->vocinsc) |
| 370 |
{ |
| 371 |
min = v; |
| 372 |
minprv = prv; |
| 373 |
} |
| 374 |
} |
| 375 |
} |
| 376 |
|
| 377 |
if (!min) |
| 378 |
{ |
| 379 |
uint need; |
| 380 |
|
| 381 |
|
| 382 |
need = osrndsz(sizeof(vocidef) + (numsc - 1)*sizeof(objnum)); |
| 383 |
if (ctx->voccxilst + need >= VOCISIZ) |
| 384 |
{ |
| 385 |
|
| 386 |
ctx->voccxip[++(ctx->voccxiplst)] = |
| 387 |
mchalo(ctx->voccxerr, VOCISIZ, "vociadd"); |
| 388 |
ctx->voccxilst = 0; |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
v = (vocidef *)(ctx->voccxip[ctx->voccxiplst] + ctx->voccxilst); |
| 393 |
ctx->voccxilst += need; |
| 394 |
} |
| 395 |
else |
| 396 |
{ |
| 397 |
|
| 398 |
v = min; |
| 399 |
if (minprv) |
| 400 |
minprv->vocinxt = v->vocinxt; |
| 401 |
else |
| 402 |
ctx->voccxifr = v->vocinxt; |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
if (vocinh(ctx, obj) != (vocidef *)0) errsig(ctx->voccxerr, ERR_VOCINUS); |
| 407 |
v->vociloc = loc; |
| 408 |
v->vociilc = MCMONINV; |
| 409 |
v->vociflg = (flags & ~VOCIFXLAT); |
| 410 |
v->vocinsc = numsc; |
| 411 |
if (numsc) |
| 412 |
{ |
| 413 |
if (flags & VOCIFXLAT) |
| 414 |
{ |
| 415 |
int i; |
| 416 |
|
| 417 |
for (i = 0 ; i < numsc ; ++i) |
| 418 |
v->vocisc[i] = osrp2(&sc[i]); |
| 419 |
} |
| 420 |
else |
| 421 |
memcpy(v->vocisc, sc, (size_t)(numsc * sizeof(objnum))); |
| 422 |
} |
| 423 |
vocinh(ctx, obj) = v; |
| 424 |
} |
| 425 |
|
| 426 |
|
| 427 |
void vocrevert(voccxdef *vctx) |
| 428 |
{ |
| 429 |
vocidef ***vpg; |
| 430 |
vocidef **v; |
| 431 |
int i; |
| 432 |
int j; |
| 433 |
objnum obj; |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
for (vpg = vctx->voccxinh, i = 0 ; i < VOCINHMAX ; ++vpg, ++i) |
| 441 |
{ |
| 442 |
if (!*vpg) continue; |
| 443 |
for (v = *vpg, obj = (i << 8), j = 0 ; j < 256 ; ++v, ++obj, ++j) |
| 444 |
{ |
| 445 |
if (*v) |
| 446 |
{ |
| 447 |
|
| 448 |
if ((*v)->vociflg & VOCIFNEW) |
| 449 |
{ |
| 450 |
|
| 451 |
vocidel(vctx, obj); |
| 452 |
vocdel(vctx, obj); |
| 453 |
|
| 454 |
|
| 455 |
mcmfre(vctx->voccxmem, (mcmon)obj); |
| 456 |
} |
| 457 |
else |
| 458 |
{ |
| 459 |
|
| 460 |
mcmrevert(vctx->voccxmem, (mcmon)obj); |
| 461 |
} |
| 462 |
} |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
vocdel1(vctx, MCMONINV, (char *)0, 0, TRUE, TRUE, FALSE); |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
void vocini(voccxdef *vocctx, errcxdef *errctx, mcmcxdef *memctx, |
| 475 |
runcxdef *runctx, objucxdef *undoctx, |
| 476 |
int fuses, int daemons, int notifiers) |
| 477 |
{ |
| 478 |
CLRSTRUCT(*vocctx); |
| 479 |
vocctx->voccxerr = errctx; |
| 480 |
vocctx->voccxiplst = (uint)-1; |
| 481 |
vocctx->voccxilst = VOCISIZ; |
| 482 |
vocctx->voccxmem = memctx; |
| 483 |
vocctx->voccxrun = runctx; |
| 484 |
vocctx->voccxundo = undoctx; |
| 485 |
|
| 486 |
vocctx->voccxme = |
| 487 |
vocctx->voccxme_init = |
| 488 |
vocctx->voccxvtk = |
| 489 |
vocctx->voccxstr = |
| 490 |
vocctx->voccxnum = |
| 491 |
vocctx->voccxit = |
| 492 |
vocctx->voccxhim = |
| 493 |
vocctx->voccxprd = |
| 494 |
vocctx->voccxpre = |
| 495 |
vocctx->voccxpre2 = |
| 496 |
vocctx->voccxppc = |
| 497 |
vocctx->voccxlsv = |
| 498 |
vocctx->voccxpreinit = |
| 499 |
vocctx->voccxper = |
| 500 |
vocctx->voccxprom = |
| 501 |
vocctx->voccxpostprom = |
| 502 |
vocctx->voccxpdis = |
| 503 |
vocctx->voccxper2 = |
| 504 |
vocctx->voccxperp = |
| 505 |
vocctx->voccxpdef = |
| 506 |
vocctx->voccxpdef2 = |
| 507 |
vocctx->voccxpask = |
| 508 |
vocctx->voccxpask2 = |
| 509 |
vocctx->voccxpask3 = |
| 510 |
vocctx->voccxinitrestore = |
| 511 |
vocctx->voccxpuv = |
| 512 |
vocctx->voccxpnp = |
| 513 |
vocctx->voccxpostact = |
| 514 |
vocctx->voccxendcmd = |
| 515 |
vocctx->voccxher = MCMONINV; |
| 516 |
vocctx->voccxthc = 0; |
| 517 |
#ifdef VOCW_IN_CACHE |
| 518 |
vocctx->voccxwplck = MCMONINV; |
| 519 |
#endif |
| 520 |
|
| 521 |
vocctx->voccxactor = MCMONINV; |
| 522 |
vocctx->voccxverb = MCMONINV; |
| 523 |
vocctx->voccxprep = MCMONINV; |
| 524 |
vocctx->voccxdobj = 0; |
| 525 |
vocctx->voccxiobj = 0; |
| 526 |
|
| 527 |
vocctx->voccxunknown = 0; |
| 528 |
vocctx->voccxlastunk = 0; |
| 529 |
|
| 530 |
vocctx->voc_stk_ptr = 0; |
| 531 |
vocctx->voc_stk_cur = 0; |
| 532 |
vocctx->voc_stk_end = 0; |
| 533 |
|
| 534 |
|
| 535 |
vocinialo(vocctx, &vocctx->voccxfus, (vocctx->voccxfuc = fuses)); |
| 536 |
vocinialo(vocctx, &vocctx->voccxdmn, (vocctx->voccxdmc = daemons)); |
| 537 |
vocinialo(vocctx, &vocctx->voccxalm, (vocctx->voccxalc = notifiers)); |
| 538 |
|
| 539 |
|
| 540 |
vocctx->voccxwfre = VOCCXW_NONE; |
| 541 |
} |
| 542 |
|
| 543 |
|
| 544 |
void vocterm(voccxdef *ctx) |
| 545 |
{ |
| 546 |
|
| 547 |
voctermfree(ctx->voccxfus); |
| 548 |
voctermfree(ctx->voccxdmn); |
| 549 |
voctermfree(ctx->voccxalm); |
| 550 |
|
| 551 |
|
| 552 |
if (ctx->voc_stk_ptr != 0) |
| 553 |
mchfre(ctx->voc_stk_ptr); |
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
void voctermfree(vocddef *what) |
| 558 |
{ |
| 559 |
if (what != 0) |
| 560 |
mchfre(what); |
| 561 |
} |
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
void voc_iterate(voccxdef *ctx, objnum objn, |
| 569 |
void (*fn)(void *, vocdef *, vocwdef *), void *fnctx) |
| 570 |
{ |
| 571 |
int i; |
| 572 |
vocdef *v; |
| 573 |
vocdef **vp; |
| 574 |
vocwdef *vw; |
| 575 |
uint idx; |
| 576 |
|
| 577 |
|
| 578 |
for (i = VOCHASHSIZ, vp = ctx->voccxhsh ; i ; ++vp, --i) |
| 579 |
{ |
| 580 |
|
| 581 |
for (v = *vp ; v ; v = v->vocnxt) |
| 582 |
{ |
| 583 |
|
| 584 |
for (idx = v->vocwlst, vw = vocwget(ctx, idx) ; vw ; |
| 585 |
idx = vw->vocwnxt, vw = vocwget(ctx, idx)) |
| 586 |
{ |
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
if (objn == MCMONINV || vw->vocwobj == objn) |
| 591 |
(*fn)(fnctx, v, vw); |
| 592 |
} |
| 593 |
} |
| 594 |
} |
| 595 |
} |
| 596 |
|
| 597 |
|
| 598 |
struct voc_count_ctx |
| 599 |
{ |
| 600 |
int cnt; |
| 601 |
int siz; |
| 602 |
prpnum prp; |
| 603 |
}; |
| 604 |
|
| 605 |
|
| 606 |
static void voc_count_cb(void *ctx0, vocdef *voc, vocwdef *vocw) |
| 607 |
{ |
| 608 |
struct voc_count_ctx *ctx = (struct voc_count_ctx *)ctx0; |
| 609 |
|
| 610 |
VARUSED(vocw); |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
if ((ctx->prp == 0 || ctx->prp == vocw->vocwtyp) |
| 617 |
&& !(vocw->vocwflg & VOCFDEL)) |
| 618 |
{ |
| 619 |
|
| 620 |
ctx->cnt++; |
| 621 |
|
| 622 |
|
| 623 |
ctx->siz += voc->voclen + voc->vocln2; |
| 624 |
} |
| 625 |
} |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
void voc_count(voccxdef *ctx, objnum objn, prpnum prp, int *cnt, int *siz) |
| 633 |
{ |
| 634 |
struct voc_count_ctx fnctx; |
| 635 |
|
| 636 |
|
| 637 |
fnctx.cnt = 0; |
| 638 |
fnctx.siz = 0; |
| 639 |
fnctx.prp = prp; |
| 640 |
|
| 641 |
|
| 642 |
voc_iterate(ctx, objn, voc_count_cb, &fnctx); |
| 643 |
|
| 644 |
|
| 645 |
if (cnt) *cnt = fnctx.cnt; |
| 646 |
if (siz) *siz = fnctx.siz; |
| 647 |
} |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
void vocdel1(voccxdef *ctx, objnum objn, char *wrd1, prpnum prp, |
| 661 |
int really_delete, int revert, int keep_undo) |
| 662 |
{ |
| 663 |
int i; |
| 664 |
vocdef *v; |
| 665 |
vocdef *prv; |
| 666 |
vocdef *nxt; |
| 667 |
vocdef **vp; |
| 668 |
vocwdef *vw; |
| 669 |
vocwdef *prvw; |
| 670 |
vocwdef *nxtw; |
| 671 |
uint nxtidx; |
| 672 |
uint idx; |
| 673 |
int deleted_vocdef; |
| 674 |
char *wrd2; |
| 675 |
int len1, len2; |
| 676 |
int do_del; |
| 677 |
char *orgwrd; |
| 678 |
|
| 679 |
|
| 680 |
orgwrd = wrd1; |
| 681 |
if (wrd1) |
| 682 |
voc_parse_words(&wrd1, &len1, &wrd2, &len2); |
| 683 |
|
| 684 |
|
| 685 |
for (i = VOCHASHSIZ, vp = ctx->voccxhsh ; i ; ++vp, --i) |
| 686 |
{ |
| 687 |
|
| 688 |
for (prv = (vocdef *)0, v = *vp ; v ; v = nxt) |
| 689 |
{ |
| 690 |
|
| 691 |
nxt = v->vocnxt; |
| 692 |
|
| 693 |
|
| 694 |
if (wrd1) |
| 695 |
{ |
| 696 |
|
| 697 |
if (v->voclen != len1 |
| 698 |
|| memicmp((char *)v->voctxt, wrd1, (size_t)len1)) |
| 699 |
{ |
| 700 |
prv = v; |
| 701 |
continue; |
| 702 |
} |
| 703 |
|
| 704 |
|
| 705 |
if (wrd2 && (v->vocln2 != len2 |
| 706 |
|| memicmp((char *)v->voctxt + len1, |
| 707 |
wrd2, (size_t)len2))) |
| 708 |
{ |
| 709 |
prv = v; |
| 710 |
continue; |
| 711 |
} |
| 712 |
} |
| 713 |
|
| 714 |
|
| 715 |
deleted_vocdef = FALSE; |
| 716 |
|
| 717 |
|
| 718 |
for (prvw = 0, idx = v->vocwlst, vw = vocwget(ctx, idx) ; vw ; |
| 719 |
vw = nxtw, idx = nxtidx) |
| 720 |
{ |
| 721 |
|
| 722 |
nxtidx = vw->vocwnxt; |
| 723 |
nxtw = vocwget(ctx, nxtidx); |
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
if (revert) |
| 730 |
{ |
| 731 |
|
| 732 |
do_del = (vw->vocwflg & VOCFNEW); |
| 733 |
|
| 734 |
|
| 735 |
vw->vocwflg &= ~VOCFDEL; |
| 736 |
} |
| 737 |
else |
| 738 |
{ |
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
do_del = (vw->vocwobj == objn |
| 748 |
&& (wrd1 == 0 || vw->vocwtyp == prp)); |
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
if (do_del && !really_delete && !(vw->vocwflg & VOCFNEW)) |
| 758 |
{ |
| 759 |
|
| 760 |
if (keep_undo && orgwrd) |
| 761 |
vocdusave_delwrd(ctx, objn, prp, |
| 762 |
vw->vocwflg, orgwrd); |
| 763 |
|
| 764 |
|
| 765 |
vw->vocwflg |= VOCFDEL; |
| 766 |
do_del = FALSE; |
| 767 |
} |
| 768 |
} |
| 769 |
|
| 770 |
|
| 771 |
if (do_del) |
| 772 |
{ |
| 773 |
|
| 774 |
if (keep_undo && orgwrd) |
| 775 |
vocdusave_delwrd(ctx, objn, prp, vw->vocwflg, orgwrd); |
| 776 |
|
| 777 |
|
| 778 |
if (prvw) |
| 779 |
prvw->vocwnxt = vw->vocwnxt; |
| 780 |
else |
| 781 |
v->vocwlst = vw->vocwnxt; |
| 782 |
|
| 783 |
|
| 784 |
vw->vocwnxt = ctx->voccxwfre; |
| 785 |
ctx->voccxwfre = idx; |
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
if (v->vocwlst == VOCCXW_NONE) |
| 792 |
{ |
| 793 |
if (prv) prv->vocnxt = v->vocnxt; |
| 794 |
else *vp = v->vocnxt; |
| 795 |
|
| 796 |
|
| 797 |
v->vocnxt = ctx->voccxfre; |
| 798 |
ctx->voccxfre = v; |
| 799 |
|
| 800 |
|
| 801 |
deleted_vocdef = TRUE; |
| 802 |
} |
| 803 |
} |
| 804 |
else |
| 805 |
{ |
| 806 |
|
| 807 |
prvw = vw; |
| 808 |
} |
| 809 |
} |
| 810 |
|
| 811 |
|
| 812 |
if (!deleted_vocdef) |
| 813 |
prv = v; |
| 814 |
} |
| 815 |
} |
| 816 |
} |
| 817 |
|
| 818 |
|
| 819 |
void vocdel(voccxdef *ctx, objnum objn) |
| 820 |
{ |
| 821 |
vocdel1(ctx, objn, (char *)0, (prpnum)0, TRUE, FALSE, FALSE); |
| 822 |
} |
| 823 |
|
| 824 |
|
| 825 |
void vocidel(voccxdef *ctx, objnum obj) |
| 826 |
{ |
| 827 |
vocidef *v; |
| 828 |
|
| 829 |
|
| 830 |
v = vocinh(ctx, obj); |
| 831 |
vocinh(ctx, obj) = (vocidef *)0; |
| 832 |
|
| 833 |
|
| 834 |
if (v) |
| 835 |
{ |
| 836 |
v->vocinxt = ctx->voccxifr; |
| 837 |
ctx->voccxifr = v; |
| 838 |
} |
| 839 |
} |
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
int voctplfnd(voccxdef *ctx, objnum verb_in, objnum prep, |
| 846 |
uchar *tplout, int *newstyle) |
| 847 |
{ |
| 848 |
uchar *tplptr; |
| 849 |
uchar *thistpl; |
| 850 |
int found; |
| 851 |
int tplcnt; |
| 852 |
uint tplofs; |
| 853 |
objnum verb; |
| 854 |
|
| 855 |
|
| 856 |
tplofs = objgetap(ctx->voccxmem, verb_in, PRP_TPL2, &verb, FALSE); |
| 857 |
if (tplofs) |
| 858 |
{ |
| 859 |
|
| 860 |
*newstyle = TRUE; |
| 861 |
} |
| 862 |
else |
| 863 |
{ |
| 864 |
|
| 865 |
tplofs = objgetap(ctx->voccxmem, verb_in, PRP_TPL, &verb, FALSE); |
| 866 |
*newstyle = FALSE; |
| 867 |
} |
| 868 |
|
| 869 |
|
| 870 |
for (;;) |
| 871 |
{ |
| 872 |
|
| 873 |
if (tplofs) |
| 874 |
{ |
| 875 |
size_t siz; |
| 876 |
|
| 877 |
|
| 878 |
siz = (*newstyle ? VOCTPL2SIZ : VOCTPLSIZ); |
| 879 |
|
| 880 |
|
| 881 |
tplptr = mcmlck(ctx->voccxmem, verb); |
| 882 |
thistpl = prpvalp(tplptr + tplofs); |
| 883 |
|
| 884 |
|
| 885 |
tplcnt = *thistpl++; |
| 886 |
|
| 887 |
|
| 888 |
for (found = FALSE ; tplcnt ; thistpl += siz, --tplcnt) |
| 889 |
{ |
| 890 |
if (voctplpr(thistpl) == prep) |
| 891 |
{ |
| 892 |
found = TRUE; |
| 893 |
break; |
| 894 |
} |
| 895 |
} |
| 896 |
|
| 897 |
|
| 898 |
mcmunlck(ctx->voccxmem, verb); |
| 899 |
if (found) |
| 900 |
{ |
| 901 |
memcpy(tplout, thistpl, siz); |
| 902 |
return(TRUE); |
| 903 |
} |
| 904 |
} |
| 905 |
|
| 906 |
|
| 907 |
tplofs = objgetap(ctx->voccxmem, verb_in, PRP_TPL2, &verb, TRUE); |
| 908 |
if (tplofs) |
| 909 |
*newstyle = TRUE; |
| 910 |
else |
| 911 |
{ |
| 912 |
tplofs = objgetap(ctx->voccxmem, verb_in, PRP_TPL, &verb, TRUE); |
| 913 |
*newstyle = FALSE; |
| 914 |
} |
| 915 |
|
| 916 |
|
| 917 |
if (!tplofs) |
| 918 |
return FALSE; |
| 919 |
|
| 920 |
|
| 921 |
verb_in = verb; |
| 922 |
} |
| 923 |
} |
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
void voc_set_me(voccxdef *ctx, objnum new_me) |
| 929 |
{ |
| 930 |
|
| 931 |
vocdusave_me(ctx, ctx->voccxme); |
| 932 |
|
| 933 |
|
| 934 |
ctx->voccxme = new_me; |
| 935 |
} |
| 936 |
|