| 1 |
#ifdef RCSID |
| 2 |
static char RCSid[] = |
| 3 |
"$Header: d:/cvsroot/tads/TADS2/TCD.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 |
|
| 25 |
|
| 26 |
#include <stdio.h> |
| 27 |
#include <string.h> |
| 28 |
#include <time.h> |
| 29 |
#include <ctype.h> |
| 30 |
#include <stdarg.h> |
| 31 |
#include "os.h" |
| 32 |
#include "std.h" |
| 33 |
#include "lin.h" |
| 34 |
#include "linf.h" |
| 35 |
#include "err.h" |
| 36 |
#include "tok.h" |
| 37 |
#include "mch.h" |
| 38 |
#include "mcm.h" |
| 39 |
#include "prs.h" |
| 40 |
#include "emt.h" |
| 41 |
#include "opc.h" |
| 42 |
#include "run.h" |
| 43 |
#include "voc.h" |
| 44 |
#include "bif.h" |
| 45 |
#include "dbg.h" |
| 46 |
#include "sup.h" |
| 47 |
#include "cmd.h" |
| 48 |
#include "fio.h" |
| 49 |
#include "oem.h" |
| 50 |
#include "cmap.h" |
| 51 |
#include "tcg.h" |
| 52 |
|
| 53 |
|
| 54 |
#include "tcd.h" |
| 55 |
|
| 56 |
|
| 57 |
int dbgpresent() |
| 58 |
{ |
| 59 |
return FALSE; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
void trchid() {} |
| 64 |
void trcsho() {} |
| 65 |
|
| 66 |
int dbgu_err_resume(dbgcxdef *ctx) |
| 67 |
{ |
| 68 |
VARUSED(ctx); |
| 69 |
return FALSE; |
| 70 |
} |
| 71 |
|
| 72 |
void dbguquitting(dbgcxdef *ctx) |
| 73 |
{ |
| 74 |
VARUSED(ctx); |
| 75 |
} |
| 76 |
|
| 77 |
int dbgu_find_src(const char *origname, int origlen, |
| 78 |
char *fullname, size_t full_len, int must_find_file) |
| 79 |
{ |
| 80 |
VARUSED(origname); |
| 81 |
VARUSED(origlen); |
| 82 |
VARUSED(fullname); |
| 83 |
VARUSED(full_len); |
| 84 |
VARUSED(must_find_file); |
| 85 |
|
| 86 |
|
| 87 |
return FALSE; |
| 88 |
} |
| 89 |
|
| 90 |
struct runsdef *dbgfrfind(dbgcxdef *ctx, objnum frobj, uint frofs) |
| 91 |
{ |
| 92 |
VARUSED(frobj); |
| 93 |
VARUSED(frofs); |
| 94 |
errsig(ctx->dbgcxerr, ERR_INACTFR); |
| 95 |
return 0; |
| 96 |
} |
| 97 |
|
| 98 |
void dbgss(struct dbgcxdef *ctx, uint ofs, int instr, int err, |
| 99 |
uchar *noreg *instrp) |
| 100 |
{ |
| 101 |
VARUSED(ctx); |
| 102 |
VARUSED(ofs); |
| 103 |
VARUSED(instr); |
| 104 |
VARUSED(err); |
| 105 |
return; |
| 106 |
} |
| 107 |
|
| 108 |
int dbgstart(struct dbgcxdef *ctx) |
| 109 |
{ |
| 110 |
VARUSED(ctx); |
| 111 |
return(TRUE); |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
void vocinialo(voccxdef *ctx, vocddef **what, int cnt) |
| 117 |
{ |
| 118 |
VARUSED(ctx); |
| 119 |
VARUSED(what); |
| 120 |
VARUSED(cnt); |
| 121 |
} |
| 122 |
|
| 123 |
void vocremfd(voccxdef *ctx, vocddef *what, objnum func, prpnum prop, |
| 124 |
runsdef *val, int err) |
| 125 |
{ |
| 126 |
VARUSED(ctx); |
| 127 |
VARUSED(what); |
| 128 |
VARUSED(func); |
| 129 |
VARUSED(prop); |
| 130 |
VARUSED(val); |
| 131 |
VARUSED(err); |
| 132 |
} |
| 133 |
|
| 134 |
void vocsetfd(voccxdef *ctx, vocddef *what, objnum func, prpnum prop, |
| 135 |
uint tm, runsdef *val, int err) |
| 136 |
{ |
| 137 |
VARUSED(ctx); |
| 138 |
VARUSED(what); |
| 139 |
VARUSED(func); |
| 140 |
VARUSED(prop); |
| 141 |
VARUSED(tm); |
| 142 |
VARUSED(val); |
| 143 |
VARUSED(err); |
| 144 |
} |
| 145 |
|
| 146 |
void vocturn(voccxdef *ctx, int cnt, int do_fuses) |
| 147 |
{ |
| 148 |
VARUSED(ctx); |
| 149 |
VARUSED(cnt); |
| 150 |
VARUSED(do_fuses); |
| 151 |
} |
| 152 |
|
| 153 |
void vocdmnclr(voccxdef *ctx) |
| 154 |
{ |
| 155 |
VARUSED(ctx); |
| 156 |
} |
| 157 |
|
| 158 |
int voclistlen(vocoldef *lst) |
| 159 |
{ |
| 160 |
VARUSED(lst); |
| 161 |
return 0; |
| 162 |
} |
| 163 |
|
| 164 |
void exedaem(voccxdef *ctx) |
| 165 |
{ |
| 166 |
VARUSED(ctx); |
| 167 |
} |
| 168 |
|
| 169 |
int exefuse(voccxdef *ctx, int do_run) |
| 170 |
{ |
| 171 |
VARUSED(ctx); |
| 172 |
VARUSED(do_run); |
| 173 |
return FALSE; |
| 174 |
} |
| 175 |
|
| 176 |
int execmd_recurs(voccxdef *ctx, objnum actor, objnum verb, |
| 177 |
objnum dobj, objnum prep, objnum iobj, |
| 178 |
int validate_dobj, int validate_iobj) |
| 179 |
{ |
| 180 |
VARUSED(ctx); |
| 181 |
VARUSED(actor); |
| 182 |
VARUSED(verb); |
| 183 |
VARUSED(dobj); |
| 184 |
VARUSED(prep); |
| 185 |
VARUSED(iobj); |
| 186 |
return 0; |
| 187 |
} |
| 188 |
|
| 189 |
void voc_parse_tok(voccxdef *ctx) { VARUSED(ctx); } |
| 190 |
void voc_parse_types(voccxdef *ctx) { VARUSED(ctx); } |
| 191 |
void voc_parse_dict_lookup(voccxdef *ctx) { VARUSED(ctx); } |
| 192 |
void voc_parse_np(voccxdef *ctx) { VARUSED(ctx); } |
| 193 |
void voc_parse_disambig(voccxdef *ctx) { VARUSED(ctx); } |
| 194 |
void voc_parse_replace_cmd(voccxdef *ctx) { VARUSED(ctx); } |
| 195 |
void voc_push_objlist(voccxdef *ctx, objnum objlist[], int cnt) |
| 196 |
{ |
| 197 |
VARUSED(ctx); |
| 198 |
VARUSED(objlist); |
| 199 |
VARUSED(cnt); |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
FILE *scrfp; |
| 204 |
int scrquiet; |
| 205 |
|
| 206 |
char *qasgets(char *buf, int bufl) |
| 207 |
{ |
| 208 |
VARUSED(buf); |
| 209 |
return((char *)0); |
| 210 |
} |
| 211 |
|
| 212 |
void qasclose(void) |
| 213 |
{ |
| 214 |
} |
| 215 |
|
| 216 |
void vocdusave_newobj(voccxdef *ctx, objnum objn) {} |
| 217 |
void vocdusave_delobj(voccxdef *ctx, objnum objn) {} |
| 218 |
void vocdusave_addwrd(voccxdef *ctx, objnum objn, prpnum typ, int flags, |
| 219 |
char *wrd) {} |
| 220 |
void vocdusave_delwrd(voccxdef *ctx, objnum objn, prpnum typ, int flags, |
| 221 |
char *wrd) {} |
| 222 |
void vocdusave_me(voccxdef *ctx, objnum old_me) {} |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
void runstat(void) |
| 229 |
{ |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
static void tcdptf(const char *fmt, ...) |
| 234 |
{ |
| 235 |
char buf[256]; |
| 236 |
va_list va; |
| 237 |
|
| 238 |
|
| 239 |
va_start(va, fmt); |
| 240 |
vsprintf(buf, fmt, va); |
| 241 |
va_end(va); |
| 242 |
|
| 243 |
|
| 244 |
os_printz(buf); |
| 245 |
} |
| 246 |
|
| 247 |
static void tcduspt(errcxdef *ec, int first, int last) |
| 248 |
{ |
| 249 |
int i; |
| 250 |
char buf[128]; |
| 251 |
|
| 252 |
for (i = first ; i <= last ; ++i) |
| 253 |
{ |
| 254 |
errmsg(ec, buf, (uint)sizeof(buf), i); |
| 255 |
tcdptf("%s\n", buf); |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
static void tcdtogusage(errcxdef *ec) |
| 260 |
{ |
| 261 |
tcduspt(ec, ERR_TCTGUS1, ERR_TCTGUSL); |
| 262 |
} |
| 263 |
|
| 264 |
static void tcdusage(errcxdef *ec) |
| 265 |
{ |
| 266 |
tcduspt(ec, ERR_TCUS1, ERR_TCUSL); |
| 267 |
tcdtogusage(ec); |
| 268 |
errsig(ec, ERR_USAGE); |
| 269 |
} |
| 270 |
|
| 271 |
static void tcdzusage(errcxdef *ec) |
| 272 |
{ |
| 273 |
tcduspt(ec, ERR_TCZUS1, ERR_TCZUSL); |
| 274 |
tcdtogusage(ec); |
| 275 |
errsig(ec, ERR_USAGE); |
| 276 |
} |
| 277 |
|
| 278 |
static void tcd1usage(errcxdef *ec) |
| 279 |
{ |
| 280 |
tcduspt(ec, ERR_TC1US1, ERR_TC1USL); |
| 281 |
tcdtogusage(ec); |
| 282 |
errsig(ec, ERR_USAGE); |
| 283 |
} |
| 284 |
|
| 285 |
static void tcdmusage(errcxdef *ec) |
| 286 |
{ |
| 287 |
tcduspt(ec, ERR_TCMUS1, ERR_TCMUSL); |
| 288 |
errsig(ec, ERR_USAGE); |
| 289 |
} |
| 290 |
|
| 291 |
static void tcdvusage(errcxdef *ec) |
| 292 |
{ |
| 293 |
tcduspt(ec, ERR_TCVUS1, ERR_TCVUSL); |
| 294 |
errsig(ec, ERR_USAGE); |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
typedef struct tcdchkctx |
| 299 |
{ |
| 300 |
mcmcxdef *mem; |
| 301 |
errcxdef *ec; |
| 302 |
int cnt; |
| 303 |
} tcdchkctx; |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
static void tcdchkundef(void *ctx0, toksdef *t) |
| 309 |
{ |
| 310 |
tcdchkctx *ctx = (tcdchkctx *)ctx0; |
| 311 |
int err; |
| 312 |
|
| 313 |
switch(t->tokstyp) |
| 314 |
{ |
| 315 |
case TOKSTFWDOBJ: |
| 316 |
|
| 317 |
err = ERR_UNDEFO; |
| 318 |
goto log_the_error; |
| 319 |
|
| 320 |
case TOKSTFWDFN: |
| 321 |
|
| 322 |
err = ERR_UNDEFF; |
| 323 |
|
| 324 |
log_the_error: |
| 325 |
|
| 326 |
sup_log_undefobj(ctx->mem, ctx->ec, err, |
| 327 |
t->toksnam, (int)t->tokslen, (objnum)t->toksval); |
| 328 |
|
| 329 |
|
| 330 |
++(ctx->cnt); |
| 331 |
break; |
| 332 |
|
| 333 |
default: |
| 334 |
|
| 335 |
break; |
| 336 |
} |
| 337 |
} |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
struct tcderrdef |
| 344 |
{ |
| 345 |
FILE *tcderrfil; |
| 346 |
tokcxdef *tcderrtok; |
| 347 |
int tcderrlvl; |
| 348 |
int tcderrcnt; |
| 349 |
int tcdwrncnt; |
| 350 |
int tcdfatal; |
| 351 |
char tcdwrn_AMBIGBIN; |
| 352 |
}; |
| 353 |
typedef struct tcderrdef tcderrdef; |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
static char vsn_major[] = "2"; |
| 362 |
static char vsn_minor[] = "5"; |
| 363 |
static char vsn_maint[] = "17"; |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
#ifndef TCD_SETTINGS_DEFINED |
| 370 |
# define TCD_POOLSIZ (6 * 1024) |
| 371 |
# define TCD_LCLSIZ 2048 |
| 372 |
# define TCD_HEAPSIZ 4096 |
| 373 |
# define TCD_STKSIZ 50 |
| 374 |
# define TCD_LABSIZ 1024 |
| 375 |
#endif |
| 376 |
|
| 377 |
|
| 378 |
static int ex_pause = FALSE; |
| 379 |
|
| 380 |
|
| 381 |
static void tcdmain1(errcxdef *ec, int argc, char *argv[], tcderrdef *errcbcx, |
| 382 |
char *save_ext) |
| 383 |
{ |
| 384 |
tokcxdef *tc; |
| 385 |
prscxdef *pctx; |
| 386 |
osfildef *swapfp = (osfildef *)0; |
| 387 |
emtcxdef *ectx; |
| 388 |
tokthdef symtab; |
| 389 |
toktldef labtab; |
| 390 |
runcxdef runctx; |
| 391 |
bifcxdef bifctx; |
| 392 |
uchar *labmem; |
| 393 |
mcmon evalobj; |
| 394 |
voccxdef vocctx; |
| 395 |
void (*bif[100])(struct bifcxdef *, int); |
| 396 |
mcmcxdef *mctx = 0; |
| 397 |
mcmcx1def *globalctx; |
| 398 |
objnum preinit; |
| 399 |
dbgcxdef dbg; |
| 400 |
supcxdef supctx; |
| 401 |
int err; |
| 402 |
char *swapname = 0; |
| 403 |
char swapbuf[OSFNMAX]; |
| 404 |
char **argp; |
| 405 |
char *arg; |
| 406 |
char *outfile = (char *)0; |
| 407 |
char outfile_abs[OSFNMAX]; |
| 408 |
char outfile_path[OSFNMAX]; |
| 409 |
char *infile; |
| 410 |
ulong swapsize = 0xffffffffL; |
| 411 |
int swapena = OS_DEFAULT_SWAP_ENABLED; |
| 412 |
linfdef *noreg linf = 0; |
| 413 |
int i; |
| 414 |
char inbuf[OSFNMAX]; |
| 415 |
char outbuf[OSFNMAX]; |
| 416 |
ulong cachelimit = 0xffffffffL; |
| 417 |
int argchecking = TRUE; |
| 418 |
int v1kw = FALSE; |
| 419 |
int v1else = FALSE; |
| 420 |
int stats = FALSE; |
| 421 |
int symdeb = FALSE; |
| 422 |
int symdeb2 = FALSE; |
| 423 |
int genoutput = TRUE; |
| 424 |
uint poolsiz = TCD_POOLSIZ; |
| 425 |
uint lclsiz = TCD_LCLSIZ; |
| 426 |
uint heapsiz = TCD_HEAPSIZ; |
| 427 |
uint stksiz = TCD_STKSIZ; |
| 428 |
uint labsiz = TCD_LABSIZ; |
| 429 |
char *binout = (char *)0; |
| 430 |
char *binin = (char *)0; |
| 431 |
fiolcxdef fiolctx; |
| 432 |
noreg int loadopen = FALSE; |
| 433 |
uint inflags; |
| 434 |
char *do_kw = (char *)0; |
| 435 |
int warnlevel = 0; |
| 436 |
char *filever = "*"; |
| 437 |
int c_mode = FALSE; |
| 438 |
char *sym; |
| 439 |
int symlen; |
| 440 |
char *expan; |
| 441 |
int explen; |
| 442 |
static char vsn_major_nm[] = "__TADS_VERSION_MAJOR"; |
| 443 |
static char vsn_minor_nm[] = "__TADS_VERSION_MINOR"; |
| 444 |
static char sys_name[] = "__TADS_SYSTEM_NAME"; |
| 445 |
static char oem_name[] = "__TADS_OEM_NAME"; |
| 446 |
static char dbg_name[] = "__DEBUG"; |
| 447 |
static char date_name[] = "__DATE__"; |
| 448 |
static char time_name[] = "__TIME__"; |
| 449 |
static char line_name[] = "__LINE__"; |
| 450 |
static char file_name[] = "__FILE__"; |
| 451 |
static char si_sysinfo[] = "__SYSINFO_SYSINFO"; |
| 452 |
static char si_version[] = "__SYSINFO_VERSION"; |
| 453 |
static char si_osname[] = "__SYSINFO_OS_NAME"; |
| 454 |
static char si_html[] = "__SYSINFO_HTML"; |
| 455 |
static char si_jpeg[] = "__SYSINFO_JPEG"; |
| 456 |
static char si_png[] = "__SYSINFO_PNG"; |
| 457 |
static char si_wav[] = "__SYSINFO_WAV"; |
| 458 |
static char si_midi[] = "__SYSINFO_MIDI"; |
| 459 |
static char si_wav_midi_ovl[] = "__SYSINFO_WAV_MIDI_OVL"; |
| 460 |
static char si_wav_ovl[] = "__SYSINFO_WAV_OVL"; |
| 461 |
static char si_pref_images[] = "__SYSINFO_PREF_IMAGES"; |
| 462 |
static char si_pref_sounds[] = "__SYSINFO_PREF_SOUNDS"; |
| 463 |
static char si_pref_music[] = "__SYSINFO_PREF_MUSIC"; |
| 464 |
static char si_pref_links[] = "__SYSINFO_PREF_LINKS"; |
| 465 |
static char si_mpeg[] = "__SYSINFO_MPEG_AUDIO"; |
| 466 |
static char si_mpeg1[] = "__SYSINFO_MPEG_AUDIO_1"; |
| 467 |
static char si_mpeg2[] = "__SYSINFO_MPEG_AUDIO_2"; |
| 468 |
static char si_mpeg3[] = "__SYSINFO_MPEG_AUDIO_3"; |
| 469 |
static char si_htmlmode[] = "__SYSINFO_HTML_MODE"; |
| 470 |
static char si_links_http[] = "__SYSINFO_LINKS_HTTP"; |
| 471 |
static char si_links_ftp[] = "__SYSINFO_LINKS_FTP"; |
| 472 |
static char si_links_news[] = "__SYSINFO_LINKS_NEWS"; |
| 473 |
static char si_links_mailto[] = "__SYSINFO_LINKS_MAILTO"; |
| 474 |
static char si_links_telnet[] = "__SYSINFO_LINKS_TELNET"; |
| 475 |
static char si_png_trans[] = "__SYSINFO_PNG_TRANS"; |
| 476 |
static char si_png_alpha[] = "__SYSINFO_PNG_ALPHA"; |
| 477 |
static char si_ogg[] = "__SYSINFO_OGG"; |
| 478 |
static char si_mng[] = "__SYSINFO_MNG"; |
| 479 |
static char si_mng_trans[] = "__SYSINFO_MNG_TRANS"; |
| 480 |
static char si_mng_alpha[] = "__SYSINFO_MNG_ALPHA"; |
| 481 |
static char si_txtcol[] = "__SYSINFO_TEXT_COLORS"; |
| 482 |
static char si_txthi[] = "__SYSINFO_TEXT_HILITE"; |
| 483 |
static char si_banners[] = "__SYSINFO_BANNERS"; |
| 484 |
static char si_interp_class[] = "__SYSINFO_INTERP_CLASS"; |
| 485 |
static char si_ic_text[] = "__SYSINFO_ICLASS_TEXT"; |
| 486 |
static char si_ic_textgui[] = "__SYSINFO_ICLASS_TEXTGUI"; |
| 487 |
static char si_ic_html[] = "__SYSINFO_ICLASS_HTML"; |
| 488 |
static char si_audio_fade[] = "__SYSINFO_AUDIO_FADE"; |
| 489 |
static char si_audio_crossfade[] = "__SYSINFO_AUDIO_CROSSFADE"; |
| 490 |
static char si_af_wav[] = "__SYSINFO_AUDIOFADE_WAV"; |
| 491 |
static char si_af_mpeg[] = "__SYSINFO_AUDIOFADE_MPEG"; |
| 492 |
static char si_af_ogg[] = "__SYSINFO_AUDIOFADE_OGG"; |
| 493 |
static char si_af_midi[] = "__SYSINFO_AUDIOFADE_MIDI"; |
| 494 |
time_t timer; |
| 495 |
struct tm *tblock; |
| 496 |
char *datetime; |
| 497 |
char datebuf[15]; |
| 498 |
ulong totsize; |
| 499 |
uchar *myheap; |
| 500 |
runsdef *mystack; |
| 501 |
char *strfile = 0; |
| 502 |
char *charmap = 0; |
| 503 |
int checked_undefs = FALSE; |
| 504 |
|
| 505 |
NOREG((&loadopen)) |
| 506 |
NOREG((&linf)) |
| 507 |
|
| 508 |
|
| 509 |
out_init(); |
| 510 |
|
| 511 |
|
| 512 |
ex_pause = FALSE; |
| 513 |
|
| 514 |
|
| 515 |
tc = tokcxini(ec, (mcmcxdef *)0, supsctab); |
| 516 |
tc->tokcxdbg = &dbg; |
| 517 |
ec->errcxlgc = errcbcx; |
| 518 |
errcbcx->tcderrfil = 0; |
| 519 |
errcbcx->tcderrtok = tc; |
| 520 |
errcbcx->tcderrlvl = 0; |
| 521 |
|
| 522 |
|
| 523 |
tokaddinc(tc, "", 0); |
| 524 |
|
| 525 |
|
| 526 |
for (i = 1, argp = argv + 1 ; i < argc ; ++argp, ++i) |
| 527 |
{ |
| 528 |
arg = *argp; |
| 529 |
if (*arg == '-') |
| 530 |
{ |
| 531 |
switch(*(arg+1)) |
| 532 |
{ |
| 533 |
case 'D': |
| 534 |
|
| 535 |
sym = cmdarg(ec, &argp, &i, argc, 1, tcdusage); |
| 536 |
|
| 537 |
|
| 538 |
for (expan = sym ; *expan && *expan != '=' ; ++expan) ; |
| 539 |
|
| 540 |
|
| 541 |
if (*expan == '\0') |
| 542 |
{ |
| 543 |
expan = "1"; |
| 544 |
symlen = strlen(sym); |
| 545 |
} |
| 546 |
else |
| 547 |
{ |
| 548 |
symlen = expan - sym; |
| 549 |
++expan; |
| 550 |
} |
| 551 |
explen = strlen(expan); |
| 552 |
|
| 553 |
|
| 554 |
tok_add_define_cvtcase(tc, sym, symlen, expan, explen); |
| 555 |
break; |
| 556 |
|
| 557 |
case 'U': |
| 558 |
|
| 559 |
sym = cmdarg(ec, &argp, &i, argc, 1, tcdusage); |
| 560 |
symlen = strlen(sym); |
| 561 |
tok_del_define(tc, sym, symlen); |
| 562 |
break; |
| 563 |
|
| 564 |
case 'C': |
| 565 |
c_mode = cmdtog(ec, c_mode, arg, 1, tcdusage); |
| 566 |
break; |
| 567 |
|
| 568 |
case 'c': |
| 569 |
{ |
| 570 |
int case_sensitive; |
| 571 |
|
| 572 |
if (strlen(arg+1) >= 4 |
| 573 |
&& !memcmp(arg+1, "case", (size_t)4)) |
| 574 |
{ |
| 575 |
case_sensitive = |
| 576 |
cmdtog(ec, (tc->tokcxflg & TOKCXCASEFOLD) == 0, |
| 577 |
arg, 4, tcdusage); |
| 578 |
if (case_sensitive) |
| 579 |
tc->tokcxflg &= ~TOKCXCASEFOLD; |
| 580 |
else |
| 581 |
tc->tokcxflg |= TOKCXCASEFOLD; |
| 582 |
} |
| 583 |
else if (!strcmp(arg+1, "ctab")) |
| 584 |
{ |
| 585 |
|
| 586 |
charmap = cmdarg(ec, &argp, &i, argc, 4, tcdusage); |
| 587 |
} |
| 588 |
else |
| 589 |
tcdusage(ec); |
| 590 |
break; |
| 591 |
} |
| 592 |
|
| 593 |
case 'e': |
| 594 |
{ |
| 595 |
char *errfname; |
| 596 |
errfname = cmdarg(ec, &argp, &i, argc, 1, tcdusage); |
| 597 |
if (!(errcbcx->tcderrfil = fopen(errfname, "w"))) |
| 598 |
errsig(ec, ERR_ERRFIL); |
| 599 |
break; |
| 600 |
} |
| 601 |
|
| 602 |
case 'd': |
| 603 |
if (arg[2] == 's') |
| 604 |
{ |
| 605 |
if (arg[3] == '2') |
| 606 |
{ |
| 607 |
|
| 608 |
symdeb2 = cmdtog(ec, symdeb, arg, 3, tcdusage); |
| 609 |
symdeb = symdeb2; |
| 610 |
} |
| 611 |
else |
| 612 |
{ |
| 613 |
|
| 614 |
symdeb = cmdtog(ec, symdeb, arg, 2, tcdusage); |
| 615 |
} |
| 616 |
} |
| 617 |
else |
| 618 |
tcdusage(ec); |
| 619 |
break; |
| 620 |
|
| 621 |
case 'm': |
| 622 |
switch(*(arg+2)) |
| 623 |
{ |
| 624 |
case '?': |
| 625 |
tcdmusage(ec); |
| 626 |
|
| 627 |
case 'g': |
| 628 |
labsiz = atoi(cmdarg(ec, &argp, &i, argc, 2, tcdusage)); |
| 629 |
break; |
| 630 |
|
| 631 |
case 'p': |
| 632 |
poolsiz = atoi(cmdarg(ec, &argp, &i, argc, 2, tcdusage)); |
| 633 |
break; |
| 634 |
|
| 635 |
case 'l': |
| 636 |
lclsiz = atoi(cmdarg(ec, &argp, &i, argc, 2, tcdusage)); |
| 637 |
break; |
| 638 |
|
| 639 |
case 's': |
| 640 |
stksiz = atoi(cmdarg(ec, &argp, &i, argc, 2, tcdusage)); |
| 641 |
break; |
| 642 |
|
| 643 |
case 'h': |
| 644 |
heapsiz = atoi(cmdarg(ec, &argp, &i, argc, 2, tcdusage)); |
| 645 |
break; |
| 646 |
|
| 647 |
default: |
| 648 |
cachelimit = atol(cmdarg(ec, &argp, &i, argc, |
| 649 |
1, tcdusage)); |
| 650 |
break; |
| 651 |
} |
| 652 |
break; |
| 653 |
|
| 654 |
case 'o': |
| 655 |
if (arg[2] == '-') |
| 656 |
genoutput = FALSE; |
| 657 |
else |
| 658 |
outfile = cmdarg(ec, &argp, &i, argc, 1, tcdusage); |
| 659 |
break; |
| 660 |
|
| 661 |
case 's': |
| 662 |
stats = cmdtog(ec, stats, arg, 1, tcdusage); |
| 663 |
break; |
| 664 |
|
| 665 |
case 't': |
| 666 |
|
| 667 |
switch(*(arg+2)) |
| 668 |
{ |
| 669 |
case 'f': |
| 670 |
swapname = cmdarg(ec, &argp, &i, argc, 2, tcdusage); |
| 671 |
break; |
| 672 |
|
| 673 |
case 's': |
| 674 |
swapsize = atol(cmdarg(ec, &argp, &i, argc, 2, tcdusage)); |
| 675 |
break; |
| 676 |
|
| 677 |
default: |
| 678 |
swapena = cmdtog(ec, swapena, arg, 1, tcdusage); |
| 679 |
break; |
| 680 |
} |
| 681 |
break; |
| 682 |
|
| 683 |
case 'i': |
| 684 |
{ |
| 685 |
char *path = cmdarg(ec, &argp, &i, argc, 1, tcdusage); |
| 686 |
tokaddinc(tc, path, (int)strlen(path)); |
| 687 |
break; |
| 688 |
} |
| 689 |
|
| 690 |
case 'l': |
| 691 |
binin = cmdarg(ec, &argp, &i, argc, 1, tcdusage); |
| 692 |
break; |
| 693 |
|
| 694 |
case 'p': |
| 695 |
ex_pause = cmdtog(ec, ex_pause, arg, 1, tcdusage); |
| 696 |
break; |
| 697 |
|
| 698 |
case 'w': |
| 699 |
binout = cmdarg(ec, &argp, &i, argc, 1, tcdusage); |
| 700 |
break; |
| 701 |
|
| 702 |
case 'f': |
| 703 |
switch(arg[2]) |
| 704 |
{ |
| 705 |
case 'v': |
| 706 |
filever = cmdarg(ec, &argp, &i, argc, 2, tcdusage); |
| 707 |
if (filever[1] != '\0' || |
| 708 |
(*filever != 'a' && *filever != 'b' && |
| 709 |
*filever != 'c' && *filever != '*')) |
| 710 |
tcdusage(ec); |
| 711 |
break; |
| 712 |
|
| 713 |
default: |
| 714 |
tcdusage(ec); |
| 715 |
} |
| 716 |
break; |
| 717 |
|
| 718 |
case 'F': |
| 719 |
switch(arg[2]) |
| 720 |
{ |
| 721 |
case 's': |
| 722 |
strfile = cmdarg(ec, &argp, &i, argc, 2, tcdusage); |
| 723 |
break; |
| 724 |
|
| 725 |
default: |
| 726 |
tcdusage(ec); |
| 727 |
} |
| 728 |
break; |
| 729 |
|
| 730 |
case '1': |
| 731 |
switch(arg[2]) |
| 732 |
{ |
| 733 |
case '?': |
| 734 |
tcd1usage(ec); |
| 735 |
|
| 736 |
case 'k': |
| 737 |
v1kw = cmdtog(ec, v1kw, arg, 2, tcdusage); |
| 738 |
break; |
| 739 |
|
| 740 |
case 'e': |
| 741 |
v1else = cmdtog(ec, v1else, arg, 2, tcdusage); |
| 742 |
break; |
| 743 |
|
| 744 |
case 'a': |
| 745 |
argchecking = cmdtog(ec, argchecking, arg, 2, tcdusage); |
| 746 |
break; |
| 747 |
|
| 748 |
case 'd': |
| 749 |
do_kw = cmdarg(ec, &argp, &i, argc, 2, tcdusage); |
| 750 |
break; |
| 751 |
|
| 752 |
case '\0': |
| 753 |
|
| 754 |
argchecking = !argchecking; |
| 755 |
v1else = !v1else; |
| 756 |
v1kw = !v1kw; |
| 757 |
break; |
| 758 |
|
| 759 |
default: |
| 760 |
tcdusage(ec); |
| 761 |
} |
| 762 |
break; |
| 763 |
|
| 764 |
case 'v': |
| 765 |
{ |
| 766 |
char *p; |
| 767 |
|
| 768 |
|
| 769 |
p = cmdarg(ec, &argp, &i, argc, 1, tcdusage); |
| 770 |
if (isdigit((uchar)*p)) |
| 771 |
{ |
| 772 |
|
| 773 |
warnlevel = atoi(p); |
| 774 |
errcbcx->tcderrlvl = warnlevel; |
| 775 |
} |
| 776 |
else if (*p == '-' || *p == '+') |
| 777 |
{ |
| 778 |
if (!strcmp(p+1, "abin")) |
| 779 |
errcbcx->tcdwrn_AMBIGBIN = (*p == '+'); |
| 780 |
else |
| 781 |
tcdvusage(ec); |
| 782 |
} |
| 783 |
else if (*p == '?') |
| 784 |
tcdvusage(ec); |
| 785 |
else |
| 786 |
tcdusage(ec); |
| 787 |
} |
| 788 |
break; |
| 789 |
|
| 790 |
case 'Z': |
| 791 |
switch(arg[2]) |
| 792 |
{ |
| 793 |
case '?': |
| 794 |
tcdzusage(ec); |
| 795 |
|
| 796 |
case 'a': |
| 797 |
argchecking = cmdtog(ec, argchecking, arg, 2, tcdusage); |
| 798 |
break; |
| 799 |
|
| 800 |
default: |
| 801 |
tcdusage(ec); |
| 802 |
} |
| 803 |
break; |
| 804 |
|
| 805 |
default: |
| 806 |
tcdusage(ec); |
| 807 |
} |
| 808 |
} |
| 809 |
else break; |
| 810 |
} |
| 811 |
|
| 812 |
|
| 813 |
if (cmap_load(charmap)) |
| 814 |
errsig(ec, ERR_INVCMAP); |
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
{ |
| 824 |
char buf[40]; |
| 825 |
|
| 826 |
sprintf(buf, "'%s'", OS_SYSTEM_NAME); |
| 827 |
tok_add_define_cvtcase(tc, sys_name, (int)sizeof(sys_name) - 1, |
| 828 |
buf, (int)strlen(buf)); |
| 829 |
} |
| 830 |
tok_add_define_cvtcase(tc, OS_SYSTEM_NAME, (int)strlen(OS_SYSTEM_NAME), |
| 831 |
"1", 1); |
| 832 |
|
| 833 |
|
| 834 |
tok_add_define_cvtcase(tc, vsn_major_nm, (int)sizeof(vsn_major_nm) - 1, |
| 835 |
vsn_major, (int)sizeof(vsn_major) - 1); |
| 836 |
tok_add_define_cvtcase(tc, vsn_minor_nm, (int)sizeof(vsn_minor_nm) - 1, |
| 837 |
vsn_minor, (int)sizeof(vsn_minor) - 1); |
| 838 |
|
| 839 |
|
| 840 |
{ |
| 841 |
char buf[256]; |
| 842 |
|
| 843 |
sprintf(buf, "'%s'", TADS_OEM_NAME); |
| 844 |
tok_add_define_cvtcase(tc, oem_name, (int)sizeof(oem_name) - 1, |
| 845 |
buf, (int)strlen(buf)); |
| 846 |
} |
| 847 |
|
| 848 |
|
| 849 |
timer = time(NULL); |
| 850 |
tblock = localtime(&timer); |
| 851 |
datetime = asctime(tblock); |
| 852 |
|
| 853 |
|
| 854 |
datebuf[0] = '\''; |
| 855 |
memcpy(datebuf + 1, datetime + 4, (size_t)7); |
| 856 |
memcpy(datebuf + 8, datetime + 20, (size_t)4); |
| 857 |
datebuf[12] = '\''; |
| 858 |
tok_add_define_cvtcase(tc, date_name, (int)sizeof(date_name) - 1, |
| 859 |
datebuf, 13); |
| 860 |
|
| 861 |
|
| 862 |
memcpy(datebuf + 1, datetime + 11, (size_t)8); |
| 863 |
datebuf[9] = '\''; |
| 864 |
tok_add_define_cvtcase(tc, time_name, (int)sizeof(time_name)-1, |
| 865 |
datebuf, 10); |
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
tok_add_define_cvtcase(tc, file_name, (int)sizeof(file_name) - 1, |
| 873 |
inbuf, OSFNMAX); |
| 874 |
tok_add_define_cvtcase(tc, line_name, (int)sizeof(line_name) - 1, |
| 875 |
inbuf, 40); |
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
tok_add_define_num_cvtcase(tc, si_sysinfo, (int)sizeof(si_sysinfo) - 1, |
| 881 |
SYSINFO_SYSINFO); |
| 882 |
tok_add_define_num_cvtcase(tc, si_version, (int)sizeof(si_version) - 1, |
| 883 |
SYSINFO_VERSION); |
| 884 |
tok_add_define_num_cvtcase(tc, si_osname, (int)sizeof(si_osname) - 1, |
| 885 |
SYSINFO_OS_NAME); |
| 886 |
tok_add_define_num_cvtcase(tc, si_html, (int)sizeof(si_html) - 1, |
| 887 |
SYSINFO_HTML); |
| 888 |
tok_add_define_num_cvtcase(tc, si_jpeg, (int)sizeof(si_jpeg) - 1, |
| 889 |
SYSINFO_JPEG); |
| 890 |
tok_add_define_num_cvtcase(tc, si_png, (int)sizeof(si_png) - 1, |
| 891 |
SYSINFO_PNG); |
| 892 |
tok_add_define_num_cvtcase(tc, si_wav, (int)sizeof(si_wav) - 1, |
| 893 |
SYSINFO_WAV); |
| 894 |
tok_add_define_num_cvtcase(tc, si_midi, (int)sizeof(si_midi) - 1, |
| 895 |
SYSINFO_MIDI); |
| 896 |
tok_add_define_num_cvtcase(tc, si_wav_midi_ovl, |
| 897 |
(int)sizeof(si_wav_midi_ovl) - 1, |
| 898 |
SYSINFO_WAV_MIDI_OVL); |
| 899 |
tok_add_define_num_cvtcase(tc, si_wav_ovl, (int)sizeof(si_wav_ovl) - 1, |
| 900 |
SYSINFO_WAV_OVL); |
| 901 |
tok_add_define_num_cvtcase(tc, si_pref_images, |
| 902 |
(int)sizeof(si_pref_images) - 1, |
| 903 |
SYSINFO_PREF_IMAGES); |
| 904 |
tok_add_define_num_cvtcase(tc, si_pref_sounds, |
| 905 |
(int)sizeof(si_pref_sounds) - 1, |
| 906 |
SYSINFO_PREF_SOUNDS); |
| 907 |
tok_add_define_num_cvtcase(tc, si_pref_music, |
| 908 |
(int)sizeof(si_pref_music) - 1, |
| 909 |
SYSINFO_PREF_MUSIC); |
| 910 |
tok_add_define_num_cvtcase(tc, si_pref_links, |
| 911 |
(int)sizeof(si_pref_links) - 1, |
| 912 |
SYSINFO_PREF_LINKS); |
| 913 |
tok_add_define_num_cvtcase(tc, si_mpeg, (int)sizeof(si_mpeg) - 1, |
| 914 |
SYSINFO_MPEG); |
| 915 |
tok_add_define_num_cvtcase(tc, si_mpeg1, (int)sizeof(si_mpeg1) - 1, |
| 916 |
SYSINFO_MPEG1); |
| 917 |
tok_add_define_num_cvtcase(tc, si_mpeg2, (int)sizeof(si_mpeg2) - 1, |
| 918 |
SYSINFO_MPEG2); |
| 919 |
tok_add_define_num_cvtcase(tc, si_mpeg3, (int)sizeof(si_mpeg3) - 1, |
| 920 |
SYSINFO_MPEG3); |
| 921 |
tok_add_define_num_cvtcase(tc, si_htmlmode, (int)sizeof(si_htmlmode) - 1, |
| 922 |
SYSINFO_HTML_MODE); |
| 923 |
tok_add_define_num_cvtcase(tc, si_links_http, |
| 924 |
(int)sizeof(si_links_http) - 1, |
| 925 |
SYSINFO_LINKS_HTTP); |
| 926 |
tok_add_define_num_cvtcase(tc, si_links_ftp, |
| 927 |
(int)sizeof(si_links_ftp) - 1, |
| 928 |
SYSINFO_LINKS_FTP); |
| 929 |
tok_add_define_num_cvtcase(tc, si_links_news, |
| 930 |
(int)sizeof(si_links_news) - 1, |
| 931 |
SYSINFO_LINKS_NEWS); |
| 932 |
tok_add_define_num_cvtcase(tc, si_links_mailto, |
| 933 |
(int)sizeof(si_links_mailto) - 1, |
| 934 |
SYSINFO_LINKS_MAILTO); |
| 935 |
tok_add_define_num_cvtcase(tc, si_links_telnet, |
| 936 |
(int)sizeof(si_links_telnet) - 1, |
| 937 |
SYSINFO_LINKS_TELNET); |
| 938 |
tok_add_define_num_cvtcase(tc, si_png_trans, |
| 939 |
(int)sizeof(si_png_trans) - 1, |
| 940 |
SYSINFO_PNG_TRANS); |
| 941 |
tok_add_define_num_cvtcase(tc, si_png_alpha, |
| 942 |
(int)sizeof(si_png_alpha) - 1, |
| 943 |
SYSINFO_PNG_ALPHA); |
| 944 |
tok_add_define_num_cvtcase(tc, si_ogg, (int)sizeof(si_ogg) - 1, |
| 945 |
SYSINFO_OGG); |
| 946 |
tok_add_define_num_cvtcase(tc, si_mng, (int)sizeof(si_mng) - 1, |
| 947 |
SYSINFO_MNG); |
| 948 |
tok_add_define_num_cvtcase(tc, si_mng_trans, |
| 949 |
(int)sizeof(si_mng_trans) - 1, |
| 950 |
SYSINFO_MNG_TRANS); |
| 951 |
tok_add_define_num_cvtcase(tc, si_mng_alpha, |
| 952 |
(int)sizeof(si_mng_alpha) - 1, |
| 953 |
SYSINFO_MNG_ALPHA); |
| 954 |
tok_add_define_num_cvtcase(tc, si_txthi, (int)sizeof(si_txthi) - 1, |
| 955 |
SYSINFO_TEXT_HILITE); |
| 956 |
tok_add_define_num_cvtcase(tc, si_txtcol, (int)sizeof(si_txtcol) - 1, |
| 957 |
SYSINFO_TEXT_COLORS); |
| 958 |
tok_add_define_num_cvtcase(tc, si_banners, (int)sizeof(si_banners) - 1, |
| 959 |
SYSINFO_BANNERS); |
| 960 |
tok_add_define_num_cvtcase(tc, si_interp_class, |
| 961 |
(int)sizeof(si_interp_class) - 1, |
| 962 |
SYSINFO_INTERP_CLASS); |
| 963 |
tok_add_define_num_cvtcase(tc, si_ic_text, |
| 964 |
(int)sizeof(si_ic_text) - 1, |
| 965 |
SYSINFO_ICLASS_TEXT); |
| 966 |
tok_add_define_num_cvtcase(tc, si_ic_textgui, |
| 967 |
(int)sizeof(si_ic_textgui) - 1, |
| 968 |
SYSINFO_ICLASS_TEXTGUI); |
| 969 |
tok_add_define_num_cvtcase(tc, si_ic_html, |
| 970 |
(int)sizeof(si_ic_html) - 1, |
| 971 |
SYSINFO_ICLASS_HTML); |
| 972 |
tok_add_define_num_cvtcase(tc, si_audio_fade, |
| 973 |
(int)sizeof(si_audio_fade) - 1, |
| 974 |
SYSINFO_AUDIO_FADE); |
| 975 |
tok_add_define_num_cvtcase(tc, si_audio_crossfade, |
| 976 |
(int)sizeof(si_audio_crossfade) - 1, |
| 977 |
SYSINFO_AUDIO_CROSSFADE); |
| 978 |
tok_add_define_num_cvtcase(tc, si_af_wav, (int)sizeof(si_af_wav) - 1, |
| 979 |
SYSINFO_AUDIOFADE_WAV); |
| 980 |
tok_add_define_num_cvtcase(tc, si_af_mpeg, (int)sizeof(si_af_mpeg) - 1, |
| 981 |
SYSINFO_AUDIOFADE_MPEG); |
| 982 |
tok_add_define_num_cvtcase(tc, si_af_ogg, (int)sizeof(si_af_ogg) - 1, |
| 983 |
SYSINFO_AUDIOFADE_OGG); |
| 984 |
tok_add_define_num_cvtcase(tc, si_af_midi, (int)sizeof(si_af_midi) - 1, |
| 985 |
SYSINFO_AUDIOFADE_MIDI); |
| 986 |
|
| 987 |
|
| 988 |
if (symdeb) |
| 989 |
tok_add_define_cvtcase(tc, dbg_name, |
| 990 |
(int)(sizeof(dbg_name) - 1), "1", 1); |
| 991 |
|
| 992 |
|
| 993 |
if (i == argc) tcdusage(ec); |
| 994 |
infile = *argp; |
| 995 |
if (i + 1 != argc) tcdusage(ec); |
| 996 |
|
| 997 |
|
| 998 |
strcpy(inbuf, infile); |
| 999 |
os_defext(inbuf, "t"); |
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
if (outfile) |
| 1006 |
{ |
| 1007 |
|
| 1008 |
strcpy(outbuf, outfile); |
| 1009 |
|
| 1010 |
|
| 1011 |
if (!strcmp(outfile, infile)) |
| 1012 |
{ |
| 1013 |
os_remext(outbuf); |
| 1014 |
os_addext(outbuf, "gam"); |
| 1015 |
} |
| 1016 |
} |
| 1017 |
else |
| 1018 |
{ |
| 1019 |
|
| 1020 |
strcpy(outbuf, infile); |
| 1021 |
os_remext(outbuf); |
| 1022 |
|
| 1023 |
|
| 1024 |
os_addext(outbuf, "gam"); |
| 1025 |
} |
| 1026 |
|
| 1027 |
|
| 1028 |
infile = inbuf; |
| 1029 |
outfile = outbuf; |
| 1030 |
|
| 1031 |
|
| 1032 |
if (errcbcx->tcderrfil) |
| 1033 |
{ |
| 1034 |
time_t t; |
| 1035 |
|
| 1036 |
t = time(NULL); |
| 1037 |
fprintf(errcbcx->tcderrfil, "TADS Compilation of %s\n%s\n", |
| 1038 |
infile, ctime(&t)); |
| 1039 |
} |
| 1040 |
|
| 1041 |
|
| 1042 |
if (swapena && swapsize) |
| 1043 |
{ |
| 1044 |
swapfp = os_create_tempfile(swapname, swapbuf); |
| 1045 |
if (swapname == 0) swapname = swapbuf; |
| 1046 |
if (swapfp == 0) errsig(ec, ERR_OPSWAP); |
| 1047 |
} |
| 1048 |
|
| 1049 |
ERRBEGIN(ec) |
| 1050 |
|
| 1051 |
|
| 1052 |
globalctx = mcmini(cachelimit, 128, swapsize, swapfp, 0, ec); |
| 1053 |
mctx = mcmcini(globalctx, 128, fioldobj, &fiolctx, |
| 1054 |
(void (*)(void *, mcmon))objrevert, (void *)0); |
| 1055 |
mctx->mcmcxrvc = mctx; |
| 1056 |
|
| 1057 |
tc->tokcxmem = mctx; |
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
totsize = sizeof(prscxdef) + (long)poolsiz + (long)lclsiz; |
| 1062 |
if (totsize != (size_t)totsize) |
| 1063 |
errsig1(ec, ERR_PRSCXSIZ, ERRTINT, (int)(65535 - sizeof(prscxdef))); |
| 1064 |
pctx = (prscxdef *)mchalo(ec, (size_t)totsize, "tcdmain"); |
| 1065 |
pctx->prscxerr = ec; |
| 1066 |
pctx->prscxtok = tc; |
| 1067 |
pctx->prscxmem = mctx; |
| 1068 |
pctx->prscxprp = 0; |
| 1069 |
pctx->prscxext = 0; |
| 1070 |
pctx->prscxnsiz = pctx->prscxrrst = poolsiz; |
| 1071 |
pctx->prscxnrst = pctx->prscxpool; |
| 1072 |
pctx->prscxplcl = &pctx->prscxpool[poolsiz]; |
| 1073 |
pctx->prscxslcl = lclsiz; |
| 1074 |
pctx->prscxflg = 0; |
| 1075 |
pctx->prscxnode = &pctx->prscxpool[0]; |
| 1076 |
pctx->prscxgtab = (toktdef *)&labtab; |
| 1077 |
pctx->prscxvoc = &vocctx; |
| 1078 |
pctx->prscxcpp = (char *)0; |
| 1079 |
pctx->prscxcps = 0; |
| 1080 |
pctx->prscxcpf = 0; |
| 1081 |
pctx->prscxspp = (char *)0; |
| 1082 |
pctx->prscxspf = 0; |
| 1083 |
pctx->prscxsps = 0; |
| 1084 |
pctx->prscxfsp = (uchar *)0; |
| 1085 |
pctx->prscxfsf = 0; |
| 1086 |
pctx->prscxfss = 0; |
| 1087 |
pctx->prscxextc = 0; |
| 1088 |
|
| 1089 |
|
| 1090 |
if (strfile != 0) |
| 1091 |
{ |
| 1092 |
|
| 1093 |
pctx->prscxstrfile = osfopwt(strfile, OSFTTEXT); |
| 1094 |
|
| 1095 |
|
| 1096 |
if (pctx->prscxstrfile == 0) |
| 1097 |
errsig(ec, ERR_OPNSTRFIL); |
| 1098 |
} |
| 1099 |
else |
| 1100 |
pctx->prscxstrfile = 0; |
| 1101 |
|
| 1102 |
|
| 1103 |
if (argchecking) pctx->prscxflg |= PRSCXFARC; |
| 1104 |
if (symdeb) pctx->prscxflg |= (PRSCXFLIN | PRSCXFLCL); |
| 1105 |
if (symdeb2) pctx->prscxflg |= (PRSCXFLIN2 | PRSCXFLCL); |
| 1106 |
if (v1else) pctx->prscxflg |= PRSCXFV1E; |
| 1107 |
if (c_mode) tc->tokcxflg |= TOKCXFCMODE; |
| 1108 |
if (symdeb2) tc->tokcxflg |= TOKCXFLIN2; |
| 1109 |
if (*filever != '*' && *filever < 'c') pctx->prscxflg |= PRSCXFTPL1; |
| 1110 |
|
| 1111 |
|
| 1112 |
vocini(&vocctx, ec, mctx, &runctx, (objucxdef *)0, 50, 50, 100); |
| 1113 |
vocctx.voccxflg |= VOCCXFVWARN; |
| 1114 |
|
| 1115 |
|
| 1116 |
totsize = (ulong)stksiz * (ulong)sizeof(runsdef); |
| 1117 |
if (totsize != (size_t)totsize) |
| 1118 |
errsig1(ec, ERR_STKSIZE, ERRTINT, (uint)(65535/sizeof(runsdef))); |
| 1119 |
mystack = (runsdef *)mchalo(ec, (size_t)totsize, "runtime stack"); |
| 1120 |
myheap = mchalo(ec, (size_t)heapsiz, "runtime heap"); |
| 1121 |
|
| 1122 |
|
| 1123 |
labmem = mchalo(ec, (size_t)labsiz, "main1"); |
| 1124 |
toktlini(ec, &labtab, labmem, labsiz); |
| 1125 |
labtab.toktlsc.toktnxt = (toktdef *)&symtab; |
| 1126 |
|
| 1127 |
|
| 1128 |
tc->tokcxsst = (ushort (*)(void *))prsxsst; |
| 1129 |
tc->tokcxsad = (void (*)(void *, char *, ushort))prsxsad; |
| 1130 |
tc->tokcxsend = (void (*)(void *))prsxsend; |
| 1131 |
tc->tokcxscx = (void *)pctx; |
| 1132 |
|
| 1133 |
|
| 1134 |
dbg.dbgcxtio = (tiocxdef *)0; |
| 1135 |
dbg.dbgcxtab = &symtab; |
| 1136 |
dbg.dbgcxmem = mctx; |
| 1137 |
dbg.dbgcxerr = ec; |
| 1138 |
dbg.dbgcxfcn = 0; |
| 1139 |
dbg.dbgcxdep = 0; |
| 1140 |
dbg.dbgcxfid = 0; |
| 1141 |
dbg.dbgcxflg = 0; |
| 1142 |
|
| 1143 |
vocctx.voccxrun = &runctx; |
| 1144 |
runctx.runcxdbg = &dbg; |
| 1145 |
dbg.dbgcxtab = &symtab; |
| 1146 |
|
| 1147 |
|
| 1148 |
if (!(linf = linfini(mctx, ec, infile, (int)strlen(infile), |
| 1149 |
(tokpdef *)0, TRUE, symdeb2))) |
| 1150 |
errsig(ec, ERR_OPNINP); |
| 1151 |
|
| 1152 |
linf->linflin.linpar = (lindef *)0; |
| 1153 |
dbg.dbgcxlin = &linf->linflin; |
| 1154 |
tc->tokcxhdr = (linfdef *)&linf->linflin; |
| 1155 |
|
| 1156 |
|
| 1157 |
tc->tokcxlin = &linf->linflin; |
| 1158 |
linf->linflin.linid = dbg.dbgcxfid++; |
| 1159 |
linf->linflin.linnxt = (lindef *)0; |
| 1160 |
|
| 1161 |
|
| 1162 |
tokthini(ec, mctx, (toktdef *)&symtab); |
| 1163 |
pctx->prscxstab = (toktdef *)&symtab; |
| 1164 |
|
| 1165 |
tc->tokcxstab = (toktdef *)&symtab; |
| 1166 |
|
| 1167 |
|
| 1168 |
ectx = (emtcxdef *)mchalo(ec, |
| 1169 |
(sizeof(emtcxdef) + 511*sizeof(emtldef)), |
| 1170 |
"tcdmain"); |
| 1171 |
ectx->emtcxerr = ec; |
| 1172 |
ectx->emtcxmem = pctx->prscxmem; |
| 1173 |
ectx->emtcxptr = 0; |
| 1174 |
ectx->emtcxlcnt = 512; |
| 1175 |
ectx->emtcxfrob = MCMONINV; |
| 1176 |
emtlini(ectx); |
| 1177 |
|
| 1178 |
|
| 1179 |
pctx->prscxemt = ectx; |
| 1180 |
|
| 1181 |
|
| 1182 |
os_get_abs_filename(outfile_abs, sizeof(outfile_abs), outfile); |
| 1183 |
os_get_path_name(outfile_path, sizeof(outfile_path), outfile_abs); |
| 1184 |
|
| 1185 |
|
| 1186 |
runctx.runcxerr = ec; |
| 1187 |
runctx.runcxmem = pctx->prscxmem; |
| 1188 |
runctx.runcxstk = mystack; |
| 1189 |
runctx.runcxstop = &mystack[stksiz]; |
| 1190 |
runctx.runcxsp = mystack; |
| 1191 |
runctx.runcxbp = mystack; |
| 1192 |
runctx.runcxheap = myheap; |
| 1193 |
runctx.runcxhp = myheap; |
| 1194 |
runctx.runcxhtop = &myheap[heapsiz]; |
| 1195 |
runctx.runcxundo = (objucxdef *)0; |
| 1196 |
runctx.runcxbcx = &bifctx; |
| 1197 |
runctx.runcxbi = bif; |
| 1198 |
runctx.runcxtio = (tiocxdef *)0; |
| 1199 |
runctx.runcxdbg = &dbg; |
| 1200 |
runctx.runcxvoc = &vocctx; |
| 1201 |
runctx.runcxdmd = (void (*)(void *, objnum, prpnum))supcont; |
| 1202 |
runctx.runcxdmc = &supctx; |
| 1203 |
runctx.runcxgamename = outfile; |
| 1204 |
runctx.runcxgamepath = outfile_path; |
| 1205 |
|
| 1206 |
|
| 1207 |
supctx.supcxerr = ec; |
| 1208 |
supctx.supcxmem = mctx; |
| 1209 |
supctx.supcxtab = &symtab; |
| 1210 |
supctx.supcxbuf = (uchar *)0; |
| 1211 |
supctx.supcxlen = 0; |
| 1212 |
supctx.supcxvoc = &vocctx; |
| 1213 |
supctx.supcxrun = &runctx; |
| 1214 |
|
| 1215 |
|
| 1216 |
CLRSTRUCT(bifctx); |
| 1217 |
bifctx.bifcxerr = ec; |
| 1218 |
bifctx.bifcxrun = &runctx; |
| 1219 |
bifctx.bifcxtio = (tiocxdef *)0; |
| 1220 |
bifctx.bifcxsavext = save_ext; |
| 1221 |
|
| 1222 |
|
| 1223 |
mcmalo(pctx->prscxmem, (ushort)1024, &evalobj); |
| 1224 |
mcmunlck(pctx->prscxmem, evalobj); |
| 1225 |
|
| 1226 |
|
| 1227 |
pctx->prscxprp = PRP_LASTRSV + 1; |
| 1228 |
|
| 1229 |
|
| 1230 |
suprsrv(&supctx, bif, (toktdef *)&symtab, |
| 1231 |
(int)(sizeof(bif)/sizeof(bif[0])), v1kw, do_kw, |
| 1232 |
tc->tokcxflg & TOKCXCASEFOLD); |
| 1233 |
|
| 1234 |
|
| 1235 |
if (binin) |
| 1236 |
{ |
| 1237 |
dbg.dbgcxfid--; |
| 1238 |
|
| 1239 |
fiord(mctx, &vocctx, tc, binin, (char *)0, &fiolctx, &preinit, |
| 1240 |
&inflags, tc->tokcxinc, |
| 1241 |
&pctx->prscxfsp, &pctx->prscxfsf, &pctx->prscxprp, FALSE, 0, |
| 1242 |
argv[0]); |
| 1243 |
tc->tokcxhdr = (linfdef *)dbg.dbgcxlin; |
| 1244 |
pctx->prscxfss = pctx->prscxfsf; |
| 1245 |
pctx->prscxcpp = vocctx.voccxcpp; |
| 1246 |
pctx->prscxcps = |
| 1247 |
pctx->prscxcpf = vocctx.voccxcpl; |
| 1248 |
pctx->prscxspp = vocctx.voccxspp; |
| 1249 |
pctx->prscxsps = |
| 1250 |
pctx->prscxspf = vocctx.voccxspl; |
| 1251 |
loadopen = TRUE; |
| 1252 |
|
| 1253 |
linf->linflin.linid = dbg.dbgcxfid++; |
| 1254 |
|
| 1255 |
|
| 1256 |
if (inflags & FIOFCASE) |
| 1257 |
tc->tokcxflg |= TOKCXCASEFOLD; |
| 1258 |
else |
| 1259 |
tc->tokcxflg &= ~TOKCXCASEFOLD; |
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
for (i = 1, argp = argv + 1 ; i < argc ; ++argp, ++i) |
| 1267 |
{ |
| 1268 |
arg = *argp; |
| 1269 |
if (*arg == '-') |
| 1270 |
{ |
| 1271 |
switch(*(arg+1)) |
| 1272 |
{ |
| 1273 |
case 'U': |
| 1274 |
|
| 1275 |
sym = cmdarg(ec, &argp, &i, argc, 1, tcdusage); |
| 1276 |
symlen = strlen(sym); |
| 1277 |
tok_del_define(tc, sym, symlen); |
| 1278 |
break; |
| 1279 |
|
| 1280 |
default: |
| 1281 |
|
| 1282 |
break; |
| 1283 |
} |
| 1284 |
} |
| 1285 |
} |
| 1286 |
|
| 1287 |
} |
| 1288 |
|
| 1289 |
|
| 1290 |
prsrstn(pctx); |
| 1291 |
toknext(tc); |
| 1292 |
|
| 1293 |
|
| 1294 |
parse_loop: |
| 1295 |
ERRBEGIN(ec) |
| 1296 |
for ( ;; ) |
| 1297 |
{ |
| 1298 |
|
| 1299 |
ectx->emtcxofs = 0; |
| 1300 |
|
| 1301 |
|
| 1302 |
os_progress(((linfdef *)tc->tokcxlin)->linfnam, |
| 1303 |
((linfdef *)tc->tokcxlin)->linfnum); |
| 1304 |
|
| 1305 |
|
| 1306 |
if (os_yield()) |
| 1307 |
errsig(ec, ERR_USRINT); |
| 1308 |
|
| 1309 |
|
| 1310 |
if (errcbcx->tcdfatal) |
| 1311 |
break; |
| 1312 |
|
| 1313 |
|
| 1314 |
if (tc->tokcxcur.toktyp == TOKTEOF) |
| 1315 |
break; |
| 1316 |
|
| 1317 |
|
| 1318 |
prscode(pctx, TRUE); |
| 1319 |
} |
| 1320 |
ERRCATCH(ec, err) |
| 1321 |
if (err >= 100 && err < 450) |
| 1322 |
{ |
| 1323 |
int brace_cnt; |
| 1324 |
int paren_cnt; |
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
errclog(ec); |
| 1332 |
for (brace_cnt = paren_cnt = 0 ;; ) |
| 1333 |
{ |
| 1334 |
switch(tc->tokcxcur.toktyp) |
| 1335 |
{ |
| 1336 |
case TOKTSEM: |
| 1337 |
|
| 1338 |
if (brace_cnt || paren_cnt) |
| 1339 |
break; |
| 1340 |
|
| 1341 |
|
| 1342 |
case TOKTEOF: |
| 1343 |
toknext(tc); |
| 1344 |
goto parse_loop; |
| 1345 |
|
| 1346 |
case TOKTLBRACE: |
| 1347 |
|
| 1348 |
++brace_cnt; |
| 1349 |
paren_cnt = 0; |
| 1350 |
break; |
| 1351 |
|
| 1352 |
case TOKTRBRACE: |
| 1353 |
|
| 1354 |
paren_cnt = 0; |
| 1355 |
if (brace_cnt) |
| 1356 |
--brace_cnt; |
| 1357 |
break; |
| 1358 |
|
| 1359 |
case TOKTLPAR: |
| 1360 |
++paren_cnt; |
| 1361 |
break; |
| 1362 |
|
| 1363 |
case TOKTRPAR: |
| 1364 |
--paren_cnt; |
| 1365 |
break; |
| 1366 |
} |
| 1367 |
|
| 1368 |
|
| 1369 |
toknext(tc); |
| 1370 |
} |
| 1371 |
} |
| 1372 |
|
| 1373 |
|
| 1374 |
errrse(ec); |
| 1375 |
ERREND(ec) |
| 1376 |
|
| 1377 |
|
| 1378 |
vocctx.voccxcpp = pctx->prscxcpp; |
| 1379 |
vocctx.voccxcpl = pctx->prscxcpf; |
| 1380 |
|
| 1381 |
|
| 1382 |
vocctx.voccxspp = pctx->prscxspp; |
| 1383 |
vocctx.voccxspl = pctx->prscxspf; |
| 1384 |
|
| 1385 |
if (!binout && !errcbcx->tcdfatal) |
| 1386 |
{ |
| 1387 |
tcdchkctx cbctx; |
| 1388 |
|
| 1389 |
|
| 1390 |
tcgcomp(ec, pctx, infile); |
| 1391 |
|
| 1392 |
|
| 1393 |
tiosetfmt((tiocxdef *)0, &runctx, pctx->prscxfsp, |
| 1394 |
(uint)pctx->prscxfsf); |
| 1395 |
|
| 1396 |
|
| 1397 |
supfind(ec, &symtab, &vocctx, &preinit, warnlevel, |
| 1398 |
tc->tokcxflg & TOKCXCASEFOLD); |
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
supivoc(&supctx); |
| 1406 |
|
| 1407 |
|
| 1408 |
cbctx.mem = mctx; |
| 1409 |
cbctx.ec = ec; |
| 1410 |
cbctx.cnt = 0; |
| 1411 |
toktheach(&symtab.tokthsc, tcdchkundef, &cbctx); |
| 1412 |
checked_undefs = TRUE; |
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
if (preinit != MCMONINV && !symdeb |
| 1419 |
&& errcbcx->tcderrcnt == 0 && errcbcx->tcdfatal == 0) |
| 1420 |
runfn(&runctx, preinit, 0); |
| 1421 |
} |
| 1422 |
|
| 1423 |
if (binout && errcbcx->tcderrcnt == 0) |
| 1424 |
{ |
| 1425 |
fiowrt(mctx, &vocctx, tc, &symtab, pctx->prscxfsp, |
| 1426 |
(uint)pctx->prscxfsf, |
| 1427 |
binout, FIOFSYM + FIOFLIN + FIOFPRE + FIOFBIN |
| 1428 |
+ (tc->tokcxflg & TOKCXCASEFOLD ? FIOFCASE : 0), |
| 1429 |
(objnum)MCMONINV, pctx->prscxextc, pctx->prscxprp, filever); |
| 1430 |
} |
| 1431 |
|
| 1432 |
|
| 1433 |
if (genoutput && !binout |
| 1434 |
&& errcbcx->tcderrcnt == 0 && errcbcx->tcdfatal == 0) |
| 1435 |
{ |
| 1436 |
fiowrt(mctx, &vocctx, tc, |
| 1437 |
&symtab, pctx->prscxfsp, (uint)pctx->prscxfsf, |
| 1438 |
outfile, |
| 1439 |
(FIOFFAST |
| 1440 |
+ (symdeb ? (FIOFSYM + FIOFLIN + FIOFPRE |
| 1441 |
+ ((tc->tokcxflg & TOKCXCASEFOLD) |
| 1442 |
? FIOFCASE : 0) |
| 1443 |
) |
| 1444 |
: FIOFCRYPT |
| 1445 |
) |
| 1446 |
+ (symdeb2 ? FIOFLIN2 : 0) |
| 1447 |
), |
| 1448 |
preinit, pctx->prscxextc, (uint)0, filever); |
| 1449 |
} |
| 1450 |
else if (!binout && !checked_undefs) |
| 1451 |
{ |
| 1452 |
tcdchkctx cbctx; |
| 1453 |
|
| 1454 |
|
| 1455 |
cbctx.mem = mctx; |
| 1456 |
cbctx.ec = ec; |
| 1457 |
cbctx.cnt = 0; |
| 1458 |
toktheach(&symtab.tokthsc, tcdchkundef, &cbctx); |
| 1459 |
} |
| 1460 |
|
| 1461 |
|
| 1462 |
if (stats) |
| 1463 |
{ |
| 1464 |
int count; |
| 1465 |
int i; |
| 1466 |
int j; |
| 1467 |
vocdef **vhsh; |
| 1468 |
vocdef *voc; |
| 1469 |
vocidef ***vpg; |
| 1470 |
vocidef **v; |
| 1471 |
|
| 1472 |
IF_DEBUG(extern ulong mchtotmem;) |
| 1473 |
|
| 1474 |
tcdptf("\n* * * Statistics * * *\n"); |
| 1475 |
tcdptf("Virtual Object Cache size: %lu\n", mcmcsiz(mctx)); |
| 1476 |
tcdptf("Global symbol table size: %lu\n", |
| 1477 |
((ulong)symtab.tokthpcnt * (ulong)TOKTHSIZE)); |
| 1478 |
IF_DEBUG(tcdptf("Total heap memory: %lu\n", mchtotmem);) |
| 1479 |
|
| 1480 |
|
| 1481 |
count = 0; |
| 1482 |
for (i = 0, vhsh = vocctx.voccxhsh ; i < VOCHASHSIZ ; ++i, ++vhsh) |
| 1483 |
{ |
| 1484 |
for (voc = *vhsh ; voc ; voc = voc->vocnxt) |
| 1485 |
{ |
| 1486 |
|
| 1487 |
++count; |
| 1488 |
#if 0 |
| 1489 |
|
| 1490 |
{ |
| 1491 |
vocdef *voc2; |
| 1492 |
for (voc2 = voc->vocnxt ; voc2 ; voc2 = voc2->vocnxt) |
| 1493 |
{ |
| 1494 |
if (voc->voclen == voc2->voclen |
| 1495 |
&& voc->vocln2 == voc2->vocln2 |
| 1496 |
&& !memcmp(voc->voctxt, voc2->voctxt, |
| 1497 |
(size_t)(voc->voclen + voc->vocln2))) |
| 1498 |
{ |
| 1499 |
--count; |
| 1500 |
break; |
| 1501 |
} |
| 1502 |
} |
| 1503 |
} |
| 1504 |
#endif |
| 1505 |
|
| 1506 |
} |
| 1507 |
} |
| 1508 |
tcdptf("Vocabulary words: %d\n", count); |
| 1509 |
|
| 1510 |
|
| 1511 |
count = 0; |
| 1512 |
for (vpg = vocctx.voccxinh, i = 0 ; i < VOCINHMAX ; ++vpg, ++i) |
| 1513 |
{ |
| 1514 |
if (!*vpg) continue; |
| 1515 |
for (v = *vpg, j = 0 ; j < 256 ; ++v, ++j) |
| 1516 |
{ |
| 1517 |
if (*v) ++count; |
| 1518 |
} |
| 1519 |
} |
| 1520 |
tcdptf("Objects: %d\n", count); |
| 1521 |
} |
| 1522 |
|
| 1523 |
|
| 1524 |
if (swapfp) |
| 1525 |
{ |
| 1526 |
osfcls(swapfp); |
| 1527 |
swapfp = (osfildef *)0; |
| 1528 |
osfdel_temp(swapname); |
| 1529 |
} |
| 1530 |
|
| 1531 |
|
| 1532 |
if (loadopen) |
| 1533 |
fiorcls(&fiolctx); |
| 1534 |
|
| 1535 |
|
| 1536 |
if (errcbcx->tcderrfil) |
| 1537 |
{ |
| 1538 |
fclose(errcbcx->tcderrfil); |
| 1539 |
errcbcx->tcderrfil = 0; |
| 1540 |
} |
| 1541 |
|
| 1542 |
|
| 1543 |
if (pctx->prscxstrfile != 0) |
| 1544 |
{ |
| 1545 |
osfcls(pctx->prscxstrfile); |
| 1546 |
pctx->prscxstrfile = 0; |
| 1547 |
} |
| 1548 |
|
| 1549 |
|
| 1550 |
if (linf != 0) |
| 1551 |
linfcls(&linf->linflin); |
| 1552 |
|
| 1553 |
ERRCATCH(ec, err) |
| 1554 |
|
| 1555 |
if (err == ERR_NOMEM) |
| 1556 |
{ |
| 1557 |
tcdptf("*** Note for -m option:\n"); |
| 1558 |
tcdptf("*** Current cache size is %lu\n", mcmcsiz(mctx)); |
| 1559 |
} |
| 1560 |
|
| 1561 |
|
| 1562 |
if (swapfp) |
| 1563 |
{ |
| 1564 |
osfcls(swapfp); |
| 1565 |
swapfp = (osfildef *)0; |
| 1566 |
osfdel_temp(swapname); |
| 1567 |
} |
| 1568 |
|
| 1569 |
|
| 1570 |
if (loadopen) |
| 1571 |
fiorcls(&fiolctx); |
| 1572 |
|
| 1573 |
|
| 1574 |
if (linf != 0) |
| 1575 |
linfcls(&linf->linflin); |
| 1576 |
|
| 1577 |
|
| 1578 |
errrse(ec); |
| 1579 |
ERREND(ec) |
| 1580 |
} |
| 1581 |
|
| 1582 |
|
| 1583 |
static void tcdlogerr(void *ectx0, char *fac, int err, int argc, |
| 1584 |
erradef *argv) |
| 1585 |
{ |
| 1586 |
tcderrdef *ectx = (tcderrdef *)ectx0; |
| 1587 |
char buf[256]; |
| 1588 |
char msg[256]; |
| 1589 |
tokcxdef *ctx = ectx->tcderrtok; |
| 1590 |
FILE *fp; |
| 1591 |
|
| 1592 |
|
| 1593 |
switch(err) |
| 1594 |
{ |
| 1595 |
case ERR_INCRPT: |
| 1596 |
if (ectx->tcderrlvl < 1) return; |
| 1597 |
break; |
| 1598 |
} |
| 1599 |
|
| 1600 |
if (!ctx) |
| 1601 |
{ |
| 1602 |
tcdptf("%s-%d: error message not available\n", buf, fac, err); |
| 1603 |
return; |
| 1604 |
} |
| 1605 |
|
| 1606 |
|
| 1607 |
switch(err) |
| 1608 |
{ |
| 1609 |
case ERR_AMBIGBIN: |
| 1610 |
|
| 1611 |
if (!ectx->tcdwrn_AMBIGBIN) return; |
| 1612 |
goto do_warning; |
| 1613 |
|
| 1614 |
case ERR_TRUNC: |
| 1615 |
case ERR_INCRPT: |
| 1616 |
case ERR_WEQASI: |
| 1617 |
case ERR_STREND: |
| 1618 |
case ERR_RPLSPEC: |
| 1619 |
case ERR_VOCREVB: |
| 1620 |
case ERR_LOCNOBJ: |
| 1621 |
case ERR_CNTNLST: |
| 1622 |
case ERR_WRNONF: |
| 1623 |
case ERR_GNOFIL: |
| 1624 |
case ERR_PUNDEF: |
| 1625 |
case ERR_PIA: |
| 1626 |
do_warning: |
| 1627 |
|
| 1628 |
++(ectx->tcdwrncnt); |
| 1629 |
break; |
| 1630 |
|
| 1631 |
case ERR_NOMEM: |
| 1632 |
case ERR_FSEEK: |
| 1633 |
case ERR_FREAD: |
| 1634 |
case ERR_FWRITE: |
| 1635 |
case ERR_NOPAGE: |
| 1636 |
case ERR_SWAPBIG: |
| 1637 |
case ERR_SWAPPG: |
| 1638 |
case ERR_CLIFULL: |
| 1639 |
case ERR_NOMEM1: |
| 1640 |
case ERR_NOMEM2: |
| 1641 |
case ERR_NOLCLSY: |
| 1642 |
case ERR_MANYSYM: |
| 1643 |
case ERR_NONODE: |
| 1644 |
case ERR_VOCSTK: |
| 1645 |
case ERR_MANYDBG: |
| 1646 |
case ERR_VOCMNPG: |
| 1647 |
case ERR_NOMEMLC: |
| 1648 |
case ERR_NOMEMAR: |
| 1649 |
|
| 1650 |
ectx->tcdfatal = TRUE; |
| 1651 |
++(ectx->tcderrcnt); |
| 1652 |
break; |
| 1653 |
|
| 1654 |
default: |
| 1655 |
|
| 1656 |
++(ectx->tcderrcnt); |
| 1657 |
break; |
| 1658 |
} |
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
switch(err) |
| 1665 |
{ |
| 1666 |
case ERR_UNDFOBJ: |
| 1667 |
case ERR_UNDEFO: |
| 1668 |
case ERR_UNDEFF: |
| 1669 |
|
| 1670 |
strcpy(buf, argv[1].errastr); |
| 1671 |
break; |
| 1672 |
|
| 1673 |
default: |
| 1674 |
|
| 1675 |
if (ctx->tokcxlin != 0) |
| 1676 |
linppos(ctx->tokcxlin, buf, (uint)sizeof(buf)); |
| 1677 |
else |
| 1678 |
buf[0] = '\0'; |
| 1679 |
} |
| 1680 |
|
| 1681 |
fp = ectx->tcderrfil; |
| 1682 |
|
| 1683 |
tcdptf("%serror %s-%d: ", buf, fac, err); |
| 1684 |
if (fp) fprintf(fp, "%serror %s-%d: ", buf, fac, err); |
| 1685 |
|
| 1686 |
errmsg(ctx->tokcxerr, msg, (uint)sizeof(msg), err); |
| 1687 |
errfmt(buf, (int)sizeof(buf), msg, argc, argv); |
| 1688 |
tcdptf("%s\n", buf); |
| 1689 |
if (fp) fprintf(fp, "%s\n", buf); |
| 1690 |
|
| 1691 |
#ifdef OS_ERRLINE |
| 1692 |
if ((err >= ERR_INVTOK && err < ERR_VOCINUS) |
| 1693 |
|| err == ERR_UNDFOBJ || err == ERR_UNDEFO || err == ERR_UNDEFF) |
| 1694 |
{ |
| 1695 |
char *p; |
| 1696 |
int len; |
| 1697 |
|
| 1698 |
switch(err) |
| 1699 |
{ |
| 1700 |
case ERR_UNDFOBJ: |
| 1701 |
case ERR_UNDEFO: |
| 1702 |
case ERR_UNDEFF: |
| 1703 |
p = argv[1].errastr; |
| 1704 |
p += strlen(p) + 1; |
| 1705 |
len = strlen(p); |
| 1706 |
break; |
| 1707 |
|
| 1708 |
default: |
| 1709 |
p = ctx->tokcxlin->linbuf; |
| 1710 |
len = ctx->tokcxlin->linlen; |
| 1711 |
break; |
| 1712 |
} |
| 1713 |
|
| 1714 |
if (len + 1 > sizeof(buf)) len = sizeof(buf) - 1; |
| 1715 |
memcpy(buf, p, (size_t)len); |
| 1716 |
buf[len] = '\0'; |
| 1717 |
tcdptf("%s\n\n", buf); |
| 1718 |
if (fp) fprintf(fp, "%s\n\n", buf); |
| 1719 |
} |
| 1720 |
#endif |
| 1721 |
} |
| 1722 |
|
| 1723 |
|
| 1724 |
static void maybe_pause(void) |
| 1725 |
{ |
| 1726 |
|
| 1727 |
if (ex_pause) |
| 1728 |
{ |
| 1729 |
tcdptf("[done with compilation - press a key to continue]"); |
| 1730 |
os_waitc(); |
| 1731 |
tcdptf("\n"); |
| 1732 |
} |
| 1733 |
} |
| 1734 |
|
| 1735 |
|
| 1736 |
int tcdmain(int argc, char **argv, char *save_ext) |
| 1737 |
{ |
| 1738 |
errcxdef errctx; |
| 1739 |
int err; |
| 1740 |
osfildef *fp; |
| 1741 |
extern char tcgname[]; |
| 1742 |
tcderrdef errcbcx; |
| 1743 |
char vsnbuf[128]; |
| 1744 |
|
| 1745 |
|
| 1746 |
CLRSTRUCT(errcbcx); |
| 1747 |
errcbcx.tcdwrn_AMBIGBIN = TRUE; |
| 1748 |
|
| 1749 |
errctx.errcxlog = tcdlogerr; |
| 1750 |
errctx.errcxlgc = (void *)0; |
| 1751 |
errctx.errcxofs = 0; |
| 1752 |
errctx.errcxfp = (osfildef *)0; |
| 1753 |
errctx.errcxappctx = 0; |
| 1754 |
fp = oserrop(argv[0]); |
| 1755 |
errini(&errctx, fp); |
| 1756 |
|
| 1757 |
|
| 1758 |
sprintf(vsnbuf, "%s v%s.%s.%s %s\n", tcgname, |
| 1759 |
vsn_major, vsn_minor, vsn_maint, |
| 1760 |
"Copyright (c) 1993, 2012 Michael J. Roberts"); |
| 1761 |
tcdptf(vsnbuf); |
| 1762 |
sprintf(vsnbuf, "TADS for %s [%s] patchlevel %s.%s\n", |
| 1763 |
OS_SYSTEM_LDESC, OS_SYSTEM_NAME, |
| 1764 |
TADS_OEM_VERSION, OS_SYSTEM_PATCHSUBLVL); |
| 1765 |
tcdptf(vsnbuf); |
| 1766 |
tcdptf("%s maintains this port.\n", TADS_OEM_NAME); |
| 1767 |
|
| 1768 |
ERRBEGIN(&errctx) |
| 1769 |
tcdmain1(&errctx, argc, argv, &errcbcx, save_ext); |
| 1770 |
ERRCATCH(&errctx, err) |
| 1771 |
if (err != ERR_USAGE) |
| 1772 |
errclog(&errctx); |
| 1773 |
|
| 1774 |
if (errctx.errcxfp) osfcls(errctx.errcxfp); |
| 1775 |
if (errcbcx.tcderrfil) fclose(errcbcx.tcderrfil); |
| 1776 |
|
| 1777 |
maybe_pause(); |
| 1778 |
return(OSEXFAIL); |
| 1779 |
ERREND(&errctx) |
| 1780 |
|
| 1781 |
|
| 1782 |
if (errctx.errcxfp) osfcls(errctx.errcxfp); |
| 1783 |
|
| 1784 |
|
| 1785 |
if (errcbcx.tcderrfil) fclose(errcbcx.tcderrfil); |
| 1786 |
|
| 1787 |
|
| 1788 |
maybe_pause(); |
| 1789 |
return(errcbcx.tcderrcnt == 0 ? OSEXSUCC : OSEXFAIL); |
| 1790 |
} |
| 1791 |
|