| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
#include <assert.h> |
| 11 |
#include <ctype.h> |
| 12 |
#include "agility.h" |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
rbool PURE_ANSWER=0; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
rbool PURE_TIME=1; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
rbool PURE_AND=1; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
rbool PURE_METAVERB=1; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
rbool PURE_ROOMTITLE=1; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
rbool PURE_SYN=0; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
rbool PURE_NOUN=0; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
rbool PURE_ADJ=1; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
rbool PURE_DUMMY=0; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
rbool PURE_SUBNAME=0; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
rbool PURE_PROSUB=0; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
rbool PURE_HOSTILE=1; |
| 100 |
|
| 101 |
rbool PURE_ALL=1; |
| 102 |
rbool PURE_DISAMBIG=1; |
| 103 |
rbool PURE_GETHOSTILE=1; |
| 104 |
|
| 105 |
|
| 106 |
rbool PURE_OBJ_DESC=1; |
| 107 |
|
| 108 |
|
| 109 |
rbool PURE_ERROR=0; |
| 110 |
|
| 111 |
|
| 112 |
rbool PURE_SIZE=1; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
rbool PURE_GRAMMAR=1; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
rbool PURE_SYSMSG=1; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
rbool PURE_AFTER=1; |
| 127 |
|
| 128 |
|
| 129 |
rbool PURE_PROPER=1; |
| 130 |
|
| 131 |
rbool TWO_CYCLE=0; |
| 132 |
rbool FORCE_VERSION=0; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
#define opt(s) (strcasecmp(optstr[0],s)==0) |
| 152 |
|
| 153 |
static void cfg_option(int optnum,char *optstr[], rbool lastpass) |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
{ |
| 161 |
rbool setflag; |
| 162 |
|
| 163 |
if (optnum==0 || optstr[0]==NULL) return; |
| 164 |
|
| 165 |
if (strncasecmp(optstr[0],"no_",3)==0) { |
| 166 |
optstr[0]+=3; |
| 167 |
setflag=0; |
| 168 |
} else setflag=1; |
| 169 |
|
| 170 |
if (opt("slash_bold")) bold_mode=setflag; |
| 171 |
else if (!lastpass) { |
| 172 |
|
| 173 |
agil_option(optnum,optstr,setflag,lastpass); |
| 174 |
return; |
| 175 |
} |
| 176 |
else if (opt("irun")) irun_mode=setflag; |
| 177 |
else if (opt("block_hostile")) PURE_HOSTILE=setflag; |
| 178 |
else if (opt("get_hostile")) PURE_GETHOSTILE=setflag; |
| 179 |
else if (opt("debug")) { |
| 180 |
if (!agx_file && aver<=AGTME10) debug_mode=setflag; |
| 181 |
if (setflag==0) debug_mode=0; |
| 182 |
} |
| 183 |
else if (opt("pure_answer")) PURE_ANSWER=setflag; |
| 184 |
else if (opt("const_time")) PURE_TIME=!setflag; |
| 185 |
else if (opt("fix_multinoun")) PURE_AND=!setflag; |
| 186 |
else if (opt("fix_metaverb")) PURE_METAVERB=!setflag; |
| 187 |
else if (opt("roomtitle")) PURE_ROOMTITLE=!setflag; |
| 188 |
else if (opt("pure_synonym")) PURE_SYN=setflag; |
| 189 |
else if (opt("adj_noun")) PURE_ADJ=!setflag; |
| 190 |
else if (opt("pure_dummy")) PURE_DUMMY=setflag; |
| 191 |
else if (opt("pure_subroutine")) PURE_SUBNAME=setflag; |
| 192 |
else if (opt("pronoun_subs")) PURE_PROSUB=!setflag; |
| 193 |
else if (opt("verbose")) verboseflag=setflag; |
| 194 |
else if (opt("fixed_font")) font_status=1+!setflag; |
| 195 |
else if (opt("alt_any")) mars_fix=setflag; |
| 196 |
else if (opt("smart_disambig")) PURE_DISAMBIG=!setflag; |
| 197 |
else if (opt("expand_all")) PURE_ALL=!setflag; |
| 198 |
else if (opt("object_notes")) PURE_OBJ_DESC=setflag; |
| 199 |
else if (opt("error")) PURE_ERROR=!setflag; |
| 200 |
else if (opt("ignore_size")) PURE_SIZE=!setflag; |
| 201 |
else if (opt("check_grammar")) PURE_GRAMMAR=!setflag; |
| 202 |
else if (opt("default_errors")) PURE_SYSMSG=!setflag; |
| 203 |
else if (opt("pure_after")) PURE_AFTER=!setflag; |
| 204 |
else if (opt("proper_creature")) PURE_PROPER=!setflag; |
| 205 |
else agil_option(optnum,optstr,setflag,lastpass); |
| 206 |
} |
| 207 |
|
| 208 |
#undef opt |
| 209 |
|
| 210 |
|
| 211 |
rbool parse_config_line(char *buff, rbool lastpass) |
| 212 |
{ |
| 213 |
char *opt[50], *p; |
| 214 |
int optc; |
| 215 |
|
| 216 |
optc=0; |
| 217 |
opt[0]=NULL; |
| 218 |
for(p=buff;*p;p++) { |
| 219 |
if (isspace(*p)) { |
| 220 |
if (opt[optc]!=NULL) { |
| 221 |
if (optc==50) return 0; |
| 222 |
opt[++optc]=NULL; |
| 223 |
} |
| 224 |
*p=0; |
| 225 |
} else |
| 226 |
if (opt[optc]==NULL) |
| 227 |
opt[optc]=p; |
| 228 |
} |
| 229 |
if (opt[optc]!=NULL) opt[++optc]=NULL; |
| 230 |
cfg_option(optc,opt,lastpass); |
| 231 |
return 1; |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
void read_config(genfile cfgfile, rbool lastpass) |
| 237 |
{ |
| 238 |
char buff[100]; |
| 239 |
|
| 240 |
if (lastpass) { |
| 241 |
|
| 242 |
if (aver>=AGT15) PURE_DISAMBIG=0; |
| 243 |
} |
| 244 |
|
| 245 |
if (!filevalid(cfgfile,fCFG)) return; |
| 246 |
|
| 247 |
while(readln(cfgfile,buff,99)) { |
| 248 |
if (buff[0]=='#') continue; |
| 249 |
|
| 250 |
|
| 251 |
if (!parse_config_line(buff,lastpass)) |
| 252 |
rprintf("Too many tokens on configuration line.\n"); |
| 253 |
} |
| 254 |
readclose(cfgfile); |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
void read_opt(fc_type fc) |
| 286 |
{ |
| 287 |
char *errstr; |
| 288 |
genfile optfile; |
| 289 |
|
| 290 |
have_opt=0; |
| 291 |
optfile=openbin(fc,fOPT,NULL,0); |
| 292 |
if (filevalid(optfile,fOPT)) { |
| 293 |
if (!binread(optfile,opt_data,14,1,&errstr)) |
| 294 |
fatal("Invalid OPT file."); |
| 295 |
have_opt=1; |
| 296 |
readclose(optfile); |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
#define SOGCREDIT 7 |
| 312 |
static const char *sogauthor[SOGCREDIT]={ |
| 313 |
"Mark \"Sam\" Baker", |
| 314 |
"Steve \"Aaargh\" Bauman", |
| 315 |
"Belisana \"The\" Magnificent", |
| 316 |
"Mike \"of Locksley\" Laskey", |
| 317 |
"Judith \"Teela Brown\" Pintar", |
| 318 |
"Hercules \"The Loyal\" SysOp", |
| 319 |
"Cindy \"Nearly Amelia\" Yans" |
| 320 |
}; |
| 321 |
|
| 322 |
static rbool check_dollar(char *s) |
| 323 |
|
| 324 |
|
| 325 |
{ |
| 326 |
rbool dfound; |
| 327 |
dfound=0; |
| 328 |
for(;*s!=0;s++) |
| 329 |
if (*s=='$' && !dfound) dfound=1; |
| 330 |
else if (!rspace(*s)) return 0; |
| 331 |
return dfound; |
| 332 |
} |
| 333 |
|
| 334 |
descr_line *read_ttl(fc_type fc) |
| 335 |
{ |
| 336 |
genfile ttlfile; |
| 337 |
int i, j, height; |
| 338 |
descr_line *buff; |
| 339 |
|
| 340 |
ttlfile=openfile(fc,fTTL,NULL,0); |
| 341 |
|
| 342 |
if (!filevalid(ttlfile,fTTL)) return NULL; |
| 343 |
build_fixchar(); |
| 344 |
|
| 345 |
buff=rmalloc(sizeof(descr_line)); |
| 346 |
i=0; |
| 347 |
while( NULL!=(buff[i]=readln(ttlfile,NULL,0)) ) { |
| 348 |
if (strncmp(buff[i],"END OF FILE",11)==0) break; |
| 349 |
else if (aver>=AGT18 && aver<=AGT18MAX && check_dollar(buff[i])) |
| 350 |
statusmode=4; |
| 351 |
else { |
| 352 |
for(j=0;buff[i][j]!=0;j++) |
| 353 |
buff[i][j]=fixchar[(uchar)buff[i][j]]; |
| 354 |
|
| 355 |
buff=rrealloc(buff,sizeof(descr_line)*(++i + 1)); |
| 356 |
buff[i]=NULL; |
| 357 |
} |
| 358 |
rfree(buff[i]); |
| 359 |
} |
| 360 |
readclose(ttlfile); |
| 361 |
|
| 362 |
rfree(buff[i]); |
| 363 |
while(buff[i]==NULL || strlen(buff[i])<=1) { |
| 364 |
if (i==0) break; |
| 365 |
rfree(buff[i]); |
| 366 |
i--; |
| 367 |
} |
| 368 |
height=i; |
| 369 |
|
| 370 |
if (aver==AGTCOS && ver==4 && height>=17) |
| 371 |
for(i=0;i<SOGCREDIT;i++) |
| 372 |
if (strlen(sogauthor[i])+9+i<strlen(buff[i+7])) |
| 373 |
memcpy(buff[i+7]+9+i,sogauthor[i],strlen(sogauthor[i])); |
| 374 |
|
| 375 |
return buff; |
| 376 |
} |
| 377 |
|
| 378 |
void free_ttl(descr_line *title) |
| 379 |
{ |
| 380 |
int i; |
| 381 |
if (title==NULL) return; |
| 382 |
for(i=0;title[i]!=NULL;i++) |
| 383 |
rfree(title[i]); |
| 384 |
rfree(title); |
| 385 |
} |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
static char *newvoc[]={"1 Menu","1 Restart","1 Undo"}; |
| 395 |
static int newindex=0; |
| 396 |
|
| 397 |
void add_verbrec(char *verbline,rbool addnew) |
| 398 |
{ |
| 399 |
char s[3],*p; |
| 400 |
|
| 401 |
while(rspace(*verbline)) verbline++; |
| 402 |
if (*verbline==0 || verbline[0]=='!') return; |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
if (!addnew) |
| 407 |
while (newindex<3 && strcasecmp(verbline+2,newvoc[newindex]+2)>0) |
| 408 |
add_verbrec(newvoc[newindex++],1); |
| 409 |
|
| 410 |
verbinfo=rrealloc(verbinfo,(vm_size+1)*sizeof(verbentry_rec)); |
| 411 |
|
| 412 |
s[0]=verbline[0];s[1]=0; |
| 413 |
verbinfo[vm_size].objnum=strtol(s,NULL,10)-1; |
| 414 |
|
| 415 |
verbline+=2; |
| 416 |
|
| 417 |
verbinfo[vm_size].verb=verbinfo[vm_size].prep=0; |
| 418 |
p=verbline; |
| 419 |
if (*p!=0) { |
| 420 |
while(*p && !rspace(*p)) p++; |
| 421 |
if (*p!=0) { |
| 422 |
*p=0; |
| 423 |
p++; |
| 424 |
} |
| 425 |
verbinfo[vm_size].verb=search_dict(verbline); |
| 426 |
if (verbinfo[vm_size].verb==-1) { |
| 427 |
verbinfo[vm_size].verb=0;return;} |
| 428 |
if (*p!=0) { |
| 429 |
verbinfo[vm_size].prep=search_dict(p); |
| 430 |
if (verbinfo[vm_size].prep==-1) |
| 431 |
verbinfo[vm_size].prep=0; |
| 432 |
} |
| 433 |
} |
| 434 |
vm_size++; |
| 435 |
} |
| 436 |
|
| 437 |
void init_verbrec(void) |
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
{ |
| 442 |
verbinfo=NULL; |
| 443 |
vm_size=0; |
| 444 |
newindex=0; |
| 445 |
if (freeze_mode) newindex=1; |
| 446 |
|
| 447 |
} |
| 448 |
|
| 449 |
void finish_verbrec(void) |
| 450 |
{ |
| 451 |
for(;newindex<3;newindex++) add_verbrec(newvoc[newindex],1); |
| 452 |
} |
| 453 |
|
| 454 |
|
| 455 |
void read_voc(fc_type fc) |
| 456 |
{ |
| 457 |
char linbuf[80]; |
| 458 |
genfile vocfile; |
| 459 |
|
| 460 |
init_verbrec(); |
| 461 |
vocfile=openfile(fc,fVOC,NULL,0); |
| 462 |
if (filevalid(vocfile,fVOC)) { |
| 463 |
while(readln(vocfile,linbuf,79)) |
| 464 |
add_verbrec(linbuf,0); |
| 465 |
readclose(vocfile); |
| 466 |
finish_verbrec(); |
| 467 |
} |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
static genfile insfile=BAD_TEXTFILE; |
| 480 |
static char *ins_buff; |
| 481 |
|
| 482 |
static descr_line *ins_descr=NULL; |
| 483 |
static int ins_line; |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
rbool open_ins_file(fc_type fc, rbool report_error) |
| 488 |
{ |
| 489 |
ins_buff=NULL; |
| 490 |
ins_line=0; |
| 491 |
|
| 492 |
if (ins_descr!=NULL) return 1; |
| 493 |
|
| 494 |
if (filevalid(insfile,fINS)) { |
| 495 |
textrewind(insfile); |
| 496 |
return 1; |
| 497 |
} |
| 498 |
|
| 499 |
if (agx_file) { |
| 500 |
ins_descr=read_descr(ins_ptr.start,ins_ptr.size); |
| 501 |
if (ins_descr!=NULL) return 1; |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
} |
| 506 |
|
| 507 |
insfile=openfile(fc, fINS, |
| 508 |
report_error |
| 509 |
? "Sorry, Instructions aren't available for this game" |
| 510 |
: NULL, |
| 511 |
0); |
| 512 |
return(filevalid(insfile,fINS)); |
| 513 |
} |
| 514 |
|
| 515 |
char *read_ins_line(void) |
| 516 |
{ |
| 517 |
if (ins_descr) { |
| 518 |
if (ins_descr[ins_line]!=NULL) |
| 519 |
return ins_descr[ins_line++]; |
| 520 |
else return NULL; |
| 521 |
} else { |
| 522 |
rfree(ins_buff); |
| 523 |
ins_buff=readln(insfile,NULL,0); |
| 524 |
return ins_buff; |
| 525 |
} |
| 526 |
} |
| 527 |
|
| 528 |
void close_ins_file(void) |
| 529 |
{ |
| 530 |
if (ins_descr) { |
| 531 |
free_descr(ins_descr); |
| 532 |
ins_descr=NULL; |
| 533 |
} else if (filevalid(insfile,fINS)) { |
| 534 |
rfree(ins_buff); |
| 535 |
readclose(insfile); |
| 536 |
insfile=BAD_TEXTFILE; |
| 537 |
} |
| 538 |
} |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
descr_line *read_ins(fc_type fc) |
| 543 |
{ |
| 544 |
descr_line *txt; |
| 545 |
char *buff; |
| 546 |
int i; |
| 547 |
|
| 548 |
i=0; |
| 549 |
txt=NULL; |
| 550 |
if (open_ins_file(fc,0)) { |
| 551 |
while ( NULL!=(buff=read_ins_line()) ) { |
| 552 |
|
| 553 |
txt=rrealloc(txt,sizeof(descr_ptr)*(i+2)); |
| 554 |
txt[i++]=rstrdup(buff); |
| 555 |
} |
| 556 |
if (txt!=NULL) |
| 557 |
txt[i]=0; |
| 558 |
close_ins_file(); |
| 559 |
} |
| 560 |
return txt; |
| 561 |
} |
| 562 |
|
| 563 |
|
| 564 |
void free_ins(descr_line *instr) |
| 565 |
{ |
| 566 |
int i; |
| 567 |
if (instr==NULL) return; |
| 568 |
for(i=0;instr[i]!=NULL;i++) |
| 569 |
rfree(instr[i]); |
| 570 |
rfree(instr); |
| 571 |
} |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
void build_fixchar(void) |
| 577 |
{ |
| 578 |
int i; |
| 579 |
for(i=0;i<256;i++) { |
| 580 |
if (i=='\r' || i=='\n') fixchar[i]=' '; |
| 581 |
else if (i=='\\' && bold_mode) fixchar[i]=FORMAT_CODE; |
| 582 |
else if (i>=0x80 && fix_ascii_flag) |
| 583 |
fixchar[i]=trans_ibm[i & 0x7f]; |
| 584 |
else if (i==0) |
| 585 |
fixchar[i]=FORMAT_CODE; |
| 586 |
else fixchar[i]=i; |
| 587 |
} |
| 588 |
} |
| 589 |
|
| 590 |
|
| 591 |
|