ecere/com: Fixed sprintf/snprintf confusion; Support for setting argc/argc later on
authorJerome St-Louis <jerome@ecere.com>
Wed, 1 Jun 2016 04:14:15 +0000 (00:14 -0400)
committerJerome St-Louis <jerome@ecere.com>
Sat, 11 Jun 2016 07:07:23 +0000 (03:07 -0400)
ecere/src/com/instance.c
ecere/src/com/instance.ec
ecere/src/gfx/Display.ec

index 992af78..59304a8 100644 (file)
@@ -428,6 +428,21 @@ void Instance_COM_Initialize(int argc, char ** argv, char ** parsedCommand, int
 #endif
 }
 
+void System_SetArgs(int argc, char ** argv, int * argcPtr, const char *** argvPtr)
+{
+#if defined(__unix__)
+   *argcPtr = argc;
+   *argvPtr = (const char **)argv;
+
+   if(!__thisModule && argv)
+   {
+      if(!getcwd(exeLocation, MAX_LOCATION))
+         exeLocation[0] = 0;
+      PathCat(exeLocation, argv[0]);
+   }
+#endif
+}
+
 void * Instance_Module_Load(const char * libLocation, const char * name, void ** Load, void ** Unload)
 {
    char fileName[MAX_LOCATION];
index 4f33b92..d90d650 100644 (file)
@@ -141,6 +141,7 @@ dllexport int isblank(int c);
 #endif
 bool Instance_LocateModule(const char * name, const char * fileName);
 void Instance_COM_Initialize(int argc, char ** argv, char ** parsedCommand, int * argcPtr, const char *** argvPtr);
+void System_SetArgs(int argc, char ** argv, int * argcPtr, const char *** argvPtr);
 void * Instance_Module_Load(const char * libLocation, const char * name, void ** Load, void ** Unload);
 void Instance_Module_Free(void * library);
 #if defined(_DEBUG)
@@ -6569,7 +6570,7 @@ static void LoadCOM(Module module)
 
    // --- Stdio ---
    eSystem_RegisterFunction("sprintf", "int sprintf(char *, const char *, ...)", sprintf, module, baseSystemAccess);
-   eSystem_RegisterFunction("snprintf", "int sprintf(char *, uintsize, const char *, ...)", snprintf, module, baseSystemAccess);
+   eSystem_RegisterFunction("snprintf", "int snprintf(char *, uintsize, const char *, ...)", snprintf, module, baseSystemAccess);
    eSystem_RegisterFunction("printf", "int printf(const char *, ...)", printf, module, baseSystemAccess);
    eSystem_RegisterFunction("vsprintf", "int vsprintf(char*, const char*, __builtin_va_list)", vsprintf, module, baseSystemAccess);
    eSystem_RegisterFunction("vsnprintf", "int vsnprintf(char*, uintsize, const char*, __builtin_va_list)", vsnprintf, module, baseSystemAccess);
@@ -6636,6 +6637,11 @@ public dllexport Application __ecere_COM_Initialize(bool guiApp, int argc, char
    return app;
 }
 
+public dllexport void eSystem_SetArgs(Application app, int argc, char * argv[])
+{
+   System_SetArgs(argc, argv, &app.argc, &app.argv);
+}
+
 public dllexport ClassTemplateParameter eClass_AddTemplateParameter(Class _class, const char * name, TemplateParameterType type, const void * info, ClassTemplateArgument defaultArg)
 {
    if(_class && name)
index ac4ad73..6e562aa 100644 (file)
@@ -419,7 +419,7 @@ public:
    Surface GetSurface(int x, int y, Box clip)
    {
       Surface result = null;
-      Surface surface { };
+      Surface surface { _refCount = 1 };
       if(surface)
       {
          Box box { -x, -y, -x + width - 1, -y + height - 1 };