| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#include <stdio.h> |
| 10 |
#include <ctype.h> |
| 11 |
|
| 12 |
#include "types.h" |
| 13 |
|
| 14 |
#ifdef USE_READLINE |
| 15 |
#include "readline.h" |
| 16 |
#endif |
| 17 |
|
| 18 |
#include "main.h" |
| 19 |
#include "inter.h" |
| 20 |
#include "exe.h" |
| 21 |
#include "term.h" |
| 22 |
#include "debug.h" |
| 23 |
#include "params.h" |
| 24 |
|
| 25 |
#include "parse.h" |
| 26 |
|
| 27 |
#ifdef GLK |
| 28 |
#include "glkio.h" |
| 29 |
#endif |
| 30 |
|
| 31 |
|
| 32 |
#define LISTLEN 100 |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
int wrds[LISTLEN/2] = {EOF}; |
| 38 |
int wrdidx; |
| 39 |
|
| 40 |
Boolean plural = FALSE; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
int paramidx; |
| 45 |
ParamElem *params; |
| 46 |
static ParamElem *pparams; |
| 47 |
static ParamElem *mlst; |
| 48 |
static ParamElem *pmlst; |
| 49 |
|
| 50 |
|
| 51 |
LitElem litValues[MAXPARAMS+1]; |
| 52 |
int litCount; |
| 53 |
|
| 54 |
|
| 55 |
int vrbwrd; |
| 56 |
int vrbcode; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
static char buf[LISTLEN+1]; |
| 79 |
static char isobuf[LISTLEN+1]; |
| 80 |
|
| 81 |
|
| 82 |
static Boolean eol = TRUE; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
#ifdef _PROTOTYPES_ |
| 87 |
static void unknown( |
| 88 |
char token[] |
| 89 |
) |
| 90 |
#else |
| 91 |
static void unknown(token) |
| 92 |
char token[]; |
| 93 |
#endif |
| 94 |
{ |
| 95 |
char *str = allocate((int)strlen(token)+4); |
| 96 |
|
| 97 |
str[0] = '\''; |
| 98 |
strcpy(&str[1], token); |
| 99 |
strcat(str, "'?"); |
| 100 |
#if ISO == 0 |
| 101 |
fromIso(str, str); |
| 102 |
#endif |
| 103 |
output(str); |
| 104 |
free(str); |
| 105 |
eol = TRUE; |
| 106 |
error(M_UNKNOWN_WORD); |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
static char *token; |
| 112 |
|
| 113 |
|
| 114 |
#ifdef _PROTOTYPES_ |
| 115 |
static int lookup( |
| 116 |
char wrd[] |
| 117 |
) |
| 118 |
#else |
| 119 |
static int lookup(wrd) |
| 120 |
char wrd[]; |
| 121 |
#endif |
| 122 |
{ |
| 123 |
int i; |
| 124 |
|
| 125 |
for (i = 0; !endOfTable(&dict[i]); i++) { |
| 126 |
if (strcmp(wrd, (char *) addrTo(dict[i].wrd)) == 0) |
| 127 |
return (i); |
| 128 |
} |
| 129 |
unknown(wrd); |
| 130 |
return(EOF); |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
#ifdef _PROTOTYPES_ |
| 135 |
static int number( |
| 136 |
char token[] |
| 137 |
) |
| 138 |
#else |
| 139 |
static int number(token) |
| 140 |
char token[]; |
| 141 |
#endif |
| 142 |
{ |
| 143 |
int i; |
| 144 |
|
| 145 |
sscanf(token, "%d", &i); |
| 146 |
return i; |
| 147 |
} |
| 148 |
|
| 149 |
#ifdef _PROTOTYPES_ |
| 150 |
static char *gettoken( |
| 151 |
char *buf |
| 152 |
) |
| 153 |
#else |
| 154 |
static char *gettoken(buf) |
| 155 |
char *buf; |
| 156 |
#endif |
| 157 |
{ |
| 158 |
static char *marker; |
| 159 |
static char oldch; |
| 160 |
|
| 161 |
if (buf == NULL) |
| 162 |
*marker = oldch; |
| 163 |
else |
| 164 |
marker = buf; |
| 165 |
while (*marker != '\0' && isSpace(*marker) && *marker != '\n') marker++; |
| 166 |
buf = marker; |
| 167 |
if (isISOLetter(*marker)) |
| 168 |
while (*marker&&(isISOLetter(*marker)||isdigit(*marker)||*marker=='\'')) marker++; |
| 169 |
else if (isdigit(*marker)) |
| 170 |
while (isdigit(*marker)) marker++; |
| 171 |
else if (*marker == '\"') { |
| 172 |
marker++; |
| 173 |
while (*marker != '\"') marker++; |
| 174 |
marker++; |
| 175 |
} else if (*marker == '\0' || *marker == '\n') |
| 176 |
return NULL; |
| 177 |
else |
| 178 |
marker++; |
| 179 |
oldch = *marker; |
| 180 |
*marker = '\0'; |
| 181 |
return buf; |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
#ifdef _PROTOTYPES_ |
| 186 |
static void agetline(void) |
| 187 |
#else |
| 188 |
static void agetline() |
| 189 |
#endif |
| 190 |
{ |
| 191 |
para(); |
| 192 |
do { |
| 193 |
#if defined(HAVE_ANSI) || defined(GLK) |
| 194 |
statusline(); |
| 195 |
#endif |
| 196 |
printf("> "); |
| 197 |
if (logflg) |
| 198 |
fprintf(logfil, "> "); |
| 199 |
#ifdef USE_READLINE |
| 200 |
if (!readline(buf)) { |
| 201 |
newline(); |
| 202 |
quit(); |
| 203 |
} |
| 204 |
#else |
| 205 |
if (fgets(buf, LISTLEN, stdin) == NULL) { |
| 206 |
newline(); |
| 207 |
quit(); |
| 208 |
} |
| 209 |
#endif |
| 210 |
getPageSize(); |
| 211 |
anyOutput = FALSE; |
| 212 |
if (logflg) |
| 213 |
#ifndef __amiga__ |
| 214 |
fprintf(logfil, "%s\n", buf); |
| 215 |
#else |
| 216 |
fprintf(logfil, "%s", buf); |
| 217 |
#endif |
| 218 |
#if ISO == 0 |
| 219 |
toIso(isobuf, buf, NATIVECHARSET); |
| 220 |
#else |
| 221 |
strcpy(isobuf, buf); |
| 222 |
#endif |
| 223 |
token = gettoken(isobuf); |
| 224 |
if (token != NULL && strcmp("debug", token) == 0 && header->debug) { |
| 225 |
dbgflg = TRUE; |
| 226 |
debug(); |
| 227 |
token = NULL; |
| 228 |
} |
| 229 |
} while (token == NULL); |
| 230 |
eol = FALSE; |
| 231 |
lin = 1; |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
#ifdef _PROTOTYPES_ |
| 236 |
static void scan(void) |
| 237 |
#else |
| 238 |
static void scan() |
| 239 |
#endif |
| 240 |
{ |
| 241 |
int i; |
| 242 |
int w; |
| 243 |
char *str; |
| 244 |
|
| 245 |
agetline(); |
| 246 |
wrds[0] = 0; |
| 247 |
for (i = 0; i < litCount; i++) |
| 248 |
if (litValues[i].type == TYPSTR && litValues[i].value != 0) |
| 249 |
free((char *) litValues[i].value); |
| 250 |
i = 0; |
| 251 |
litCount = 0; |
| 252 |
do { |
| 253 |
if (isISOLetter(token[0])) { |
| 254 |
(void) stringLower(token); |
| 255 |
w = lookup(token); |
| 256 |
if (!isNoise(w)) |
| 257 |
wrds[i++] = w; |
| 258 |
} else if (isdigit(token[0])) { |
| 259 |
if (litCount > MAXPARAMS) |
| 260 |
syserr("Too many parameters."); |
| 261 |
wrds[i++] = dictsize+litCount; |
| 262 |
litValues[litCount].type = TYPNUM; |
| 263 |
litValues[litCount++].value = number(token); |
| 264 |
} else if (token[0] == '\"') { |
| 265 |
if (litCount > MAXPARAMS) |
| 266 |
syserr("Too many parameters."); |
| 267 |
wrds[i++] = dictsize+litCount; |
| 268 |
litValues[litCount].type = TYPSTR; |
| 269 |
|
| 270 |
str = strdup(&token[1]); |
| 271 |
str[strlen(token)-2] = '\0'; |
| 272 |
litValues[litCount++].value = (Aptr) str; |
| 273 |
} else if (token[0] == ',') { |
| 274 |
wrds[i++] = conjWord; |
| 275 |
} else |
| 276 |
unknown(token); |
| 277 |
wrds[i] = EOF; |
| 278 |
eol = (token = gettoken(NULL)) == NULL; |
| 279 |
} while (!eol); |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
static int allLength; |
| 301 |
|
| 302 |
|
| 303 |
#ifdef _PROTOTYPES_ |
| 304 |
static void nonverb(void) |
| 305 |
#else |
| 306 |
static void nonverb() |
| 307 |
#endif |
| 308 |
{ |
| 309 |
if (isDir(wrds[wrdidx])) { |
| 310 |
wrdidx++; |
| 311 |
if (wrds[wrdidx] != EOF && !isConj(wrds[wrdidx])) |
| 312 |
error(M_WHAT); |
| 313 |
else |
| 314 |
go(dict[wrds[wrdidx-1]].code); |
| 315 |
if (wrds[wrdidx] != EOF) |
| 316 |
wrdidx++; |
| 317 |
} else |
| 318 |
error(M_WHAT); |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
#ifdef _PROTOTYPES_ |
| 323 |
static void buildall( |
| 324 |
ParamElem list[] |
| 325 |
) |
| 326 |
#else |
| 327 |
static void buildall(list) |
| 328 |
ParamElem list[]; |
| 329 |
#endif |
| 330 |
{ |
| 331 |
int o, i = 0; |
| 332 |
Boolean found = FALSE; |
| 333 |
|
| 334 |
for (o = OBJMIN; o <= OBJMAX; o++) |
| 335 |
if (isHere(o)) { |
| 336 |
found = TRUE; |
| 337 |
list[i].code = o; |
| 338 |
list[i++].firstWord = EOF; |
| 339 |
} |
| 340 |
if (!found) |
| 341 |
error(M_WHAT_ALL); |
| 342 |
else |
| 343 |
list[i].code = EOF; |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
#ifdef _PROTOTYPES_ |
| 348 |
static void unambig( |
| 349 |
ParamElem plst[] |
| 350 |
) |
| 351 |
#else |
| 352 |
static void unambig(plst) |
| 353 |
ParamElem plst[]; |
| 354 |
#endif |
| 355 |
{ |
| 356 |
int i; |
| 357 |
Boolean found = FALSE; |
| 358 |
static ParamElem *refs; |
| 359 |
static ParamElem *savlst; |
| 360 |
int firstWord, lastWord; |
| 361 |
|
| 362 |
if (refs == NULL) |
| 363 |
refs = (ParamElem *)allocate((MAXENTITY+1)*sizeof(ParamElem)); |
| 364 |
|
| 365 |
if (savlst == NULL) |
| 366 |
savlst = (ParamElem *)allocate((MAXENTITY+1)*sizeof(ParamElem)); |
| 367 |
|
| 368 |
if (isLiteral(wrds[wrdidx])) { |
| 369 |
|
| 370 |
plst[0].code = wrds[wrdidx++]-dictsize+LITMIN; |
| 371 |
plst[0].firstWord = EOF; |
| 372 |
plst[1].code = EOF; |
| 373 |
return; |
| 374 |
} |
| 375 |
|
| 376 |
plst[0].code = EOF; |
| 377 |
if (isIt(wrds[wrdidx])) { |
| 378 |
wrdidx++; |
| 379 |
|
| 380 |
for (i = lstlen(pparams)-1; i >= 0 && (pparams[i].code == 0 || pparams[i].code >= LITMIN); i--); |
| 381 |
if (i < 0) |
| 382 |
error(M_WHAT_IT); |
| 383 |
if (!isHere(pparams[i].code)) { |
| 384 |
params[0].code = pparams[i].code; |
| 385 |
params[0].firstWord = EOF; |
| 386 |
params[1].code = EOF; |
| 387 |
error(M_NO_SUCH); |
| 388 |
} |
| 389 |
plst[0] = pparams[i]; |
| 390 |
plst[0].firstWord = EOF; |
| 391 |
plst[1].code = EOF; |
| 392 |
return; |
| 393 |
} |
| 394 |
|
| 395 |
firstWord = wrdidx; |
| 396 |
while (wrds[wrdidx] != EOF && isAdj(wrds[wrdidx])) { |
| 397 |
|
| 398 |
if (isNoun(wrds[wrdidx]) && (wrds[wrdidx+1] == EOF || !isNoun(wrds[wrdidx+1]))) |
| 399 |
break; |
| 400 |
cpyrefs(refs, (Aword *)addrTo(dict[wrds[wrdidx]].adjrefs)); |
| 401 |
lstcpy(savlst, plst); |
| 402 |
if (found) |
| 403 |
isect(plst, refs); |
| 404 |
else { |
| 405 |
lstcpy(plst, refs); |
| 406 |
found = TRUE; |
| 407 |
} |
| 408 |
wrdidx++; |
| 409 |
} |
| 410 |
if (wrds[wrdidx] != EOF) { |
| 411 |
if (isNoun(wrds[wrdidx])) { |
| 412 |
cpyrefs(refs, (Aword *)addrTo(dict[wrds[wrdidx]].nounrefs)); |
| 413 |
if (found) |
| 414 |
isect(plst, refs); |
| 415 |
else { |
| 416 |
lstcpy(plst, refs); |
| 417 |
found = TRUE; |
| 418 |
} |
| 419 |
wrdidx++; |
| 420 |
} else |
| 421 |
error(M_NOUN); |
| 422 |
} else if (found) { |
| 423 |
if (isNoun(wrds[wrdidx-1])) { |
| 424 |
|
| 425 |
lstcpy(plst, savlst); |
| 426 |
cpyrefs(refs, (Aword *)addrTo(dict[wrds[wrdidx-1]].nounrefs)); |
| 427 |
if (plst[0].code == EOF) |
| 428 |
lstcpy(plst, refs); |
| 429 |
else |
| 430 |
isect(plst, refs); |
| 431 |
} else |
| 432 |
error(M_NOUN); |
| 433 |
} |
| 434 |
lastWord = wrdidx-1; |
| 435 |
|
| 436 |
|
| 437 |
if (lstlen(plst) > 1) { |
| 438 |
for (i=0; plst[i].code != EOF; i++) |
| 439 |
if (!isHere(plst[i].code)) |
| 440 |
plst[i].code = 0; |
| 441 |
compact(plst); |
| 442 |
} |
| 443 |
|
| 444 |
if (lstlen(plst) > 1 || (found && lstlen(plst) == 0)) { |
| 445 |
params[0].code = 0; |
| 446 |
params[0].firstWord = firstWord; |
| 447 |
params[0].lastWord = lastWord; |
| 448 |
params[1].code = EOF; |
| 449 |
if (lstlen(plst) > 1) |
| 450 |
error(M_WHICH_ONE); |
| 451 |
else if (found && lstlen(plst) == 0) |
| 452 |
error(M_NO_SUCH); |
| 453 |
} else { |
| 454 |
plst[0].firstWord = firstWord; |
| 455 |
plst[0].lastWord = lastWord; |
| 456 |
} |
| 457 |
} |
| 458 |
|
| 459 |
|
| 460 |
#ifdef _PROTOTYPES_ |
| 461 |
static void simple( |
| 462 |
ParamElem olst[] |
| 463 |
) |
| 464 |
#else |
| 465 |
static void simple(olst) |
| 466 |
ParamElem olst[]; |
| 467 |
#endif |
| 468 |
{ |
| 469 |
static ParamElem *tlst = NULL; |
| 470 |
int savidx = wrdidx; |
| 471 |
Boolean savplur = FALSE; |
| 472 |
int i; |
| 473 |
|
| 474 |
if (tlst == NULL) |
| 475 |
tlst = (ParamElem *) allocate(sizeof(ParamElem)*(MAXENTITY+1)); |
| 476 |
tlst[0].code = EOF; |
| 477 |
|
| 478 |
for (;;) { |
| 479 |
if (isThem(wrds[wrdidx])) { |
| 480 |
plural = TRUE; |
| 481 |
for (i = 0; pmlst[i].code != EOF; i++) |
| 482 |
if (!isHere(pmlst[i].code)) |
| 483 |
pmlst[i].code = 0; |
| 484 |
compact(pmlst); |
| 485 |
if (lstlen(pmlst) == 0) |
| 486 |
error(M_WHAT_THEM); |
| 487 |
lstcpy(olst, pmlst); |
| 488 |
olst[0].firstWord = EOF; |
| 489 |
wrdidx++; |
| 490 |
} else { |
| 491 |
unambig(olst); |
| 492 |
if (lstlen(olst) == 0) { |
| 493 |
lstcpy(olst, tlst); |
| 494 |
wrdidx = savidx; |
| 495 |
plural = savplur; |
| 496 |
return; |
| 497 |
} |
| 498 |
} |
| 499 |
mrglst(tlst, olst); |
| 500 |
if (wrds[wrdidx] != EOF |
| 501 |
&& (isConj(wrds[wrdidx]) && |
| 502 |
(isAdj(wrds[wrdidx+1]) || isNoun(wrds[wrdidx+1])))) { |
| 503 |
|
| 504 |
savplur = plural; |
| 505 |
savidx = wrdidx; |
| 506 |
wrdidx++; |
| 507 |
plural = TRUE; |
| 508 |
} else { |
| 509 |
lstcpy(olst, tlst); |
| 510 |
return; |
| 511 |
} |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
#ifdef _PROTOTYPES_ |
| 526 |
static void complex( |
| 527 |
ParamElem olst[] |
| 528 |
) |
| 529 |
#else |
| 530 |
static void complex(olst) |
| 531 |
ParamElem olst[]; |
| 532 |
#endif |
| 533 |
{ |
| 534 |
static ParamElem *alst = NULL; |
| 535 |
|
| 536 |
if (alst == NULL) |
| 537 |
alst = (ParamElem *) allocate((MAXENTITY+1)*sizeof(ParamElem)); |
| 538 |
|
| 539 |
if (isAll(wrds[wrdidx])) { |
| 540 |
plural = TRUE; |
| 541 |
buildall(alst); |
| 542 |
wrdidx++; |
| 543 |
if (wrds[wrdidx] != EOF && isBut(wrds[wrdidx])) { |
| 544 |
wrdidx++; |
| 545 |
simple(olst); |
| 546 |
if (lstlen(olst) == 0) |
| 547 |
error(M_AFTER_BUT); |
| 548 |
sublst(alst, olst); |
| 549 |
if (lstlen(alst) == 0) |
| 550 |
error(M_NOT_MUCH); |
| 551 |
} |
| 552 |
lstcpy(olst, alst); |
| 553 |
allLength = lstlen(olst); |
| 554 |
} else |
| 555 |
simple(olst); |
| 556 |
} |
| 557 |
|
| 558 |
|
| 559 |
#ifdef _PROTOTYPES_ |
| 560 |
static Boolean claCheck( |
| 561 |
ClaElem *cla |
| 562 |
) |
| 563 |
#else |
| 564 |
static Boolean claCheck(cla) |
| 565 |
ClaElem *cla; |
| 566 |
#endif |
| 567 |
{ |
| 568 |
Boolean ok = FALSE; |
| 569 |
|
| 570 |
if ((cla->classes&(Aword)CLA_OBJ) != 0) |
| 571 |
ok = ok || isObj(params[cla->code-1].code); |
| 572 |
if ((cla->classes&(Aword)CLA_CNT) != 0) |
| 573 |
ok = ok || isCnt(params[cla->code-1].code); |
| 574 |
if ((cla->classes&(Aword)CLA_ACT) != 0) |
| 575 |
ok = ok || isAct(params[cla->code-1].code); |
| 576 |
if ((cla->classes&(Aword)CLA_NUM) != 0) |
| 577 |
ok = ok || isNum(params[cla->code-1].code); |
| 578 |
if ((cla->classes&(Aword)CLA_STR) != 0) |
| 579 |
ok = ok || isStr(params[cla->code-1].code); |
| 580 |
if ((cla->classes&(Aword)CLA_COBJ) != 0) |
| 581 |
ok = ok || (isCnt(params[cla->code-1].code) && isObj(params[cla->code-1].code)); |
| 582 |
if ((cla->classes&(Aword)CLA_CACT) != 0) |
| 583 |
ok = ok || (isCnt(params[cla->code-1].code) && isAct(params[cla->code-1].code)); |
| 584 |
return ok; |
| 585 |
} |
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
static void resolve(ParamElem plst[]) |
| 597 |
{ |
| 598 |
int i; |
| 599 |
|
| 600 |
if (allLength > 0) return; |
| 601 |
|
| 602 |
|
| 603 |
for (i=0; plst[i].code != EOF; i++) |
| 604 |
if (plst[i].code < LITMIN) |
| 605 |
if (!isHere(plst[i].code)) { |
| 606 |
params[0] = plst[i]; |
| 607 |
params[1].code = EOF; |
| 608 |
error(M_NO_SUCH); |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
#ifdef _PROTOTYPES_ |
| 614 |
static void try( |
| 615 |
ParamElem mlst[] |
| 616 |
) |
| 617 |
#else |
| 618 |
static void try(mlst) |
| 619 |
ParamElem mlst[]; |
| 620 |
#endif |
| 621 |
{ |
| 622 |
ElmElem *elms; |
| 623 |
StxElem *stx; |
| 624 |
ClaElem *cla; |
| 625 |
Boolean anyPlural = FALSE; |
| 626 |
int i, p; |
| 627 |
static ParamElem *tlst = NULL; |
| 628 |
static Boolean *checked = NULL; |
| 629 |
|
| 630 |
if (tlst == NULL) { |
| 631 |
tlst = (ParamElem *) allocate((MAXENTITY+1)*sizeof(ParamElem)); |
| 632 |
checked = (Boolean *) allocate((MAXENTITY+1)*sizeof(Boolean)); |
| 633 |
} |
| 634 |
|
| 635 |
for (stx = stxs; !endOfTable(stx); stx++) |
| 636 |
if (stx->code == vrbcode) |
| 637 |
break; |
| 638 |
if (endOfTable(stx)) |
| 639 |
error(M_WHAT); |
| 640 |
|
| 641 |
elms = (ElmElem *) addrTo(stx->elms); |
| 642 |
|
| 643 |
while (TRUE) { |
| 644 |
|
| 645 |
if (wrds[wrdidx] == EOF || isConj(wrds[wrdidx])) { |
| 646 |
while (!endOfTable(elms) && elms->code != EOS) |
| 647 |
elms++; |
| 648 |
if (endOfTable(elms)) |
| 649 |
error(M_WHAT); |
| 650 |
else |
| 651 |
break; |
| 652 |
} else { |
| 653 |
|
| 654 |
if (isPrep(wrds[wrdidx])) { |
| 655 |
while (!endOfTable(elms) && elms->code != dict[wrds[wrdidx]].code) |
| 656 |
elms++; |
| 657 |
if (endOfTable(elms)) |
| 658 |
error(M_WHAT); |
| 659 |
else |
| 660 |
wrdidx++; |
| 661 |
} else { |
| 662 |
|
| 663 |
while (!endOfTable(elms) && elms->code != 0) |
| 664 |
elms++; |
| 665 |
if (endOfTable(elms)) |
| 666 |
error(M_WHAT); |
| 667 |
|
| 668 |
plural = FALSE; |
| 669 |
complex(tlst); |
| 670 |
if (lstlen(tlst) == 0) |
| 671 |
error(M_WHAT); |
| 672 |
if ((elms->flags & OMNIBIT) == 0) |
| 673 |
|
| 674 |
resolve(tlst); |
| 675 |
if (plural) { |
| 676 |
if ((elms->flags & MULTIPLEBIT) == 0) |
| 677 |
error(M_MULTIPLE); |
| 678 |
else { |
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
params[paramidx++].code = 0; |
| 684 |
lstcpy(mlst, tlst); |
| 685 |
anyPlural = TRUE; |
| 686 |
} |
| 687 |
} else |
| 688 |
params[paramidx++] = tlst[0]; |
| 689 |
params[paramidx].code = EOF; |
| 690 |
} |
| 691 |
elms = (ElmElem *) addrTo(elms->next); |
| 692 |
} |
| 693 |
} |
| 694 |
|
| 695 |
|
| 696 |
if (elms->next == 0) |
| 697 |
error(M_CANT0); |
| 698 |
|
| 699 |
for (p = 0; params[p].code != EOF; p++) |
| 700 |
checked[p] = FALSE; |
| 701 |
for (cla = (ClaElem *) addrTo(elms->next); !endOfTable(cla); cla++) { |
| 702 |
if (params[cla->code-1].code == 0) { |
| 703 |
|
| 704 |
for (i = 0; mlst[i].code != EOF; i++) { |
| 705 |
params[cla->code-1] = mlst[i]; |
| 706 |
if (!claCheck(cla)) { |
| 707 |
|
| 708 |
if (allLength == 0) { |
| 709 |
char marker[80]; |
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
sprintf(marker, "($%ld)", (unsigned long) cla->code); |
| 715 |
output(marker); |
| 716 |
interpret(cla->stms); |
| 717 |
para(); |
| 718 |
} |
| 719 |
mlst[i].code = 0; |
| 720 |
} |
| 721 |
} |
| 722 |
params[cla->code-1].code = 0; |
| 723 |
} else { |
| 724 |
if (!claCheck(cla)) { |
| 725 |
interpret(cla->stms); |
| 726 |
error(MSGMAX); |
| 727 |
} |
| 728 |
} |
| 729 |
checked[cla->code-1] = TRUE; |
| 730 |
} |
| 731 |
|
| 732 |
for (p = 0; params[p].code != EOF; p++) |
| 733 |
if (!checked[p]) { |
| 734 |
if (params[p].code == 0) { |
| 735 |
|
| 736 |
for (i = 0; mlst[i].code != EOF; i++) |
| 737 |
if (mlst[i].code != 0) |
| 738 |
if (!isObj(mlst[i].code)) |
| 739 |
mlst[i].code = 0; |
| 740 |
} else if (!isObj(params[p].code)) |
| 741 |
error(M_CANT0); |
| 742 |
} |
| 743 |
|
| 744 |
|
| 745 |
cur.vrb = ((Aword *) cla)[1]; |
| 746 |
|
| 747 |
|
| 748 |
if (allLength > 0) { |
| 749 |
for (p = 0; params[p].code != 0; p++); |
| 750 |
for (i = 0; i < allLength; i++) { |
| 751 |
if (mlst[i].code != 0) { |
| 752 |
params[p] = mlst[i]; |
| 753 |
if (!possible()) |
| 754 |
mlst[i].code = 0; |
| 755 |
} |
| 756 |
} |
| 757 |
params[p].code = 0; |
| 758 |
compact(mlst); |
| 759 |
if (lstlen(mlst) == 0) { |
| 760 |
params[0].code = EOF; |
| 761 |
error(M_WHAT_ALL); |
| 762 |
} |
| 763 |
} else if (anyPlural) { |
| 764 |
compact(mlst); |
| 765 |
if (lstlen(mlst) == 0) |
| 766 |
|
| 767 |
|
| 768 |
error(MSGMAX); |
| 769 |
} |
| 770 |
plural = anyPlural; |
| 771 |
} |
| 772 |
|
| 773 |
|
| 774 |
#ifdef _PROTOTYPES_ |
| 775 |
static void match( |
| 776 |
ParamElem *mlst |
| 777 |
) |
| 778 |
#else |
| 779 |
static void match(mlst) |
| 780 |
ParamElem *mlst; |
| 781 |
#endif |
| 782 |
{ |
| 783 |
try(mlst); |
| 784 |
if (wrds[wrdidx] != EOF && !isConj(wrds[wrdidx])) |
| 785 |
error(M_WHAT); |
| 786 |
if (wrds[wrdidx] != EOF) |
| 787 |
wrdidx++; |
| 788 |
} |
| 789 |
|
| 790 |
|
| 791 |
#ifdef _PROTOTYPES_ |
| 792 |
void parse(void) |
| 793 |
#else |
| 794 |
void parse() |
| 795 |
#endif |
| 796 |
{ |
| 797 |
if (mlst == NULL) { |
| 798 |
mlst = (ParamElem *) allocate(sizeof(ParamElem)*(MAXENTITY+1)); |
| 799 |
mlst[0].code = EOF; |
| 800 |
pmlst = (ParamElem *) allocate(sizeof(ParamElem)*(MAXENTITY+1)); |
| 801 |
params = (ParamElem *) allocate(sizeof(ParamElem)*(MAXENTITY+1)); |
| 802 |
params[0].code = EOF; |
| 803 |
pparams = (ParamElem *) allocate(sizeof(ParamElem)*(MAXENTITY+1)); |
| 804 |
} |
| 805 |
|
| 806 |
if (wrds[wrdidx] == EOF) { |
| 807 |
wrdidx = 0; |
| 808 |
scan(); |
| 809 |
} else if (anyOutput) |
| 810 |
para(); |
| 811 |
|
| 812 |
allLength = 0; |
| 813 |
paramidx = 0; |
| 814 |
lstcpy(pparams, params); |
| 815 |
params[0].code = EOF; |
| 816 |
lstcpy(pmlst, mlst); |
| 817 |
mlst[0].code = EOF; |
| 818 |
if (isVerb(wrds[wrdidx])) { |
| 819 |
vrbwrd = wrds[wrdidx]; |
| 820 |
vrbcode = dict[vrbwrd].code; |
| 821 |
wrdidx++; |
| 822 |
match(mlst); |
| 823 |
action(mlst); |
| 824 |
} else { |
| 825 |
params[0].code = EOF; |
| 826 |
pmlst[0].code = EOF; |
| 827 |
nonverb(); |
| 828 |
} |
| 829 |
} |