/* AGT2AGX, AGT to AGX file converter */ /* Copyright (C) 1996-1999,2001 Robert Masenten */ /* This program may be redistributed under the terms of the GNU General Public License, version 2; see agility.h for details. */ /* */ /* This is part of the source for AGiliTy, the (Mostly) Universal */ /* AGT Interpreter */ #include #define global #include "agility.h" static long cntvar, cntflag, cntcnt, cntquest, cntstr, cntsub; /* We can't count messages because they can be referenced by variable */ #define m(cnt) do {if (arg>cnt) cnt=arg; return;} while(0) void check_arg(integer argtype, integer arg) { if (argtype & AGT_VAR) argtype=AGT_VAR; switch(argtype) { case AGT_VAR:m(cntvar); case AGT_FLAG:m(cntflag); case AGT_CNT:m(cntcnt); case AGT_QUEST:m(cntquest); case AGT_STR:m(cntstr); case AGT_SUB:m(cntsub); #if 0 /* These are already taken care of AFAIK */ case AGT_PIC:m(cntpic); case AGT_PIX:m(cntpix); case AGT_FONT:m(cntfont); case AGT_SONG:m(cntsong); case AGT_ROOMFLAG:m(cntroomflag); #endif default:break; } } #undef m /* AGT stores a lot of junk in the command blocks. This shortens the command blocks to their real length (Determined by scanning for end markers). */ /* This also analyzes commands to determine the maximum variable,flag,counter,question,and userstr used. */ void truncate_cmd(void) { int i, j; const opdef *opdata; cntvar=cntflag=cntcnt=cntquest=cntstr=cntsub=0; for(i=0;i=END_ACT) break; opdata=get_opdef(command[i].data[j++]); if (opdata==&illegal_def) agtwarn("Illegal opcode found.",1); if (j+opdata->argnum>command[i].cmdsize || opdata==&illegal_def) { j=command[i].cmdsize; /* To prevent cmdsize from being changed */ if (!(opdata==&illegal_def)) agtwarn("Command block overrun",0); break; } /* Note: j now points to the token *after* the opcode */ if (opdata->argnum>=1) { check_arg(opdata->arg1,command[i].data[j++]); if (opdata->argnum>=2) check_arg(opdata->arg2,command[i].data[j++]); } } if (jcntvar) VAR_NUM=cntvar; if (FLAG_NUM>cntflag) FLAG_NUM=cntflag; if (CNT_NUM>cntcnt) CNT_NUM=cntcnt; if (MAX_USTR>cntstr) MAX_USTR=cntstr; if (MAX_SUB>cntsub) MAX_SUB=cntsub; if (MaxQuestion>cntquest) MaxQuestion=cntquest; } /* This transfers descriptions from an AGT D$$ file to our AGX file */ /* Note that this overwrites the descr_ptr it is sent */ void copydesc(descr_ptr *descp,int num) { int i; descr_line *txt; if (num<=0 || descp==NULL) return; for(i=0;i \n"); printf("Options:\n"); printf("(all of these can be turned off by putting a - after the option)\n"); printf("-h Print this help message.\n"); printf("-o Specify output file root.\n"); #ifdef OPEN_AS_TEXT printf(" -b Open data files as binary files.\n"); #endif } char *outname; /* Name of output file */ int parse_options(char *opt,char *next) { if (opt[0]=='-' && opt[1]==0) /* -- */ {end_cmd_options=1;return 0;} for(;*opt!=0;opt++) switch(tolower(*opt)) { case '?': case 'h': helpmsg(); exit(EXIT_SUCCESS); case 'i': if (opt[1]=='-') {DIAG=0;opt++;} else if (opt[1]=='+') {DIAG=1;opt++;} else DIAG=1; break; #ifdef OPEN_FILE_AS_TEXT case 'b': if (opt[1]=='-') {open_as_binary=0;opt++;} else if (opt[1]=='+') {open_as_binary=1;opt++;} else open_as_binary=1; break; #endif case 'o': if (opt[1]!=0 || next!=NULL) { if (opt[1]!=0) outname=opt+1; else outname=next; return (opt[1]==0); /* Skip next argument if opt[1]==0 */ } else { printf("-o requires a file name\n"); exit(EXIT_FAILURE); } default:printf("Do not recognize option %c\n",*opt); helpmsg(); exit(EXIT_FAILURE); } return 0; } int main(int argc,char *argv[]) { int i; char *gamefile; fc_type fc, fc_out; end_cmd_options=0; init_flags(); no_auxsyn=1; fix_ascii_flag=0; /* We don't want to translate the character set when we're converting files */ /* Mark all of the purity settings as "undecided" */ PURE_ANSWER=PURE_TIME=PURE_ROOMTITLE=2; PURE_AND=PURE_METAVERB=PURE_SYN=PURE_NOUN=PURE_ADJ=2; PURE_DUMMY=PURE_SUBNAME=PURE_PROSUB=PURE_HOSTILE=2; PURE_GETHOSTILE=PURE_DISAMBIG=PURE_ALL=2; irun_mode=verboseflag=2; build_trans_ascii(); printf("agt2agx: Convert AGT game files into AGX files\n"); printf("%s\n",version_str); printf(" Copyright (C) 1996-1999,2001 Robert Masenten\n"); printf("[%s]\n\n",portstr); outname=gamefile=NULL; for(i=1;i