update for [a,b] = getversion()
Allan Cornet [Thu, 5 Jun 2008 08:30:22 +0000 (08:30 +0000)]
modelicac is searched in PATH environment variable

scilab/modules/core/src/c/inisci-c.c
scilab/modules/io/includes/getenvc.h
scilab/modules/io/src/c/Scilab_Windows_Import.def [new file with mode: 0644]
scilab/modules/io/src/c/getenvc.c
scilab/modules/io/src/c/io.vcproj

index bb96644..a3986b3 100644 (file)
@@ -175,23 +175,14 @@ int C2F(gettmpdir)(char *buf,int *nbuf,long int lbuf)
 /*--------------------------------------------------------------------------*/
 BOOL ExistModelicac(void)
 {
-       // @ TO DO remove this
-       // used in getversion (compatibility)
-       #define FORMAT_SCIBIN_PATH "%s/bin/%s"
-       BOOL bOK=FALSE;
-       char *SCIPATH = (char*)getSCIpath();
-       char *fullpathModelicac=NULL;
-       int length_path = strlen(SCIPATH) + 
-                                       strlen(ModelicacName) + 
-                                       strlen(FORMAT_SCIBIN_PATH) + 1 ;
-       
-       fullpathModelicac=(char*)MALLOC((length_path)*sizeof(char));
-       sprintf(fullpathModelicac,FORMAT_SCIBIN_PATH,SCIPATH,ModelicacName);
-
-       bOK = FileExist(fullpathModelicac);
-       if (fullpathModelicac) FREE(fullpathModelicac);
-       if (SCIPATH) FREE(SCIPATH);
-       return bOK;
+       char *fullpathModelicac = searchEnv( ModelicacName,"PATH");
+       if (fullpathModelicac)
+       {
+               FREE(fullpathModelicac);
+               fullpathModelicac = NULL;
+               return TRUE;
+       }
+       return FALSE;
 }
 /*--------------------------------------------------------------------------*/
 int C2F(withgui)(int *rep)
index 21abc4b..96809e2 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2007 - INRIA - Sylvestre LEDRU
+ * Copyright (C) 2008 - INRIA - Allan CORNET
  * 
  * This file must be used under the terms of the CeCILL.
  * This source file is licensed as described in the file COPYING, which
  */
 void C2F(getenvc)(int *ierr,char *var,char *buf,int *buflen,int *iflag);
 
+/**
+* Searches for a file using environment paths
+* @param[in] filename
+* @param[in] environment variable where we search
+* @return path found
+*/
+char *searchEnv(const char *name,const char *env_var);
+
+
 #endif /* __GETENVC_H__ */
diff --git a/scilab/modules/io/src/c/Scilab_Windows_Import.def b/scilab/modules/io/src/c/Scilab_Windows_Import.def
new file mode 100644 (file)
index 0000000..3a3e9b3
--- /dev/null
@@ -0,0 +1,10 @@
+       LIBRARY    scilab_windows.dll\r
+\r
+\r
+EXPORTS\r
+;\r
+; scilab_windows\r
+;\r
+ strdup_windows\r
+;\r
+\r
index a3eb031..e1151d0 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2006 - INRIA
+ * Copyright (C) 2008 - INRIA - Allan CORNET
  * 
  * This file must be used under the terms of the CeCILL.
  * This source file is licensed as described in the file COPYING, which
  *
  */
 
+#include <stdlib.h> 
+#include <string.h> /* strlen */
 #ifdef _MSC_VER
        #include <Windows.h> /* GetEnvironmentVariable */
-#else
-       #include <stdlib.h> /* getenv */
+       #include "strdup_windows.h"
 #endif
-#include <string.h> /* strlen */
+#include "MALLOC.h"
 #include "getenvc.h"
 #include "localization.h"
 #include "sciprint.h"
+#include "FileExist.h"
+/*--------------------------------------------------------------------------*/
+#ifndef _MSC_VER
+static void searchenv_others(const char *filename, const char *varname,
+                           char *pathname);
+#endif
 /*--------------------------------------------------------------------------*/
 void C2F(getenvc)(int *ierr,char *var,char *buf,int *buflen,int *iflag)
 {
@@ -49,4 +57,92 @@ void C2F(getenvc)(int *ierr,char *var,char *buf,int *buflen,int *iflag)
        #endif
 }
 /*--------------------------------------------------------------------------*/
+#ifndef _MSC_VER
+static void searchenv_others(const char *filename, 
+                           const char *varname,
+                           char *pathname)
+{
+       char *cp = NULL;
+
+       *pathname = '\0';
+
+       if( filename[0] == DIR_SEPARATOR[0])
+       {
+               strcpy(pathname, filename);
+               return;
+       }
+       
+       cp = getenv(varname);
+       if(cp == NULL)
+       {
+               /* environment Variable not defined. */
+               return;
+       }
+
+       while(*cp)
+       {
+               char *concat = NULL;
+               *pathname = '\0';
+        concat = pathname;
+               /* skip PATH_SEPARATOR[0] and empty entries */
+               while( (*cp) && (*cp == PATH_SEPARATOR[0]) )
+               {
+                       cp++;
+               }
+
+               /* copy path */
+               while( (*cp) && (*cp != PATH_SEPARATOR[0]) )
+               {
+                       *concat = *cp;
+                       cp++;
+                       concat++;
+               }
+               
+               if ( concat == pathname )
+               {
+                       /* filename not found */
+                       *pathname = '\0';
+                       return;
+               }
+               
+               if( *(concat-1) != DIR_SEPARATOR[0] )
+               {
+                       /* add directory separator */
+                       *concat = DIR_SEPARATOR[0];
+                       concat++;
+               }
+
+               /* concatate path & filename */
+               strcpy(concat, filename);
+
+               /* file exists ? */
+               if(FileExist(pathname))
+               {
+                       // file found
+                       return;
+               }
+       }
+
+       /* file not found */
+       *pathname = '\0';
+}
+#endif
+/*--------------------------------------------------------------------------*/
+char *searchEnv(const char *name,const char *env_var)
+{
+       char *buffer = NULL;
+       char fullpath[PATH_MAX];
+
+       strcpy(fullpath,"");
+
+       #if _MSC_VER 
+               _searchenv(name,env_var,fullpath);
+       #else
+               searchenv_others(name,env_var,fullpath);
+       #endif
+
+       if (strlen(fullpath) > 0) buffer = strdup(fullpath);
+       return buffer;
+}
+/*--------------------------------------------------------------------------*/
 
index 7a00fdd..bee9a18 100644 (file)
@@ -6,7 +6,7 @@
        ProjectGUID="{80C0F142-184B-4E08-A8EE-5E71437CF904}"
        RootNamespace="io"
        Keyword="Win32Proj"
-       
+       TargetFrameworkVersion="0"
        >
        <Platforms>
                <Platform
@@ -44,7 +44,7 @@
                        <Tool
                                Name="VCCLCompilerTool"
                                Optimization="0"
-                               AdditionalIncludeDirectories=".;../../includes;../../../../libs/MALLOC/includes;../../../localization/includes;../../../core/includes;../../../output_stream/includes;../../../../libs/hashtable;../../../fileio/includes;../../../../libs/intl"
+                               AdditionalIncludeDirectories=".;../../includes;../../../../libs/MALLOC/includes;../../../localization/includes;../../../core/includes;../../../output_stream/includes;../../../../libs/hashtable;../../../fileio/includes;../../../windows_tools/includes;../../../../libs/intl"
                                PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WITH_TK;FORDLL;_DEBUG;_WINDOWS;_USRDLL;IO_EXPORTS"
                                MinimalRebuild="true"
                                BasicRuntimeChecks="0"
                        <Tool
                                Name="VCPreLinkEventTool"
                                Description="Make dependencies"
-                               CommandLine="lib /DEF:&quot;$(InputDir)LibScilab_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)LibScilab.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)io_f_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)io_f.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;cd $(IntDir) &gt;nul&#x0D;&#x0A;for %%f in (*.obj) do  ..\..\..\..\..\bin\dumpexts -o %%~nf.def -n io.dll %%f &gt;nul&#x0D;&#x0A;copy *.def iotmp.def &gt;nul&#x0D;&#x0A;copy ..\io_header.def+iotmp.def  ..\io.def &gt;nul&#x0D;&#x0A;del *.def &gt;nul&#x0D;&#x0A;cd .. &gt;nul&#x0D;&#x0A;"
+                               CommandLine="lib /DEF:&quot;$(InputDir)LibScilab_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)LibScilab.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)io_f_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)io_f.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)scilab_windows_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)scilab_windows.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;cd $(IntDir) &gt;nul&#x0D;&#x0A;for %%f in (*.obj) do  ..\..\..\..\..\bin\dumpexts -o %%~nf.def -n io.dll %%f &gt;nul&#x0D;&#x0A;copy *.def iotmp.def &gt;nul&#x0D;&#x0A;copy ..\io_header.def+iotmp.def  ..\io.def &gt;nul&#x0D;&#x0A;del *.def &gt;nul&#x0D;&#x0A;cd .. &gt;nul&#x0D;&#x0A;"
                        />
                        <Tool
                                Name="VCLinkerTool"
                                AdditionalOptions="/fixed:no"
-                               AdditionalDependencies="LibScilab.lib io_f.lib"
+                               AdditionalDependencies="LibScilab.lib io_f.lib scilab_windows.lib"
                                OutputFile="../../../../bin/$(ProjectName).dll"
                                LinkIncremental="1"
                                ModuleDefinitionFile="io.def"
                        <Tool
                                Name="VCCLCompilerTool"
                                Optimization="0"
-                               AdditionalIncludeDirectories=".;../../includes;../../../../libs/MALLOC/includes;../../../localization/includes;../../../core/includes;../../../output_stream/includes;../../../../libs/hashtable;../../../fileio/includes;../../../../libs/intl"
+                               AdditionalIncludeDirectories=".;../../includes;../../../../libs/MALLOC/includes;../../../localization/includes;../../../core/includes;../../../output_stream/includes;../../../../libs/hashtable;../../../fileio/includes;../../../windows_tools/includes;../../../../libs/intl"
                                PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WITH_TK;FORDLL;_DEBUG;_WINDOWS;_USRDLL;IO_EXPORTS"
                                MinimalRebuild="true"
                                BasicRuntimeChecks="0"
                        <Tool
                                Name="VCPreLinkEventTool"
                                Description="Make dependencies"
-                               CommandLine="lib /DEF:&quot;$(InputDir)LibScilab_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X64 /OUT:&quot;$(InputDir)LibScilab.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)io_f_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X64 /OUT:&quot;$(InputDir)io_f.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;cd $(IntDir) &gt;nul&#x0D;&#x0A;for %%f in (*.obj) do  ..\..\..\..\..\bin\dumpexts -o %%~nf.def -n io.dll %%f &gt;nul&#x0D;&#x0A;copy *.def iotmp.def &gt;nul&#x0D;&#x0A;copy ..\io_header.def+iotmp.def  ..\io.def &gt;nul&#x0D;&#x0A;del *.def &gt;nul&#x0D;&#x0A;cd .. &gt;nul&#x0D;&#x0A;"
+                               CommandLine="lib /DEF:&quot;$(InputDir)LibScilab_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X64 /OUT:&quot;$(InputDir)LibScilab.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)io_f_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X64 /OUT:&quot;$(InputDir)io_f.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)scilab_windows_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X64 /OUT:&quot;$(InputDir)scilab_windows.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;cd $(IntDir) &gt;nul&#x0D;&#x0A;for %%f in (*.obj) do  ..\..\..\..\..\bin\dumpexts -o %%~nf.def -n io.dll %%f &gt;nul&#x0D;&#x0A;copy *.def iotmp.def &gt;nul&#x0D;&#x0A;copy ..\io_header.def+iotmp.def  ..\io.def &gt;nul&#x0D;&#x0A;del *.def &gt;nul&#x0D;&#x0A;cd .. &gt;nul&#x0D;&#x0A;"
                        />
                        <Tool
                                Name="VCLinkerTool"
                                AdditionalOptions="/fixed:no"
-                               AdditionalDependencies="LibScilab.lib io_f.lib"
+                               AdditionalDependencies="LibScilab.lib io_f.lib scilab_windows.lib"
                                OutputFile="../../../../bin/$(ProjectName).dll"
                                LinkIncremental="1"
                                ModuleDefinitionFile="io.def"
                                InlineFunctionExpansion="1"
                                FavorSizeOrSpeed="1"
                                WholeProgramOptimization="false"
-                               AdditionalIncludeDirectories=".;../../includes;../../../../libs/MALLOC/includes;../../../localization/includes;../../../core/includes;../../../output_stream/includes;../../../../libs/hashtable;../../../fileio/includes;../../../../libs/intl"
+                               AdditionalIncludeDirectories=".;../../includes;../../../../libs/MALLOC/includes;../../../localization/includes;../../../core/includes;../../../output_stream/includes;../../../../libs/hashtable;../../../fileio/includes;../../../windows_tools/includes;../../../../libs/intl"
                                PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WITH_TK;FORDLL;NDEBUG;_WINDOWS;_USRDLL;IO_EXPORTS"
                                StringPooling="true"
                                RuntimeLibrary="0"
                        <Tool
                                Name="VCPreLinkEventTool"
                                Description="Make dependencies"
-                               CommandLine="lib /DEF:&quot;$(InputDir)LibScilab_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)LibScilab.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)io_f_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)io_f.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;cd $(IntDir) &gt;nul&#x0D;&#x0A;for %%f in (*.obj) do  ..\..\..\..\..\bin\dumpexts -o %%~nf.def -n io.dll %%f &gt;nul&#x0D;&#x0A;copy *.def iotmp.def &gt;nul&#x0D;&#x0A;copy ..\io_header.def+iotmp.def  ..\io.def &gt;nul&#x0D;&#x0A;del *.def &gt;nul&#x0D;&#x0A;cd .. &gt;nul&#x0D;&#x0A;"
+                               CommandLine="lib /DEF:&quot;$(InputDir)LibScilab_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)LibScilab.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)io_f_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)io_f.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)scilab_windows_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)scilab_windows.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;cd $(IntDir) &gt;nul&#x0D;&#x0A;for %%f in (*.obj) do  ..\..\..\..\..\bin\dumpexts -o %%~nf.def -n io.dll %%f &gt;nul&#x0D;&#x0A;copy *.def iotmp.def &gt;nul&#x0D;&#x0A;copy ..\io_header.def+iotmp.def  ..\io.def &gt;nul&#x0D;&#x0A;del *.def &gt;nul&#x0D;&#x0A;cd .. &gt;nul&#x0D;&#x0A;"
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="LibScilab.lib io_f.lib"
+                               AdditionalDependencies="LibScilab.lib io_f.lib scilab_windows.lib"
                                OutputFile="../../../../bin/$(ProjectName).dll"
                                LinkIncremental="1"
                                ModuleDefinitionFile="io.def"
                                InlineFunctionExpansion="1"
                                FavorSizeOrSpeed="1"
                                WholeProgramOptimization="false"
-                               AdditionalIncludeDirectories=".;../../includes;../../../../libs/MALLOC/includes;../../../localization/includes;../../../core/includes;../../../output_stream/includes;../../../../libs/hashtable;../../../fileio/includes;../../../../libs/intl"
+                               AdditionalIncludeDirectories=".;../../includes;../../../../libs/MALLOC/includes;../../../localization/includes;../../../core/includes;../../../output_stream/includes;../../../../libs/hashtable;../../../fileio/includes;../../../windows_tools/includes;../../../../libs/intl"
                                PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WITH_TK;FORDLL;NDEBUG;_WINDOWS;_USRDLL;IO_EXPORTS"
                                StringPooling="true"
                                RuntimeLibrary="0"
                        <Tool
                                Name="VCPreLinkEventTool"
                                Description="Make dependencies"
-                               CommandLine="lib /DEF:&quot;$(InputDir)LibScilab_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X64 /OUT:&quot;$(InputDir)LibScilab.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)io_f_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X64 /OUT:&quot;$(InputDir)io_f.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;cd $(IntDir) &gt;nul&#x0D;&#x0A;for %%f in (*.obj) do  ..\..\..\..\..\bin\dumpexts -o %%~nf.def -n io.dll %%f &gt;nul&#x0D;&#x0A;copy *.def iotmp.def &gt;nul&#x0D;&#x0A;copy ..\io_header.def+iotmp.def  ..\io.def &gt;nul&#x0D;&#x0A;del *.def &gt;nul&#x0D;&#x0A;cd .. &gt;nul&#x0D;&#x0A;"
+                               CommandLine="lib /DEF:&quot;$(InputDir)LibScilab_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X64 /OUT:&quot;$(InputDir)LibScilab.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)io_f_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X64 /OUT:&quot;$(InputDir)io_f.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)scilab_windows_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X64 /OUT:&quot;$(InputDir)scilab_windows.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;cd $(IntDir) &gt;nul&#x0D;&#x0A;for %%f in (*.obj) do  ..\..\..\..\..\bin\dumpexts -o %%~nf.def -n io.dll %%f &gt;nul&#x0D;&#x0A;copy *.def iotmp.def &gt;nul&#x0D;&#x0A;copy ..\io_header.def+iotmp.def  ..\io.def &gt;nul&#x0D;&#x0A;del *.def &gt;nul&#x0D;&#x0A;cd .. &gt;nul&#x0D;&#x0A;"
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="LibScilab.lib io_f.lib"
+                               AdditionalDependencies="LibScilab.lib io_f.lib scilab_windows.lib"
                                OutputFile="../../../../bin/$(ProjectName).dll"
                                LinkIncremental="1"
                                ModuleDefinitionFile="io.def"
                                >
                        </File>
                        <File
-                               RelativePath=".\setenvc.h"
+                               RelativePath="..\..\includes\setenvc.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\..\includes\setenvc.h"
+                               RelativePath=".\setenvc.h"
                                >
                        </File>
                        <File