Debian Codegraph @

terps/agility/agtout.c

raw symbols SCIP
1 /* agtout.c-- Program to test agtread.c */
2 /* Copyright (C) 1996-1999,2001 Robert Masenten */
3 /* This program may be redistributed under the terms of the
4 GNU General Public License, version 2; see agility.h for details. */
5 /* */
6 /* This is part of the source for AGiliTy, the (Mostly) Universal */
7 /* AGT Interpreter */
8
9 /* This program was originally written to test agtread.c. */
10 /* It dumps all of the file information to stdout in a human readable */
11 /* format and so will also be of use to game authors who want to know */
12 /* how the AGT compiler translated their work, and of course to game */
13 /* players who have gotten stuck... :-) */
14 /* It's not quite as polished as some of the other modules; in particular, */
15 /* if your system doesn't support I/O redirection, you'll need to redirect */
16 /* stdin yourself in main() (using freopen, say) or else replace all the */
17 /* printf calls by fprintf calls. */
18
19 #include <ctype.h>
20 #define global
21 #include "agility.h"
22
23 #define AGX_DESC 1
24
25 /* These are for the sake of the disassembler */
26 integer dobj=0, iobj=0, actor=0;
27
28
29
30 /* DICTFIX */
31
32 #define verbose_dump 1
33
34 rbool printmsg, printdict, sortflag;
35 global rbool dbg_msgrange; /* Print the range of messages for
36 RandomMessage (only checked if
37 dbg_nomsg isn't set) */
38 global rbool quick_rndmsg; /* Don't give RandomMessage special treatment. */
39 global rbool no_badobj; /* Filter out objects with garbage names. */
40
41 long msgcnt(int ver,int aver)
42 {
43 switch(ver) {
44 case 1:return 250;
45 case 2:if (aver==AGTCOS) return 700; /* Cosmosrv */
46 else if (aver<=AGT12) return 500;
47 else return 600; /* 500? */
48 case 3:return 700;
49 case 4:return 900;
50 }
51 printf("INTERNAL ERROR: Invalid VER\n");
52 return 0;
53 }
54
55 long cmdcnt(int ver,int aver)
56 {
57 switch(ver) {
58 case 1:return 400;
59 case 2: if (aver==AGTCOS) return 1100;
60 else return 900; /* 700? */
61 case 3:return 900;
62 case 4:return 1500;
63 }
64 printf("INTERNAL ERROR: Invalid VER\n");
65 return 0;
66
67
68 }
69
70 long cmdsize(void)
71 {
72 int i;
73 long size;
74
75 size=0;
76 for(i=0;i<last_cmd;i++)
77 size+=command[i].cmdsize;
78 return size*sizeof(integer);
79 }
80
81
82 extern long dictstrptr, dictstrsize;
83
84
85 void printopt(char *s, char opt)
86 {
87 static int x;
88 if (s==NULL) {x=0;return;}
89 if (opt==2) return;
90 if (opt==1) printf("%s ",s);
91 if (opt==0) {printf("NO_%s ",s);x+=3;}
92 x+=strlen(s);
93 if (x>60) {
94 printf("\n");
95 x=0;
96 }
97 }
98
99
100 void nprintopt(char *s, char opt)
101 {
102 if (opt==1) opt=0;
103 else if (opt==0) opt=1;
104 printopt(s,opt);
105 }
106
107
108 void info_out(void)
109 {
110 integer creatcnt;
111 long tmp;
112
113 printf("\nGeneral Information:(ver=%d, aver=%d)\n",ver,aver);
114 printf("Signature: %ld\n",game_sig);
115 printf("AGT Version %s, (Size:%s)\n",averstr[aver],verstr[ver]);
116 printf("\tStart room: %d Treas Room: %d Resurrect Room: %d\n",
117 start_room,treas_room,resurrect_room);
118 printf("\tLives: %d Max Score: %ld\n",max_lives,max_score);
119 printf("\t");
120 if (debug_mode) printf("<DEBUG>\t");
121 if (have_meta) printf("<META>\t");
122 if (freeze_mode) printf("<FREEZE>\t");
123 if (mars_fix) printf("<MARS>\t");
124 printf("Status Mode %d Score mode %d",statusmode,score_mode);
125 printf(" Time %d+%d\n",start_time,delta_time);
126 if (milltime_mode) printf("\t<MILITARY>");
127 printf("\n");
128 printf("Ranges-- Room: %d..%d Noun: %d..%d Creature: %d..%d\n",
129 first_room,maxroom,first_noun,maxnoun,first_creat,maxcreat);
130 printf(" ExitMsg Base:%d\n",exitmsg_base);
131 printf("Max--\tVars: %d Counters: %d Flags: %d User Strings: %d\n",
132 VAR_NUM, CNT_NUM, FLAG_NUM, MAX_USTR);
133 printf("\tMetacommands: %ld Subroutines: %d Error Messages: %d\n",
134 last_cmd, MAX_SUB, NUM_ERR);
135 if (aver>=AGTME10)
136 printf("\tGlobal Nouns: %ld Picts: %ld RoomPIXs: %ld Fonts: %ld "
137 "Songs: %ld\n",
138 numglobal,maxpict,maxpix,maxfont,maxsong);
139 if (aver>=AGX00) {
140 printf("\tObject flags: %d/%d/%d \tObject Props: %d/%d/%d\n",
141 8*num_rflags,8*num_nflags,8*num_cflags,
142 num_rprops,num_nprops,num_cprops);
143 printf("\t(Total ObjFlags: %d \tTotal ObjProps: %d )\n",
144 oflag_cnt,oprop_cnt);
145 }
146 printf("\tVocabulary: %ld\n",dp);
147 printf("\n");
148 printf("\nStatistics:\n");
149 printf(" Static String Size: %6ld Syntbl Size: %6ld\n",
150 ss_end,((long)synptr)*sizeof(word));
151 if (maxcreat>=first_creat) creatcnt=maxcreat-first_creat+1;
152 else creatcnt=0;
153 printf(" Data size-- Room: %5ld Noun: %5ld Creat: %5ld\n",
154 sizeof(room_rec)*(long)(maxroom-first_room+1),
155 sizeof(noun_rec)*(long)(maxnoun-first_noun+1),
156 sizeof(creat_rec)*(long)creatcnt);
157 tmp=cmdsize();
158 printf(" Commands: Headers: %5ld Text: %5ld Total: %5ld\n",
159 sizeof(cmd_rec)*last_cmd,tmp,sizeof(cmd_rec)*last_cmd+tmp);
160 printf(" Dictionary: Dict: %5ld Text: %5ld(%5ld) Tot: %5ld\n",
161 ((long)dp)*sizeof(char*),
162 dictstrptr,dictstrsize,dp*sizeof(char*)+dictstrptr);
163 printf("\n");
164 printf(" Num of Objs-- Room: %3d/%3d Noun: %3d/%3d Creat: %3d/%3d\n",
165 maxroom-first_room+1, first_noun-first_room,
166 maxnoun-first_noun+1, first_creat-first_noun,
167 creatcnt, last_obj-first_creat+1);
168 printf(" Message: %3ld/%3ld Cmd: %4ld/%4ld\n",
169 last_message,msgcnt(ver,aver), last_cmd,cmdcnt(ver,aver));
170 printf("\n");
171 printf("Settings:\n");
172 printopt(NULL,0);
173 printopt("INTRO_FIRST",intro_first);
174 printopt("SLASH_BOLD",bold_mode);
175 printopt("PURE_ANSWER",PURE_ANSWER);
176 nprintopt("CONST_TIME", PURE_TIME);
177 nprintopt("ROOMTITLE", PURE_ROOMTITLE);
178 nprintopt("FIX_MULTINOUN",PURE_AND);
179 nprintopt("FIX_METAVERB",PURE_METAVERB);
180 nprintopt("CHECK_GRAMMAR",PURE_GRAMMAR);
181 /*
182 printopt( PURE_SYN);
183 printopt( PURE_NOUN);
184 printopt( PURE_ADJ);
185 */
186 printopt("PURE_DUMMY",PURE_DUMMY);
187 printopt("PURE_SUBNAME",PURE_SUBNAME);
188 nprintopt("PRONOUN_SUBS",PURE_PROSUB);
189 printopt("BLOCK_HOSTILE",PURE_HOSTILE);
190 printopt("GET_HOSTILE",PURE_GETHOSTILE);
191 nprintopt("SMART_DISAMBIG",PURE_DISAMBIG);
192 nprintopt("EXPAND_ALL",PURE_ALL);
193 printopt("IRUN",irun_mode);
194 printopt("VERBOSE",verboseflag);
195 printf("\n");
196 }
197
198
199
200 /* Doprint=0 ==>don't print, = 1: do print unless size 0,
201 =2: print regardless */
202 void print_descr(char *name,descr_ptr dp, int doprint)
203 {
204 int j;
205 descr_line *txt;
206
207 if (doprint==0) return;
208 if (doprint==1 && dp.size==0) return;
209
210 printf("%s (%ld,%ld)\n",name,dp.start,dp.size);
211 if (agx_file && !AGX_DESC) return;
212 txt=read_descr(dp.start,dp.size);
213 if (txt!=NULL)
214 for(j=0;txt[j]!=NULL;j++)
215 printf("%s\n",txt[j]);
216 free_descr(txt);
217 }
218
219
220 void dump_attr(int t, int objnum)
221 /* t=0 for room, 1 for noun, 2 for creature */
222 /* objnum is the object index */
223 {
224 int i, line;
225 char ofs;
226
227 if (num_oattrs(t,0)>0) { /* List flags */
228 printf(" FLAGS:\n");
229 line=0;
230 for(i=0;i<oflag_cnt;i++)
231 if (lookup_objflag(i,t,&ofs)!=-1) {
232 if (line==0) printf(" ");
233 printf("Flag %2d: %s ",i,op_objflag(2,objnum,i)?"Yes":"No ");
234 if (++line==4) {
235 printf("\n");
236 line=0;
237 }
238 }
239 if (line!=0) printf("\n");
240 }
241 if (num_oattrs(t,1)>0) { /* List properties */
242 printf(" PROPS:\n");
243 line=0;
244 for(i=0;i<oprop_cnt;i++)
245 if (lookup_objprop(i,t)!=-1) {
246 if (line==0) printf(" ");
247 printf("Prop %2d=%6ld ",i,op_objprop(2,objnum,i,0));
248 if (++line==2) {
249 printf("\n");
250 line=0;
251 }
252 }
253 if (line!=0) printf("\n");
254 }
255 }
256
257
258
259 void print_slist(slist sp)
260 {
261 while(syntbl[sp]!=0) {
262 printf("%s",dict[syntbl[sp++]]);
263 if (syntbl[sp]!=0) printf(", ");
264 }
265 }
266
267 rbool badname(uchar *s)
268 {
269 if (aver>=AGTME10 || !no_badobj)
270 return 0; /* ME games shouldn't have gaps. */
271 for(;*s!=0;s++)
272 if (*s<32) return 1;
273 return 0;
274 }
275
276
277 void rooms_out(void)
278 {
279 long i,j;
280
281 printf("\nRoom List:");
282 for(i=0;i<maxroom-first_room+1;i++)
283 {
284 /* if (badname((uchar*)room[i].name)) continue;*/
285 if (room[i].unused) continue;
286 printf("\nROOM %ld:%-15s",i+first_room,room[i].name);
287 if (room[i].oclass!=0)
288 printf(" (Class:%d)",room[i].oclass);
289 printf("\n ATTR:");
290 if (room[i].seen)
291 printf(" seen ");
292 if (room[i].locked_door)
293 printf(" lck door ");
294 if (room[i].win) printf(" WIN ");
295 if (room[i].end) printf(" END ");
296 if (room[i].killplayer) printf(" DIE ");
297 printf("\n");
298 printf(" Key=%d Light=%d Points=%d",
299 room[i].key,room[i].light,room[i].points);
300 if (room_inside!=NULL)
301 printf(" #Nouns=%d\n",room_inside[i]);
302 else printf("\n");
303 for(j=0;j<12;j++)
304 printf(" %s:%d",exitname[j],room[i].path[j]);
305 printf("\n SPECIAL:%d\n",room[i].path[12]);
306 printf(" SYN %s=",dict[room[i].replace_word]);
307 print_slist(room[i].replacing_word);
308 printf("\n");
309 if (ver==3) {
310 printf(" Initial=%d Picture=%d Flags=%08lx PIX=%08lx\n",
311 room[i].initdesc,room[i].pict,room[i].flag_noun_bits,
312 room[i].PIX_bits);
313 printf(" Autoexec=%s\n",dict[room[i].autoverb]);
314 }
315 dump_attr(0,i+first_room);
316 if (verbose_dump) {
317 print_descr("DESCR:",room_ptr[i],2);
318 print_descr("HELP:",help_ptr[i],1);
319 print_descr("SPECIAL:",special_ptr[i],1);
320 }
321 }
322 }
323
324 void nouns_out(void)
325 {
326 long i;
327
328 printf("\n\nNoun List:");
329 for(i=0;i<maxnoun-first_noun+1;i++)
330 {
331 /* if (badname((uchar*)noun[i].shortdesc)) continue; */
332 if (noun[i].unused) continue;
333 printf("\n\nNOUN %ld:%s %s",i+first_noun,dict[noun[i].adj],
334 dict[noun[i].name]);
335 if (noun[i].oclass!=0)
336 printf(" (Class:%d)",noun[i].oclass);
337 if (noun[i].flagnum!=0)
338 printf(" [flag %d]",noun[i].flagnum);
339 printf("\n%s\n",noun[i].shortdesc);
340 printf(" Pos:%s\n",(noun[i].position==NULL)?"<none>":noun[i].position);
341 printf(" Location:%d (behind %d) Points:%d",
342 noun[i].location,noun[i].nearby_noun,noun[i].points);
343 if (noun_inside!=NULL)
344 printf(" #Nouns=%d\n",noun_inside[i]);
345 else printf("\n");
346 printf(" Wt=%d Size=%d Key:%d #Shots=%d\n",
347 noun[i].weight,noun[i].size,noun[i].key,noun[i].num_shots);
348 printf(" ATTR:");
349 if (noun[i].plural) printf(" pl ");
350 else printf(" sing ");
351 if (noun[i].something_pos_near_noun) printf(" in_front ");
352 if (noun[i].win) printf(" WIN ");
353 if (noun[i].has_syns) printf(" syns ");
354 printf("\n CAN:");
355 if (noun[i].pushable) printf(" push ");
356 if (noun[i].pullable) printf(" pull ");
357 if (noun[i].turnable) printf(" turn ");
358 if (noun[i].playable) printf(" play ");
359 if (noun[i].readable) printf(" read ");
360 if (noun[i].closable) printf(" close ");
361 if (noun[i].lockable) printf(" lock ");
362 if (noun[i].edible) printf(" eat ");
363 if (noun[i].wearable) printf(" wear ");
364 if (noun[i].drinkable) printf(" drink ");
365 if (noun[i].movable) printf(" move ");
366 printf("\n ATT2:");
367 if (noun[i].on) printf(" on ");
368 if (noun[i].open) printf(" open ");
369 if (noun[i].locked) printf(" locked ");
370 if (noun[i].poisonous) printf(" poison ");
371 if (noun[i].light) printf(" light ");
372 if (noun[i].shootable) printf(" shoot ");
373 if (noun[i].isglobal) printf(" global ");
374 printf("\n");
375 if (noun[i].has_syns) {
376 printf(" Syns:");
377 print_slist(noun[i].syns);printf("\n");
378 }
379 if (ver==3)
380 printf(" Initial=%d Picture=%d Related->%d\n",
381 noun[i].initdesc,noun[i].pict,noun[i].related_name);
382 dump_attr(1,i+first_noun);
383 if (verbose_dump) {
384 print_descr("DESCR:",noun_ptr[i],2);
385 print_descr("TEXT:",text_ptr[i],noun[i].readable);
386 print_descr("PUSH:",push_ptr[i],noun[i].pushable);
387 print_descr("PULL:",pull_ptr[i],noun[i].pullable);
388 print_descr("TURN:",turn_ptr[i],noun[i].turnable);
389 print_descr("PLAY:",play_ptr[i],noun[i].playable);
390 }
391 }
392 }
393
394 void creat_out(void)
395 {
396 int i;
397 printf("\n\nCreature List:");
398 for(i=0;i<maxcreat-first_creat+1;i++)
399 {
400 /* if (badname((uchar*)creature[i].shortdesc)) continue;*/
401 if (creature[i].unused) continue;
402 printf("\nCREATURE: %d:%s %s",i+first_creat,
403 dict[creature[i].adj],dict[creature[i].name]);
404 if (creature[i].oclass!=0)
405 printf(" (Class:%d)",creature[i].oclass);
406 if (creature[i].flagnum!=0)
407 printf(" [flag %d]",creature[i].flagnum);
408 printf("\n%s\n",creature[i].shortdesc);
409 printf(" ATTR:");
410 if (creature[i].groupmemb) printf(" grp ");
411 if (creature[i].hostile) printf(" hostile ");
412 if (creature[i].gender==0) printf(" thing ");
413 else if (creature[i].gender==1) printf(" woman ");
414 else printf(" man ");
415 if (creature[i].has_syns) printf(" syns ");
416 if (creature[i].isglobal) printf(" global ");
417 printf("\n");
418 printf(" Loc=%d Weap=%d Points=%d",
419 creature[i].location,creature[i].weapon,creature[i].points);
420 if (creat_inside!=NULL)
421 printf(" #Nouns=%d\n",creat_inside[i]);
422 else printf("\n");
423 printf(" Thres=%d(%d) TimeThres=%d(%d)\n",
424 creature[i].threshold,creature[i].counter,creature[i].timethresh,
425 creature[i].timecounter);
426 if (creature[i].has_syns) {
427 printf(" Syns:");
428 print_slist(creature[i].syns);printf("\n");
429 }
430 if (ver==3) printf(" Initial=%d Pict=%d\n",
431 creature[i].initdesc,creature[i].pict);
432 dump_attr(2,i+first_creat);
433 if (verbose_dump) {
434 print_descr("DESCR:",creat_ptr[i],2);
435 print_descr("TALK:",talk_ptr[i],1);
436 print_descr("ASK:",ask_ptr[i],1);
437 }
438 }
439 }
440
441 static void fake_noun_out(void)
442 {
443 int i;
444
445 if (globalnoun!=NULL && numglobal>0) {
446 printf("\n\nGLOBAL NOUNS:\n");
447 for(i=0;i<numglobal;i++)
448 printf(" %s\n",dict[globalnoun[i]]);
449 }
450 for(i=0;i<MAX_FLAG_NOUN && flag_noun[i]==0;i++);
451 if (i<MAX_FLAG_NOUN) {
452 printf("\n\nFLAG NOUNS:\n");
453 for(;i<MAX_FLAG_NOUN;i++)
454 if (flag_noun[i]!=0)
455 printf(" %2d: %-25s(%08lx)\n",i,dict[flag_noun[i]],1L<<i);
456 }
457 }
458
459
460 static void print_message_range(int msg1,int msg2)
461 {
462 int i;
463 if (msg1<1) return;
464 if (msg1>last_message) return;
465 for(i=msg1;i<=msg2;i++) {
466 printf("\n\t");
467 argout(AGT_MSG,i,0);
468 }
469 }
470
471 void cmd_codes_out(integer *clist,int cnt)
472 {
473 int ip,j;
474 const opdef *opdata;
475 char endflag;
476 char save_dbg_nomsg;
477 int op, optype;
478
479 ip=0;endflag=0;
480 save_dbg_nomsg=0; /* Just to silence compiler warnings */
481 while(ip<cnt && !endflag) {
482 printf(" %2d:",ip);
483 op=clist[ip]%2048;
484 optype=clist[ip]/2048;
485 opdata=get_opdef(op);
486 ip++;
487 if (opdata==&illegal_def)
488 printf("ILLEGAL %d\n",op);
489 else {
490 if (op>=END_ACT) { /* End codes */
491 /* Magx games support Goto commands, so we can't stop just
492 because we hit an end code-- it might be possible to jump
493 beyond it. */
494 if (aver<AGX00) endflag=1;
495 printf("!");
496 }
497 else if (op<=MAX_COND) printf("?");
498 printf("%s",opdata->opcode);
499 if (op==1063 && !quick_rndmsg) {
500 save_dbg_nomsg=dbg_nomsg;
501 dbg_nomsg=1;
502 }
503 for(j=0;j<opdata->argnum;j++) {
504 printf("\t");
505 if (ip<cnt || (optype&4))
506 ip+=argout(j==0 ? opdata->arg1 : opdata->arg2 ,
507 ip<cnt ? clist[ip] : 0, optype>>2);
508 optype=optype<<2;
509 }
510 if (op==1063 && !quick_rndmsg) {
511 dbg_nomsg=save_dbg_nomsg;
512 if (optype==0 && !dbg_nomsg && dbg_msgrange && ip>=2)
513 print_message_range(clist[ip-2],clist[ip-1]);
514 }
515 printf("\n");
516 }
517 }
518 }
519
520
521
522 void raw_cmd_codes_out(integer *clist,int cnt)
523 {
524 int j,col;
525
526 printf(" "); col=5;
527 for(j=0;j<cnt;j++)
528 {
529 if (col>70) {
530 if (j>200) break;
531 printf("\n ");
532 col=5;
533 }
534 printf(" %04d",clist[j]);col+=6;
535 }
536 printf("\n");
537 if (j!=cnt)
538 printf(" .... <Continues for %d more tokens> ....\n",cnt-j);
539 }
540
541 /* This is called from the disassembler */
542 void print_tos(void)
543 {
544 printf("TOS"); /* Reference to the Top of Stack */
545 }
546
547 void commands_out(void)
548 {
549 int i, v, a;
550 word w;
551 rbool noncanon; /* Header verb-code != verb-word */
552
553 printf("\nCommands:\n");
554 if (last_cmd==0) {
555 printf("<None>\n");
556 return;
557 }
558 for(i=0;i<last_cmd;i++)
559 {
560 /* Decode dummy verbs */
561 v=verb_code(command[i].verbcmd);
562 w=command[i].verbcmd;
563 noncanon=(w!=syntbl[auxsyn[v]]);
564 if (noncanon && v!=0) {
565 printf("NONCANONICAL HEADER:");
566 printf(" %d:%s instead of %d:%s\n",w,dict[w],syntbl[auxsyn[v]],
567 dict[syntbl[auxsyn[v]]]);
568 }
569 if (v>=BASE_VERB && v<BASE_VERB+DUMB_VERB && syntbl[synlist[v]]!=0)
570 w=syntbl[synlist[v]]; /* Replace dummy verbs with their first
571 synonyms */
572
573 if (command[i].actor>0) {
574 printf("CMD %d: ",i);
575 a=command[i].actor;
576 } else {
577 printf("REDIR: ");
578 a=-command[i].actor;
579 }
580 if (a==2)
581 printf("anybody, ");
582 else if (a>2) {
583 char *name;
584 name=objname(a);
585 name[0]=toupper(name[0]);
586 printf("%s, ",name);
587 rfree(name);
588 }
589
590 /* Now to print out the actually command to be matched. */
591 printf("%s",dict[w]);
592 if (noncanon) printf("[%d]",v);
593 printf(" ");
594 if (command[i].noun_adj!=0)
595 printf("%s ",gdict(command[i].noun_adj) );
596 printf("%s",gdict(command[i].nouncmd));
597 if (command[i].noun_obj!=0) printf("[%d]",command[i].noun_obj);
598 printf(" %s ",(ver==3) ? gdict(command[i].prep) : "->");
599 if (command[i].obj_adj!=0)
600 printf("%s ",gdict(command[i].obj_adj) );
601 printf("%s",gdict(command[i].objcmd) );
602 if (command[i].obj_obj!=0) printf("[%d]",command[i].obj_obj);
603
604 if (ver==3 ||agx_file) printf(" ===> %lx (%lx) [%d]\n",cmd_ptr[i],
605 cmd_ptr[i]*2-2,command[i].cmdsize);
606 else
607 printf("\n");
608 if (!RAW_CMD_OUT)
609 cmd_codes_out(command[i].data,command[i].cmdsize);
610 else
611 raw_cmd_codes_out(command[i].data,command[i].cmdsize);
612 }
613 }
614
615
616 void strings_out(void)
617 {
618 int i;
619 printf("\n\nStrings:\n");
620 if (userstr!=NULL)
621 for(i=0;i<MAX_USTR;i++)
622 printf("%d:%s\n",i+1,userstr[i]);
623 else printf(" <Not defined in this version of AGT>\n");
624 printf("\n");
625 }
626
627 void msg_out(void)
628 {
629 int i;
630 char s[50];
631
632 printf("\n\nMessages:\n");
633 for(i=0;i<last_message;i++) {
634 sprintf(s,"MSG %d",i+1);
635 print_descr(s,msg_ptr[i],2);
636 }
637 }
638
639
640 void stdmsg_out(void)
641 {
642 int i;
643 char s[50];
644
645 printf("\n\nStandard Error Messages:\n");
646 if (err_ptr==NULL) {
647 printf("<Not defined in this version of AGT>\n");
648 return;
649 }
650 for(i=0;i<NUM_ERR;i++) {
651 sprintf(s,"STD MSG %d",i+1);
652 print_descr(s,err_ptr[i],1);
653 }
654 }
655
656 void syn_out(void)
657 {
658 int i;
659 int num_verb;
660
661 num_verb=BASE_VERB+DVERB;
662 if (aver>=AGTME10) num_verb+=MAX_SUB;
663
664 build_verblist();
665
666 printf("\nSynonyms:\n");
667 for(i=0;i<num_verb;i++) {
668 printf("%s--",verblist[i]);
669 print_slist(synlist[i]);
670 printf("\n");
671 }
672 }
673
674 void prep_out(void)
675 {
676 int i;
677 if (num_prep==0) return;
678 printf("\nPrepositions:\n");
679 for(i=0;i<num_prep;i++) {
680 printf("%s ( ",dict[syntbl[userprep[i]]]);
681 print_slist(userprep[i]+1);
682 printf(" )\n");
683 }
684 }
685
686 void dict_out(void)
687 {
688 int i;
689
690 printf("\n\nDICTIONARY:\n");
691 for(i=0;i<dp;i++)
692 printf("%d: %s\n",i,dict[i]);
693 }
694
695
696 void propstr_out(long ptr, long cnt)
697 {
698 int i;
699 printf("%ld[%ld]",ptr,cnt);
700 if (cnt==0) return;
701 printf(": ");
702 for(i=0;i<cnt;i++)
703 printf("\"%s\" ",propstr[ptr+i]);
704 }
705
706
707 void propetc_out(void)
708 {
709 int i;
710 if (proptable) {
711 printf("\n\nObjProps:\n");
712 for(i=0;i<oprop_cnt;i++) {
713 printf("%2d: ",i);
714 propstr_out(proptable[i].str_list,proptable[i].str_cnt);
715 printf("\n");
716 }
717 }
718 if (attrtable) {
719 printf("\n\nObjFlags:\n");
720 for(i=0;i<oflag_cnt;i++) {
721 printf("%2d: ",i);
722 printf("\"%s\" / \"%s\"",attrtable[i].ystr,attrtable[i].nstr);
723 printf("\n");
724 }
725 }
726 if (vartable) {
727 printf("\n\nItemized Variables:\n");
728 for(i=0;i<=VAR_NUM;i++) {
729 printf("%3d: ",i);
730 if (vartable[i].str_cnt>0) {
731 propstr_out(vartable[i].str_list,vartable[i].str_cnt);
732 printf("\n");
733 }
734 }
735 }
736 if (flagtable) {
737 printf("\n\nItemized Flags:\n");
738 for(i=0;i<=FLAG_NUM;i++) {
739 printf("%3d: ",i);
740 if (flagtable[i].ystr!=NULL || flagtable[i].nstr!=NULL) {
741 printf("\"%s\" / \"%s\"",flagtable[i].ystr,flagtable[i].nstr);
742 printf("\n");
743 }
744 }
745 }
746 }
747
748
749
750
751 rbool end_cmd_options;
752
753 void helpmsg(void)
754 {
755 printf("Syntax: agtout <options> <game name>\n");
756 printf("Options:\n");
757 printf("(all of these can be turned off by putting a - after the option)\n");
758 printf("-v Verbose: equivalent to -dmia\n");
759 printf("-i Print basic diagnostic information\n");
760 printf("-d Print out dictionary\n");
761 printf("-m Dump messages\n");
762 printf("-o Try to avoid printing 'undefined' objects.\n");
763 printf("-s Show all possible messages printed out by RandomMessage.\n");
764 printf("-q Quick RandomMessage printout (only show actual arguments).\n");
765 printf("-u Leave commands unsorted.\n");
766 printf("-x Examine .DA1 file as it is read (implies -i).\n");
767 printf("-a Interpret arguments to metacommands (implies -r-).\n");
768 printf("-r Raw command out: don't disassemble metacommands (implies -a-)\n");
769 }
770
771 static rbool setarg(char **optptr)
772 {
773 if ( (*optptr)[1]=='+') {(*optptr)++;return 1;}
774 if ( (*optptr)[1]=='-') {(*optptr)++;return 0;}
775 return 1;
776 }
777
778 void parse_options(char *opt,char *next)
779 {
780 if (opt[0]=='-' && opt[1]==0) /* -- */
781 {end_cmd_options=1;return;}
782 for(;*opt!=0;opt++)
783 switch(tolower(*opt))
784 {
785 case 'v':
786 printdict=1; printmsg=1; DIAG=1;
787 interp_arg=1;
788 break;
789 case '?': case 'h':
790 helpmsg();
791 exit(EXIT_SUCCESS);
792 case 'd': printdict=setarg(&opt);break;
793 case 's': dbg_msgrange=setarg(&opt);break;
794 case 'q': quick_rndmsg=setarg(&opt);break;
795 case 'm': printmsg=setarg(&opt);break;
796 case 'i': DIAG=setarg(&opt);break;
797 case 'o': no_badobj=setarg(&opt); break;
798 case 'a': interp_arg=setarg(&opt);
799 if (interp_arg) RAW_CMD_OUT=0;
800 break;
801 case 'x': debug_da1=setarg(&opt);
802 if (debug_da1) DIAG=1;
803 break;
804 case 'r': RAW_CMD_OUT=setarg(&opt);
805 if (RAW_CMD_OUT) interp_arg=0;
806 break;
807 case 'u': sortflag=!setarg(&opt);break;
808 #ifdef OPEN_FILE_AS_TEXT
809 case 'b': open_as_binary=setarg(&opt);break;
810 #endif
811 default:printf("Do not recognize option %c\n",*opt);
812 helpmsg();
813 exit(EXIT_FAILURE);
814 }
815 }
816
817
818 int main(int argc,char *argv[])
819 {
820 int i;
821 char *gamefile;
822 fc_type fc;
823
824 end_cmd_options=0;
825
826 init_flags();
827 debug_mode=1; /* Unless something turns it off explictly */
828 build_trans_ascii();
829
830 printmsg=printdict=0;
831 sortflag=1;
832 dbg_msgrange=0; /* Don't print out message range for RandomMessage */
833 quick_rndmsg=0; /* Don't print out arguments to RandomMessage
834 (except perhaps the range above) */
835
836 printf("AGTOut: Prints contents of AGT files in human readable form\n");
837 printf("%s\n",version_str);
838 printf(" Copyright (C) 1996-1999,2001 Robert Masenten\n");
839 printf("[%s]\n\n",portstr);
840
841 gamefile=NULL;
842 for(i=1;i<argc;i++)
843 if (argv[i][0]=='-' && !end_cmd_options)
844 parse_options(argv[i]+1,argv[i+1]);
845 else if (gamefile==NULL)
846 gamefile=argv[i];
847 else {helpmsg();exit(EXIT_FAILURE);}
848 if (gamefile==NULL)
849 {helpmsg();exit(EXIT_FAILURE);}
850
851 fc=init_file_context(gamefile,fDA1);
852 if (!read_agx(fc,1) && !readagt(fc,1))
853 fatal("Unable to open game file.");
854 #ifndef DEVEL_TEST
855 if (!debug_mode)
856 fatal("Disassembly blocked by game author.");
857 #endif
858
859 if (sortflag && !agx_file) sort_cmd();
860 if (!agx_file)
861 open_descr(fc);
862 info_out();
863 rooms_out();
864 nouns_out();
865 creat_out();
866 fake_noun_out(); /* Global and flag nouns */
867 printf("\n\n");
868
869 print_descr("INTRO:",intro_ptr,2);
870 commands_out();
871 if (printmsg) msg_out();
872 syn_out();
873 prep_out();
874 propetc_out();
875 strings_out();
876 if (printmsg) stdmsg_out();
877
878 if (agx_file)
879 agx_close_descr();
880 else
881 close_descr();
882
883 if (printdict) dict_out();
884 free_all_agtread();
885 return 0;
886 }
887