| 1 |
#ifdef RCSID |
| 2 |
static char RCSid[] = |
| 3 |
"$Header: d:/cvsroot/tads/TADS2/TDD.C,v 1.4 1999/07/11 00:46:30 MJRoberts Exp $"; |
| 4 |
#endif |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include <stdio.h> |
| 25 |
#include <stdarg.h> |
| 26 |
#include "os.h" |
| 27 |
#include "std.h" |
| 28 |
#include "trd.h" |
| 29 |
#include "err.h" |
| 30 |
#include "mch.h" |
| 31 |
#include "obj.h" |
| 32 |
#include "run.h" |
| 33 |
#include "voc.h" |
| 34 |
#include "bif.h" |
| 35 |
#include "dbg.h" |
| 36 |
#include "sup.h" |
| 37 |
#include "cmd.h" |
| 38 |
#include "fio.h" |
| 39 |
#include "prs.h" |
| 40 |
#include "tok.h" |
| 41 |
#include "emt.h" |
| 42 |
#include "ply.h" |
| 43 |
#include "oem.h" |
| 44 |
#include "cmap.h" |
| 45 |
#include "regex.h" |
| 46 |
|
| 47 |
|
| 48 |
static void tddlogerr(void *ctx, char *fac, int err, int argc, erradef *argv); |
| 49 |
|
| 50 |
|
| 51 |
static void tddptf(const char *fmt, ...) |
| 52 |
{ |
| 53 |
char buf[256]; |
| 54 |
va_list va; |
| 55 |
|
| 56 |
|
| 57 |
va_start(va, fmt); |
| 58 |
vsprintf(buf, fmt, va); |
| 59 |
va_end(va); |
| 60 |
|
| 61 |
|
| 62 |
os_printz(buf); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
static void tddusage_range(errcxdef *ec, int first_msg, int last_msg) |
| 67 |
{ |
| 68 |
int i; |
| 69 |
char buf[128]; |
| 70 |
|
| 71 |
for (i = first_msg ; i <= last_msg ; ++i) |
| 72 |
{ |
| 73 |
errmsg(ec, buf, (uint)sizeof(buf), i); |
| 74 |
tddptf("%s\n", buf); |
| 75 |
} |
| 76 |
|
| 77 |
errsig(ec, ERR_USAGE); |
| 78 |
} |
| 79 |
|
| 80 |
static void tddusage(errcxdef *ctx) |
| 81 |
{ |
| 82 |
if (ctx->errcxappctx != 0 && ctx->errcxappctx->usage_app_name != 0) |
| 83 |
{ |
| 84 |
char buf[128]; |
| 85 |
char buf2[128]; |
| 86 |
erradef argv[1]; |
| 87 |
|
| 88 |
|
| 89 |
errmsg(ctx, buf, (uint)sizeof(buf), ERR_TRUSPARM); |
| 90 |
|
| 91 |
|
| 92 |
argv[0].errastr = (char *)ctx->errcxappctx->usage_app_name;; |
| 93 |
errfmt(buf2, (int)sizeof(buf2), buf, 1, argv); |
| 94 |
|
| 95 |
|
| 96 |
tddptf("%s\n", buf2); |
| 97 |
|
| 98 |
|
| 99 |
tddusage_range(ctx, ERR_TDBUS1+1, ERR_TDBUSL); |
| 100 |
} |
| 101 |
else |
| 102 |
{ |
| 103 |
|
| 104 |
tddusage_range(ctx, ERR_TDBUS1, ERR_TDBUSL); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
static void tddusage_s(errcxdef *ctx) |
| 109 |
{ |
| 110 |
tddusage_range(ctx, ERR_TRSUS1, ERR_TRSUSL); |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
static void tddmain1(errcxdef *ec, int argc, char **argv, appctxdef *appctx, |
| 115 |
char *save_ext) |
| 116 |
{ |
| 117 |
osfildef *swapfp = (osfildef *)0; |
| 118 |
runcxdef runctx; |
| 119 |
bifcxdef bifctx; |
| 120 |
voccxdef vocctx; |
| 121 |
void (*bif[100])(struct bifcxdef *ctx, int argc); |
| 122 |
mcmcxdef *mctx; |
| 123 |
mcmcx1def *globalctx; |
| 124 |
dbgcxdef dbg; |
| 125 |
supcxdef supctx; |
| 126 |
char *swapname = 0; |
| 127 |
char swapbuf[OSFNMAX]; |
| 128 |
char **argp; |
| 129 |
char *arg; |
| 130 |
char *infile; |
| 131 |
char infile_abs[OSFNMAX]; |
| 132 |
char infile_path[OSFNMAX]; |
| 133 |
ulong swapsize = 0xffffffffL; |
| 134 |
int swapena = OS_DEFAULT_SWAP_ENABLED; |
| 135 |
int i; |
| 136 |
int pause = FALSE; |
| 137 |
fiolcxdef fiolctx; |
| 138 |
noreg int loadopen = FALSE; |
| 139 |
char inbuf[OSFNMAX]; |
| 140 |
ulong cachelimit = 0xffffffff; |
| 141 |
ushort undosiz = TDD_UNDOSIZ; |
| 142 |
objucxdef *undoptr; |
| 143 |
uint flags; |
| 144 |
objnum preinit; |
| 145 |
prscxdef *pctx; |
| 146 |
tokcxdef *tc; |
| 147 |
emtcxdef *ectx; |
| 148 |
uint heapsiz = TDD_HEAPSIZ; |
| 149 |
uint stksiz = TDD_STKSIZ; |
| 150 |
runsdef *mystack; |
| 151 |
uchar *myheap; |
| 152 |
uint lclsiz = TDD_LCLSIZ; |
| 153 |
uint poolsiz = TDD_POOLSIZ; |
| 154 |
int safety_read, safety_write; |
| 155 |
char *restore_file = 0; |
| 156 |
char *charmap = 0; |
| 157 |
int charmap_none = FALSE; |
| 158 |
|
| 159 |
NOREG((&loadopen)) |
| 160 |
|
| 161 |
|
| 162 |
out_init(); |
| 163 |
|
| 164 |
|
| 165 |
tc = tokcxini(ec, (mcmcxdef *)0, supsctab); |
| 166 |
tc->tokcxdbg = &dbg; |
| 167 |
tc->tokcxsst = (ushort (*)(void *))prsxsst; |
| 168 |
tc->tokcxsad = (void (*)(void *, char *, ushort))prsxsad; |
| 169 |
tc->tokcxsend = (void (*)(void *))prsxsend; |
| 170 |
|
| 171 |
|
| 172 |
tokaddinc(tc, "", 0); |
| 173 |
|
| 174 |
|
| 175 |
safety_read = safety_write = 2; |
| 176 |
|
| 177 |
|
| 178 |
for (i = 1, argp = argv + 1 ; i < argc ; ++argp, ++i) |
| 179 |
{ |
| 180 |
arg = *argp; |
| 181 |
if (*arg == '-') |
| 182 |
{ |
| 183 |
switch(*(arg+1)) |
| 184 |
{ |
| 185 |
case 'c': |
| 186 |
if (!strcmp(arg+1, "ctab-")) |
| 187 |
{ |
| 188 |
|
| 189 |
charmap_none = TRUE; |
| 190 |
} |
| 191 |
else if (!strcmp(arg+1, "ctab")) |
| 192 |
{ |
| 193 |
|
| 194 |
charmap = cmdarg(ec, &argp, &i, argc, 4, tddusage); |
| 195 |
} |
| 196 |
else |
| 197 |
tddusage(ec); |
| 198 |
break; |
| 199 |
|
| 200 |
case 'r': |
| 201 |
|
| 202 |
restore_file = cmdarg(ec, &argp, &i, argc, 1, tddusage); |
| 203 |
break; |
| 204 |
|
| 205 |
case 's': |
| 206 |
{ |
| 207 |
char *p; |
| 208 |
|
| 209 |
|
| 210 |
p = cmdarg(ec, &argp, &i, argc, 1, tddusage); |
| 211 |
|
| 212 |
|
| 213 |
if (*p == '?') |
| 214 |
tddusage_s(ec); |
| 215 |
|
| 216 |
|
| 217 |
safety_read = *p - '0'; |
| 218 |
safety_write = (*(p+1) != '\0' ? *(p+1) - '0' : |
| 219 |
safety_read); |
| 220 |
|
| 221 |
|
| 222 |
if (safety_read < 0 || safety_read > 4 |
| 223 |
|| safety_write < 0 || safety_write > 4) |
| 224 |
tddusage_s(ec); |
| 225 |
|
| 226 |
|
| 227 |
if (appctx != 0 && appctx->set_io_safety_level != 0) |
| 228 |
(*appctx->set_io_safety_level) |
| 229 |
(appctx->io_safety_level_ctx, |
| 230 |
safety_read, safety_write); |
| 231 |
} |
| 232 |
break; |
| 233 |
|
| 234 |
case 'm': |
| 235 |
switch(*(arg + 2)) |
| 236 |
{ |
| 237 |
case 's': |
| 238 |
stksiz = atoi(cmdarg(ec, &argp, &i, argc, 2, tddusage)); |
| 239 |
break; |
| 240 |
|
| 241 |
case 'h': |
| 242 |
heapsiz = atoi(cmdarg(ec, &argp, &i, argc, 2, tddusage)); |
| 243 |
break; |
| 244 |
|
| 245 |
case 'p': |
| 246 |
poolsiz = atoi(cmdarg(ec, &argp, &i, argc, 2, tddusage)); |
| 247 |
break; |
| 248 |
|
| 249 |
default: |
| 250 |
cachelimit = atol(cmdarg(ec, &argp, &i, argc, 1, |
| 251 |
tddusage)); |
| 252 |
break; |
| 253 |
} |
| 254 |
break; |
| 255 |
|
| 256 |
case 't': |
| 257 |
|
| 258 |
switch(*(arg+2)) |
| 259 |
{ |
| 260 |
case 'f': |
| 261 |
swapname = cmdarg(ec, &argp, &i, argc, 2, tddusage); |
| 262 |
break; |
| 263 |
|
| 264 |
case 's': |
| 265 |
swapsize = atol(cmdarg(ec, &argp, &i, argc, 2, tddusage)); |
| 266 |
break; |
| 267 |
|
| 268 |
default: |
| 269 |
swapena = cmdtog(ec, swapena, arg, 1, tddusage); |
| 270 |
break; |
| 271 |
} |
| 272 |
break; |
| 273 |
|
| 274 |
case 'u': |
| 275 |
undosiz = atoi(cmdarg(ec, &argp, &i, argc, 1, tddusage)); |
| 276 |
break; |
| 277 |
|
| 278 |
case 'i': |
| 279 |
{ |
| 280 |
char *path = cmdarg(ec, &argp, &i, argc, 1, tddusage); |
| 281 |
tokaddinc(tc, path, (int)strlen(path)); |
| 282 |
break; |
| 283 |
} |
| 284 |
|
| 285 |
default: |
| 286 |
tddusage(ec); |
| 287 |
} |
| 288 |
} |
| 289 |
else break; |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
if (i == argc) |
| 294 |
{ |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
infile = 0; |
| 301 |
if (restore_file != 0) |
| 302 |
{ |
| 303 |
|
| 304 |
if (fiorso_getgame(restore_file, inbuf, sizeof(inbuf))) |
| 305 |
{ |
| 306 |
|
| 307 |
infile = inbuf; |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
if (infile == 0 && appctx != 0 && appctx->get_game_name != 0 |
| 315 |
&& (*appctx->get_game_name)(appctx->get_game_name_ctx, |
| 316 |
inbuf, sizeof(inbuf))) |
| 317 |
{ |
| 318 |
|
| 319 |
infile = inbuf; |
| 320 |
} |
| 321 |
else |
| 322 |
{ |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
tddusage(ec); |
| 328 |
} |
| 329 |
} |
| 330 |
else |
| 331 |
{ |
| 332 |
|
| 333 |
infile = *argp; |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
if (i + 1 != argc) |
| 340 |
tddusage(ec); |
| 341 |
|
| 342 |
|
| 343 |
if (osfacc(infile)) |
| 344 |
{ |
| 345 |
strcpy(inbuf, infile); |
| 346 |
os_defext(inbuf, "gam"); |
| 347 |
infile = inbuf; |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
|
| 352 |
if (swapena && swapsize) |
| 353 |
{ |
| 354 |
swapfp = os_create_tempfile(swapname, swapbuf); |
| 355 |
if (swapname == 0) swapname = swapbuf; |
| 356 |
if (swapfp == 0) errsig(ec, ERR_OPSWAP); |
| 357 |
} |
| 358 |
|
| 359 |
|
| 360 |
if (charmap_none) |
| 361 |
cmap_override(); |
| 362 |
else if (cmap_load(charmap)) |
| 363 |
errsig(ec, ERR_INVCMAP); |
| 364 |
|
| 365 |
ERRBEGIN(ec) |
| 366 |
|
| 367 |
|
| 368 |
globalctx = mcmini(cachelimit, 128, swapsize, swapfp, 0, ec); |
| 369 |
mctx = mcmcini(globalctx, 128, fioldobj, &fiolctx, |
| 370 |
objrevert, (void *)0); |
| 371 |
mctx->mcmcxrvc = mctx; |
| 372 |
|
| 373 |
|
| 374 |
pctx = (prscxdef *)mchalo(ec, (sizeof(prscxdef) + poolsiz + |
| 375 |
lclsiz), "tcdmain"); |
| 376 |
pctx->prscxerr = ec; |
| 377 |
pctx->prscxtok = tc; |
| 378 |
pctx->prscxmem = mctx; |
| 379 |
pctx->prscxprp = 0; |
| 380 |
pctx->prscxext = 0; |
| 381 |
pctx->prscxnsiz = pctx->prscxrrst = poolsiz; |
| 382 |
pctx->prscxnrst = pctx->prscxpool; |
| 383 |
pctx->prscxplcl = &pctx->prscxpool[poolsiz]; |
| 384 |
pctx->prscxslcl = lclsiz; |
| 385 |
pctx->prscxflg = 0; |
| 386 |
pctx->prscxnode = &pctx->prscxpool[0]; |
| 387 |
pctx->prscxgtab = (toktdef *)0; |
| 388 |
pctx->prscxvoc = &vocctx; |
| 389 |
pctx->prscxcpp = (char *)0; |
| 390 |
pctx->prscxcps = 0; |
| 391 |
pctx->prscxcpf = 0; |
| 392 |
pctx->prscxfsp = (uchar *)0; |
| 393 |
pctx->prscxfsf = 0; |
| 394 |
pctx->prscxfss = 0; |
| 395 |
pctx->prscxstab = (toktdef *)0; |
| 396 |
|
| 397 |
tc->tokcxscx = (void *)pctx; |
| 398 |
|
| 399 |
|
| 400 |
ectx = (emtcxdef *)mchalo(ec, (sizeof(emtcxdef) + |
| 401 |
511*sizeof(emtldef)), "tcdmain"); |
| 402 |
ectx->emtcxerr = ec; |
| 403 |
ectx->emtcxmem = pctx->prscxmem; |
| 404 |
ectx->emtcxptr = 0; |
| 405 |
ectx->emtcxlcnt = 512; |
| 406 |
ectx->emtcxfrob = MCMONINV; |
| 407 |
emtlini(ectx); |
| 408 |
|
| 409 |
pctx->prscxemt = ectx; |
| 410 |
|
| 411 |
|
| 412 |
if (undosiz) |
| 413 |
undoptr = objuini(mctx, undosiz, vocdundo, vocdusz, &vocctx); |
| 414 |
else |
| 415 |
undoptr = (objucxdef *)0; |
| 416 |
|
| 417 |
|
| 418 |
vocini(&vocctx, ec, mctx, &runctx, undoptr, 50, 50, 100); |
| 419 |
|
| 420 |
|
| 421 |
mystack = (runsdef *)mchalo(ec, (stksiz * sizeof(runsdef)), |
| 422 |
"runtime stack"); |
| 423 |
myheap = mchalo(ec, heapsiz, "runtime heap"); |
| 424 |
|
| 425 |
|
| 426 |
os_get_abs_filename(infile_abs, sizeof(infile_abs), infile); |
| 427 |
os_get_path_name(infile_path, sizeof(infile_path), infile_abs); |
| 428 |
|
| 429 |
|
| 430 |
runctx.runcxerr = ec; |
| 431 |
runctx.runcxmem = mctx; |
| 432 |
runctx.runcxstk = mystack; |
| 433 |
runctx.runcxstop = &mystack[stksiz]; |
| 434 |
runctx.runcxsp = mystack; |
| 435 |
runctx.runcxbp = mystack; |
| 436 |
runctx.runcxheap = myheap; |
| 437 |
runctx.runcxhp = myheap; |
| 438 |
runctx.runcxhtop = &myheap[heapsiz]; |
| 439 |
runctx.runcxundo = undoptr; |
| 440 |
runctx.runcxbcx = &bifctx; |
| 441 |
runctx.runcxbi = bif; |
| 442 |
runctx.runcxtio = (tiocxdef *)0; |
| 443 |
runctx.runcxdbg = &dbg; |
| 444 |
runctx.runcxvoc = &vocctx; |
| 445 |
runctx.runcxdmd = supcont; |
| 446 |
runctx.runcxdmc = &supctx; |
| 447 |
runctx.runcxext = 0; |
| 448 |
runctx.runcxgamename = infile; |
| 449 |
runctx.runcxgamepath = infile_path; |
| 450 |
|
| 451 |
|
| 452 |
supctx.supcxerr = ec; |
| 453 |
supctx.supcxmem = mctx; |
| 454 |
supctx.supcxtab = (tokthdef *)0; |
| 455 |
supctx.supcxbuf = (uchar *)0; |
| 456 |
supctx.supcxlen = 0; |
| 457 |
supctx.supcxvoc = &vocctx; |
| 458 |
supctx.supcxrun = &runctx; |
| 459 |
|
| 460 |
|
| 461 |
dbg.dbgcxtio = (tiocxdef *)0; |
| 462 |
dbg.dbgcxmem = mctx; |
| 463 |
dbg.dbgcxerr = ec; |
| 464 |
dbg.dbgcxtab = (tokthdef *)0; |
| 465 |
dbg.dbgcxfcn = 0; |
| 466 |
dbg.dbgcxdep = 0; |
| 467 |
dbg.dbgcxflg = DBGCXFSS + DBGCXFOK; |
| 468 |
dbg.dbgcxprs = pctx; |
| 469 |
dbg.dbgcxrun = &runctx; |
| 470 |
dbg.dbgcxlin = (lindef *)0; |
| 471 |
dbg.dbgcxnams = 2048; |
| 472 |
dbg.dbgcxnam = (char *)mchalo(ec, dbg.dbgcxnams, "bp names"); |
| 473 |
dbg.dbgcxnamf = 0; |
| 474 |
dbg.dbgcxhstl = 4096; |
| 475 |
dbg.dbgcxhstf = 0; |
| 476 |
dbg.dbgcxui = 0; |
| 477 |
dbg.dbgcxhstp = (char *)mchalo(ec, dbg.dbgcxhstl, "history buf"); |
| 478 |
|
| 479 |
memset(dbg.dbgcxbp, 0, sizeof(dbg.dbgcxbp)); |
| 480 |
memset(dbg.dbgcxwx, 0, sizeof(dbg.dbgcxwx)); |
| 481 |
|
| 482 |
|
| 483 |
CLRSTRUCT(bifctx); |
| 484 |
bifctx.bifcxerr = ec; |
| 485 |
bifctx.bifcxrun = &runctx; |
| 486 |
bifctx.bifcxtio = (tiocxdef *)0; |
| 487 |
bifctx.bifcxrnd = 0; |
| 488 |
bifctx.bifcxrndset = FALSE; |
| 489 |
bifctx.bifcxappctx = appctx; |
| 490 |
bifctx.bifcxsafetyr = safety_read; |
| 491 |
bifctx.bifcxsafetyw = safety_write; |
| 492 |
bifctx.bifcxsavext = save_ext; |
| 493 |
|
| 494 |
|
| 495 |
re_init(&bifctx.bifcxregex, ec); |
| 496 |
|
| 497 |
ec->errcxlog = tddlogerr; |
| 498 |
ec->errcxlgc = &dbg; |
| 499 |
|
| 500 |
|
| 501 |
dbguini(&dbg, infile); |
| 502 |
|
| 503 |
|
| 504 |
fiord(mctx, &vocctx, (struct tokcxdef *)0, |
| 505 |
infile, (char *)0, &fiolctx, &preinit, &flags, |
| 506 |
tc->tokcxinc, (uchar **)0, (uint *)0, (uint *)0, FALSE, appctx, |
| 507 |
argv[0]); |
| 508 |
loadopen = TRUE; |
| 509 |
|
| 510 |
|
| 511 |
if (flags & FIOFCASE) |
| 512 |
tc->tokcxflg |= TOKCXCASEFOLD; |
| 513 |
else |
| 514 |
tc->tokcxflg &= ~TOKCXCASEFOLD; |
| 515 |
|
| 516 |
|
| 517 |
if ((flags & (FIOFSYM + FIOFLIN + FIOFPRE)) != |
| 518 |
(FIOFSYM + FIOFLIN + FIOFPRE)) |
| 519 |
errsig(ec, ERR_NODBG); |
| 520 |
|
| 521 |
|
| 522 |
suprsrv(&supctx, bif, &dbg.dbgcxtab->tokthsc, |
| 523 |
(int)(sizeof(bif)/sizeof(bif[0])), |
| 524 |
FALSE, (char *)0, tc->tokcxflg & TOKCXCASEFOLD); |
| 525 |
tc->tokcxstab = (toktdef *)dbg.dbgcxtab; |
| 526 |
|
| 527 |
|
| 528 |
dbguini2(&dbg); |
| 529 |
|
| 530 |
|
| 531 |
runistat(&vocctx, &runctx, (tiocxdef *)0); |
| 532 |
|
| 533 |
|
| 534 |
plygo(&runctx, &vocctx, (tiocxdef *)0, preinit, restore_file); |
| 535 |
|
| 536 |
if (pause) |
| 537 |
{ |
| 538 |
tddptf("[strike a key to exit]"); |
| 539 |
os_waitc(); |
| 540 |
tddptf("\n"); |
| 541 |
} |
| 542 |
|
| 543 |
|
| 544 |
fiorcls(&fiolctx); |
| 545 |
loadopen = FALSE; |
| 546 |
|
| 547 |
|
| 548 |
if (swapfp != 0) |
| 549 |
{ |
| 550 |
osfcls(swapfp); |
| 551 |
swapfp = (osfildef *)0; |
| 552 |
osfdel_temp(swapname); |
| 553 |
} |
| 554 |
|
| 555 |
|
| 556 |
dbguterm(&dbg); |
| 557 |
|
| 558 |
ERRCLEAN(ec) |
| 559 |
|
| 560 |
if (swapfp != 0) |
| 561 |
{ |
| 562 |
osfcls(swapfp); |
| 563 |
swapfp = (osfildef *)0; |
| 564 |
osfdel_temp(swapname); |
| 565 |
} |
| 566 |
|
| 567 |
|
| 568 |
if (loadopen) |
| 569 |
fiorcls(&fiolctx); |
| 570 |
|
| 571 |
|
| 572 |
dbguterm(&dbg); |
| 573 |
|
| 574 |
|
| 575 |
vocterm(&vocctx); |
| 576 |
|
| 577 |
|
| 578 |
if (undoptr != 0) |
| 579 |
objuterm(undoptr); |
| 580 |
|
| 581 |
|
| 582 |
mcmcterm(mctx); |
| 583 |
mcmterm(globalctx); |
| 584 |
|
| 585 |
ERRENDCLN(ec) |
| 586 |
|
| 587 |
|
| 588 |
vocterm(&vocctx); |
| 589 |
|
| 590 |
|
| 591 |
if (undoptr != 0) |
| 592 |
objuterm(undoptr); |
| 593 |
|
| 594 |
|
| 595 |
mcmcterm(mctx); |
| 596 |
mcmterm(globalctx); |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
static void tddlogerr(void *ctx, char *fac, int err, int argc, erradef *argv) |
| 601 |
{ |
| 602 |
char buf[512]; |
| 603 |
char msg[512]; |
| 604 |
|
| 605 |
errmsg(((dbgcxdef *)ctx)->dbgcxerr, msg, (uint)sizeof(msg), err); |
| 606 |
errfmt(buf, (int)sizeof(buf), msg, argc, argv); |
| 607 |
dbguerr((dbgcxdef *)ctx, err, buf); |
| 608 |
} |
| 609 |
|
| 610 |
|
| 611 |
static void tddlogerr1(void *ctx0, char *fac, int err, int argc, |
| 612 |
erradef *argv) |
| 613 |
{ |
| 614 |
errcxdef *ctx = (errcxdef *)ctx0; |
| 615 |
char buf[512]; |
| 616 |
char msg[512]; |
| 617 |
|
| 618 |
errmsg(ctx, msg, (uint)sizeof(msg), err); |
| 619 |
errfmt(buf, (int)sizeof(buf), msg, argc, argv); |
| 620 |
tddptf("%s-%d: %s\n", fac, err, buf); |
| 621 |
} |
| 622 |
|
| 623 |
|
| 624 |
int tddmain(int argc, char **argv, appctxdef *appctx, char *save_ext) |
| 625 |
{ |
| 626 |
errcxdef errctx; |
| 627 |
int err; |
| 628 |
osfildef *fp; |
| 629 |
|
| 630 |
errctx.errcxlog = tddlogerr1; |
| 631 |
errctx.errcxlgc = &errctx; |
| 632 |
errctx.errcxfp = (osfildef *)0; |
| 633 |
errctx.errcxofs = 0; |
| 634 |
errctx.errcxappctx = appctx; |
| 635 |
fp = oserrop(argv[0]); |
| 636 |
errini(&errctx, fp); |
| 637 |
|
| 638 |
|
| 639 |
tddptf("%s - A %s TADS %s Debugger.\n" |
| 640 |
"%sopyright (c) 1993, 2012 Michael J. Roberts\n", |
| 641 |
G_tads_oem_dbg_name, G_tads_oem_display_mode, TADS_RUNTIME_VERSION, |
| 642 |
G_tads_oem_copyright_prefix ? "TADS c" : "C"); |
| 643 |
tddptf("%s\n", G_tads_oem_author); |
| 644 |
|
| 645 |
|
| 646 |
tddptf(OS_TDB_STARTUP_MSG); |
| 647 |
|
| 648 |
ERRBEGIN(&errctx) |
| 649 |
tddmain1(&errctx, argc, argv, appctx, save_ext); |
| 650 |
ERRCATCH(&errctx, err) |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
if (err != ERR_USAGE && err != ERR_RUNQUIT) |
| 656 |
errclog(&errctx); |
| 657 |
|
| 658 |
|
| 659 |
if (errctx.errcxfp != 0) |
| 660 |
osfcls(errctx.errcxfp); |
| 661 |
|
| 662 |
|
| 663 |
return (err == ERR_RUNQUIT ? OSEXSUCC : OSEXFAIL); |
| 664 |
ERREND(&errctx) |
| 665 |
|
| 666 |
|
| 667 |
if (errctx.errcxfp != 0) |
| 668 |
osfcls(errctx.errcxfp); |
| 669 |
|
| 670 |
|
| 671 |
return OSEXSUCC; |
| 672 |
} |
| 673 |
|
| 674 |
|