#include "WriteMainFile.h" #include "Tools.h" #include "MB_protos.h" #include "MB_pragmas.h" #include "mb.h" #include #include #include #include extern void Quit(void); #define HEADER_END_MSG "/* GenCodeC header end */" #define HEADER_END HEADER_END_MSG "\n" #define LIBRARY_DECLARATION_MSG "/* Declarations for libraries (inserted by GenCodeC) */" #define LIBRARY_DECLARATION LIBRARY_DECLARATION_MSG "\n" #define LIBRARY_MUI_MSG "struct Library * MUIMasterBase" #define LIBRARY_MUI LIBRARY_MUI_MSG ";\n" #define LIBRARY_LOCALE_MSG "struct Library * LocaleBase" #define LIBRARY_LOCALE LIBRARY_LOCALE_MSG ";\n" #define OPEN_LOCALE_LIBRARY_MSG "if (!(LocaleBase = OpenLibrary(\"locale.library\",38)))" #define OPEN_LOCALE_LIBRARY "\t" OPEN_LOCALE_LIBRARY_MSG "\n" #define CLOSE_LOCALE_LIBRARY_MSG "CloseLibrary(LocaleBase)" #define CLOSE_LOCALE_LIBRARY CLOSE_LOCALE_LIBRARY_MSG ";\n" #define INIT_BEGIN_MSG "/* Init() function */" #define INIT_BEGIN "\n" INIT_BEGIN_MSG "\n" #define INIT_END_MSG "/* GenCodeC init() end */" #define INIT_END "}\n" INIT_END_MSG "\n" #define END_BEGIN_MSG "/* End() function */" #define END_BEGIN "\n" END_BEGIN_MSG "\n" #define END_FUNCTION_MSG "void end( void )" #define END_FUNCTION END_FUNCTION_MSG "\n{\n" #define END_END_MSG "/* GenCodeC end() end */" #define END_END "}\n" END_END_MSG "\n" #define OPEN_CATALOG_MSG "OpenAppCatalog(NULL,NULL)" #define OPEN_CATALOG OPEN_CATALOG_MSG ";\n" #define CLOSE_CATALOG_MSG "CloseAppCatalog()" #define CLOSE_CATALOG "\t" CLOSE_CATALOG_MSG ";\n" #define CASE_BEGIN_MSG "/* Insert your code between the \"case\" statement and comment \"end of case ...\" */" #define CASE_BEGIN CASE_BEGIN_MSG "\n" #define CASE_END_MSG "/* End computing of IDCMP */" #define CASE_END CASE_END_MSG "\n" /****************************************************************************************************************/ /***** *****/ /** WriteIDCMP **/ /***** *****/ /****************************************************************************************************************/ static void WriteIDCMP(FILE *file,char *adr_file,char *buf,ULONG varnb) { int i; char *name; char *tmp; ULONG type; char *str; char *str1; char ctmp; /* Write IDCMPs */ for(i=0;i%s,MUIM_Application_Input,&signal))\n",name,name); fprintf(file,"\t\t{\n"); fprintf(file,"\t\t\tcase MUIV_Application_ReturnID_Quit:\n"); fprintf(file,"\t\t\t\trunning = FALSE;\n"); fprintf(file,"\t\t\t\tbreak;\n\n"); fprintf(file,"\t\t\t%s",CASE_BEGIN); } else { str = CopyBlock(file,adr_file,str,END_END,CASE_BEGIN, END_END_MSG,CASE_BEGIN_MSG,MainFile); fprintf(file,CASE_BEGIN); } if (!OldMainExists) WriteIDCMP(file,adr_file,adr_file,varnb); else WriteIDCMP(file,adr_file,str,varnb); if (!OldMainExists) { fprintf(file,"\t\t\t/* End computing of IDCMP */\n"); fprintf(file,"\t\t}\n"); fprintf(file,"\t\tif (running && signal) Wait(signal);\n"); fprintf(file,"\t}\n"); fprintf(file,"\tDispose%s(%s);\n",name,name); fprintf(file,"\tend();\n"); fprintf(file,"}\n"); } else { fprintf(file,"\t\t\t%s",CASE_END); CopyBlock(file,adr_file,str,CASE_END,NULL, CASE_END_MSG,NULL,MainFile); } } /****************************************************************************************************************/ /***** *****/ /** WriteMainFile **/ /***** *****/ /****************************************************************************************************************/ void WriteMainFile(char *HeaderFile,char *MainFile,char *MainHeaderText,ULONG varnb,BOOL Locale) { ULONG length; BPTR TMPfile; BPTR BakFile; char *adr_file = NULL; char *str; __aligned struct FileInfoBlock Info; char *buffer = NULL; char *name = NULL; BOOL OldMainExists = FALSE; FILE *file; /* If the file already exists, we load it in memory and we save it in a .bak file*/ if (TMPfile = Open(MainFile, MODE_OLDFILE)) { OldMainExists = TRUE; ExamineFH(TMPfile, &Info); length = Info.fib_Size; if (!(adr_file = AllocMemory(length+1))) { Close(TMPfile); Quit(); } Read( TMPfile, adr_file, length); adr_file[length] = '\0'; Close(TMPfile); if (!(buffer = AllocMemory(strlen(MainFile)+4+1))) { Close(TMPfile); Quit(); } strcpy(buffer,MainFile); strcat(buffer,".bak"); if (BakFile = Open(buffer,MODE_NEWFILE)) { Write(BakFile,adr_file,length); Close(BakFile); } FreeMemory(buffer); } MB_GetVarInfo(0, MUIB_VarName, &name, TAG_END); if (file = fopen(MainFile,"w")) { fprintf(file,"/* Main-Header File inserted by GenCodeC */\n"); /* Copy Main-Header into MainFile */ fprintf(file,"%s",MainHeaderText); fprintf(file,HEADER_END); str = WriteIncludes(file,adr_file,HeaderFile,MainFile,OldMainExists); str = WriteDeclarations(file,adr_file,str,MainFile,OldMainExists,Locale); str = WriteInitFunction(file,adr_file,str,MainFile,OldMainExists,Locale); if (OldMainExists) str = CopyBlock(file,adr_file,str,INIT_END,END_BEGIN, INIT_END_MSG,END_BEGIN_MSG,MainFile); str = WriteEndFunction(file,adr_file,str,MainFile,OldMainExists,Locale); WriteMainFunction(file,adr_file,str,MainFile,name,OldMainExists,varnb); fclose(file); FreeMemory(adr_file); } else DisplayMsg("Unable to create Main-File !\n"); }