/************************/ /*** DataFile Creator ***/ /************************/ #include #include #include #include #include #include #include #include #include #include #include #include "Mkdata.h" using namespace std; //*********************************************************************** //*********************************************************************** //*********************************************************************** int DebugFlag=0; int AlignSize=2048; char *AlignBuffer; //*********************************************************************** CBank Banks; CFileList Files; char *BaseDir=0; //*********************************************************************** static void app_debug_msg(const char * pszFmt,va_list args) { char szBuf[256]; vsprintf(szBuf,pszFmt,args); printf("%s\n",szBuf); } //****************************************************************** //****************************************************************** void __cdecl DEBUG(const char * pszFmt,...) { if (DebugFlag) if (pszFmt) { va_list args; va_start(args,pszFmt); app_debug_msg(pszFmt,args); va_end(args); } } void __cdecl FATAL(const char * pszFmt,...) { if (pszFmt) { va_list args; va_start(args,pszFmt); app_debug_msg(pszFmt,args); va_end(args); } exit(123); } //****************************************************************** char *LoadFileInMem(const char * FileName,int *OutSize) { FILE *FileHandle; char *Buffer; int Size; FileHandle= fopen( FileName,"rb" ); if(!FileHandle) { FATAL("ERROR : Could not open file %s\n",FileName); } else { fseek(FileHandle,0,SEEK_END); Size=ftell(FileHandle); fseek(FileHandle,0,SEEK_SET); if( (Buffer=(char*)malloc(Size))==NULL ) {printf("Out of memory.\n");exit(123);} fread(Buffer, 1,Size,FileHandle); fclose(FileHandle); } if (OutSize) *OutSize=Size; return Buffer; } //****************************************************************** static char s_illegalChars[] = "\\/!£$%^&*()+-=-:. "; static int s_nbChars = sizeof(s_illegalChars); void convertIllegalChar( char *c ) { for (int i=0;i=EndPtr) return; switch (*Ptr) { case CHAR_COMMENT: Ptr=ScriptComment(Ptr,EndPtr); break; case CHAR_STARTBANK: Ptr=ScriptStartBank(Ptr,EndPtr); break; case CHAR_ENDBANK: Ptr=ScriptEndBank(Ptr,EndPtr); break; default: Ptr=ScriptFile(Ptr,EndPtr); break; } } free(Script); } //*********************************************************************** //*********************************************************************** //*********************************************************************** void ResetFAT(std::vector &FAT) { int FATSize=Files.GetCount(); int Loop; FAT.resize(FATSize); for (Loop=0; Loop &FAT,int Align) { int Pos=ftell(FileHandle); int FATSize=Files.GetCount(); for (int Loop=0;Loop FAT; sBank &ThisBank=Banks.GetBank(BankIdx); int ThisListSize=ThisBank.FileList.size(); int Loop; long StartFilePos,EndFilePos; // reset FAT and write dummy FAT ResetFAT(FAT); ParentFAT.FilePos=WriteFAT(FileHandle,FAT,ThisBank.Align); StartFilePos=ftell(FileHandle);; // Write files for (Loop=0; Loop FAT; int FATSize=Files.GetCount(),Idx; FileHandle= fopen( Filename,"wb" ); if(!FileHandle) FATAL( "Could not write %s", Filename); ResetFAT(FAT); WriteFAT(FileHandle,FAT,AlignSize); for (Idx=0; Idx Scripts; // Parse Input for (int Loop=1;Loop