fix trouble in string(lib) about SCI expand 29/18829/3
Antoine ELIAS [Tue, 3 Jan 2017 09:45:27 +0000 (10:45 +0100)]
Change-Id: I60a04d059351c61199bf8d250927f2fcfa2782a8

scilab/modules/ast/src/cpp/types/library.cpp
scilab/modules/fileio/includes/expandPathVariable.h
scilab/modules/fileio/includes/pathconvert.h
scilab/modules/fileio/src/c/fullpath.c
scilab/modules/fileio/src/c/pathconvert.c
scilab/modules/fileio/src/cpp/expandPathVariable.cpp
scilab/modules/io/sci_gateway/cpp/sci_lib.cpp
scilab/modules/io/src/cpp/loadlib.cpp

index ee6c122..1e929b7 100644 (file)
@@ -131,10 +131,6 @@ int Library::getMacrosName(std::list<std::wstring>& lst)
 
 std::wstring Library::getPath()
 {
-    wchar_t* pwstFullPath = (wchar_t*)MALLOC(sizeof(wchar_t) * (PATH_MAX * 2));
-    get_full_pathW(pwstFullPath, m_wstPath.c_str(), PATH_MAX * 2);
-    std::wstring wstrOut(pwstFullPath);
-    FREE(pwstFullPath);
-    return wstrOut;
+    return m_wstPath;
 }
 }
index a92d03b..1dfdc06 100644 (file)
@@ -36,14 +36,14 @@ extern "C"
 * @param[in] string where to find a variable and expand
 * @return string with expanded variable
 */
-FILEIO_IMPEXP char *expandPathVariable(char* str);
+FILEIO_IMPEXP char *expandPathVariable(const char* str);
 
 /**
 * expand in_name to produce out_name (wide string)
 * @param[in] wide string where to find a variable and expand
 * @return wide string with expanded variable
 */
-FILEIO_IMPEXP wchar_t *expandPathVariableW(wchar_t *wcstr);
+FILEIO_IMPEXP wchar_t *expandPathVariableW(const wchar_t *wcstr);
 
 /**
 * set NULL to all scilab "Variable" (ie: SCI, SCIHOME, ....)
index 716b0b1..73ff8a6 100644 (file)
@@ -28,9 +28,9 @@ typedef enum
     AUTO_STYLE = 2
 } PathConvertType;
 
-FILEIO_IMPEXP wchar_t *pathconvertW(wchar_t* wcpath, BOOL flagtrail, BOOL flagexpand, PathConvertType PType);
+FILEIO_IMPEXP wchar_t *pathconvertW(const wchar_t* wcpath, BOOL flagtrail, BOOL flagexpand, PathConvertType PType);
 
-FILEIO_IMPEXP char *pathconvert(char* path, BOOL flagtrail, BOOL flagexpand, PathConvertType PType);
+FILEIO_IMPEXP char *pathconvert(const char* path, BOOL flagtrail, BOOL flagexpand, PathConvertType PType);
 
 #endif /* PATHCONVERT_H__ */
 /*--------------------------------------------------------------------------*/
index 9bf1280..fb72e13 100644 (file)
@@ -42,7 +42,7 @@ char *get_full_path(char *_FullPath, const char *_Path, size_t _SizeInBytes)
     wchar_t *wPath = to_wide_string((char *)_Path);
     wchar_t *wFullPath = (wchar_t *) MALLOC(sizeof(wchar_t) * _SizeInBytes);
 
-    _wfullpath(wFullPath, wPath, _SizeInBytes);
+    get_full_pathW(wFullPath, wPath, _SizeInBytes);
     returnedFullPath = wide_string_to_UTF8(wFullPath);
     if (returnedFullPath)
     {
index b26f0d4..cffc767 100644 (file)
 /*--------------------------------------------------------------------------*/
 #define CYGWINSTART L"/cygdrive/"
 /*--------------------------------------------------------------------------*/
-static wchar_t *cygwintowindowspath(wchar_t *cygwinpath, BOOL *bConverted);
-static wchar_t *windowstocygwinpath(wchar_t *windowspath, BOOL *bConverted);
+static wchar_t *cygwintowindowspath(const wchar_t *cygwinpath, BOOL *bConverted);
+static wchar_t *windowstocygwinpath(const wchar_t *windowspath, BOOL *bConverted);
 /*--------------------------------------------------------------------------*/
-wchar_t *pathconvertW(wchar_t* wcpath, BOOL flagtrail, BOOL flagexpand, PathConvertType PType)
+wchar_t *pathconvertW(const wchar_t* wcpath, BOOL flagtrail, BOOL flagexpand, PathConvertType PType)
 {
     wchar_t *convertedPath = NULL;
     if (wcpath)
@@ -115,7 +115,7 @@ wchar_t *pathconvertW(wchar_t* wcpath, BOOL flagtrail, BOOL flagexpand, PathConv
     return convertedPath;
 }
 /*--------------------------------------------------------------------------*/
-char *pathconvert(char* path, BOOL flagtrail, BOOL flagexpand, PathConvertType PType)
+char *pathconvert(const char* path, BOOL flagtrail, BOOL flagexpand, PathConvertType PType)
 {
     char *convertedPath = NULL;
     if (path)
@@ -136,7 +136,7 @@ char *pathconvert(char* path, BOOL flagtrail, BOOL flagexpand, PathConvertType P
     return convertedPath;
 }
 /*--------------------------------------------------------------------------*/
-static wchar_t *cygwintowindowspath(wchar_t *cygwinpath, BOOL *bConverted)
+static wchar_t *cygwintowindowspath(const wchar_t *cygwinpath, BOOL *bConverted)
 {
     wchar_t *windowspath = NULL;
     *bConverted        = FALSE;
@@ -205,7 +205,7 @@ static wchar_t *cygwintowindowspath(wchar_t *cygwinpath, BOOL *bConverted)
     return windowspath;
 }
 /*--------------------------------------------------------------------------*/
-static wchar_t *windowstocygwinpath(wchar_t *windowspath, BOOL *bConverted)
+static wchar_t *windowstocygwinpath(const wchar_t *windowspath, BOOL *bConverted)
 {
     wchar_t *cygwinpath = NULL;
     *bConverted = FALSE;
index 611d0c8..df6f718 100644 (file)
@@ -55,7 +55,7 @@ static struct VARIABLEALIAS VARIABLES_words[NB_ALIAS] =
 static wchar_t *getVariableValueDefinedInScilab(VARIABLEALIAS* var);
 static wchar_t *convertFileSeparators(wchar_t *wcStr);
 /*--------------------------------------------------------------------------*/
-wchar_t *expandPathVariableW(wchar_t *wcstr)
+wchar_t *expandPathVariableW(const wchar_t *wcstr)
 {
     wchar_t *wcexpanded = NULL;
     if (wcstr)
@@ -128,7 +128,7 @@ wchar_t *expandPathVariableW(wchar_t *wcstr)
     return wcexpanded;
 }
 /*--------------------------------------------------------------------------*/
-char *expandPathVariable(char* str)
+char *expandPathVariable(const char* str)
 {
     char *expanded = NULL;
     wchar_t *wstr = to_wide_string(str);
index dd08cde..baed8e9 100644 (file)
@@ -53,7 +53,7 @@ types::Function::ReturnValue sci_gwlib(types::typed_list &in, int /*_iRetCount*/
     }
 
     wchar_t* pstPath = pS->get(0);
-    wchar_t* pwstPath = pathconvertW(pstPath, TRUE, TRUE, AUTO_STYLE);
+    wchar_t* pwstPath = pathconvertW(pstPath, TRUE, FALSE, AUTO_STYLE);
     int err = 0;
     types::Library* lib = loadlib(pwstPath, &err, false, false);
     FREE(pwstPath);
index c648f4a..a97d69a 100644 (file)
@@ -25,6 +25,7 @@ extern "C"
 #include "expandPathVariable.h"
 #include "fullpath.h"
 #include "PATH_MAX.h"
+#include "pathconvert.h"
 #include <libxml/xpath.h>
 #include <libxml/xmlreader.h>
 }
@@ -37,13 +38,22 @@ types::Library* loadlib(const std::wstring& _wstXML, int* err, bool _isFile, boo
 {
     types::Library* lib = NULL;
 
-    wchar_t* pwstPathLib = expandPathVariableW((wchar_t*)_wstXML.c_str());
+    wchar_t* pwstXML = pathconvertW(_wstXML.data(), FALSE, FALSE, AUTO_STYLE);
+    wchar_t* pwstPathLib = expandPathVariableW(pwstXML);
+
+    bool expanded = true;
+    if (wcscmp(pwstPathLib, pwstXML) == 0)
+    {
+        expanded = false;
+    }
 
     wchar_t* pwstTemp = (wchar_t*)MALLOC(sizeof(wchar_t) * (PATH_MAX * 2));
     get_full_pathW(pwstTemp, pwstPathLib, PATH_MAX * 2);
     FREE(pwstPathLib);
 
-    std::wstring wstOriginalPath(_wstXML);
+
+    std::wstring wstOriginalPath(pwstXML);
+    FREE(pwstXML);
     std::wstring wstFile(pwstTemp);
     std::wstring wstPath(pwstTemp);
     FREE(pwstTemp);
@@ -52,7 +62,7 @@ types::Library* loadlib(const std::wstring& _wstXML, int* err, bool _isFile, boo
     {
         //remove / or \ at the end
         size_t pos = wstPath.find_last_of(L"/\\");
-        wstPath = wstPath.substr(0, pos);
+        wstPath = wstPath.substr(0, pos + 1);
         pos = wstOriginalPath.find_last_of(L"/\\");
         wstOriginalPath = wstOriginalPath.substr(0, pos + 1); //with ending /
     }
@@ -74,7 +84,7 @@ types::Library* loadlib(const std::wstring& _wstXML, int* err, bool _isFile, boo
         return lib;
     }
 
-    lib = new types::Library(wstOriginalPath);
+    lib = new types::Library(expanded ? wstOriginalPath : wstPath);
 
     std::wstring stFilename(wstPath);
     if (stFilename.empty() == false && *stFilename.rbegin() != DIR_SEPARATORW[0])
@@ -119,18 +129,19 @@ int parseLibFile(const std::wstring& _wstXML, MacroInfoList& info, std::wstring&
         FREE(pstFile);
         return 1;
     }
-    std::string s(_wstXML.begin(),_wstXML.end());
+
+    std::string s(_wstXML.begin(), _wstXML.end());
     std::ifstream file(s);
     if (file)
     {
         const std::string XMLDecl("<?xml");
         std::string readXMLDecl;
-        readXMLDecl.resize(XMLDecl.length(),' ');//reserve space
-        file.read(&*readXMLDecl.begin(),XMLDecl.length());
+        readXMLDecl.resize(XMLDecl.length(), ' ');//reserve space
+        file.read(&*readXMLDecl.begin(), XMLDecl.length());
         if (XMLDecl != readXMLDecl)
         {
-          FREE(pstFile);
-          return 4;
+            FREE(pstFile);
+            return 4;
         }
     }