manage relative path in -scihome option 05/19505/3
Antoine ELIAS [Tue, 24 Oct 2017 15:24:57 +0000 (17:24 +0200)]
Change-Id: Ic13e448c8598548d68194fad3883ddb1667ef7d2

scilab/modules/ast/ast.vcxproj
scilab/modules/ast/includes/system_env/sci_home.h
scilab/modules/ast/src/cpp/system_env/sci_home.cpp
scilab/modules/core/help/en_US/scilab.xml
scilab/modules/core/help/fr_FR/scilab.xml
scilab/modules/core/help/ja_JP/scilab.xml
scilab/modules/core/help/pt_BR/scilab.xml
scilab/modules/core/help/ru_RU/scilab.xml

index f1b8184..a5d79fd 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
     <ProjectConfiguration Include="Debug|Win32">
       <OutputFile>$(SolutionDir)bin\$(ProjectName).dll</OutputFile>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <ImportLibrary>../../bin/$(ProjectName).lib</ImportLibrary>
-      <AdditionalDependencies>functions_manager.lib;string.lib;fileio.lib;dynamic_link.lib;sciconsole.lib;output_stream.lib;core.lib;io.lib;elementary_functions_f.lib;elementary_functions.lib;polynomials_f.lib;linear_algebra_f.lib;coverage.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>Shlwapi.lib;functions_manager.lib;string.lib;fileio.lib;dynamic_link.lib;sciconsole.lib;output_stream.lib;core.lib;io.lib;elementary_functions_f.lib;elementary_functions.lib;polynomials_f.lib;linear_algebra_f.lib;coverage.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <RandomizedBaseAddress>false</RandomizedBaseAddress>
     </Link>
     <PreLinkEvent>
@@ -150,7 +150,7 @@ lib /DEF:"$(ProjectDir)functions_manager_import.def" /SUBSYSTEM:WINDOWS /MACHINE
       <OutputFile>$(SolutionDir)bin\$(ProjectName).dll</OutputFile>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <ImportLibrary>../../bin/$(ProjectName).lib</ImportLibrary>
-      <AdditionalDependencies>functions_manager.lib;string.lib;fileio.lib;dynamic_link.lib;sciconsole.lib;output_stream.lib;core.lib;io.lib;elementary_functions_f.lib;elementary_functions.lib;polynomials_f.lib;linear_algebra_f.lib;coverage.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>Shlwapi.lib;functions_manager.lib;string.lib;fileio.lib;dynamic_link.lib;sciconsole.lib;output_stream.lib;core.lib;io.lib;elementary_functions_f.lib;elementary_functions.lib;polynomials_f.lib;linear_algebra_f.lib;coverage.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <RandomizedBaseAddress>false</RandomizedBaseAddress>
     </Link>
     <PreLinkEvent>
@@ -187,7 +187,7 @@ lib /DEF:"$(ProjectDir)functions_manager_import.def" /SUBSYSTEM:WINDOWS /MACHINE
     <Link>
       <OutputFile>$(SolutionDir)bin\$(ProjectName).dll</OutputFile>
       <ImportLibrary>../../bin/$(ProjectName).lib</ImportLibrary>
-      <AdditionalDependencies>functions_manager.lib;string.lib;fileio.lib;dynamic_link.lib;sciconsole.lib;output_stream.lib;core.lib;io.lib;elementary_functions_f.lib;elementary_functions.lib;polynomials_f.lib;linear_algebra_f.lib;coverage.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>Shlwapi.lib;functions_manager.lib;string.lib;fileio.lib;dynamic_link.lib;sciconsole.lib;output_stream.lib;core.lib;io.lib;elementary_functions_f.lib;elementary_functions.lib;polynomials_f.lib;linear_algebra_f.lib;coverage.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <RandomizedBaseAddress>false</RandomizedBaseAddress>
     </Link>
     <PreLinkEvent>
@@ -227,7 +227,7 @@ lib /DEF:"$(ProjectDir)functions_manager_import.def" /SUBSYSTEM:WINDOWS /MACHINE
     <Link>
       <OutputFile>$(SolutionDir)bin\$(ProjectName).dll</OutputFile>
       <ImportLibrary>../../bin/$(ProjectName).lib</ImportLibrary>
-      <AdditionalDependencies>functions_manager.lib;string.lib;fileio.lib;dynamic_link.lib;sciconsole.lib;output_stream.lib;core.lib;io.lib;elementary_functions_f.lib;elementary_functions.lib;polynomials_f.lib;linear_algebra_f.lib;coverage.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>Shlwapi.lib;functions_manager.lib;string.lib;fileio.lib;dynamic_link.lib;sciconsole.lib;output_stream.lib;core.lib;io.lib;elementary_functions_f.lib;elementary_functions.lib;polynomials_f.lib;linear_algebra_f.lib;coverage.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <RandomizedBaseAddress>false</RandomizedBaseAddress>
     </Link>
     <PreLinkEvent>
index 2e724d9..8dcfd53 100644 (file)
 EXTERN_AST wchar_t *getSCIHOMEW(void);
 EXTERN_AST char *getSCIHOME(void);
 
-EXTERN_AST void setSCIHOMEW(const wchar_t* _sci_path);
-EXTERN_AST void setSCIHOME(const char* _sci_path);
-
-EXTERN_AST wchar_t* computeSCIHOMEW();
-EXTERN_AST char* computeSCIHOME();
-
-EXTERN_AST wchar_t* getenvSCIHOMEW(void);
-EXTERN_AST char* getenvSCIHOME(void);
-
-EXTERN_AST void putenvSCIHOMEW(const wchar_t* _sci_path);
-EXTERN_AST void putenvSCIHOME(const char* _sci_path);
-
 EXTERN_AST void defineSCIHOME();
 
 #endif // ! __SCI_HOME_H__
index 19830ee..e4c8b59 100644 (file)
@@ -37,9 +37,19 @@ extern "C"
 #include "createdirectory.h"
 #ifndef _MSC_VER
 #include <sys/stat.h>
+#else
+#include <Shlwapi.h>
 #endif
 }
 
+static void setSCIHOMEW(const wchar_t* _sci_home);
+static void putenvSCIHOME(const char* _sci_home);
+static char* computeSCIHOME(const char* path = "");
+static wchar_t* computeSCIHOMEW(const wchar_t* path = L"");
+static bool createDirectoryRecursivelyW(const std::wstring& path);
+static bool createDirectoryRecursively(const std::string& path);
+
+
 /*--------------------------------------------------------------------------*/
 wchar_t* getSCIHOMEW(void)
 {
@@ -56,14 +66,14 @@ char* getSCIHOME(void)
     return wide_string_to_UTF8(tmpSCIHOME.c_str());
 }
 /*--------------------------------------------------------------------------*/
-void setSCIHOME(const char* _sci_home)
+static void setSCIHOME(const char* _sci_home)
 {
     wchar_t* pstTemp = to_wide_string(_sci_home);
     setSCIHOMEW(pstTemp);
     FREE(pstTemp);
 }
 /*--------------------------------------------------------------------------*/
-void setSCIHOMEW(const wchar_t* _sci_home)
+static void setSCIHOMEW(const wchar_t* _sci_home)
 {
     //add SCI value in context as variable
     types::String *pS = new types::String(_sci_home);
@@ -74,16 +84,18 @@ void setSCIHOMEW(const wchar_t* _sci_home)
 }
 
 /*--------------------------------------------------------------------------*/
-wchar_t* computeSCIHOMEW(void)
+static wchar_t* computeSCIHOMEW(const wchar_t* path)
 {
-    char* pstTemp = computeSCIHOME();
+    char* pstHome = wide_string_to_UTF8(path);
+    char* pstTemp = computeSCIHOME(pstHome);
     wchar_t* pstReturn = to_wide_string(pstTemp);
     FREE(pstTemp);
+    FREE(pstHome);
     return pstReturn;
 }
 /*--------------------------------------------------------------------------*/
 #ifdef _MSC_VER
-char* computeSCIHOME(void)
+static char* computeSCIHOME(const char* path)
 {
 #define BASEDIR "Scilab"
     int ierr = 0;
@@ -151,17 +163,24 @@ char* computeSCIHOME(void)
 
     /* Set SCIHOME environment variable */
     os_sprintf(USERPATHSCILAB, "%s%s%s", USERHOMESYSTEM, DIR_SEPARATOR, BASEDIR);
-    os_sprintf(SCIHOMEPATH, "%s%s%s", USERPATHSCILAB, DIR_SEPARATOR, SCI_VERSION_STRING);
+    if (path && path[0] != '\0')
+    {
+        os_sprintf(SCIHOMEPATH, "%s%s%s", USERPATHSCILAB, DIR_SEPARATOR, path);
+    }
+    else
+    {
+        os_sprintf(SCIHOMEPATH, "%s%s%s", USERPATHSCILAB, DIR_SEPARATOR, SCI_VERSION_STRING);
+    }
 
     /* creates directory if it does not exists */
     if (!isdir(SCIHOMEPATH))
     {
         if (!isdir(USERPATHSCILAB))
         {
-            createdirectory(USERPATHSCILAB);
+            createDirectoryRecursively(USERPATHSCILAB);
         }
 
-        if (createdirectory(SCIHOMEPATH))
+        if (createDirectoryRecursively(SCIHOMEPATH))
         {
 
             return os_strdup(SCIHOMEPATH);
@@ -175,7 +194,7 @@ char* computeSCIHOME(void)
     return NULL;
 }
 #else
-char* computeSCIHOME(void)
+static char* computeSCIHOME(const char* path)
 {
 #define BASEDIR ".Scilab"
     int ierr   = 0;
@@ -194,17 +213,24 @@ char* computeSCIHOME(void)
 
     /* Set SCIHOME environment variable */
     sprintf(USERPATHSCILAB, "%s%s%s", USERHOMESYSTEM, DIR_SEPARATOR, BASEDIR);
-    sprintf(SCIHOMEPATH, "%s%s%s", USERPATHSCILAB, DIR_SEPARATOR, SCI_VERSION_STRING);
+    if (path && path[0] != '\0')
+    {
+        sprintf(SCIHOMEPATH, "%s%s%s", USERPATHSCILAB, DIR_SEPARATOR, path);
+    }
+    else
+    {
+        sprintf(SCIHOMEPATH, "%s%s%s", USERPATHSCILAB, DIR_SEPARATOR, SCI_VERSION_STRING);
+    }
 
     /* creates directory if it does not exists */
     if (!isdir(SCIHOMEPATH))
     {
         if (!isdir(USERPATHSCILAB))
         {
-            createdirectory(USERPATHSCILAB);
+            createDirectoryRecursively(USERPATHSCILAB);
         }
 
-        if (createdirectory(SCIHOMEPATH))
+        if (createDirectoryRecursively(SCIHOMEPATH))
         {
             return os_strdup(SCIHOMEPATH);
         }
@@ -219,7 +245,7 @@ char* computeSCIHOME(void)
 #endif
 
 /*--------------------------------------------------------------------------*/
-char* getenvSCIHOME(void)
+static char* getenvSCIHOME(void)
 {
     int ierr, iflag = 0;
     int lbuf = PATH_MAX;
@@ -238,7 +264,7 @@ char* getenvSCIHOME(void)
     return SciHome;
 }
 /*--------------------------------------------------------------------------*/
-wchar_t* getenvSCIHOMEW(void)
+static wchar_t* getenvSCIHOMEW(void)
 {
     char *SciHome = getenvSCIHOME();
     wchar_t* pstTemp = to_wide_string(SciHome);
@@ -246,7 +272,7 @@ wchar_t* getenvSCIHOMEW(void)
     return pstTemp;
 }
 /*--------------------------------------------------------------------------*/
-void putenvSCIHOMEW(const wchar_t* _sci_home)
+static void putenvSCIHOMEW(const wchar_t* _sci_home)
 {
     char* pstTemp = wide_string_to_UTF8(_sci_home);
     putenvSCIHOME(pstTemp);
@@ -254,7 +280,7 @@ void putenvSCIHOMEW(const wchar_t* _sci_home)
     return;
 }
 
-void putenvSCIHOME(const char* _sci_home)
+static void putenvSCIHOME(const char* _sci_home)
 {
     char *ShortPath = NULL;
     char *CopyOfDefaultPath = NULL;
@@ -273,14 +299,22 @@ void putenvSCIHOME(const char* _sci_home)
     FREE(ShortPath);
 }
 /*--------------------------------------------------------------------------*/
-static bool createDirectoryRecursively(std::wstring path)
+static bool createDirectoryRecursivelyW(const std::wstring& path)
+{
+    char* c = wide_string_to_UTF8(path.data());
+    std::string s(c);
+    FREE(c);
+    return createDirectoryRecursively(s);
+}
+
+static bool createDirectoryRecursively(const std::string& path)
 {
 #ifdef _MSC_VER
     size_t pos = 0;
     do
     {
-        pos = path.find_first_of(L"\\/", pos + 1);
-        if (CreateDirectoryW(path.substr(0, pos).c_str(), NULL) == FALSE)
+        pos = path.find_first_of("\\/", pos + 1);
+        if (CreateDirectoryA(path.substr(0, pos).c_str(), NULL) == FALSE)
         {
             DWORD d = GetLastError();
             if (d == ERROR_PATH_NOT_FOUND)
@@ -290,14 +324,15 @@ static bool createDirectoryRecursively(std::wstring path)
         }
     } while (pos != std::string::npos);
 
+    return true;
 #else
-    char* file_path = wide_string_to_UTF8(path.data());
+    char* file_path = os_strdup(path.data());
 
     char* p = NULL;
     for (p = strchr(file_path + 1, '/'); p; p = strchr(p + 1, '/'))
     {
         *p = '\0';
-        if (mkdir(file_path, 777) == -1)
+        if (mkdir(file_path, 0777) == -1)
         {
             if (errno != EEXIST)
             {
@@ -309,11 +344,38 @@ static bool createDirectoryRecursively(std::wstring path)
         *p = '/';
     }
 
+    //create final folder
+    if (mkdir(path.data(), 0777) == -1)
+    {
+        if (errno != EEXIST)
+        {
+            *p = '/';
+            FREE(file_path);
+            return false;
+        }
+    }
+
     FREE(file_path);
-#endif
     return true;
+#endif
 }
 /*--------------------------------------------------------------------------*/
+static bool isAbsolutePath(const wchar_t* path)
+{
+#ifdef _MSC_VER
+    if(PathIsRelative(path))
+    {
+        return false;
+    }
+    else
+    {
+        return true;
+    }
+#else
+    return path[0] == L'/';
+#endif
+}
+
 void defineSCIHOME()
 {
     wchar_t* sci_home = getSCIHOMEW();
@@ -324,12 +386,21 @@ void defineSCIHOME()
     }
     else
     {
-        if (createDirectoryRecursively(sci_home) == false)
+        if (isAbsolutePath(sci_home))
+        {
+            if (createDirectoryRecursivelyW(sci_home) == false)
+            {
+                sciprint("Unable to create SCIHOME in `%ls`.\n", sci_home);
+                sciprint("Back to normal behaviour.\n");
+                FREE(sci_home);
+                sci_home = computeSCIHOMEW();
+            }
+        }
+        else
         {
-            sciprint("Unable to create SCIHOME in `%ls`.\n", sci_home);
-            sciprint("Back to normal behaviour.\n");
+            std::wstring w(sci_home);
             FREE(sci_home);
-            sci_home = computeSCIHOMEW();
+            sci_home = computeSCIHOMEW(w.data());
         }
     }
 
index bcbeb49..185a029 100644 (file)
@@ -278,6 +278,9 @@ evstr(a(i+2))*2
                     <para>Forces SCIHOME to the <literal>dir</literal> directory. If the path
                       includes some white space, it must be specified between double-quotes (no
                       single quotes!).
+                      if <literal>dir</literal> is a relative path, <literal>dir</literal> is add to parent standard SCIHOME folder.
+                      On Windows: %USERPROFILE%\AppData\Roaming\Scilab\<literal>dir</literal>
+                      On Linux/MacOS: ~/.Scilab/<literal>dir</literal>
                     </para>
                 </listitem>
             </varlistentry>
index 5f173e1..197bd24 100644 (file)
@@ -291,6 +291,9 @@ evstr(a(i+2))*2
                 <listitem>
                     <para>Affecte à SCIHOME le chemin spécifié par <literal>dir</literal> (entre
                       guillemets s'il inclut des espaces)(pas entre apostrophes !).
+                      Si <literal>dir</literal> est un chemin relatif il est ajouté au répertoire parent de SCIHOME.
+                      Sous Windows: %USERPROFILE%\AppData\Roaming\Scilab\<literal>dir</literal>
+                      Sous Linux/MacOS: ~/.Scilab/<literal>dir</literal>
                     </para>
                 </listitem>
             </varlistentry>
index ce31694..e3ed18c 100644 (file)
@@ -280,6 +280,9 @@ evstr(a(i+2))*2
                     <para>Forces SCIHOME to the <literal>dir</literal> directory. If the path
                       includes some white space, it must be specified between double-quotes (no
                       single quotes!).
+                      if <literal>dir</literal> is a relative path, <literal>dir</literal> is add to parent standard SCIHOME folder.
+                      On Windows: %USERPROFILE%\AppData\Roaming\Scilab\<literal>dir</literal>
+                      On Linux/MacOS: ~/.Scilab/<literal>dir</literal>
                     </para>
                 </listitem>
             </varlistentry>
index 90d3cef..0420829 100644 (file)
@@ -220,6 +220,9 @@ evstr(a(i+2))*2
                     <para>Forces SCIHOME to the <literal>dir</literal> directory. If the path
                       includes some white space, it must be specified between double-quotes (no
                       single quotes!).
+                      if <literal>dir</literal> is a relative path, <literal>dir</literal> is add to parent standard SCIHOME folder.
+                      On Windows: %USERPROFILE%\AppData\Roaming\Scilab\<literal>dir</literal>
+                      On Linux/MacOS: ~/.Scilab/<literal>dir</literal>
                     </para>
                 </listitem>
             </varlistentry>
index 392011f..b9e9c24 100644 (file)
@@ -288,6 +288,9 @@ evstr(a(i+2))*2
                     <para>Forces SCIHOME to the <literal>dir</literal> directory. If the path
                       includes some white space, it must be specified between double-quotes (no
                       single quotes!).
+                      if <literal>dir</literal> is a relative path, <literal>dir</literal> is add to parent standard SCIHOME folder.
+                      On Windows: %USERPROFILE%\AppData\Roaming\Scilab\<literal>dir</literal>
+                      On Linux/MacOS: ~/.Scilab/<literal>dir</literal>
                     </para>
                 </listitem>
             </varlistentry>