| 1 |
#ifdef RCSID |
| 2 |
static char RCSid[] = |
| 3 |
"$Header: d:/cvsroot/tads/TADS2/vocab.c,v 1.5 1999/07/11 00:46:35 MJRoberts Exp $"; |
| 4 |
#endif |
| 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 |
#include <stdio.h> |
| 39 |
#include <ctype.h> |
| 40 |
#include <string.h> |
| 41 |
#include <stdlib.h> |
| 42 |
#include <stdarg.h> |
| 43 |
|
| 44 |
#include "os.h" |
| 45 |
#include "err.h" |
| 46 |
#include "voc.h" |
| 47 |
#include "tio.h" |
| 48 |
#include "mcm.h" |
| 49 |
#include "obj.h" |
| 50 |
#include "prp.h" |
| 51 |
#include "run.h" |
| 52 |
#include "lst.h" |
| 53 |
|
| 54 |
|
| 55 |
static char *type_names[] = |
| 56 |
{ |
| 57 |
"article", "adj", "noun", "prep", "verb", "special", "plural", |
| 58 |
"unknown" |
| 59 |
}; |
| 60 |
|
| 61 |
|
| 62 |
static int voctype[] = |
| 63 |
{ 0, 0, VOCT_VERB, VOCT_NOUN, VOCT_ADJ, VOCT_PREP, VOCT_ARTICLE }; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
uchar *voc_push_list_siz(voccxdef *ctx, uint lstsiz) |
| 71 |
{ |
| 72 |
runcxdef *rcx = ctx->voccxrun; |
| 73 |
runsdef val; |
| 74 |
uchar *lstp; |
| 75 |
|
| 76 |
|
| 77 |
lstsiz += 2; |
| 78 |
|
| 79 |
|
| 80 |
runhres(rcx, lstsiz, 0); |
| 81 |
|
| 82 |
|
| 83 |
val.runstyp = DAT_LIST; |
| 84 |
val.runsv.runsvstr = lstp = ctx->voccxrun->runcxhp; |
| 85 |
|
| 86 |
|
| 87 |
oswp2(lstp, lstsiz); |
| 88 |
lstp += 2; |
| 89 |
|
| 90 |
|
| 91 |
rcx->runcxhp += lstsiz; |
| 92 |
|
| 93 |
|
| 94 |
runrepush(rcx, &val); |
| 95 |
|
| 96 |
|
| 97 |
return lstp; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
static uchar *voc_push_list(voccxdef *ctx, int ele_count, int ele_size) |
| 105 |
{ |
| 106 |
uint lstsiz; |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
lstsiz = (uint)(ele_count * (1 + ele_size)); |
| 114 |
|
| 115 |
|
| 116 |
return voc_push_list_siz(ctx, lstsiz); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
static void voc_push_numlist(voccxdef *ctx, uint numlist[], int cnt) |
| 123 |
{ |
| 124 |
int i; |
| 125 |
uchar *lstp; |
| 126 |
|
| 127 |
|
| 128 |
lstp = voc_push_list(ctx, cnt, 4); |
| 129 |
|
| 130 |
|
| 131 |
for (i = 0 ; i < cnt ; ++i) |
| 132 |
{ |
| 133 |
|
| 134 |
*lstp++ = DAT_NUMBER; |
| 135 |
|
| 136 |
|
| 137 |
oswp4(lstp, numlist[i]); |
| 138 |
lstp += 4; |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
void voc_push_vocoldef_list(voccxdef *ctx, vocoldef *objlist, int cnt) |
| 146 |
{ |
| 147 |
int i; |
| 148 |
uchar *lstp; |
| 149 |
uint lstsiz; |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
for (lstsiz = 0, i = 0 ; i < cnt ; ++i) |
| 156 |
lstsiz += (objlist[i].vocolobj == MCMONINV ? 1 : 3); |
| 157 |
|
| 158 |
|
| 159 |
lstp = voc_push_list_siz(ctx, lstsiz); |
| 160 |
|
| 161 |
|
| 162 |
for (i = 0 ; i < cnt ; ++i) |
| 163 |
{ |
| 164 |
if (objlist[i].vocolobj == MCMONINV) |
| 165 |
{ |
| 166 |
|
| 167 |
*lstp++ = DAT_NIL; |
| 168 |
} |
| 169 |
else |
| 170 |
{ |
| 171 |
|
| 172 |
*lstp++ = DAT_OBJECT; |
| 173 |
|
| 174 |
|
| 175 |
oswp2(lstp, objlist[i].vocolobj); |
| 176 |
lstp += 2; |
| 177 |
} |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
void voc_push_objlist(voccxdef *ctx, objnum objlist[], int cnt) |
| 185 |
{ |
| 186 |
int i; |
| 187 |
uchar *lstp; |
| 188 |
uint lstsiz; |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
for (lstsiz = 0, i = 0 ; i < cnt ; ++i) |
| 195 |
lstsiz += (objlist[i] == MCMONINV ? 1 : 3); |
| 196 |
|
| 197 |
|
| 198 |
lstp = voc_push_list_siz(ctx, lstsiz); |
| 199 |
|
| 200 |
|
| 201 |
for (i = 0 ; i < cnt ; ++i) |
| 202 |
{ |
| 203 |
if (objlist[i] == MCMONINV) |
| 204 |
{ |
| 205 |
|
| 206 |
*lstp++ = DAT_NIL; |
| 207 |
} |
| 208 |
else |
| 209 |
{ |
| 210 |
|
| 211 |
*lstp++ = DAT_OBJECT; |
| 212 |
|
| 213 |
|
| 214 |
oswp2(lstp, objlist[i]); |
| 215 |
lstp += 2; |
| 216 |
} |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
static void voc_push_strlist(voccxdef *ctx, char *firstwrd, char *lastwrd) |
| 227 |
{ |
| 228 |
size_t curlen; |
| 229 |
char *p; |
| 230 |
uint lstsiz; |
| 231 |
uchar *lstp; |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
for (lstsiz = 0, p = firstwrd ; p != 0 && p <= lastwrd ; p += curlen + 1) |
| 239 |
{ |
| 240 |
curlen = strlen(p); |
| 241 |
lstsiz += curlen + (1+2); |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
lstp = voc_push_list_siz(ctx, lstsiz); |
| 246 |
|
| 247 |
|
| 248 |
for (p = firstwrd ; p != 0 && p <= lastwrd ; p += curlen + 1) |
| 249 |
{ |
| 250 |
|
| 251 |
*lstp++ = DAT_SSTRING; |
| 252 |
|
| 253 |
|
| 254 |
curlen = strlen(p); |
| 255 |
oswp2(lstp, curlen + 2); |
| 256 |
lstp += 2; |
| 257 |
|
| 258 |
|
| 259 |
memcpy(lstp, p, curlen); |
| 260 |
lstp += curlen; |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
static void voc_push_strlist_arr(voccxdef *ctx, char *wordlist[], int cnt) |
| 268 |
{ |
| 269 |
int i; |
| 270 |
char **p; |
| 271 |
uint lstsiz; |
| 272 |
uchar *lstp; |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
for (lstsiz = 0, p = wordlist, i = 0 ; i < cnt ; ++i, ++p) |
| 280 |
lstsiz += strlen(*p) + 3; |
| 281 |
|
| 282 |
|
| 283 |
lstp = voc_push_list_siz(ctx, lstsiz); |
| 284 |
|
| 285 |
|
| 286 |
for (p = wordlist, i = 0 ; i < cnt ; ++i, ++p) |
| 287 |
{ |
| 288 |
size_t curlen; |
| 289 |
|
| 290 |
|
| 291 |
*lstp++ = DAT_SSTRING; |
| 292 |
|
| 293 |
|
| 294 |
curlen = strlen(*p); |
| 295 |
oswp2(lstp, curlen + 2); |
| 296 |
lstp += 2; |
| 297 |
|
| 298 |
|
| 299 |
memcpy(lstp, *p, curlen); |
| 300 |
lstp += curlen; |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
static void voc_push_toklist(voccxdef *ctx, char *wordlist[], int cnt) |
| 311 |
{ |
| 312 |
int i; |
| 313 |
char **p; |
| 314 |
uint lstsiz; |
| 315 |
uchar *lstp; |
| 316 |
size_t cur_len; |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
for (lstsiz = 0, p = wordlist, i = 0 ; i < cnt ; ++i, ++p) |
| 324 |
{ |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
if (**p == '"') |
| 331 |
{ |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
cur_len = osrp2(*p + 1) - 2 + 2; |
| 342 |
} |
| 343 |
else |
| 344 |
{ |
| 345 |
|
| 346 |
cur_len = strlen(*p); |
| 347 |
} |
| 348 |
|
| 349 |
|
| 350 |
lstsiz += cur_len + 3; |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
lstp = voc_push_list_siz(ctx, lstsiz); |
| 355 |
|
| 356 |
|
| 357 |
for (p = wordlist, i = 0 ; i < cnt ; ++i, ++p) |
| 358 |
{ |
| 359 |
char *cur_ptr; |
| 360 |
size_t copy_len; |
| 361 |
|
| 362 |
|
| 363 |
*lstp++ = DAT_SSTRING; |
| 364 |
|
| 365 |
|
| 366 |
if (**p == '"') |
| 367 |
{ |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
copy_len = osrp2(*p + 1) - 2; |
| 373 |
|
| 374 |
|
| 375 |
cur_len = copy_len + 2; |
| 376 |
|
| 377 |
|
| 378 |
cur_ptr = *p + 3; |
| 379 |
} |
| 380 |
else |
| 381 |
{ |
| 382 |
|
| 383 |
cur_len = copy_len = strlen(*p); |
| 384 |
cur_ptr = *p; |
| 385 |
} |
| 386 |
|
| 387 |
|
| 388 |
oswp2(lstp, cur_len + 2); |
| 389 |
lstp += 2; |
| 390 |
|
| 391 |
|
| 392 |
if (**p == '"') |
| 393 |
*lstp++ = '"'; |
| 394 |
|
| 395 |
|
| 396 |
memcpy(lstp, cur_ptr, copy_len); |
| 397 |
lstp += copy_len; |
| 398 |
|
| 399 |
|
| 400 |
if (**p == '"') |
| 401 |
*lstp++ = '"'; |
| 402 |
} |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
int vocread(voccxdef *ctx, objnum actor, objnum verb, |
| 411 |
char *buf, int bufl, int type) |
| 412 |
{ |
| 413 |
char *prompt; |
| 414 |
int ret; |
| 415 |
|
| 416 |
|
| 417 |
ret = VOCREAD_OK; |
| 418 |
|
| 419 |
|
| 420 |
tiocapture(ctx->voccxtio, (mcmcxdef *)0, FALSE); |
| 421 |
tioclrcapture(ctx->voccxtio); |
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
buf[0] = '\0'; |
| 433 |
|
| 434 |
|
| 435 |
if (ctx->voccxprom != MCMONINV) |
| 436 |
{ |
| 437 |
runpnum(ctx->voccxrun, (long)type); |
| 438 |
runfn(ctx->voccxrun, ctx->voccxprom, 1); |
| 439 |
tioflushn(ctx->voccxtio, 0); |
| 440 |
prompt = ""; |
| 441 |
} |
| 442 |
else |
| 443 |
{ |
| 444 |
|
| 445 |
tioblank(tio); |
| 446 |
prompt = ">"; |
| 447 |
} |
| 448 |
|
| 449 |
|
| 450 |
if (tiogets(ctx->voccxtio, prompt, buf, bufl)) |
| 451 |
errsig(ctx->voccxerr, ERR_RUNQUIT); |
| 452 |
|
| 453 |
|
| 454 |
if (!strcmp(buf, "$$ABEND")) |
| 455 |
{ |
| 456 |
|
| 457 |
qasclose(); |
| 458 |
|
| 459 |
|
| 460 |
os_term(OSEXFAIL); |
| 461 |
|
| 462 |
|
| 463 |
errsig(ctx->voccxerr, ERR_RUNQUIT); |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
if (ctx->voccxpostprom != MCMONINV) |
| 468 |
{ |
| 469 |
runpnum(ctx->voccxrun, (long)type); |
| 470 |
runfn(ctx->voccxrun, ctx->voccxpostprom, 1); |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
if (ctx->voccxpre2 != MCMONINV && type != 0) |
| 479 |
{ |
| 480 |
uchar *s; |
| 481 |
size_t len; |
| 482 |
|
| 483 |
|
| 484 |
runpnum(ctx->voccxrun, (long)type); |
| 485 |
runpstr(ctx->voccxrun, buf, (int)strlen(buf), 0); |
| 486 |
runpobj(ctx->voccxrun, verb); |
| 487 |
runpobj(ctx->voccxrun, actor); |
| 488 |
|
| 489 |
|
| 490 |
runfn(ctx->voccxrun, ctx->voccxpre2, 4); |
| 491 |
|
| 492 |
|
| 493 |
switch(runtostyp(ctx->voccxrun)) |
| 494 |
{ |
| 495 |
case DAT_SSTRING: |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
s = runpopstr(ctx->voccxrun); |
| 502 |
len = osrp2(s) - 2; |
| 503 |
s += 2; |
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
if (len > (size_t)bufl - 1) |
| 510 |
len = bufl - 1; |
| 511 |
|
| 512 |
|
| 513 |
memcpy(buf, s, len); |
| 514 |
|
| 515 |
|
| 516 |
buf[len] = '\0'; |
| 517 |
|
| 518 |
|
| 519 |
break; |
| 520 |
|
| 521 |
case DAT_TRUE: |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
break; |
| 527 |
|
| 528 |
case DAT_NIL: |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
ret = VOCREAD_REDO; |
| 537 |
break; |
| 538 |
} |
| 539 |
} |
| 540 |
|
| 541 |
|
| 542 |
return ret; |
| 543 |
} |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
static int voceq(uchar *s1, uint l1, uchar *s2, uint l2) |
| 552 |
{ |
| 553 |
uint i; |
| 554 |
|
| 555 |
if (l1 == 0 && l2 == 0) return(TRUE); |
| 556 |
if (l1 == 0 || l2 == 0) return(FALSE); |
| 557 |
if (l1 >= 6 && l2 >= l1) l2 = l1; |
| 558 |
if (l1 != l2) return(FALSE); |
| 559 |
for (i = 0 ; i < l1 ; i++) |
| 560 |
if (*s1++ != *s2++) return(FALSE); |
| 561 |
return(TRUE); |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
vocwdef *vocfnw(voccxdef *voccx, vocseadef *search_ctx) |
| 566 |
{ |
| 567 |
vocdef *v, *vf; |
| 568 |
vocwdef *vw, *vwf; |
| 569 |
vocdef *c = search_ctx->v; |
| 570 |
int first; |
| 571 |
|
| 572 |
|
| 573 |
first = TRUE; |
| 574 |
vw = vocwget(voccx, search_ctx->vw->vocwnxt); |
| 575 |
|
| 576 |
|
| 577 |
for (v = c, vf = 0 ; v != 0 && vf == 0 ; v = v->vocnxt, first = FALSE) |
| 578 |
{ |
| 579 |
|
| 580 |
if (first |
| 581 |
|| (voceq(search_ctx->wrd1, search_ctx->len1, |
| 582 |
v->voctxt, v->voclen) |
| 583 |
&& voceq(search_ctx->wrd2, search_ctx->len2, |
| 584 |
v->voctxt + v->voclen, v->vocln2))) |
| 585 |
{ |
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
if (!first) |
| 593 |
vw = vocwget(voccx, v->vocwlst); |
| 594 |
|
| 595 |
|
| 596 |
for ( ; vw ; vw = vocwget(voccx, vw->vocwnxt)) |
| 597 |
{ |
| 598 |
if (search_ctx->vw->vocwtyp == vw->vocwtyp |
| 599 |
&& !(vw->vocwflg & VOCFCLASS) |
| 600 |
&& !(vw->vocwflg & VOCFDEL)) |
| 601 |
{ |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
vf = v; |
| 608 |
vwf = vw; |
| 609 |
break; |
| 610 |
} |
| 611 |
} |
| 612 |
} |
| 613 |
} |
| 614 |
|
| 615 |
|
| 616 |
search_ctx->v = vf; |
| 617 |
search_ctx->vw = (vf ? vwf : 0); |
| 618 |
return(search_ctx->vw); |
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
vocwdef *vocffw(voccxdef *ctx, char *wrd, int len, char *wrd2, int len2, |
| 623 |
int p, vocseadef *search_ctx) |
| 624 |
{ |
| 625 |
uint hshval; |
| 626 |
vocdef *v, *vf; |
| 627 |
vocwdef *vw, *vwf; |
| 628 |
|
| 629 |
|
| 630 |
hshval = vochsh((uchar *)wrd, len); |
| 631 |
|
| 632 |
|
| 633 |
for (v = ctx->voccxhsh[hshval], vf = 0 ; v != 0 && vf == 0 ; |
| 634 |
v = v->vocnxt) |
| 635 |
{ |
| 636 |
|
| 637 |
if (voceq((uchar *)wrd, len, v->voctxt, v->voclen) |
| 638 |
&& voceq((uchar *)wrd2, len2, v->voctxt + v->voclen, v->vocln2)) |
| 639 |
{ |
| 640 |
|
| 641 |
for (vw = vocwget(ctx, v->vocwlst) ; vw ; |
| 642 |
vw = vocwget(ctx, vw->vocwnxt)) |
| 643 |
{ |
| 644 |
if (vw->vocwtyp == p && !(vw->vocwflg & VOCFCLASS) |
| 645 |
&& !(vw->vocwflg & VOCFDEL)) |
| 646 |
{ |
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
vf = v; |
| 653 |
vwf = vw; |
| 654 |
break; |
| 655 |
} |
| 656 |
} |
| 657 |
} |
| 658 |
} |
| 659 |
|
| 660 |
|
| 661 |
vw = (vf != 0 ? vwf : 0); |
| 662 |
if (search_ctx) |
| 663 |
{ |
| 664 |
|
| 665 |
search_ctx->v = vf; |
| 666 |
search_ctx->vw = vw; |
| 667 |
|
| 668 |
|
| 669 |
search_ctx->wrd1 = (uchar *)wrd; |
| 670 |
search_ctx->len1 = len; |
| 671 |
search_ctx->wrd2 = (uchar *)wrd2; |
| 672 |
search_ctx->len2 = len2; |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
return vw; |
| 677 |
} |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
struct vocerr_va_info |
| 685 |
{ |
| 686 |
|
| 687 |
char user_msg[400]; |
| 688 |
|
| 689 |
|
| 690 |
char *fmt; |
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
char *outp; |
| 698 |
|
| 699 |
|
| 700 |
size_t outsiz; |
| 701 |
}; |
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
static void vocerr_va_prep(voccxdef *ctx, struct vocerr_va_info *info, |
| 709 |
int err, char *f, va_list argptr) |
| 710 |
{ |
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
info->fmt = f; |
| 716 |
|
| 717 |
|
| 718 |
info->outp = info->user_msg; |
| 719 |
info->outsiz = sizeof(info->user_msg); |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
if (ctx->voccxper != MCMONINV || ctx->voccxperp != MCMONINV) |
| 726 |
{ |
| 727 |
runcxdef *rcx = ctx->voccxrun; |
| 728 |
dattyp typ; |
| 729 |
size_t len; |
| 730 |
int argc; |
| 731 |
|
| 732 |
|
| 733 |
argc = 2; |
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
if (ctx->voccxperp != MCMONINV) |
| 740 |
{ |
| 741 |
enum typ_t |
| 742 |
{ |
| 743 |
ARGBUF_STR, ARGBUF_INT, ARGBUF_CHAR |
| 744 |
}; |
| 745 |
struct argbuf_t |
| 746 |
{ |
| 747 |
enum typ_t typ; |
| 748 |
union |
| 749 |
{ |
| 750 |
char *strval; |
| 751 |
int intval; |
| 752 |
char charval; |
| 753 |
} val; |
| 754 |
}; |
| 755 |
struct argbuf_t args[5]; |
| 756 |
struct argbuf_t *argp; |
| 757 |
char *p; |
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
for (p = f, argp = args ; *p != '\0' ; ++p) |
| 766 |
{ |
| 767 |
|
| 768 |
if (*p == '%') |
| 769 |
{ |
| 770 |
|
| 771 |
switch(*++p) |
| 772 |
{ |
| 773 |
case 's': |
| 774 |
|
| 775 |
argp->val.strval = va_arg(argptr, char *); |
| 776 |
argp->typ = ARGBUF_STR; |
| 777 |
|
| 778 |
|
| 779 |
++argp; |
| 780 |
break; |
| 781 |
|
| 782 |
case 'd': |
| 783 |
|
| 784 |
argp->val.intval = va_arg(argptr, int); |
| 785 |
argp->typ = ARGBUF_INT; |
| 786 |
|
| 787 |
|
| 788 |
++argp; |
| 789 |
break; |
| 790 |
|
| 791 |
case 'c': |
| 792 |
|
| 793 |
argp->val.charval = (char)va_arg(argptr, int); |
| 794 |
argp->typ = ARGBUF_CHAR; |
| 795 |
|
| 796 |
|
| 797 |
++argp; |
| 798 |
break; |
| 799 |
|
| 800 |
default: |
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
break; |
| 806 |
} |
| 807 |
} |
| 808 |
} |
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
while (argp != args) |
| 815 |
{ |
| 816 |
|
| 817 |
--argp; |
| 818 |
|
| 819 |
|
| 820 |
switch(argp->typ) |
| 821 |
{ |
| 822 |
case ARGBUF_STR: |
| 823 |
|
| 824 |
runpstr(rcx, argp->val.strval, |
| 825 |
(int)strlen(argp->val.strval), 0); |
| 826 |
break; |
| 827 |
|
| 828 |
case ARGBUF_INT: |
| 829 |
|
| 830 |
runpnum(rcx, argp->val.intval); |
| 831 |
break; |
| 832 |
|
| 833 |
case ARGBUF_CHAR: |
| 834 |
|
| 835 |
runpstr(rcx, &argp->val.charval, 1, 0); |
| 836 |
break; |
| 837 |
} |
| 838 |
|
| 839 |
|
| 840 |
++argc; |
| 841 |
} |
| 842 |
} |
| 843 |
|
| 844 |
|
| 845 |
runpstr(rcx, f, (int)strlen(f), 0); |
| 846 |
runpnum(rcx, (long)err); |
| 847 |
|
| 848 |
|
| 849 |
runfn(rcx, (objnum)(ctx->voccxperp == MCMONINV |
| 850 |
? ctx->voccxper : ctx->voccxperp), argc); |
| 851 |
|
| 852 |
|
| 853 |
typ = runtostyp(rcx); |
| 854 |
if (typ == DAT_SSTRING) |
| 855 |
{ |
| 856 |
char *p; |
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
p = (char *)runpopstr(rcx); |
| 863 |
len = osrp2(p) - 2; |
| 864 |
p += 2; |
| 865 |
if (len > sizeof(info->user_msg) - 1) |
| 866 |
len = sizeof(info->user_msg) - 1; |
| 867 |
memcpy(info->user_msg, p, len); |
| 868 |
info->user_msg[len] = '\0'; |
| 869 |
|
| 870 |
|
| 871 |
info->fmt = info->user_msg; |
| 872 |
|
| 873 |
|
| 874 |
info->outp = info->user_msg + len + 1; |
| 875 |
info->outsiz = sizeof(info->user_msg) - len - 1; |
| 876 |
} |
| 877 |
else |
| 878 |
{ |
| 879 |
|
| 880 |
rundisc(rcx); |
| 881 |
} |
| 882 |
} |
| 883 |
|
| 884 |
} |
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
static void vocerr_va(voccxdef *ctx, struct vocerr_va_info *info, |
| 897 |
int err, char *f, va_list argptr) |
| 898 |
{ |
| 899 |
char *buf; |
| 900 |
|
| 901 |
|
| 902 |
(void)tioshow(ctx->voccxtio); |
| 903 |
|
| 904 |
|
| 905 |
if (os_vasprintf(&buf, info->fmt, argptr) >= 0) |
| 906 |
{ |
| 907 |
|
| 908 |
tioputs(ctx->voccxtio, buf); |
| 909 |
|
| 910 |
|
| 911 |
osfree(buf); |
| 912 |
} |
| 913 |
} |
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
void vocerr_info(voccxdef *ctx, int err, char *f, ...) |
| 920 |
{ |
| 921 |
va_list argptr; |
| 922 |
struct vocerr_va_info info; |
| 923 |
|
| 924 |
|
| 925 |
va_start(argptr, f); |
| 926 |
vocerr_va_prep(ctx, &info, err, f, argptr); |
| 927 |
va_end(argptr); |
| 928 |
|
| 929 |
|
| 930 |
va_start(argptr, f); |
| 931 |
vocerr_va(ctx, &info, err, f, argptr); |
| 932 |
va_end(argptr); |
| 933 |
} |
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
void vocerr(voccxdef *ctx, int err, char *f, ...) |
| 939 |
{ |
| 940 |
va_list argptr; |
| 941 |
struct vocerr_va_info info; |
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
if (ctx->voccxunknown > 0) |
| 949 |
return; |
| 950 |
|
| 951 |
|
| 952 |
va_start(argptr, f); |
| 953 |
vocerr_va_prep(ctx, &info, err, f, argptr); |
| 954 |
va_end(argptr); |
| 955 |
|
| 956 |
|
| 957 |
va_start(argptr, f); |
| 958 |
vocerr_va(ctx, &info, err, f, argptr); |
| 959 |
va_end(argptr); |
| 960 |
} |
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
int try_unknown_verb(voccxdef *ctx, objnum actor, |
| 992 |
char **cmd, int *typelist, int wrdcnt, int *next_start, |
| 993 |
int do_fuses, int vocerr_err, char *vocerr_msg, ...) |
| 994 |
{ |
| 995 |
int show_msg; |
| 996 |
va_list argptr; |
| 997 |
|
| 998 |
|
| 999 |
show_msg = FALSE; |
| 1000 |
|
| 1001 |
|
| 1002 |
if (wrdcnt == 0) |
| 1003 |
{ |
| 1004 |
|
| 1005 |
for ( ; cmd[wrdcnt] != 0 ; ++wrdcnt) ; |
| 1006 |
} |
| 1007 |
|
| 1008 |
|
| 1009 |
if (ctx->voccxpuv != MCMONINV) |
| 1010 |
{ |
| 1011 |
int err; |
| 1012 |
int i; |
| 1013 |
int do_fuses; |
| 1014 |
|
| 1015 |
|
| 1016 |
err = 0; |
| 1017 |
|
| 1018 |
|
| 1019 |
do_fuses = TRUE; |
| 1020 |
|
| 1021 |
|
| 1022 |
runpnum(ctx->voccxrun, (long)vocerr_err); |
| 1023 |
|
| 1024 |
|
| 1025 |
voc_push_numlist(ctx, (uint *)typelist, wrdcnt); |
| 1026 |
|
| 1027 |
|
| 1028 |
voc_push_toklist(ctx, cmd, wrdcnt); |
| 1029 |
|
| 1030 |
|
| 1031 |
if (actor == MCMONINV) |
| 1032 |
actor = ctx->voccxme; |
| 1033 |
|
| 1034 |
|
| 1035 |
runpobj(ctx->voccxrun, actor); |
| 1036 |
|
| 1037 |
|
| 1038 |
ERRBEGIN(ctx->voccxerr) |
| 1039 |
{ |
| 1040 |
|
| 1041 |
runfn(ctx->voccxrun, ctx->voccxpuv, 4); |
| 1042 |
|
| 1043 |
|
| 1044 |
switch(runtostyp(ctx->voccxrun)) |
| 1045 |
{ |
| 1046 |
case DAT_TRUE: |
| 1047 |
|
| 1048 |
rundisc(ctx->voccxrun); |
| 1049 |
|
| 1050 |
|
| 1051 |
*next_start = wrdcnt; |
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
ctx->voccxunknown = 0; |
| 1058 |
break; |
| 1059 |
|
| 1060 |
case DAT_NUMBER: |
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
*next_start = runpopnum(ctx->voccxrun); |
| 1070 |
if (*next_start > 0) |
| 1071 |
--(*next_start); |
| 1072 |
|
| 1073 |
|
| 1074 |
if (*next_start < 0) |
| 1075 |
*next_start = 0; |
| 1076 |
else if (*next_start > wrdcnt) |
| 1077 |
*next_start = wrdcnt; |
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
for (i = 0 ; i < *next_start ; ++i) |
| 1084 |
{ |
| 1085 |
|
| 1086 |
if ((typelist[i] & VOCT_UNKNOWN) != 0 |
| 1087 |
&& ctx->voccxunknown > 0) |
| 1088 |
--(ctx->voccxunknown); |
| 1089 |
} |
| 1090 |
break; |
| 1091 |
|
| 1092 |
default: |
| 1093 |
|
| 1094 |
|
| 1095 |
case DAT_NIL: |
| 1096 |
|
| 1097 |
rundisc(ctx->voccxrun); |
| 1098 |
show_msg = TRUE; |
| 1099 |
break; |
| 1100 |
} |
| 1101 |
} |
| 1102 |
ERRCATCH(ctx->voccxerr, err) |
| 1103 |
{ |
| 1104 |
|
| 1105 |
switch(err) |
| 1106 |
{ |
| 1107 |
case ERR_RUNEXIT: |
| 1108 |
case ERR_RUNEXITOBJ: |
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
ctx->voccxunknown = 0; |
| 1116 |
break; |
| 1117 |
|
| 1118 |
case ERR_RUNABRT: |
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
do_fuses = FALSE; |
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
ctx->voccxunknown = 0; |
| 1132 |
break; |
| 1133 |
|
| 1134 |
default: |
| 1135 |
|
| 1136 |
errrse(ctx->voccxerr); |
| 1137 |
} |
| 1138 |
} |
| 1139 |
ERREND(ctx->voccxerr); |
| 1140 |
|
| 1141 |
|
| 1142 |
if (!show_msg) |
| 1143 |
{ |
| 1144 |
|
| 1145 |
if (exe_fuses_and_daemons(ctx, err, do_fuses, |
| 1146 |
actor, MCMONINV, 0, 0, |
| 1147 |
MCMONINV, MCMONINV) != 0) |
| 1148 |
{ |
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
return FALSE; |
| 1155 |
} |
| 1156 |
|
| 1157 |
|
| 1158 |
return TRUE; |
| 1159 |
} |
| 1160 |
} |
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
if (ctx->voccxunknown == 0) |
| 1168 |
{ |
| 1169 |
struct vocerr_va_info info; |
| 1170 |
|
| 1171 |
|
| 1172 |
va_start(argptr, vocerr_msg); |
| 1173 |
vocerr_va_prep(ctx, &info, vocerr_err, vocerr_msg, argptr); |
| 1174 |
va_end(argptr); |
| 1175 |
|
| 1176 |
|
| 1177 |
va_start(argptr, vocerr_msg); |
| 1178 |
vocerr_va(ctx, &info, vocerr_err, vocerr_msg, argptr); |
| 1179 |
va_end(argptr); |
| 1180 |
} |
| 1181 |
|
| 1182 |
|
| 1183 |
return FALSE; |
| 1184 |
} |
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
#define vocisspec(wrd) \ |
| 1190 |
(vocisupper(*wrd) || (!vocisalpha(*wrd) && *wrd != '\'' && *wrd != '-')) |
| 1191 |
|
| 1192 |
static vocspdef vocsptab[] = |
| 1193 |
{ |
| 1194 |
{ "of", VOCW_OF }, |
| 1195 |
{ "and", VOCW_AND }, |
| 1196 |
{ "then", VOCW_THEN }, |
| 1197 |
{ "all", VOCW_ALL }, |
| 1198 |
{ "everyt", VOCW_ALL }, |
| 1199 |
{ "both", VOCW_BOTH }, |
| 1200 |
{ "but", VOCW_BUT }, |
| 1201 |
{ "except", VOCW_BUT }, |
| 1202 |
{ "one", VOCW_ONE }, |
| 1203 |
{ "ones", VOCW_ONES }, |
| 1204 |
{ "it", VOCW_IT }, |
| 1205 |
{ "them", VOCW_THEM }, |
| 1206 |
{ "him", VOCW_HIM }, |
| 1207 |
{ "her", VOCW_HER }, |
| 1208 |
{ "any", VOCW_ANY }, |
| 1209 |
{ "either", VOCW_ANY }, |
| 1210 |
{ 0, 0 } |
| 1211 |
}; |
| 1212 |
|
| 1213 |
|
| 1214 |
static int voc_check_special(voccxdef *ctx, char *wrd, int checktyp) |
| 1215 |
{ |
| 1216 |
|
| 1217 |
if (ctx->voccxspp) |
| 1218 |
{ |
| 1219 |
char *p; |
| 1220 |
char *endp; |
| 1221 |
char typ; |
| 1222 |
int len; |
| 1223 |
int wrdlen = strlen((char *)wrd); |
| 1224 |
|
| 1225 |
for (p = ctx->voccxspp, endp = p + ctx->voccxspl ; |
| 1226 |
p < endp ; ) |
| 1227 |
{ |
| 1228 |
typ = *p++; |
| 1229 |
len = *p++; |
| 1230 |
|
| 1231 |
|
| 1232 |
if (typ == checktyp |
| 1233 |
&& len == wrdlen && !memcmp(p, wrd, (size_t)len)) |
| 1234 |
return TRUE; |
| 1235 |
|
| 1236 |
|
| 1237 |
p += len; |
| 1238 |
} |
| 1239 |
} |
| 1240 |
else |
| 1241 |
{ |
| 1242 |
vocspdef *x; |
| 1243 |
|
| 1244 |
for (x = vocsptab ; x->vocspin ; ++x) |
| 1245 |
{ |
| 1246 |
|
| 1247 |
if (x->vocspout == checktyp |
| 1248 |
&& !strncmp((char *)wrd, x->vocspin, (size_t)6)) |
| 1249 |
return TRUE; |
| 1250 |
} |
| 1251 |
} |
| 1252 |
|
| 1253 |
|
| 1254 |
return FALSE; |
| 1255 |
} |
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
int voctok(voccxdef *ctx, char *cmd, char *outbuf, char **wrd, |
| 1260 |
int lower, int cvt_ones, int show_errors) |
| 1261 |
{ |
| 1262 |
int i; |
| 1263 |
vocspdef *x; |
| 1264 |
int l; |
| 1265 |
char *p; |
| 1266 |
char *w; |
| 1267 |
uint len; |
| 1268 |
|
| 1269 |
for (i = 0 ;; ) |
| 1270 |
{ |
| 1271 |
while (vocisspace(*cmd)) cmd++; |
| 1272 |
if (!*cmd) |
| 1273 |
{ |
| 1274 |
wrd[i] = outbuf; |
| 1275 |
*outbuf = '\0'; |
| 1276 |
return(i); |
| 1277 |
} |
| 1278 |
|
| 1279 |
wrd[i++] = outbuf; |
| 1280 |
if (vocisalpha(*cmd) || *cmd == '-') |
| 1281 |
{ |
| 1282 |
while(vocisalpha(*cmd) || vocisdigit(*cmd) || |
| 1283 |
*cmd=='\'' || *cmd=='-') |
| 1284 |
{ |
| 1285 |
*outbuf++ = (vocisupper(*cmd) && lower) ? tolower(*cmd) : *cmd; |
| 1286 |
++cmd; |
| 1287 |
} |
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
w = wrd[i-1]; |
| 1298 |
len = outbuf - w; |
| 1299 |
if (*cmd == '.') |
| 1300 |
{ |
| 1301 |
*outbuf++ = *cmd++; |
| 1302 |
*outbuf = '\0'; |
| 1303 |
++len; |
| 1304 |
if (!vocffw(ctx, (char *)w, len, 0, 0, PRP_NOUN, |
| 1305 |
(vocseadef *)0) |
| 1306 |
&& !vocffw(ctx, (char *)w, len, 0, 0, PRP_ADJ, |
| 1307 |
(vocseadef *)0)) |
| 1308 |
{ |
| 1309 |
|
| 1310 |
--outbuf; |
| 1311 |
--cmd; |
| 1312 |
--len; |
| 1313 |
} |
| 1314 |
} |
| 1315 |
|
| 1316 |
|
| 1317 |
*outbuf = '\0'; |
| 1318 |
|
| 1319 |
|
| 1320 |
for (p = ctx->voccxcpp, l = ctx->voccxcpl ; l ; ) |
| 1321 |
{ |
| 1322 |
uint l1 = osrp2(p); |
| 1323 |
char *p2 = p + l1; |
| 1324 |
uint l2 = osrp2(p2); |
| 1325 |
char *p3 = p2 + l2; |
| 1326 |
uint l3 = osrp2(p3); |
| 1327 |
|
| 1328 |
if (i > 1 && len == (l2 - 2) |
| 1329 |
&& !memcmp(w, p2 + 2, (size_t)len) |
| 1330 |
&& strlen((char *)wrd[i-2]) == (l1 - 2) |
| 1331 |
&& !memcmp(wrd[i-2], p + 2, (size_t)(l1 - 2))) |
| 1332 |
{ |
| 1333 |
memcpy(wrd[i-2], p3 + 2, (size_t)(l3 - 2)); |
| 1334 |
*(wrd[i-2] + l3 - 2) = '\0'; |
| 1335 |
--i; |
| 1336 |
break; |
| 1337 |
} |
| 1338 |
|
| 1339 |
|
| 1340 |
l -= l1 + l2 + l3; |
| 1341 |
p = p3 + l3; |
| 1342 |
} |
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
if (ctx->voccxspp) |
| 1351 |
{ |
| 1352 |
char *p; |
| 1353 |
char *endp; |
| 1354 |
char typ; |
| 1355 |
int len; |
| 1356 |
int wrdlen = strlen((char *)wrd[i-1]); |
| 1357 |
|
| 1358 |
for (p = ctx->voccxspp, endp = p + ctx->voccxspl ; |
| 1359 |
p < endp ; ) |
| 1360 |
{ |
| 1361 |
typ = *p++; |
| 1362 |
len = *p++; |
| 1363 |
if (len == wrdlen && !memcmp(p, wrd[i-1], (size_t)len) |
| 1364 |
&& (cvt_ones || (typ != VOCW_ONE && typ != VOCW_ONES)) |
| 1365 |
&& typ != VOCW_OF) |
| 1366 |
{ |
| 1367 |
*wrd[i-1] = typ; |
| 1368 |
*(wrd[i-1] + 1) = '\0'; |
| 1369 |
break; |
| 1370 |
} |
| 1371 |
p += len; |
| 1372 |
} |
| 1373 |
} |
| 1374 |
else |
| 1375 |
{ |
| 1376 |
for (x = vocsptab ; x->vocspin ; ++x) |
| 1377 |
{ |
| 1378 |
if (!strncmp((char *)wrd[i-1], (char *)x->vocspin, |
| 1379 |
(size_t)6) |
| 1380 |
&& (cvt_ones || |
| 1381 |
(x->vocspout != VOCW_ONE |
| 1382 |
&& x->vocspout != VOCW_ONES)) |
| 1383 |
&& x->vocspout != VOCW_OF) |
| 1384 |
{ |
| 1385 |
*wrd[i-1] = x->vocspout; |
| 1386 |
*(wrd[i-1] + 1) = '\0'; |
| 1387 |
break; |
| 1388 |
} |
| 1389 |
} |
| 1390 |
} |
| 1391 |
|
| 1392 |
|
| 1393 |
outbuf = wrd[i-1]; |
| 1394 |
outbuf += strlen((char *)outbuf); |
| 1395 |
} |
| 1396 |
else if (vocisdigit( *cmd )) |
| 1397 |
{ |
| 1398 |
while(vocisdigit(*cmd) || vocisalpha(*cmd) |
| 1399 |
|| *cmd == '\'' || *cmd == '-') |
| 1400 |
*outbuf++ = *cmd++; |
| 1401 |
} |
| 1402 |
else switch( *cmd ) |
| 1403 |
{ |
| 1404 |
case '.': |
| 1405 |
case '!': |
| 1406 |
case '?': |
| 1407 |
case ';': |
| 1408 |
*outbuf++ = VOCW_THEN; |
| 1409 |
++cmd; |
| 1410 |
break; |
| 1411 |
|
| 1412 |
case ',': |
| 1413 |
case ':': |
| 1414 |
*outbuf++ = VOCW_AND; |
| 1415 |
++cmd; |
| 1416 |
break; |
| 1417 |
|
| 1418 |
case '"': |
| 1419 |
case '\'': |
| 1420 |
{ |
| 1421 |
char *lenptr; |
| 1422 |
char quote = *cmd++; |
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
*outbuf++ = '"'; |
| 1431 |
|
| 1432 |
|
| 1433 |
lenptr = outbuf; |
| 1434 |
outbuf += 2; |
| 1435 |
|
| 1436 |
|
| 1437 |
while (*cmd && *cmd != quote) |
| 1438 |
{ |
| 1439 |
char c; |
| 1440 |
|
| 1441 |
|
| 1442 |
c = *cmd++; |
| 1443 |
|
| 1444 |
|
| 1445 |
switch(c) |
| 1446 |
{ |
| 1447 |
case '\\': |
| 1448 |
*outbuf++ = '\\'; |
| 1449 |
break; |
| 1450 |
} |
| 1451 |
|
| 1452 |
|
| 1453 |
*outbuf++ = c; |
| 1454 |
} |
| 1455 |
|
| 1456 |
oswp2(lenptr, ((int)(outbuf - lenptr))); |
| 1457 |
if (*cmd == quote) cmd++; |
| 1458 |
break; |
| 1459 |
} |
| 1460 |
|
| 1461 |
default: |
| 1462 |
|
| 1463 |
if (show_errors) |
| 1464 |
{ |
| 1465 |
int hmode = tio_is_html_mode(); |
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
if (hmode) |
| 1473 |
tioputs(ctx->voccxtio, "\\H-"); |
| 1474 |
|
| 1475 |
|
| 1476 |
vocerr(ctx, VOCERR(1), |
| 1477 |
"I don't understand the punctuation \"%c\".", *cmd); |
| 1478 |
|
| 1479 |
|
| 1480 |
if (hmode) |
| 1481 |
tioputs(ctx->voccxtio, "\\H+"); |
| 1482 |
} |
| 1483 |
|
| 1484 |
|
| 1485 |
return -1; |
| 1486 |
} |
| 1487 |
|
| 1488 |
|
| 1489 |
*outbuf++ = '\0'; |
| 1490 |
} |
| 1491 |
} |
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
static int voc_lookup_type(voccxdef *ctx, char *p, int len, int of_is_spec) |
| 1500 |
{ |
| 1501 |
int t; |
| 1502 |
|
| 1503 |
|
| 1504 |
if (vocisspec(p)) |
| 1505 |
{ |
| 1506 |
|
| 1507 |
t = VOCT_SPEC; |
| 1508 |
} |
| 1509 |
else |
| 1510 |
{ |
| 1511 |
vocwdef *vw; |
| 1512 |
vocdef *v; |
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
for (t = 0, v = ctx->voccxhsh[vochsh((uchar *)p, len)] ; v != 0 ; |
| 1525 |
v = v->vocnxt) |
| 1526 |
{ |
| 1527 |
|
| 1528 |
if (voceq((uchar *)p, len, v->voctxt, v->voclen)) |
| 1529 |
{ |
| 1530 |
|
| 1531 |
for (vw = vocwget(ctx, v->vocwlst) ; vw != 0 ; |
| 1532 |
vw = vocwget(ctx, vw->vocwnxt)) |
| 1533 |
{ |
| 1534 |
|
| 1535 |
if (vw->vocwflg & VOCFDEL) |
| 1536 |
continue; |
| 1537 |
|
| 1538 |
|
| 1539 |
if (vw->vocwtyp == PRP_PLURAL) |
| 1540 |
{ |
| 1541 |
|
| 1542 |
if (len == v->voclen) |
| 1543 |
{ |
| 1544 |
|
| 1545 |
t |= (VOCT_NOUN | VOCT_PLURAL); |
| 1546 |
} |
| 1547 |
} |
| 1548 |
else |
| 1549 |
{ |
| 1550 |
|
| 1551 |
t |= voctype[vw->vocwtyp]; |
| 1552 |
} |
| 1553 |
} |
| 1554 |
} |
| 1555 |
} |
| 1556 |
} |
| 1557 |
|
| 1558 |
|
| 1559 |
if (of_is_spec && t == 0 && voc_check_special(ctx, p, VOCW_OF)) |
| 1560 |
t = VOCT_SPEC; |
| 1561 |
|
| 1562 |
|
| 1563 |
return t; |
| 1564 |
} |
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
static char *voc_read_oops(voccxdef *ctx, char *oopsbuf, size_t oopsbuflen, |
| 1576 |
const char *unknown_word) |
| 1577 |
{ |
| 1578 |
char *p; |
| 1579 |
|
| 1580 |
|
| 1581 |
vocerr(ctx, VOCERR(2), "I don't know the word \"%s\".", unknown_word); |
| 1582 |
|
| 1583 |
|
| 1584 |
if (vocread(ctx, MCMONINV, MCMONINV, |
| 1585 |
oopsbuf, (int)oopsbuflen, 1) == VOCREAD_REDO) |
| 1586 |
{ |
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
return 0; |
| 1592 |
} |
| 1593 |
|
| 1594 |
|
| 1595 |
for (p = oopsbuf ; *p != '\0' ; ++p) |
| 1596 |
*p = (vocisupper(*p) ? tolower(*p) : *p); |
| 1597 |
|
| 1598 |
|
| 1599 |
for (p = oopsbuf ; vocisspace(*p) ; ++p) ; |
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
if ((strlen(p) > 5 && memcmp(p, "oops ", 5) == 0) |
| 1606 |
|| (strlen(p) > 5 && memcmp(p, "oops,", 5) == 0)) |
| 1607 |
{ |
| 1608 |
|
| 1609 |
p += 5; |
| 1610 |
} |
| 1611 |
else if ((strlen(p) > 2 && memcmp(p, "o ", 2) == 0) |
| 1612 |
|| (strlen(p) > 2 && memcmp(p, "o,", 2) == 0)) |
| 1613 |
{ |
| 1614 |
|
| 1615 |
p += 2; |
| 1616 |
} |
| 1617 |
else |
| 1618 |
{ |
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
return 0; |
| 1624 |
} |
| 1625 |
|
| 1626 |
|
| 1627 |
for ( ; vocisspace(*p) ; ++p) ; |
| 1628 |
|
| 1629 |
|
| 1630 |
return p; |
| 1631 |
} |
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
int vocgtyp(voccxdef *ctx, char *cmd[], int types[], char *orgbuf) |
| 1639 |
{ |
| 1640 |
int cur; |
| 1641 |
int t; |
| 1642 |
char *p; |
| 1643 |
int len; |
| 1644 |
int unknown_count = 0; |
| 1645 |
|
| 1646 |
startover: |
| 1647 |
if (ctx->voccxflg & VOCCXFDBG) |
| 1648 |
tioputs(ctx->vocxtio, ". Checking words:\\n"); |
| 1649 |
|
| 1650 |
for (cur = 0 ; cmd[cur] ; ++cur) |
| 1651 |
{ |
| 1652 |
|
| 1653 |
p = cmd[cur]; |
| 1654 |
len = strlen(p); |
| 1655 |
|
| 1656 |
|
| 1657 |
t = voc_lookup_type(ctx, p, len, FALSE); |
| 1658 |
|
| 1659 |
|
| 1660 |
if (t == 0 && !voc_check_special(ctx, p, VOCW_OF)) |
| 1661 |
{ |
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
t = VOCT_UNKNOWN; |
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
if (ctx->voccxunknown != 0 |
| 1685 |
&& unknown_count >= ctx->voccxlastunk - ctx->voccxunknown) |
| 1686 |
{ |
| 1687 |
char oopsbuf[VOCBUFSIZ]; |
| 1688 |
char *p1; |
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
ctx->voccxunknown = 0; |
| 1695 |
|
| 1696 |
|
| 1697 |
p1 = voc_read_oops(ctx, oopsbuf, sizeof(oopsbuf), p); |
| 1698 |
|
| 1699 |
|
| 1700 |
if (p1 != 0) |
| 1701 |
{ |
| 1702 |
char redobuf[200]; |
| 1703 |
char *q; |
| 1704 |
int i; |
| 1705 |
int wc; |
| 1706 |
char **w; |
| 1707 |
char *outp; |
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
for (outp = redobuf, i = 0, w = cmd ; *w != 0 ; ++i, ++w) |
| 1715 |
{ |
| 1716 |
|
| 1717 |
|
| 1718 |
if (i == cur) |
| 1719 |
{ |
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
for (q = p1, len = 0 ; |
| 1727 |
*q != '\0' && *q != '.' && *q != ',' |
| 1728 |
&& *q != '?' && *q != '!' ; ++q, ++len) ; |
| 1729 |
memcpy(outp, p1, (size_t)len); |
| 1730 |
outp += len; |
| 1731 |
} |
| 1732 |
else if (**w == '"') |
| 1733 |
{ |
| 1734 |
char *strp; |
| 1735 |
char *p2; |
| 1736 |
char qu; |
| 1737 |
int rem; |
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
len = osrp2(*w + 1) - 2; |
| 1750 |
strp = *w + 3; |
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
for (qu = '"', p2 = strp, rem = len ; rem != 0 ; |
| 1762 |
--rem, ++p2) |
| 1763 |
{ |
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
if (*p2 == '"') |
| 1770 |
{ |
| 1771 |
|
| 1772 |
qu = '\''; |
| 1773 |
|
| 1774 |
|
| 1775 |
break; |
| 1776 |
} |
| 1777 |
} |
| 1778 |
|
| 1779 |
|
| 1780 |
*outp++ = qu; |
| 1781 |
|
| 1782 |
|
| 1783 |
memcpy(outp, strp, len); |
| 1784 |
outp += len; |
| 1785 |
|
| 1786 |
|
| 1787 |
*outp++ = qu; |
| 1788 |
} |
| 1789 |
else |
| 1790 |
{ |
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
len = strlen(*w); |
| 1797 |
memcpy(outp, *w, (size_t)len); |
| 1798 |
outp += len; |
| 1799 |
} |
| 1800 |
|
| 1801 |
|
| 1802 |
*outp++ = ' '; |
| 1803 |
} |
| 1804 |
|
| 1805 |
|
| 1806 |
*outp = '\0'; |
| 1807 |
|
| 1808 |
|
| 1809 |
*(cmd[0]) = '\0'; |
| 1810 |
if ((wc = voctok(ctx, redobuf, cmd[0], |
| 1811 |
cmd, FALSE, FALSE, TRUE)) <= 0) |
| 1812 |
return 1; |
| 1813 |
cmd[wc] = 0; |
| 1814 |
|
| 1815 |
|
| 1816 |
goto startover; |
| 1817 |
} |
| 1818 |
else |
| 1819 |
{ |
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
strcpy(orgbuf, oopsbuf); |
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
ctx->voccxunknown = 0; |
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
ctx->voccxredo = 1; |
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
return 1; |
| 1844 |
} |
| 1845 |
} |
| 1846 |
else |
| 1847 |
{ |
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
++unknown_count; |
| 1857 |
} |
| 1858 |
} |
| 1859 |
|
| 1860 |
|
| 1861 |
if (ctx->voccxflg & VOCCXFDBG) |
| 1862 |
{ |
| 1863 |
char buf[128]; |
| 1864 |
size_t i; |
| 1865 |
char *p; |
| 1866 |
int cnt; |
| 1867 |
|
| 1868 |
(void)tioshow(ctx->voccxtio); |
| 1869 |
sprintf(buf, "... %s (", cmd[cur]); |
| 1870 |
p = buf + strlen(buf); |
| 1871 |
cnt = 0; |
| 1872 |
for (i = 0 ; i < sizeof(type_names)/sizeof(type_names[0]) ; ++i) |
| 1873 |
{ |
| 1874 |
if (t & (1 << i)) |
| 1875 |
{ |
| 1876 |
if (cnt) *p++ = ','; |
| 1877 |
strcpy(p, type_names[i]); |
| 1878 |
p += strlen(p); |
| 1879 |
++cnt; |
| 1880 |
} |
| 1881 |
} |
| 1882 |
*p++ = ')'; |
| 1883 |
*p++ = '\\'; |
| 1884 |
*p++ = 'n'; |
| 1885 |
*p = '\0'; |
| 1886 |
tioputs(ctx->voccxtio, buf); |
| 1887 |
} |
| 1888 |
|
| 1889 |
types[cur] = t; |
| 1890 |
} |
| 1891 |
|
| 1892 |
|
| 1893 |
ctx->voccxunknown = unknown_count; |
| 1894 |
ctx->voccxlastunk = unknown_count; |
| 1895 |
|
| 1896 |
|
| 1897 |
return 0; |
| 1898 |
} |
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
static int vocisect(objnum *list1, objnum *list2) |
| 1905 |
{ |
| 1906 |
int i, j, k; |
| 1907 |
|
| 1908 |
for (i = k = 0 ; list1[i] != MCMONINV ; ++i) |
| 1909 |
{ |
| 1910 |
for (j = 0 ; list2[j] != MCMONINV ; ++j) |
| 1911 |
{ |
| 1912 |
if (list1[i] == list2[j]) |
| 1913 |
{ |
| 1914 |
list1[k++] = list1[i]; |
| 1915 |
break; |
| 1916 |
} |
| 1917 |
} |
| 1918 |
} |
| 1919 |
list1[k] = MCMONINV; |
| 1920 |
return(k); |
| 1921 |
} |
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
static int vocisect_flags(objnum *list1, uint *flags1, |
| 1928 |
objnum *list2, uint *flags2) |
| 1929 |
{ |
| 1930 |
int i, j, k; |
| 1931 |
|
| 1932 |
for (i = k = 0 ; list1[i] != MCMONINV ; ++i) |
| 1933 |
{ |
| 1934 |
for (j = 0 ; list2[j] != MCMONINV ; ++j) |
| 1935 |
{ |
| 1936 |
if (list1[i] == list2[j]) |
| 1937 |
{ |
| 1938 |
list1[k] = list1[i]; |
| 1939 |
flags1[k] = flags1[i] | flags2[j]; |
| 1940 |
++k; |
| 1941 |
break; |
| 1942 |
} |
| 1943 |
} |
| 1944 |
} |
| 1945 |
list1[k] = MCMONINV; |
| 1946 |
return(k); |
| 1947 |
} |
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
static int vocgol(voccxdef *ctx, objnum *list, uint *flags, char **wrdlst, |
| 1954 |
int *typlst, int first, int cur, int last, int ofword) |
| 1955 |
{ |
| 1956 |
char *wrd; |
| 1957 |
int typ; |
| 1958 |
vocwdef *v; |
| 1959 |
int cnt; |
| 1960 |
int len; |
| 1961 |
vocseadef search_ctx; |
| 1962 |
int try_plural; |
| 1963 |
int try_noun_before_num; |
| 1964 |
int try_endadj; |
| 1965 |
int trying_endadj; |
| 1966 |
int wrdtyp; |
| 1967 |
|
| 1968 |
|
| 1969 |
wrd = wrdlst[cur]; |
| 1970 |
typ = typlst[cur]; |
| 1971 |
|
| 1972 |
|
| 1973 |
len = strlen(wrd); |
| 1974 |
|
| 1975 |
|
| 1976 |
|
| 1977 |
|
| 1978 |
|
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
|
| 1983 |
|
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
try_plural = (typ & VOCT_PLURAL); |
| 1988 |
|
| 1989 |
|
| 1990 |
try_endadj = FALSE; |
| 1991 |
|
| 1992 |
|
| 1993 |
try_noun_before_num = FALSE; |
| 1994 |
|
| 1995 |
|
| 1996 |
trying_endadj = FALSE; |
| 1997 |
|
| 1998 |
|
| 1999 |
if ((typ & (VOCT_NOUN | VOCT_PLURAL)) && (typ & VOCT_ADJ)) |
| 2000 |
{ |
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
if (cur + 1 == last || cur == ofword - 1) |
| 2007 |
{ |
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
wrdtyp = ((typ & VOCT_NOUN) ? PRP_NOUN : PRP_PLURAL); |
| 2015 |
|
| 2016 |
|
| 2017 |
|
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
if ((typ & VOCT_ADJ) != 0) |
| 2025 |
try_endadj = TRUE; |
| 2026 |
} |
| 2027 |
else if ((cur + 2 == last || cur == ofword - 2) |
| 2028 |
&& vocisdigit(wrdlst[cur+1][0])) |
| 2029 |
{ |
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
|
| 2035 |
|
| 2036 |
wrdtyp = PRP_ADJ; |
| 2037 |
try_noun_before_num = TRUE; |
| 2038 |
} |
| 2039 |
else |
| 2040 |
{ |
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
wrdtyp = PRP_ADJ; |
| 2046 |
} |
| 2047 |
} |
| 2048 |
else if (typ & VOCT_NOUN) |
| 2049 |
wrdtyp = PRP_NOUN; |
| 2050 |
else if (typ & VOCT_UNKNOWN) |
| 2051 |
wrdtyp = PRP_UNKNOWN; |
| 2052 |
else |
| 2053 |
{ |
| 2054 |
|
| 2055 |
wrdtyp = PRP_ADJ; |
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
|
| 2060 |
|
| 2061 |
if (cur + 1 == last || cur == ofword - 1) |
| 2062 |
trying_endadj = TRUE; |
| 2063 |
} |
| 2064 |
|
| 2065 |
|
| 2066 |
if (ctx->voccxflg & VOCCXFDBG) |
| 2067 |
{ |
| 2068 |
char buf[128]; |
| 2069 |
|
| 2070 |
sprintf(buf, "... %s (treating as %s%s)\\n", wrd, |
| 2071 |
(wrdtyp == PRP_ADJ ? "adjective" : |
| 2072 |
wrdtyp == PRP_NOUN ? "noun" : |
| 2073 |
wrdtyp == PRP_INVALID ? "unknown" : "plural"), |
| 2074 |
(wrdtyp == PRP_NOUN && try_plural ? " + plural" : "")); |
| 2075 |
tioputs(ctx->vocxtio, buf); |
| 2076 |
} |
| 2077 |
|
| 2078 |
|
| 2079 |
if (wrdtyp == PRP_UNKNOWN) |
| 2080 |
{ |
| 2081 |
list[0] = MCMONINV; |
| 2082 |
return 0; |
| 2083 |
} |
| 2084 |
|
| 2085 |
|
| 2086 |
cnt = 0; |
| 2087 |
|
| 2088 |
add_words: |
| 2089 |
for (v = vocffw(ctx, wrd, len, (char *)0, 0, wrdtyp, &search_ctx) |
| 2090 |
; v != 0 ; v = vocfnw(ctx, &search_ctx)) |
| 2091 |
{ |
| 2092 |
int i; |
| 2093 |
|
| 2094 |
|
| 2095 |
list[cnt] = v->vocwobj; |
| 2096 |
|
| 2097 |
|
| 2098 |
flags[cnt] = 0; |
| 2099 |
|
| 2100 |
|
| 2101 |
if (wrdtyp == PRP_PLURAL) |
| 2102 |
flags[cnt] |= VOCS_PLURAL; |
| 2103 |
|
| 2104 |
|
| 2105 |
if (wrdtyp == PRP_ADJ && trying_endadj) |
| 2106 |
flags[cnt] |= VOCS_ENDADJ; |
| 2107 |
|
| 2108 |
|
| 2109 |
|
| 2110 |
|
| 2111 |
|
| 2112 |
if (len < search_ctx.v->voclen) |
| 2113 |
flags[cnt] |= VOCS_TRUNC; |
| 2114 |
|
| 2115 |
|
| 2116 |
++cnt; |
| 2117 |
|
| 2118 |
|
| 2119 |
|
| 2120 |
|
| 2121 |
|
| 2122 |
for (i = 0 ; i < cnt - 1 ; ++i) |
| 2123 |
{ |
| 2124 |
|
| 2125 |
if (list[i] == list[cnt-1] && flags[i] == flags[cnt-1]) |
| 2126 |
{ |
| 2127 |
|
| 2128 |
--cnt; |
| 2129 |
|
| 2130 |
|
| 2131 |
break; |
| 2132 |
} |
| 2133 |
} |
| 2134 |
|
| 2135 |
|
| 2136 |
if (cnt >= VOCMAXAMBIG) |
| 2137 |
{ |
| 2138 |
vocerr(ctx, VOCERR(3), |
| 2139 |
"The word \"%s\" refers to too many objects.", wrd); |
| 2140 |
list[0] = MCMONINV; |
| 2141 |
return -1; |
| 2142 |
} |
| 2143 |
} |
| 2144 |
|
| 2145 |
|
| 2146 |
|
| 2147 |
|
| 2148 |
|
| 2149 |
if (try_noun_before_num && wrdtyp == PRP_ADJ) |
| 2150 |
{ |
| 2151 |
|
| 2152 |
wrdtyp = PRP_NOUN; |
| 2153 |
|
| 2154 |
|
| 2155 |
try_noun_before_num = FALSE; |
| 2156 |
|
| 2157 |
|
| 2158 |
goto add_words; |
| 2159 |
} |
| 2160 |
|
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
if (try_plural && wrdtyp != PRP_PLURAL) |
| 2166 |
{ |
| 2167 |
|
| 2168 |
wrdtyp = PRP_PLURAL; |
| 2169 |
|
| 2170 |
|
| 2171 |
try_plural = FALSE; |
| 2172 |
|
| 2173 |
|
| 2174 |
goto add_words; |
| 2175 |
} |
| 2176 |
|
| 2177 |
|
| 2178 |
|
| 2179 |
|
| 2180 |
|
| 2181 |
if (try_endadj && wrdtyp != PRP_ADJ) |
| 2182 |
{ |
| 2183 |
|
| 2184 |
wrdtyp = PRP_ADJ; |
| 2185 |
|
| 2186 |
|
| 2187 |
trying_endadj = TRUE; |
| 2188 |
|
| 2189 |
|
| 2190 |
try_endadj = FALSE; |
| 2191 |
|
| 2192 |
|
| 2193 |
goto add_words; |
| 2194 |
} |
| 2195 |
|
| 2196 |
|
| 2197 |
|
| 2198 |
|
| 2199 |
|
| 2200 |
|
| 2201 |
|
| 2202 |
if (vocisdigit(wrd[0]) && wrdtyp == PRP_ADJ && first + 1 != last) |
| 2203 |
{ |
| 2204 |
wrd = "#"; |
| 2205 |
len = 1; |
| 2206 |
goto add_words; |
| 2207 |
} |
| 2208 |
|
| 2209 |
list[cnt] = MCMONINV; |
| 2210 |
return cnt; |
| 2211 |
} |
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
static void vocaddof(voccxdef *ctx, char *buf) |
| 2218 |
{ |
| 2219 |
if (ctx->voccxspp) |
| 2220 |
{ |
| 2221 |
size_t len = ctx->voccxspp[1]; |
| 2222 |
size_t oldlen = strlen(buf); |
| 2223 |
memcpy(buf + oldlen, ctx->voccxspp + 2, len); |
| 2224 |
buf[len + oldlen] = '\0'; |
| 2225 |
} |
| 2226 |
else |
| 2227 |
strcat(buf, "of"); |
| 2228 |
} |
| 2229 |
|
| 2230 |
|
| 2231 |
|
| 2232 |
|
| 2233 |
|
| 2234 |
|
| 2235 |
|
| 2236 |
|
| 2237 |
|
| 2238 |
|
| 2239 |
|
| 2240 |
static int voc_pnp_hook(voccxdef *ctx, char *cmd[], int typelist[], |
| 2241 |
int cur, int *next, int complain, |
| 2242 |
vocoldef *out_nounlist, int *out_nouncount, |
| 2243 |
int chkact, int *no_match) |
| 2244 |
{ |
| 2245 |
runcxdef *rcx = ctx->voccxrun; |
| 2246 |
runsdef val; |
| 2247 |
int wordcnt; |
| 2248 |
char **cmdp; |
| 2249 |
int outcnt; |
| 2250 |
vocoldef *outp; |
| 2251 |
int i; |
| 2252 |
|
| 2253 |
|
| 2254 |
if (ctx->voccxpnp == MCMONINV) |
| 2255 |
return VOC_PNP_DEFAULT; |
| 2256 |
|
| 2257 |
|
| 2258 |
val.runstyp = (chkact ? DAT_TRUE : DAT_NIL); |
| 2259 |
runpush(rcx, val.runstyp, &val); |
| 2260 |
|
| 2261 |
|
| 2262 |
val.runstyp = (complain ? DAT_TRUE : DAT_NIL); |
| 2263 |
runpush(rcx, val.runstyp, &val); |
| 2264 |
|
| 2265 |
|
| 2266 |
runpnum(rcx, cur + 1); |
| 2267 |
|
| 2268 |
|
| 2269 |
for (wordcnt = 0, cmdp = cmd ; *cmdp != 0 && **cmdp != '\0' ; |
| 2270 |
++wordcnt, ++cmdp) ; |
| 2271 |
|
| 2272 |
|
| 2273 |
voc_push_numlist(ctx, (uint *)typelist, wordcnt); |
| 2274 |
|
| 2275 |
|
| 2276 |
voc_push_strlist_arr(ctx, cmd, wordcnt); |
| 2277 |
|
| 2278 |
|
| 2279 |
runfn(rcx, ctx->voccxpnp, 5); |
| 2280 |
|
| 2281 |
|
| 2282 |
if (runtostyp(rcx) == DAT_NUMBER) |
| 2283 |
{ |
| 2284 |
|
| 2285 |
return (int)runpopnum(rcx); |
| 2286 |
} |
| 2287 |
else if (runtostyp(rcx) == DAT_LIST) |
| 2288 |
{ |
| 2289 |
uchar *lstp; |
| 2290 |
uint lstsiz; |
| 2291 |
|
| 2292 |
|
| 2293 |
lstp = runpoplst(rcx); |
| 2294 |
|
| 2295 |
|
| 2296 |
lstsiz = osrp2(lstp); |
| 2297 |
lstsiz -= 2; |
| 2298 |
lstp += 2; |
| 2299 |
|
| 2300 |
|
| 2301 |
if (lstsiz > 1 && *lstp == DAT_NUMBER) |
| 2302 |
{ |
| 2303 |
|
| 2304 |
*next = osrp4(lstp+1) - 1; |
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
if (*next < cur) |
| 2313 |
*next = cur; |
| 2314 |
else if (*next > wordcnt) |
| 2315 |
*next = wordcnt; |
| 2316 |
|
| 2317 |
|
| 2318 |
lstadv(&lstp, &lstsiz); |
| 2319 |
} |
| 2320 |
else |
| 2321 |
{ |
| 2322 |
|
| 2323 |
return VOC_PNP_DEFAULT; |
| 2324 |
} |
| 2325 |
|
| 2326 |
|
| 2327 |
for (outcnt = 0, outp = out_nounlist ; lstsiz > 0 ; ) |
| 2328 |
{ |
| 2329 |
|
| 2330 |
if (outcnt >= VOCMAXAMBIG - 1) |
| 2331 |
break; |
| 2332 |
|
| 2333 |
|
| 2334 |
if (*lstp == DAT_NIL) |
| 2335 |
{ |
| 2336 |
|
| 2337 |
outp->vocolobj = MCMONINV; |
| 2338 |
|
| 2339 |
|
| 2340 |
lstadv(&lstp, &lstsiz); |
| 2341 |
} |
| 2342 |
else if (*lstp == DAT_OBJECT) |
| 2343 |
{ |
| 2344 |
|
| 2345 |
outp->vocolobj = osrp2(lstp+1); |
| 2346 |
|
| 2347 |
|
| 2348 |
lstadv(&lstp, &lstsiz); |
| 2349 |
} |
| 2350 |
else |
| 2351 |
{ |
| 2352 |
|
| 2353 |
lstadv(&lstp, &lstsiz); |
| 2354 |
continue; |
| 2355 |
} |
| 2356 |
|
| 2357 |
|
| 2358 |
if (lstsiz > 0 && *lstp == DAT_NUMBER) |
| 2359 |
{ |
| 2360 |
|
| 2361 |
outp->vocolflg = (int)osrp4(lstp+1); |
| 2362 |
|
| 2363 |
|
| 2364 |
lstadv(&lstp, &lstsiz); |
| 2365 |
} |
| 2366 |
else |
| 2367 |
{ |
| 2368 |
|
| 2369 |
outp->vocolflg = 0; |
| 2370 |
} |
| 2371 |
|
| 2372 |
|
| 2373 |
outp->vocolfst = cmd[cur]; |
| 2374 |
outp->vocollst = cmd[*next - 1]; |
| 2375 |
|
| 2376 |
|
| 2377 |
++outp; |
| 2378 |
++outcnt; |
| 2379 |
} |
| 2380 |
|
| 2381 |
|
| 2382 |
outp->vocolobj = MCMONINV; |
| 2383 |
outp->vocolflg = 0; |
| 2384 |
|
| 2385 |
|
| 2386 |
*out_nouncount = outcnt; |
| 2387 |
|
| 2388 |
|
| 2389 |
|
| 2390 |
|
| 2391 |
|
| 2392 |
if (no_match != 0) |
| 2393 |
*no_match = (outcnt == 0 && *next > cur); |
| 2394 |
|
| 2395 |
|
| 2396 |
|
| 2397 |
|
| 2398 |
|
| 2399 |
|
| 2400 |
|
| 2401 |
|
| 2402 |
|
| 2403 |
|
| 2404 |
for (i = cur ; i < *next ; ++i) |
| 2405 |
{ |
| 2406 |
|
| 2407 |
if ((typelist[i] & VOCT_UNKNOWN) != 0) |
| 2408 |
--(ctx->voccxunknown); |
| 2409 |
} |
| 2410 |
for (i = 0, outp = out_nounlist ; i < outcnt ; ++i) |
| 2411 |
{ |
| 2412 |
|
| 2413 |
if ((outp->vocolflg & VOCS_UNKNOWN) != 0) |
| 2414 |
++(ctx->voccxunknown); |
| 2415 |
} |
| 2416 |
|
| 2417 |
|
| 2418 |
return VOC_PNP_SUCCESS; |
| 2419 |
} |
| 2420 |
else |
| 2421 |
{ |
| 2422 |
|
| 2423 |
|
| 2424 |
|
| 2425 |
|
| 2426 |
rundisc(rcx); |
| 2427 |
return VOC_PNP_DEFAULT; |
| 2428 |
} |
| 2429 |
} |
| 2430 |
|
| 2431 |
|
| 2432 |
|
| 2433 |
|
| 2434 |
|
| 2435 |
void voc_make_obj_name(voccxdef *ctx, char *namebuf, char *cmd[], |
| 2436 |
int firstwrd, int lastwrd) |
| 2437 |
{ |
| 2438 |
int i; |
| 2439 |
|
| 2440 |
|
| 2441 |
for (i = firstwrd, namebuf[0] = '\0' ; i < lastwrd ; ++i) |
| 2442 |
{ |
| 2443 |
if (voc_check_special(ctx, cmd[i], VOCW_OF)) |
| 2444 |
vocaddof(ctx, namebuf); |
| 2445 |
else |
| 2446 |
strcat(namebuf, cmd[i]); |
| 2447 |
|
| 2448 |
if (cmd[i][strlen(cmd[i])-1] == '.' && i + 1 < lastwrd) |
| 2449 |
strcat(namebuf, "\\"); |
| 2450 |
|
| 2451 |
if (i + 1 < lastwrd) |
| 2452 |
strcat(namebuf, " "); |
| 2453 |
} |
| 2454 |
} |
| 2455 |
|
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
void voc_make_obj_name_from_list(voccxdef *ctx, char *namebuf, |
| 2460 |
char *cmd[], char *firstwrd, char *lastwrd) |
| 2461 |
{ |
| 2462 |
int i, i1, i2; |
| 2463 |
|
| 2464 |
|
| 2465 |
for (i = i1 = i2 = 0 ; cmd[i] != 0 && *cmd[i] != 0 ; ++i) |
| 2466 |
{ |
| 2467 |
if (cmd[i] == firstwrd) |
| 2468 |
i1 = i; |
| 2469 |
if (cmd[i] == lastwrd) |
| 2470 |
i2 = i + 1; |
| 2471 |
} |
| 2472 |
|
| 2473 |
|
| 2474 |
voc_make_obj_name(ctx, namebuf, cmd, i1, i2); |
| 2475 |
} |
| 2476 |
|
| 2477 |
|
| 2478 |
|
| 2479 |
|
| 2480 |
|
| 2481 |
|
| 2482 |
|
| 2483 |
|
| 2484 |
|
| 2485 |
|
| 2486 |
|
| 2487 |
|
| 2488 |
|
| 2489 |
|
| 2490 |
|
| 2491 |
|
| 2492 |
|
| 2493 |
|
| 2494 |
|
| 2495 |
|
| 2496 |
|
| 2497 |
|
| 2498 |
static int vocg1o(voccxdef *ctx, char *cmd[], int typelist[], |
| 2499 |
int cur, int *next, int complain, vocoldef *nounlist, |
| 2500 |
int chkact, int *no_match) |
| 2501 |
{ |
| 2502 |
int l1; |
| 2503 |
int firstwrd; |
| 2504 |
int i; |
| 2505 |
int ofword = -1; |
| 2506 |
int hypothetical_last = -1; |
| 2507 |
int trim_flags = 0; |
| 2508 |
int outcnt = 0; |
| 2509 |
objnum *list1; |
| 2510 |
uint *flags1; |
| 2511 |
objnum *list2; |
| 2512 |
uint *flags2; |
| 2513 |
char *namebuf; |
| 2514 |
int has_any = FALSE; |
| 2515 |
uchar *save_sp; |
| 2516 |
int found_plural; |
| 2517 |
int unknown_count; |
| 2518 |
int trying_count = FALSE; |
| 2519 |
int retry_with_count; |
| 2520 |
|
| 2521 |
voc_enter(ctx, &save_sp); |
| 2522 |
VOC_MAX_ARRAY(ctx, objnum, list1); |
| 2523 |
VOC_MAX_ARRAY(ctx, uint, flags1); |
| 2524 |
VOC_MAX_ARRAY(ctx, objnum, list2); |
| 2525 |
VOC_MAX_ARRAY(ctx, uint, flags2); |
| 2526 |
VOC_STK_ARRAY(ctx, char, namebuf, VOCBUFSIZ); |
| 2527 |
|
| 2528 |
|
| 2529 |
if (no_match != 0) |
| 2530 |
*no_match = FALSE; |
| 2531 |
|
| 2532 |
|
| 2533 |
*next = cur; |
| 2534 |
|
| 2535 |
|
| 2536 |
if (cur == -1 || !cmd[cur]) { VOC_RETVAL(ctx, save_sp, 0); } |
| 2537 |
|
| 2538 |
|
| 2539 |
if (ctx->voccxflg & VOCCXFDBG) |
| 2540 |
tioputs(ctx->vocxtio, |
| 2541 |
chkact ? ". Checking for actor\\n" |
| 2542 |
: ". Reading noun phrase\\n"); |
| 2543 |
|
| 2544 |
|
| 2545 |
switch(voc_pnp_hook(ctx, cmd, typelist, cur, next, complain, |
| 2546 |
nounlist, &outcnt, chkact, no_match)) |
| 2547 |
{ |
| 2548 |
case VOC_PNP_DEFAULT: |
| 2549 |
|
| 2550 |
break; |
| 2551 |
|
| 2552 |
case VOC_PNP_ERROR: |
| 2553 |
default: |
| 2554 |
|
| 2555 |
VOC_RETVAL(ctx, save_sp, -1); |
| 2556 |
|
| 2557 |
case VOC_PNP_SUCCESS: |
| 2558 |
|
| 2559 |
VOC_RETVAL(ctx, save_sp, outcnt); |
| 2560 |
} |
| 2561 |
|
| 2562 |
|
| 2563 |
if (*cmd[cur] == '"') |
| 2564 |
{ |
| 2565 |
|
| 2566 |
if (chkact) { VOC_RETVAL(ctx, save_sp, 0); } |
| 2567 |
|
| 2568 |
if (ctx->voccxflg & VOCCXFDBG) |
| 2569 |
tioputs(ctx->vocxtio, "... found quoted string\\n"); |
| 2570 |
|
| 2571 |
nounlist[outcnt].vocolobj = MCMONINV; |
| 2572 |
nounlist[outcnt].vocolflg = VOCS_STR; |
| 2573 |
nounlist[outcnt].vocolfst = nounlist[outcnt].vocollst = cmd[cur]; |
| 2574 |
*next = ++cur; |
| 2575 |
++outcnt; |
| 2576 |
VOC_RETVAL(ctx, save_sp, outcnt); |
| 2577 |
} |
| 2578 |
|
| 2579 |
|
| 2580 |
if ((vocspec(cmd[cur], VOCW_ALL) |
| 2581 |
|| vocspec(cmd[cur], VOCW_BOTH) |
| 2582 |
|| vocspec(cmd[cur], VOCW_ANY)) && |
| 2583 |
cmd[cur+1] != (char *)0) |
| 2584 |
{ |
| 2585 |
int nxt; |
| 2586 |
int n = cur+1; |
| 2587 |
int has_of; |
| 2588 |
|
| 2589 |
|
| 2590 |
if (chkact) { VOC_RETVAL(ctx, save_sp, 0); } |
| 2591 |
|
| 2592 |
|
| 2593 |
has_any = vocspec(cmd[cur], VOCW_ANY); |
| 2594 |
|
| 2595 |
|
| 2596 |
if (voc_check_special(ctx, cmd[n], VOCW_OF)) |
| 2597 |
{ |
| 2598 |
if (ctx->voccxflg & VOCCXFDBG) |
| 2599 |
tioputs(ctx->vocxtio, "... found ALL/ANY/BOTH/EITHER OF\\n"); |
| 2600 |
|
| 2601 |
has_of = TRUE; |
| 2602 |
n++; |
| 2603 |
if (!cmd[n]) |
| 2604 |
{ |
| 2605 |
char *p; |
| 2606 |
int ver; |
| 2607 |
|
| 2608 |
if (vocspec(cmd[cur], VOCW_ALL)) |
| 2609 |
{ |
| 2610 |
ver = VOCERR(4); |
| 2611 |
p = "I think you left something out after \"all of\"."; |
| 2612 |
} |
| 2613 |
else if (vocspec(cmd[cur], VOCW_ANY)) |
| 2614 |
{ |
| 2615 |
ver = VOCERR(29); |
| 2616 |
p = "I think you left something out after \"any of\"."; |
| 2617 |
} |
| 2618 |
else |
| 2619 |
{ |
| 2620 |
ver = VOCERR(5); |
| 2621 |
p = "There's something missing after \"both of\"."; |
| 2622 |
} |
| 2623 |
vocerr(ctx, ver, p); |
| 2624 |
VOC_RETVAL(ctx, save_sp, -1); |
| 2625 |
} |
| 2626 |
} |
| 2627 |
else |
| 2628 |
has_of = FALSE; |
| 2629 |
|
| 2630 |
nxt = n; |
| 2631 |
if (typelist[n] & VOCT_ARTICLE) ++n; |
| 2632 |
for ( ;; ) |
| 2633 |
{ |
| 2634 |
if (!cmd[n]) |
| 2635 |
break; |
| 2636 |
|
| 2637 |
if (voc_check_special(ctx, cmd[n], VOCW_OF)) |
| 2638 |
{ |
| 2639 |
++n; |
| 2640 |
if (!cmd[n]) |
| 2641 |
{ |
| 2642 |
vocerr(ctx, VOCERR(6), "I expected a noun after \"of\"."); |
| 2643 |
VOC_RETVAL(ctx, save_sp, -1); |
| 2644 |
} |
| 2645 |
if (*cmd[n] & VOCT_ARTICLE) ++n; |
| 2646 |
} |
| 2647 |
else if (typelist[n] & (VOCT_ADJ | VOCT_NOUN)) |
| 2648 |
++n; |
| 2649 |
else |
| 2650 |
break; |
| 2651 |
} |
| 2652 |
|
| 2653 |
|
| 2654 |
|
| 2655 |
|
| 2656 |
|
| 2657 |
|
| 2658 |
|
| 2659 |
|
| 2660 |
if (n > cur && ((typelist[n-1] & VOCT_PLURAL) |
| 2661 |
|| (has_any && !has_of))) |
| 2662 |
{ |
| 2663 |
if (ctx->voccxflg & VOCCXFDBG) |
| 2664 |
tioputs(ctx->vocxtio, |
| 2665 |
"... found ALL/ANY/BOTH/EITHER + noun phrase\\n"); |
| 2666 |
|
| 2667 |
cur = nxt; |
| 2668 |
} |
| 2669 |
} |
| 2670 |
|
| 2671 |
if (vocspec(cmd[cur], VOCW_ALL) && !has_any) |
| 2672 |
{ |
| 2673 |
|
| 2674 |
if (chkact) |
| 2675 |
{ |
| 2676 |
VOC_RETVAL(ctx, save_sp, 0); |
| 2677 |
} |
| 2678 |
|
| 2679 |
if (ctx->voccxflg & VOCCXFDBG) |
| 2680 |
tioputs(ctx->vocxtio, "... found ALL\\n"); |
| 2681 |
|
| 2682 |
nounlist[outcnt].vocolobj = MCMONINV; |
| 2683 |
nounlist[outcnt].vocolflg = VOCS_ALL; |
| 2684 |
nounlist[outcnt].vocolfst = nounlist[outcnt].vocollst = cmd[cur]; |
| 2685 |
++outcnt; |
| 2686 |
++cur; |
| 2687 |
|
| 2688 |
if (cmd[cur] && vocspec(cmd[cur], VOCW_BUT)) |
| 2689 |
{ |
| 2690 |
int cnt; |
| 2691 |
int i; |
| 2692 |
vocoldef *xlist; |
| 2693 |
uchar *inner_save_sp; |
| 2694 |
|
| 2695 |
if (ctx->voccxflg & VOCCXFDBG) |
| 2696 |
tioputs(ctx->vocxtio, "... found ALL EXCEPT\\n"); |
| 2697 |
|
| 2698 |
voc_enter(ctx, &inner_save_sp); |
| 2699 |
VOC_MAX_ARRAY(ctx, vocoldef, xlist); |
| 2700 |
|
| 2701 |
cur++; |
| 2702 |
cnt = vocgobj(ctx, cmd, typelist, cur, next, complain, xlist, 1, |
| 2703 |
chkact, 0); |
| 2704 |
if (cnt < 0) |
| 2705 |
{ |
| 2706 |
|
| 2707 |
|
| 2708 |
|
| 2709 |
|
| 2710 |
|
| 2711 |
|
| 2712 |
|
| 2713 |
|
| 2714 |
VOC_RETVAL(ctx, save_sp, cnt); |
| 2715 |
} |
| 2716 |
cur = *next; |
| 2717 |
for (i = 0 ; i < cnt ; ++i) |
| 2718 |
{ |
| 2719 |
OSCPYSTRUCT(nounlist[outcnt], xlist[i]); |
| 2720 |
nounlist[outcnt].vocolflg |= VOCS_EXCEPT; |
| 2721 |
++outcnt; |
| 2722 |
} |
| 2723 |
|
| 2724 |
voc_leave(ctx, inner_save_sp); |
| 2725 |
} |
| 2726 |
*next = cur; |
| 2727 |
nounlist[outcnt].vocolobj = MCMONINV; |
| 2728 |
nounlist[outcnt].vocolflg = 0; |
| 2729 |
VOC_RETVAL(ctx, save_sp, outcnt); |
| 2730 |
} |
| 2731 |
|
| 2732 |
switch(*cmd[cur]) |
| 2733 |
{ |
| 2734 |
case VOCW_IT: |
| 2735 |
nounlist[outcnt].vocolflg = VOCS_IT; |
| 2736 |
goto do_special; |
| 2737 |
case VOCW_THEM: |
| 2738 |
nounlist[outcnt].vocolflg = VOCS_THEM; |
| 2739 |
goto do_special; |
| 2740 |
case VOCW_HIM: |
| 2741 |
nounlist[outcnt].vocolflg = VOCS_HIM; |
| 2742 |
goto do_special; |
| 2743 |
case VOCW_HER: |
| 2744 |
nounlist[outcnt].vocolflg = VOCS_HER; |
| 2745 |
|
| 2746 |
do_special: |
| 2747 |
if (ctx->voccxflg & VOCCXFDBG) |
| 2748 |
tioputs(ctx->vocxtio, "... found pronoun\\n"); |
| 2749 |
|
| 2750 |
*next = cur + 1; |
| 2751 |
nounlist[outcnt].vocolobj = MCMONINV; |
| 2752 |
nounlist[outcnt].vocolfst = nounlist[outcnt].vocollst = cmd[cur]; |
| 2753 |
++outcnt; |
| 2754 |
VOC_RETVAL(ctx, save_sp, outcnt); |
| 2755 |
default: |
| 2756 |
break; |
| 2757 |
} |
| 2758 |
|
| 2759 |
if (((typelist[cur] |
| 2760 |
& (VOCT_ARTICLE | VOCT_ADJ | VOCT_NOUN | VOCT_UNKNOWN)) == 0) |
| 2761 |
&& !vocisdigit(*cmd[cur])) |
| 2762 |
{ |
| 2763 |
VOC_RETVAL(ctx, save_sp, 0); |
| 2764 |
} |
| 2765 |
|
| 2766 |
if (typelist[cur] & VOCT_ARTICLE) |
| 2767 |
{ |
| 2768 |
++cur; |
| 2769 |
if (cmd[cur] == (char *)0 |
| 2770 |
|| ((typelist[cur] & (VOCT_ADJ | VOCT_NOUN | VOCT_UNKNOWN)) == 0 |
| 2771 |
&& !vocisdigit(*cmd[cur]))) |
| 2772 |
{ |
| 2773 |
vocerr(ctx, VOCERR(7), "An article must be followed by a noun."); |
| 2774 |
*next = cur; |
| 2775 |
VOC_RETVAL(ctx, save_sp, -1); |
| 2776 |
} |
| 2777 |
} |
| 2778 |
|
| 2779 |
|
| 2780 |
firstwrd = cur; |
| 2781 |
|
| 2782 |
|
| 2783 |
for (found_plural = FALSE, unknown_count = 0, l1 = 0 ; ; ) |
| 2784 |
{ |
| 2785 |
if (cmd[cur] == (char *)0) |
| 2786 |
break; |
| 2787 |
|
| 2788 |
if (typelist[cur] & VOCT_ADJ) |
| 2789 |
++cur; |
| 2790 |
else if (typelist[cur] & VOCT_UNKNOWN) |
| 2791 |
{ |
| 2792 |
|
| 2793 |
|
| 2794 |
|
| 2795 |
|
| 2796 |
|
| 2797 |
++unknown_count; |
| 2798 |
++cur; |
| 2799 |
} |
| 2800 |
else if (typelist[cur] & VOCT_NOUN) |
| 2801 |
{ |
| 2802 |
++cur; |
| 2803 |
if (cmd[cur] == (char *)0) break; |
| 2804 |
if (vocisdigit(*cmd[cur])) ++cur; |
| 2805 |
if (cmd[cur] == (char *)0) break; |
| 2806 |
if (!voc_check_special(ctx, cmd[cur], VOCW_OF)) break; |
| 2807 |
} |
| 2808 |
else if (vocisdigit(*cmd[cur])) |
| 2809 |
++cur; |
| 2810 |
else if (voc_check_special(ctx, cmd[cur], VOCW_OF)) |
| 2811 |
{ |
| 2812 |
++cur; |
| 2813 |
if (ofword != -1) |
| 2814 |
{ |
| 2815 |
|
| 2816 |
--cur; |
| 2817 |
break; |
| 2818 |
} |
| 2819 |
ofword = cur-1; |
| 2820 |
if (typelist[cur] & VOCT_ARTICLE) |
| 2821 |
++cur; |
| 2822 |
} |
| 2823 |
else |
| 2824 |
break; |
| 2825 |
|
| 2826 |
|
| 2827 |
if (cmd[cur] != 0 && (typelist[cur] & VOCT_PLURAL) != 0) |
| 2828 |
found_plural = TRUE; |
| 2829 |
} |
| 2830 |
|
| 2831 |
try_again: |
| 2832 |
|
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
voc_make_obj_name(ctx, namebuf, cmd, firstwrd, cur); |
| 2837 |
|
| 2838 |
|
| 2839 |
*next = cur; |
| 2840 |
|
| 2841 |
|
| 2842 |
|
| 2843 |
|
| 2844 |
|
| 2845 |
|
| 2846 |
|
| 2847 |
if (unknown_count > 0) |
| 2848 |
{ |
| 2849 |
|
| 2850 |
|
| 2851 |
|
| 2852 |
|
| 2853 |
|
| 2854 |
|
| 2855 |
|
| 2856 |
for ( ; unknown_count > 0 ; --unknown_count) |
| 2857 |
{ |
| 2858 |
nounlist[outcnt].vocolobj = MCMONINV; |
| 2859 |
nounlist[outcnt].vocolflg = VOCS_UNKNOWN; |
| 2860 |
nounlist[outcnt].vocolfst = cmd[firstwrd]; |
| 2861 |
nounlist[outcnt].vocollst = cmd[cur-1]; |
| 2862 |
++outcnt; |
| 2863 |
} |
| 2864 |
nounlist[outcnt].vocolobj = MCMONINV; |
| 2865 |
nounlist[outcnt].vocolflg = 0; |
| 2866 |
VOC_RETVAL(ctx, save_sp, outcnt); |
| 2867 |
} |
| 2868 |
|
| 2869 |
|
| 2870 |
l1 = vocgol(ctx, list1, flags1, cmd, typelist, |
| 2871 |
firstwrd, firstwrd, cur, ofword); |
| 2872 |
|
| 2873 |
|
| 2874 |
|
| 2875 |
|
| 2876 |
|
| 2877 |
|
| 2878 |
retry_with_count = ((vocisdigit(*cmd[firstwrd]) && found_plural) |
| 2879 |
|| (vocisdigit(*cmd[firstwrd]) |
| 2880 |
&& cur != firstwrd+1 |
| 2881 |
&& atoi(cmd[firstwrd]) == 1)); |
| 2882 |
|
| 2883 |
|
| 2884 |
if (l1 <= 0) |
| 2885 |
{ |
| 2886 |
if (chkact) { VOC_RETVAL(ctx, save_sp, 0); } |
| 2887 |
|
| 2888 |
if (vocisdigit(*cmd[firstwrd])) |
| 2889 |
{ |
| 2890 |
if (retry_with_count) |
| 2891 |
{ |
| 2892 |
|
| 2893 |
trying_count = TRUE; |
| 2894 |
|
| 2895 |
|
| 2896 |
retry_with_count = FALSE; |
| 2897 |
} |
| 2898 |
else |
| 2899 |
{ |
| 2900 |
|
| 2901 |
nounlist[outcnt].vocolobj = MCMONINV; |
| 2902 |
nounlist[outcnt].vocolflg = VOCS_NUM; |
| 2903 |
nounlist[outcnt].vocolfst = nounlist[outcnt].vocollst = |
| 2904 |
cmd[firstwrd]; |
| 2905 |
*next = firstwrd + 1; |
| 2906 |
++outcnt; |
| 2907 |
nounlist[outcnt].vocolobj = MCMONINV; |
| 2908 |
nounlist[outcnt].vocolflg = 0; |
| 2909 |
VOC_RETVAL(ctx, save_sp, outcnt); |
| 2910 |
} |
| 2911 |
} |
| 2912 |
else |
| 2913 |
{ |
| 2914 |
|
| 2915 |
|
| 2916 |
|
| 2917 |
|
| 2918 |
|
| 2919 |
if (l1 == 0) |
| 2920 |
vocerr(ctx, VOCERR(9), "I don't see any %s here.", namebuf); |
| 2921 |
|
| 2922 |
|
| 2923 |
VOC_RETVAL(ctx, save_sp, -1); |
| 2924 |
} |
| 2925 |
} |
| 2926 |
|
| 2927 |
retry_exclude_first: |
| 2928 |
for (i = firstwrd + 1 ; i < cur ; ++i) |
| 2929 |
{ |
| 2930 |
int l2; |
| 2931 |
|
| 2932 |
if (voc_check_special(ctx, cmd[i], VOCW_OF) |
| 2933 |
|| (typelist[i] & VOCT_ARTICLE)) |
| 2934 |
continue; |
| 2935 |
|
| 2936 |
|
| 2937 |
l2 = vocgol(ctx, list2, flags2, cmd, typelist, |
| 2938 |
firstwrd, i, cur, ofword); |
| 2939 |
|
| 2940 |
|
| 2941 |
if (l2 < 0) |
| 2942 |
{ |
| 2943 |
|
| 2944 |
VOC_RETVAL(ctx, save_sp, -1); |
| 2945 |
} |
| 2946 |
|
| 2947 |
|
| 2948 |
|
| 2949 |
|
| 2950 |
|
| 2951 |
|
| 2952 |
|
| 2953 |
|
| 2954 |
if (l1 == 0) |
| 2955 |
{ |
| 2956 |
|
| 2957 |
l1 = l2; |
| 2958 |
memcpy(list1, list2, (size_t)((l1+1) * sizeof(list1[0]))); |
| 2959 |
memcpy(flags1, flags2, (size_t)(l1 * sizeof(flags1[0]))); |
| 2960 |
} |
| 2961 |
else |
| 2962 |
{ |
| 2963 |
|
| 2964 |
l1 = vocisect_flags(list1, flags1, list2, flags2); |
| 2965 |
} |
| 2966 |
|
| 2967 |
|
| 2968 |
|
| 2969 |
|
| 2970 |
|
| 2971 |
if (l1 == 0) |
| 2972 |
{ |
| 2973 |
if (ctx->voccxflg & VOCCXFDBG) |
| 2974 |
tioputs(ctx->vocxtio, |
| 2975 |
"... can't find any objects matching these words\\n"); |
| 2976 |
|
| 2977 |
|
| 2978 |
|
| 2979 |
|
| 2980 |
|
| 2981 |
|
| 2982 |
if (ofword != -1) |
| 2983 |
{ |
| 2984 |
if (ctx->voccxflg & VOCCXFDBG) |
| 2985 |
tioputs(ctx->vocxtio, |
| 2986 |
"... dropping the part after OF and retrying\\n"); |
| 2987 |
|
| 2988 |
|
| 2989 |
|
| 2990 |
|
| 2991 |
|
| 2992 |
hypothetical_last = cur; |
| 2993 |
trim_flags |= VOCS_TRIMPREP; |
| 2994 |
cur = ofword; |
| 2995 |
|
| 2996 |
|
| 2997 |
ofword = -1; |
| 2998 |
|
| 2999 |
|
| 3000 |
goto try_again; |
| 3001 |
} |
| 3002 |
|
| 3003 |
|
| 3004 |
|
| 3005 |
|
| 3006 |
|
| 3007 |
if (retry_with_count) |
| 3008 |
{ |
| 3009 |
if (ctx->voccxflg & VOCCXFDBG) |
| 3010 |
tioputs(ctx->vocxtio, |
| 3011 |
"... treating the number as a count and retrying\\n"); |
| 3012 |
|
| 3013 |
|
| 3014 |
retry_with_count = FALSE; |
| 3015 |
trying_count = TRUE; |
| 3016 |
|
| 3017 |
|
| 3018 |
goto retry_exclude_first; |
| 3019 |
} |
| 3020 |
|
| 3021 |
|
| 3022 |
|
| 3023 |
|
| 3024 |
|
| 3025 |
|
| 3026 |
for (i = cur - 1; i > firstwrd ; --i) |
| 3027 |
{ |
| 3028 |
if (typelist[i] & VOCT_PREP) |
| 3029 |
{ |
| 3030 |
if (ctx->voccxflg & VOCCXFDBG) |
| 3031 |
tioputs(ctx->vocxtio, |
| 3032 |
"... changing word to prep and retrying\\n"); |
| 3033 |
|
| 3034 |
hypothetical_last = cur; |
| 3035 |
trim_flags |= VOCS_TRIMPREP; |
| 3036 |
cur = i; |
| 3037 |
goto try_again; |
| 3038 |
} |
| 3039 |
} |
| 3040 |
|
| 3041 |
|
| 3042 |
if (chkact) { VOC_RETVAL(ctx, save_sp, 0); } |
| 3043 |
|
| 3044 |
|
| 3045 |
|
| 3046 |
|
| 3047 |
|
| 3048 |
if (complain) |
| 3049 |
vocerr(ctx, VOCERR(9), "I don't see any %s here.", namebuf); |
| 3050 |
if (no_match != 0) |
| 3051 |
*no_match = TRUE; |
| 3052 |
VOC_RETVAL(ctx, save_sp, 0); |
| 3053 |
} |
| 3054 |
} |
| 3055 |
|
| 3056 |
|
| 3057 |
|
| 3058 |
|
| 3059 |
|
| 3060 |
if (ctx->voccxflg & VOCCXFDBG) |
| 3061 |
tioputs(ctx->vocxtio, "... found objects matching vocabulary:\\n"); |
| 3062 |
|
| 3063 |
|
| 3064 |
for (i = 0 ; i < l1 ; ++i) |
| 3065 |
{ |
| 3066 |
if (ctx->voccxflg & VOCCXFDBG) |
| 3067 |
{ |
| 3068 |
tioputs(ctx->voccxtio, "..... "); |
| 3069 |
runppr(ctx->voccxrun, list1[i], PRP_SDESC, 0); |
| 3070 |
tioflushn(ctx->voccxtio, 1); |
| 3071 |
} |
| 3072 |
|
| 3073 |
nounlist[outcnt].vocolfst = cmd[firstwrd]; |
| 3074 |
nounlist[outcnt].vocollst = cmd[cur-1]; |
| 3075 |
nounlist[outcnt].vocolflg = |
| 3076 |
flags1[i] | (trying_count ? VOCS_COUNT : 0) | trim_flags; |
| 3077 |
if (trim_flags) |
| 3078 |
nounlist[outcnt].vocolhlst = cmd[hypothetical_last - 1]; |
| 3079 |
if (has_any) |
| 3080 |
nounlist[outcnt].vocolflg |= VOCS_ANY; |
| 3081 |
nounlist[outcnt++].vocolobj = list1[i]; |
| 3082 |
if (outcnt > VOCMAXAMBIG) |
| 3083 |
{ |
| 3084 |
vocerr(ctx, VOCERR(10), |
| 3085 |
"You're referring to too many objects with \"%s\".", |
| 3086 |
namebuf); |
| 3087 |
VOC_RETVAL(ctx, save_sp, -2); |
| 3088 |
} |
| 3089 |
} |
| 3090 |
|
| 3091 |
|
| 3092 |
|
| 3093 |
|
| 3094 |
|
| 3095 |
|
| 3096 |
|
| 3097 |
|
| 3098 |
|
| 3099 |
if (firstwrd + 1 == cur && vocisdigit(*cmd[firstwrd])) |
| 3100 |
{ |
| 3101 |
|
| 3102 |
nounlist[outcnt].vocolobj = ctx->voccxnum; |
| 3103 |
nounlist[outcnt].vocolflg = VOCS_NUM; |
| 3104 |
nounlist[outcnt].vocolfst = nounlist[outcnt].vocollst = |
| 3105 |
cmd[firstwrd]; |
| 3106 |
++outcnt; |
| 3107 |
} |
| 3108 |
|
| 3109 |
|
| 3110 |
nounlist[outcnt].vocolobj = MCMONINV; |
| 3111 |
nounlist[outcnt].vocolflg = 0; |
| 3112 |
|
| 3113 |
|
| 3114 |
VOC_RETVAL(ctx, save_sp, outcnt); |
| 3115 |
} |
| 3116 |
|
| 3117 |
|
| 3118 |
|
| 3119 |
|
| 3120 |
|
| 3121 |
|
| 3122 |
|
| 3123 |
|
| 3124 |
|
| 3125 |
|
| 3126 |
int vocgobj(voccxdef *ctx, char *cmd[], int typelist[], |
| 3127 |
int cur, int *next, int complain, vocoldef *nounlist, |
| 3128 |
int multi, int chkact, int *no_match) |
| 3129 |
{ |
| 3130 |
int cnt; |
| 3131 |
int outcnt = 0; |
| 3132 |
int i; |
| 3133 |
int again = FALSE; |
| 3134 |
int lastcur; |
| 3135 |
vocoldef *tmplist; |
| 3136 |
uchar *save_sp; |
| 3137 |
|
| 3138 |
voc_enter(ctx, &save_sp); |
| 3139 |
VOC_MAX_ARRAY(ctx, vocoldef, tmplist); |
| 3140 |
|
| 3141 |
for ( ;; ) |
| 3142 |
{ |
| 3143 |
|
| 3144 |
cnt = vocg1o(ctx, cmd, typelist, cur, next, complain, |
| 3145 |
tmplist, chkact, no_match); |
| 3146 |
|
| 3147 |
|
| 3148 |
if (cnt < 0) |
| 3149 |
{ |
| 3150 |
VOC_RETVAL(ctx, save_sp, cnt); |
| 3151 |
} |
| 3152 |
|
| 3153 |
|
| 3154 |
if (cnt > 0) |
| 3155 |
{ |
| 3156 |
for (i = 0 ; i < cnt ; ++i) |
| 3157 |
{ |
| 3158 |
OSCPYSTRUCT(nounlist[outcnt], tmplist[i]); |
| 3159 |
if (++outcnt > VOCMAXAMBIG) |
| 3160 |
{ |
| 3161 |
vocerr(ctx, VOCERR(11), |
| 3162 |
"You're referring to too many objects."); |
| 3163 |
VOC_RETVAL(ctx, save_sp, -1); |
| 3164 |
} |
| 3165 |
} |
| 3166 |
} |
| 3167 |
|
| 3168 |
|
| 3169 |
if (cnt == 0) |
| 3170 |
{ |
| 3171 |
if (again) |
| 3172 |
*next = lastcur; |
| 3173 |
break; |
| 3174 |
} |
| 3175 |
|
| 3176 |
|
| 3177 |
|
| 3178 |
|
| 3179 |
|
| 3180 |
|
| 3181 |
if (!multi || chkact) |
| 3182 |
break; |
| 3183 |
|
| 3184 |
|
| 3185 |
cur = *next; |
| 3186 |
|
| 3187 |
|
| 3188 |
|
| 3189 |
|
| 3190 |
|
| 3191 |
if (cur != -1 && cmd[cur] != 0 && vocspec(cmd[cur], VOCW_AND)) |
| 3192 |
{ |
| 3193 |
lastcur = cur; |
| 3194 |
while (cmd[cur] && vocspec(cmd[cur], VOCW_AND)) ++cur; |
| 3195 |
again = TRUE; |
| 3196 |
if (complain) complain = 2; |
| 3197 |
} |
| 3198 |
else |
| 3199 |
{ |
| 3200 |
|
| 3201 |
break; |
| 3202 |
} |
| 3203 |
} |
| 3204 |
|
| 3205 |
|
| 3206 |
nounlist[outcnt].vocolobj = MCMONINV; |
| 3207 |
nounlist[outcnt].vocolflg = 0; |
| 3208 |
VOC_RETVAL(ctx, save_sp, outcnt); |
| 3209 |
} |
| 3210 |
|
| 3211 |
|
| 3212 |
|
| 3213 |
|
| 3214 |
|
| 3215 |
|
| 3216 |
|
| 3217 |
void voc_parse_tok(voccxdef *ctx) |
| 3218 |
{ |
| 3219 |
uchar *save_sp; |
| 3220 |
runcxdef *rcx = ctx->voccxrun; |
| 3221 |
char **cmd; |
| 3222 |
char *inbuf; |
| 3223 |
char *outbuf; |
| 3224 |
uchar *p; |
| 3225 |
uint len; |
| 3226 |
int cnt; |
| 3227 |
|
| 3228 |
|
| 3229 |
voc_enter(ctx, &save_sp); |
| 3230 |
|
| 3231 |
|
| 3232 |
p = runpopstr(rcx); |
| 3233 |
|
| 3234 |
|
| 3235 |
len = osrp2(p) - 2; |
| 3236 |
p += 2; |
| 3237 |
|
| 3238 |
|
| 3239 |
|
| 3240 |
|
| 3241 |
|
| 3242 |
|
| 3243 |
|
| 3244 |
|
| 3245 |
VOC_STK_ARRAY(ctx, char, inbuf, len + 1); |
| 3246 |
VOC_STK_ARRAY(ctx, char, outbuf, len*2); |
| 3247 |
VOC_STK_ARRAY(ctx, char *, cmd, len*2); |
| 3248 |
|
| 3249 |
|
| 3250 |
memcpy(inbuf, p, len); |
| 3251 |
inbuf[len] = '\0'; |
| 3252 |
|
| 3253 |
|
| 3254 |
cnt = voctok(ctx, inbuf, outbuf, cmd, TRUE, FALSE, FALSE); |
| 3255 |
|
| 3256 |
|
| 3257 |
if (cnt < 0) |
| 3258 |
{ |
| 3259 |
|
| 3260 |
runpnil(rcx); |
| 3261 |
} |
| 3262 |
else |
| 3263 |
{ |
| 3264 |
|
| 3265 |
voc_push_toklist(ctx, cmd, cnt); |
| 3266 |
} |
| 3267 |
|
| 3268 |
|
| 3269 |
voc_leave(ctx, save_sp); |
| 3270 |
} |
| 3271 |
|
| 3272 |
|
| 3273 |
|
| 3274 |
|
| 3275 |
|
| 3276 |
|
| 3277 |
|
| 3278 |
|
| 3279 |
void voc_parse_types(voccxdef *ctx) |
| 3280 |
{ |
| 3281 |
runcxdef *rcx = ctx->voccxrun; |
| 3282 |
uchar *wrdp; |
| 3283 |
uint wrdsiz; |
| 3284 |
uchar *typp; |
| 3285 |
uchar *lstp; |
| 3286 |
uint lstsiz; |
| 3287 |
int wrdcnt; |
| 3288 |
|
| 3289 |
|
| 3290 |
wrdp = runpoplst(rcx); |
| 3291 |
|
| 3292 |
|
| 3293 |
wrdsiz = osrp2(wrdp) - 2; |
| 3294 |
wrdp += 2; |
| 3295 |
|
| 3296 |
|
| 3297 |
for (wrdcnt = 0, lstp = wrdp, lstsiz = wrdsiz ; lstsiz != 0 ; |
| 3298 |
lstadv(&lstp, &lstsiz)) |
| 3299 |
{ |
| 3300 |
|
| 3301 |
if (*lstp == DAT_SSTRING) |
| 3302 |
++wrdcnt; |
| 3303 |
} |
| 3304 |
|
| 3305 |
|
| 3306 |
typp = voc_push_list(ctx, wrdcnt, 4); |
| 3307 |
|
| 3308 |
|
| 3309 |
for (lstp = wrdp, lstsiz = wrdsiz ; lstsiz != 0 ; lstadv(&lstp, &lstsiz)) |
| 3310 |
{ |
| 3311 |
|
| 3312 |
if (*lstp == DAT_SSTRING) |
| 3313 |
{ |
| 3314 |
char buf[256]; |
| 3315 |
int curtyp; |
| 3316 |
uint len; |
| 3317 |
|
| 3318 |
|
| 3319 |
len = osrp2(lstp+1) - 2; |
| 3320 |
if (len < sizeof(buf)) |
| 3321 |
{ |
| 3322 |
|
| 3323 |
memcpy(buf, lstp+3, len); |
| 3324 |
|
| 3325 |
|
| 3326 |
buf[len] = '\0'; |
| 3327 |
|
| 3328 |
|
| 3329 |
curtyp = voc_lookup_type(ctx, buf, len, TRUE); |
| 3330 |
|
| 3331 |
|
| 3332 |
if (curtyp == 0) |
| 3333 |
curtyp = VOCT_UNKNOWN; |
| 3334 |
} |
| 3335 |
else |
| 3336 |
{ |
| 3337 |
|
| 3338 |
curtyp = VOCT_UNKNOWN; |
| 3339 |
} |
| 3340 |
|
| 3341 |
|
| 3342 |
*typp++ = DAT_NUMBER; |
| 3343 |
oswp4s(typp, curtyp); |
| 3344 |
typp += 4; |
| 3345 |
} |
| 3346 |
} |
| 3347 |
} |
| 3348 |
|
| 3349 |
|
| 3350 |
|
| 3351 |
|
| 3352 |
|
| 3353 |
|
| 3354 |
|
| 3355 |
|
| 3356 |
|
| 3357 |
|
| 3358 |
|
| 3359 |
void voc_parse_np(voccxdef *ctx) |
| 3360 |
{ |
| 3361 |
runcxdef *rcx = ctx->voccxrun; |
| 3362 |
vocoldef *objlist; |
| 3363 |
uchar *save_sp; |
| 3364 |
uchar *wordp; |
| 3365 |
uint wordsiz; |
| 3366 |
uchar *typp; |
| 3367 |
uint typsiz; |
| 3368 |
int cnt; |
| 3369 |
char **wordarr; |
| 3370 |
int wordcnt; |
| 3371 |
char *wordchararr; |
| 3372 |
uint wordcharsiz; |
| 3373 |
int *typarr; |
| 3374 |
int complain; |
| 3375 |
int chkact; |
| 3376 |
int multi; |
| 3377 |
int no_match; |
| 3378 |
int next; |
| 3379 |
int cur; |
| 3380 |
uchar *lstp; |
| 3381 |
uint lstsiz; |
| 3382 |
char *p; |
| 3383 |
int i; |
| 3384 |
int old_unknown, old_lastunk; |
| 3385 |
|
| 3386 |
|
| 3387 |
voc_enter(ctx, &save_sp); |
| 3388 |
VOC_MAX_ARRAY(ctx, vocoldef, objlist); |
| 3389 |
|
| 3390 |
|
| 3391 |
|
| 3392 |
|
| 3393 |
|
| 3394 |
|
| 3395 |
old_unknown = ctx->voccxunknown; |
| 3396 |
old_lastunk = ctx->voccxlastunk; |
| 3397 |
ctx->voccxunknown = ctx->voccxlastunk = 0; |
| 3398 |
|
| 3399 |
|
| 3400 |
wordp = runpoplst(rcx); |
| 3401 |
wordsiz = osrp2(wordp) - 2; |
| 3402 |
wordp += 2; |
| 3403 |
|
| 3404 |
|
| 3405 |
typp = runpoplst(rcx); |
| 3406 |
typsiz = osrp2(typp) - 2; |
| 3407 |
typp += 2; |
| 3408 |
|
| 3409 |
|
| 3410 |
cur = runpopnum(rcx) - 1; |
| 3411 |
next = cur; |
| 3412 |
|
| 3413 |
|
| 3414 |
complain = runpoplog(rcx); |
| 3415 |
multi = runpoplog(rcx); |
| 3416 |
chkact = runpoplog(rcx); |
| 3417 |
|
| 3418 |
|
| 3419 |
for (wordcnt = 0, lstp = wordp, wordcharsiz = 0, lstsiz = wordsiz ; |
| 3420 |
lstsiz != 0 ; lstadv(&lstp, &lstsiz)) |
| 3421 |
{ |
| 3422 |
|
| 3423 |
++wordcnt; |
| 3424 |
|
| 3425 |
|
| 3426 |
|
| 3427 |
|
| 3428 |
|
| 3429 |
if (*lstp == DAT_SSTRING) |
| 3430 |
wordcharsiz += osrp2(lstp+1) + 1; |
| 3431 |
} |
| 3432 |
|
| 3433 |
|
| 3434 |
VOC_STK_ARRAY(ctx, char, wordchararr, wordcharsiz); |
| 3435 |
VOC_STK_ARRAY(ctx, char *, wordarr, wordcnt+1); |
| 3436 |
VOC_STK_ARRAY(ctx, int, typarr, wordcnt+1); |
| 3437 |
|
| 3438 |
|
| 3439 |
for (i = 0, p = wordchararr, lstp = wordp, lstsiz = wordsiz ; |
| 3440 |
lstsiz != 0 ; lstadv(&lstp, &lstsiz)) |
| 3441 |
{ |
| 3442 |
|
| 3443 |
if (*lstp == DAT_SSTRING) |
| 3444 |
{ |
| 3445 |
uint len; |
| 3446 |
|
| 3447 |
|
| 3448 |
wordarr[i] = p; |
| 3449 |
|
| 3450 |
|
| 3451 |
len = osrp2(lstp + 1) - 2; |
| 3452 |
memcpy(p, lstp + 3, len); |
| 3453 |
p[len] = '\0'; |
| 3454 |
|
| 3455 |
|
| 3456 |
p += len + 1; |
| 3457 |
|
| 3458 |
|
| 3459 |
++i; |
| 3460 |
} |
| 3461 |
} |
| 3462 |
|
| 3463 |
|
| 3464 |
wordarr[i] = 0; |
| 3465 |
|
| 3466 |
|
| 3467 |
for (i = 0, lstp = typp, lstsiz = typsiz ; |
| 3468 |
lstsiz != 0 && i < wordcnt ; lstadv(&lstp, &lstsiz)) |
| 3469 |
{ |
| 3470 |
|
| 3471 |
if (*lstp == DAT_NUMBER) |
| 3472 |
{ |
| 3473 |
|
| 3474 |
typarr[i] = (int)osrp4(lstp + 1); |
| 3475 |
|
| 3476 |
|
| 3477 |
++i; |
| 3478 |
} |
| 3479 |
} |
| 3480 |
|
| 3481 |
|
| 3482 |
cnt = vocgobj(ctx, wordarr, typarr, cur, &next, complain, objlist, |
| 3483 |
multi, chkact, &no_match); |
| 3484 |
|
| 3485 |
|
| 3486 |
ctx->voccxunknown = old_unknown; |
| 3487 |
ctx->voccxlastunk = old_lastunk; |
| 3488 |
|
| 3489 |
|
| 3490 |
if (cnt < 0) |
| 3491 |
{ |
| 3492 |
|
| 3493 |
runpnil(rcx); |
| 3494 |
} |
| 3495 |
else if (cnt == 0) |
| 3496 |
{ |
| 3497 |
|
| 3498 |
|
| 3499 |
|
| 3500 |
|
| 3501 |
|
| 3502 |
|
| 3503 |
|
| 3504 |
|
| 3505 |
|
| 3506 |
|
| 3507 |
|
| 3508 |
|
| 3509 |
++next; |
| 3510 |
voc_push_numlist(ctx, (uint *)&next, 1); |
| 3511 |
} |
| 3512 |
else |
| 3513 |
{ |
| 3514 |
|
| 3515 |
|
| 3516 |
|
| 3517 |
|
| 3518 |
|
| 3519 |
|
| 3520 |
|
| 3521 |
|
| 3522 |
|
| 3523 |
|
| 3524 |
|
| 3525 |
|
| 3526 |
|
| 3527 |
|
| 3528 |
for (lstsiz = 0, i = 0 ; i < cnt ; ) |
| 3529 |
{ |
| 3530 |
int j; |
| 3531 |
|
| 3532 |
|
| 3533 |
|
| 3534 |
|
| 3535 |
|
| 3536 |
for (j = i ; |
| 3537 |
j < cnt && objlist[j].vocolfst == objlist[i].vocolfst ; |
| 3538 |
++j) |
| 3539 |
{ |
| 3540 |
|
| 3541 |
|
| 3542 |
|
| 3543 |
|
| 3544 |
if (objlist[j].vocolobj == MCMONINV) |
| 3545 |
lstsiz += 1; |
| 3546 |
else |
| 3547 |
lstsiz += 3; |
| 3548 |
lstsiz += 5; |
| 3549 |
} |
| 3550 |
|
| 3551 |
|
| 3552 |
|
| 3553 |
|
| 3554 |
|
| 3555 |
|
| 3556 |
|
| 3557 |
|
| 3558 |
lstsiz += (5 + 5) + 3; |
| 3559 |
|
| 3560 |
|
| 3561 |
i = j; |
| 3562 |
} |
| 3563 |
|
| 3564 |
|
| 3565 |
|
| 3566 |
|
| 3567 |
|
| 3568 |
lstsiz += 5; |
| 3569 |
|
| 3570 |
|
| 3571 |
lstp = voc_push_list_siz(ctx, lstsiz); |
| 3572 |
|
| 3573 |
|
| 3574 |
|
| 3575 |
|
| 3576 |
|
| 3577 |
*lstp++ = DAT_NUMBER; |
| 3578 |
oswp4s(lstp, next + 1); |
| 3579 |
lstp += 4; |
| 3580 |
|
| 3581 |
|
| 3582 |
for (i = 0 ; i < cnt ; ) |
| 3583 |
{ |
| 3584 |
uchar *sublstp; |
| 3585 |
int j; |
| 3586 |
int firstidx; |
| 3587 |
int lastidx; |
| 3588 |
|
| 3589 |
|
| 3590 |
*lstp++ = DAT_LIST; |
| 3591 |
|
| 3592 |
|
| 3593 |
|
| 3594 |
|
| 3595 |
|
| 3596 |
sublstp = lstp; |
| 3597 |
lstp += 2; |
| 3598 |
|
| 3599 |
|
| 3600 |
for (j = 0 ; j < wordcnt ; ++j) |
| 3601 |
{ |
| 3602 |
|
| 3603 |
if (wordarr[j] == objlist[i].vocolfst) |
| 3604 |
firstidx = j; |
| 3605 |
|
| 3606 |
|
| 3607 |
if (wordarr[j] == objlist[i].vocollst) |
| 3608 |
{ |
| 3609 |
|
| 3610 |
lastidx = j; |
| 3611 |
|
| 3612 |
|
| 3613 |
|
| 3614 |
|
| 3615 |
|
| 3616 |
|
| 3617 |
break; |
| 3618 |
} |
| 3619 |
} |
| 3620 |
|
| 3621 |
|
| 3622 |
*lstp++ = DAT_NUMBER; |
| 3623 |
oswp4s(lstp, firstidx + 1); |
| 3624 |
lstp += 4; |
| 3625 |
*lstp++ = DAT_NUMBER; |
| 3626 |
oswp4s(lstp, lastidx + 1); |
| 3627 |
lstp += 4; |
| 3628 |
|
| 3629 |
|
| 3630 |
for (j = i ; |
| 3631 |
j < cnt && objlist[j].vocolfst == objlist[i].vocolfst ; |
| 3632 |
++j) |
| 3633 |
{ |
| 3634 |
|
| 3635 |
if (objlist[j].vocolobj == MCMONINV) |
| 3636 |
{ |
| 3637 |
|
| 3638 |
*lstp++ = DAT_NIL; |
| 3639 |
} |
| 3640 |
else |
| 3641 |
{ |
| 3642 |
|
| 3643 |
*lstp++ = DAT_OBJECT; |
| 3644 |
oswp2(lstp, objlist[j].vocolobj); |
| 3645 |
lstp += 2; |
| 3646 |
} |
| 3647 |
|
| 3648 |
|
| 3649 |
*lstp++ = DAT_NUMBER; |
| 3650 |
oswp4s(lstp, objlist[i].vocolflg); |
| 3651 |
lstp += 4; |
| 3652 |
} |
| 3653 |
|
| 3654 |
|
| 3655 |
oswp2(sublstp, lstp - sublstp); |
| 3656 |
|
| 3657 |
|
| 3658 |
i = j; |
| 3659 |
} |
| 3660 |
} |
| 3661 |
|
| 3662 |
|
| 3663 |
voc_leave(ctx, save_sp); |
| 3664 |
} |
| 3665 |
|
| 3666 |
|
| 3667 |
|
| 3668 |
|
| 3669 |
|
| 3670 |
|
| 3671 |
|
| 3672 |
void voc_parse_dict_lookup(voccxdef *ctx) |
| 3673 |
{ |
| 3674 |
uchar *save_sp; |
| 3675 |
runcxdef *rcx = ctx->voccxrun; |
| 3676 |
uchar *wrdp; |
| 3677 |
uint wrdsiz; |
| 3678 |
uchar *typp; |
| 3679 |
uint typsiz; |
| 3680 |
objnum *list1; |
| 3681 |
objnum *list2; |
| 3682 |
int cnt1; |
| 3683 |
int cnt2; |
| 3684 |
|
| 3685 |
|
| 3686 |
voc_enter(ctx, &save_sp); |
| 3687 |
VOC_MAX_ARRAY(ctx, objnum, list1); |
| 3688 |
VOC_MAX_ARRAY(ctx, objnum, list2); |
| 3689 |
|
| 3690 |
|
| 3691 |
wrdp = runpoplst(rcx); |
| 3692 |
wrdsiz = osrp2(wrdp) - 2; |
| 3693 |
wrdp += 2; |
| 3694 |
|
| 3695 |
|
| 3696 |
typp = runpoplst(rcx); |
| 3697 |
typsiz = osrp2(typp) - 2; |
| 3698 |
typp += 2; |
| 3699 |
|
| 3700 |
|
| 3701 |
cnt1 = 0; |
| 3702 |
|
| 3703 |
|
| 3704 |
while (wrdsiz > 0) |
| 3705 |
{ |
| 3706 |
int curtyp; |
| 3707 |
int type_prop; |
| 3708 |
char *curword; |
| 3709 |
uint curwordlen; |
| 3710 |
char *curword2; |
| 3711 |
uint curwordlen2; |
| 3712 |
vocwdef *v; |
| 3713 |
char *p; |
| 3714 |
uint len; |
| 3715 |
vocseadef search_ctx; |
| 3716 |
|
| 3717 |
|
| 3718 |
if (*wrdp == DAT_SSTRING) |
| 3719 |
{ |
| 3720 |
|
| 3721 |
curword = (char *)(wrdp + 3); |
| 3722 |
curwordlen = osrp2(wrdp+1) - 2; |
| 3723 |
|
| 3724 |
|
| 3725 |
for (p = curword, len = curwordlen ; len != 0 && !t_isspace(*p) ; |
| 3726 |
++p, --len) ; |
| 3727 |
if (len != 0) |
| 3728 |
{ |
| 3729 |
|
| 3730 |
curword2 = p + 1; |
| 3731 |
curwordlen2 = len - 1; |
| 3732 |
|
| 3733 |
|
| 3734 |
curwordlen -= len; |
| 3735 |
} |
| 3736 |
else |
| 3737 |
{ |
| 3738 |
|
| 3739 |
curword2 = 0; |
| 3740 |
curwordlen2 = 0; |
| 3741 |
} |
| 3742 |
|
| 3743 |
|
| 3744 |
type_prop = PRP_INVALID; |
| 3745 |
|
| 3746 |
|
| 3747 |
|
| 3748 |
|
| 3749 |
|
| 3750 |
if (typsiz > 0 && *typp == DAT_NUMBER) |
| 3751 |
{ |
| 3752 |
|
| 3753 |
|
| 3754 |
|
| 3755 |
|
| 3756 |
|
| 3757 |
|
| 3758 |
|
| 3759 |
int i; |
| 3760 |
struct typemap_t |
| 3761 |
{ |
| 3762 |
int flag; |
| 3763 |
int prop; |
| 3764 |
}; |
| 3765 |
static struct typemap_t typemap[] = |
| 3766 |
{ |
| 3767 |
{ VOCT_ARTICLE, PRP_ARTICLE }, |
| 3768 |
{ VOCT_ADJ, PRP_ADJ }, |
| 3769 |
{ VOCT_NOUN, PRP_NOUN }, |
| 3770 |
{ VOCT_PREP, PRP_PREP }, |
| 3771 |
{ VOCT_VERB, PRP_VERB }, |
| 3772 |
{ VOCT_PLURAL, PRP_PLURAL } |
| 3773 |
}; |
| 3774 |
struct typemap_t *mapp; |
| 3775 |
|
| 3776 |
|
| 3777 |
curtyp = (int)osrp4(typp+1); |
| 3778 |
|
| 3779 |
|
| 3780 |
for (mapp = typemap, i = sizeof(typemap)/sizeof(typemap[0]) ; |
| 3781 |
i != 0 ; ++mapp, --i) |
| 3782 |
{ |
| 3783 |
|
| 3784 |
if ((curtyp & mapp->flag) != 0) |
| 3785 |
{ |
| 3786 |
|
| 3787 |
type_prop = mapp->prop; |
| 3788 |
break; |
| 3789 |
} |
| 3790 |
} |
| 3791 |
} |
| 3792 |
|
| 3793 |
|
| 3794 |
cnt2 = 0; |
| 3795 |
|
| 3796 |
|
| 3797 |
for (v = vocffw(ctx, curword, curwordlen, curword2, curwordlen2, |
| 3798 |
type_prop, &search_ctx) ; |
| 3799 |
v != 0 ; |
| 3800 |
v = vocfnw(ctx, &search_ctx)) |
| 3801 |
{ |
| 3802 |
int i; |
| 3803 |
|
| 3804 |
|
| 3805 |
if (cnt2 >= VOCMAXAMBIG - 1) |
| 3806 |
break; |
| 3807 |
|
| 3808 |
|
| 3809 |
for (i = 0 ; i < cnt2 ; ++i) |
| 3810 |
{ |
| 3811 |
|
| 3812 |
if (list2[i] == v->vocwobj) |
| 3813 |
break; |
| 3814 |
} |
| 3815 |
|
| 3816 |
|
| 3817 |
if (i == cnt2) |
| 3818 |
{ |
| 3819 |
|
| 3820 |
list2[cnt2++] = v->vocwobj; |
| 3821 |
} |
| 3822 |
} |
| 3823 |
|
| 3824 |
|
| 3825 |
list2[cnt2] = MCMONINV; |
| 3826 |
|
| 3827 |
|
| 3828 |
|
| 3829 |
|
| 3830 |
|
| 3831 |
if (cnt1 == 0) |
| 3832 |
{ |
| 3833 |
|
| 3834 |
memcpy(list1, list2, (cnt2+1)*sizeof(list2[0])); |
| 3835 |
cnt1 = cnt2; |
| 3836 |
} |
| 3837 |
else |
| 3838 |
{ |
| 3839 |
|
| 3840 |
cnt1 = vocisect(list1, list2); |
| 3841 |
} |
| 3842 |
|
| 3843 |
|
| 3844 |
|
| 3845 |
|
| 3846 |
|
| 3847 |
|
| 3848 |
if (cnt1 == 0) |
| 3849 |
break; |
| 3850 |
} |
| 3851 |
|
| 3852 |
|
| 3853 |
lstadv(&wrdp, &wrdsiz); |
| 3854 |
|
| 3855 |
|
| 3856 |
if (typsiz > 0) |
| 3857 |
lstadv(&typp, &typsiz); |
| 3858 |
} |
| 3859 |
|
| 3860 |
|
| 3861 |
voc_push_objlist(ctx, list1, cnt1); |
| 3862 |
|
| 3863 |
|
| 3864 |
voc_leave(ctx, save_sp); |
| 3865 |
} |
| 3866 |
|
| 3867 |
|
| 3868 |
|
| 3869 |
|
| 3870 |
|
| 3871 |
|
| 3872 |
|
| 3873 |
void voc_parse_disambig(voccxdef *ctx) |
| 3874 |
{ |
| 3875 |
voccxdef ctx_copy; |
| 3876 |
uchar *save_sp; |
| 3877 |
runcxdef *rcx = ctx->voccxrun; |
| 3878 |
vocoldef *inlist; |
| 3879 |
vocoldef *outlist; |
| 3880 |
int objcnt; |
| 3881 |
char **cmd; |
| 3882 |
char *cmdbuf; |
| 3883 |
char *oopsbuf; |
| 3884 |
objnum actor; |
| 3885 |
objnum verb; |
| 3886 |
objnum prep; |
| 3887 |
objnum otherobj; |
| 3888 |
prpnum defprop; |
| 3889 |
prpnum accprop; |
| 3890 |
prpnum verprop; |
| 3891 |
uchar *tokp; |
| 3892 |
uint toksiz; |
| 3893 |
uchar *objp; |
| 3894 |
uint objsiz; |
| 3895 |
uchar *lstp; |
| 3896 |
uint lstsiz; |
| 3897 |
int tokcnt; |
| 3898 |
char *p; |
| 3899 |
int i; |
| 3900 |
int silent; |
| 3901 |
int err; |
| 3902 |
int unknown_count; |
| 3903 |
|
| 3904 |
|
| 3905 |
voc_enter(ctx, &save_sp); |
| 3906 |
VOC_MAX_ARRAY(ctx, vocoldef, outlist); |
| 3907 |
VOC_STK_ARRAY(ctx, char, cmdbuf, VOCBUFSIZ); |
| 3908 |
VOC_STK_ARRAY(ctx, char, oopsbuf, VOCBUFSIZ); |
| 3909 |
|
| 3910 |
|
| 3911 |
actor = runpopobj(rcx); |
| 3912 |
verb = runpopobj(rcx); |
| 3913 |
prep = runpopobjnil(rcx); |
| 3914 |
otherobj = runpopobjnil(rcx); |
| 3915 |
|
| 3916 |
|
| 3917 |
|
| 3918 |
|
| 3919 |
|
| 3920 |
switch(runpopnum(rcx)) |
| 3921 |
{ |
| 3922 |
case VOC_PRO_RESOLVE_DOBJ: |
| 3923 |
default: |
| 3924 |
defprop = PRP_DODEFAULT; |
| 3925 |
accprop = PRP_VALIDDO; |
| 3926 |
break; |
| 3927 |
|
| 3928 |
case VOC_PRO_RESOLVE_IOBJ: |
| 3929 |
defprop = PRP_IODEFAULT; |
| 3930 |
accprop = PRP_VALIDIO; |
| 3931 |
break; |
| 3932 |
|
| 3933 |
case VOC_PRO_RESOLVE_ACTOR: |
| 3934 |
defprop = PRP_DODEFAULT; |
| 3935 |
accprop = PRP_VALIDACTOR; |
| 3936 |
break; |
| 3937 |
} |
| 3938 |
|
| 3939 |
|
| 3940 |
verprop = runpopprp(rcx); |
| 3941 |
|
| 3942 |
|
| 3943 |
tokp = runpoplst(rcx); |
| 3944 |
toksiz = osrp2(tokp) - 2; |
| 3945 |
tokp += 2; |
| 3946 |
|
| 3947 |
|
| 3948 |
objp = runpoplst(rcx); |
| 3949 |
objsiz = osrp2(objp) - 2; |
| 3950 |
objp += 2; |
| 3951 |
|
| 3952 |
|
| 3953 |
silent = runpoplog(rcx); |
| 3954 |
|
| 3955 |
|
| 3956 |
for (lstp = tokp, lstsiz = toksiz, tokcnt = 0 ; |
| 3957 |
lstsiz != 0 ; lstadv(&lstp, &lstsiz)) |
| 3958 |
{ |
| 3959 |
|
| 3960 |
if (*lstp == DAT_SSTRING) |
| 3961 |
++tokcnt; |
| 3962 |
} |
| 3963 |
|
| 3964 |
|
| 3965 |
VOC_STK_ARRAY(ctx, char *, cmd, tokcnt + 1); |
| 3966 |
|
| 3967 |
|
| 3968 |
for (lstp = tokp, lstsiz = toksiz, i = 0, p = cmdbuf ; |
| 3969 |
lstsiz != 0 ; lstadv(&lstp, &lstsiz)) |
| 3970 |
{ |
| 3971 |
|
| 3972 |
if (*lstp == DAT_SSTRING) |
| 3973 |
{ |
| 3974 |
uint len; |
| 3975 |
|
| 3976 |
|
| 3977 |
cmd[i++] = p; |
| 3978 |
|
| 3979 |
|
| 3980 |
len = osrp2(lstp + 1) - 2; |
| 3981 |
memcpy(p, lstp + 3, len); |
| 3982 |
p[len] = '\0'; |
| 3983 |
|
| 3984 |
|
| 3985 |
p += len + 1; |
| 3986 |
} |
| 3987 |
} |
| 3988 |
|
| 3989 |
|
| 3990 |
cmd[i] = 0; |
| 3991 |
|
| 3992 |
|
| 3993 |
|
| 3994 |
|
| 3995 |
|
| 3996 |
|
| 3997 |
|
| 3998 |
|
| 3999 |
if (objsiz > 0 && *objp == DAT_NUMBER) |
| 4000 |
lstadv(&objp, &objsiz); |
| 4001 |
|
| 4002 |
|
| 4003 |
|
| 4004 |
|
| 4005 |
|
| 4006 |
for (lstp = objp, lstsiz = objsiz, objcnt = 0 ; lstsiz != 0 ; |
| 4007 |
lstadv(&lstp, &lstsiz)) |
| 4008 |
{ |
| 4009 |
|
| 4010 |
if (*lstp == DAT_LIST) |
| 4011 |
{ |
| 4012 |
uchar *subp; |
| 4013 |
uint subsiz; |
| 4014 |
|
| 4015 |
|
| 4016 |
subp = lstp + 1; |
| 4017 |
subsiz = osrp2(subp) - 2; |
| 4018 |
subp += 2; |
| 4019 |
|
| 4020 |
|
| 4021 |
while (subsiz > 0) |
| 4022 |
{ |
| 4023 |
|
| 4024 |
if (*subp == DAT_OBJECT || *subp == DAT_NIL) |
| 4025 |
++objcnt; |
| 4026 |
|
| 4027 |
|
| 4028 |
lstadv(&subp, &subsiz); |
| 4029 |
} |
| 4030 |
} |
| 4031 |
} |
| 4032 |
|
| 4033 |
|
| 4034 |
VOC_STK_ARRAY(ctx, vocoldef, inlist, objcnt + 1); |
| 4035 |
|
| 4036 |
|
| 4037 |
unknown_count = 0; |
| 4038 |
|
| 4039 |
|
| 4040 |
for (lstp = objp, lstsiz = objsiz, i = 0 ; lstsiz != 0 ; |
| 4041 |
lstadv(&lstp, &lstsiz)) |
| 4042 |
{ |
| 4043 |
|
| 4044 |
if (*lstp == DAT_LIST) |
| 4045 |
{ |
| 4046 |
uchar *subp; |
| 4047 |
uint subsiz; |
| 4048 |
int firstwrd, lastwrd; |
| 4049 |
|
| 4050 |
|
| 4051 |
subp = lstp + 1; |
| 4052 |
subsiz = osrp2(subp) - 2; |
| 4053 |
subp += 2; |
| 4054 |
|
| 4055 |
|
| 4056 |
firstwrd = 0; |
| 4057 |
lastwrd = 0; |
| 4058 |
|
| 4059 |
|
| 4060 |
|
| 4061 |
|
| 4062 |
|
| 4063 |
if (subsiz > 0 && *subp == DAT_NUMBER) |
| 4064 |
{ |
| 4065 |
|
| 4066 |
firstwrd = (int)osrp4(subp+1) - 1; |
| 4067 |
|
| 4068 |
|
| 4069 |
if (firstwrd < 0) |
| 4070 |
firstwrd = 0; |
| 4071 |
else if (firstwrd > tokcnt) |
| 4072 |
firstwrd = tokcnt; |
| 4073 |
|
| 4074 |
|
| 4075 |
lstadv(&subp, &subsiz); |
| 4076 |
} |
| 4077 |
if (subsiz > 0 && *subp == DAT_NUMBER) |
| 4078 |
{ |
| 4079 |
|
| 4080 |
lastwrd = (int)osrp4(subp+1) - 1; |
| 4081 |
|
| 4082 |
|
| 4083 |
if (lastwrd < firstwrd) |
| 4084 |
lastwrd = firstwrd; |
| 4085 |
else if (lastwrd > tokcnt) |
| 4086 |
lastwrd = tokcnt; |
| 4087 |
|
| 4088 |
|
| 4089 |
lstadv(&subp, &subsiz); |
| 4090 |
} |
| 4091 |
|
| 4092 |
|
| 4093 |
while (subsiz > 0) |
| 4094 |
{ |
| 4095 |
|
| 4096 |
if (*subp == DAT_OBJECT || *subp == DAT_NIL) |
| 4097 |
{ |
| 4098 |
|
| 4099 |
if (*subp == DAT_OBJECT) |
| 4100 |
inlist[i].vocolobj = osrp2(subp+1); |
| 4101 |
else |
| 4102 |
inlist[i].vocolobj = MCMONINV; |
| 4103 |
|
| 4104 |
|
| 4105 |
inlist[i].vocolfst = cmd[firstwrd]; |
| 4106 |
inlist[i].vocollst = cmd[lastwrd]; |
| 4107 |
|
| 4108 |
|
| 4109 |
lstadv(&subp, &subsiz); |
| 4110 |
|
| 4111 |
|
| 4112 |
if (subsiz > 0 && *subp == DAT_NUMBER) |
| 4113 |
{ |
| 4114 |
|
| 4115 |
inlist[i].vocolflg = (int)osrp4(subp+1); |
| 4116 |
|
| 4117 |
|
| 4118 |
lstadv(&subp, &subsiz); |
| 4119 |
} |
| 4120 |
else |
| 4121 |
{ |
| 4122 |
|
| 4123 |
inlist[i].vocolflg = 0; |
| 4124 |
} |
| 4125 |
|
| 4126 |
|
| 4127 |
if ((inlist[i].vocolflg & VOCS_UNKNOWN) != 0) |
| 4128 |
++unknown_count; |
| 4129 |
|
| 4130 |
|
| 4131 |
++i; |
| 4132 |
} |
| 4133 |
else |
| 4134 |
{ |
| 4135 |
|
| 4136 |
lstadv(&subp, &subsiz); |
| 4137 |
} |
| 4138 |
} |
| 4139 |
} |
| 4140 |
} |
| 4141 |
|
| 4142 |
|
| 4143 |
inlist[i].vocolobj = MCMONINV; |
| 4144 |
inlist[i].vocolflg = 0; |
| 4145 |
|
| 4146 |
|
| 4147 |
|
| 4148 |
|
| 4149 |
|
| 4150 |
memcpy(&ctx_copy, ctx, sizeof(ctx_copy)); |
| 4151 |
|
| 4152 |
|
| 4153 |
|
| 4154 |
|
| 4155 |
|
| 4156 |
|
| 4157 |
|
| 4158 |
ctx_copy.voccxunknown = ctx_copy.voccxlastunk = unknown_count; |
| 4159 |
|
| 4160 |
|
| 4161 |
err = vocdisambig(&ctx_copy, outlist, inlist, |
| 4162 |
defprop, accprop, verprop, cmd, |
| 4163 |
otherobj, actor, verb, prep, cmdbuf, silent); |
| 4164 |
|
| 4165 |
|
| 4166 |
|
| 4167 |
|
| 4168 |
|
| 4169 |
|
| 4170 |
|
| 4171 |
|
| 4172 |
|
| 4173 |
|
| 4174 |
|
| 4175 |
|
| 4176 |
|
| 4177 |
|
| 4178 |
if (err == VOCERR(2) && ctx_copy.voccxunknown != 0 && !silent) |
| 4179 |
{ |
| 4180 |
char *unk; |
| 4181 |
int unk_idx; |
| 4182 |
char *rpl_text; |
| 4183 |
|
| 4184 |
|
| 4185 |
|
| 4186 |
|
| 4187 |
|
| 4188 |
ctx_copy.voccxunknown = 0; |
| 4189 |
|
| 4190 |
|
| 4191 |
|
| 4192 |
|
| 4193 |
|
| 4194 |
for (i = 0, unk = 0 ; cmd[i] != 0 ; ++i) |
| 4195 |
{ |
| 4196 |
int t; |
| 4197 |
|
| 4198 |
|
| 4199 |
|
| 4200 |
|
| 4201 |
|
| 4202 |
t = voc_lookup_type(ctx, cmd[i], strlen(cmd[i]), TRUE); |
| 4203 |
if (t == 0) |
| 4204 |
{ |
| 4205 |
|
| 4206 |
unk_idx = i; |
| 4207 |
unk = cmd[i]; |
| 4208 |
break; |
| 4209 |
} |
| 4210 |
} |
| 4211 |
|
| 4212 |
|
| 4213 |
|
| 4214 |
|
| 4215 |
|
| 4216 |
if (unk == 0) |
| 4217 |
{ |
| 4218 |
unk_idx = 0; |
| 4219 |
unk = cmd[0]; |
| 4220 |
} |
| 4221 |
|
| 4222 |
|
| 4223 |
rpl_text = voc_read_oops(&ctx_copy, oopsbuf, VOCBUFSIZ, unk); |
| 4224 |
|
| 4225 |
|
| 4226 |
|
| 4227 |
|
| 4228 |
|
| 4229 |
if (rpl_text == 0) |
| 4230 |
{ |
| 4231 |
|
| 4232 |
|
| 4233 |
|
| 4234 |
|
| 4235 |
ctx_copy.voccxredo = TRUE; |
| 4236 |
|
| 4237 |
|
| 4238 |
strcpy(cmdbuf, oopsbuf); |
| 4239 |
} |
| 4240 |
else |
| 4241 |
{ |
| 4242 |
|
| 4243 |
err = VOCERR(45); |
| 4244 |
|
| 4245 |
|
| 4246 |
|
| 4247 |
|
| 4248 |
|
| 4249 |
|
| 4250 |
|
| 4251 |
for (p = cmdbuf, i = 0 ; cmd[i] != 0 ; ++i) |
| 4252 |
{ |
| 4253 |
size_t needed; |
| 4254 |
|
| 4255 |
|
| 4256 |
if (i == unk_idx) |
| 4257 |
{ |
| 4258 |
|
| 4259 |
needed = strlen(rpl_text); |
| 4260 |
} |
| 4261 |
else |
| 4262 |
{ |
| 4263 |
|
| 4264 |
needed = strlen(cmd[i]); |
| 4265 |
} |
| 4266 |
|
| 4267 |
|
| 4268 |
|
| 4269 |
|
| 4270 |
|
| 4271 |
if (cmd[i+1] != 0 && needed != 0) |
| 4272 |
needed += 1; |
| 4273 |
|
| 4274 |
|
| 4275 |
needed += 1; |
| 4276 |
|
| 4277 |
|
| 4278 |
if (needed > (size_t)(VOCBUFSIZ - (p - cmdbuf))) |
| 4279 |
break; |
| 4280 |
|
| 4281 |
|
| 4282 |
|
| 4283 |
|
| 4284 |
|
| 4285 |
if (i == unk_idx) |
| 4286 |
{ |
| 4287 |
|
| 4288 |
strcpy(p, rpl_text); |
| 4289 |
} |
| 4290 |
else if (*cmd[i] == '"') |
| 4291 |
{ |
| 4292 |
char *p1; |
| 4293 |
char qu; |
| 4294 |
|
| 4295 |
|
| 4296 |
|
| 4297 |
|
| 4298 |
|
| 4299 |
|
| 4300 |
|
| 4301 |
|
| 4302 |
|
| 4303 |
|
| 4304 |
for (qu = '"', p1 = cmd[i] + 1 ; |
| 4305 |
*p1 != '\0' && *(p1 + 1) != '\0' ; ++p1) |
| 4306 |
{ |
| 4307 |
|
| 4308 |
if (*p1 == '"') |
| 4309 |
{ |
| 4310 |
|
| 4311 |
qu = '\''; |
| 4312 |
|
| 4313 |
|
| 4314 |
break; |
| 4315 |
} |
| 4316 |
} |
| 4317 |
|
| 4318 |
|
| 4319 |
*p++ = qu; |
| 4320 |
|
| 4321 |
|
| 4322 |
|
| 4323 |
|
| 4324 |
|
| 4325 |
if (strlen(cmd[i]) > 2) |
| 4326 |
{ |
| 4327 |
memcpy(p, cmd[i] + 1, strlen(cmd[i]) - 2); |
| 4328 |
p += strlen(cmd[i]) - 2; |
| 4329 |
} |
| 4330 |
|
| 4331 |
|
| 4332 |
*p++ = qu; |
| 4333 |
|
| 4334 |
|
| 4335 |
*p = '\0'; |
| 4336 |
} |
| 4337 |
else |
| 4338 |
{ |
| 4339 |
|
| 4340 |
strcpy(p, cmd[i]); |
| 4341 |
} |
| 4342 |
|
| 4343 |
|
| 4344 |
p += strlen(p); |
| 4345 |
|
| 4346 |
|
| 4347 |
if (cmd[i+1] != 0) |
| 4348 |
*p++ = ' '; |
| 4349 |
} |
| 4350 |
|
| 4351 |
|
| 4352 |
*p = '\0'; |
| 4353 |
} |
| 4354 |
} |
| 4355 |
|
| 4356 |
|
| 4357 |
|
| 4358 |
|
| 4359 |
|
| 4360 |
if (err == 0 || err == VOCERR(44)) |
| 4361 |
{ |
| 4362 |
|
| 4363 |
for (i = 0 ; outlist[i].vocolobj != MCMONINV ; ++i) ; |
| 4364 |
objcnt = i; |
| 4365 |
} |
| 4366 |
else |
| 4367 |
{ |
| 4368 |
|
| 4369 |
objcnt = 0; |
| 4370 |
} |
| 4371 |
|
| 4372 |
|
| 4373 |
lstsiz = (1+2) * objcnt; |
| 4374 |
|
| 4375 |
|
| 4376 |
lstsiz += (1 + 4); |
| 4377 |
|
| 4378 |
|
| 4379 |
if (ctx_copy.voccxredo || err == VOCERR(45)) |
| 4380 |
{ |
| 4381 |
|
| 4382 |
|
| 4383 |
|
| 4384 |
|
| 4385 |
lstsiz += (1 + 2 + strlen(cmdbuf)); |
| 4386 |
|
| 4387 |
|
| 4388 |
|
| 4389 |
|
| 4390 |
|
| 4391 |
|
| 4392 |
if (ctx_copy.voccxredo) |
| 4393 |
err = VOCERR(43); |
| 4394 |
} |
| 4395 |
|
| 4396 |
|
| 4397 |
lstp = voc_push_list_siz(ctx, lstsiz); |
| 4398 |
|
| 4399 |
|
| 4400 |
*lstp++ = DAT_NUMBER; |
| 4401 |
oswp4s(lstp, err); |
| 4402 |
lstp += 4; |
| 4403 |
|
| 4404 |
|
| 4405 |
if (err == 0 || err == VOCERR(44)) |
| 4406 |
{ |
| 4407 |
|
| 4408 |
for (i = 0 ; i < objcnt ; ++i) |
| 4409 |
{ |
| 4410 |
|
| 4411 |
*lstp++ = DAT_OBJECT; |
| 4412 |
oswp2(lstp, outlist[i].vocolobj); |
| 4413 |
lstp += 2; |
| 4414 |
} |
| 4415 |
} |
| 4416 |
else if (ctx_copy.voccxredo || err == VOCERR(45)) |
| 4417 |
{ |
| 4418 |
uint len; |
| 4419 |
|
| 4420 |
|
| 4421 |
*lstp++ = DAT_SSTRING; |
| 4422 |
|
| 4423 |
|
| 4424 |
len = strlen(cmdbuf); |
| 4425 |
oswp2(lstp, len + 2); |
| 4426 |
lstp += 2; |
| 4427 |
|
| 4428 |
|
| 4429 |
memcpy(lstp, cmdbuf, len); |
| 4430 |
} |
| 4431 |
|
| 4432 |
|
| 4433 |
voc_leave(ctx, save_sp); |
| 4434 |
} |
| 4435 |
|
| 4436 |
|
| 4437 |
|
| 4438 |
|
| 4439 |
|
| 4440 |
|
| 4441 |
|
| 4442 |
void voc_parse_replace_cmd(voccxdef *ctx) |
| 4443 |
{ |
| 4444 |
runcxdef *rcx = ctx->voccxrun; |
| 4445 |
uchar *p; |
| 4446 |
uint len; |
| 4447 |
|
| 4448 |
|
| 4449 |
p = runpopstr(rcx); |
| 4450 |
|
| 4451 |
|
| 4452 |
len = osrp2(p) - 2; |
| 4453 |
p += 2; |
| 4454 |
|
| 4455 |
|
| 4456 |
if (len + 1 > VOCBUFSIZ) |
| 4457 |
len = VOCBUFSIZ - 1; |
| 4458 |
|
| 4459 |
|
| 4460 |
memcpy(ctx->voccxredobuf, p, len); |
| 4461 |
ctx->voccxredobuf[len] = '\0'; |
| 4462 |
|
| 4463 |
|
| 4464 |
ctx->voccxredo = TRUE; |
| 4465 |
|
| 4466 |
|
| 4467 |
errsig(ctx->voccxerr, ERR_RUNABRT); |
| 4468 |
} |
| 4469 |
|
| 4470 |
|
| 4471 |
|
| 4472 |
|
| 4473 |
|
| 4474 |
|
| 4475 |
|
| 4476 |
|
| 4477 |
|
| 4478 |
|
| 4479 |
|
| 4480 |
|
| 4481 |
static objnum vocgetactor(voccxdef *ctx, char *cmd[], int typelist[], |
| 4482 |
int cur, int *next, char *cmdbuf) |
| 4483 |
{ |
| 4484 |
int l; |
| 4485 |
vocoldef *nounlist; |
| 4486 |
vocoldef *actlist; |
| 4487 |
int cnt; |
| 4488 |
uchar *save_sp; |
| 4489 |
prpnum valprop, verprop; |
| 4490 |
|
| 4491 |
voc_enter(ctx, &save_sp); |
| 4492 |
VOC_MAX_ARRAY(ctx, vocoldef, nounlist); |
| 4493 |
VOC_MAX_ARRAY(ctx, vocoldef, actlist); |
| 4494 |
|
| 4495 |
*next = cur; |
| 4496 |
cnt = vocchknoun(ctx, cmd, typelist, cur, next, nounlist, TRUE); |
| 4497 |
if (cnt > 0 && *next != -1 && cmd[*next] && vocspec(cmd[*next], VOCW_AND)) |
| 4498 |
{ |
| 4499 |
int have_unknown; |
| 4500 |
|
| 4501 |
|
| 4502 |
have_unknown = ((nounlist[0].vocolflg & VOCS_UNKNOWN) != 0); |
| 4503 |
|
| 4504 |
|
| 4505 |
|
| 4506 |
|
| 4507 |
|
| 4508 |
|
| 4509 |
|
| 4510 |
|
| 4511 |
|
| 4512 |
|
| 4513 |
|
| 4514 |
|
| 4515 |
|
| 4516 |
verprop = PRP_VERACTOR; |
| 4517 |
if (nounlist[0].vocolobj == MCMONINV |
| 4518 |
|| objgetap(ctx->voccxmem, nounlist[0].vocolobj, PRP_VALIDACTOR, |
| 4519 |
(objnum *)0, FALSE)) |
| 4520 |
valprop = PRP_VALIDACTOR; |
| 4521 |
else |
| 4522 |
valprop = PRP_VALIDDO; |
| 4523 |
|
| 4524 |
|
| 4525 |
if (vocdisambig(ctx, actlist, nounlist, PRP_DODEFAULT, valprop, |
| 4526 |
verprop, cmd, MCMONINV, ctx->voccxme, |
| 4527 |
ctx->voccxvtk, MCMONINV, cmdbuf, FALSE)) |
| 4528 |
{ |
| 4529 |
|
| 4530 |
|
| 4531 |
|
| 4532 |
|
| 4533 |
|
| 4534 |
if (have_unknown) |
| 4535 |
{ |
| 4536 |
|
| 4537 |
*next = cur; |
| 4538 |
} |
| 4539 |
|
| 4540 |
|
| 4541 |
VOC_RETVAL(ctx, save_sp, MCMONINV); |
| 4542 |
} |
| 4543 |
|
| 4544 |
if ((l = voclistlen(actlist)) > 1) |
| 4545 |
{ |
| 4546 |
vocerr(ctx, VOCERR(12), |
| 4547 |
"You can only speak to one person at a time."); |
| 4548 |
*next = cur + 1; |
| 4549 |
VOC_RETVAL(ctx, save_sp, MCMONINV); |
| 4550 |
} |
| 4551 |
else if (l == 0) |
| 4552 |
return(MCMONINV); |
| 4553 |
|
| 4554 |
if (cmd[*next] && vocspec(cmd[*next], VOCW_AND)) |
| 4555 |
{ |
| 4556 |
++(*next); |
| 4557 |
VOC_RETVAL(ctx, save_sp, actlist[0].vocolobj); |
| 4558 |
} |
| 4559 |
} |
| 4560 |
if (cnt < 0) |
| 4561 |
{ |
| 4562 |
|
| 4563 |
*next = cur + 1; |
| 4564 |
} |
| 4565 |
else |
| 4566 |
*next = cur; |
| 4567 |
|
| 4568 |
VOC_RETVAL(ctx, save_sp, MCMONINV); |
| 4569 |
} |
| 4570 |
|
| 4571 |
|
| 4572 |
int voclistlen(vocoldef *lst) |
| 4573 |
{ |
| 4574 |
int i; |
| 4575 |
|
| 4576 |
for (i = 0 ; lst->vocolobj != MCMONINV || lst->vocolflg != 0 ; |
| 4577 |
++lst, ++i) ; |
| 4578 |
return(i); |
| 4579 |
} |
| 4580 |
|
| 4581 |
|
| 4582 |
|
| 4583 |
|
| 4584 |
|
| 4585 |
|
| 4586 |
|
| 4587 |
|
| 4588 |
|
| 4589 |
|
| 4590 |
|
| 4591 |
|
| 4592 |
|
| 4593 |
|
| 4594 |
int vocchkaccess(voccxdef *ctx, objnum obj, prpnum verprop, |
| 4595 |
int seqno, objnum cmdActor, objnum cmdVerb) |
| 4596 |
{ |
| 4597 |
|
| 4598 |
|
| 4599 |
|
| 4600 |
|
| 4601 |
if (obj == ctx->voccxstr || obj == ctx->voccxnum) |
| 4602 |
return TRUE; |
| 4603 |
|
| 4604 |
|
| 4605 |
|
| 4606 |
|
| 4607 |
|
| 4608 |
|
| 4609 |
|
| 4610 |
if (verprop == PRP_VALIDACTOR) |
| 4611 |
{ |
| 4612 |
|
| 4613 |
if (objgetap(ctx->voccxmem, obj, PRP_VALIDACTOR, (objnum *)0, FALSE)) |
| 4614 |
{ |
| 4615 |
|
| 4616 |
runppr(ctx->voccxrun, obj, verprop, 0); |
| 4617 |
|
| 4618 |
|
| 4619 |
return runpoplog(ctx->voccxrun); |
| 4620 |
} |
| 4621 |
else |
| 4622 |
{ |
| 4623 |
|
| 4624 |
cmdVerb = ctx->voccxvtk; |
| 4625 |
verprop = PRP_VALIDDO; |
| 4626 |
} |
| 4627 |
} |
| 4628 |
|
| 4629 |
|
| 4630 |
runpnum(ctx->voccxrun, (long)(seqno + 1)); |
| 4631 |
runpobj(ctx->voccxrun, obj); |
| 4632 |
runpobj(ctx->voccxrun, |
| 4633 |
(objnum)(cmdActor == MCMONINV ? ctx->voccxme : cmdActor)); |
| 4634 |
runppr(ctx->voccxrun, cmdVerb, verprop, 3); |
| 4635 |
|
| 4636 |
|
| 4637 |
return runpoplog(ctx->voccxrun); |
| 4638 |
} |
| 4639 |
|
| 4640 |
|
| 4641 |
int vocchkvis(voccxdef *ctx, objnum obj, objnum cmdActor) |
| 4642 |
{ |
| 4643 |
runpobj(ctx->voccxrun, |
| 4644 |
(objnum)(cmdActor == MCMONINV ? ctx->voccxme : cmdActor)); |
| 4645 |
runppr(ctx->voccxrun, obj, (prpnum)PRP_ISVIS, 1); |
| 4646 |
return(runpoplog(ctx->voccxrun)); |
| 4647 |
} |
| 4648 |
|
| 4649 |
|
| 4650 |
void vocsetobj(voccxdef *ctx, objnum obj, dattyp typ, void *val, |
| 4651 |
vocoldef *inobj, vocoldef *outobj) |
| 4652 |
{ |
| 4653 |
*outobj = *inobj; |
| 4654 |
outobj->vocolobj = obj; |
| 4655 |
objsetp(ctx->voccxmem, obj, PRP_VALUE, typ, val, ctx->voccxundo); |
| 4656 |
} |
| 4657 |
|
| 4658 |
|
| 4659 |
static void vocout(vocoldef *outobj, objnum obj, int flg, |
| 4660 |
char *fst, char *lst) |
| 4661 |
{ |
| 4662 |
outobj->vocolobj = obj; |
| 4663 |
outobj->vocolflg = flg; |
| 4664 |
outobj->vocolfst = fst; |
| 4665 |
outobj->vocollst = lst; |
| 4666 |
} |
| 4667 |
|
| 4668 |
|
| 4669 |
|
| 4670 |
|
| 4671 |
|
| 4672 |
|
| 4673 |
|
| 4674 |
void vocnoreach(voccxdef *ctx, objnum *list1, int cnt, |
| 4675 |
objnum actor, objnum verb, objnum prep, prpnum defprop, |
| 4676 |
int show_multi_prefix, |
| 4677 |
int multi_flags, int multi_base_index, int multi_total_count) |
| 4678 |
{ |
| 4679 |
|
| 4680 |
if (objgetap(ctx->voccxmem, verb, PRP_NOREACH, (objnum *)0, FALSE)) |
| 4681 |
{ |
| 4682 |
|
| 4683 |
runpobj(ctx->voccxrun, prep); |
| 4684 |
if (defprop == PRP_DODEFAULT) |
| 4685 |
{ |
| 4686 |
runpnil(ctx->voccxrun); |
| 4687 |
voc_push_objlist(ctx, list1, cnt); |
| 4688 |
} |
| 4689 |
else |
| 4690 |
{ |
| 4691 |
voc_push_objlist(ctx, list1, cnt); |
| 4692 |
runpnil(ctx->voccxrun); |
| 4693 |
} |
| 4694 |
runpobj(ctx->voccxrun, actor); |
| 4695 |
|
| 4696 |
|
| 4697 |
runppr(ctx->voccxrun, verb, PRP_NOREACH, 4); |
| 4698 |
} |
| 4699 |
else |
| 4700 |
{ |
| 4701 |
int i; |
| 4702 |
|
| 4703 |
|
| 4704 |
for (i = 0 ; i < cnt ; ++i) |
| 4705 |
{ |
| 4706 |
|
| 4707 |
|
| 4708 |
|
| 4709 |
|
| 4710 |
|
| 4711 |
voc_multi_prefix(ctx, list1[i], show_multi_prefix, multi_flags, |
| 4712 |
multi_base_index + i, multi_total_count); |
| 4713 |
|
| 4714 |
|
| 4715 |
runpobj(ctx->voccxrun, |
| 4716 |
(objnum)(actor == MCMONINV ? ctx->voccxme : actor)); |
| 4717 |
runppr(ctx->voccxrun, list1[i], (prpnum)PRP_NOREACH, 1); |
| 4718 |
tioflush(ctx->voccxtio); |
| 4719 |
} |
| 4720 |
} |
| 4721 |
} |
| 4722 |
|
| 4723 |
|
| 4724 |
|
| 4725 |
|
| 4726 |
|
| 4727 |
static void voc_get_spec_str(voccxdef *ctx, char vocw_id, |
| 4728 |
char *buf, size_t buflen, |
| 4729 |
const char *default_name) |
| 4730 |
{ |
| 4731 |
int found; |
| 4732 |
|
| 4733 |
|
| 4734 |
found = FALSE; |
| 4735 |
|
| 4736 |
|
| 4737 |
if (ctx->voccxspp != 0) |
| 4738 |
{ |
| 4739 |
char *p; |
| 4740 |
char *endp; |
| 4741 |
size_t len; |
| 4742 |
|
| 4743 |
|
| 4744 |
for (p = ctx->voccxspp, endp = p + ctx->voccxspl ; p < endp ; ) |
| 4745 |
{ |
| 4746 |
|
| 4747 |
if (*p++ == vocw_id) |
| 4748 |
{ |
| 4749 |
|
| 4750 |
found = TRUE; |
| 4751 |
|
| 4752 |
|
| 4753 |
|
| 4754 |
|
| 4755 |
|
| 4756 |
len = *p++; |
| 4757 |
if (len + 1 > buflen) |
| 4758 |
len = buflen - 1; |
| 4759 |
|
| 4760 |
|
| 4761 |
memcpy(buf, p, len); |
| 4762 |
buf[len] = '\0'; |
| 4763 |
|
| 4764 |
|
| 4765 |
break; |
| 4766 |
} |
| 4767 |
|
| 4768 |
|
| 4769 |
|
| 4770 |
|
| 4771 |
|
| 4772 |
p += *p + 1; |
| 4773 |
} |
| 4774 |
} |
| 4775 |
|
| 4776 |
|
| 4777 |
if (!found) |
| 4778 |
{ |
| 4779 |
strncpy(buf, default_name, (size_t)buflen); |
| 4780 |
buf[buflen - 1] = '\0'; |
| 4781 |
} |
| 4782 |
} |
| 4783 |
|
| 4784 |
|
| 4785 |
static int vocsetit(voccxdef *ctx, objnum obj, int accprop, |
| 4786 |
objnum actor, objnum verb, objnum prep, |
| 4787 |
vocoldef *outobj, char *default_name, char vocw_id, |
| 4788 |
prpnum defprop, int silent) |
| 4789 |
{ |
| 4790 |
if (obj == MCMONINV || !vocchkaccess(ctx, obj, (prpnum)accprop, |
| 4791 |
0, actor, verb)) |
| 4792 |
{ |
| 4793 |
char nambuf[40]; |
| 4794 |
|
| 4795 |
|
| 4796 |
voc_get_spec_str(ctx, vocw_id, nambuf, sizeof(nambuf), default_name); |
| 4797 |
|
| 4798 |
|
| 4799 |
if (!silent) |
| 4800 |
{ |
| 4801 |
|
| 4802 |
if (obj == MCMONINV) |
| 4803 |
vocerr(ctx, VOCERR(13), |
| 4804 |
"I don't know what you're referring to with '%s'.", |
| 4805 |
nambuf); |
| 4806 |
else |
| 4807 |
vocnoreach(ctx, &obj, 1, actor, verb, prep, |
| 4808 |
defprop, FALSE, 0, 0, 1); |
| 4809 |
} |
| 4810 |
|
| 4811 |
|
| 4812 |
return VOCERR(13); |
| 4813 |
} |
| 4814 |
|
| 4815 |
|
| 4816 |
vocout(outobj, obj, 0, default_name, default_name); |
| 4817 |
return 0; |
| 4818 |
} |
| 4819 |
|
| 4820 |
|
| 4821 |
|
| 4822 |
|
| 4823 |
|
| 4824 |
|
| 4825 |
|
| 4826 |
static objnum voc_new_num_obj(voccxdef *ctx, objnum objn, |
| 4827 |
objnum actor, objnum verb, |
| 4828 |
long num, int plural) |
| 4829 |
{ |
| 4830 |
|
| 4831 |
if (plural) |
| 4832 |
runpnil(ctx->voccxrun); |
| 4833 |
else |
| 4834 |
runpnum(ctx->voccxrun, num); |
| 4835 |
|
| 4836 |
|
| 4837 |
runpobj(ctx->voccxrun, verb); |
| 4838 |
runpobj(ctx->voccxrun, actor); |
| 4839 |
runppr(ctx->voccxrun, objn, PRP_NEWNUMOBJ, 3); |
| 4840 |
|
| 4841 |
|
| 4842 |
if (runtostyp(ctx->voccxrun) == DAT_NIL) |
| 4843 |
{ |
| 4844 |
rundisc(ctx->voccxrun); |
| 4845 |
return MCMONINV; |
| 4846 |
} |
| 4847 |
else |
| 4848 |
return runpopobj(ctx->voccxrun); |
| 4849 |
} |
| 4850 |
|
| 4851 |
|
| 4852 |
static int has_gen_num_adj(voccxdef *ctx, objnum objn) |
| 4853 |
{ |
| 4854 |
vocwdef *v; |
| 4855 |
vocseadef search_ctx; |
| 4856 |
|
| 4857 |
|
| 4858 |
for (v = vocffw(ctx, "#", 1, (char *)0, 0, PRP_ADJ, &search_ctx) ; |
| 4859 |
v ; v = vocfnw(ctx, &search_ctx)) |
| 4860 |
{ |
| 4861 |
|
| 4862 |
if (v->vocwobj == objn) |
| 4863 |
return TRUE; |
| 4864 |
} |
| 4865 |
|
| 4866 |
|
| 4867 |
return FALSE; |
| 4868 |
} |
| 4869 |
|
| 4870 |
|
| 4871 |
|
| 4872 |
|
| 4873 |
|
| 4874 |
|
| 4875 |
|
| 4876 |
static int voc_disambig_hook(voccxdef *ctx, objnum verb, objnum actor, |
| 4877 |
objnum prep, objnum otherobj, |
| 4878 |
prpnum accprop, prpnum verprop, |
| 4879 |
objnum *objlist, uint *flags, int *objcount, |
| 4880 |
char *firstwrd, char *lastwrd, |
| 4881 |
int num_wanted, int is_ambig, char *resp, |
| 4882 |
int silent) |
| 4883 |
{ |
| 4884 |
runcxdef *rcx = ctx->voccxrun; |
| 4885 |
prpnum call_prop; |
| 4886 |
runsdef val; |
| 4887 |
uchar *lstp; |
| 4888 |
uint lstsiz; |
| 4889 |
int ret; |
| 4890 |
int i; |
| 4891 |
|
| 4892 |
|
| 4893 |
if (verprop == PRP_VERACTOR) |
| 4894 |
{ |
| 4895 |
|
| 4896 |
return VOC_DISAMBIG_CONT; |
| 4897 |
} |
| 4898 |
|
| 4899 |
|
| 4900 |
call_prop = (accprop == PRP_VALIDDO ? PRP_DISAMBIGDO : PRP_DISAMBIGIO); |
| 4901 |
|
| 4902 |
|
| 4903 |
if (objgetap(ctx->voccxmem, verb, call_prop, (objnum *)0, FALSE) == 0) |
| 4904 |
return VOC_DISAMBIG_CONT; |
| 4905 |
|
| 4906 |
|
| 4907 |
val.runstyp = (silent ? DAT_TRUE : DAT_NIL); |
| 4908 |
runpush(rcx, val.runstyp, &val); |
| 4909 |
|
| 4910 |
|
| 4911 |
val.runstyp = (is_ambig ? DAT_TRUE : DAT_NIL); |
| 4912 |
runpush(rcx, val.runstyp, &val); |
| 4913 |
|
| 4914 |
|
| 4915 |
runpnum(rcx, num_wanted); |
| 4916 |
|
| 4917 |
|
| 4918 |
voc_push_numlist(ctx, flags, *objcount); |
| 4919 |
|
| 4920 |
|
| 4921 |
voc_push_objlist(ctx, objlist, *objcount); |
| 4922 |
|
| 4923 |
|
| 4924 |
voc_push_strlist(ctx, firstwrd, lastwrd); |
| 4925 |
|
| 4926 |
|
| 4927 |
val.runstyp = DAT_PROPNUM; |
| 4928 |
val.runsv.runsvprp = verprop; |
| 4929 |
runpush(rcx, DAT_PROPNUM, &val); |
| 4930 |
|
| 4931 |
|
| 4932 |
runpobj(rcx, otherobj); |
| 4933 |
|
| 4934 |
|
| 4935 |
runpobj(rcx, prep); |
| 4936 |
runpobj(rcx, actor); |
| 4937 |
|
| 4938 |
|
| 4939 |
runppr(rcx, verb, call_prop, 10); |
| 4940 |
|
| 4941 |
|
| 4942 |
switch(runtostyp(rcx)) |
| 4943 |
{ |
| 4944 |
case DAT_LIST: |
| 4945 |
|
| 4946 |
lstp = runpoplst(rcx); |
| 4947 |
|
| 4948 |
|
| 4949 |
lstsiz = osrp2(lstp) - 2; |
| 4950 |
lstp += 2; |
| 4951 |
|
| 4952 |
|
| 4953 |
if (lstsiz > 0 && *lstp == DAT_NUMBER) |
| 4954 |
{ |
| 4955 |
|
| 4956 |
ret = osrp4s(lstp+1); |
| 4957 |
|
| 4958 |
|
| 4959 |
lstadv(&lstp, &lstsiz); |
| 4960 |
} |
| 4961 |
else |
| 4962 |
{ |
| 4963 |
|
| 4964 |
ret = VOC_DISAMBIG_CONT; |
| 4965 |
} |
| 4966 |
|
| 4967 |
|
| 4968 |
if (ret == VOC_DISAMBIG_PARSE_RESP) |
| 4969 |
{ |
| 4970 |
|
| 4971 |
if (*lstp == DAT_SSTRING) |
| 4972 |
{ |
| 4973 |
uint len; |
| 4974 |
|
| 4975 |
|
| 4976 |
len = osrp2(lstp+1) - 2; |
| 4977 |
if (len > VOCBUFSIZ - 1) |
| 4978 |
len = VOCBUFSIZ - 1; |
| 4979 |
|
| 4980 |
|
| 4981 |
memcpy(resp, lstp+3, len); |
| 4982 |
resp[len] = '\0'; |
| 4983 |
} |
| 4984 |
else |
| 4985 |
{ |
| 4986 |
|
| 4987 |
ret = VOC_DISAMBIG_CONT; |
| 4988 |
} |
| 4989 |
} |
| 4990 |
else |
| 4991 |
{ |
| 4992 |
|
| 4993 |
for (i = 0 ; lstsiz > 0 && i < VOCMAXAMBIG-1 ; ++i) |
| 4994 |
{ |
| 4995 |
|
| 4996 |
if (*lstp == DAT_OBJECT) |
| 4997 |
objlist[i] = osrp2(lstp+1); |
| 4998 |
else |
| 4999 |
objlist[i] = MCMONINV; |
| 5000 |
|
| 5001 |
|
| 5002 |
lstadv(&lstp, &lstsiz); |
| 5003 |
|
| 5004 |
|
| 5005 |
if (lstsiz > 0 && *lstp == DAT_NUMBER) |
| 5006 |
{ |
| 5007 |
|
| 5008 |
flags[i] = (int)osrp4(lstp+1); |
| 5009 |
|
| 5010 |
|
| 5011 |
lstadv(&lstp, &lstsiz); |
| 5012 |
} |
| 5013 |
else |
| 5014 |
{ |
| 5015 |
|
| 5016 |
flags[i] = 0; |
| 5017 |
} |
| 5018 |
} |
| 5019 |
|
| 5020 |
|
| 5021 |
objlist[i] = MCMONINV; |
| 5022 |
flags[i] = 0; |
| 5023 |
|
| 5024 |
|
| 5025 |
*objcount = i; |
| 5026 |
} |
| 5027 |
|
| 5028 |
|
| 5029 |
return ret; |
| 5030 |
|
| 5031 |
case DAT_NUMBER: |
| 5032 |
|
| 5033 |
ret = runpopnum(rcx); |
| 5034 |
|
| 5035 |
|
| 5036 |
if (ret == VOC_DISAMBIG_PARSE_RESP) |
| 5037 |
ret = VOC_DISAMBIG_CONT; |
| 5038 |
|
| 5039 |
|
| 5040 |
return ret; |
| 5041 |
|
| 5042 |
default: |
| 5043 |
|
| 5044 |
rundisc(rcx); |
| 5045 |
return VOC_DISAMBIG_CONT; |
| 5046 |
} |
| 5047 |
} |
| 5048 |
|
| 5049 |
|
| 5050 |
|
| 5051 |
|
| 5052 |
|
| 5053 |
|
| 5054 |
|
| 5055 |
|
| 5056 |
|
| 5057 |
|
| 5058 |
|
| 5059 |
|
| 5060 |
static int voc_remove_objs_with_flag(voccxdef *ctx, |
| 5061 |
objnum *list, uint *flags, int cnt, |
| 5062 |
int flag_to_remove) |
| 5063 |
{ |
| 5064 |
int i; |
| 5065 |
int flag_cnt; |
| 5066 |
int special_cnt; |
| 5067 |
|
| 5068 |
|
| 5069 |
for (i = 0, flag_cnt = special_cnt = 0 ; i < cnt ; ++i) |
| 5070 |
{ |
| 5071 |
|
| 5072 |
if ((flags[i] & flag_to_remove) != 0) |
| 5073 |
++flag_cnt; |
| 5074 |
|
| 5075 |
|
| 5076 |
if (list[i] == ctx->voccxnum || list[i] == ctx->voccxstr) |
| 5077 |
++special_cnt; |
| 5078 |
} |
| 5079 |
|
| 5080 |
|
| 5081 |
|
| 5082 |
|
| 5083 |
|
| 5084 |
|
| 5085 |
|
| 5086 |
if (flag_cnt != 0 && flag_cnt < cnt - special_cnt) |
| 5087 |
{ |
| 5088 |
int dst; |
| 5089 |
|
| 5090 |
|
| 5091 |
|
| 5092 |
|
| 5093 |
|
| 5094 |
|
| 5095 |
for (i = 0, dst = 0 ; i < cnt ; ++i) |
| 5096 |
{ |
| 5097 |
|
| 5098 |
|
| 5099 |
|
| 5100 |
|
| 5101 |
if ((flags[i] & flag_to_remove) == 0 |
| 5102 |
|| list[i] == ctx->voccxnum |
| 5103 |
|| list[i] == ctx->voccxstr) |
| 5104 |
{ |
| 5105 |
|
| 5106 |
list[dst] = list[i]; |
| 5107 |
flags[dst] = flags[i]; |
| 5108 |
|
| 5109 |
|
| 5110 |
++dst; |
| 5111 |
} |
| 5112 |
} |
| 5113 |
|
| 5114 |
|
| 5115 |
cnt = dst; |
| 5116 |
list[cnt] = MCMONINV; |
| 5117 |
} |
| 5118 |
|
| 5119 |
|
| 5120 |
return cnt; |
| 5121 |
} |
| 5122 |
|
| 5123 |
|
| 5124 |
|
| 5125 |
|
| 5126 |
|
| 5127 |
|
| 5128 |
|
| 5129 |
|
| 5130 |
|
| 5131 |
|
| 5132 |
|
| 5133 |
|
| 5134 |
|
| 5135 |
|
| 5136 |
|
| 5137 |
|
| 5138 |
static int voc_prune_matches(voccxdef *ctx, |
| 5139 |
objnum *list, uint *flags, int cnt) |
| 5140 |
{ |
| 5141 |
|
| 5142 |
cnt = voc_remove_objs_with_flag(ctx, list, flags, cnt, VOCS_ENDADJ); |
| 5143 |
|
| 5144 |
|
| 5145 |
cnt = voc_remove_objs_with_flag(ctx, list, flags, cnt, VOCS_TRUNC); |
| 5146 |
|
| 5147 |
|
| 5148 |
return cnt; |
| 5149 |
} |
| 5150 |
|
| 5151 |
|
| 5152 |
|
| 5153 |
|
| 5154 |
|
| 5155 |
|
| 5156 |
|
| 5157 |
|
| 5158 |
|
| 5159 |
static int voc_count_diff(voccxdef *ctx, objnum *list, uint *flags, int *cnt, |
| 5160 |
int keep_all) |
| 5161 |
{ |
| 5162 |
int i; |
| 5163 |
int diff_cnt; |
| 5164 |
|
| 5165 |
|
| 5166 |
|
| 5167 |
|
| 5168 |
|
| 5169 |
|
| 5170 |
|
| 5171 |
diff_cnt = *cnt; |
| 5172 |
|
| 5173 |
|
| 5174 |
|
| 5175 |
|
| 5176 |
|
| 5177 |
|
| 5178 |
|
| 5179 |
|
| 5180 |
|
| 5181 |
|
| 5182 |
|
| 5183 |
|
| 5184 |
|
| 5185 |
for (i = 0 ; i < *cnt ; ++i) |
| 5186 |
{ |
| 5187 |
|
| 5188 |
|
| 5189 |
|
| 5190 |
|
| 5191 |
|
| 5192 |
runppr(ctx->voccxrun, list[i], PRP_ISEQUIV, 0); |
| 5193 |
if (runpoplog(ctx->voccxrun)) |
| 5194 |
{ |
| 5195 |
int j; |
| 5196 |
int dst; |
| 5197 |
objnum sc; |
| 5198 |
|
| 5199 |
|
| 5200 |
sc = objget1sc(ctx->voccxmem, list[i]); |
| 5201 |
if (sc == MCMONINV) |
| 5202 |
continue; |
| 5203 |
|
| 5204 |
|
| 5205 |
|
| 5206 |
|
| 5207 |
|
| 5208 |
for (j = i + 1, dst = i + 1 ; j < *cnt ; ++j) |
| 5209 |
{ |
| 5210 |
|
| 5211 |
|
| 5212 |
|
| 5213 |
|
| 5214 |
if (objget1sc(ctx->voccxmem, list[j]) != sc) |
| 5215 |
{ |
| 5216 |
|
| 5217 |
list[dst] = list[j]; |
| 5218 |
flags[dst++] = flags[j]; |
| 5219 |
} |
| 5220 |
else |
| 5221 |
{ |
| 5222 |
|
| 5223 |
|
| 5224 |
|
| 5225 |
|
| 5226 |
--diff_cnt; |
| 5227 |
|
| 5228 |
|
| 5229 |
|
| 5230 |
|
| 5231 |
|
| 5232 |
if (keep_all) |
| 5233 |
{ |
| 5234 |
|
| 5235 |
list[dst] = list[j]; |
| 5236 |
flags[dst++] = flags[j]; |
| 5237 |
} |
| 5238 |
} |
| 5239 |
} |
| 5240 |
|
| 5241 |
|
| 5242 |
*cnt = dst; |
| 5243 |
|
| 5244 |
|
| 5245 |
list[dst] = MCMONINV; |
| 5246 |
flags[dst] = 0; |
| 5247 |
} |
| 5248 |
} |
| 5249 |
|
| 5250 |
|
| 5251 |
return diff_cnt; |
| 5252 |
} |
| 5253 |
|
| 5254 |
|
| 5255 |
|
| 5256 |
|
| 5257 |
|
| 5258 |
|
| 5259 |
|
| 5260 |
|
| 5261 |
|
| 5262 |
|
| 5263 |
|
| 5264 |
|
| 5265 |
|
| 5266 |
|
| 5267 |
|
| 5268 |
int vocdisambig(voccxdef *ctx, vocoldef *outlist, vocoldef *inlist, |
| 5269 |
prpnum defprop, prpnum accprop, prpnum verprop, |
| 5270 |
char *cmd[], objnum otherobj, objnum cmdActor, |
| 5271 |
objnum cmdVerb, objnum cmdPrep, char *cmdbuf, |
| 5272 |
int silent) |
| 5273 |
{ |
| 5274 |
int inpos; |
| 5275 |
int outpos; |
| 5276 |
int listlen = voclistlen(inlist); |
| 5277 |
int noreach = FALSE; |
| 5278 |
prpnum listprop; |
| 5279 |
uchar *save_sp; |
| 5280 |
int old_unknown, old_lastunk; |
| 5281 |
int err; |
| 5282 |
int still_ambig; |
| 5283 |
|
| 5284 |
voc_enter(ctx, &save_sp); |
| 5285 |
|
| 5286 |
ERRBEGIN(ctx->voccxerr) |
| 5287 |
|
| 5288 |
|
| 5289 |
still_ambig = FALSE; |
| 5290 |
|
| 5291 |
|
| 5292 |
for (inpos = outpos = 0 ; inpos < listlen ; ++inpos) |
| 5293 |
{ |
| 5294 |
|
| 5295 |
|
| 5296 |
|
| 5297 |
|
| 5298 |
voc_leave(ctx, save_sp); |
| 5299 |
voc_enter(ctx, &save_sp); |
| 5300 |
|
| 5301 |
if (inlist[inpos].vocolflg == VOCS_STR) |
| 5302 |
{ |
| 5303 |
vocsetobj(ctx, ctx->voccxstr, DAT_SSTRING, |
| 5304 |
inlist[inpos].vocolfst + 1, |
| 5305 |
&inlist[inpos], &outlist[outpos]); |
| 5306 |
++outpos; |
| 5307 |
} |
| 5308 |
else if (inlist[inpos].vocolflg == VOCS_NUM) |
| 5309 |
{ |
| 5310 |
long v1; |
| 5311 |
char vbuf[4]; |
| 5312 |
|
| 5313 |
v1 = atol(inlist[inpos].vocolfst); |
| 5314 |
oswp4s(vbuf, v1); |
| 5315 |
vocsetobj(ctx, ctx->voccxnum, DAT_NUMBER, vbuf, |
| 5316 |
&inlist[inpos], &outlist[outpos]); |
| 5317 |
++outpos; |
| 5318 |
} |
| 5319 |
else if (inlist[inpos].vocolflg == VOCS_IT || |
| 5320 |
(inlist[inpos].vocolflg == VOCS_THEM && ctx->voccxthc == 0)) |
| 5321 |
{ |
| 5322 |
err = vocsetit(ctx, ctx->voccxit, accprop, cmdActor, |
| 5323 |
cmdVerb, cmdPrep, &outlist[outpos], |
| 5324 |
inlist[inpos].vocolflg == VOCS_IT ? "it" : "them", |
| 5325 |
(char)(inlist[inpos].vocolflg == VOCS_IT |
| 5326 |
? VOCW_IT : VOCW_THEM), defprop, silent); |
| 5327 |
if (err != 0) |
| 5328 |
goto done; |
| 5329 |
++outpos; |
| 5330 |
} |
| 5331 |
else if (inlist[inpos].vocolflg == VOCS_HIM) |
| 5332 |
{ |
| 5333 |
err = vocsetit(ctx, ctx->voccxhim, accprop, cmdActor, cmdVerb, |
| 5334 |
cmdPrep, &outlist[outpos], "him", VOCW_HIM, |
| 5335 |
defprop, silent); |
| 5336 |
if (err != 0) |
| 5337 |
goto done; |
| 5338 |
++outpos; |
| 5339 |
} |
| 5340 |
else if (inlist[inpos].vocolflg == VOCS_HER) |
| 5341 |
{ |
| 5342 |
err = vocsetit(ctx, ctx->voccxher, accprop, cmdActor, cmdVerb, |
| 5343 |
cmdPrep, &outlist[outpos], "her", VOCW_HER, |
| 5344 |
defprop, silent); |
| 5345 |
if (err != 0) |
| 5346 |
goto done; |
| 5347 |
++outpos; |
| 5348 |
} |
| 5349 |
else if (inlist[inpos].vocolflg == VOCS_THEM) |
| 5350 |
{ |
| 5351 |
int i; |
| 5352 |
int thempos = outpos; |
| 5353 |
static char them_name[] = "them"; |
| 5354 |
|
| 5355 |
for (i = 0 ; i < ctx->voccxthc ; ++i) |
| 5356 |
{ |
| 5357 |
if (outpos >= VOCMAXAMBIG) |
| 5358 |
{ |
| 5359 |
if (!silent) |
| 5360 |
vocerr(ctx, VOCERR(11), |
| 5361 |
"You're referring to too many objects."); |
| 5362 |
err = VOCERR(11); |
| 5363 |
goto done; |
| 5364 |
} |
| 5365 |
|
| 5366 |
|
| 5367 |
if (vocchkaccess(ctx, ctx->voccxthm[i], accprop, 0, |
| 5368 |
cmdActor, cmdVerb)) |
| 5369 |
{ |
| 5370 |
|
| 5371 |
vocout(&outlist[outpos++], ctx->voccxthm[i], VOCS_THEM, |
| 5372 |
them_name, them_name); |
| 5373 |
} |
| 5374 |
else |
| 5375 |
{ |
| 5376 |
|
| 5377 |
vocnoreach(ctx, &ctx->voccxthm[i], 1, |
| 5378 |
cmdActor, cmdVerb, cmdPrep, |
| 5379 |
defprop, TRUE, VOCS_THEM, i, ctx->voccxthc); |
| 5380 |
tioflush(ctx->voccxtio); |
| 5381 |
} |
| 5382 |
} |
| 5383 |
|
| 5384 |
|
| 5385 |
if (outpos == thempos) |
| 5386 |
{ |
| 5387 |
if (!silent) |
| 5388 |
vocerr(ctx, VOCERR(14), |
| 5389 |
"I don't know what you're referring to."); |
| 5390 |
err = VOCERR(14); |
| 5391 |
goto done; |
| 5392 |
} |
| 5393 |
} |
| 5394 |
else if (inlist[inpos].vocolflg == VOCS_ALL) |
| 5395 |
{ |
| 5396 |
uchar *l; |
| 5397 |
int exccnt = 0; |
| 5398 |
int allpos = outpos; |
| 5399 |
int k; |
| 5400 |
uint len; |
| 5401 |
static char all_name[] = "all"; |
| 5402 |
vocoldef *exclist; |
| 5403 |
vocoldef *exclist2; |
| 5404 |
|
| 5405 |
VOC_MAX_ARRAY(ctx, vocoldef, exclist); |
| 5406 |
VOC_MAX_ARRAY(ctx, vocoldef, exclist2); |
| 5407 |
|
| 5408 |
if (defprop != PRP_IODEFAULT) |
| 5409 |
runpobj(ctx->voccxrun, otherobj); |
| 5410 |
runpobj(ctx->voccxrun, cmdPrep); |
| 5411 |
runpobj(ctx->voccxrun, cmdActor); |
| 5412 |
runppr(ctx->voccxrun, cmdVerb, defprop, |
| 5413 |
defprop == PRP_DODEFAULT ? 3 : 2); |
| 5414 |
|
| 5415 |
if (runtostyp(ctx->voccxrun) == DAT_LIST) |
| 5416 |
{ |
| 5417 |
l = runpoplst(ctx->voccxrun); |
| 5418 |
len = osrp2(l) - 2; |
| 5419 |
l += 2; |
| 5420 |
|
| 5421 |
while (len) |
| 5422 |
{ |
| 5423 |
|
| 5424 |
if (*l == DAT_OBJECT) |
| 5425 |
vocout(&outlist[outpos++], (objnum)osrp2(l+1), 0, |
| 5426 |
all_name, all_name); |
| 5427 |
|
| 5428 |
|
| 5429 |
lstadv(&l, &len); |
| 5430 |
} |
| 5431 |
|
| 5432 |
vocout(&outlist[outpos], MCMONINV, 0, (char *)0, (char *)0); |
| 5433 |
} |
| 5434 |
else |
| 5435 |
rundisc(ctx->voccxrun); |
| 5436 |
|
| 5437 |
|
| 5438 |
if (outpos <= allpos) |
| 5439 |
{ |
| 5440 |
if (!silent) |
| 5441 |
vocerr(ctx, VOCERR(15), |
| 5442 |
"I don't see what you're referring to."); |
| 5443 |
err = VOCERR(15); |
| 5444 |
goto done; |
| 5445 |
} |
| 5446 |
|
| 5447 |
|
| 5448 |
while (inlist[inpos + 1].vocolflg & VOCS_EXCEPT) |
| 5449 |
{ |
| 5450 |
OSCPYSTRUCT(exclist[exccnt], inlist[++inpos]); |
| 5451 |
exclist[exccnt++].vocolflg &= ~VOCS_EXCEPT; |
| 5452 |
} |
| 5453 |
exclist[exccnt].vocolobj = MCMONINV; |
| 5454 |
exclist[exccnt].vocolflg = 0; |
| 5455 |
|
| 5456 |
|
| 5457 |
if (exccnt) |
| 5458 |
{ |
| 5459 |
err = vocdisambig(ctx, exclist2, exclist, defprop, accprop, |
| 5460 |
verprop, cmd, otherobj, cmdActor, |
| 5461 |
cmdVerb, cmdPrep, cmdbuf, silent); |
| 5462 |
if (err != 0) |
| 5463 |
goto done; |
| 5464 |
|
| 5465 |
exccnt = voclistlen(exclist2); |
| 5466 |
for (k = 0 ; k < exccnt ; ++k) |
| 5467 |
{ |
| 5468 |
int i; |
| 5469 |
for (i = allpos ; i < outpos ; ++i) |
| 5470 |
{ |
| 5471 |
if (outlist[i].vocolobj == exclist2[k].vocolobj) |
| 5472 |
{ |
| 5473 |
int j; |
| 5474 |
for (j = i ; j < outpos ; ++j) |
| 5475 |
outlist[j].vocolobj = outlist[j+1].vocolobj; |
| 5476 |
--i; |
| 5477 |
--outpos; |
| 5478 |
if (outpos <= allpos) |
| 5479 |
{ |
| 5480 |
if (!silent) |
| 5481 |
vocerr(ctx, VOCERR(15), |
| 5482 |
"I don't see what you're referring to."); |
| 5483 |
err = VOCERR(15); |
| 5484 |
goto done; |
| 5485 |
} |
| 5486 |
} |
| 5487 |
} |
| 5488 |
} |
| 5489 |
} |
| 5490 |
} |
| 5491 |
else |
| 5492 |
{ |
| 5493 |
int lpos = inpos; |
| 5494 |
int i = 0; |
| 5495 |
int cnt; |
| 5496 |
char *p; |
| 5497 |
int cnt2, cnt3; |
| 5498 |
int trying_again; |
| 5499 |
int user_count = 0; |
| 5500 |
objnum *cantreach_list; |
| 5501 |
int unknown_count; |
| 5502 |
int use_all_objs; |
| 5503 |
objnum *list1; |
| 5504 |
uint *flags1; |
| 5505 |
objnum *list2; |
| 5506 |
uint *flags2; |
| 5507 |
objnum *list3; |
| 5508 |
uint *flags3; |
| 5509 |
char *usrobj; |
| 5510 |
uchar *lstbuf; |
| 5511 |
char *newobj; |
| 5512 |
char *disnewbuf; |
| 5513 |
char *disbuffer; |
| 5514 |
char **diswordlist; |
| 5515 |
int *distypelist; |
| 5516 |
vocoldef *disnounlist; |
| 5517 |
int dst; |
| 5518 |
|
| 5519 |
VOC_MAX_ARRAY(ctx, objnum, list1); |
| 5520 |
VOC_MAX_ARRAY(ctx, objnum, list2); |
| 5521 |
VOC_MAX_ARRAY(ctx, objnum, list3); |
| 5522 |
VOC_MAX_ARRAY(ctx, uint, flags1); |
| 5523 |
VOC_MAX_ARRAY(ctx, uint, flags2); |
| 5524 |
VOC_MAX_ARRAY(ctx, uint, flags3); |
| 5525 |
VOC_MAX_ARRAY(ctx, vocoldef, disnounlist); |
| 5526 |
VOC_STK_ARRAY(ctx, char, disnewbuf, VOCBUFSIZ); |
| 5527 |
VOC_STK_ARRAY(ctx, char, disbuffer, 2*VOCBUFSIZ); |
| 5528 |
VOC_STK_ARRAY(ctx, char *, diswordlist, VOCBUFSIZ); |
| 5529 |
VOC_STK_ARRAY(ctx, int, distypelist, VOCBUFSIZ); |
| 5530 |
VOC_STK_ARRAY(ctx, char, usrobj, VOCBUFSIZ); |
| 5531 |
VOC_STK_ARRAY(ctx, char, newobj, VOCBUFSIZ); |
| 5532 |
VOC_STK_ARRAY(ctx, uchar, lstbuf, 2 + VOCMAXAMBIG*3); |
| 5533 |
|
| 5534 |
|
| 5535 |
unknown_count = 0; |
| 5536 |
|
| 5537 |
|
| 5538 |
|
| 5539 |
|
| 5540 |
|
| 5541 |
|
| 5542 |
|
| 5543 |
|
| 5544 |
|
| 5545 |
use_all_objs = FALSE; |
| 5546 |
|
| 5547 |
|
| 5548 |
|
| 5549 |
|
| 5550 |
|
| 5551 |
while (inlist[lpos].vocolfst == inlist[inpos].vocolfst |
| 5552 |
&& lpos < listlen) |
| 5553 |
{ |
| 5554 |
|
| 5555 |
list1[i] = inlist[lpos].vocolobj; |
| 5556 |
|
| 5557 |
|
| 5558 |
|
| 5559 |
|
| 5560 |
|
| 5561 |
|
| 5562 |
flags1[i] = inlist[lpos].vocolflg |
| 5563 |
& (VOCS_PLURAL | VOCS_ANY | VOCS_COUNT |
| 5564 |
| VOCS_ENDADJ | VOCS_TRUNC); |
| 5565 |
|
| 5566 |
|
| 5567 |
if (list1[i] != MCMONINV) |
| 5568 |
++i; |
| 5569 |
|
| 5570 |
|
| 5571 |
if ((inlist[lpos].vocolflg & VOCS_COUNT) != 0) |
| 5572 |
user_count = atoi(inlist[lpos].vocolfst); |
| 5573 |
|
| 5574 |
|
| 5575 |
if ((inlist[lpos].vocolflg & VOCS_UNKNOWN) != 0) |
| 5576 |
++unknown_count; |
| 5577 |
|
| 5578 |
|
| 5579 |
++lpos; |
| 5580 |
} |
| 5581 |
|
| 5582 |
|
| 5583 |
list1[i] = MCMONINV; |
| 5584 |
cnt = i; |
| 5585 |
|
| 5586 |
|
| 5587 |
|
| 5588 |
|
| 5589 |
|
| 5590 |
|
| 5591 |
if (unknown_count > 0) |
| 5592 |
{ |
| 5593 |
prpnum prp; |
| 5594 |
|
| 5595 |
|
| 5596 |
|
| 5597 |
|
| 5598 |
|
| 5599 |
|
| 5600 |
prp = (defprop == PRP_DODEFAULT |
| 5601 |
? PRP_PARSEUNKNOWNDOBJ : PRP_PARSEUNKNOWNIOBJ); |
| 5602 |
|
| 5603 |
|
| 5604 |
if (objgetap(ctx->voccxmem, cmdVerb, prp, (objnum *)0, FALSE)) |
| 5605 |
{ |
| 5606 |
uchar *lstp; |
| 5607 |
uint lstlen; |
| 5608 |
|
| 5609 |
|
| 5610 |
if (ctx->voccxflg & VOCCXFDBG) |
| 5611 |
tioputs(ctx->voccxtio, |
| 5612 |
"... unknown word: calling " |
| 5613 |
"parseUnknownXobj\\n"); |
| 5614 |
|
| 5615 |
|
| 5616 |
voc_push_strlist(ctx, inlist[inpos].vocolfst, |
| 5617 |
inlist[inpos].vocollst); |
| 5618 |
|
| 5619 |
|
| 5620 |
runpobj(ctx->voccxrun, otherobj); |
| 5621 |
runpobj(ctx->voccxrun, cmdPrep); |
| 5622 |
runpobj(ctx->voccxrun, cmdActor); |
| 5623 |
|
| 5624 |
|
| 5625 |
runppr(ctx->voccxrun, cmdVerb, prp, 4); |
| 5626 |
|
| 5627 |
|
| 5628 |
switch(runtostyp(ctx->voccxrun)) |
| 5629 |
{ |
| 5630 |
case DAT_OBJECT: |
| 5631 |
|
| 5632 |
|
| 5633 |
|
| 5634 |
|
| 5635 |
list1[cnt++] = runpopobj(ctx->voccxrun); |
| 5636 |
|
| 5637 |
|
| 5638 |
list1[cnt] = MCMONINV; |
| 5639 |
break; |
| 5640 |
|
| 5641 |
case DAT_LIST: |
| 5642 |
|
| 5643 |
|
| 5644 |
|
| 5645 |
|
| 5646 |
lstp = runpoplst(ctx->voccxrun); |
| 5647 |
|
| 5648 |
|
| 5649 |
lstlen = osrp2(lstp) - 2; |
| 5650 |
lstp += 2; |
| 5651 |
|
| 5652 |
|
| 5653 |
while (lstlen != 0) |
| 5654 |
{ |
| 5655 |
|
| 5656 |
if (*lstp == DAT_OBJECT |
| 5657 |
&& i < VOCMAXAMBIG) |
| 5658 |
list1[cnt++] = osrp2(lstp+1); |
| 5659 |
|
| 5660 |
|
| 5661 |
lstadv(&lstp, &lstlen); |
| 5662 |
} |
| 5663 |
|
| 5664 |
|
| 5665 |
|
| 5666 |
|
| 5667 |
|
| 5668 |
|
| 5669 |
|
| 5670 |
use_all_objs = TRUE; |
| 5671 |
|
| 5672 |
|
| 5673 |
list1[cnt] = MCMONINV; |
| 5674 |
break; |
| 5675 |
|
| 5676 |
case DAT_TRUE: |
| 5677 |
|
| 5678 |
|
| 5679 |
|
| 5680 |
|
| 5681 |
|
| 5682 |
|
| 5683 |
|
| 5684 |
|
| 5685 |
rundisc(ctx->voccxrun); |
| 5686 |
|
| 5687 |
|
| 5688 |
continue; |
| 5689 |
|
| 5690 |
default: |
| 5691 |
|
| 5692 |
|
| 5693 |
|
| 5694 |
|
| 5695 |
|
| 5696 |
|
| 5697 |
|
| 5698 |
|
| 5699 |
|
| 5700 |
|
| 5701 |
rundisc(ctx->voccxrun); |
| 5702 |
err = VOCERR(2); |
| 5703 |
goto done; |
| 5704 |
} |
| 5705 |
|
| 5706 |
|
| 5707 |
|
| 5708 |
|
| 5709 |
|
| 5710 |
|
| 5711 |
ctx->voccxunknown -= unknown_count; |
| 5712 |
} |
| 5713 |
else |
| 5714 |
{ |
| 5715 |
|
| 5716 |
if (ctx->voccxflg & VOCCXFDBG) |
| 5717 |
tioputs(ctx->voccxtio, |
| 5718 |
"... unknown word: no parseUnknownXobj - " |
| 5719 |
"restarting parsing\\n"); |
| 5720 |
|
| 5721 |
|
| 5722 |
|
| 5723 |
|
| 5724 |
|
| 5725 |
|
| 5726 |
|
| 5727 |
|
| 5728 |
|
| 5729 |
err = VOCERR(2); |
| 5730 |
goto done; |
| 5731 |
} |
| 5732 |
} |
| 5733 |
|
| 5734 |
|
| 5735 |
|
| 5736 |
|
| 5737 |
|
| 5738 |
|
| 5739 |
|
| 5740 |
|
| 5741 |
|
| 5742 |
|
| 5743 |
|
| 5744 |
|
| 5745 |
|
| 5746 |
|
| 5747 |
|
| 5748 |
|
| 5749 |
|
| 5750 |
|
| 5751 |
|
| 5752 |
|
| 5753 |
|
| 5754 |
|
| 5755 |
|
| 5756 |
if (accprop != PRP_VALIDACTOR && cnt != 0) |
| 5757 |
{ |
| 5758 |
if (defprop == PRP_DODEFAULT) |
| 5759 |
listprop = PRP_VALDOLIST; |
| 5760 |
else |
| 5761 |
listprop = PRP_VALIOLIST; |
| 5762 |
|
| 5763 |
|
| 5764 |
runpobj(ctx->voccxrun, otherobj); |
| 5765 |
runpobj(ctx->voccxrun, cmdPrep); |
| 5766 |
runpobj(ctx->voccxrun, cmdActor); |
| 5767 |
runppr(ctx->voccxrun, cmdVerb, listprop, 3); |
| 5768 |
if (runtostyp(ctx->voccxrun) == DAT_LIST) |
| 5769 |
{ |
| 5770 |
uchar *l; |
| 5771 |
uint len; |
| 5772 |
int kept_numobj; |
| 5773 |
|
| 5774 |
|
| 5775 |
kept_numobj = FALSE; |
| 5776 |
|
| 5777 |
|
| 5778 |
l = runpoplst(ctx->voccxrun); |
| 5779 |
len = osrp2(l) - 2; |
| 5780 |
l += 2; |
| 5781 |
|
| 5782 |
|
| 5783 |
|
| 5784 |
|
| 5785 |
|
| 5786 |
|
| 5787 |
for (cnt2 = 0 ; len != 0 ; ) |
| 5788 |
{ |
| 5789 |
if (*l == DAT_OBJECT) |
| 5790 |
{ |
| 5791 |
objnum o = osrp2(l+1); |
| 5792 |
|
| 5793 |
for (i = 0 ; i < cnt ; ++i) |
| 5794 |
{ |
| 5795 |
if (list1[i] == o) |
| 5796 |
{ |
| 5797 |
int j; |
| 5798 |
|
| 5799 |
|
| 5800 |
for (j = 0 ; j < cnt2 ; ++j) |
| 5801 |
if (list2[j] == o) break; |
| 5802 |
|
| 5803 |
|
| 5804 |
if (j == cnt2) |
| 5805 |
{ |
| 5806 |
|
| 5807 |
list2[cnt2] = o; |
| 5808 |
flags2[cnt2] = flags1[i]; |
| 5809 |
++cnt2; |
| 5810 |
|
| 5811 |
|
| 5812 |
|
| 5813 |
|
| 5814 |
|
| 5815 |
|
| 5816 |
|
| 5817 |
if (o == ctx->voccxnum) |
| 5818 |
kept_numobj = TRUE; |
| 5819 |
} |
| 5820 |
break; |
| 5821 |
} |
| 5822 |
} |
| 5823 |
} |
| 5824 |
|
| 5825 |
|
| 5826 |
lstadv(&l, &len); |
| 5827 |
} |
| 5828 |
|
| 5829 |
|
| 5830 |
|
| 5831 |
|
| 5832 |
|
| 5833 |
|
| 5834 |
|
| 5835 |
|
| 5836 |
|
| 5837 |
|
| 5838 |
|
| 5839 |
if (!kept_numobj) |
| 5840 |
{ |
| 5841 |
|
| 5842 |
for (i = 0 ; i < cnt ; ++i) |
| 5843 |
{ |
| 5844 |
|
| 5845 |
if (list1[i] == ctx->voccxnum) |
| 5846 |
{ |
| 5847 |
|
| 5848 |
list2[cnt2++] = ctx->voccxnum; |
| 5849 |
|
| 5850 |
|
| 5851 |
break; |
| 5852 |
} |
| 5853 |
} |
| 5854 |
} |
| 5855 |
|
| 5856 |
|
| 5857 |
memcpy(list1, list2, (size_t)(cnt2 * sizeof(list1[0]))); |
| 5858 |
memcpy(flags1, flags2, (size_t)cnt2 * sizeof(flags1[0])); |
| 5859 |
cnt = cnt2; |
| 5860 |
list1[cnt] = MCMONINV; |
| 5861 |
} |
| 5862 |
else |
| 5863 |
rundisc(ctx->voccxrun); |
| 5864 |
} |
| 5865 |
|
| 5866 |
|
| 5867 |
|
| 5868 |
|
| 5869 |
|
| 5870 |
|
| 5871 |
for (cnt = cnt3 = i = 0 ; list1[i] != MCMONINV ; ++i) |
| 5872 |
{ |
| 5873 |
int is_vis; |
| 5874 |
int is_acc; |
| 5875 |
|
| 5876 |
|
| 5877 |
is_vis = vocchkvis(ctx, list1[i], cmdActor); |
| 5878 |
|
| 5879 |
|
| 5880 |
is_acc = vocchkaccess(ctx, list1[i], accprop, i, |
| 5881 |
cmdActor, cmdVerb); |
| 5882 |
|
| 5883 |
|
| 5884 |
if (is_acc || is_vis) |
| 5885 |
{ |
| 5886 |
list1[cnt] = list1[i]; |
| 5887 |
flags1[cnt] = flags1[i]; |
| 5888 |
++cnt; |
| 5889 |
} |
| 5890 |
|
| 5891 |
|
| 5892 |
|
| 5893 |
|
| 5894 |
|
| 5895 |
if (is_vis) |
| 5896 |
{ |
| 5897 |
list3[cnt3] = list1[i]; |
| 5898 |
flags3[cnt3] = flags1[i]; |
| 5899 |
++cnt3; |
| 5900 |
} |
| 5901 |
} |
| 5902 |
|
| 5903 |
|
| 5904 |
|
| 5905 |
|
| 5906 |
|
| 5907 |
|
| 5908 |
|
| 5909 |
|
| 5910 |
|
| 5911 |
|
| 5912 |
|
| 5913 |
|
| 5914 |
|
| 5915 |
|
| 5916 |
|
| 5917 |
cnt = voc_prune_matches(ctx, list1, flags1, cnt); |
| 5918 |
cnt3 = voc_prune_matches(ctx, list3, flags3, cnt3); |
| 5919 |
|
| 5920 |
|
| 5921 |
|
| 5922 |
|
| 5923 |
|
| 5924 |
|
| 5925 |
|
| 5926 |
|
| 5927 |
|
| 5928 |
|
| 5929 |
|
| 5930 |
|
| 5931 |
|
| 5932 |
|
| 5933 |
for (dst = 0, i = 0 ; i < cnt ; ++i) |
| 5934 |
{ |
| 5935 |
|
| 5936 |
if (vocchkaccess(ctx, list1[i], accprop, i, |
| 5937 |
cmdActor, cmdVerb)) |
| 5938 |
{ |
| 5939 |
|
| 5940 |
list1[dst] = list1[i]; |
| 5941 |
flags1[dst] = flags1[i]; |
| 5942 |
|
| 5943 |
|
| 5944 |
++dst; |
| 5945 |
} |
| 5946 |
} |
| 5947 |
|
| 5948 |
|
| 5949 |
cnt = dst; |
| 5950 |
list1[dst] = MCMONINV; |
| 5951 |
|
| 5952 |
|
| 5953 |
|
| 5954 |
|
| 5955 |
|
| 5956 |
|
| 5957 |
for (i = 0, cnt2 = 0 ; i < cnt ; ++i) |
| 5958 |
{ |
| 5959 |
|
| 5960 |
if (accprop == PRP_VALIDACTOR) |
| 5961 |
{ |
| 5962 |
|
| 5963 |
runppr(ctx->voccxrun, list1[i], PRP_PREFACTOR, 0); |
| 5964 |
if (runpoplog(ctx->voccxrun)) |
| 5965 |
{ |
| 5966 |
list2[cnt2] = list1[i]; |
| 5967 |
flags2[cnt2] = flags1[i]; |
| 5968 |
++cnt2; |
| 5969 |
} |
| 5970 |
} |
| 5971 |
else |
| 5972 |
{ |
| 5973 |
|
| 5974 |
tiohide(ctx->voccxtio); |
| 5975 |
if (otherobj != MCMONINV) |
| 5976 |
runpobj(ctx->voccxrun, otherobj); |
| 5977 |
runpobj(ctx->voccxrun, cmdActor); |
| 5978 |
runppr(ctx->voccxrun, list1[i], verprop, |
| 5979 |
(otherobj != MCMONINV ? 2 : 1)); |
| 5980 |
|
| 5981 |
|
| 5982 |
|
| 5983 |
|
| 5984 |
|
| 5985 |
|
| 5986 |
if (!tioshow(ctx->voccxtio)) |
| 5987 |
{ |
| 5988 |
list2[cnt2] = list1[i]; |
| 5989 |
flags2[cnt2] = flags1[i]; |
| 5990 |
++cnt2; |
| 5991 |
} |
| 5992 |
} |
| 5993 |
} |
| 5994 |
|
| 5995 |
|
| 5996 |
|
| 5997 |
|
| 5998 |
|
| 5999 |
usrobj[0] = '\0'; |
| 6000 |
if (inlist[inpos].vocolfst != 0 && inlist[inpos].vocollst != 0) |
| 6001 |
{ |
| 6002 |
for (p = inlist[inpos].vocolfst ; p <= inlist[inpos].vocollst |
| 6003 |
; p += strlen(p) + 1) |
| 6004 |
{ |
| 6005 |
|
| 6006 |
if (usrobj[0] != '\0') |
| 6007 |
{ |
| 6008 |
|
| 6009 |
if (p[strlen(p)-1] == '.') |
| 6010 |
strcat(usrobj, "\\"); |
| 6011 |
|
| 6012 |
|
| 6013 |
strcat(usrobj, " "); |
| 6014 |
} |
| 6015 |
|
| 6016 |
|
| 6017 |
if (voc_check_special(ctx, p, VOCW_OF)) |
| 6018 |
vocaddof(ctx, usrobj); |
| 6019 |
else |
| 6020 |
strcat(usrobj, p); |
| 6021 |
} |
| 6022 |
} |
| 6023 |
|
| 6024 |
|
| 6025 |
|
| 6026 |
|
| 6027 |
|
| 6028 |
|
| 6029 |
|
| 6030 |
|
| 6031 |
|
| 6032 |
|
| 6033 |
|
| 6034 |
|
| 6035 |
|
| 6036 |
|
| 6037 |
if ((cnt2 == 0 |
| 6038 |
|| (cnt2 == 1 && list2[0] == ctx->voccxnum)) |
| 6039 |
&& inlist[inpos].vocolfst != 0 |
| 6040 |
&& inlist[inpos].vocolfst == inlist[inpos].vocollst |
| 6041 |
&& vocisdigit(*inlist[inpos].vocolfst)) |
| 6042 |
{ |
| 6043 |
long v1; |
| 6044 |
char vbuf[4]; |
| 6045 |
|
| 6046 |
v1 = atol(inlist[inpos].vocolfst); |
| 6047 |
oswp4s(vbuf, v1); |
| 6048 |
vocsetobj(ctx, ctx->voccxnum, DAT_NUMBER, vbuf, |
| 6049 |
&inlist[inpos], &outlist[outpos]); |
| 6050 |
outlist[outpos].vocolflg = VOCS_NUM; |
| 6051 |
++outpos; |
| 6052 |
|
| 6053 |
|
| 6054 |
for ( ; inlist[inpos+1].vocolobj != MCMONINV |
| 6055 |
&& inlist[inpos+1].vocolfst == inlist[inpos].vocolfst |
| 6056 |
; ++inpos) ; |
| 6057 |
continue; |
| 6058 |
} |
| 6059 |
|
| 6060 |
|
| 6061 |
|
| 6062 |
|
| 6063 |
|
| 6064 |
|
| 6065 |
if (cnt2 == 0 && cnt == 0) |
| 6066 |
{ |
| 6067 |
|
| 6068 |
|
| 6069 |
|
| 6070 |
|
| 6071 |
|
| 6072 |
if (cnt3 != 0) |
| 6073 |
{ |
| 6074 |
|
| 6075 |
cnt = cnt3; |
| 6076 |
cantreach_list = list3; |
| 6077 |
noreach = TRUE; |
| 6078 |
|
| 6079 |
|
| 6080 |
goto noreach1; |
| 6081 |
} |
| 6082 |
else |
| 6083 |
{ |
| 6084 |
|
| 6085 |
|
| 6086 |
|
| 6087 |
|
| 6088 |
|
| 6089 |
if (!silent) |
| 6090 |
vocerr(ctx, VOCERR(9), |
| 6091 |
"I don't see any %s here.", usrobj); |
| 6092 |
err = VOCERR(9); |
| 6093 |
goto done; |
| 6094 |
} |
| 6095 |
} |
| 6096 |
|
| 6097 |
|
| 6098 |
|
| 6099 |
|
| 6100 |
|
| 6101 |
|
| 6102 |
|
| 6103 |
|
| 6104 |
if (cnt2 != 0) |
| 6105 |
{ |
| 6106 |
|
| 6107 |
|
| 6108 |
|
| 6109 |
|
| 6110 |
cnt = cnt2; |
| 6111 |
memcpy(list1, list2, (size_t)(cnt2 * sizeof(list1[0]))); |
| 6112 |
memcpy(flags1, flags2, (size_t)(cnt2 * sizeof(flags1[0]))); |
| 6113 |
} |
| 6114 |
|
| 6115 |
|
| 6116 |
|
| 6117 |
|
| 6118 |
|
| 6119 |
|
| 6120 |
|
| 6121 |
|
| 6122 |
|
| 6123 |
|
| 6124 |
|
| 6125 |
for (dst = 0, i = 0 ; i < cnt ; ++i) |
| 6126 |
{ |
| 6127 |
int dup; |
| 6128 |
int j; |
| 6129 |
|
| 6130 |
|
| 6131 |
dup = FALSE; |
| 6132 |
|
| 6133 |
|
| 6134 |
|
| 6135 |
|
| 6136 |
|
| 6137 |
for (j = i + 1 ; j < cnt ; ++j) |
| 6138 |
{ |
| 6139 |
|
| 6140 |
if (list1[i] == list1[j]) |
| 6141 |
{ |
| 6142 |
|
| 6143 |
dup = TRUE; |
| 6144 |
|
| 6145 |
|
| 6146 |
break; |
| 6147 |
} |
| 6148 |
} |
| 6149 |
|
| 6150 |
|
| 6151 |
|
| 6152 |
|
| 6153 |
|
| 6154 |
if (!dup) |
| 6155 |
{ |
| 6156 |
|
| 6157 |
list1[dst] = list1[i]; |
| 6158 |
flags1[dst] = flags1[i]; |
| 6159 |
|
| 6160 |
|
| 6161 |
++dst; |
| 6162 |
} |
| 6163 |
} |
| 6164 |
|
| 6165 |
|
| 6166 |
cnt = dst; |
| 6167 |
list1[cnt] = MCMONINV; |
| 6168 |
|
| 6169 |
|
| 6170 |
|
| 6171 |
|
| 6172 |
|
| 6173 |
|
| 6174 |
|
| 6175 |
|
| 6176 |
if (cnt > 1) |
| 6177 |
{ |
| 6178 |
|
| 6179 |
for (i = 0, dst = 0 ; i < cnt ; ++i) |
| 6180 |
{ |
| 6181 |
|
| 6182 |
if (list1[i] != ctx->voccxnum) |
| 6183 |
list1[dst++] = list1[i]; |
| 6184 |
} |
| 6185 |
|
| 6186 |
|
| 6187 |
cnt = dst; |
| 6188 |
list1[cnt] = MCMONINV; |
| 6189 |
} |
| 6190 |
|
| 6191 |
|
| 6192 |
|
| 6193 |
|
| 6194 |
|
| 6195 |
|
| 6196 |
|
| 6197 |
for (i = 0 ; i < cnt ; ++i) |
| 6198 |
{ |
| 6199 |
if (has_gen_num_adj(ctx, list1[i])) |
| 6200 |
{ |
| 6201 |
|
| 6202 |
|
| 6203 |
|
| 6204 |
|
| 6205 |
|
| 6206 |
|
| 6207 |
|
| 6208 |
|
| 6209 |
|
| 6210 |
|
| 6211 |
if ((flags1[i] & (VOCS_ANY | VOCS_COUNT)) != 0) |
| 6212 |
{ |
| 6213 |
int n = (user_count ? user_count : 1); |
| 6214 |
int j; |
| 6215 |
objnum objn = list1[i]; |
| 6216 |
|
| 6217 |
|
| 6218 |
|
| 6219 |
|
| 6220 |
|
| 6221 |
|
| 6222 |
|
| 6223 |
|
| 6224 |
if (i + 1 != cnt && n > 1) |
| 6225 |
{ |
| 6226 |
memmove(&list1[i + n - 1], &list1[i], |
| 6227 |
(cnt - i) * sizeof(list1[i])); |
| 6228 |
memmove(&flags1[i + n - 1], &flags1[i], |
| 6229 |
(cnt - i) * sizeof(flags1[i])); |
| 6230 |
} |
| 6231 |
|
| 6232 |
|
| 6233 |
for (j = 0 ; j < n ; ++j) |
| 6234 |
{ |
| 6235 |
long l; |
| 6236 |
|
| 6237 |
|
| 6238 |
|
| 6239 |
|
| 6240 |
|
| 6241 |
|
| 6242 |
runpnum(ctx->voccxrun, (long)(j + 1)); |
| 6243 |
runppr(ctx->voccxrun, objn, PRP_ANYVALUE, 1); |
| 6244 |
l = runpopnum(ctx->voccxrun); |
| 6245 |
|
| 6246 |
|
| 6247 |
list1[i+j] = |
| 6248 |
voc_new_num_obj(ctx, objn, |
| 6249 |
cmdActor, cmdVerb, |
| 6250 |
l, FALSE); |
| 6251 |
if (list1[i+j] == MCMONINV) |
| 6252 |
{ |
| 6253 |
err = VOCERR(40); |
| 6254 |
goto done; |
| 6255 |
} |
| 6256 |
} |
| 6257 |
} |
| 6258 |
else if ((flags1[i] & VOCS_PLURAL) != 0) |
| 6259 |
{ |
| 6260 |
|
| 6261 |
|
| 6262 |
|
| 6263 |
|
| 6264 |
list1[i] = |
| 6265 |
voc_new_num_obj(ctx, list1[i], cmdActor, cmdVerb, |
| 6266 |
(long)0, TRUE); |
| 6267 |
if (list1[i] == MCMONINV) |
| 6268 |
{ |
| 6269 |
err = VOCERR(40); |
| 6270 |
goto done; |
| 6271 |
} |
| 6272 |
} |
| 6273 |
else |
| 6274 |
{ |
| 6275 |
char *p; |
| 6276 |
int found; |
| 6277 |
|
| 6278 |
|
| 6279 |
|
| 6280 |
|
| 6281 |
|
| 6282 |
|
| 6283 |
|
| 6284 |
for (found = FALSE, p = inlist[inpos].vocolfst ; |
| 6285 |
p != 0 && p <= inlist[inpos].vocollst ; |
| 6286 |
p += strlen(p) + 1) |
| 6287 |
{ |
| 6288 |
|
| 6289 |
if (vocisdigit(*p)) |
| 6290 |
{ |
| 6291 |
long l; |
| 6292 |
|
| 6293 |
|
| 6294 |
l = atol(p); |
| 6295 |
|
| 6296 |
|
| 6297 |
list1[i] = voc_new_num_obj(ctx, list1[i], |
| 6298 |
cmdActor, cmdVerb, |
| 6299 |
l, FALSE); |
| 6300 |
if (list1[i] == MCMONINV) |
| 6301 |
{ |
| 6302 |
err = VOCERR(40); |
| 6303 |
goto done; |
| 6304 |
} |
| 6305 |
|
| 6306 |
|
| 6307 |
found = TRUE; |
| 6308 |
break; |
| 6309 |
} |
| 6310 |
} |
| 6311 |
|
| 6312 |
|
| 6313 |
if (!found) |
| 6314 |
{ |
| 6315 |
if (!silent) |
| 6316 |
vocerr(ctx, VOCERR(160), |
| 6317 |
"You'll have to be more specific about which %s you mean.", |
| 6318 |
usrobj); |
| 6319 |
err = VOCERR(160); |
| 6320 |
goto done; |
| 6321 |
} |
| 6322 |
} |
| 6323 |
} |
| 6324 |
} |
| 6325 |
|
| 6326 |
|
| 6327 |
|
| 6328 |
|
| 6329 |
|
| 6330 |
trying_again = FALSE; |
| 6331 |
for (;;) |
| 6332 |
{ |
| 6333 |
int wrdcnt; |
| 6334 |
int next; |
| 6335 |
uchar *p; |
| 6336 |
int cleared_noun; |
| 6337 |
int diff_cnt; |
| 6338 |
int stat; |
| 6339 |
int num_wanted; |
| 6340 |
int is_ambig; |
| 6341 |
int all_plural; |
| 6342 |
|
| 6343 |
|
| 6344 |
|
| 6345 |
|
| 6346 |
|
| 6347 |
|
| 6348 |
if ((flags1[0] & (VOCS_PLURAL | VOCS_ANY | VOCS_COUNT)) != 0) |
| 6349 |
{ |
| 6350 |
int i; |
| 6351 |
|
| 6352 |
|
| 6353 |
|
| 6354 |
|
| 6355 |
|
| 6356 |
|
| 6357 |
|
| 6358 |
|
| 6359 |
for (all_plural = VOCS_PLURAL | VOCS_ANY | VOCS_COUNT, |
| 6360 |
i = 0 ; i < cnt ; ++i) |
| 6361 |
{ |
| 6362 |
|
| 6363 |
all_plural &= flags1[i]; |
| 6364 |
|
| 6365 |
|
| 6366 |
|
| 6367 |
|
| 6368 |
|
| 6369 |
if (!all_plural) |
| 6370 |
break; |
| 6371 |
} |
| 6372 |
} |
| 6373 |
else |
| 6374 |
{ |
| 6375 |
|
| 6376 |
|
| 6377 |
|
| 6378 |
|
| 6379 |
all_plural = 0; |
| 6380 |
} |
| 6381 |
|
| 6382 |
|
| 6383 |
|
| 6384 |
|
| 6385 |
|
| 6386 |
|
| 6387 |
|
| 6388 |
|
| 6389 |
|
| 6390 |
|
| 6391 |
|
| 6392 |
|
| 6393 |
diff_cnt = voc_count_diff(ctx, list1, flags1, &cnt, |
| 6394 |
all_plural != 0 || use_all_objs); |
| 6395 |
|
| 6396 |
|
| 6397 |
|
| 6398 |
|
| 6399 |
|
| 6400 |
|
| 6401 |
|
| 6402 |
|
| 6403 |
|
| 6404 |
|
| 6405 |
if (use_all_objs) |
| 6406 |
{ |
| 6407 |
|
| 6408 |
num_wanted = cnt; |
| 6409 |
is_ambig = FALSE; |
| 6410 |
} |
| 6411 |
else if ((all_plural & VOCS_COUNT) != 0) |
| 6412 |
{ |
| 6413 |
|
| 6414 |
|
| 6415 |
|
| 6416 |
|
| 6417 |
|
| 6418 |
|
| 6419 |
num_wanted = user_count; |
| 6420 |
is_ambig = FALSE; |
| 6421 |
} |
| 6422 |
else if ((all_plural & VOCS_ANY) != 0) |
| 6423 |
{ |
| 6424 |
|
| 6425 |
|
| 6426 |
|
| 6427 |
|
| 6428 |
|
| 6429 |
num_wanted = 1; |
| 6430 |
is_ambig = FALSE; |
| 6431 |
} |
| 6432 |
else if (all_plural != 0) |
| 6433 |
{ |
| 6434 |
|
| 6435 |
|
| 6436 |
|
| 6437 |
|
| 6438 |
num_wanted = cnt; |
| 6439 |
is_ambig = FALSE; |
| 6440 |
} |
| 6441 |
else |
| 6442 |
{ |
| 6443 |
|
| 6444 |
|
| 6445 |
|
| 6446 |
|
| 6447 |
|
| 6448 |
num_wanted = 1; |
| 6449 |
is_ambig = (cnt != 1); |
| 6450 |
} |
| 6451 |
|
| 6452 |
|
| 6453 |
stat = voc_disambig_hook(ctx, cmdVerb, cmdActor, cmdPrep, |
| 6454 |
otherobj, accprop, verprop, |
| 6455 |
list1, flags1, &cnt, |
| 6456 |
inlist[inpos].vocolfst, |
| 6457 |
inlist[inpos].vocollst, |
| 6458 |
num_wanted, is_ambig, disnewbuf, |
| 6459 |
silent); |
| 6460 |
|
| 6461 |
|
| 6462 |
if (stat == VOC_DISAMBIG_DONE) |
| 6463 |
{ |
| 6464 |
|
| 6465 |
for (i = 0 ; i < cnt ; ++i) |
| 6466 |
vocout(&outlist[outpos++], list1[i], flags1[i], |
| 6467 |
inlist[inpos].vocolfst, |
| 6468 |
inlist[inpos].vocollst); |
| 6469 |
|
| 6470 |
|
| 6471 |
break; |
| 6472 |
} |
| 6473 |
else if (stat == VOC_DISAMBIG_CONT) |
| 6474 |
{ |
| 6475 |
|
| 6476 |
|
| 6477 |
|
| 6478 |
|
| 6479 |
|
| 6480 |
|
| 6481 |
|
| 6482 |
|
| 6483 |
|
| 6484 |
|
| 6485 |
diff_cnt = voc_count_diff(ctx, list1, flags1, &cnt, TRUE); |
| 6486 |
} |
| 6487 |
else if (stat == VOC_DISAMBIG_PARSE_RESP |
| 6488 |
|| stat == VOC_DISAMBIG_PROMPTED) |
| 6489 |
{ |
| 6490 |
|
| 6491 |
|
| 6492 |
|
| 6493 |
|
| 6494 |
|
| 6495 |
|
| 6496 |
|
| 6497 |
|
| 6498 |
|
| 6499 |
|
| 6500 |
|
| 6501 |
|
| 6502 |
|
| 6503 |
|
| 6504 |
|
| 6505 |
|
| 6506 |
|
| 6507 |
|
| 6508 |
} |
| 6509 |
else |
| 6510 |
{ |
| 6511 |
|
| 6512 |
err = VOCERR(41); |
| 6513 |
goto done; |
| 6514 |
} |
| 6515 |
|
| 6516 |
|
| 6517 |
|
| 6518 |
|
| 6519 |
|
| 6520 |
|
| 6521 |
if (cnt == 1 || all_plural || use_all_objs) |
| 6522 |
{ |
| 6523 |
int flags; |
| 6524 |
|
| 6525 |
|
| 6526 |
if ((all_plural & VOCS_COUNT) != 0) |
| 6527 |
{ |
| 6528 |
if (user_count > cnt) |
| 6529 |
{ |
| 6530 |
if (!silent) |
| 6531 |
vocerr(ctx, VOCERR(30), |
| 6532 |
"I only see %d of those.", cnt); |
| 6533 |
err = VOCERR(30); |
| 6534 |
goto done; |
| 6535 |
} |
| 6536 |
cnt = user_count; |
| 6537 |
flags = VOCS_ALL; |
| 6538 |
} |
| 6539 |
else if ((all_plural & VOCS_ANY) != 0) |
| 6540 |
{ |
| 6541 |
cnt = 1; |
| 6542 |
flags = VOCS_ALL; |
| 6543 |
} |
| 6544 |
else |
| 6545 |
flags = 0; |
| 6546 |
|
| 6547 |
|
| 6548 |
for (i = 0 ; i < cnt ; ++i) |
| 6549 |
vocout(&outlist[outpos++], list1[i], flags, |
| 6550 |
inlist[inpos].vocolfst, |
| 6551 |
inlist[inpos].vocollst); |
| 6552 |
|
| 6553 |
|
| 6554 |
break; |
| 6555 |
} |
| 6556 |
|
| 6557 |
|
| 6558 |
tiocapture(ctx->voccxtio, (mcmcxdef *)0, FALSE); |
| 6559 |
tioclrcapture(ctx->voccxtio); |
| 6560 |
|
| 6561 |
|
| 6562 |
|
| 6563 |
|
| 6564 |
|
| 6565 |
if (silent) |
| 6566 |
{ |
| 6567 |
|
| 6568 |
|
| 6569 |
|
| 6570 |
|
| 6571 |
|
| 6572 |
|
| 6573 |
|
| 6574 |
for (i = 0 ; i < cnt && outpos < VOCMAXAMBIG ; ++i) |
| 6575 |
vocout(&outlist[outpos++], list1[i], 0, |
| 6576 |
inlist[inpos].vocolfst, |
| 6577 |
inlist[inpos].vocollst); |
| 6578 |
|
| 6579 |
|
| 6580 |
still_ambig = TRUE; |
| 6581 |
|
| 6582 |
|
| 6583 |
break; |
| 6584 |
} |
| 6585 |
|
| 6586 |
|
| 6587 |
|
| 6588 |
|
| 6589 |
|
| 6590 |
|
| 6591 |
|
| 6592 |
|
| 6593 |
|
| 6594 |
|
| 6595 |
|
| 6596 |
|
| 6597 |
|
| 6598 |
|
| 6599 |
if (stat == VOC_DISAMBIG_PARSE_RESP |
| 6600 |
|| stat == VOC_DISAMBIG_PROMPTED) |
| 6601 |
{ |
| 6602 |
|
| 6603 |
|
| 6604 |
|
| 6605 |
|
| 6606 |
} |
| 6607 |
else if (ctx->voccxpdis != MCMONINV) |
| 6608 |
{ |
| 6609 |
uint l; |
| 6610 |
|
| 6611 |
|
| 6612 |
|
| 6613 |
|
| 6614 |
|
| 6615 |
|
| 6616 |
|
| 6617 |
for (i = 0, p = lstbuf+2 ; i < cnt ; ++i, p += 2) |
| 6618 |
{ |
| 6619 |
*p++ = DAT_OBJECT; |
| 6620 |
oswp2(p, list1[i]); |
| 6621 |
} |
| 6622 |
l = p - lstbuf; |
| 6623 |
oswp2(lstbuf, l); |
| 6624 |
runpbuf(ctx->voccxrun, DAT_LIST, lstbuf); |
| 6625 |
runpstr(ctx->voccxrun, usrobj, (int)strlen(usrobj), 1); |
| 6626 |
runfn(ctx->voccxrun, ctx->voccxpdis, 2); |
| 6627 |
} |
| 6628 |
else |
| 6629 |
{ |
| 6630 |
|
| 6631 |
if (trying_again) |
| 6632 |
vocerr_info(ctx, VOCERR(100), "Let's try it again: "); |
| 6633 |
|
| 6634 |
|
| 6635 |
vocerr_info(ctx, VOCERR(101), |
| 6636 |
"Which %s do you mean, ", usrobj); |
| 6637 |
for (i = 0 ; i < cnt ; ) |
| 6638 |
{ |
| 6639 |
int eqcnt; |
| 6640 |
int j; |
| 6641 |
objnum sc; |
| 6642 |
|
| 6643 |
|
| 6644 |
|
| 6645 |
|
| 6646 |
|
| 6647 |
|
| 6648 |
|
| 6649 |
|
| 6650 |
eqcnt = 1; |
| 6651 |
runppr(ctx->voccxrun, list1[i], PRP_ISEQUIV, 0); |
| 6652 |
if (runpoplog(ctx->voccxrun)) |
| 6653 |
{ |
| 6654 |
|
| 6655 |
sc = objget1sc(ctx->voccxmem, list1[i]); |
| 6656 |
if (sc != MCMONINV) |
| 6657 |
{ |
| 6658 |
|
| 6659 |
for (j = i + 1 ; j < cnt ; ++j) |
| 6660 |
{ |
| 6661 |
if (objget1sc(ctx->voccxmem, list1[j]) |
| 6662 |
== sc) |
| 6663 |
++eqcnt; |
| 6664 |
else |
| 6665 |
break; |
| 6666 |
} |
| 6667 |
} |
| 6668 |
} |
| 6669 |
|
| 6670 |
|
| 6671 |
|
| 6672 |
|
| 6673 |
|
| 6674 |
|
| 6675 |
runppr(ctx->voccxrun, list1[i], |
| 6676 |
(prpnum)(eqcnt == 1 ? |
| 6677 |
PRP_THEDESC : PRP_ADESC), 0); |
| 6678 |
|
| 6679 |
|
| 6680 |
if (i + 1 < diff_cnt) |
| 6681 |
vocerr_info(ctx, VOCERR(102), ", "); |
| 6682 |
if (i + 2 == diff_cnt) |
| 6683 |
vocerr_info(ctx, VOCERR(103), "or "); |
| 6684 |
|
| 6685 |
|
| 6686 |
i += eqcnt; |
| 6687 |
} |
| 6688 |
vocerr_info(ctx, VOCERR(104), "?"); |
| 6689 |
} |
| 6690 |
|
| 6691 |
|
| 6692 |
|
| 6693 |
|
| 6694 |
|
| 6695 |
|
| 6696 |
if (stat != VOC_DISAMBIG_PARSE_RESP |
| 6697 |
&& vocread(ctx, cmdActor, cmdVerb, disnewbuf, |
| 6698 |
(int)VOCBUFSIZ, 2) == VOCREAD_REDO) |
| 6699 |
{ |
| 6700 |
|
| 6701 |
strcpy(cmdbuf, disnewbuf); |
| 6702 |
ctx->voccxunknown = 0; |
| 6703 |
ctx->voccxredo = TRUE; |
| 6704 |
err = VOCERR(43); |
| 6705 |
goto done; |
| 6706 |
} |
| 6707 |
|
| 6708 |
|
| 6709 |
|
| 6710 |
|
| 6711 |
|
| 6712 |
|
| 6713 |
wrdcnt = voctok(ctx, disnewbuf, disbuffer, diswordlist, |
| 6714 |
TRUE, TRUE, TRUE); |
| 6715 |
if (wrdcnt == 0) |
| 6716 |
{ |
| 6717 |
|
| 6718 |
runfn(ctx->voccxrun, ctx->voccxprd, 0); |
| 6719 |
err = VOCERR(42); |
| 6720 |
goto done; |
| 6721 |
} |
| 6722 |
if (wrdcnt < 0) |
| 6723 |
{ |
| 6724 |
|
| 6725 |
err = VOCERR(1); |
| 6726 |
goto done; |
| 6727 |
} |
| 6728 |
|
| 6729 |
|
| 6730 |
|
| 6731 |
|
| 6732 |
|
| 6733 |
|
| 6734 |
|
| 6735 |
|
| 6736 |
|
| 6737 |
|
| 6738 |
old_unknown = ctx->voccxunknown; |
| 6739 |
old_lastunk = ctx->voccxlastunk; |
| 6740 |
ctx->voccxunknown = 0; |
| 6741 |
|
| 6742 |
|
| 6743 |
memset(distypelist, 0, VOCBUFSIZ * sizeof(distypelist[0])); |
| 6744 |
|
| 6745 |
|
| 6746 |
diswordlist[wrdcnt] = 0; |
| 6747 |
if (vocgtyp(ctx, diswordlist, distypelist, cmdbuf) |
| 6748 |
|| ctx->voccxunknown != 0) |
| 6749 |
{ |
| 6750 |
|
| 6751 |
|
| 6752 |
|
| 6753 |
|
| 6754 |
strcpy(cmdbuf, disnewbuf); |
| 6755 |
ctx->voccxunknown = 0; |
| 6756 |
ctx->voccxredo = TRUE; |
| 6757 |
err = VOCERR(2); |
| 6758 |
goto done; |
| 6759 |
} |
| 6760 |
|
| 6761 |
|
| 6762 |
ctx->voccxunknown = old_unknown; |
| 6763 |
ctx->voccxlastunk = old_lastunk; |
| 6764 |
|
| 6765 |
|
| 6766 |
|
| 6767 |
|
| 6768 |
|
| 6769 |
|
| 6770 |
|
| 6771 |
|
| 6772 |
|
| 6773 |
|
| 6774 |
for (i = 0 ; i < wrdcnt ; ++i) |
| 6775 |
{ |
| 6776 |
if (!(distypelist[i] & |
| 6777 |
(VOCT_ADJ | VOCT_NOUN | VOCT_ARTICLE))) |
| 6778 |
break; |
| 6779 |
} |
| 6780 |
|
| 6781 |
if (i && (distypelist[i-1] & VOCT_ADJ) |
| 6782 |
&& (distypelist[i-1] & VOCT_NOUN)) |
| 6783 |
{ |
| 6784 |
|
| 6785 |
|
| 6786 |
|
| 6787 |
|
| 6788 |
|
| 6789 |
|
| 6790 |
|
| 6791 |
|
| 6792 |
cleared_noun = i-1; |
| 6793 |
distypelist[i-1] &= ~VOCT_NOUN; |
| 6794 |
} |
| 6795 |
else |
| 6796 |
cleared_noun = -1; |
| 6797 |
|
| 6798 |
try_current_flags: |
| 6799 |
|
| 6800 |
if (vocspec(diswordlist[0], VOCW_ALL) |
| 6801 |
|| vocspec(diswordlist[0], VOCW_BOTH)) |
| 6802 |
{ |
| 6803 |
char *nam; |
| 6804 |
static char all_name[] = "all"; |
| 6805 |
static char both_name[] = "both"; |
| 6806 |
|
| 6807 |
if (vocspec(diswordlist[0], VOCW_ALL)) |
| 6808 |
nam = all_name; |
| 6809 |
else |
| 6810 |
nam = both_name; |
| 6811 |
|
| 6812 |
for (i = 0 ; i < cnt ; ++i) |
| 6813 |
vocout(&outlist[outpos++], list1[i], 0, nam, nam); |
| 6814 |
if (noreach) |
| 6815 |
{ |
| 6816 |
cantreach_list = list1; |
| 6817 |
goto noreach1; |
| 6818 |
} |
| 6819 |
break; |
| 6820 |
} |
| 6821 |
else if (vocspec(diswordlist[0], VOCW_ANY)) |
| 6822 |
{ |
| 6823 |
static char *anynm = "any"; |
| 6824 |
|
| 6825 |
|
| 6826 |
vocout(&outlist[outpos++], list1[i], VOCS_ALL, |
| 6827 |
anynm, anynm); |
| 6828 |
break; |
| 6829 |
} |
| 6830 |
else |
| 6831 |
{ |
| 6832 |
|
| 6833 |
cnt2 = vocchknoun(ctx, diswordlist, distypelist, |
| 6834 |
0, &next, disnounlist, FALSE); |
| 6835 |
if (cnt2 > 0) |
| 6836 |
{ |
| 6837 |
|
| 6838 |
|
| 6839 |
|
| 6840 |
|
| 6841 |
|
| 6842 |
|
| 6843 |
if (diswordlist[next] != 0 |
| 6844 |
&& !vocspec(diswordlist[next], VOCW_ONE) |
| 6845 |
&& !vocspec(diswordlist[next], VOCW_ONES) |
| 6846 |
&& !vocspec(diswordlist[next], VOCW_THEN)) |
| 6847 |
{ |
| 6848 |
cnt2 = 0; |
| 6849 |
} |
| 6850 |
} |
| 6851 |
else if (cnt2 < 0) |
| 6852 |
{ |
| 6853 |
|
| 6854 |
|
| 6855 |
|
| 6856 |
|
| 6857 |
|
| 6858 |
err = VOCERR(45); |
| 6859 |
goto done; |
| 6860 |
} |
| 6861 |
|
| 6862 |
|
| 6863 |
if (cnt2 > 0) |
| 6864 |
{ |
| 6865 |
int cnt3; |
| 6866 |
int newcnt; |
| 6867 |
|
| 6868 |
|
| 6869 |
for (i = 0, newcnt = 0 ; i < cnt2 ; ++i) |
| 6870 |
{ |
| 6871 |
int j; |
| 6872 |
int found; |
| 6873 |
|
| 6874 |
|
| 6875 |
|
| 6876 |
|
| 6877 |
|
| 6878 |
for (j = 0, found = FALSE ; j < newcnt ; ++j) |
| 6879 |
{ |
| 6880 |
|
| 6881 |
if (list2[j] == disnounlist[i].vocolobj) |
| 6882 |
{ |
| 6883 |
found = TRUE; |
| 6884 |
break; |
| 6885 |
} |
| 6886 |
} |
| 6887 |
|
| 6888 |
|
| 6889 |
|
| 6890 |
|
| 6891 |
|
| 6892 |
if (!found) |
| 6893 |
{ |
| 6894 |
|
| 6895 |
list2[newcnt] = disnounlist[i].vocolobj; |
| 6896 |
|
| 6897 |
|
| 6898 |
flags2[newcnt] = disnounlist[i].vocolflg |
| 6899 |
& (VOCS_PLURAL | VOCS_ANY |
| 6900 |
| VOCS_COUNT); |
| 6901 |
|
| 6902 |
|
| 6903 |
++newcnt; |
| 6904 |
} |
| 6905 |
} |
| 6906 |
|
| 6907 |
|
| 6908 |
list2[newcnt] = MCMONINV; |
| 6909 |
|
| 6910 |
|
| 6911 |
newcnt = vocisect(list2, list1); |
| 6912 |
|
| 6913 |
|
| 6914 |
for (i = cnt3 = 0 ; i < cnt2 ; ++i) |
| 6915 |
{ |
| 6916 |
|
| 6917 |
++cnt3; |
| 6918 |
|
| 6919 |
|
| 6920 |
if (disnounlist[i].vocolfst != 0) |
| 6921 |
{ |
| 6922 |
int j; |
| 6923 |
|
| 6924 |
|
| 6925 |
for (j = i + 1 ; disnounlist[i].vocolfst == |
| 6926 |
disnounlist[j].vocolfst ; ++j) ; |
| 6927 |
i = j - 1; |
| 6928 |
} |
| 6929 |
} |
| 6930 |
|
| 6931 |
|
| 6932 |
|
| 6933 |
|
| 6934 |
|
| 6935 |
|
| 6936 |
|
| 6937 |
|
| 6938 |
|
| 6939 |
|
| 6940 |
if (newcnt |
| 6941 |
&& (newcnt <= cnt3 |
| 6942 |
|| (diswordlist[next] |
| 6943 |
&& vocspec(diswordlist[next], |
| 6944 |
VOCW_ONES)))) |
| 6945 |
{ |
| 6946 |
static char one_name[] = "ones"; |
| 6947 |
|
| 6948 |
for (i = 0 ; i < cnt ; ++i) |
| 6949 |
vocout(&outlist[outpos++], list2[i], 0, |
| 6950 |
one_name, one_name); |
| 6951 |
|
| 6952 |
if (noreach) |
| 6953 |
{ |
| 6954 |
cnt = newcnt; |
| 6955 |
cantreach_list = list2; |
| 6956 |
noreach1: |
| 6957 |
if (accprop == PRP_VALIDACTOR) |
| 6958 |
{ |
| 6959 |
|
| 6960 |
vocerr(ctx, VOCERR(31), |
| 6961 |
"You can't talk to that."); |
| 6962 |
} |
| 6963 |
else |
| 6964 |
{ |
| 6965 |
|
| 6966 |
vocnoreach(ctx, cantreach_list, cnt, |
| 6967 |
cmdActor, cmdVerb, cmdPrep, |
| 6968 |
defprop, cnt > 1, 0, 0, cnt); |
| 6969 |
} |
| 6970 |
err = VOCERR(31); |
| 6971 |
goto done; |
| 6972 |
} |
| 6973 |
break; |
| 6974 |
} |
| 6975 |
else if (newcnt == 0) |
| 6976 |
{ |
| 6977 |
|
| 6978 |
|
| 6979 |
|
| 6980 |
|
| 6981 |
|
| 6982 |
|
| 6983 |
|
| 6984 |
|
| 6985 |
if (cleared_noun != -1) |
| 6986 |
{ |
| 6987 |
distypelist[cleared_noun] |= VOCT_NOUN; |
| 6988 |
cleared_noun = -1; |
| 6989 |
goto try_current_flags; |
| 6990 |
} |
| 6991 |
|
| 6992 |
|
| 6993 |
for (i = 0 ; i < cnt2 ; ++i) |
| 6994 |
{ |
| 6995 |
|
| 6996 |
if (disnounlist[i].vocolfst != 0) |
| 6997 |
break; |
| 6998 |
} |
| 6999 |
|
| 7000 |
|
| 7001 |
|
| 7002 |
|
| 7003 |
|
| 7004 |
|
| 7005 |
if (i != cnt2) |
| 7006 |
{ |
| 7007 |
char *p; |
| 7008 |
char *last; |
| 7009 |
|
| 7010 |
|
| 7011 |
newobj[0] = '\0'; |
| 7012 |
|
| 7013 |
|
| 7014 |
p = disnounlist[i].vocolfst; |
| 7015 |
last = disnounlist[i].vocollst; |
| 7016 |
for ( ; p <= last ; p += strlen(p) + 1) |
| 7017 |
{ |
| 7018 |
|
| 7019 |
|
| 7020 |
|
| 7021 |
|
| 7022 |
|
| 7023 |
|
| 7024 |
|
| 7025 |
|
| 7026 |
|
| 7027 |
|
| 7028 |
|
| 7029 |
|
| 7030 |
|
| 7031 |
if (vocisspec(p)) |
| 7032 |
{ |
| 7033 |
|
| 7034 |
|
| 7035 |
|
| 7036 |
|
| 7037 |
strcpy(newobj, "such"); |
| 7038 |
|
| 7039 |
|
| 7040 |
|
| 7041 |
|
| 7042 |
|
| 7043 |
|
| 7044 |
break; |
| 7045 |
} |
| 7046 |
|
| 7047 |
|
| 7048 |
if (newobj[0] != '\0') |
| 7049 |
strcat(newobj, " "); |
| 7050 |
|
| 7051 |
|
| 7052 |
strcat(newobj, p); |
| 7053 |
} |
| 7054 |
} |
| 7055 |
else |
| 7056 |
{ |
| 7057 |
|
| 7058 |
strcpy(newobj, "such"); |
| 7059 |
} |
| 7060 |
|
| 7061 |
|
| 7062 |
vocerr(ctx, VOCERR(16), |
| 7063 |
"You don't see any %s %s here.", |
| 7064 |
newobj, usrobj); |
| 7065 |
err = VOCERR(16); |
| 7066 |
goto done; |
| 7067 |
} |
| 7068 |
|
| 7069 |
|
| 7070 |
|
| 7071 |
|
| 7072 |
|
| 7073 |
|
| 7074 |
|
| 7075 |
|
| 7076 |
memcpy(list1, list2, |
| 7077 |
(size_t)((newcnt + 1) * sizeof(list1[0]))); |
| 7078 |
cnt = newcnt; |
| 7079 |
trying_again = TRUE; |
| 7080 |
} |
| 7081 |
else |
| 7082 |
{ |
| 7083 |
|
| 7084 |
|
| 7085 |
|
| 7086 |
|
| 7087 |
|
| 7088 |
|
| 7089 |
|
| 7090 |
|
| 7091 |
if (cleared_noun != -1) |
| 7092 |
{ |
| 7093 |
distypelist[cleared_noun] |= VOCT_NOUN; |
| 7094 |
cleared_noun = -1; |
| 7095 |
goto try_current_flags; |
| 7096 |
} |
| 7097 |
|
| 7098 |
|
| 7099 |
strcpy(cmdbuf, disnewbuf); |
| 7100 |
ctx->voccxunknown = 0; |
| 7101 |
ctx->voccxredo = TRUE; |
| 7102 |
err = VOCERR(43); |
| 7103 |
goto done; |
| 7104 |
} |
| 7105 |
} |
| 7106 |
} |
| 7107 |
inpos = lpos - 1; |
| 7108 |
} |
| 7109 |
} |
| 7110 |
|
| 7111 |
|
| 7112 |
vocout(&outlist[outpos], MCMONINV, 0, (char *)0, (char *)0); |
| 7113 |
|
| 7114 |
|
| 7115 |
|
| 7116 |
|
| 7117 |
|
| 7118 |
|
| 7119 |
if (still_ambig) |
| 7120 |
err = VOCERR(44); |
| 7121 |
|
| 7122 |
|
| 7123 |
err = 0; |
| 7124 |
|
| 7125 |
done: |
| 7126 |
ERRCLEAN(ctx->voccxerr) |
| 7127 |
{ |
| 7128 |
|
| 7129 |
|
| 7130 |
|
| 7131 |
|
| 7132 |
voc_leave(ctx, save_sp); |
| 7133 |
} |
| 7134 |
ERRENDCLN(ctx->voccxerr); |
| 7135 |
|
| 7136 |
|
| 7137 |
VOC_RETVAL(ctx, save_sp, err); |
| 7138 |
} |
| 7139 |
|
| 7140 |
|
| 7141 |
static int vocready(voccxdef *ctx, char *cmd[], int *typelist, int cur, |
| 7142 |
objnum cmdActor, objnum cmdPrep, char *vverb, char *vprep, |
| 7143 |
vocoldef *dolist, vocoldef *iolist, int *errp, |
| 7144 |
char *cmdbuf, int first_word, uchar **preparse_list, |
| 7145 |
int *next_start) |
| 7146 |
{ |
| 7147 |
if (cur != -1 |
| 7148 |
&& (cmd[cur] == (char *)0 |
| 7149 |
|| vocspec(cmd[cur], VOCW_AND) || vocspec(cmd[cur], VOCW_THEN))) |
| 7150 |
{ |
| 7151 |
if (ctx->voccxflg & VOCCXFDBG) |
| 7152 |
{ |
| 7153 |
char buf[128]; |
| 7154 |
|
| 7155 |
sprintf(buf, ". executing verb: %s %s\\n", |
| 7156 |
vverb, vprep ? vprep : ""); |
| 7157 |
tioputs(ctx->vocxtio, buf); |
| 7158 |
} |
| 7159 |
|
| 7160 |
*errp = execmd(ctx, cmdActor, cmdPrep, vverb, vprep, dolist, iolist, |
| 7161 |
&cmd[first_word], &typelist[first_word],cmdbuf, |
| 7162 |
cur - first_word, preparse_list, next_start); |
| 7163 |
return(TRUE); |
| 7164 |
} |
| 7165 |
return(FALSE); |
| 7166 |
} |
| 7167 |
|
| 7168 |
|
| 7169 |
static int voc1cmd(voccxdef *ctx, char *cmd[], char *cmdbuf, |
| 7170 |
objnum *cmdActorp, int first) |
| 7171 |
{ |
| 7172 |
int cur; |
| 7173 |
int next; |
| 7174 |
objnum o; |
| 7175 |
vocwdef *v; |
| 7176 |
char *vverb; |
| 7177 |
int vvlen; |
| 7178 |
char *vprep; |
| 7179 |
int cnt; |
| 7180 |
int err; |
| 7181 |
vocoldef *dolist; |
| 7182 |
vocoldef *iolist; |
| 7183 |
int *typelist; |
| 7184 |
objnum cmdActor = *cmdActorp; |
| 7185 |
objnum cmdPrep; |
| 7186 |
int swapObj; |
| 7187 |
int again; |
| 7188 |
int first_word; |
| 7189 |
uchar *preparse_list; |
| 7190 |
int next_start; |
| 7191 |
struct |
| 7192 |
{ |
| 7193 |
int active; |
| 7194 |
int cur; |
| 7195 |
char **cmd; |
| 7196 |
char *cmdbuf; |
| 7197 |
} preparseCmd_stat; |
| 7198 |
char **newcmd; |
| 7199 |
char *origcmdbuf; |
| 7200 |
char *newcmdbuf; |
| 7201 |
uchar *save_sp; |
| 7202 |
int no_match; |
| 7203 |
int retval; |
| 7204 |
|
| 7205 |
voc_enter(ctx, &save_sp); |
| 7206 |
VOC_MAX_ARRAY(ctx, vocoldef, dolist); |
| 7207 |
VOC_MAX_ARRAY(ctx, vocoldef, iolist); |
| 7208 |
VOC_STK_ARRAY(ctx, int, typelist, VOCBUFSIZ); |
| 7209 |
VOC_STK_ARRAY(ctx, char *, newcmd, VOCBUFSIZ); |
| 7210 |
VOC_STK_ARRAY(ctx, char, newcmdbuf, VOCBUFSIZ); |
| 7211 |
|
| 7212 |
|
| 7213 |
origcmdbuf = cmdbuf; |
| 7214 |
|
| 7215 |
|
| 7216 |
memset(typelist, 0, VOCBUFSIZ*sizeof(typelist[0])); |
| 7217 |
|
| 7218 |
|
| 7219 |
if (vocgtyp(ctx, cmd, typelist, cmdbuf)) |
| 7220 |
{ |
| 7221 |
retval = 1; |
| 7222 |
goto done; |
| 7223 |
} |
| 7224 |
|
| 7225 |
|
| 7226 |
cur = next = first_word = 0; |
| 7227 |
|
| 7228 |
|
| 7229 |
|
| 7230 |
|
| 7231 |
|
| 7232 |
|
| 7233 |
|
| 7234 |
|
| 7235 |
next_start = 0; |
| 7236 |
|
| 7237 |
|
| 7238 |
preparseCmd_stat.active = FALSE; |
| 7239 |
|
| 7240 |
|
| 7241 |
for (again = FALSE, err = 0 ; ; again = TRUE) |
| 7242 |
{ |
| 7243 |
|
| 7244 |
|
| 7245 |
|
| 7246 |
|
| 7247 |
if (err == ERR_PREPRSCMDREDO) |
| 7248 |
{ |
| 7249 |
uchar *src; |
| 7250 |
size_t len; |
| 7251 |
size_t curlen; |
| 7252 |
char *dst; |
| 7253 |
int cnt; |
| 7254 |
|
| 7255 |
|
| 7256 |
if (preparseCmd_stat.active) |
| 7257 |
{ |
| 7258 |
vocerr(ctx, VOCERR(34), |
| 7259 |
"Internal game error: preparseCmd loop"); |
| 7260 |
retval = 1; |
| 7261 |
goto done; |
| 7262 |
} |
| 7263 |
|
| 7264 |
|
| 7265 |
preparseCmd_stat.active = TRUE; |
| 7266 |
preparseCmd_stat.cur = cur; |
| 7267 |
preparseCmd_stat.cmd = cmd; |
| 7268 |
preparseCmd_stat.cmdbuf = cmdbuf; |
| 7269 |
|
| 7270 |
|
| 7271 |
cmd = newcmd; |
| 7272 |
cmdbuf = newcmdbuf; |
| 7273 |
cur = 0; |
| 7274 |
|
| 7275 |
|
| 7276 |
src = preparse_list; |
| 7277 |
len = osrp2(src) - 2; |
| 7278 |
for (src += 2, dst = cmdbuf, cnt = 0 ; len ; ) |
| 7279 |
{ |
| 7280 |
|
| 7281 |
if (*src != DAT_SSTRING) |
| 7282 |
{ |
| 7283 |
vocerr(ctx, VOCERR(32), |
| 7284 |
"Internal game error: preparseCmd returned an invalid list"); |
| 7285 |
retval = 1; |
| 7286 |
goto done; |
| 7287 |
} |
| 7288 |
|
| 7289 |
|
| 7290 |
++src; |
| 7291 |
curlen = osrp2(src) - 2; |
| 7292 |
src += 2; |
| 7293 |
|
| 7294 |
|
| 7295 |
if (dst + curlen + 1 >= cmdbuf + VOCBUFSIZ) |
| 7296 |
{ |
| 7297 |
vocerr(ctx, VOCERR(33), |
| 7298 |
"Internal game error: preparseCmd command too long"); |
| 7299 |
retval = 1; |
| 7300 |
goto done; |
| 7301 |
} |
| 7302 |
|
| 7303 |
|
| 7304 |
cmd[cnt++] = dst; |
| 7305 |
memcpy(dst, src, curlen); |
| 7306 |
dst[curlen] = '\0'; |
| 7307 |
|
| 7308 |
|
| 7309 |
len -= 3 + curlen; |
| 7310 |
src += curlen; |
| 7311 |
dst += curlen + 1; |
| 7312 |
} |
| 7313 |
|
| 7314 |
|
| 7315 |
cmd[cnt] = 0; |
| 7316 |
|
| 7317 |
|
| 7318 |
if (vocgtyp(ctx, cmd, typelist, cmdbuf)) |
| 7319 |
{ |
| 7320 |
|
| 7321 |
retval = 1; |
| 7322 |
goto done; |
| 7323 |
} |
| 7324 |
|
| 7325 |
|
| 7326 |
|
| 7327 |
|
| 7328 |
|
| 7329 |
again = FALSE; |
| 7330 |
|
| 7331 |
|
| 7332 |
err = 0; |
| 7333 |
} |
| 7334 |
|
| 7335 |
|
| 7336 |
cmdPrep = MCMONINV; |
| 7337 |
swapObj = FALSE; |
| 7338 |
dolist[0].vocolobj = iolist[0].vocolobj = MCMONINV; |
| 7339 |
dolist[0].vocolflg = iolist[0].vocolflg = 0; |
| 7340 |
|
| 7341 |
|
| 7342 |
if (err) |
| 7343 |
{ |
| 7344 |
|
| 7345 |
retval = err; |
| 7346 |
goto done; |
| 7347 |
} |
| 7348 |
|
| 7349 |
skip_leading_stuff: |
| 7350 |
|
| 7351 |
|
| 7352 |
|
| 7353 |
|
| 7354 |
if (next_start != 0) |
| 7355 |
cur = first_word + next_start; |
| 7356 |
|
| 7357 |
|
| 7358 |
next_start = 0; |
| 7359 |
|
| 7360 |
|
| 7361 |
while (cmd[cur] && (vocspec(cmd[cur], VOCW_THEN) |
| 7362 |
|| vocspec(cmd[cur], VOCW_AND))) |
| 7363 |
++cur; |
| 7364 |
|
| 7365 |
|
| 7366 |
if (cmd[cur] == 0) |
| 7367 |
{ |
| 7368 |
|
| 7369 |
|
| 7370 |
|
| 7371 |
|
| 7372 |
if (preparseCmd_stat.active) |
| 7373 |
{ |
| 7374 |
|
| 7375 |
cur = preparseCmd_stat.cur; |
| 7376 |
cmd = preparseCmd_stat.cmd; |
| 7377 |
cmdbuf = preparseCmd_stat.cmdbuf; |
| 7378 |
preparseCmd_stat.active = FALSE; |
| 7379 |
|
| 7380 |
|
| 7381 |
if (vocgtyp(ctx, cmd, typelist, cmdbuf)) |
| 7382 |
{ |
| 7383 |
|
| 7384 |
retval = 1; |
| 7385 |
goto done; |
| 7386 |
} |
| 7387 |
|
| 7388 |
|
| 7389 |
goto skip_leading_stuff; |
| 7390 |
} |
| 7391 |
else |
| 7392 |
{ |
| 7393 |
|
| 7394 |
retval = 0; |
| 7395 |
goto done; |
| 7396 |
} |
| 7397 |
} |
| 7398 |
|
| 7399 |
|
| 7400 |
|
| 7401 |
|
| 7402 |
|
| 7403 |
|
| 7404 |
if (again) |
| 7405 |
outformat("\\b"); |
| 7406 |
|
| 7407 |
{ |
| 7408 |
|
| 7409 |
if ((o = vocgetactor(ctx, cmd, typelist, cur, &next, cmdbuf)) |
| 7410 |
!= MCMONINV) |
| 7411 |
{ |
| 7412 |
|
| 7413 |
cur = next; |
| 7414 |
|
| 7415 |
|
| 7416 |
cmdActor = *cmdActorp = o; |
| 7417 |
|
| 7418 |
|
| 7419 |
ctx->voccxactor = o; |
| 7420 |
} |
| 7421 |
|
| 7422 |
|
| 7423 |
if (cur != next) |
| 7424 |
{ |
| 7425 |
|
| 7426 |
retval = 1; |
| 7427 |
goto done; |
| 7428 |
} |
| 7429 |
} |
| 7430 |
|
| 7431 |
|
| 7432 |
first_word = cur; |
| 7433 |
|
| 7434 |
|
| 7435 |
if ((cmd[cur] == (char *)0) || !(typelist[cur] & VOCT_VERB)) |
| 7436 |
{ |
| 7437 |
|
| 7438 |
if (!try_unknown_verb(ctx, cmdActor, &cmd[cur], &typelist[cur], |
| 7439 |
0, &next_start, TRUE, VOCERR(17), |
| 7440 |
"There's no verb in that sentence!")) |
| 7441 |
{ |
| 7442 |
|
| 7443 |
retval = 1; |
| 7444 |
goto done; |
| 7445 |
} |
| 7446 |
else |
| 7447 |
{ |
| 7448 |
|
| 7449 |
continue; |
| 7450 |
} |
| 7451 |
} |
| 7452 |
vverb = cmd[cur++]; |
| 7453 |
vvlen = strlen(vverb); |
| 7454 |
vprep = 0; |
| 7455 |
|
| 7456 |
|
| 7457 |
if (vocready(ctx, cmd, typelist, cur, cmdActor, cmdPrep, |
| 7458 |
vverb, vprep, dolist, iolist, &err, cmdbuf, |
| 7459 |
first_word, &preparse_list, &next_start)) |
| 7460 |
continue; |
| 7461 |
|
| 7462 |
|
| 7463 |
|
| 7464 |
|
| 7465 |
|
| 7466 |
if (typelist[cur] & VOCT_PREP) |
| 7467 |
{ |
| 7468 |
if (vocffw(ctx, vverb, vvlen, cmd[cur], (int)strlen(cmd[cur]), |
| 7469 |
PRP_VERB, (vocseadef *)0)) |
| 7470 |
{ |
| 7471 |
vprep = cmd[cur++]; |
| 7472 |
if (vocready(ctx, cmd, typelist, cur, cmdActor, cmdPrep, |
| 7473 |
vverb, vprep, dolist, iolist, &err, cmdbuf, |
| 7474 |
first_word, &preparse_list, &next_start)) |
| 7475 |
continue; |
| 7476 |
} |
| 7477 |
else |
| 7478 |
{ |
| 7479 |
|
| 7480 |
|
| 7481 |
|
| 7482 |
|
| 7483 |
|
| 7484 |
|
| 7485 |
|
| 7486 |
|
| 7487 |
if ((v = vocffw(ctx, cmd[cur], (int)strlen(cmd[cur]), |
| 7488 |
(char *)0, 0, PRP_PREP, (vocseadef *)0)) != 0) |
| 7489 |
{ |
| 7490 |
int swap_ok; |
| 7491 |
|
| 7492 |
|
| 7493 |
if (typelist[cur] & VOCT_NOUN) |
| 7494 |
{ |
| 7495 |
|
| 7496 |
swap_ok = FALSE; |
| 7497 |
} |
| 7498 |
else if (typelist[cur] & VOCT_ADJ) |
| 7499 |
{ |
| 7500 |
int i; |
| 7501 |
|
| 7502 |
|
| 7503 |
for (i = cur + 1 ; |
| 7504 |
cmd[i] && (typelist[i] & VOCT_ADJ) |
| 7505 |
&& !(typelist[i] & VOCT_NOUN) ; ++i) ; |
| 7506 |
swap_ok = (!cmd[i] || !(typelist[i] & VOCT_NOUN)); |
| 7507 |
} |
| 7508 |
else |
| 7509 |
{ |
| 7510 |
|
| 7511 |
swap_ok = TRUE; |
| 7512 |
} |
| 7513 |
|
| 7514 |
if (swap_ok) |
| 7515 |
{ |
| 7516 |
cmdPrep = v->vocwobj; |
| 7517 |
swapObj = TRUE; |
| 7518 |
++cur; |
| 7519 |
} |
| 7520 |
} |
| 7521 |
} |
| 7522 |
} |
| 7523 |
|
| 7524 |
retry_swap: |
| 7525 |
|
| 7526 |
if ((cnt = vocchknoun2(ctx, cmd, typelist, cur, &next, dolist, |
| 7527 |
FALSE, &no_match)) > 0) |
| 7528 |
{ |
| 7529 |
|
| 7530 |
cur = next; |
| 7531 |
} |
| 7532 |
else if (no_match) |
| 7533 |
{ |
| 7534 |
|
| 7535 |
|
| 7536 |
|
| 7537 |
|
| 7538 |
|
| 7539 |
vocgetnoun(ctx, cmd, typelist, cur, &next, dolist); |
| 7540 |
|
| 7541 |
|
| 7542 |
retval = 1; |
| 7543 |
goto done; |
| 7544 |
} |
| 7545 |
else if (cnt < 0) |
| 7546 |
{ |
| 7547 |
|
| 7548 |
retval = 1; |
| 7549 |
goto done; |
| 7550 |
} |
| 7551 |
else |
| 7552 |
{ |
| 7553 |
|
| 7554 |
|
| 7555 |
|
| 7556 |
|
| 7557 |
|
| 7558 |
|
| 7559 |
if (swapObj && |
| 7560 |
((typelist[cur-1] & VOCT_NOUN) |
| 7561 |
|| (typelist[cur-1] & VOCT_ADJ))) |
| 7562 |
{ |
| 7563 |
--cur; |
| 7564 |
swapObj = FALSE; |
| 7565 |
cmdPrep = MCMONINV; |
| 7566 |
goto retry_swap; |
| 7567 |
} |
| 7568 |
|
| 7569 |
bad_sentence: |
| 7570 |
|
| 7571 |
while (cmd[cur]) ++cur; |
| 7572 |
|
| 7573 |
|
| 7574 |
err = try_preparse_cmd(ctx, &cmd[first_word], cur - first_word, |
| 7575 |
&preparse_list); |
| 7576 |
switch(err) |
| 7577 |
{ |
| 7578 |
case 0: |
| 7579 |
|
| 7580 |
if (!try_unknown_verb(ctx, cmdActor, &cmd[first_word], |
| 7581 |
&typelist[first_word], 0, &next_start, |
| 7582 |
TRUE, VOCERR(18), |
| 7583 |
"I don't understand that sentence.")) |
| 7584 |
{ |
| 7585 |
|
| 7586 |
retval = 1; |
| 7587 |
goto done; |
| 7588 |
} |
| 7589 |
else |
| 7590 |
{ |
| 7591 |
|
| 7592 |
continue; |
| 7593 |
} |
| 7594 |
|
| 7595 |
case ERR_PREPRSCMDCAN: |
| 7596 |
|
| 7597 |
retval = 0; |
| 7598 |
goto done; |
| 7599 |
|
| 7600 |
case ERR_PREPRSCMDREDO: |
| 7601 |
|
| 7602 |
continue; |
| 7603 |
} |
| 7604 |
} |
| 7605 |
|
| 7606 |
|
| 7607 |
if (vocready(ctx, cmd, typelist, cur, cmdActor, cmdPrep, |
| 7608 |
vverb, vprep, |
| 7609 |
swapObj ? iolist : dolist, |
| 7610 |
swapObj ? dolist : iolist, |
| 7611 |
&err, cmdbuf, first_word, &preparse_list, |
| 7612 |
&next_start)) |
| 7613 |
continue; |
| 7614 |
|
| 7615 |
|
| 7616 |
|
| 7617 |
|
| 7618 |
|
| 7619 |
|
| 7620 |
|
| 7621 |
|
| 7622 |
if (cmdPrep == MCMONINV && (typelist[cur] & VOCT_PREP)) |
| 7623 |
{ |
| 7624 |
char *p1 = cmd[cur++]; |
| 7625 |
|
| 7626 |
|
| 7627 |
if (cmd[cur] == (char *)0 |
| 7628 |
|| vocspec(cmd[cur], VOCW_AND) |
| 7629 |
|| vocspec(cmd[cur], VOCW_THEN)) |
| 7630 |
{ |
| 7631 |
if (vocffw(ctx, vverb, vvlen, p1, (int)strlen(p1), PRP_VERB, |
| 7632 |
(vocseadef *)0) |
| 7633 |
&& !vprep) |
| 7634 |
vprep = p1; |
| 7635 |
else |
| 7636 |
{ |
| 7637 |
|
| 7638 |
if (!try_unknown_verb(ctx, cmdActor, &cmd[first_word], |
| 7639 |
&typelist[first_word], 0, |
| 7640 |
&next_start, TRUE, VOCERR(19), |
| 7641 |
"There are words after your command I couldn't use.")) |
| 7642 |
{ |
| 7643 |
|
| 7644 |
retval = 1; |
| 7645 |
goto done; |
| 7646 |
} |
| 7647 |
else |
| 7648 |
{ |
| 7649 |
|
| 7650 |
continue; |
| 7651 |
} |
| 7652 |
} |
| 7653 |
|
| 7654 |
if ((err = execmd(ctx, cmdActor, cmdPrep, vverb, vprep, |
| 7655 |
dolist, iolist, |
| 7656 |
&cmd[first_word], &typelist[first_word], |
| 7657 |
cmdbuf, cur - first_word, |
| 7658 |
&preparse_list, &next_start)) != 0) |
| 7659 |
{ |
| 7660 |
retval = 1; |
| 7661 |
goto done; |
| 7662 |
} |
| 7663 |
continue; |
| 7664 |
} |
| 7665 |
|
| 7666 |
|
| 7667 |
|
| 7668 |
|
| 7669 |
|
| 7670 |
|
| 7671 |
|
| 7672 |
|
| 7673 |
|
| 7674 |
|
| 7675 |
if (cmd[cur] && (typelist[cur] & VOCT_PREP) && cmd[cur+1] |
| 7676 |
&& vprep == 0 |
| 7677 |
&& vocffw(ctx, vverb, vvlen, p1, (int)strlen(p1), PRP_VERB, |
| 7678 |
(vocseadef *)0)) |
| 7679 |
{ |
| 7680 |
|
| 7681 |
|
| 7682 |
|
| 7683 |
|
| 7684 |
|
| 7685 |
|
| 7686 |
|
| 7687 |
if (vocgobj(ctx, cmd, typelist, cur, &next, |
| 7688 |
FALSE, iolist, FALSE, FALSE, 0) <= 0) |
| 7689 |
{ |
| 7690 |
|
| 7691 |
vprep = p1; |
| 7692 |
|
| 7693 |
|
| 7694 |
p1 = cmd[cur++]; |
| 7695 |
} |
| 7696 |
} |
| 7697 |
|
| 7698 |
|
| 7699 |
cnt = vocgobj(ctx, cmd, typelist, cur, &next, TRUE, iolist, |
| 7700 |
TRUE, FALSE, &no_match); |
| 7701 |
if (cnt > 0) |
| 7702 |
{ |
| 7703 |
cur = next; |
| 7704 |
v = vocffw(ctx, p1, (int)strlen(p1), (char *)0, 0, PRP_PREP, |
| 7705 |
(vocseadef *)0); |
| 7706 |
if (v == (vocwdef *)0) |
| 7707 |
{ |
| 7708 |
|
| 7709 |
if (!try_unknown_verb(ctx, cmdActor, &cmd[first_word], |
| 7710 |
&typelist[first_word], 0, |
| 7711 |
&next_start, TRUE, VOCERR(20), |
| 7712 |
"I don't know how to use the word \"%s\" like that.", p1)) |
| 7713 |
{ |
| 7714 |
|
| 7715 |
retval = 1; |
| 7716 |
goto done; |
| 7717 |
} |
| 7718 |
else |
| 7719 |
{ |
| 7720 |
|
| 7721 |
continue; |
| 7722 |
} |
| 7723 |
} |
| 7724 |
cmdPrep = v->vocwobj; |
| 7725 |
|
| 7726 |
if (vocready(ctx, cmd, typelist, cur, cmdActor, cmdPrep, |
| 7727 |
vverb, vprep, dolist, iolist, &err, cmdbuf, |
| 7728 |
first_word, &preparse_list, &next_start)) |
| 7729 |
continue; |
| 7730 |
else if ((typelist[cur] & VOCT_PREP) && |
| 7731 |
vocffw(ctx, vverb, vvlen, cmd[cur], |
| 7732 |
(int)strlen(cmd[cur]), PRP_VERB, |
| 7733 |
(vocseadef *)0) && !vprep) |
| 7734 |
{ |
| 7735 |
vprep = cmd[cur++]; |
| 7736 |
if (vocready(ctx, cmd, typelist, cur, cmdActor, |
| 7737 |
cmdPrep, vverb, vprep, dolist, iolist, |
| 7738 |
&err, cmdbuf, first_word, &preparse_list, |
| 7739 |
&next_start)) |
| 7740 |
continue; |
| 7741 |
else |
| 7742 |
{ |
| 7743 |
|
| 7744 |
if (!try_unknown_verb(ctx, cmdActor, &cmd[first_word], |
| 7745 |
&typelist[first_word], 0, |
| 7746 |
&next_start, TRUE, VOCERR(19), |
| 7747 |
"There are words after your command I couldn't use.")) |
| 7748 |
{ |
| 7749 |
|
| 7750 |
retval = 1; |
| 7751 |
goto done; |
| 7752 |
} |
| 7753 |
else |
| 7754 |
{ |
| 7755 |
|
| 7756 |
continue; |
| 7757 |
} |
| 7758 |
} |
| 7759 |
} |
| 7760 |
else |
| 7761 |
{ |
| 7762 |
|
| 7763 |
|
| 7764 |
|
| 7765 |
|
| 7766 |
|
| 7767 |
|
| 7768 |
|
| 7769 |
|
| 7770 |
|
| 7771 |
|
| 7772 |
|
| 7773 |
|
| 7774 |
vocoldef *np1 = |
| 7775 |
(dolist[0].vocolflg & VOCS_TRIMPREP) != 0 |
| 7776 |
? &dolist[0] |
| 7777 |
: (iolist[0].vocolflg & VOCS_TRIMPREP) != 0 |
| 7778 |
? &iolist[0] |
| 7779 |
: 0; |
| 7780 |
if (np1 != 0) |
| 7781 |
{ |
| 7782 |
char namebuf[VOCBUFSIZ]; |
| 7783 |
|
| 7784 |
|
| 7785 |
voc_make_obj_name_from_list( |
| 7786 |
ctx, namebuf, cmd, np1->vocolfst, np1->vocolhlst); |
| 7787 |
vocerr(ctx, VOCERR(9), "I don't see any %s here.", |
| 7788 |
namebuf); |
| 7789 |
|
| 7790 |
|
| 7791 |
retval = 1; |
| 7792 |
goto done; |
| 7793 |
} |
| 7794 |
else if (!try_unknown_verb( |
| 7795 |
ctx, cmdActor, |
| 7796 |
&cmd[first_word], &typelist[first_word], |
| 7797 |
0, &next_start, TRUE, VOCERR(19), |
| 7798 |
"There are words after your command that I couldn't use.")) |
| 7799 |
{ |
| 7800 |
|
| 7801 |
retval = 1; |
| 7802 |
goto done; |
| 7803 |
} |
| 7804 |
else |
| 7805 |
{ |
| 7806 |
|
| 7807 |
continue; |
| 7808 |
} |
| 7809 |
} |
| 7810 |
} |
| 7811 |
else if (cnt < 0) |
| 7812 |
{ |
| 7813 |
|
| 7814 |
|
| 7815 |
|
| 7816 |
|
| 7817 |
retval = 1; |
| 7818 |
goto done; |
| 7819 |
} |
| 7820 |
else if (no_match) |
| 7821 |
{ |
| 7822 |
|
| 7823 |
|
| 7824 |
|
| 7825 |
|
| 7826 |
|
| 7827 |
retval = 1; |
| 7828 |
goto done; |
| 7829 |
} |
| 7830 |
else |
| 7831 |
{ |
| 7832 |
goto bad_sentence; |
| 7833 |
} |
| 7834 |
} |
| 7835 |
else if ((cnt = vocchknoun(ctx, cmd, typelist, cur, |
| 7836 |
&next, iolist, FALSE)) > 0) |
| 7837 |
{ |
| 7838 |
|
| 7839 |
cur = next; |
| 7840 |
if (cmd[cur]) |
| 7841 |
{ |
| 7842 |
if ((typelist[cur] & VOCT_PREP) && |
| 7843 |
vocffw(ctx, vverb, vvlen, cmd[cur], |
| 7844 |
(int)strlen(cmd[cur]), PRP_VERB, |
| 7845 |
(vocseadef *)0) && !vprep) |
| 7846 |
{ |
| 7847 |
vprep = cmd[cur++]; |
| 7848 |
} |
| 7849 |
} |
| 7850 |
|
| 7851 |
|
| 7852 |
if (cmd[cur] != 0) |
| 7853 |
{ |
| 7854 |
|
| 7855 |
if (!try_unknown_verb(ctx, cmdActor, &cmd[first_word], |
| 7856 |
&typelist[first_word], 0, |
| 7857 |
&next_start, TRUE, VOCERR(21), |
| 7858 |
"There appear to be extra words after your command.")) |
| 7859 |
{ |
| 7860 |
|
| 7861 |
retval = 1; |
| 7862 |
goto done; |
| 7863 |
} |
| 7864 |
else |
| 7865 |
{ |
| 7866 |
|
| 7867 |
continue; |
| 7868 |
} |
| 7869 |
} |
| 7870 |
|
| 7871 |
|
| 7872 |
|
| 7873 |
|
| 7874 |
|
| 7875 |
|
| 7876 |
|
| 7877 |
if (cmdPrep == MCMONINV && |
| 7878 |
(v = vocffw(ctx, vverb, vvlen, |
| 7879 |
vprep, (vprep ? (int)strlen(vprep) : 0), |
| 7880 |
PRP_VERB, (vocseadef *)0)) != 0) |
| 7881 |
{ |
| 7882 |
runppr(ctx->voccxrun, v->vocwobj, PRP_NILPREP, 0); |
| 7883 |
if (runtostyp(ctx->voccxrun) == DAT_OBJECT) |
| 7884 |
cmdPrep = runpopobj(ctx->voccxrun); |
| 7885 |
else |
| 7886 |
rundisc(ctx->voccxrun); |
| 7887 |
} |
| 7888 |
|
| 7889 |
|
| 7890 |
if (cmdPrep == MCMONINV) |
| 7891 |
{ |
| 7892 |
v = vocffw(ctx, "to", 2, (char *)0, 0, PRP_PREP, |
| 7893 |
(vocseadef *)0); |
| 7894 |
if (v) cmdPrep = v->vocwobj; |
| 7895 |
} |
| 7896 |
|
| 7897 |
|
| 7898 |
err = execmd(ctx, cmdActor, cmdPrep, vverb, vprep, |
| 7899 |
iolist, dolist, |
| 7900 |
&cmd[first_word], &typelist[first_word], cmdbuf, |
| 7901 |
cur - first_word, &preparse_list, &next_start); |
| 7902 |
continue; |
| 7903 |
} |
| 7904 |
else if (cnt < 0) |
| 7905 |
{ |
| 7906 |
retval = 1; |
| 7907 |
goto done; |
| 7908 |
} |
| 7909 |
else |
| 7910 |
{ |
| 7911 |
goto bad_sentence; |
| 7912 |
} |
| 7913 |
} |
| 7914 |
|
| 7915 |
done: |
| 7916 |
|
| 7917 |
if (ctx->voccxredo && cmdbuf != origcmdbuf) |
| 7918 |
strcpy(origcmdbuf, cmdbuf); |
| 7919 |
|
| 7920 |
|
| 7921 |
VOC_RETVAL(ctx, save_sp, retval); |
| 7922 |
} |
| 7923 |
|
| 7924 |
|
| 7925 |
int voccmd(voccxdef *ctx, char *cmd, uint cmdlen) |
| 7926 |
{ |
| 7927 |
int wrdcnt; |
| 7928 |
int cur; |
| 7929 |
int next; |
| 7930 |
char *buffer; |
| 7931 |
char **wordlist; |
| 7932 |
objnum cmdActor; |
| 7933 |
int first; |
| 7934 |
|
| 7935 |
|
| 7936 |
|
| 7937 |
|
| 7938 |
|
| 7939 |
|
| 7940 |
voc_stk_ini(ctx, (uint)VOC_STACK_SIZE); |
| 7941 |
|
| 7942 |
|
| 7943 |
VOC_STK_ARRAY(ctx, char, buffer, 2*VOCBUFSIZ); |
| 7944 |
VOC_STK_ARRAY(ctx, char *, wordlist, VOCBUFSIZ); |
| 7945 |
|
| 7946 |
|
| 7947 |
tiosetactor(ctx->voccxtio, ctx->voccxme); |
| 7948 |
|
| 7949 |
|
| 7950 |
ctx->voccxflg &= ~VOCCXFCLEAR; |
| 7951 |
|
| 7952 |
|
| 7953 |
if (ctx->voccxpre != MCMONINV) |
| 7954 |
{ |
| 7955 |
int typ; |
| 7956 |
uchar *s; |
| 7957 |
size_t len; |
| 7958 |
int err; |
| 7959 |
|
| 7960 |
|
| 7961 |
runpstr(ctx->voccxrun, cmd, (int)strlen(cmd), 0); |
| 7962 |
|
| 7963 |
|
| 7964 |
err = 0; |
| 7965 |
|
| 7966 |
|
| 7967 |
ERRBEGIN(ctx->voccxerr) |
| 7968 |
{ |
| 7969 |
|
| 7970 |
runfn(ctx->voccxrun, ctx->voccxpre, 1); |
| 7971 |
} |
| 7972 |
ERRCATCH(ctx->voccxerr, err) |
| 7973 |
{ |
| 7974 |
|
| 7975 |
switch(err) |
| 7976 |
{ |
| 7977 |
case ERR_RUNEXIT: |
| 7978 |
case ERR_RUNEXITOBJ: |
| 7979 |
case ERR_RUNABRT: |
| 7980 |
|
| 7981 |
|
| 7982 |
|
| 7983 |
|
| 7984 |
|
| 7985 |
break; |
| 7986 |
|
| 7987 |
default: |
| 7988 |
|
| 7989 |
errrse(ctx->voccxerr); |
| 7990 |
} |
| 7991 |
} |
| 7992 |
ERREND(ctx->voccxerr); |
| 7993 |
|
| 7994 |
|
| 7995 |
if (err != 0) |
| 7996 |
return 0; |
| 7997 |
|
| 7998 |
|
| 7999 |
typ = runtostyp(ctx->voccxrun); |
| 8000 |
if (typ == DAT_SSTRING) |
| 8001 |
{ |
| 8002 |
|
| 8003 |
|
| 8004 |
|
| 8005 |
|
| 8006 |
s = runpopstr(ctx->voccxrun); |
| 8007 |
len = osrp2(s) - 2; |
| 8008 |
s += 2; |
| 8009 |
|
| 8010 |
|
| 8011 |
|
| 8012 |
|
| 8013 |
|
| 8014 |
if (len > cmdlen - 1) |
| 8015 |
len = cmdlen - 1; |
| 8016 |
|
| 8017 |
|
| 8018 |
memcpy(cmd, s, len); |
| 8019 |
|
| 8020 |
|
| 8021 |
cmd[len] = '\0'; |
| 8022 |
} |
| 8023 |
else |
| 8024 |
{ |
| 8025 |
|
| 8026 |
rundisc(ctx->voccxrun); |
| 8027 |
|
| 8028 |
|
| 8029 |
if (typ == DAT_NIL) |
| 8030 |
return 0; |
| 8031 |
} |
| 8032 |
} |
| 8033 |
|
| 8034 |
|
| 8035 |
if ((wrdcnt = voctok(ctx, cmd, buffer, wordlist, TRUE, FALSE, TRUE)) > 0) |
| 8036 |
{ |
| 8037 |
|
| 8038 |
for (cur = 0 ; cur < wrdcnt ; ++cur) |
| 8039 |
{ |
| 8040 |
|
| 8041 |
if (!vocspec(wordlist[cur], VOCW_THEN) |
| 8042 |
&& !vocspec(wordlist[cur], VOCW_AND)) |
| 8043 |
break; |
| 8044 |
} |
| 8045 |
} |
| 8046 |
|
| 8047 |
|
| 8048 |
|
| 8049 |
|
| 8050 |
|
| 8051 |
|
| 8052 |
if (wrdcnt == 0 || (wrdcnt > 0 && cur >= wrdcnt)) |
| 8053 |
{ |
| 8054 |
runfn(ctx->voccxrun, ctx->voccxprd, 0); |
| 8055 |
return 0; |
| 8056 |
} |
| 8057 |
|
| 8058 |
|
| 8059 |
|
| 8060 |
|
| 8061 |
|
| 8062 |
|
| 8063 |
if (wrdcnt < 0) |
| 8064 |
return 0; |
| 8065 |
|
| 8066 |
|
| 8067 |
for (first = TRUE, cmdActor = ctx->voccxactor = MCMONINV ; cur < wrdcnt ; |
| 8068 |
++cur, first = FALSE) |
| 8069 |
{ |
| 8070 |
|
| 8071 |
ctx->voccxunknown = 0; |
| 8072 |
|
| 8073 |
|
| 8074 |
for (next = cur ; cur < wrdcnt && !vocspec(wordlist[cur], VOCW_THEN) |
| 8075 |
; ++cur) ; |
| 8076 |
wordlist[cur] = (char *)0; |
| 8077 |
|
| 8078 |
|
| 8079 |
for (;;) |
| 8080 |
{ |
| 8081 |
|
| 8082 |
if (voc1cmd(ctx, &wordlist[next], cmd, &cmdActor, first)) |
| 8083 |
{ |
| 8084 |
|
| 8085 |
|
| 8086 |
|
| 8087 |
|
| 8088 |
|
| 8089 |
|
| 8090 |
|
| 8091 |
if (ctx->voccxunknown > 0) |
| 8092 |
continue; |
| 8093 |
|
| 8094 |
|
| 8095 |
return 1; |
| 8096 |
} |
| 8097 |
|
| 8098 |
|
| 8099 |
break; |
| 8100 |
} |
| 8101 |
|
| 8102 |
|
| 8103 |
if (ctx->voccxflg & VOCCXFCLEAR) |
| 8104 |
return 0; |
| 8105 |
|
| 8106 |
|
| 8107 |
while (cur + 1 < wrdcnt |
| 8108 |
&& (vocspec(wordlist[cur+1], VOCW_THEN) |
| 8109 |
|| vocspec(wordlist[cur+1], VOCW_AND))) |
| 8110 |
++cur; |
| 8111 |
|
| 8112 |
|
| 8113 |
|
| 8114 |
|
| 8115 |
|
| 8116 |
|
| 8117 |
if (cur + 1 < wrdcnt) |
| 8118 |
outformat("\\b"); |
| 8119 |
} |
| 8120 |
|
| 8121 |
|
| 8122 |
return 0; |
| 8123 |
} |
| 8124 |
|
| 8125 |
|
| 8126 |
|
| 8127 |
|
| 8128 |
|
| 8129 |
|
| 8130 |
|
| 8131 |
void voc_stk_ini(voccxdef *ctx, uint siz) |
| 8132 |
{ |
| 8133 |
|
| 8134 |
if (ctx->voc_stk_ptr == 0) |
| 8135 |
{ |
| 8136 |
ctx->voc_stk_ptr = mchalo(ctx->voccxerr, siz, "voc_stk_ini"); |
| 8137 |
ctx->voc_stk_end = ctx->voc_stk_ptr + siz; |
| 8138 |
} |
| 8139 |
|
| 8140 |
|
| 8141 |
ctx->voc_stk_cur = ctx->voc_stk_ptr; |
| 8142 |
} |
| 8143 |
|
| 8144 |
|
| 8145 |
void *voc_stk_alo(voccxdef *ctx, uint siz) |
| 8146 |
{ |
| 8147 |
void *ret; |
| 8148 |
|
| 8149 |
|
| 8150 |
siz = osrndsz(siz); |
| 8151 |
|
| 8152 |
|
| 8153 |
if (ctx->voc_stk_cur + siz > ctx->voc_stk_end) |
| 8154 |
errsig(ctx->voccxerr, ERR_VOCSTK); |
| 8155 |
|
| 8156 |
|
| 8157 |
ret = ctx->voc_stk_cur; |
| 8158 |
|
| 8159 |
|
| 8160 |
ctx->voc_stk_cur += siz; |
| 8161 |
|
| 8162 |
|
| 8163 |
#ifdef SHOW_HI |
| 8164 |
{ |
| 8165 |
static uint maxsiz; |
| 8166 |
if (ctx->voc_stk_cur - ctx->voc_stk_ptr > maxsiz) |
| 8167 |
{ |
| 8168 |
char buf[20]; |
| 8169 |
|
| 8170 |
maxsiz = ctx->voc_stk_cur - ctx->voc_stk_ptr; |
| 8171 |
sprintf(buf, "%u\n", maxsiz); |
| 8172 |
os_printz(buf); |
| 8173 |
} |
| 8174 |
} |
| 8175 |
#endif |
| 8176 |
|
| 8177 |
|
| 8178 |
|
| 8179 |
return ret; |
| 8180 |
} |
| 8181 |
|