| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
#include "types.h" |
| 13 |
#include "acode.h" |
| 14 |
|
| 15 |
#include "reverse.h" |
| 16 |
|
| 17 |
#define endOfTable(x) ((*(Aword *) x) == EOF) |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
Aword *memory; |
| 22 |
AcdHdr *header; |
| 23 |
|
| 24 |
static int memTop = 0; |
| 25 |
|
| 26 |
static char *acdfnm; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
static int dumpdict, dumpatrs, dumpacts, dumpobjs, dumplocs, dumpstxs, |
| 31 |
dumpvrbs, dumpevts, dumpcnts, dumpruls, dumpstms; |
| 32 |
|
| 33 |
int eot(Aword *adr) |
| 34 |
{ |
| 35 |
return *adr == EOF; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
static void syserr(char str[]) |
| 41 |
{ |
| 42 |
printf("ERROR - %s\n", str); |
| 43 |
exit(0); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
static void indent(int level) |
| 48 |
{ |
| 49 |
int i; |
| 50 |
|
| 51 |
for (i = 0; i < level; i++) |
| 52 |
printf(" "); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
static void dumpAwords(Aaddr awords) |
| 65 |
{ |
| 66 |
Aword *adr; |
| 67 |
|
| 68 |
if (awords == 0) return; |
| 69 |
|
| 70 |
for (adr = addrTo(awords); *(adr+1) != EOF; adr++) |
| 71 |
printf("%ld, ", *adr); |
| 72 |
printf("%ld\n", *adr); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
static void dumpWrdClass(Aword class) |
| 86 |
{ |
| 87 |
if ((class&((Aword)1L<<WRD_VRB)) != 0) printf("Verb "); |
| 88 |
if ((class&((Aword)1L<<WRD_CONJ)) != 0) printf("Conjunction "); |
| 89 |
if ((class&((Aword)1L<<WRD_BUT)) != 0) printf("But "); |
| 90 |
if ((class&((Aword)1L<<WRD_THEM)) != 0) printf("Them "); |
| 91 |
if ((class&((Aword)1L<<WRD_IT)) != 0) printf("It "); |
| 92 |
if ((class&((Aword)1L<<WRD_NOUN)) != 0) printf("Noun "); |
| 93 |
if ((class&((Aword)1L<<WRD_ADJ)) != 0) printf("Adjective "); |
| 94 |
if ((class&((Aword)1L<<WRD_PREP)) != 0) printf("Preposition "); |
| 95 |
if ((class&((Aword)1L<<WRD_ALL)) != 0) printf("All "); |
| 96 |
if ((class&((Aword)1L<<WRD_DIR)) != 0) printf("Direction "); |
| 97 |
if ((class&((Aword)1L<<WRD_NOISE)) != 0) printf("Noise "); |
| 98 |
if ((class&((Aword)1L<<WRD_SYN)) != 0) printf("Synonym "); |
| 99 |
printf("\n"); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
static void dumpDict(int level, Aword dict) |
| 112 |
{ |
| 113 |
WrdElem *wrd; |
| 114 |
|
| 115 |
if (dict == 0) return; |
| 116 |
|
| 117 |
for (wrd = (WrdElem *)addrTo(dict); !endOfTable(wrd); wrd++) { |
| 118 |
indent(level); |
| 119 |
printf("WRD: \n"); |
| 120 |
indent(level+1); |
| 121 |
printf("WRD: %ld(0x%lx)", wrd->wrd, wrd->wrd); |
| 122 |
if (wrd->wrd != 0) |
| 123 |
printf(" -> \"%s\"", (char *)&memory[wrd->wrd]); |
| 124 |
printf("\n"); |
| 125 |
indent(level+1); |
| 126 |
printf("CLASS: %ld = ", wrd->class); dumpWrdClass(wrd->class); |
| 127 |
indent(level+1); |
| 128 |
printf("CODE: %ld\n", wrd->code); |
| 129 |
indent(level+1); |
| 130 |
printf("ADJREFS: %ld(0x%lx)", wrd->adjrefs, wrd->adjrefs); |
| 131 |
if (wrd->adjrefs != 0) { |
| 132 |
printf(" -> "); |
| 133 |
dumpAwords(wrd->adjrefs); |
| 134 |
} else |
| 135 |
printf("\n"); |
| 136 |
indent(level+1); |
| 137 |
printf("NOUNREFS: %ld(0x%lx)", wrd->nounrefs, wrd->nounrefs); |
| 138 |
if (wrd->nounrefs != 0) { |
| 139 |
printf(" -> "); |
| 140 |
dumpAwords(wrd->nounrefs); |
| 141 |
} else |
| 142 |
printf("\n"); |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
static void dumpAtrs(int level, Aword atrs) |
| 156 |
{ |
| 157 |
AtrElem *atr; |
| 158 |
int atrno = 1; |
| 159 |
|
| 160 |
if (atrs == 0) return; |
| 161 |
|
| 162 |
for (atr = (AtrElem *)addrTo(atrs); !endOfTable(atr); atr++, atrno++) { |
| 163 |
indent(level); |
| 164 |
printf("ATR: #%d\n", atrno); |
| 165 |
indent(level+1); |
| 166 |
printf("VAL: %ld\n", atr->val); |
| 167 |
indent(level+1); |
| 168 |
printf("STRADR: %ld(0x%lx)", atr->stradr, atr->stradr); |
| 169 |
if (atr->stradr != 0) |
| 170 |
printf(" -> \"%s\"", (char *)&memory[atr->stradr]); |
| 171 |
printf("\n"); |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
static void dumpChks(int level, Aword chks) |
| 185 |
{ |
| 186 |
ChkElem *chk; |
| 187 |
|
| 188 |
if (chks == 0) return; |
| 189 |
|
| 190 |
for (chk = (ChkElem *)addrTo(chks); !endOfTable(chk); chk++) { |
| 191 |
indent(level); |
| 192 |
printf("CHK:\n"); |
| 193 |
indent(level+1); |
| 194 |
printf("EXP: %ld(0x%lx)\n", chk->exp, chk->exp); |
| 195 |
indent(level+1); |
| 196 |
printf("STMS: %ld(0x%lx)\n", chk->stms, chk->stms); |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
static void dumpQual(Aword qual) |
| 210 |
{ |
| 211 |
switch (qual) { |
| 212 |
case Q_DEFAULT: printf("Default"); break; |
| 213 |
case Q_AFTER: printf("After"); break; |
| 214 |
case Q_BEFORE: printf("Before"); break; |
| 215 |
case Q_ONLY: printf("Only"); break; |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
static void dumpAlts(int level, Aword alts) |
| 228 |
{ |
| 229 |
AltElem *alt; |
| 230 |
|
| 231 |
if (alts == 0) return; |
| 232 |
|
| 233 |
for (alt = (AltElem *)addrTo(alts); !endOfTable(alt); alt++) { |
| 234 |
indent(level); |
| 235 |
printf("ALT:\n"); |
| 236 |
indent(level+1); |
| 237 |
printf("PARAM: %ld\n", alt->param); |
| 238 |
indent(level+1); |
| 239 |
printf("QUAL: "); dumpQual(alt->qual); printf("\n"); |
| 240 |
indent(level+1); |
| 241 |
printf("CHECKS: %ld(0x%lx)\n", alt->checks, alt->checks); |
| 242 |
dumpChks(level+2, alt->checks); |
| 243 |
indent(level+1); |
| 244 |
printf("ACTION: %ld(0x%lx)\n", alt->action, alt->action); |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
static void dumpVrbs(int level, Aword vrbs) |
| 258 |
{ |
| 259 |
VrbElem *vrb; |
| 260 |
|
| 261 |
if (vrbs == 0) return; |
| 262 |
|
| 263 |
for (vrb = (VrbElem *)addrTo(vrbs); !endOfTable(vrb); vrb++) { |
| 264 |
indent(level); |
| 265 |
printf("VRB:\n"); |
| 266 |
indent(level+1); |
| 267 |
printf("CODE: %ld\n", vrb->code); |
| 268 |
indent(level+1); |
| 269 |
printf("ALT: %ld(0x%lx)\n", vrb->alts, vrb->alts); |
| 270 |
dumpAlts(level+2, vrb->alts); |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
static void dumpCnts(int level, Aword cnts) |
| 284 |
{ |
| 285 |
CntElem *cnt; |
| 286 |
|
| 287 |
if (cnts == 0) return; |
| 288 |
|
| 289 |
for (cnt = (CntElem *)addrTo(cnts); !endOfTable(cnt); cnt++) { |
| 290 |
indent(level); |
| 291 |
printf("CNT:\n"); |
| 292 |
indent(level+1); |
| 293 |
printf("LIMS: %ld(0x%lx)\n", cnt->lims, cnt->lims); |
| 294 |
indent(level+1); |
| 295 |
printf("HEADER: %ld(0x%lx)\n", cnt->header, cnt->header); |
| 296 |
indent(level+1); |
| 297 |
printf("EMPTY: %ld(0x%lx)\n", cnt->empty, cnt->empty); |
| 298 |
indent(level+1); |
| 299 |
printf("PARENT: %ld\n", cnt->parent); |
| 300 |
indent(level+1); |
| 301 |
printf("NAM: %ld(0x%lx)\n", cnt->nam, cnt->nam); |
| 302 |
|
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
static void dumpObjs(int level, Aword objs) |
| 316 |
{ |
| 317 |
ObjElem *obj; |
| 318 |
int objno = header->objmin; |
| 319 |
|
| 320 |
if (objs == 0) return; |
| 321 |
|
| 322 |
for (obj = (ObjElem *)addrTo(objs); !endOfTable(obj); obj++, objno++) { |
| 323 |
indent(level); |
| 324 |
printf("OBJ: #%d\n", objno); |
| 325 |
indent(level+1); |
| 326 |
printf("LOC: %ld\n", obj->loc); |
| 327 |
indent(level+1); |
| 328 |
printf("DESCRIBE: %s\n", obj->describe?"Yes":"No"); |
| 329 |
indent(level+1); |
| 330 |
printf("ATRS: %ld(0x%lx)\n", obj->atrs, obj->atrs); |
| 331 |
dumpAtrs(level+2, obj->atrs); |
| 332 |
indent(level+1); |
| 333 |
printf("CONT: %ld(0x%lx)\n", obj->cont, obj->cont); |
| 334 |
indent(level+1); |
| 335 |
printf("VRBS: %ld(0x%lx)\n", obj->vrbs, obj->vrbs); |
| 336 |
dumpVrbs(level+2, obj->vrbs); |
| 337 |
indent(level+1); |
| 338 |
printf("DSCR1: %ld(0x%lx)\n", obj->dscr1, obj->dscr1); |
| 339 |
indent(level+1); |
| 340 |
printf("ART: %s\n", obj->art?"Yes":"No"); |
| 341 |
indent(level+1); |
| 342 |
printf("DSCR2: %ld(0x%lx)\n", obj->dscr2, obj->dscr2); |
| 343 |
} |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
static void dumpActs(int level, Aword acts) |
| 356 |
{ |
| 357 |
ActElem *act; |
| 358 |
int actno = header->actmin; |
| 359 |
|
| 360 |
if (acts == 0) return; |
| 361 |
|
| 362 |
for (act = (ActElem *)addrTo(acts); !endOfTable(act); act++, actno++) { |
| 363 |
indent(level); |
| 364 |
printf("ACT: #%d\n", actno); |
| 365 |
indent(level+1); |
| 366 |
printf("LOC: %ld\n", act->loc); |
| 367 |
indent(level+1); |
| 368 |
printf("DESCRIBE: %s\n", act->describe?"Yes":"No"); |
| 369 |
indent(level+1); |
| 370 |
printf("NAM: %ld(0x%lx)\n", act->nam, act->nam); |
| 371 |
indent(level+1); |
| 372 |
printf("ATRS: %ld(0x%lx)\n", act->atrs, act->atrs); |
| 373 |
dumpAtrs(level+2, act->atrs); |
| 374 |
indent(level+1); |
| 375 |
printf("CONT: %ld(0x%lx)\n", act->cont, act->cont); |
| 376 |
indent(level+1); |
| 377 |
printf("SCRIPT: %ld(0x%lx)\n", act->script, act->script); |
| 378 |
indent(level+1); |
| 379 |
printf("SCRADR: %ld(0x%lx)\n", act->scradr, act->scradr); |
| 380 |
indent(level+1); |
| 381 |
printf("STEP: %ld\n", act->step); |
| 382 |
indent(level+1); |
| 383 |
printf("COUNT: %ld\n", act->count); |
| 384 |
indent(level+1); |
| 385 |
printf("VRBS: %ld(0x%lx)\n", act->vrbs, act->vrbs); |
| 386 |
dumpVrbs(level+2, act->vrbs); |
| 387 |
indent(level+1); |
| 388 |
printf("DSCR: %ld(0x%lx)\n", act->dscr, act->dscr); |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
static void dumpExts(int level, Aword exts) |
| 402 |
{ |
| 403 |
ExtElem *ext; |
| 404 |
|
| 405 |
if (exts == 0) return; |
| 406 |
|
| 407 |
for (ext = (ExtElem *)addrTo(exts); !endOfTable(ext); ext++) { |
| 408 |
indent(level); |
| 409 |
printf("EXT:\n"); |
| 410 |
indent(level+1); |
| 411 |
printf("CODE: %ld\n", ext->code); |
| 412 |
indent(level+1); |
| 413 |
printf("CHECKS: %ld(0x%lx)\n", ext->checks, ext->checks); |
| 414 |
dumpChks(level+2, ext->checks); |
| 415 |
indent(level+1); |
| 416 |
printf("ACTION: %ld(0x%lx)\n", ext->action, ext->action); |
| 417 |
indent(level+1); |
| 418 |
printf("NEXT: %ld(0x%lx)\n", ext->next, ext->next); |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
static void dumpLocs(int level, Aword locs) |
| 432 |
{ |
| 433 |
LocElem *loc; |
| 434 |
int locno = header->locmin; |
| 435 |
|
| 436 |
if (locs == 0) return; |
| 437 |
|
| 438 |
for (loc = (LocElem *)addrTo(locs); !endOfTable(loc); loc++, locno++) { |
| 439 |
indent(level); |
| 440 |
printf("LOC: #%d\n", locno); |
| 441 |
indent(level+1); |
| 442 |
printf("NAMS: %ld(0x%lx)\n", loc->nams, loc->nams); |
| 443 |
indent(level+1); |
| 444 |
printf("DSCR: %ld(0x%lx)\n", loc->dscr, loc->dscr); |
| 445 |
indent(level+1); |
| 446 |
printf("DOES: %ld(0x%lx)\n", loc->does, loc->does); |
| 447 |
indent(level+1); |
| 448 |
printf("DESCRIBE: %ld\n", loc->describe); |
| 449 |
indent(level+1); |
| 450 |
printf("ATRS: %ld(0x%lx)\n", loc->atrs, loc->atrs); |
| 451 |
dumpAtrs(level+2, loc->atrs); |
| 452 |
indent(level+1); |
| 453 |
printf("EXTS: %ld(0x%lx)\n", loc->exts, loc->exts); |
| 454 |
dumpExts(level+2, loc->exts); |
| 455 |
indent(level+1); |
| 456 |
printf("VRBS: %ld(0x%lx)\n", loc->vrbs, loc->vrbs); |
| 457 |
dumpVrbs(level+2, loc->vrbs); |
| 458 |
} |
| 459 |
} |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
static void dumpElms(int level, Aword elms) |
| 471 |
{ |
| 472 |
ElmElem *elm; |
| 473 |
|
| 474 |
if (elms == 0) return; |
| 475 |
|
| 476 |
for (elm = (ElmElem *)addrTo(elms); !endOfTable(elm); elm++) { |
| 477 |
indent(level); |
| 478 |
printf("ELM: #%ld\n", elm->code); |
| 479 |
indent(level+1); |
| 480 |
printf("FLAGS: %ld(0x%lx)\n", elm->flags, elm->flags); |
| 481 |
indent(level+1); |
| 482 |
printf("NEXT (%s): %ld(0x%lx)\n", elm->code==-2?"cla":"elm", elm->next, elm->next); |
| 483 |
if(elm->code != EOS) { |
| 484 |
dumpElms(level+2, elm->next); |
| 485 |
} |
| 486 |
} |
| 487 |
} |
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
static void dumpStxs(int level, Aword stxs) |
| 499 |
{ |
| 500 |
StxElem *stx; |
| 501 |
|
| 502 |
if (stxs == 0) return; |
| 503 |
|
| 504 |
for (stx = (StxElem *)addrTo(stxs); !endOfTable(stx); stx++) { |
| 505 |
indent(level); |
| 506 |
printf("STX: #%ld\n", stx->code); |
| 507 |
indent(level+1); |
| 508 |
printf("ELMS: %ld(0x%lx)\n", stx->elms, stx->elms); |
| 509 |
dumpElms(level+2, stx->elms); |
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
static void dumpStms(Aword pc) |
| 523 |
{ |
| 524 |
Aword i; |
| 525 |
|
| 526 |
while(TRUE) { |
| 527 |
printf("\n%4lx: ", pc); |
| 528 |
if (pc > memTop) |
| 529 |
syserr("Dumping outside program memory."); |
| 530 |
|
| 531 |
i = memory[pc++]; |
| 532 |
|
| 533 |
switch (I_CLASS(i)) { |
| 534 |
case C_CONST: |
| 535 |
printf("PUSH \t%5ld", I_OP(i)); |
| 536 |
break; |
| 537 |
case C_CURVAR: |
| 538 |
switch (I_OP(i)) { |
| 539 |
case V_PARAM: |
| 540 |
printf("PARAM"); |
| 541 |
break; |
| 542 |
case V_CURLOC: |
| 543 |
printf("CURLOC"); |
| 544 |
break; |
| 545 |
case V_CURACT: |
| 546 |
printf("CURACT"); |
| 547 |
break; |
| 548 |
case V_CURVRB: |
| 549 |
printf("CURVRB"); |
| 550 |
break; |
| 551 |
case V_SCORE: |
| 552 |
printf("CURSCORE"); |
| 553 |
break; |
| 554 |
default: |
| 555 |
syserr("Unknown CURVAR instruction."); |
| 556 |
break; |
| 557 |
} |
| 558 |
break; |
| 559 |
|
| 560 |
case C_STMOP: |
| 561 |
switch (I_OP(i)) { |
| 562 |
case I_PRINT: { |
| 563 |
printf("PRINT"); |
| 564 |
break; |
| 565 |
} |
| 566 |
case I_SYSTEM: { |
| 567 |
printf("SYSTEM"); |
| 568 |
break; |
| 569 |
} |
| 570 |
case I_GETSTR: { |
| 571 |
printf("GETST"); |
| 572 |
break; |
| 573 |
} |
| 574 |
case I_QUIT: { |
| 575 |
printf("QUIT"); |
| 576 |
break; |
| 577 |
} |
| 578 |
case I_LOOK: { |
| 579 |
printf("LOOK"); |
| 580 |
break; |
| 581 |
} |
| 582 |
case I_SAVE: { |
| 583 |
printf("SAVE"); |
| 584 |
break; |
| 585 |
} |
| 586 |
case I_RESTORE: { |
| 587 |
printf("RESTORE"); |
| 588 |
break; |
| 589 |
} |
| 590 |
case I_RESTART: { |
| 591 |
printf("RESTART"); |
| 592 |
break; |
| 593 |
} |
| 594 |
case I_LIST: { |
| 595 |
printf("LIST"); |
| 596 |
break; |
| 597 |
} |
| 598 |
case I_EMPTY: { |
| 599 |
printf("EMPTY"); |
| 600 |
break; |
| 601 |
} |
| 602 |
case I_SCORE: { |
| 603 |
printf("SCORE"); |
| 604 |
break; |
| 605 |
} |
| 606 |
case I_VISITS: { |
| 607 |
printf("VISITS"); |
| 608 |
break; |
| 609 |
} |
| 610 |
case I_SCHEDULE: { |
| 611 |
printf("SCHEDULE"); |
| 612 |
break; |
| 613 |
} |
| 614 |
case I_CANCEL: { |
| 615 |
printf("CANCEL"); |
| 616 |
break; |
| 617 |
} |
| 618 |
case I_MAKE: { |
| 619 |
printf("MAKE"); |
| 620 |
break; |
| 621 |
} |
| 622 |
case I_SET: { |
| 623 |
printf("SET"); |
| 624 |
break; |
| 625 |
} |
| 626 |
case I_STRSET: { |
| 627 |
printf("STRSET"); |
| 628 |
break; |
| 629 |
} |
| 630 |
case I_INCR: { |
| 631 |
printf("INCR"); |
| 632 |
break; |
| 633 |
} |
| 634 |
case I_DECR: { |
| 635 |
printf("DECR"); |
| 636 |
break; |
| 637 |
} |
| 638 |
case I_ATTRIBUTE: { |
| 639 |
printf("ATTRIBUTE"); |
| 640 |
break; |
| 641 |
} |
| 642 |
case I_STRATTR: { |
| 643 |
printf("STRATTR"); |
| 644 |
break; |
| 645 |
} |
| 646 |
case I_LOCATE: { |
| 647 |
printf("LOCATE"); |
| 648 |
break; |
| 649 |
} |
| 650 |
case I_WHERE: { |
| 651 |
printf("WHERE"); |
| 652 |
break; |
| 653 |
} |
| 654 |
case I_HERE: { |
| 655 |
printf("HERE"); |
| 656 |
break; |
| 657 |
} |
| 658 |
case I_NEAR: { |
| 659 |
printf("NEAR"); |
| 660 |
break; |
| 661 |
} |
| 662 |
case I_USE: { |
| 663 |
printf("USE"); |
| 664 |
break; |
| 665 |
} |
| 666 |
case I_IN: { |
| 667 |
printf("IN "); |
| 668 |
break; |
| 669 |
} |
| 670 |
case I_DESCRIBE: { |
| 671 |
printf("DESCRIBE "); |
| 672 |
break; |
| 673 |
} |
| 674 |
case I_SAY: { |
| 675 |
printf("SAY"); |
| 676 |
break; |
| 677 |
} |
| 678 |
case I_SAYINT: { |
| 679 |
printf("SAYINT"); |
| 680 |
break; |
| 681 |
} |
| 682 |
case I_SAYSTR: { |
| 683 |
printf("SAYSTR"); |
| 684 |
break; |
| 685 |
} |
| 686 |
case I_IF: { |
| 687 |
printf("IF"); |
| 688 |
break; |
| 689 |
} |
| 690 |
case I_ELSE: { |
| 691 |
printf("ELSE"); |
| 692 |
break; |
| 693 |
} |
| 694 |
case I_ENDIF: { |
| 695 |
printf("ENDIF"); |
| 696 |
break; |
| 697 |
} |
| 698 |
case I_AND: { |
| 699 |
printf("AND"); |
| 700 |
break; |
| 701 |
} |
| 702 |
case I_OR: { |
| 703 |
printf("OR"); |
| 704 |
break; |
| 705 |
} |
| 706 |
case I_NE: { |
| 707 |
printf("NE"); |
| 708 |
break; |
| 709 |
} |
| 710 |
case I_EQ: { |
| 711 |
printf("EQ "); |
| 712 |
break; |
| 713 |
} |
| 714 |
case I_STREQ: { |
| 715 |
printf("STREQ "); |
| 716 |
break; |
| 717 |
} |
| 718 |
case I_STREXACT: { |
| 719 |
printf("STREXACT "); |
| 720 |
break; |
| 721 |
} |
| 722 |
case I_LE: { |
| 723 |
printf("LE "); |
| 724 |
break; |
| 725 |
} |
| 726 |
case I_GE: { |
| 727 |
printf("GE "); |
| 728 |
break; |
| 729 |
} |
| 730 |
case I_LT: { |
| 731 |
printf("LT "); |
| 732 |
break; |
| 733 |
} |
| 734 |
case I_GT: { |
| 735 |
printf("GT "); |
| 736 |
break; |
| 737 |
} |
| 738 |
case I_PLUS: { |
| 739 |
printf("PLUS "); |
| 740 |
break; |
| 741 |
} |
| 742 |
case I_MINUS: { |
| 743 |
printf("MINUS "); |
| 744 |
break; |
| 745 |
} |
| 746 |
case I_MULT: { |
| 747 |
printf("MULT "); |
| 748 |
break; |
| 749 |
} |
| 750 |
case I_DIV: { |
| 751 |
printf("DIV "); |
| 752 |
break; |
| 753 |
} |
| 754 |
case I_NOT: { |
| 755 |
printf("NOT "); |
| 756 |
break; |
| 757 |
} |
| 758 |
case I_MAX: { |
| 759 |
printf("MAX "); |
| 760 |
break; |
| 761 |
} |
| 762 |
case I_SUM: { |
| 763 |
printf("SUM "); |
| 764 |
break; |
| 765 |
} |
| 766 |
case I_COUNT: { |
| 767 |
printf("COUNT "); |
| 768 |
break; |
| 769 |
} |
| 770 |
case I_RND: { |
| 771 |
printf("RANDOM "); |
| 772 |
break; |
| 773 |
} |
| 774 |
case I_BTW: { |
| 775 |
printf("BETWEEN "); |
| 776 |
break; |
| 777 |
} |
| 778 |
case I_CONTAINS: { |
| 779 |
printf("CONTAINS "); |
| 780 |
break; |
| 781 |
} |
| 782 |
|
| 783 |
case I_DEPSTART: |
| 784 |
printf("DEPSTART"); |
| 785 |
break; |
| 786 |
|
| 787 |
case I_DEPCASE: |
| 788 |
printf("DEPCASE"); |
| 789 |
break; |
| 790 |
|
| 791 |
case I_DEPEXEC: { |
| 792 |
printf("DEPEXEC"); |
| 793 |
break; |
| 794 |
} |
| 795 |
|
| 796 |
case I_DEPELSE: |
| 797 |
printf("DEPELSE"); |
| 798 |
break; |
| 799 |
|
| 800 |
case I_DEPEND: |
| 801 |
printf("DEPEND"); |
| 802 |
break; |
| 803 |
|
| 804 |
case I_RETURN: |
| 805 |
printf("RETURN"); |
| 806 |
printf("\n"); |
| 807 |
return; |
| 808 |
|
| 809 |
default: |
| 810 |
syserr("Unknown STMOP instruction."); |
| 811 |
break; |
| 812 |
} |
| 813 |
break; |
| 814 |
|
| 815 |
default: |
| 816 |
syserr("Unknown instruction class."); |
| 817 |
break; |
| 818 |
} |
| 819 |
} |
| 820 |
} |
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
static void dumpACD(void) |
| 832 |
{ |
| 833 |
Aword crc = 0; |
| 834 |
int i; |
| 835 |
|
| 836 |
printf("VERSION: %d.%d(%d)%c\n", header->vers[0], |
| 837 |
header->vers[1], header->vers[2], header->vers[3]?header->vers[3]:' '); |
| 838 |
printf("SIZE: %ld(0x%lx)\n", header->size, header->size); |
| 839 |
printf("PACK: %s\n", header->pack?"Yes":"No"); |
| 840 |
printf("PAGLEN: %ld\n", header->paglen); |
| 841 |
printf("PAGWIDTH: %ld\n", header->pagwidth); |
| 842 |
printf("DEBUG: %s\n", header->debug?"Yes":"No"); |
| 843 |
printf("DICT: %ld(0x%lx)\n", header->dict, header->dict); |
| 844 |
if (dumpdict) dumpDict(1, header->dict); |
| 845 |
printf("OATRS: %ld(0x%lx)\n", header->oatrs, header->oatrs); |
| 846 |
if (dumpatrs) dumpAtrs(1, header->oatrs); |
| 847 |
printf("LATRS: %ld(0x%lx)\n", header->latrs, header->latrs); |
| 848 |
if (dumpatrs) dumpAtrs(1, header->latrs); |
| 849 |
printf("AATRS: %ld(0x%lx)\n", header->aatrs, header->aatrs); |
| 850 |
if (dumpatrs) dumpAtrs(1, header->aatrs); |
| 851 |
printf("ACTS: %ld(0x%lx)\n", header->acts, header->acts); |
| 852 |
if (dumpacts) dumpActs(1, header->acts); |
| 853 |
printf("OBJS: %ld(0x%lx)\n", header->objs, header->objs); |
| 854 |
if (dumpobjs) dumpObjs(1, header->objs); |
| 855 |
printf("LOCS: %ld(0x%lx)\n", header->locs, header->locs); |
| 856 |
if (dumplocs) dumpLocs(1, header->locs); |
| 857 |
printf("STXS: %ld(0x%lx)\n", header->stxs, header->stxs); |
| 858 |
if (dumpstxs) dumpStxs(1, header->stxs); |
| 859 |
printf("VRBS: %ld(0x%lx)\n", header->vrbs, header->vrbs); |
| 860 |
if (dumpvrbs) dumpVrbs(1, header->vrbs); |
| 861 |
printf("EVTS: %ld(0x%lx)\n", header->evts, header->evts); |
| 862 |
printf("CNTS: %ld(0x%lx)\n", header->cnts, header->cnts); |
| 863 |
if (dumpcnts) dumpCnts(1, header->cnts); |
| 864 |
printf("RULS: %ld(0x%lx)\n", header->ruls, header->ruls); |
| 865 |
printf("INIT: %ld(0x%lx)\n", header->init, header->init); |
| 866 |
printf("START: %ld(0x%lx)\n", header->start, header->start); |
| 867 |
printf("MSGS: %ld(0x%lx)\n", header->msgs, header->msgs); |
| 868 |
printf("OBJ-MIN: %3ld MAX: %3ld\n", header->objmin, header->objmax); |
| 869 |
printf("ACT-MIN: %3ld MAX: %3ld\n", header->actmin, header->actmax); |
| 870 |
printf("CNT-MIN: %3ld MAX: %3ld\n", header->cntmin, header->cntmax); |
| 871 |
printf("LOC-MIN: %3ld MAX: %3ld\n", header->locmin, header->locmax); |
| 872 |
printf("DIR-MIN: %3ld MAX: %3ld\n", header->dirmin, header->dirmax); |
| 873 |
printf("EVT-MIN: %3ld MAX: %3ld\n", header->evtmin, header->evtmax); |
| 874 |
printf("RUL-MIN: %3ld MAX: %3ld\n", header->rulmin, header->rulmax); |
| 875 |
printf("MAXSCORE: %ld\n", header->maxscore); |
| 876 |
printf("SCORES: %ld(0x%lx)\n", header->scores, header->scores); |
| 877 |
printf("FREQ: %ld(0x%lx)\n", header->freq, header->freq); |
| 878 |
printf("ACDCRC: 0x%lx ", header->acdcrc); |
| 879 |
|
| 880 |
for (i = sizeof(*header)/sizeof(Aword); i < memTop; i++) { |
| 881 |
crc += memory[i]&0xff; |
| 882 |
crc += (memory[i]>>8)&0xff; |
| 883 |
crc += (memory[i]>>16)&0xff; |
| 884 |
crc += (memory[i]>>24)&0xff; |
| 885 |
} |
| 886 |
if (crc != header->acdcrc) |
| 887 |
printf("WARNING! Expected 0x%lx\n", crc); |
| 888 |
else |
| 889 |
printf("Ok.\n"); |
| 890 |
printf("TXTCRC: 0x%lx\n", header->txtcrc); |
| 891 |
if (dumpstms != 0) |
| 892 |
dumpStms(dumpstms); |
| 893 |
} |
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
static void load(char acdfnm[]) |
| 903 |
{ |
| 904 |
AcdHdr tmphdr; |
| 905 |
FILE *codfil; |
| 906 |
|
| 907 |
if ((codfil = fopen(acdfnm, "rb")) == NULL) { |
| 908 |
printf("Could not open ACD-file '%s'\n", acdfnm); |
| 909 |
exit(1); |
| 910 |
} |
| 911 |
|
| 912 |
fread(&tmphdr, sizeof(tmphdr), 1, codfil); |
| 913 |
rewind(codfil); |
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
#ifdef REVERSED |
| 918 |
reverseHdr(&tmphdr); |
| 919 |
#endif |
| 920 |
|
| 921 |
memory = malloc(tmphdr.size*sizeof(Aword)); |
| 922 |
header = (AcdHdr *) memory; |
| 923 |
|
| 924 |
memTop = fread(addrTo(0), sizeof(Aword), tmphdr.size, codfil); |
| 925 |
if (memTop != tmphdr.size) |
| 926 |
printf("WARNING! Could not read all ACD code."); |
| 927 |
|
| 928 |
#ifdef REVERSED |
| 929 |
printf("Hmm, this is a little-endian machine, please wait a moment while I fix byte ordering....\n"); |
| 930 |
reverseACD(0); |
| 931 |
printf("OK.\n"); |
| 932 |
#endif |
| 933 |
} |
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
#include "spa.h" |
| 938 |
|
| 939 |
|
| 940 |
static SPA_FUN(usage) |
| 941 |
{ |
| 942 |
printf("Usage: DUMPACD <acdfile> [-help] [options]\n"); |
| 943 |
} |
| 944 |
|
| 945 |
|
| 946 |
static SPA_ERRFUN(paramError) |
| 947 |
{ |
| 948 |
char *sevstr; |
| 949 |
|
| 950 |
switch (sev) { |
| 951 |
case 'E': sevstr = "error"; break; |
| 952 |
case 'W': sevstr = "warning"; break; |
| 953 |
default: sevstr = "internal error"; break; |
| 954 |
} |
| 955 |
printf("Parameter %s: %s, %s\n", sevstr, msg, add); |
| 956 |
usage(NULL, NULL, 0); |
| 957 |
exit(EXIT_FAILURE); |
| 958 |
} |
| 959 |
|
| 960 |
static SPA_FUN(extraArg) |
| 961 |
{ |
| 962 |
printf("Extra argument: '%s'\n", rawName); |
| 963 |
usage(NULL, NULL, 0); |
| 964 |
exit(EXIT_FAILURE); |
| 965 |
} |
| 966 |
|
| 967 |
static SPA_FUN(xit) {exit(EXIT_SUCCESS);} |
| 968 |
|
| 969 |
static SPA_DECLARE(arguments) |
| 970 |
SPA_STRING("acdfile", "file name of the ACD-file to dump", acdfnm, NULL, NULL) |
| 971 |
SPA_FUNCTION("", "extra argument", extraArg) |
| 972 |
SPA_END |
| 973 |
|
| 974 |
static SPA_DECLARE(options) |
| 975 |
SPA_HELP("help", "this help", usage, xit) |
| 976 |
SPA_FLAG("dict", "dump details on dictionary entries", dumpdict, FALSE, NULL) |
| 977 |
SPA_FLAG("atrs", "dump details on default attribute entries", dumpatrs, FALSE, NULL) |
| 978 |
SPA_FLAG("acts", "dump details on actor entries", dumpacts, FALSE, NULL) |
| 979 |
SPA_FLAG("objs", "dump details on object entries", dumpobjs, FALSE, NULL) |
| 980 |
SPA_FLAG("locs", "dump details on location entries", dumplocs, FALSE, NULL) |
| 981 |
SPA_FLAG("stxs", "dump details on syntax entries", dumpstxs, FALSE, NULL) |
| 982 |
SPA_FLAG("vrbs", "dump details on verb entries", dumpvrbs, FALSE, NULL) |
| 983 |
SPA_FLAG("evts", "dump details on event entries", dumpevts, FALSE, NULL) |
| 984 |
SPA_FLAG("cnts", "dump details on container entries", dumpcnts, FALSE, NULL) |
| 985 |
SPA_INTEGER("stms <address>", "dump statement opcodes starting at <address>", dumpstms, 0, NULL) |
| 986 |
SPA_END |
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
int main(int argc, char **argv) |
| 999 |
{ |
| 1000 |
int nArgs; |
| 1001 |
|
| 1002 |
nArgs = spaProcess(argc, argv, arguments, options, paramError); |
| 1003 |
if (nArgs == 0) { |
| 1004 |
usage(NULL, NULL, 0); |
| 1005 |
exit(EXIT_FAILURE); |
| 1006 |
} else if (nArgs > 1) |
| 1007 |
exit(EXIT_FAILURE); |
| 1008 |
|
| 1009 |
load(acdfnm); |
| 1010 |
dumpACD(); |
| 1011 |
exit(0); |
| 1012 |
} |