From 2bd67674df81ddd985f10d76b20acde2a2398087 Mon Sep 17 00:00:00 2001 From: Antoine ELIAS Date: Tue, 3 Jan 2017 16:12:53 +0100 Subject: [PATCH] bug 14909: getshortpathname and getlongpathname return values with '\' instead of '/' Change-Id: I1cac6de9737a85c41b67a14ffb6591cfac1befe1 --- scilab/CHANGES.md | 1 + scilab/modules/fileio/includes/getshortpathname.h | 2 +- .../fileio/sci_gateway/cpp/sci_getlongpathname.cpp | 5 +- .../sci_gateway/cpp/sci_getshortpathname.cpp | 58 ++------------------ scilab/modules/fileio/src/c/getlongpathname.c | 4 +- scilab/modules/fileio/src/c/getlongpathname.h | 4 +- scilab/modules/fileio/src/c/getshortpathname.c | 2 +- .../fileio/tests/nonreg_tests/bug_14909.dia.ref | 21 +++++++ .../fileio/tests/nonreg_tests/bug_14909.tst | 24 ++++++++ 9 files changed, 60 insertions(+), 61 deletions(-) create mode 100644 scilab/modules/fileio/tests/nonreg_tests/bug_14909.dia.ref create mode 100644 scilab/modules/fileio/tests/nonreg_tests/bug_14909.tst diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md index e9053d2..ba1e968 100644 --- a/scilab/CHANGES.md +++ b/scilab/CHANGES.md @@ -416,6 +416,7 @@ Bug Fixes * [#14821](http://bugzilla.scilab.org/show_bug.cgi?id=14821): `getio` function was missing. An error on the diary file opened has been corrected * [#14839](http://bugzilla.scilab.org/show_bug.cgi?id=14839): `plot2d2` crashed Scilab. * [#14887](http://bugzilla.scilab.org/show_bug.cgi?id=14887): For many graphic handle types, the display of the `.tag` value missed `".."` delimiters +* [#14909](http://bugzilla.scilab.org/show_bug.cgi?id=14909): getlongpathname and getshortpathname return values with "\" instead of "/" ### Bugs fixed in 6.0.0 beta-2 and earlier 6.0.0 pre-releases: diff --git a/scilab/modules/fileio/includes/getshortpathname.h b/scilab/modules/fileio/includes/getshortpathname.h index dab3f7d..d51b756 100644 --- a/scilab/modules/fileio/includes/getshortpathname.h +++ b/scilab/modules/fileio/includes/getshortpathname.h @@ -33,7 +33,7 @@ FILEIO_IMPEXP char *getshortpathname(const char *longpathname, BOOL *convertok); FILEIO_IMPEXP int C2F(getshortpathname)(char *pathname, int *len); -FILEIO_IMPEXP wchar_t* getshortpathnameW(wchar_t* _pwstLongPathName, BOOL* _pbOK); +FILEIO_IMPEXP wchar_t* getshortpathnameW(const wchar_t* _pwstLongPathName, BOOL* _pbOK); #endif /* __GETSHORTPATHNAME_H__ */ /*--------------------------------------------------------------------------*/ diff --git a/scilab/modules/fileio/sci_gateway/cpp/sci_getlongpathname.cpp b/scilab/modules/fileio/sci_gateway/cpp/sci_getlongpathname.cpp index 3e70bfc..d87e3ed 100644 --- a/scilab/modules/fileio/sci_gateway/cpp/sci_getlongpathname.cpp +++ b/scilab/modules/fileio/sci_gateway/cpp/sci_getlongpathname.cpp @@ -20,6 +20,7 @@ extern "C" { +#include "pathconvert.h" #include "getlongpathname.h" #include "Scierror.h" #include "localization.h" @@ -55,7 +56,9 @@ types::Function::ReturnValue sci_getlongpathname(types::typed_list &in, int _iRe for (int i = 0 ; i < size; i++) { wchar_t* tmp = getlongpathnameW(p[i], (BOOL*)&pBool[i]); - pOut1->set(i, tmp); + wchar_t* pwstPath = pathconvertW(tmp, FALSE, FALSE, AUTO_STYLE); + pOut1->set(i, pwstPath); + FREE(pwstPath); FREE(tmp); } diff --git a/scilab/modules/fileio/sci_gateway/cpp/sci_getshortpathname.cpp b/scilab/modules/fileio/sci_gateway/cpp/sci_getshortpathname.cpp index d9f0cbe..aad5f1a 100644 --- a/scilab/modules/fileio/sci_gateway/cpp/sci_getshortpathname.cpp +++ b/scilab/modules/fileio/sci_gateway/cpp/sci_getshortpathname.cpp @@ -22,7 +22,7 @@ extern "C" { -#include +#include "pathconvert.h" #include "getshortpathname.h" #include "sci_malloc.h" #include "Scierror.h" @@ -59,7 +59,9 @@ types::Function::ReturnValue sci_getshortpathname(types::typed_list &in, int _iR for (int i = 0 ; i < size; i++) { wchar_t* tmp = getshortpathnameW(p[i], (BOOL*)&pBool[i]); - pOut1->set(i, tmp); + wchar_t* pwstPath = pathconvertW(tmp, FALSE, FALSE, AUTO_STYLE); + pOut1->set(i, pwstPath); + FREE(pwstPath); FREE(tmp); } @@ -74,57 +76,5 @@ types::Function::ReturnValue sci_getshortpathname(types::typed_list &in, int _iR } return types::Function::OK; - //CheckRhs(0,1); - //CheckLhs(1,2); - - //if (GetType(1) == sci_strings) - //{ - // int n1 = 0,m1 = 0, m1n1 = 0; - // char **LongNames = NULL; - // char **ShortNames = NULL; - // BOOL *bOK = NULL; - // int i = 0; - - // GetRhsVar(1,MATRIX_OF_STRING_DATATYPE,&m1,&n1,&LongNames); - // m1n1 = m1*n1; - - // if (m1n1 > 0) - // { - // ShortNames = (char**) MALLOC(sizeof(char*)* (m1n1)); - // bOK = (BOOL*) MALLOC(sizeof(BOOL)*(m1n1)); - - // if ( (ShortNames == NULL) || (bOK == NULL) ) - // { - // freeArrayOfString(LongNames, m1n1); - // Scierror(999,"%s: Memory allocation error.\n", fname); - // return 0; - // } - // } - - // for (i = 0;i < m1n1; i++) - // { - // ShortNames[i] = getshortpathname(LongNames[i], &bOK[i]); - // } - // freeArrayOfString(LongNames, m1n1); - - // CreateVarFromPtr( Rhs+1,MATRIX_OF_STRING_DATATYPE,&m1,&n1,ShortNames); - // LhsVar(1) = Rhs+1; - - // if (Lhs == 2) - // { - // CreateVarFromPtr(Rhs+2,MATRIX_OF_BOOLEAN_DATATYPE, &m1, &n1, &bOK); - // LhsVar(2) = Rhs + 2; - // } - - // C2F(putlhsvar)(); - - // freeArrayOfString(ShortNames, m1n1); - // if (bOK) {FREE(bOK); bOK = NULL;} - //} - //else - //{ - // Scierror(999,_("%s: Wrong type for input argument: string expected.\n"),fname); - //} - //return 0; } /*--------------------------------------------------------------------------*/ diff --git a/scilab/modules/fileio/src/c/getlongpathname.c b/scilab/modules/fileio/src/c/getlongpathname.c index 2d7577c..e9c1d79 100644 --- a/scilab/modules/fileio/src/c/getlongpathname.c +++ b/scilab/modules/fileio/src/c/getlongpathname.c @@ -28,7 +28,7 @@ #endif #endif /*--------------------------------------------------------------------------*/ -char *getlongpathname(char *shortpathname, BOOL *convertok) +char *getlongpathname(const char *shortpathname, BOOL *convertok) { char *LongName = NULL; wchar_t *wcshortpathname = to_wide_string(shortpathname); @@ -56,7 +56,7 @@ char *getlongpathname(char *shortpathname, BOOL *convertok) return LongName; } /*--------------------------------------------------------------------------*/ -wchar_t *getlongpathnameW(wchar_t *wcshortpathname, BOOL *convertok) +wchar_t *getlongpathnameW(const wchar_t *wcshortpathname, BOOL *convertok) { wchar_t *wcLongName = NULL; diff --git a/scilab/modules/fileio/src/c/getlongpathname.h b/scilab/modules/fileio/src/c/getlongpathname.h index 485ac68..ed1f98f 100644 --- a/scilab/modules/fileio/src/c/getlongpathname.h +++ b/scilab/modules/fileio/src/c/getlongpathname.h @@ -28,7 +28,7 @@ * on Linux returns same path name * used for Windows */ -FILEIO_IMPEXP char *getlongpathname(char *shortpathname, BOOL *convertok); +FILEIO_IMPEXP char *getlongpathname(const char *shortpathname, BOOL *convertok); /** * Retrieves the long path form of the specified path (wide string) @@ -38,7 +38,7 @@ FILEIO_IMPEXP char *getlongpathname(char *shortpathname, BOOL *convertok); * on Linux returns same path name * used for Windows */ -FILEIO_IMPEXP wchar_t *getlongpathnameW(wchar_t *wcshortpathname, BOOL *convertok); +FILEIO_IMPEXP wchar_t *getlongpathnameW(const wchar_t *wcshortpathname, BOOL *convertok); #endif /* __GETLONGPATHNAME_H__ */ diff --git a/scilab/modules/fileio/src/c/getshortpathname.c b/scilab/modules/fileio/src/c/getshortpathname.c index 284fc88..481e092 100644 --- a/scilab/modules/fileio/src/c/getshortpathname.c +++ b/scilab/modules/fileio/src/c/getshortpathname.c @@ -116,7 +116,7 @@ char *getshortpathname(const char *longpathname, BOOL *convertok) return ShortName; } /*--------------------------------------------------------------------------*/ -wchar_t* getshortpathnameW(wchar_t* _pwstLongPathName, BOOL* _pbOK) +wchar_t* getshortpathnameW(const wchar_t* _pwstLongPathName, BOOL* _pbOK) { wchar_t* pwstOutput = NULL; if (_pwstLongPathName) diff --git a/scilab/modules/fileio/tests/nonreg_tests/bug_14909.dia.ref b/scilab/modules/fileio/tests/nonreg_tests/bug_14909.dia.ref new file mode 100644 index 0000000..c143f7f --- /dev/null +++ b/scilab/modules/fileio/tests/nonreg_tests/bug_14909.dia.ref @@ -0,0 +1,21 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2017 - Scilab Enterprises - Antoine ELIAS +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// <-- WINDOWS ONLY --> +// +// <-- Non-regression test for bug 14909 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/show_bug.cgi?id=14909 +// +// <-- Short Description --> +// getlongpathname and getshortpathname must return value with "\" instead of "/" +p = getlongpathname(SCI); +assert_checkequal(grep(p, "/"), []); +p = getshortpathname(WSCI); +assert_checkequal(grep(p, "/"), []); diff --git a/scilab/modules/fileio/tests/nonreg_tests/bug_14909.tst b/scilab/modules/fileio/tests/nonreg_tests/bug_14909.tst new file mode 100644 index 0000000..a60e37e --- /dev/null +++ b/scilab/modules/fileio/tests/nonreg_tests/bug_14909.tst @@ -0,0 +1,24 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2017 - Scilab Enterprises - Antoine ELIAS +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// <-- WINDOWS ONLY --> +// +// <-- Non-regression test for bug 14909 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/show_bug.cgi?id=14909 +// +// <-- Short Description --> +// getlongpathname and getshortpathname must return value with "\" instead of "/" + +p = getlongpathname(SCI); +assert_checkequal(grep(p, "/"), []); + +p = getshortpathname(WSCI); +assert_checkequal(grep(p, "/"), []); + -- 1.7.9.5