ChangeCh(mainModuleName, '-', '_');
ChangeCh(mainModuleName, ' ', '_');
- if(i18n)
- f.Puts("#include <libintl.h>\n\n");
if(targetPlatform == win32 && !isConsole && !isStaticLibrary && !isDynamicLibrary)
{
//f.Puts("#include <windows.h>\n\n");
else
f.Puts(" __thisModule = __currentModule = module = __ecere_COM_Initialize(1, _argc, (void *)_argv);\n\n");
- if(i18n)
- {
- f.Printf(" bindtextdomain(\"%s\", \"%s\");\n", projectName, localeDir);
- f.Printf(" textdomain(\"%s\");\n", projectName);
- f.Printf(" bind_textdomain_codeset (\"%s\", \"utf-8\");\n", projectName);
- }
-
// First load all modules
if(_imports.count)
{
}
}
+ for(defModule = ::modules.first; defModule; defModule = defModule.next)
+ if(defModule.globalInstance)
+ {
+ if(!strcmp(defModule.name, "i18n"))
+ f.Printf(" __ecereCreateModuleInstances_i18n();\n");
+ }
+ if(i18n)
+ f.Printf(" LoadTranslatedStrings(module, \"%s\");\n", projectName);
if(isDynamicLibrary)
{
//f.Printf(" module._vTbl[10](module);\n");
if(defModule.globalInstance)
{
char moduleName[1024];
+ if(!strcmp(defModule.name, "i18n")) continue;
strcpy(moduleName, defModule.name);
ChangeCh(moduleName, ' ', '_');
ChangeCh(moduleName, '-', '_');
f.Puts(" {\n");
}
// Then check if there's any global instances to destroy
- if(::modules.count)
{
- for(defModule = ::modules.first; defModule; defModule = defModule.next)
- if(defModule.globalInstance)
- {
- char moduleName[1024];
- strcpy(moduleName, defModule.name);
- ChangeCh(moduleName, ' ', '_');
- ChangeCh(moduleName, '-', '_');
- ChangeCh(moduleName, '.', '_');
- f.Printf(" __ecereDestroyModuleInstances_%s();\n", moduleName);
- }
+ bool destroyI18n = false;
+ if(::modules.count)
+ {
+ for(defModule = ::modules.first; defModule; defModule = defModule.next)
+ if(defModule.globalInstance)
+ {
+ char moduleName[1024];
+ if(!strcmp(defModule.name, "i18n")) { destroyI18n = true; continue; }
+ strcpy(moduleName, defModule.name);
+ ChangeCh(moduleName, ' ', '_');
+ ChangeCh(moduleName, '-', '_');
+ ChangeCh(moduleName, '.', '_');
+ f.Printf(" __ecereDestroyModuleInstances_%s();\n", moduleName);
+ }
- f.Printf("\n");
+ f.Printf("\n");
+ }
+ if(i18n)
+ f.Printf(" UnloadTranslatedStrings(__currentModule);\n");
+ if(destroyI18n)
+ f.Printf(" __ecereDestroyModuleInstances_i18n();\n");
}
if(isDynamicLibrary)
{
f.Printf(" = 0");
f.Printf(";\n\n");
}
- //f.Printf(" incref this;\n");
+ f.Printf(" incref this;\n");
for(param = method.dataType.params.first; param; param = param.next)
{
char type[1024] = "";
}
f.Printf(" }\n");
f.Printf(" __ecereBuffer.Free();\n");
- //f.Printf(" delete this;\n");
+ f.Printf(" delete this;\n");
if(method.dataType.returnType.kind != voidType)
{
f.Printf(" return __ecereResult;\n");
static void BindDCOMServer()
{
+ bool mutexDeclared = false;
Class _class;
for(_class = privateModule.classes.first; _class; _class = _class.next)
{
// f.Printf("\n");
f.Printf(" virtual void CallMethod(uint __ecereMethodID, SerialBuffer __ecereBuffer)\n");
f.Printf(" {\n");
+ f.Printf(" %s inst = (%s)instance;\n", _class.fullName, _class.fullName);
+ f.Printf(" incref inst;\n");
f.Printf(" switch(__ecereMethodID)\n");
f.Printf(" {\n");
}
}
f.Printf(" }\n");
+ f.Printf(" delete inst;\n");
f.Printf(" }\n");
// *** VIRTUAL FUNCTIONS BINDINGS ***
break;
if(method)
{
+ if(!mutexDeclared)
+ {
+ DeclareClass(FindClass("ecere::sys::Mutex"), "__ecereClass___ecereNameSpace__ecere__sys__Mutex");
+ DeclareMethod(
+ eClass_FindMethod(
+ eSystem_FindClass(privateModule, "ecere::sys::Mutex"), "Wait", privateModule),
+ "__ecereMethod___ecereNameSpace__ecere__sys__Mutex_Wait");
+ DeclareMethod(
+ eClass_FindMethod(
+ eSystem_FindClass(privateModule, "ecere::sys::Mutex"), "Release", privateModule),
+ "__ecereMethod___ecereNameSpace__ecere__sys__Mutex_Release");
+ mutexDeclared = true;
+ }
+
f.Printf("\n");
if(!method.dataType)
method.dataType = ProcessTypeString(method.dataTypeString, false);
f.Printf(" = 0");
f.Printf(";\n\n");
}
+
+ f.Printf(" incref __ecereObject;\n");
+ f.Printf(" __ecereMethod___ecereNameSpace__ecere__sys__Mutex_Wait(__ecereObject.mutex);\n");
+
//f.Printf(" incref this;\n");
for(param = method.dataType.params.first; param; param = param.next)
{
if(param.kind == classType && !strcmp(param._class.string, "String"))
{
DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
- f.Printf(" __ecereObject.virtualsBuffer.Serialize((StaticString)%s);\n", param.name);
+ f.Printf(" __ecereObject.argsBuffer.Serialize((StaticString)%s);\n", param.name);
}
else
- f.Printf(" __ecereObject.virtualsBuffer.Serialize(%s);\n", param.name);
+ f.Printf(" __ecereObject.argsBuffer.Serialize(%s);\n", param.name);
}
DeclareMethod(
eClass_FindMethod(
eSystem_FindClass(privateModule, "ecere::net::DCOMServerObject"), "CallVirtualMethod", privateModule),
- "__ecereMethod___ecereNameSpace__ecere__net__DCOMServerObject_CallVirutalMethod");
+ "__ecereMethod___ecereNameSpace__ecere__net__DCOMServerObject_CallVirtualMethod");
- f.Printf(" if(__ecereObject.CallVirtualMethod(%d))\n", vid - _class.base.vTblSize);
+ // Check if this method needs to return anything (hasReturnValue)
+ {
+ bool hasReturnValue = method.dataType.returnType.kind != voidType;
+ if(!hasReturnValue)
+ {
+ for(param = method.dataType.params.first; param; param = param.next)
+ {
+ if(param.kind == classType && ((param._class && param._class.registered && param._class.registered.type == structClass) || !strcmp(param._class.string, "String")) && !param.constant)
+ {
+ hasReturnValue = true;
+ break;
+ }
+ }
+ }
+ f.Printf(" if(__ecereObject.CallVirtualMethod(%d, %s))\n", vid - _class.base.vTblSize,
+ hasReturnValue ? "true" : "false");
+ }
f.Printf(" {\n");
for(param = method.dataType.params.first; param; param = param.next)
{
if(!strcmp(param._class.string, "String"))
{
DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
- f.Printf(" __ecereObject.virtualsBuffer.Unserialize((StaticString)%s);\n", param.name);
+ f.Printf(" __ecereObject.returnBuffer.Unserialize((StaticString)%s);\n", param.name);
}
else
- f.Printf(" __ecereObject.virtualsBuffer.Unserialize(%s);\n", param.name);
+ f.Printf(" __ecereObject.returnBuffer.Unserialize(%s);\n", param.name);
}
}
if(method.dataType.returnType.kind != voidType)
if(method.dataType.returnType.kind == classType && !strcmp(method.dataType.returnType._class.string, "String"))
{
DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
- f.Printf(" __ecereObject.virtualsBuffer.Unserialize((StaticString)__ecereResult);\n");
+ f.Printf(" __ecereObject.returnBuffer.Unserialize((StaticString)__ecereResult);\n");
}
else
- f.Printf(" __ecereObject.virtualsBuffer.Unserialize(__ecereResult);\n");
+ f.Printf(" __ecereObject.returnBuffer.Unserialize(__ecereResult);\n");
}
f.Printf(" }\n");
f.Printf(" else\n");
}
f.Printf(");\n");
- f.Printf(" __ecereObject.virtualsBuffer.Free();\n");
+ f.Printf(" __ecereObject.returnBuffer.Free();\n");
+ f.Printf(" __ecereMethod___ecereNameSpace__ecere__sys__Mutex_Release(__ecereObject.mutex);\n");
//f.Printf(" delete this;\n");
+ f.Printf(" delete __ecereObject;\n");
if(method.dataType.returnType.kind != voidType)
{
f.Printf(" return __ecereResult;\n");
valid = false;
if(!valid)
- printf("Syntax:\n ecs [-t <target platform>] <input>[, <input>]* -o <output>\n");
+ printf($"Syntax:\n ecs [-t <target platform>] <input>[, <input>]* -o <output>\n");
else
{
int c;
//if(!strcmp(ext, "c"))
{
- File potFile = null;
- Map<String, String> intlStrings { };
- MapIterator<String, String> it { map = intlStrings };
+ String symbolsDir = GetSymbolsDir();
+ // Only generating .pot files when building from release.* directory for now
+ bool outputPot = symbolsDir && SearchString(symbolsDir, 0, "release.", false, false);
+ Map<ContextStringPair, List<String> > intlStrings { };
+ MapIterator<ContextStringPair, List<String>> it { map = intlStrings };
for(c = 1; c<argc; c++)
{
f = FileOpen(fileName, read);
if(f)
{
- if(!potFile)
- {
- char potFileName[MAX_LOCATION];
- strcpy(potFileName, output);
- StripExtension(potFileName);
- ChangeExtension(potFileName, "pot", potFileName);
- potFile = FileOpen(potFileName, write);
- }
- potFile.Printf("# %s\n", moduleName);
+ static char line[65536];
+ List<String> comments { };
+ String msgid = null, msgstr = null, msgctxt = null;
while(!f.Eof())
{
- String comment = null, msgid = null, msgstr = null;
- int c;
- for(c = 0; c < 4; c++)
+ if(f.GetLine(line, sizeof(line)))
{
- static char line[65536];
- if(f.GetLine(line, sizeof(line)))
+ int len;
+ TrimLSpaces(line, line);
+ if(line[0] == '#')
{
- if(c == 0) comment = CopyString(line);
- else if(c == 1) msgid = CopyString(line);
- else if(c == 2) msgstr = CopyString(line);
+ comments.Add(CopyString(line));
+ }
+ else if(strstr(line, "msgid \"") == line)
+ {
+ delete msgid;
+ msgid = CopyString(line + 7);
+ len = strlen(msgid);
+ if(len) msgid[len-1] = 0;
+ }
+ else if(strstr(line, "msgctxt \"") == line)
+ {
+ delete msgctxt;
+ msgctxt = CopyString(line + 9);
+ len = strlen(msgctxt);
+ if(len) msgctxt[len-1] = 0;
+ }
+ else if(strstr(line, "msgstr \"") == line)
+ {
+ delete msgstr;
+ msgstr = CopyString(line + 8);
+ len = strlen(msgstr);
+ if(len) msgstr[len-1] = 0;
+ }
+
+ if(msgid && msgstr)
+ {
+ ContextStringPair pair { msgid, msgctxt };
+ i18n = true;
+ if(!it.Index(pair, false))
+ {
+ msgid = null; msgctxt = null;
+ intlStrings[pair] = comments;
+ comments = { };
+ }
+ else
+ {
+ for(s : comments)
+ it.data.Add(s);
+ comments.RemoveAll();
+ }
+
+ delete msgid;
+ delete msgctxt;
+ delete msgstr;
}
- }
- if(msgid && !it.Index(msgid, false))
- {
- i18n = true;
- intlStrings[msgid] = comment;
- potFile.Puts(comment); potFile.Puts("\n");
- potFile.Puts(msgid); potFile.Puts("\n");
- potFile.Puts(msgstr); potFile.Puts("\n");
- potFile.Puts("\n");
- delete msgstr;
- // delete comment;
}
}
+ comments.Free();
+ delete comments;
delete f;
- potFile.Puts("\n");
}
}
}
}
WriteMain(output);
- intlStrings.Free();
- delete intlStrings;
- if(potFile)
- delete potFile;
+ if(outputPot && intlStrings.count)
+ {
+ File potFile;
+ char potFileName[MAX_LOCATION];
+ //strcpy(potFileName, output);
+ //StripExtension(potFileName);
+ strcpy(potFileName, "locale");
+ MakeDir(potFileName);
+ PathCat(potFileName, projectName);
+ ChangeExtension(potFileName, "pot", potFileName);
+ potFile = FileOpen(potFileName, write);
+ if(potFile)
+ {
+ // Write header:
+ potFile.Puts("msgid \"\"\n");
+ potFile.Puts("msgstr \"\"\n");
+ potFile.Puts("\"Project-Id-Version: \\n\"\n");
+ potFile.Puts("\"POT-Creation-Date: \\n\"\n");
+ potFile.Puts("\"PO-Revision-Date: \\n\"\n");
+ potFile.Puts("\"Last-Translator: \\n\"\n");
+ potFile.Puts("\"Language-Team: \\n\"\n");
+ potFile.Puts("\"MIME-Version: 1.0\\n\"\n");
+ potFile.Puts("\"Content-Type: text/plain; charset=iso-8859-1\\n\"\n");
+ potFile.Puts("\"Content-Transfer-Encoding: 8bit\\n\"\n");
+ potFile.Puts("\"X-Poedit-Basepath: ../\\n\"\n");
+ potFile.Puts("\n");
+
+ for(i : intlStrings)
+ {
+ ContextStringPair pair = &i;
+ List<String> comments = i;
+ for(s : comments)
+ {
+ potFile.Printf(s);
+ potFile.Puts("\n");
+ }
+
+ if(pair.context)
+ {
+ potFile.Puts("msgctxt \""); potFile.Puts(pair.context); potFile.Puts("\"\n");
+ }
+ potFile.Puts("msgid \""); potFile.Puts(pair.string); potFile.Puts("\"\n");
+ potFile.Puts("msgstr \""); potFile.Puts(pair.string); potFile.Puts("\"\n");
+ potFile.Puts("\n");
+ }
+ intlStrings.Free();
+ delete intlStrings;
+ delete potFile;
+ }
+ }
}
FreeContext(theGlobalContext);