#include "WriteGUIFiles.h" #include "MB_protos.h" #include "MB_pragmas.h" #include "mb.h" #include "MB_MUI_Strings.h" #include "Tools.h" #include #include #include #include #include extern void Quit(void); extern struct Library * MUIBBase; /* variable types */ static char *STR_type[] = { "BOOL", "int", "char *", "char *", "APTR", "", "", "", "APTR", "APTR" }; /****************************************************************************************************************/ /***** *****/ /** WriteParameters **/ /***** *****/ /****************************************************************************************************************/ static void WriteParameters(FILE *file,ULONG varnb,BOOL Notifications) { int i; char *varname, *typename; ULONG type,size; BOOL comma = FALSE; typename = STR_type[ TYPEVAR_EXTERNAL_PTR - 1 ]; if (Notifications) { for(i=0;i=70) { fprintf(file, "%s;\n", buffer); FreeMemory(buffer); buffer = NULL; } break; case TYPEVAR_HOOK: fprintf(file, "\tstatic struct Hook %sHook;\n", varname); break; default: fprintf(file, "\t%s\t%s;\n",typename, varname); break; } } } if (buffer && strlen(buffer)>0) fprintf(file, "%s;\n", buffer); FreeMemory(buffer); } /****************************************************************************************************************/ /***** *****/ /** WriteInitialisations **/ /***** *****/ /****************************************************************************************************************/ static void WriteInitialisations(FILE *file,ULONG varnb,int vartype,BOOL Locale,char *GetMBString) { int i, j; ULONG type, size; char *inits, *name; BOOL enter = FALSE; for(i=0;i%s[%d] = \"%s\";\n", name, j, inits); else fprintf(file, "\tObject->%s[%d] = %s(%s);\n", name, j, GetMBString, inits); inits = inits + strlen(inits) + 1; } fprintf(file, "\tObject->%s[%d] = NULL;\n", name, j); break; case TYPEVAR_STRING: if (*inits != 0) { if (!Locale) fprintf(file, "\tObject->%s = \"%s\";\n", name, inits); else fprintf(file, "\tObject->%s = %s(%s);\n", name, GetMBString, inits); } else fprintf(file, "\tObject->%s = NULL;\n", name); break; case TYPEVAR_HOOK: fprintf(file, "\tInstallHook(&%sHook,%s,NULL);\n", name, name); break; default: break; } } } if (enter) fprintf(file, "\n"); } /****************************************************************************************************************/ /***** *****/ /** WriteCode **/ /***** *****/ /****************************************************************************************************************/ static void WriteCode(FILE *file,char *GetString,char *GetMBString) { ULONG type; char* code; BOOL InFunction = FALSE; BOOL IndentFunction = TRUE ; BOOL obj_function; BOOL InObj; int nb_indent = 1; int nb_function = 0; int name; MB_GetNextCode(&type, &code); while(type != -1) { switch(type) { case TC_CREATEOBJ: name = atoi(code); fprintf(file, "%s,\n",MUIStrings[name]); nb_indent++; IndentFunction = TRUE; MB_GetNextCode(&type, &code); InObj = TRUE; break; case TC_ATTRIBUT: Indent(file,nb_indent); name = atoi(code); fprintf(file, "%s, ",MUIStrings[name]); IndentFunction = FALSE; MB_GetNextCode(&type, &code); break; case TC_END: nb_indent--; InObj = FALSE; Indent(file,nb_indent); name = atoi(code); fprintf(file, "%s",MUIStrings[name]); IndentFunction = TRUE; MB_GetNextCode(&type, &code); fprintf(file, ";\n\n"); break; case TC_MUIARG_OBJFUNCTION: if (IndentFunction) Indent(file,nb_indent); nb_function++; name = atoi(code); fprintf(file, "%s(",MUIStrings[name]); IndentFunction = FALSE; MB_GetNextCode(&type, &code); obj_function = TRUE; InFunction = TRUE; break; case TC_MUIARG_FUNCTION: case TC_FUNCTION: if (IndentFunction) Indent(file,nb_indent); nb_function++; name = atoi(code); fprintf(file, "%s(",MUIStrings[name]); IndentFunction = FALSE; InFunction = TRUE; MB_GetNextCode(&type, &code); obj_function = FALSE; break; case TC_OBJFUNCTION: if (IndentFunction) Indent(file,nb_indent); nb_function++; name = atoi(code); fprintf(file, "%s(",MUIStrings[name]); InFunction = TRUE; IndentFunction = FALSE; MB_GetNextCode(&type,&code); obj_function = TRUE; break; case TC_STRING: fprintf(file, "\"%s\"",code); MB_GetNextCode(&type, &code); IndentFunction = TRUE; if (InFunction) { if (type != TC_END_FUNCTION) fprintf(file, ", "); IndentFunction = FALSE; } else fprintf(file, ",\n"); break; case TC_LOCALESTRING: fprintf(file, "%s(%s)",GetMBString, code); MB_GetNextCode(&type, &code); IndentFunction = TRUE; if (InFunction) { if (type != TC_END_FUNCTION) fprintf(file, ", "); IndentFunction = FALSE; } else fprintf(file, ",\n"); break; case TC_LOCALECHAR: fprintf(file, "%s(%s)[0]",GetString, code); MB_GetNextCode(&type, &code); IndentFunction = TRUE; if (InFunction) { if (type != TC_END_FUNCTION) fprintf(file, ", "); IndentFunction = FALSE; } else fprintf(file, ",\n"); break; case TC_INTEGER: fprintf(file, "%s", code); MB_GetNextCode(&type, &code); IndentFunction = TRUE; if (InFunction) { if (type != TC_END_FUNCTION) fprintf(file, ", "); IndentFunction = FALSE; } else fprintf(file, ",\n"); break; case TC_CHAR: fprintf(file, "'%s'",code); MB_GetNextCode(&type, &code); IndentFunction = TRUE; if (InFunction) { if (type != TC_END_FUNCTION) fprintf(file, ", "); IndentFunction = FALSE; } else fprintf(file, ",\n"); break; case TC_VAR_AFFECT: name = atoi(code); MB_GetVarInfo(name, MUIB_VarName, &code, MUIB_VarType, &type, TAG_END); if (type == TYPEVAR_LOCAL_PTR) fprintf( file, "\t%s = ", code); else fprintf(file, "\tObject->%s = ", code); IndentFunction = FALSE; MB_GetNextCode(&type, &code); break; case TC_OBJ_ARG: case TC_VAR_ARG: name = atoi(code); MB_GetVarInfo(name, MUIB_VarName, &code, MUIB_VarType, &type, TAG_END); if (type == TYPEVAR_LOCAL_PTR) fprintf(file, "%s", code); else fprintf(file, "Object->%s", code); MB_GetNextCode(&type, &code); if ((InFunction)&&(type != TC_END_FUNCTION)) fprintf(file, ", "); if (!InFunction) { fprintf(file, ",\n"); IndentFunction = TRUE; } break; case TC_END_FUNCTION: MB_GetNextCode(&type, &code); if (nb_function>1) { if (type != TC_END_FUNCTION) fprintf(file, "),"); else fprintf(file, ")"); } else { if (obj_function) fprintf(file, ");\n\n"); else fprintf(file, "),\n"); IndentFunction = TRUE; InFunction = FALSE; obj_function = FALSE; } nb_function--; break; case TC_BOOL: if (*code == '0') fprintf(file, "FALSE"); else fprintf(file, "TRUE" ); MB_GetNextCode(&type, &code); if (InFunction) { if (type != TC_END_FUNCTION) { fprintf(file, ", "); IndentFunction = FALSE; } } else fprintf(file, ",\n"); break; case TC_MUIARG: if (IndentFunction) Indent(file,nb_indent); name = atoi(code); fprintf(file, "%s", MUIStrings[name]); MB_GetNextCode(&type, &code); if (InFunction) { if (type != TC_END_FUNCTION) { fprintf(file, ", "); IndentFunction = FALSE; } } else { fprintf(file, ",\n"); IndentFunction = TRUE; } break; case TC_MUIARG_ATTRIBUT: if (IndentFunction) Indent(file,nb_indent); name = atoi(code); MB_GetNextCode(&type, &code); if (InObj) fprintf(file, "%s,\n", MUIStrings[name]); else { if (InFunction) { if (type != TC_END_FUNCTION) fprintf(file, "%s,", MUIStrings[name]); else fprintf(file, "%s", MUIStrings[name]); } else fprintf(file, "%s;\n\n", MUIStrings[name]); } break; case TC_MUIARG_OBJ: if (IndentFunction) Indent(file,nb_indent); name = atoi(code); MB_GetNextCode(&type, &code); fprintf(file, "%s;\n\n", MUIStrings[name]); break; case TC_EXTERNAL_FUNCTION: fprintf(file, "&%sHook", code); MB_GetNextCode(&type, &code); if (InFunction) { if (type != TC_END_FUNCTION) { fprintf(file, ", "); IndentFunction = FALSE; } } else { fprintf(file, ",\n"); IndentFunction = TRUE; } break; default: { char msg[80]; sprintf(msg,"Type = %d\nERROR !!!!! THERE IS A PROBLEM WITH THIS FILE !!!\n", type); DisplayMsg(msg); Quit(); } break; } } } /****************************************************************************************************************/ /***** *****/ /** WriteNotify **/ /***** *****/ /****************************************************************************************************************/ static void WriteNotify(FILE *file,char *GetString,char *GetMBString) { ULONG type; char* code; int name; BOOL indent = FALSE; fprintf(file, "\n"); MB_GetNextNotify(&type, &code); while(type != -1) { if (indent) fprintf(file, "\t\t"); indent = TRUE; switch(type) { case TC_END_FUNCTION: case TC_END_NOTIFICATION: fprintf(file, ");\n\n"); MB_GetNextNotify(&type, &code); indent = FALSE; break; case TC_BEGIN_NOTIFICATION: name = atoi(code); MB_GetVarInfo(name, MUIB_VarName, &code, MUIB_VarType, &type, TAG_END); if (type == TYPEVAR_LOCAL_PTR) fprintf(file, "\tDoMethod(%s,\n", code); else fprintf(file, "\tDoMethod(Object->%s,\n", code); MB_GetNextNotify(&type, &code); break; case TC_FUNCTION: name = atoi(code); fprintf(file, "\t%s(", MUIStrings[name]); MB_GetNextNotify(&type, &code); indent = FALSE; break; case TC_STRING: fprintf(file, "\"%s\"",code); MB_GetNextNotify(&type, &code); if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) fprintf(file, ",\n"); else fprintf(file, "\n"); break; case TC_LOCALESTRING: fprintf(file, "%s(%s)",GetMBString, code); MB_GetNextNotify(&type, &code); if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) fprintf(file, ",\n"); else fprintf(file, "\n"); break; case TC_LOCALECHAR: fprintf(file, "%s(%s)[0]",GetString, code); MB_GetNextNotify(&type, &code); if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) fprintf(file, ",\n"); else fprintf(file, "\n"); break; case TC_INTEGER: fprintf(file, "%s", code); MB_GetNextNotify(&type, &code); if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) fprintf(file, ",\n"); else fprintf(file, "\n"); break; case TC_CHAR: fprintf(file, "'%s'",code); MB_GetNextNotify(&type, &code); if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) fprintf(file, ",\n"); else fprintf(file, "\n"); break; case TC_VAR_ARG: name = atoi(code); MB_GetVarInfo(name, MUIB_VarName, &code, MUIB_VarType, &type, TAG_END); if ((type==TYPEVAR_LOCAL_PTR)||(type==TYPEVAR_EXTERNAL_PTR)) fprintf(file, "%s", code); else fprintf(file, "Object->%s", code); MB_GetNextNotify(&type, &code); if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) fprintf(file, ",\n"); else fprintf(file, "\n"); break; case TC_BOOL: if (*code == '0') fprintf(file, "FALSE"); else fprintf(file, "TRUE" ); MB_GetNextNotify(&type, &code); if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) fprintf(file, ",\n"); else fprintf(file, "\n"); break; case TC_MUIARG: case TC_MUIARG_OBJ: name = atoi(code); fprintf(file, "%s", MUIStrings[name]); MB_GetNextNotify(&type, &code); if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) fprintf(file, ", "); indent = FALSE; break; case TC_MUIARG_ATTRIBUT: name = atoi(code); fprintf(file, "%s", MUIStrings[name]); MB_GetNextNotify(&type, &code); if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) fprintf(file, ",\n"); else fprintf(file, "\n"); break; case TC_EXTERNAL_CONSTANT: fprintf(file, "%s", code); MB_GetNextNotify(&type, &code); if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) fprintf(file, ",\n"); else fprintf(file, "\n"); break; case TC_EXTERNAL_FUNCTION: fprintf(file, "&%sHook", code); MB_GetNextNotify(&type, &code); if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) fprintf(file, ",\n"); else fprintf(file, "\n"); break; case TC_EXTERNAL_VARIABLE: fprintf(file, "%s", code); MB_GetNextNotify(&type, &code); if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) fprintf(file, ",\n"); else fprintf(file, "\n"); break; default: { char msg[80]; sprintf(msg,"Type = %d\nERROR !!!!! THERE IS A PROBLEM WITH THIS FILE !!!\n", type); DisplayMsg(msg); Quit(); } break; } } } /****************************************************************************************************************/ /***** *****/ /** WriteHeaderFile **/ /***** *****/ /****************************************************************************************************************/ void WriteHeaderFile(char *HeaderFile,char *HHeaderText,char *FileName,ULONG varnb, BOOL Env,BOOL Notifications,BOOL Locale) { char *name; FILE *file; file = fopen(HeaderFile, "w+"); if (file) { fprintf(file,"#ifndef GUI_FILE_H\n"); fprintf(file,"#define GUI_FILE_H\n\n"); if (Env) fprintf(file,"%s",HHeaderText); if (Locale) fprintf(file, "#include \"%s_cat.h\"\n\n",FilePart(FileName)); MB_GetVarInfo(0, MUIB_VarName, &name, TAG_END); fprintf(file, "struct Obj%s\n{\n", name); WriteDeclarations(file,varnb,TYPEVAR_PTR); WriteDeclarations(file,varnb,TYPEVAR_BOOL); WriteDeclarations(file,varnb,TYPEVAR_INT); WriteDeclarations(file,varnb,TYPEVAR_STRING); WriteDeclarations(file,varnb,TYPEVAR_TABSTRING); fprintf(file, "};\n\n"); if (Notifications) { WriteDeclarations(file,varnb,TYPEVAR_IDENT); fprintf(file, "\n"); } if (Env) { fprintf(file,"extern struct Obj%s * Create%s(",name,name); WriteParameters(file,varnb,Notifications); fprintf(file,");\n"); fprintf(file,"extern void Dispose%s(struct Obj%s *);\n", name, name); } fprintf(file,"\n#endif\n"); fclose(file); } } /****************************************************************************************************************/ /***** *****/ /** WriteGUIFile **/ /***** *****/ /****************************************************************************************************************/ void WriteGUIFile(char *MBDir,char *HeaderFile,char *GUIFile,char *CHeaderText, char *Externals,char *GetString,char *GetMBString, ULONG varnb, BOOL ExternalExist,BOOL Env,BOOL Locale,BOOL Declarations,BOOL Code,BOOL Notifications) { char *name; FILE *file; char *FromHookfile; char *ToHookfile; int i; ULONG type; size_t length; BOOL HookExist; if (file = fopen(GUIFile, "w+")) { if (Env) { fprintf(file,"%s",CHeaderText); MB_GetVarInfo(0, MUIB_VarName, &name, TAG_END); fprintf(file, "\n#include \"%s\"\n", FilePart(HeaderFile)); if (ExternalExist) fprintf(file, "#include \"%s\"\n", FilePart(Externals)); for(i = 0, HookExist = FALSE; !HookExist && i%s)\n\t{\n\t\tFreeVec(Object);", name); fprintf(file, "\n\t\treturn(NULL);\n\t}\n"); } if (Notifications) WriteNotify(file,GetString,GetMBString); if (Env) { fprintf(file, "\n\treturn(Object);\n}\n"); fprintf(file, "\nvoid Dispose%s(struct Obj%s * Object)\n{\n", name, name); fprintf(file, "\tMUI_DisposeObject(Object->%s);\n", name); fprintf(file, "\tFreeVec(Object);\n}\n"); } fclose(file); } else DisplayMsg("Unable to open GUI-File !\n"); }