set windows environment for ilib_for_link, add getenv, setenv, dos, winqueryreg gateways 33/4233/5
Antoine ELIAS [Fri, 17 Jun 2011 12:35:56 +0000 (14:35 +0200)]
Change-Id: I02c696a5fa7301ddc35a1399e0174ff9ca7830b4

12 files changed:
scilab/modules/dynamic_link/etc/dynamic_link.start
scilab/modules/io/includes/gw_io.h
scilab/modules/io/sci_gateway/c/sci_getenv.c
scilab/modules/io/sci_gateway/c/sci_setenv.c
scilab/modules/io/src/cpp/io_gw.cpp
scilab/modules/system_env/includes/setenvvar.hxx
scilab/modules/system_env/src/cpp/setenvvar.cpp
scilab/modules/system_env/system_env.vcxproj
scilab/modules/windows_tools/sci_gateway/c/sci_dos.c
scilab/modules/windows_tools/sci_gateway/c/sci_winqueryreg.c
scilab/modules/windows_tools/src/c/scilab_windows/spawncommand.c
scilab/modules/windows_tools/src/cpp/windows_tools_gw.cpp

index 54953d9..6c6a251 100644 (file)
@@ -18,18 +18,18 @@ if getos() == 'Windows' then
   if findmsvccompiler() <> 'unknown' then
     // Configure Ms VC environment
     configure_msvc();
-    clear configure_msvc
+    //clear configure_msvc
     if findmsifortcompiler() <> 'unknown' then
       // Configure Intel Fortran environment
       configure_msifort();
-      clear configure_msifort
+      //clear configure_msifort
     else
       // Use F2C 
       setenv('USE_F2C', 'YES');
     end
-    clear findmsifortcompiler
+    //clear findmsifortcompiler
   end
-  clear findmsvccompiler
+  //clear findmsvccompiler
 end
 
 // Add demos
index cad607d..26b15bf 100644 (file)
@@ -27,14 +27,12 @@ IO_IMPEXP int sci_setenv(char *fname, int* _piKey);
 int sci_read(char *fname,unsigned long fname_len);
 int sci_oldsave(char *fname,unsigned long fname_len);
 int sci_write(char *fname,unsigned long fname_len);
-int sci_unix(char *fname,unsigned long fname_len);
 int sci_readb(char *fname,unsigned long fname_len);
 int sci_writb(char *fname,unsigned long fname_len);
 int sci_getpid(char *fname,unsigned long fname_len);
 int sci_read4b(char *fname,unsigned long fname_len);
 int sci_write4b(char *fname,unsigned long fname_len);
 int sci_save(char *fname,unsigned long fname_len);
-int sci_load(char *fname,unsigned long fname_len);
 int sci_getio(char *fname,unsigned long fname_len);
 /*--------------------------------------------------------------------------*/
 #endif /* __GW_IO_H__ */
index 5140055..c0ec546 100644 (file)
 #include "freeArrayOfString.h"
 #include "localization.h"
 #include "Scierror.h"
-#include "stack-c.h"
-#include "api_scilab.h"
 #include "getenvc.h"
 #include "PATH_MAX.h"
+#include "stack-c.h"
+#include "api_scilab.h"
+#include "api_oldstack.h"
 /*--------------------------------------------------------------------------*/
 int sci_getenv(char *fname, int* _piKey)
 {
@@ -42,114 +43,48 @@ int sci_getenv(char *fname, int* _piKey)
        char *pStVarTwo = NULL;
        int lenStVarTwo = 0;
 
-       Rhs = Max(Rhs,0);
-
        CheckRhs(1,2);
        CheckLhs(1,1);
 
-       if (Rhs == 2)
-       {
+       if(Rhs == 2)
+       {//second parameter
                sciErr = getVarAddressFromPosition(_piKey, 2, &piAddressVarTwo);
                if(sciErr.iErr)
                {
                        printError(&sciErr, 0);
-                       return 0;
-               }
-
-               sciErr = getVarType(_piKey, piAddressVarTwo, &iType2);
-               if(sciErr.iErr)
-               {
-                       printError(&sciErr, 0);
-                       return 0;
+                       return 1;
                }
 
-               if (iType2  != sci_strings )
+        if(isStringType(_piKey, piAddressVarTwo) == FALSE || isScalar(_piKey, piAddressVarTwo) == FALSE)
                {
                        Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"),fname,2);
-                       return 0;
-               }
-
-               sciErr = getMatrixOfString(_piKey, piAddressVarTwo,&m2,&n2,&lenStVarTwo,&pStVarTwo);
-               if(sciErr.iErr)
-               {
-                       printError(&sciErr, 0);
-                       return 0;
-               }
-
-               if ( (m2 != n2) && (n2 != 1) ) 
-               {
-                       Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"),fname,2);
-                       return 0;
-               }
-
-               pStVarTwo = (char*)MALLOC(sizeof(char)*(lenStVarTwo + 1));
-               if (pStVarTwo)
-               {
-                       sciErr = getMatrixOfString(_piKey, piAddressVarTwo,&m2,&n2,&lenStVarTwo,&pStVarTwo);
-                       if(sciErr.iErr)
-                       {
-                               printError(&sciErr, 0);
-                               return 0;
-                       }
-               }
-               else
-               {
-                       Scierror(999,_("%s: Memory allocation error.\n"),fname);
-                       return 0;
+                       return 1;
                }
+        
+        if(getAllocatedSingleString(_piKey, piAddressVarTwo, &pStVarTwo))
+        {
+            return 1;
+        }
        }
 
+    //first parameter
        sciErr = getVarAddressFromPosition(_piKey, 1, &piAddressVarOne);
        if(sciErr.iErr)
        {
                printError(&sciErr, 0);
-               return 0;
-       }
-
-       sciErr = getVarType(_piKey, piAddressVarOne, &iType1);
-       if(sciErr.iErr)
-       {
-               printError(&sciErr, 0);
-               return 0;
-       }
-
-       if (iType1  != sci_strings )
-       {
-               if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
-               Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"),fname,2);
-               return 0;
-       }
-
-       sciErr = getMatrixOfString(_piKey, piAddressVarOne,&m1,&n1,&lenStVarOne,&pStVarOne);
-       if(sciErr.iErr)
-       {
-               printError(&sciErr, 0);
-               return 0;
+               return 1;
        }
 
-       if ( (m1 != n1) && (n1 != 1) ) 
-       {
-               if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
-               Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"),fname,1);
-               return 0;
-       }
+    if(isStringType(_piKey, piAddressVarOne) == FALSE || isScalar(_piKey, piAddressVarOne) == FALSE)
+    {
+        Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
+        return 1;
+    }
 
-       pStVarOne = (char*)MALLOC(sizeof(char)*(lenStVarOne + 1));
-       if (pStVarOne)
-       {
-               sciErr = getMatrixOfString(_piKey, piAddressVarOne,&m1,&n1,&lenStVarOne,&pStVarOne);
-               if(sciErr.iErr)
-               {
-                       printError(&sciErr, 0);
-                       return 0;
-               }
-       }
-       else
-       {
-               if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
-               Scierror(999,_("%s: Memory allocation error.\n"),fname);
-               return 0;
-       }
+    if(getAllocatedSingleString(_piKey, piAddressVarOne, &pStVarOne))
+    {
+        return 1;
+    }
 
        #ifdef _MSC_VER
        length_env = _MAX_ENV;
@@ -162,13 +97,13 @@ int sci_getenv(char *fname, int* _piKey)
 
        env_value = (char*)MALLOC( (length_env + 1) *sizeof(char) );
 
-       if (env_value == NULL)
+       if(env_value == NULL)
        {
-               if (default_env_value) {FREE(default_env_value); default_env_value = NULL;}
-               if (env_name) {FREE(env_name); env_name = NULL;}
+               if(default_env_value) {FREE(default_env_value); default_env_value = NULL;}
+               if(env_name) {FREE(env_name); env_name = NULL;}
 
                Scierror(999,_("%s: No more memory.\n"), fname);
-               return 0;
+               return 1;
        }
        else
        {
@@ -177,31 +112,31 @@ int sci_getenv(char *fname, int* _piKey)
 
                getenvc(&ierr, env_name, env_value, &length_env, &iflag);
 
-               if (ierr == 0)
+               if(ierr == 0)
                {
                        sciErr = createMatrixOfString(_piKey, Rhs + 1, m_out, n_out, &env_value);
                        if(sciErr.iErr)
                        {
                                printError(&sciErr, 0);
-                               return 0;
+                               return 1;
                        }
 
                        LhsVar(1) = Rhs + 1;
-                       C2F(putlhsvar)();       
+            PutLhsVar();       
                }
                else
                {
-                       if (default_env_value)
+                       if(default_env_value)
                        {
                                sciErr = createMatrixOfString(_piKey, Rhs + 1, m_out, n_out, &default_env_value);
                                if(sciErr.iErr)
                                {
                                        printError(&sciErr, 0);
-                                       return 0;
+                                       return 1;
                                }
 
                                LhsVar(1) = Rhs + 1;
-                               C2F(putlhsvar)();       
+                PutLhsVar();   
                        }
                        else
                        {
@@ -209,9 +144,9 @@ int sci_getenv(char *fname, int* _piKey)
                        }
                }
 
-               if (default_env_value) {FREE(default_env_value); default_env_value = NULL;}
-               if (env_name) {FREE(env_name); env_name = NULL;}
-               if (env_value) {FREE(env_value); env_value = NULL;}
+               if(default_env_value) {FREE(default_env_value); default_env_value = NULL;}
+               if(env_name) {FREE(env_name); env_name = NULL;}
+               if(env_value) {FREE(env_value); env_value = NULL;}
 
        }
        return 0;
index c2c2e98..67e0950 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #include "gw_io.h"
+#include "stack-c.h"
 #include "api_scilab.h"
+#include "api_oldstack.h"
 #include "setenvc.h"
 #include "MALLOC.h" /* MALLOC */
-#include "stack-c.h"
 #include "Scierror.h"
 #include "localization.h"
 /*--------------------------------------------------------------------------*/
@@ -41,7 +42,6 @@ int sci_setenv(char *fname, int* _piKey)
 
        int result = 0;
 
-       Rhs = Max(0,Rhs);
        CheckRhs(2,2);
        CheckLhs(0,1);
 
@@ -161,7 +161,7 @@ int sci_setenv(char *fname, int* _piKey)
 
        LhsVar(1) = Rhs + 1; 
 
-       C2F(putlhsvar)();
+    PutLhsVar();
        return 0;
 }
 /*--------------------------------------------------------------------------*/
index d6bdc47..8ac356a 100644 (file)
 #include "io_gw.hxx"
 #include "context.hxx"
 
+extern "C"
+{
+#include "gw_io.h"
+}
 #define MODULE_NAME L"io"
 
 using namespace types;
@@ -24,6 +28,8 @@ bool IoModule::Load()
     symbol::Context::getInstance()->AddFunction(Function::createFunction(L"file", &sci_file, MODULE_NAME));
     symbol::Context::getInstance()->AddFunction(Function::createFunction(L"host", &sci_host, MODULE_NAME));
     symbol::Context::getInstance()->AddFunction(Function::createFunction(L"unix", &sci_unix, MODULE_NAME));
+    symbol::Context::getInstance()->AddFunction(Function::createFunction(L"getenv", &sci_getenv, MODULE_NAME));
+    symbol::Context::getInstance()->AddFunction(Function::createFunction(L"setenv", &sci_setenv, MODULE_NAME));
     return true;
 }
 
index b22c792..ff0b914 100644 (file)
 
 bool IsTheGoodShell(void);
 bool Set_Shell(void);
-bool Set_YASP_PATH(char *DefaultPath);
-bool Set_HOME_PATH(char *DefaultPath);
-bool Set_SOME_ENVIRONMENTS_VARIABLES_FOR_SCILAB(void);
-EXTERN_SYSTEM_ENV char *getScilabDirectory(bool UnixStyle);
+void Set_SOME_ENVIRONMENTS_VARIABLES_FOR_SCILAB(void);
 void SciEnvForWindows(void);
 void SetScilabEnvironmentVariables(char *DefaultSCIPATH);
 bool convertSlash(const char *path_in,char *path_out,bool slashToAntislash);
index 8d05501..629bc51 100644 (file)
@@ -76,6 +76,7 @@ void SetScilabEnvironment(void)
 #ifdef _MSC_VER
 void SciEnvForWindows(void)
 {
+    char *SCIPathName = computeSCI();
     /* Correction Bug 1579 */
     if (!IsTheGoodShell())
     {
@@ -84,6 +85,13 @@ void SciEnvForWindows(void)
             cout << "Please modify ""ComSpec"" environment variable." << endl << "cmd.exe on W2K and more." << endl;
         }
     }
+    
+    SetScilabEnvironmentVariables(SCIPathName);
+    if (SCIPathName) 
+    {
+        FREE(SCIPathName);
+        SCIPathName = NULL;
+    }
 }
 #endif
 
@@ -134,6 +142,68 @@ bool Set_Shell(void)
     }
     return bOK;
 }
+
+static BOOL AddScilabBinDirectoryToPATHEnvironnementVariable(char *DefaultPath)
+{
+    #define PATH_FORMAT "PATH=%s/bin;%s"
+
+    BOOL bOK = FALSE;
+    char *PATH = NULL;
+    char *env = NULL;
+
+    PATH = getenv("PATH");
+
+    env = (char*) MALLOC(sizeof(char)* (strlen(PATH_FORMAT) + strlen(PATH) +
+                        strlen(DefaultPath) + 1));
+    if (env)
+    {
+        sprintf(env, PATH_FORMAT, DefaultPath, PATH);
+        if (_putenv (env))
+        {
+            bOK = FALSE;
+        }
+        else bOK = TRUE;
+        FREE(env); env = NULL;
+    }
+    return bOK;
+}
+
+void Set_SOME_ENVIRONMENTS_VARIABLES_FOR_SCILAB(void)
+{
+#ifdef _MSC_VER
+    _putenv ("COMPILER=VC++");
+#endif
+
+    /* WIN32 variable Environment */
+#ifdef _WIN32
+    _putenv ("WIN32=OK");
+#endif
+
+    /* WIN64 variable Environment */
+#ifdef _WIN64
+    _putenv ("WIN64=OK");
+#endif
+
+    if ( GetSystemMetrics(SM_REMOTESESSION) ) 
+    {
+        _putenv ("SCILAB_MSTS_SESSION=OK");
+    }
+}
+
+void SetScilabEnvironmentVariables(char *DefaultSCIPATH)
+{
+    if (DefaultSCIPATH)
+    {
+        Set_SOME_ENVIRONMENTS_VARIABLES_FOR_SCILAB();
+        AddScilabBinDirectoryToPATHEnvironnementVariable(DefaultSCIPATH);
+    }
+    else
+    {
+        /* Error */
+        exit(1);
+    }
+
+}
 #endif
 
 /*--------------------------------------------------------------------------*/
index 549a644..ac79084 100644 (file)
@@ -72,7 +72,7 @@
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>includes;..\core\includes;../symbol/includes;../types/includes;../abstractSyntaxTree/includes;../windows_tools/includes;../localization/includes;../io/includes;../../libs/MALLOC/includes;../../libs/intl;../fileio/includes;../string/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>includes;..\core\includes;../symbol/includes;../types/includes;../abstractSyntaxTree/includes;../windows_tools/includes;../localization/includes;../io/includes;../../libs/MALLOC/includes;../../libs/intl;../fileio/includes;../string/includes;../windows_tools/src/c/scilab_windows/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;SYSTEM_ENV_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <MinimalRebuild>true</MinimalRebuild>
       <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
     <ClCompile>
       <Optimization>MaxSpeed</Optimization>
       <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>includes;..\core\includes;../symbol/includes;../types/includes;../abstractSyntaxTree/includes;../windows_tools/includes;../localization/includes;../io/includes;../../libs/MALLOC/includes;../../libs/intl;../fileio/includes;../string/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>includes;..\core\includes;../symbol/includes;../types/includes;../abstractSyntaxTree/includes;../windows_tools/includes;../localization/includes;../io/includes;../../libs/MALLOC/includes;../../libs/intl;../fileio/includes;../string/includes;../windows_tools/src/c/scilab_windows/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;SYSTEM_ENV_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
       <FunctionLevelLinking>true</FunctionLevelLinking>
     <ClCompile>
       <Optimization>MaxSpeed</Optimization>
       <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>includes;..\core\includes;../symbol/includes;../types/includes;../abstractSyntaxTree/includes;../windows_tools/includes;../localization/includes;../io/includes;../../libs/MALLOC/includes;../../libs/intl;../fileio/includes;../string/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>includes;..\core\includes;../symbol/includes;../types/includes;../abstractSyntaxTree/includes;../windows_tools/includes;../localization/includes;../io/includes;../../libs/MALLOC/includes;../../libs/intl;../fileio/includes;../string/includes;../windows_tools/src/c/scilab_windows/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;SYSTEM_ENV_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
       <FunctionLevelLinking>true</FunctionLevelLinking>
       <Project>{2c60033b-0dbd-4ca4-80d3-176c9be9ce2f}</Project>
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
     </ProjectReference>
-    <ProjectReference Include="..\windows_tools\src\c\scilab_windows\scilab_windows.vcxproj">
-      <Project>{8028f371-6a94-4a26-8804-6e7f05f1d1aa}</Project>
-      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
-    </ProjectReference>
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
index 36798ca..19c190d 100644 (file)
@@ -25,6 +25,7 @@
 #include "freeArrayOfString.h"
 #include "getshortpathname.h"
 #include "api_scilab.h"
+#include "api_oldstack.h"
 /*--------------------------------------------------------------------------*/
 #define BUFSIZE 4096
 /*--------------------------------------------------------------------------*/
@@ -278,7 +279,7 @@ int sci_dos(char *fname, int* _piKey)
                        LhsVar(3) = Rhs + 3;
                }
 
-               C2F(putlhsvar)();
+               PutLhsVar();
 
                if (StatusExit) {FREE(StatusExit); StatusExit = NULL;}
                freeArrayOfString(Output, numberoflines);
index 629d3dd..79d0d5c 100644 (file)
@@ -12,8 +12,9 @@
  */
 /*--------------------------------------------------------------------------*/
 #include "gw_windows_tools.h"
-#include "api_scilab.h"
 #include "stack-c.h"
+#include "api_scilab.h"
+#include "api_oldstack.h"
 #include "MALLOC.h"
 #include "registry.h"
 #include "Scierror.h"
@@ -35,7 +36,6 @@ int sci_winqueryreg(char *fname,int *_piKey)
     char *pStrOutput = NULL;
     int iOutput = 0;
 
-    Rhs = Max(0, Rhs);
     CheckRhs(2, 3);
     CheckLhs(0, 1);
 
index cda3f48..a01d4ff 100644 (file)
@@ -254,6 +254,7 @@ char **CreateOuput(pipeinfo *pipe,BOOL DetachProcess)
                 if (pipe->NumberOfLines)
                 {
                     OuputStrings = (char**)MALLOC((pipe->NumberOfLines) * sizeof(char*));
+                    memset(OuputStrings, 0x00, sizeof(char*) * pipe->NumberOfLines);
                     if (OuputStrings)
                     {
                         char *line = strtok(buffer, LF_STR);
index 3110a49..4934a13 100644 (file)
@@ -21,5 +21,7 @@ extern "C"
 bool WindowsToolsModule::Load()
 {
     symbol::Context::getInstance()->AddFunction(types::Function::createFunction(L"win64", &sci_win64, MODULE_NAME));
+    symbol::Context::getInstance()->AddFunction(types::Function::createFunction(L"winqueryreg", &sci_winqueryreg, MODULE_NAME));
+    symbol::Context::getInstance()->AddFunction(types::Function::createFunction(L"dos", &sci_dos, MODULE_NAME));
     return true;
 }