Bug fix #14531: Allows SCIHOME to be specified by user (at start-up) 90/19490/3
Antoine ELIAS [Tue, 10 Oct 2017 15:21:37 +0000 (17:21 +0200)]
Change-Id: I1af580c5cb2a036a6e1c7492a139cfb629ccf2a7

15 files changed:
scilab/CHANGES.md
scilab/bin/scilab
scilab/modules/ast/src/cpp/system_env/sci_home.cpp
scilab/modules/core/help/en_US/scilab.xml
scilab/modules/core/help/en_US/variables/predefined/SCIHOME.xml
scilab/modules/core/help/fr_FR/scilab.xml
scilab/modules/core/help/ja_JP/scilab.xml
scilab/modules/core/help/ja_JP/variables/predefined/SCIHOME.xml
scilab/modules/core/help/pt_BR/scilab.xml
scilab/modules/core/help/ru_RU/scilab.xml
scilab/modules/core/help/ru_RU/variables/predefined/SCIHOME.xml
scilab/modules/core/includes/InitScilab.h
scilab/modules/core/src/cpp/InitScilab.cpp
scilab/modules/core/tests/nonreg_tests/bug_14531.tst [new file with mode: 0644]
scilab/modules/startup/src/cpp/scilab.cpp

index 0af4aec..5925a48 100644 (file)
@@ -394,6 +394,7 @@ the [development mailing list](dev@lists.scilab.org) for a particular toolbox.
 * [#14376](http://bugzilla.scilab.org/show_bug.cgi?id=14376): `input()` was broken: \n was introduced before prompting; multiple prompts occurred; the output value could be missing; "%" "\n" "\t" were no longer supported in messages...
 * [#14399](http://bugzilla.scilab.org/show_bug.cgi?id=14399): `whereami`: wrong information (line numbers).
 * [#14424](http://bugzilla.scilab.org/show_bug.cgi?id=14424): There were some troubles with `input`.
+* [#14531](http://bugzilla.scilab.org/show_bug.cgi?id=14531): It was not possible to specify SCIHOME as a start-up option.
 * [#14532](http://bugzilla.scilab.org/show_bug.cgi?id=14532): `test_run` failed for toolboxes that are not autoloaded.
 * [#14544](http://bugzilla.scilab.org/show_bug.cgi?id=14544): `scatter` and `scatter3` canceled any upstream `drawlater` instruction.
 * [#14573](http://bugzilla.scilab.org/show_bug.cgi?id=14573): `varargout` misworked when it was used in addition to fixed output arguments.
index 8bcc9d7..361ffeb 100755 (executable)
@@ -1015,6 +1015,7 @@ do_help()
     echo     "  -version        : print product version and exit."
     echo     "  -h/--help       : display help about this command."
     echo     "  --texmacs       : reserved for TeXMacs."
+    echo     "  -scihome dir    : Force SCIHOME to given dir."
     echo     " "
 
     echo     "Developer arguments:"
@@ -1120,7 +1121,7 @@ if test "$rest" = "yes"; then
             # Under Mac OS X, .app is adding the arg -psn_0_xxxx
             # (psn = ProcessSerialNumber). It is not used (but could be in the future)
                 ;;
-            -display|-f|-l|-e|-d|--parse-file)
+            -display|-f|-l|-e|-d|--parse-file|-scihome)
                 prevarg=1
                 ;;
             -args) # Accept extra arguments
index b277d81..c9323c3 100644 (file)
@@ -32,6 +32,10 @@ extern "C"
 #include "getenvc.h"
 #include "setenvvar.h"
 #include "getshortpathname.h"
+#include "sciprint.h"
+#ifndef _MSC_VER
+#include <sys/stat.h>
+#endif
 }
 
 /*--------------------------------------------------------------------------*/
@@ -266,11 +270,65 @@ void putenvSCIHOME(const char* _sci_home)
     delete[] CopyOfDefaultPath;
     FREE(ShortPath);
 }
+/*--------------------------------------------------------------------------*/
+static bool createDirectoryRecursively(std::wstring 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)
+        {
+            DWORD d = GetLastError();
+            if (d == ERROR_PATH_NOT_FOUND)
+            {
+                return false;
+            }
+        }
+    } while (pos != std::string::npos);
+
+#else
+    char* file_path = wide_string_to_UTF8(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 (errno != EEXIST)
+            {
+                *p = '/';
+                FREE(file_path);
+                return false;
+            }
+        }
+        *p = '/';
+    }
 
+    FREE(file_path);
+#endif
+    return true;
+}
 /*--------------------------------------------------------------------------*/
 void defineSCIHOME()
 {
-    wchar_t* sci_home = computeSCIHOMEW();
+    wchar_t* sci_home = getSCIHOMEW();
+    if (wcscmp(sci_home, L"") == 0)
+    {
+        sci_home = computeSCIHOMEW();
+    }
+    else
+    {
+        if (createDirectoryRecursively(sci_home) == false)
+        {
+            sciprint("Unable to create SCIHOME in `%ls`.\n", sci_home);
+            sciprint("Back to normal behaviour.\n");
+            sci_home = computeSCIHOMEW();
+        }
+    }
+
     setSCIHOMEW(sci_home);
     putenvSCIHOMEW(sci_home);
     FREE(sci_home);
index e71ae54..61b7665 100644 (file)
@@ -273,6 +273,15 @@ evstr(a(i+2))*2
                 </listitem>
             </varlistentry>
             <varlistentry>
+                <term>-scihome dir</term>
+                <listitem>
+                    <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!).
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
                 <term>--texmacs</term>
                 <listitem>
                     <para>This option is reserved for the external TeXMacs module.
@@ -507,6 +516,12 @@ echo $? ]]></screen>
                     <literal>-quit</literal> option added. <literal>-mem</literal> option removed.
                 </revremark>
             </revision>
+            <revision>
+                <revnumber>6.0.1</revnumber>
+                <revremark>
+                    <literal>-scihome</literal> option added.
+                </revremark>
+            </revision>
         </revhistory>
     </refsection>
 </refentry>
index da702b7..c53f694 100644 (file)
  * along with this program.
  *
  -->
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="SCIHOME" xml:lang="en">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
+          xmlns:scilab="http://www.scilab.org" xml:id="SCIHOME" xml:lang="en">
     <refnamediv>
         <refname>SCIHOME</refname>
         <refpurpose>contains the path to preferences, history files of your Scilab
         <para>
             &lt;Scilab-Version&gt; is current version of Scilab used.
         </para>
+        <note>
+           The default path assigned to <literal>SCIHOME</literal> may be replaced with a given path
+           specified with the <literal>-scihome</literal> option when launching Scilab.
+        </note>
     </refsection>
     <refsection>
         <title>Examples</title>
@@ -68,5 +75,10 @@ isdir(SCIHOME)
                 <link linkend="TMPDIR">TMPDIR</link>
             </member>
         </simplelist>
+        <simplelist type="inline">
+            <member>
+                <link linkend="scilab">Scilab startup</link>
+            </member>
+        </simplelist>
     </refsection>
 </refentry>
index 2e3b824..4666f67 100644 (file)
@@ -287,6 +287,14 @@ evstr(a(i+2))*2
                 </listitem>
             </varlistentry>
             <varlistentry>
+                <term>-scihome dir</term>
+                <listitem>
+                    <para>Affecte à SCIHOME le chemin spécifié par <literal>dir</literal> (entre
+                      guillemets s'il inclut des espaces)(pas entre apostrophes !).
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
                 <term>--texmacs</term>
                 <listitem>
                     <para>Cette option est réservée au module externe TeXMacs.</para>
@@ -522,6 +530,12 @@ echo $? ]]></screen>
                     Option <literal>-quit</literal> ajoutée. Option <literal>-mem</literal> supprimée.
                 </revremark>
             </revision>
+            <revision>
+                <revnumber>6.0.1</revnumber>
+                <revremark>
+                    Option <literal>-scihome</literal> ajoutée.
+                </revremark>
+            </revision>
         </revhistory>
     </refsection>
 </refentry>
index ba7b150..09a87ca 100644 (file)
@@ -275,6 +275,15 @@ evstr(a(i+2))*2
                 </listitem>
             </varlistentry>
             <varlistentry>
+                <term>-scihome dir</term>
+                <listitem>
+                    <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!).
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
                 <term>--texmacs</term>
                 <listitem>
                     <para>このオプションは TeXMacs用に予約されています.</para>
@@ -522,6 +531,12 @@ echo $? ]]></screen>
                     <literal>-quit</literal> option added. <literal>-mem</literal> option removed.
                 </revremark>
             </revision>
+            <revision>
+                <revnumber>6.0.1</revnumber>
+                <revremark>
+                    <literal>-scihome</literal> option added.
+                </revremark>
+            </revision>
         </revhistory>
     </refsection>
 </refentry>
\ No newline at end of file
index 092f1d5..ac4760b 100644 (file)
         </para>
         <para>&lt;User&gt; はカレントのログイン名です</para>
         <para>&lt;Scilab-Version&gt; は使用するScilabのバージョンです.</para>
+        <note>
+           The default path assigned to <literal>SCIHOME</literal> may be replaced with a given path
+           specified with the <literal>-scihome</literal> option when launching Scilab.
+        </note>
     </refsection>
     <refsection role="see also">
         <title>参照</title>
                 <link linkend="TMPDIR">TMPDIR</link>
             </member>
         </simplelist>
+        <simplelist type="inline">
+            <member>
+                <link linkend="scilab">Scilab startup</link>
+            </member>
+        </simplelist>
     </refsection>
 </refentry>
index fe975f9..fe30105 100644 (file)
@@ -215,6 +215,15 @@ evstr(a(i+2))*2
                 </listitem>
             </varlistentry>
             <varlistentry>
+                <term>-scihome dir</term>
+                <listitem>
+                    <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!).
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
                 <term>--texmacs</term>
                 <listitem>
                     <para>Esta opção é reservada para TexMacs.</para>
@@ -447,6 +456,12 @@ echo $? ]]></screen>
                     <literal>-quit</literal> option added. <literal>-mem</literal> option removed.
                 </revremark>
             </revision>
+            <revision>
+                <revnumber>6.0.1</revnumber>
+                <revremark>
+                    <literal>-scihome</literal> option added.
+                </revremark>
+            </revision>
         </revhistory>
     </refsection>
 </refentry>
index 4fced1a..9f9d1dd 100644 (file)
@@ -283,6 +283,15 @@ evstr(a(i+2))*2
                 </listitem>
             </varlistentry>
             <varlistentry>
+                <term>-scihome dir</term>
+                <listitem>
+                    <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!).
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
                 <term>--texmacs</term>
                 <listitem>
                     <para>Эта опция предназначена для TeXMacs.</para>
@@ -537,6 +546,12 @@ echo $? ]]></screen>
                     Добавлена опция <literal>-quit</literal>. Опция <literal>-mem</literal> удалена.
                 </revremark>
             </revision>
+            <revision>
+                <revnumber>6.0.1</revnumber>
+                <revremark>
+                    <literal>-scihome</literal> option added.
+                </revremark>
+            </revision>
         </revhistory>
     </refsection>
 </refentry>
index b024fa5..8724de9 100644 (file)
  * along with this program.
  *
  -->
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="SCIHOME" xml:lang="ru">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
+          xmlns:scilab="http://www.scilab.org" xml:id="SCIHOME" xml:lang="ru">
     <refnamediv>
         <refname>SCIHOME</refname>
         <refpurpose>
         <para>
             &lt;Scilab-Version&gt; - ваша текущая версия используемого Scilab.
         </para>
+        <note>
+           The default path assigned to <literal>SCIHOME</literal> may be replaced with a given path
+           specified with the <literal>-scihome</literal> option when launching Scilab.
+        </note>
     </refsection>
     <refsection role="see also">
         <title>Смотрите также</title>
                 <link linkend="TMPDIR">TMPDIR</link>
             </member>
         </simplelist>
+        <simplelist type="inline">
+            <member>
+                <link linkend="scilab">Scilab startup</link>
+            </member>
+        </simplelist>
     </refsection>
 </refentry>
index ca1ad59..616a10b 100644 (file)
@@ -25,6 +25,7 @@ typedef struct
     char* pstFile;
     char* pstExec;
     char* pstLang;
+    char* pstSciHome;
     void* pExpTree;
     int iParseTrace;
     int iPrintAst;
index 1cd6093..d0e8223 100644 (file)
@@ -148,6 +148,14 @@ int StartScilabEngine(ScilabEngineInfo* _pSEI)
     int iMainRet = 0;
     ConfigVariable::setStartProcessing(true);
 
+    // Update scihome from command line
+    if (_pSEI->pstSciHome && strcmp(_pSEI->pstSciHome, "") != 0)
+    {
+        wchar_t* w = to_wide_string(_pSEI->pstSciHome);
+        ConfigVariable::setSCIHOME(w);
+        FREE(w);
+    }
+
     // ignore -e argument if the command is empty
     if (_pSEI->pstExec && strcmp(_pSEI->pstExec, "") == 0)
     {
diff --git a/scilab/modules/core/tests/nonreg_tests/bug_14531.tst b/scilab/modules/core/tests/nonreg_tests/bug_14531.tst
new file mode 100644 (file)
index 0000000..8393c75
--- /dev/null
@@ -0,0 +1,26 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2017 - ESI - Antoine ELIAS
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- INTERACTIVE TEST -->
+//
+// <-- Non-regression test for bug 14531 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=14531
+//
+// <-- Short Description -->
+// Allow SCIHOME to be specified by user (at start-up)
+
+//start scilab like
+
+//windows
+bin\scilex -scihome %USERPROFILE%\Scilab\new_home
+
+//linux
+bin/scilab -nwni -scihome ~/Scilab/new_home
+
+//check that SCIHOME shows good directory
\ No newline at end of file
index 694c349..99ce599 100644 (file)
@@ -83,6 +83,7 @@ static void usage(void)
     std::cerr << "      -nwni            : Enable terminal mode." << std::endl;
     std::cerr << "      -ns              : Don't execute etc/scilab.start." << std::endl;
     std::cerr << "      --help           : Display this help." << std::endl;
+    std::cerr << "      -scihome <dir>   : Force SCIHOME to <dir>." << std::endl;
     std::cerr << "Developer Trace arguments:" << std::endl;
     std::cerr << "      --parse-trace    : Display bison state machine evolution." << std::endl;
     std::cerr << "      --AST-trace      : Display ASCII-art AST to be human readable." << std::endl;
@@ -300,6 +301,14 @@ static int get_option(const int argc, char *argv[], ScilabEngineInfo* _pSEI)
         {
             _pSEI->iWebMode = 1;
         }
+        else if (!strcmp("-scihome", argv[i]))
+        {
+            i++;
+            if (argc >= i)
+            {
+                _pSEI->pstSciHome = argv[i];
+            }
+        }
     }
 
     ConfigVariable::setCommandLineArgs(argc, argv);