| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#include <stdio.h> |
| 10 |
#include <ctype.h> |
| 11 |
|
| 12 |
#include "types.h" |
| 13 |
#ifdef HAVE_SHORT_FILENAMES |
| 14 |
#include "av.h" |
| 15 |
#else |
| 16 |
#include "alan.version.h" |
| 17 |
#endif |
| 18 |
|
| 19 |
|
| 20 |
#ifdef USE_READLINE |
| 21 |
#include "readline.h" |
| 22 |
#endif |
| 23 |
|
| 24 |
|
| 25 |
#include "inter.h" |
| 26 |
#include "main.h" |
| 27 |
#include "parse.h" |
| 28 |
#include "exe.h" |
| 29 |
|
| 30 |
#include "debug.h" |
| 31 |
|
| 32 |
#ifdef GLK |
| 33 |
#include "glkio.h" |
| 34 |
#endif |
| 35 |
|
| 36 |
#ifdef _PROTOTYPES_ |
| 37 |
static void showatrs( |
| 38 |
Aword atradr |
| 39 |
) |
| 40 |
#else |
| 41 |
static void showatrs(atradr) |
| 42 |
Aword atradr; |
| 43 |
#endif |
| 44 |
{ |
| 45 |
AtrElem *at; |
| 46 |
int i; |
| 47 |
char str[80]; |
| 48 |
|
| 49 |
if (atradr == 0) return; |
| 50 |
|
| 51 |
i = 1; |
| 52 |
for (at = (AtrElem *) addrTo(atradr); !endOfTable(at); at++) { |
| 53 |
sprintf(str, "$i%3ld: %ld (%s)", (long) i, (unsigned long) at->val, (char *) addrTo(at->stradr)); |
| 54 |
#if ISO == 0 |
| 55 |
fromIso(str, str); |
| 56 |
#endif |
| 57 |
output(str); |
| 58 |
i++; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
#ifdef _PROTOTYPES_ |
| 64 |
static void showobjs(void) |
| 65 |
#else |
| 66 |
static void showobjs() |
| 67 |
#endif |
| 68 |
{ |
| 69 |
char str[80]; |
| 70 |
int obj; |
| 71 |
|
| 72 |
output("OBJECTS:"); |
| 73 |
for (obj = OBJMIN; obj <= OBJMAX; obj++) { |
| 74 |
sprintf(str, "$i%3ld: ", (long) obj); |
| 75 |
output(str); |
| 76 |
say(obj); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
#ifdef _PROTOTYPES_ |
| 82 |
static void showobj( |
| 83 |
int obj |
| 84 |
) |
| 85 |
#else |
| 86 |
static void showobj(obj) |
| 87 |
int obj; |
| 88 |
#endif |
| 89 |
{ |
| 90 |
char str[80]; |
| 91 |
#define OBJ (obj-OBJMIN) |
| 92 |
|
| 93 |
|
| 94 |
if (!isObj(obj)) { |
| 95 |
sprintf(str, "Object number out of range. Between %ld and %ld, please.", (unsigned long) OBJMIN, (unsigned long) OBJMAX); |
| 96 |
output(str); |
| 97 |
return; |
| 98 |
} |
| 99 |
|
| 100 |
sprintf(str, "OBJECT %d :", obj); |
| 101 |
output(str); |
| 102 |
say(obj); |
| 103 |
|
| 104 |
sprintf(str, "$iLocation = %ld", (unsigned long) where(obj)); |
| 105 |
output(str); |
| 106 |
if (isLoc(objs[OBJ].loc)) |
| 107 |
say(objs[OBJ].loc); |
| 108 |
else if (isCnt(objs[OBJ].loc)) { |
| 109 |
if (isObj(objs[OBJ].loc)) { |
| 110 |
output("in"); |
| 111 |
say(objs[OBJ].loc); |
| 112 |
} else if (isAct(objs[OBJ].loc)) { |
| 113 |
output("carried by"); |
| 114 |
say(objs[OBJ].loc); |
| 115 |
} else |
| 116 |
interpret(cnts[objs[OBJ].loc-CNTMIN].nam); |
| 117 |
} else if (objs[OBJ].loc == 0) |
| 118 |
output("nowhere"); |
| 119 |
else |
| 120 |
output("Illegal location!"); |
| 121 |
|
| 122 |
|
| 123 |
output("$iAttributes ="); |
| 124 |
showatrs(objs[OBJ].atrs); |
| 125 |
|
| 126 |
#undef OBJ |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
#ifdef _PROTOTYPES_ |
| 131 |
static void showcnts(void) |
| 132 |
#else |
| 133 |
static void showcnts() |
| 134 |
#endif |
| 135 |
{ |
| 136 |
char str[80]; |
| 137 |
int cnt; |
| 138 |
#define CNT (cnt-CNTMIN) |
| 139 |
|
| 140 |
output("CONTAINERS:"); |
| 141 |
for (cnt = CNTMIN; cnt <= CNTMAX; cnt++) { |
| 142 |
sprintf(str, "$i%3ld: ", (long) cnt); |
| 143 |
output(str); |
| 144 |
if (cnts[CNT].nam != 0) |
| 145 |
interpret(cnts[CNT].nam); |
| 146 |
if (cnts[CNT].parent != 0) |
| 147 |
say(cnts[CNT].parent); |
| 148 |
} |
| 149 |
|
| 150 |
#undef CNT |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
#ifdef _PROTOTYPES_ |
| 155 |
static void showcnt( |
| 156 |
int cnt |
| 157 |
) |
| 158 |
#else |
| 159 |
static void showcnt(cnt) |
| 160 |
int cnt; |
| 161 |
#endif |
| 162 |
{ |
| 163 |
char str[80]; |
| 164 |
int i; |
| 165 |
Abool found = FALSE; |
| 166 |
#define CNT (cnt-CNTMIN) |
| 167 |
|
| 168 |
if (cnt < CNTMIN || cnt > CNTMAX) { |
| 169 |
sprintf(str, "Container number out of range. Between %ld and %ld, please.", (unsigned long) CNTMIN, (unsigned long) CNTMAX); |
| 170 |
output(str); |
| 171 |
return; |
| 172 |
} |
| 173 |
|
| 174 |
sprintf(str, "CONTAINER %d :", cnt); |
| 175 |
output(str); |
| 176 |
if (cnts[CNT].nam != 0) |
| 177 |
interpret(cnts[CNT].nam); |
| 178 |
if (cnts[CNT].parent != 0) { |
| 179 |
cnt = cnts[CNT].parent; |
| 180 |
say(cnt); |
| 181 |
sprintf(str, "$iLocation = %ld", (unsigned long) where(cnt)); |
| 182 |
output(str); |
| 183 |
} |
| 184 |
output("$iContains "); |
| 185 |
for (i = OBJMIN; i <= OBJMAX; i++) { |
| 186 |
if (in(i, cnt)) { |
| 187 |
if (!found) { |
| 188 |
output("$n"); |
| 189 |
found = TRUE; |
| 190 |
} |
| 191 |
sprintf(str, "$t$t%d: ", i); |
| 192 |
output(str); |
| 193 |
say(i); |
| 194 |
} |
| 195 |
} |
| 196 |
if (!found) |
| 197 |
output("nothing"); |
| 198 |
|
| 199 |
#undef CNT |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
#ifdef _PROTOTYPES_ |
| 204 |
static void showlocs(void) |
| 205 |
#else |
| 206 |
static void showlocs() |
| 207 |
#endif |
| 208 |
{ |
| 209 |
char str[80]; |
| 210 |
int loc; |
| 211 |
|
| 212 |
output("LOCATIONS:"); |
| 213 |
for (loc = LOCMIN; loc <= LOCMAX; loc++) { |
| 214 |
sprintf(str, "$i%3ld: ", (long) loc); |
| 215 |
output(str); |
| 216 |
say(loc); |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
#ifdef _PROTOTYPES_ |
| 222 |
static void showloc( |
| 223 |
int loc |
| 224 |
) |
| 225 |
#else |
| 226 |
static void showloc(loc) |
| 227 |
int loc; |
| 228 |
#endif |
| 229 |
{ |
| 230 |
char str[80]; |
| 231 |
|
| 232 |
|
| 233 |
if (!isLoc(loc)) { |
| 234 |
sprintf(str, "Location number out of range. Between %ld and %ld, please.", (unsigned long) LOCMIN, (unsigned long) LOCMAX); |
| 235 |
output(str); |
| 236 |
return; |
| 237 |
} |
| 238 |
|
| 239 |
sprintf(str, "LOCATION %d :", loc); |
| 240 |
output(str); |
| 241 |
say(loc); |
| 242 |
|
| 243 |
output("$iAttributes ="); |
| 244 |
showatrs(locs[loc-LOCMIN].atrs); |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
#ifdef _PROTOTYPES_ |
| 249 |
static void showacts(void) |
| 250 |
#else |
| 251 |
static void showacts() |
| 252 |
#endif |
| 253 |
{ |
| 254 |
char str[80]; |
| 255 |
int act; |
| 256 |
|
| 257 |
output("ACTORS:"); |
| 258 |
for (act = ACTMIN; act <= ACTMAX; act++) { |
| 259 |
sprintf(str, "$i%3ld:", (long) act); |
| 260 |
output(str); |
| 261 |
say(act); |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
#ifdef _PROTOTYPES_ |
| 267 |
static void showact( |
| 268 |
int act |
| 269 |
) |
| 270 |
#else |
| 271 |
static void showact(act) |
| 272 |
int act; |
| 273 |
#endif |
| 274 |
{ |
| 275 |
char str[80]; |
| 276 |
Boolean oldstp; |
| 277 |
|
| 278 |
if (!isAct(act)) { |
| 279 |
sprintf(str, "Actor number out of range. Between %ld and %ld, please.", (unsigned long) ACTMIN, (unsigned long) ACTMAX); |
| 280 |
output(str); |
| 281 |
return; |
| 282 |
} |
| 283 |
|
| 284 |
sprintf(str, "ACTOR %d :", act); |
| 285 |
output(str); |
| 286 |
oldstp = stpflg; stpflg = FALSE; |
| 287 |
say(act); |
| 288 |
stpflg = oldstp; |
| 289 |
|
| 290 |
sprintf(str, "$iLocation = %ld", (unsigned long) acts[act-ACTMIN].loc); |
| 291 |
output(str); |
| 292 |
if (isLoc(acts[act-ACTMIN].loc)) |
| 293 |
say(acts[act-ACTMIN].loc); |
| 294 |
else if (acts[act-ACTMIN].loc == 0) |
| 295 |
output("nowhere"); |
| 296 |
else |
| 297 |
output("Illegal location!"); |
| 298 |
|
| 299 |
sprintf(str, "$iScript = %ld", (unsigned long) acts[act-ACTMIN].script); |
| 300 |
output(str); |
| 301 |
|
| 302 |
sprintf(str, "$iStep = %ld", (unsigned long) acts[act-ACTMIN].step); |
| 303 |
output(str); |
| 304 |
|
| 305 |
output("$iAttributes ="); |
| 306 |
showatrs(acts[act-ACTMIN].atrs); |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
#ifdef _PROTOTYPES_ |
| 311 |
static void showevts(void) |
| 312 |
#else |
| 313 |
static void showevts() |
| 314 |
#endif |
| 315 |
{ |
| 316 |
int evt, i; |
| 317 |
char str[80]; |
| 318 |
Boolean scheduled; |
| 319 |
|
| 320 |
output("EVENTS:"); |
| 321 |
for (evt = EVTMIN; evt <= EVTMAX; evt++) { |
| 322 |
sprintf(str, "$i%d (%s):", evt, (char *)addrTo(evts[evt-EVTMIN].stradr)); |
| 323 |
#if ISO == 0 |
| 324 |
fromIso(str, str); |
| 325 |
#endif |
| 326 |
output(str); |
| 327 |
scheduled = FALSE; |
| 328 |
for (i = 0; i < etop; i++) |
| 329 |
if ((scheduled = (eventq[i].event == evt))) |
| 330 |
break; |
| 331 |
if (scheduled) { |
| 332 |
sprintf(str, "Scheduled for +%d, at ", eventq[i].time-cur.tick); |
| 333 |
output(str); |
| 334 |
say(eventq[i].where); |
| 335 |
} else |
| 336 |
output("Not scheduled."); |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
static Boolean trc, stp; |
| 342 |
static int loc; |
| 343 |
|
| 344 |
#ifdef _PROTOTYPES_ |
| 345 |
void saveInfo(void) |
| 346 |
#else |
| 347 |
void saveInfo() |
| 348 |
#endif |
| 349 |
{ |
| 350 |
|
| 351 |
trc = trcflg; trcflg = FALSE; |
| 352 |
stp = stpflg; stpflg = FALSE; |
| 353 |
loc = cur.loc; cur.loc = where(HERO); |
| 354 |
} |
| 355 |
|
| 356 |
#ifdef _PROTOTYPES_ |
| 357 |
void restoreInfo(void) |
| 358 |
#else |
| 359 |
void restoreInfo() |
| 360 |
#endif |
| 361 |
{ |
| 362 |
|
| 363 |
trcflg = trc; |
| 364 |
stpflg = stp; |
| 365 |
cur.loc = loc; |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
#ifdef _PROTOTYPES_ |
| 370 |
void debug(void) |
| 371 |
#else |
| 372 |
void debug() |
| 373 |
#endif |
| 374 |
{ |
| 375 |
char buf[256]; |
| 376 |
char c; |
| 377 |
int i; |
| 378 |
|
| 379 |
saveInfo(); |
| 380 |
while (TRUE) { |
| 381 |
if (anyOutput) |
| 382 |
para(); |
| 383 |
do { |
| 384 |
output("ABUG> "); |
| 385 |
#ifdef USE_READLINE |
| 386 |
(void) readline(buf); |
| 387 |
#else |
| 388 |
fgets(buf, 255, stdin); |
| 389 |
#endif |
| 390 |
lin = 1; |
| 391 |
c = buf[0]; |
| 392 |
i = 0; |
| 393 |
sscanf(&buf[1], "%d", &i); |
| 394 |
} while (c == '\0'); |
| 395 |
|
| 396 |
switch (toUpper(c)) { |
| 397 |
case 'H': |
| 398 |
case '?': |
| 399 |
output(alan.longHeader); |
| 400 |
output("$nABUG Commands:\ |
| 401 |
$iO [n] -- show object[s]\ |
| 402 |
$iA [n] -- show actor[s]\ |
| 403 |
$iL [n] -- show location[s]\ |
| 404 |
$iC [n] -- show container[s]\ |
| 405 |
$iE -- show events\ |
| 406 |
$iG -- go on\ |
| 407 |
$iT -- toggle trace mode\ |
| 408 |
$iS -- toggle step mode\ |
| 409 |
$iX -- exit debug mode\ |
| 410 |
$iQ -- quit game"); |
| 411 |
break; |
| 412 |
case 'Q': |
| 413 |
terminate(0); |
| 414 |
case 'X': |
| 415 |
dbgflg = FALSE; |
| 416 |
case 'G': |
| 417 |
restoreInfo(); |
| 418 |
return; |
| 419 |
case 'O': |
| 420 |
if (i == 0) |
| 421 |
showobjs(); |
| 422 |
else |
| 423 |
showobj(i); |
| 424 |
break; |
| 425 |
case 'C': |
| 426 |
if (i == 0) |
| 427 |
showcnts(); |
| 428 |
else |
| 429 |
showcnt(i); |
| 430 |
break; |
| 431 |
case 'A': |
| 432 |
if (i == 0) |
| 433 |
showacts(); |
| 434 |
else |
| 435 |
showact(i); |
| 436 |
break; |
| 437 |
case 'L': |
| 438 |
if (i == 0) |
| 439 |
showlocs(); |
| 440 |
else |
| 441 |
showloc(i); |
| 442 |
break; |
| 443 |
case 'E': |
| 444 |
showevts(); |
| 445 |
break; |
| 446 |
case 'S': |
| 447 |
if ((stp = !stp)) |
| 448 |
printf("Step on."); |
| 449 |
else |
| 450 |
printf("Step off."); |
| 451 |
break; |
| 452 |
case 'T': |
| 453 |
if ((trc = !trc)) |
| 454 |
printf("Trace on."); |
| 455 |
else |
| 456 |
printf("Trace off."); |
| 457 |
break; |
| 458 |
default: |
| 459 |
output("Unknown ABUG command. ? for help."); |
| 460 |
break; |
| 461 |
} |
| 462 |
} |
| 463 |
} |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
#ifdef _PROTOTYPES_ |
| 475 |
void debugsay(int item) |
| 476 |
#else |
| 477 |
void debugsay(item) |
| 478 |
int item; |
| 479 |
#endif |
| 480 |
{ |
| 481 |
saveInfo(); |
| 482 |
needsp = FALSE; |
| 483 |
col = 1; |
| 484 |
if (item == 0) |
| 485 |
printf("$null$"); |
| 486 |
else |
| 487 |
say(item); |
| 488 |
needsp = FALSE; |
| 489 |
col = 1; |
| 490 |
restoreInfo(); |
| 491 |
} |