bug 4798
Allan CORNET [Thu, 24 Sep 2009 14:11:30 +0000 (16:11 +0200)]
32 files changed:
scilab/CHANGES_5.2.X
scilab/contrib/toolbox_skeleton/etc/toolbox_skeleton.start
scilab/etc/scilab.start
scilab/modules/core/etc/core.start
scilab/modules/fileio/Makefile.am
scilab/modules/fileio/etc/fileio.start
scilab/modules/fileio/fileio.vcproj
scilab/modules/fileio/help/en_US/basename.xml
scilab/modules/fileio/includes/gw_fileio.h
scilab/modules/fileio/includes/splitpath.h
scilab/modules/fileio/macros/basename.sci [deleted file]
scilab/modules/fileio/macros/cd.sci
scilab/modules/fileio/macros/ls.sci
scilab/modules/fileio/macros/pathconvert.sci [deleted file]
scilab/modules/fileio/sci_gateway/c/gw_fileio.c
scilab/modules/fileio/sci_gateway/c/sci_basename.c [new file with mode: 0644]
scilab/modules/fileio/sci_gateway/c/sci_copyfile.c
scilab/modules/fileio/sci_gateway/c/sci_fileparts.c
scilab/modules/fileio/sci_gateway/c/sci_movefile.c
scilab/modules/fileio/sci_gateway/c/sci_pathconvert.c [new file with mode: 0644]
scilab/modules/fileio/sci_gateway/fileio_gateway.xml
scilab/modules/fileio/src/c/basename.c [new file with mode: 0644]
scilab/modules/fileio/src/c/basename.h [new file with mode: 0644]
scilab/modules/fileio/src/c/expandPathVariable.c
scilab/modules/fileio/src/c/getlongpathname.c
scilab/modules/fileio/src/c/getlongpathname.h
scilab/modules/fileio/src/c/pathconvert.c [new file with mode: 0644]
scilab/modules/fileio/src/c/pathconvert.h [new file with mode: 0644]
scilab/modules/fileio/src/c/splitpath.c
scilab/modules/fileio/tests/unit_tests/pathconvert.dia.ref
scilab/modules/fileio/tests/unit_tests/pathconvert.tst
scilab/modules/functions/scripts/buildmacros/loadgenlib.sce

index b6a7543..b76e3ea 100644 (file)
@@ -126,6 +126,8 @@ fileio functions:
    + copyfile (primitive)
    + fileparts (primitive)
    + isdir manages matrix of strings as input argument
+   + basename (primitive)
+   + pathconvert (primitive)
   
 Dynamic link:
 =============
@@ -452,6 +454,8 @@ Bug fixes:
 
 * bug 4795 fixed - CallScilab.h renamed call_scilab.h
 
+* bug 4798 fixed - pathconvert macro should be rewritten as a primitive (many times used and not faster).
+
 * bug 4807 fixed - strsubst does not check if second argument is a valid patter where fourth argument is 'r'.
 
 * bug 4810 fixed - gsort does not manage sparse vectors as sort.
index 093bcdb..69e2331 100644 (file)
@@ -48,5 +48,4 @@ clear path_addchapter;
 clear root_tlbx;
 clear etc_tlbx;
 clear pathmacros;
-clear pathconvert;
 // ====================================================================
index e3bd79d..a0f9a88 100644 (file)
@@ -108,8 +108,6 @@ else
 end
 setenv("VERSION",getversion());
 
-clear pathconvert; //remove the local variable
-
 // Protect variable previously defined  ================================
 predef("all");
 
index 9a8acb9..03c4d02 100644 (file)
@@ -11,9 +11,6 @@
 
 // load temporary functions needed by all others
 // =============================================================================
-
-load("SCI/modules/fileio/macros/pathconvert.bin");
-
 if WITH_HELPTOOLS then
        load(SCI+"/modules/helptools/macros/add_module_help_chapter.bin");
        load(SCI+"/modules/helptools/macros/add_help_chapter.bin");
index 9b95c95..2a45f6a 100644 (file)
@@ -46,6 +46,8 @@ src/c/getrelativefilename.c \
 src/c/splitpath.c \
 src/c/movefile.c \
 src/c/expandPathVariable.c \
+src/c/basename.c \
+src/c/pathconvert.c \
 src/c/copyfile_others.c
 
 GATEWAY_SOURCES = \
@@ -89,6 +91,8 @@ sci_gateway/c/sci_getrelativefilename.c \
 sci_gateway/c/sci_copyfile.c \
 sci_gateway/c/sci_fileparts.c \
 sci_gateway/c/sci_movefile.c \
+sci_gateway/c/sci_basename.c \
+sci_gateway/c/sci_pathconvert.c \
 sci_gateway/c/sci_isfile.c
 
 
index fb8220a..38eae16 100644 (file)
@@ -9,7 +9,6 @@
 
 //Load  functions libraries
 // =============================================================================
-clear pathconvert;
 load('SCI/modules/fileio/macros/lib');
 
 // Add help chapter
index a299033..0f93898 100644 (file)
                                >
                        </File>
                        <File
+                               RelativePath=".\src\c\basename.c"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\src\c\cluni0.c"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath=".\src\c\pathconvert.c"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\src\c\readline.c"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath=".\sci_gateway\c\sci_basename.c"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\sci_gateway\c\sci_chdir.c"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath=".\sci_gateway\c\sci_pathconvert.c"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\sci_gateway\c\sci_pathsep.c"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath=".\src\c\basename.h"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\includes\cluni0.h"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath=".\src\c\pathconvert.h"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\includes\removedir.h"
                                >
                        </File>
index 1288175..adb99b8 100644 (file)
     <literal>HOME</literal>, <literal>SCI</literal> or <literal>~</literal>
     are expanded using environment variables.</para>
 
-    <para>Note that <literal>basename(files,%f)</literal> can give erroneous
-    results if pathnames given in files do not follow the convention given by
-    the <literal>MSDOS</literal> variable.</para>
-
-    <para>basename uses fileparts to strip directory and suffix from
-    filenames.</para>
   </refsection>
 
   <refsection>
index 60584ef..646f608 100644 (file)
@@ -57,6 +57,8 @@ FILEIO_IMPEXP int sci_copyfile(char *fname,unsigned long fname_len);
 FILEIO_IMPEXP int sci_isfile(char *fname,unsigned long fname_len);
 FILEIO_IMPEXP int sci_fileparts(char *fname,unsigned long fname_len);
 FILEIO_IMPEXP int sci_movefile(char *fname,unsigned long fname_len);
+FILEIO_IMPEXP int sci_basename(char *fname,unsigned long fname_len);
+FILEIO_IMPEXP int sci_pathconvert(char *fname,unsigned long fname_len);
 /*--------------------------------------------------------------------------*/ 
 #endif /* __GW_FILEIO_H__ */
 /*--------------------------------------------------------------------------*/
index c11f698..35e17fc 100644 (file)
 #define __SPLIPATH_H__
 
 #include <wchar.h>
+#include "BOOL.h"
 #include "dynlib_fileio.h"
 
 /**
 * Parts of file name and path
 * @param[in] filename or path
+* @param[in] BOOL expand filename
 * @param[out] drive
 * @param[out] directory
 * @param[out] filename
 * @param[out] file extension
 */
-FILEIO_IMPEXP void splitpath(const char* path, char* drv, char* dir, char* name, char* ext);
+FILEIO_IMPEXP void splitpath(const char* path, BOOL bExpand, char* drv, char* dir, char* name, char* ext);
 
 /**
 * Parts of file name and path (Wide string)
 * @param[in] filename or path
+* @param[in] BOOL expand filename
 * @param[out] drive
 * @param[out] directory
 * @param[out] filename
 * @param[out] file extension
 */
 
-FILEIO_IMPEXP void splitpathW(const wchar_t* path, wchar_t* drv, wchar_t* dir, wchar_t* name, wchar_t* ext);
+FILEIO_IMPEXP void splitpathW(const wchar_t* path, BOOL bExpand, wchar_t* drv, wchar_t* dir, wchar_t* name, wchar_t* ext);
 
 #endif /* __SPLIPATH_H__ */
 /*--------------------------------------------------------------------------*/ 
diff --git a/scilab/modules/fileio/macros/basename.sci b/scilab/modules/fileio/macros/basename.sci
deleted file mode 100644 (file)
index 0aa056a..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) ENPC
-// Copyright (C) - 2009 - DIGITEO - 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
-// you should have received as part of this distribution.  The terms
-// are also available at
-// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
-
-function [files]= basename(files,flag,flagexpand) 
-// strip directory and suffix from filenames
-// if flag == %t files are first converted
-// according to MSDOS
-
-  [lhs,rhs]=argn(0);
-  
-  if (files == []) | (files == '') then
-    return
-  end
-  
-  if type(files) <> 10 then
-    error(999, msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"basename",1) );
-  end
-  
-  if rhs <= 1 then flag = %t ; end 
-  if rhs <= 2 then flagexpand = %t ; end 
-  
-  if (type(flag) <> 4) then
-    error(999, msprintf(gettext("%s: Wrong type for input argument #%d: A boolean expected.\n"),"basename",2));
-  end
-
-  if (type(flagexpand) <> 4) then
-    error(999, msprintf(gettext("%s: Wrong type for input argument #%d: A boolean expected.\n"),"basename",3));
-  end
-
-  if flag == %t then 
-    files = pathconvert(files,%f,flagexpand); 
-  end 
-
-  sep = filesep();
-
-  for i=1:size(files,'*')
-    if files(i) <> '' then
-      files(i) = fileparts(files(i),'fname');
-    end
-  end
-endfunction
-
index 2913659..a13fc4b 100644 (file)
@@ -1,5 +1,6 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) INRIA
+// Copyright (C) DIGITEO - 2009 - 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
@@ -8,27 +9,31 @@
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
 function path=cd(path)
-  if argn(2)==1 then
+  if (argn(2) == 1) then
     if type(path) <> 10 then 
       error(999,msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),'cd',1));
     end 
-       path=stripblanks(path)
-    if or(path==['PWD' 'SCIHOME']) then path=evstr(path),end
-    if MSDOS then 
-      if or(path==['WSCI']) then path=evstr(path),end
+    
+    if size(path,'*') <> 1 then 
+      error(999,msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),'cd',1));
+    end 
+    
+       path = stripblanks(path);
+       
+    if (path == 'PWD') then 
+      path = evstr(path);
     end
-    if or(path==['SCI' '~' 'TMPDIR' 'home' ]) path=path+'/',end
     
     if or(path==['/' '\' '..']) then
-      chdir(path)
+      chdir(path);
     else
       if ~isdir(path) then
         error(msprintf(gettext("%s: Cannot go to directory %s\n"),'cd',path),998);
       end
-      chdir(path)
+      chdir(path);
     end 
   else 
     chdir(home);
   end
-  path=pwd();
+  path = pwd();
 endfunction
index 13a6e6d..7ee3b39 100644 (file)
@@ -31,12 +31,7 @@ function files=ls(varargin)
                warning(msprintf(gettext("%s: Options ignored.\n"),"ls"));
        end
        
-       if or(path==['PWD' 'SCIHOME']) then path=evstr(path),end
-       
-       if MSDOS then 
-    if or(path==['WSCI']) then path=evstr(path),end
-  end
-  if or(path==['SCI' '~' 'TMPDIR' 'home' ]) path=path+'/',end
+       if or(path=='PWD') then path=evstr(path),end
        
        // dir returns names without the dirname
        files = listfiles(path);
diff --git a/scilab/modules/fileio/macros/pathconvert.sci b/scilab/modules/fileio/macros/pathconvert.sci
deleted file mode 100644 (file)
index 720b0da..0000000
+++ /dev/null
@@ -1,172 +0,0 @@
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) ENPC
-// Copyright (C) DIGITEO - 2009 - 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
-// you should have received as part of this distribution.  The terms
-// are also available at
-// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
-
-function paths = pathconvert(paths, flagtrail, flagexpand, str)
-// convert a path from dos style to unix style
-// using cygwin conventions i.e x: -> /cygdrive/x
-// if flagtrail is true then a trailing / or \ is added 
-// if flagexpand is true then SCI, HOME, ~ ,TMPDIR are expanded 
-// str gives the target style 'u' or 'w' 
-
-  [lhs,rhs] = argn(0);
-
-  unix_sep = '/';
-  dos_sep = '\';
-
-  sci = SCI; 
-
-  if rhs <= 1 then flagtrail = %t ;end 
-  if rhs <= 2 then flagexpand = %t ; end 
-  if rhs <= 3 then 
-    if MSDOS then 
-      str = 'w'; 
-    else 
-      str = 'u';
-    end
-  end
-
-  if str == 'w' then 
-    sep = dos_sep;
-    if isdef('WSCI') then sci = WSCI;end 
-  else
-    sep = unix_sep;
-  end
-
-  if type(paths) <> 10 then 
-    error(999,msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),'pathconvert',1));
-  end
-
-  if type(flagtrail) <> 4 then 
-    error(999,msprintf(_("%s: Wrong type for input argument #%d: A boolean expected.\n"),'pathconvert',2));
-  end
-
-  if size(flagtrail,'*') <> 1 then
-    error(999,msprintf(_("%s: Wrong size for input argument #%d: A boolean expected.\n"),'pathconvert',2));
-  end 
-
-  if type(flagexpand) <> 4 then 
-    error(999,msprintf(_("%s: Wrong type for input argument #%d: A boolean expected.\n"),'pathconvert',3));
-  end 
-
-  if size(flagexpand,'*') <> 1 then
-    error(999,msprintf(_("%s: Wrong size for input argument #%d: A boolean expected.\n"),'pathconvert',3));
-  end 
-
-  if type(str) <> 10 then 
-    error(999,msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),'pathconvert',4));
-  end
-
-  if size(str,'*') <> 1 then
-    error(999,msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),'pathconvert',4));
-  end
-
-  if ( (str <> 'w') & (str <> 'u') ) then
-    error(999,msprintf(_("%s: Wrong value for input argument #%d: ''w'' or ''u'' expected.\n"),'pathconvert',4));
-  end
-
-  // strip leading and trailink blanks 
-  paths = stripblanks(paths); 
-
-  // \ and / conversion 
-  if str == 'w' then 
-    paths = strsubst(paths, unix_sep, dos_sep);
-  else
-    paths = strsubst(paths, dos_sep, unix_sep);
-  end
-
-  // add a trailing / or \ at the end 
-
-  if flagtrail then 
-    for i = 1:size(paths,'*') 
-      path = paths(i);
-      len = length(path);
-      if len > 0 then
-        if part(path, length(path))<> sep then 
-          paths(i) = paths(i) + sep;
-        end
-      end
-    end
-  else
-    for i = 1:size(paths,'*') 
-      path = paths(i);
-      len = length(path);
-      if (len > 0) & (path <> sep) then
-        if part(path, length(path)) == sep then 
-          paths(i) = part(paths(i), 1:length(path)-1);
-        end
-      end
-    end
-  end
-  
-  // expand HOME, SCI and ~ , TMPDIR
-  
-  is_expanded = %f;
-  
-  if flagexpand then 
-    for i = 1:size(paths,'*') 
-      path = paths(i);
-      if part(path, 1:4) == 'SCI' + sep then 
-        is_expanded = %t ;
-        paths(i) = sci + part(path,4:length(path));
-      elseif part(path, 1:2) == '~' + sep then 
-        is_expanded = %t ;
-        paths(i) = getenv('HOME','/home/') + part(path,2:length(path));
-      elseif part(path, 1:5) == 'HOME' + sep then 
-        is_expanded = %t;
-        paths(i) = getenv('HOME','/home/')+part(path,5:length(path));
-      elseif part(path, 1:7) == 'TMPDIR' + sep then
-        is_expanded = %t;
-        paths(i) = TMPDIR + part(path, 7:length(path));
-      end
-    end
-  end
-
-  // \ and / conversion again 
-  if is_expanded then 
-    if str == 'w' then 
-      paths = strsubst(paths, unix_sep, dos_sep);
-    else
-      paths = strsubst(paths, dos_sep, unix_sep);
-    end
-  end
-
-  // check for \cygdrive\xx\ 
-  if str == 'w' then 
-    // convert \cygdrive\xx to xx: 
-    for i=1:size(paths,'*') 
-      path=paths(i);
-      if part(path,1:10) == '\cygdrive\' then 
-        // get the letter name 
-        k = strindex(path,'\'); 
-        if length(k) <= 2 then 
-          paths(i) = part(path,11:length(path))+':' ;
-        else
-          paths(i) = part(path,11:k(3)-1) + ':' + part(path,k(3):length(path));
-        end
-      end
-    end
-  else 
-     // convert xx: to /cygdrive/xx 
-     for i = 1:size(paths,'*') 
-       path = paths(i);
-       k = strindex(path,'/');
-       if k == [] then 
-         if part(path,length(path)) == ':' then 
-           paths(i) = '/cygdrive/' + part(path,1:length(path)-1) + sep;
-         end
-       elseif k(1) > 1 then 
-         if part(path,k(1)-1) == ':' then 
-           paths(i) = '/cygdrive/' + part(path,1:k(1)-2)+ part(path,k(1):length(path));
-         end
-       end
-     end
-  end
-
-endfunction 
index 07073aa..92ba7e9 100644 (file)
@@ -57,7 +57,9 @@ static gw_generic_table Tab[]={
        {sci_copyfile,"copyfile"},
        {sci_isfile,"isfile"},
        {sci_fileparts,"fileparts"},
-       {sci_movefile,"movefile"}
+       {sci_movefile,"movefile"},
+       {sci_basename,"basename"},
+       {sci_pathconvert,"pathconvert"}
        };
 /*--------------------------------------------------------------------------*/ 
 int gw_fileio(void)
diff --git a/scilab/modules/fileio/sci_gateway/c/sci_basename.c b/scilab/modules/fileio/sci_gateway/c/sci_basename.c
new file mode 100644 (file)
index 0000000..1366689
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2009 - DIGITEO - 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
+* you should have received as part of this distribution.  The terms
+* are also available at
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+/*--------------------------------------------------------------------------*/
+#include "gw_fileio.h"
+#include "stack-c.h"
+#include "MALLOC.h"
+#include "localization.h"
+#include "api_common.h"
+#include "api_string.h"
+#include "api_double.h"
+#include "api_boolean.h"
+#include "basename.h"
+#include "Scierror.h"
+#include "freeArrayOfString.h"
+/*--------------------------------------------------------------------------*/
+int sci_basename(char *fname,unsigned long fname_len)
+{
+       BOOL flag = TRUE; /* default */
+       BOOL flagexpand = TRUE; /* default */
+
+       int *piAddressVarOne = NULL;
+       wchar_t **pStVarOne = NULL;
+       int *lenStVarOne = NULL;
+       int m1 = 0, n1 = 0;
+
+       wchar_t **pStResult = NULL;
+
+       int i = 0;
+
+       /* Check Input & Output parameters */
+       CheckRhs(1,3);
+       CheckLhs(1,1);
+
+       if (Rhs > 2)
+       {
+               int *piAddressVarThree = NULL;
+               int *piData = NULL;
+               int m3 = 0, n3 = 0;
+
+               getVarAddressFromPosition(3, &piAddressVarThree);
+               if (getVarType(piAddressVarThree) != sci_boolean)
+               {
+                       Scierror(999,_("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 3);
+                       return 0;
+               }
+
+               getVarDimension(piAddressVarThree, &m3, &n3);
+
+               if ( (m3 != n3) && (n3 != 1) ) 
+               {
+                       Scierror(999,_("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 3);
+                       return 0;
+               }
+
+               getMatrixOfBoolean(piAddressVarThree, &m3, &n3,  &piData);
+               flagexpand = piData[0];
+
+       }
+
+       if (Rhs > 1)
+       {
+               int *piAddressVarTwo = NULL;
+               int *piData = NULL;
+               int m2 = 0, n2 = 0;
+
+               getVarAddressFromPosition(2, &piAddressVarTwo);
+               if (getVarType(piAddressVarTwo) != sci_boolean)
+               {
+                       Scierror(999,_("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 2);
+                       return 0;
+               }
+
+               getVarDimension(piAddressVarTwo, &m2, &n2);
+
+               if ( (m2 != n2) && (n2 != 1) ) 
+               {
+                       Scierror(999,_("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 2);
+                       return 0;
+               }
+
+               getMatrixOfBoolean(piAddressVarTwo, &m2, &n2,  &piData);
+               flag = piData[0];
+       }
+
+       getVarAddressFromPosition(1, &piAddressVarOne);
+
+       if (getVarType(piAddressVarOne) == sci_matrix)
+       {
+               getVarDimension(piAddressVarOne, &m1, &n1);
+               if ( (m1 == n1) && (m1 == 0) )
+               {
+                       createMatrixOfDouble(Rhs + 1, m1, n1, NULL);
+                       LhsVar(1) = Rhs + 1;
+                       C2F(putlhsvar)();
+               }
+               else
+               {
+                       Scierror(999,_("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 1);
+               }
+       }
+       else if (getVarType(piAddressVarOne) == sci_strings)
+       {
+               getVarDimension(piAddressVarOne, &m1, &n1);
+
+               lenStVarOne = (int*)MALLOC(sizeof(int) * (m1 * n1));
+               if (lenStVarOne == NULL)
+               {
+                       Scierror(999,_("%s : Memory allocation error.\n"),fname);
+                       return 0;
+               }
+
+               pStVarOne = (wchar_t**)MALLOC(sizeof(wchar_t*) * (m1 * n1));
+               if (pStVarOne == NULL)
+               {
+                       if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
+                       Scierror(999,_("%s : Memory allocation error.\n"),fname);
+                       return 0;
+               }
+
+               getMatrixOfWideString(piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
+               pStResult = (wchar_t**)MALLOC(sizeof(wchar_t*) * (m1 * n1));
+
+               if (pStResult == NULL)
+               {
+                       if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
+                       Scierror(999,_("%s : Memory allocation error.\n"),fname);
+                       return 0;
+               }
+
+               for (i=0;i< m1 * n1; i++)
+               {
+                       pStResult[i] = basenameW(pStVarOne[i], flagexpand);
+               }
+
+               createMatrixOfWideString(Rhs + 1, m1, n1, pStResult);
+               LhsVar(1) = Rhs + 1;
+               C2F(putlhsvar)();
+
+               if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
+               freeArrayOfWideString(pStResult, m1 * n1);
+       }
+       else
+       {
+               Scierror(999,_("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 1);
+       }
+       return 0;
+}
+/*--------------------------------------------------------------------------*/
index 1ebcf00..1987b37 100644 (file)
@@ -194,7 +194,7 @@ static wchar_t* getFilenameWithExtension(wchar_t* wcFullFilename)
                wchar_t* wcext = MALLOC(sizeof(wchar_t*) * ((int)wcslen(wcFullFilename) + 1));
                wcfilename = MALLOC(sizeof(wchar_t*) * ((int)wcslen(wcFullFilename) + 1));
 
-               splitpathW(wcFullFilename, wcdrv, wcdir, wcname, wcext);
+               splitpathW(wcFullFilename, FALSE, wcdrv, wcdir, wcname, wcext);
 
                wcscpy(wcfilename, wcname);
                wcscat(wcfilename, wcext);
index 717645a..71c36e8 100644 (file)
@@ -121,7 +121,7 @@ int sci_fileparts(char *fname,unsigned long fname_len)
                return 0;
        }
 
-       splitpathW(pStVarOne, drv, dir, name, ext);
+       splitpathW(pStVarOne, FALSE, drv, dir, name, ext);
 
        if (pStVarTwo) /* Rhs == 2 */
        {
index a5d9fc4..1007e16 100644 (file)
@@ -184,7 +184,7 @@ static wchar_t* getFilenameWithExtensionForMove(wchar_t* wcFullFilename)
                wchar_t* wcext = MALLOC(sizeof(wchar_t*) * ((int)wcslen(wcFullFilename) + 1));
                wcfilename = MALLOC(sizeof(wchar_t*) * ((int)wcslen(wcFullFilename) + 1));
 
-               splitpathW(wcFullFilename, wcdrv, wcdir, wcname, wcext);
+               splitpathW(wcFullFilename, FALSE, wcdrv, wcdir, wcname, wcext);
 
                wcscpy(wcfilename, wcname);
                wcscat(wcfilename, wcext);
diff --git a/scilab/modules/fileio/sci_gateway/c/sci_pathconvert.c b/scilab/modules/fileio/sci_gateway/c/sci_pathconvert.c
new file mode 100644 (file)
index 0000000..c1fd50a
--- /dev/null
@@ -0,0 +1,214 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2009 - DIGITEO - 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
+* you should have received as part of this distribution.  The terms
+* are also available at
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+/*--------------------------------------------------------------------------*/
+#include "gw_fileio.h"
+#include "stack-c.h"
+#include "MALLOC.h"
+#include "localization.h"
+#include "api_common.h"
+#include "api_string.h"
+#include "api_double.h"
+#include "api_boolean.h"
+#include "Scierror.h"
+#include "pathconvert.h"
+#include "freeArrayOfString.h"
+/*--------------------------------------------------------------------------*/
+int sci_pathconvert(char *fname,unsigned long fname_len)
+{
+       int *piAddressVarOne = NULL;
+       wchar_t **pStVarOne = NULL;
+       int *lenStVarOne = NULL;
+       int m1 = 0, n1 = 0;
+
+       wchar_t **results = NULL;
+       int i = 0;
+
+       BOOL flagtrail = TRUE;
+       BOOL flagexpand = TRUE;
+
+       PathConvertType PType = AUTO_STYLE;
+
+       /* Check Input & Output parameters */
+       CheckRhs(1,4);
+       CheckLhs(1,1);
+
+
+       if (Rhs > 3)
+       {
+               int *piAddressVarFour = NULL;
+               wchar_t *pStVarFour = NULL;
+               int lenStVarFour = 0;
+               int m4 = 0, n4 = 0;
+
+               getVarAddressFromPosition(4, &piAddressVarFour);
+               if (getVarType(piAddressVarFour) != sci_strings)
+               {
+                       Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 4);
+                       return 0;
+               }
+
+               getVarDimension(piAddressVarFour, &m4, &n4);
+
+               if ( (m4 != n4) && (n4 != 1) ) 
+               {
+                       Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 4);
+                       return 0;
+               }
+
+               getMatrixOfWideString(piAddressVarFour, &m4, &n4, &lenStVarFour, &pStVarFour);
+
+               pStVarFour = (wchar_t*)MALLOC(sizeof(wchar_t)*(lenStVarFour + 1));
+               if (pStVarFour == NULL)
+               {
+                       Scierror(999,_("%s : Memory allocation error.\n"),fname);
+                       return 0;
+               }
+
+               getMatrixOfWideString(piAddressVarFour, &m4, &n4, &lenStVarFour, &pStVarFour);
+
+               if ( (wcscmp(pStVarFour, L"w") == 0) || (wcscmp(pStVarFour, L"u") == 0) )
+               {
+                       if (wcscmp(pStVarFour, L"w") == 0)
+                       {
+                               PType = WINDOWS_STYLE;
+                       }
+                       else
+                       {
+                               PType = UNIX_STYLE;
+                       }
+                       if (pStVarFour) {FREE(pStVarFour); pStVarFour = NULL;}
+               }
+               else
+               {
+                       if (pStVarFour) {FREE(pStVarFour); pStVarFour = NULL;}
+                       Scierror(999,_("%s: Wrong value for input argument #%d: ''w'' or ''u'' string expected.\n"), fname, 4);
+                       return 0;
+               }
+       }
+
+       if (Rhs > 2)
+       {
+               int *piAddressVarThree = NULL;
+               int *piData = NULL;
+               int m3 = 0, n3 = 0;
+
+               getVarAddressFromPosition(3, &piAddressVarThree);
+               if (getVarType(piAddressVarThree) != sci_boolean)
+               {
+                       Scierror(999,_("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 3);
+                       return 0;
+               }
+
+               getVarDimension(piAddressVarThree, &m3, &n3);
+
+               if ( (m3 != n3) && (n3 != 1) ) 
+               {
+                       Scierror(999,_("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 3);
+                       return 0;
+               }
+
+               getMatrixOfBoolean(piAddressVarThree, &m3, &n3,  &piData);
+               flagexpand = piData[0];
+       }
+
+       if (Rhs > 1)
+       {
+               int *piAddressVarTwo = NULL;
+               int *piData = NULL;
+               int m2 = 0, n2 = 0;
+
+               getVarAddressFromPosition(2, &piAddressVarTwo);
+               if (getVarType(piAddressVarTwo) != sci_boolean)
+               {
+                       Scierror(999,_("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 2);
+                       return 0;
+               }
+
+               getVarDimension(piAddressVarTwo, &m2, &n2);
+
+               if ( (m2 != n2) && (n2 != 1) ) 
+               {
+                       Scierror(999,_("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 2);
+                       return 0;
+               }
+
+               getMatrixOfBoolean(piAddressVarTwo, &m2, &n2,  &piData);
+               flagtrail = piData[0];
+       }
+
+       getVarAddressFromPosition(1, &piAddressVarOne);
+
+       if (getVarType(piAddressVarOne) == sci_matrix)
+       {
+               getVarDimension(piAddressVarOne, &m1, &n1);
+               if ( (m1 == n1) && (m1 == 0) )
+               {
+                       createMatrixOfDouble(Rhs + 1, m1, n1, NULL);
+                       LhsVar(1) = Rhs + 1;
+                       C2F(putlhsvar)();
+               }
+               else
+               {
+                       Scierror(999,_("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 1);
+               }
+       }
+       else if (getVarType(piAddressVarOne) == sci_strings)
+       {
+               getVarDimension(piAddressVarOne, &m1, &n1);
+
+               lenStVarOne = (int*)MALLOC(sizeof(int) * (m1 * n1));
+               if (lenStVarOne == NULL)
+               {
+                       Scierror(999,_("%s : Memory allocation error.\n"),fname);
+                       return 0;
+               }
+
+               pStVarOne = (wchar_t**)MALLOC(sizeof(wchar_t*) * (m1 * n1));
+               if (pStVarOne == NULL)
+               {
+                       if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
+                       Scierror(999,_("%s : Memory allocation error.\n"),fname);
+                       return 0;
+               }
+
+               results = (wchar_t **)MALLOC(sizeof(wchar_t*) * (m1 * n1));
+
+               if (results == NULL)
+               {
+                       if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
+                       freeArrayOfWideString(pStVarOne, m1 * n1);
+                       Scierror(999,_("%s : Memory allocation error.\n"),fname);
+                       return 0;
+               }
+
+               getMatrixOfWideString(piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
+
+               for( i = 0; i < m1 * n1; i++)
+               {
+                       results[i] = pathconvertW(pStVarOne[i], flagtrail, flagexpand, PType);
+               }
+
+               createMatrixOfWideString(Rhs + 1, m1, n1, results);
+               LhsVar(1) = Rhs + 1;
+               C2F(putlhsvar)();
+
+               if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
+               freeArrayOfWideString(results, m1 * n1);
+       }
+       else
+       {
+               Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
+               return 0;
+       }
+       return 0;
+}
+/*--------------------------------------------------------------------------*/
index 59dfb96..f696183 100644 (file)
@@ -73,4 +73,6 @@
 <PRIMITIVE gatewayId="34" primitiveId="38" primitiveName="isfile" />
 <PRIMITIVE gatewayId="34" primitiveId="39" primitiveName="fileparts" />
 <PRIMITIVE gatewayId="34" primitiveId="40" primitiveName="movefile" />
+<PRIMITIVE gatewayId="34" primitiveId="41" primitiveName="basename" />
+<PRIMITIVE gatewayId="34" primitiveId="42" primitiveName="pathconvert" />
 </GATEWAY>
diff --git a/scilab/modules/fileio/src/c/basename.c b/scilab/modules/fileio/src/c/basename.c
new file mode 100644 (file)
index 0000000..861d3c9
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2009 - DIGITEO - 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
+* you should have received as part of this distribution.  The terms
+* are also available at
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+/*--------------------------------------------------------------------------*/
+#include "basename.h"
+#include "MALLOC.h"
+#include "expandPathVariable.h"
+#include "splitpath.h"
+#include "charEncoding.h"
+/*--------------------------------------------------------------------------*/
+wchar_t *basenameW(wchar_t *wcfullfilename, BOOL bExpand)
+{
+       wchar_t *basename_str = NULL;
+       if (wcfullfilename)
+       {
+               wchar_t *expandedPath = expandPathVariableW(wcfullfilename);
+               if (expandedPath)
+               {
+                       wchar_t *wcdrv = MALLOC(sizeof(wchar_t*) * ((int)wcslen(expandedPath) + 1));
+                       wchar_t* wcdir = MALLOC(sizeof(wchar_t*) * ((int)wcslen(expandedPath) + 1));
+                       wchar_t* wcname = MALLOC(sizeof(wchar_t*) * ((int)wcslen(expandedPath) + 1));
+                       wchar_t* wcext = MALLOC(sizeof(wchar_t*) * ((int)wcslen(expandedPath) + 1));
+
+                       splitpathW(expandedPath, bExpand, wcdrv, wcdir, wcname, wcext);
+
+                       if (wcname)
+                       {
+                               basename_str = wcname;
+                       }
+
+                       if (wcdrv) {FREE(wcdrv); wcdrv = NULL;}
+                       if (wcdir) {FREE(wcdir); wcdir = NULL;}
+                       if (wcext) {FREE(wcext); wcext = NULL;}
+
+                       FREE(expandedPath);
+                       expandedPath = NULL;
+               }
+       }
+       return basename_str;
+}
+/*--------------------------------------------------------------------------*/
+char *basename(char *fullfilename, BOOL bExpand)
+{
+       char *result = NULL;
+       if (fullfilename)
+       {
+               wchar_t *wcresult = NULL;
+               wchar_t *wcfullfilename = to_wide_string(fullfilename);
+
+               wcresult = basenameW(wcfullfilename, bExpand);
+               result = wide_string_to_UTF8(wcresult);
+               if (wcfullfilename) {FREE(wcfullfilename); wcfullfilename = NULL;}
+               if (wcresult) {FREE(wcresult); wcresult = NULL;}
+       }
+       return result;
+}
+/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/fileio/src/c/basename.h b/scilab/modules/fileio/src/c/basename.h
new file mode 100644 (file)
index 0000000..879df41
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2009 - DIGITEO - 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
+* you should have received as part of this distribution.  The terms
+* are also available at
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+
+#ifndef __BASENAME_H__
+#define __BASENAME_H__
+
+#include <wchar.h>
+#include "BOOL.h"
+
+
+/**
+* strip directory and suffix from filenames
+* @param[in] filename
+* @param[in] BOOL flagexpand
+* @return basename
+*/
+char *basename(char *fullfilename, BOOL bExpand);
+
+
+/**
+* strip directory and suffix from filenames (wide string)
+* @param[in] filename
+* @param[in] BOOL flagexpand
+* @return basename
+*/
+wchar_t *basenameW(wchar_t *wcfullfilename, BOOL bExpand);
+
+#endif
\ No newline at end of file
index 74c596e..66fd6ee 100644 (file)
@@ -18,6 +18,7 @@
 #include "PATH_MAX.h"
 #include "api_string.h"
 #include "api_common.h"
+#include "getlongpathname.h"
 /*--------------------------------------------------------------------------*/
 struct VARIABLEALIAS
 {
@@ -25,10 +26,11 @@ struct VARIABLEALIAS
        wchar_t *VariableName;
 };
 /*--------------------------------------------------------------------------*/
-#define NB_ALIAS 6
+#define NB_ALIAS 7
 static struct VARIABLEALIAS VARIABLES_words[NB_ALIAS] =
 {
        {L"SCIHOME", L"SCIHOME"},
+       {L"WSCI", L"WSCI"},
        {L"SCI", L"SCI"},
        {L"~", L"home"},
        {L"HOME", L"home"},
@@ -149,7 +151,15 @@ wchar_t *getVariableValueDefinedInScilab(wchar_t *wcVarName)
                                                VARVALUE = (wchar_t*)MALLOC(sizeof(wchar_t)*(VARVALUElen + 1));
                                                if (VARVALUE)
                                                {
+                                                       BOOL bConvLong = FALSE;
+                                                       wchar_t *LongName = NULL;
                                                        readNamedMatrixOfWideString(varname, &m, &n, &VARVALUElen, &VARVALUE);
+                                                       LongName = getlongpathnameW(VARVALUE, &bConvLong);
+                                                       if (LongName)
+                                                       {
+                                                               FREE(VARVALUE);
+                                                               VARVALUE = LongName;
+                                                       }
                                                }
                                        }
                                }
index 4d9e654..9ec49d9 100644 (file)
 char *getlongpathname(char *shortpathname,BOOL *convertok)
 {
        char *LongName = NULL;
-
-       if (shortpathname)
+       wchar_t *wcshortpathname = to_wide_string(shortpathname);
+       if (wcshortpathname)
+       {
+               wchar_t *wcLongName = getlongpathnameW(wcshortpathname, convertok);
+               if (wcLongName)
+               {
+                       LongName = wide_string_to_UTF8(wcLongName);
+                       FREE(wcLongName); wcLongName = NULL;
+               }
+               else
+               {
+                       LongName = strdup(shortpathname);
+                       *convertok = FALSE;
+               }
+       }
+       else
        {
-               #ifdef _MSC_VER
-               /* first we try to call to know path length */
-               wchar_t *wLongName = NULL;
-               wchar_t *wshortpathname = to_wide_string(shortpathname);
-               int length = GetLongPathNameW(wshortpathname, NULL, 0);
-               if (length <= 0 ) length = MAX_PATH_LONG;
+               LongName = strdup(shortpathname);
+               *convertok = FALSE;
+       }
+       return LongName;
+}
+/*--------------------------------------------------------------------------*/
+wchar_t *getlongpathnameW(wchar_t *wcshortpathname,BOOL *convertok)
+{
+       wchar_t *wcLongName = NULL;
+
+       #ifdef _MSC_VER
+       /* first we try to call to know path length */
+       int length = GetLongPathNameW(wcshortpathname, NULL, 0);
+       if (length <= 0 ) length = MAX_PATH_LONG;
 
-               wLongName = (wchar_t*)MALLOC((length + 1) * sizeof(wchar_t));
+       wcLongName = (wchar_t*)MALLOC((length + 1) * sizeof(wchar_t));
 
-               if (wLongName)
+       if (wcLongName)
+       {
+               /* second converts path */
+               if (GetLongPathNameW(wcshortpathname, wcLongName, length))
                {
-                       /* second converts path */
-                       if (GetLongPathNameW(wshortpathname, wLongName, length))
-                       {
-                               LongName = wide_string_to_UTF8(wLongName);
-                               *convertok = TRUE;
-                       }
-                       else
-                       {
-                               /* FAILED */
-                               LongName = strdup(shortpathname);
-                               *convertok = FALSE;
-                       }
-                       if (wLongName) {FREE(wLongName);wLongName = NULL;}
+                       *convertok = TRUE;
                }
                else
                {
                        /* FAILED */
-                       LongName = strdup(shortpathname);
+                       if (wcLongName) wcscpy(wcLongName, wcshortpathname);
                        *convertok = FALSE;
                }
-               if (wshortpathname) { FREE(wshortpathname); wshortpathname = NULL;}
-               #else
-               /* Linux */
-               int length = (int)strlen(shortpathname) + 1;
-               LongName = (char*)MALLOC(length * sizeof(char));
-               if (LongName) strcpy(LongName, shortpathname);
-               *convertok = FALSE;
-               #endif
        }
        else
        {
+               /* FAILED */
                *convertok = FALSE;
        }
-       return LongName;
+       #else
+       /* Linux */
+       int len = (int)wcslen(wcshortpathname) + 1;
+       wcLongName = (wchar_t*)MALLOC(len * sizeof(wchar_t));
+       if (wcLongName) wcscpy(wcLongName, wcshortpathname);
+       *convertok = FALSE;     
+       #endif
+       return wcLongName;
 }
 /*--------------------------------------------------------------------------*/
index b638c95..c8a6eec 100644 (file)
@@ -13,6 +13,7 @@
 #ifndef __GETLONGPATHNAME_H__
 #define __GETLONGPATHNAME_H__
 
+#include <wchar.h>
 #include "BOOL.h" /* BOOL */
 
 /**
 */
 char *getlongpathname(char *shortpathname,BOOL *convertok);
 
+/**
+* Retrieves the long path form of the specified path (wide string)
+* @param[in] short path name
+* @param[out] TRUE if conversion is ok
+* @return long path name
+* on Linux returns same path name
+* used for Windows
+*/
+wchar_t *getlongpathnameW(wchar_t *wcshortpathname,BOOL *convertok);
+
 
 #endif /* __GETLONGPATHNAME_H__ */
 /*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/fileio/src/c/pathconvert.c b/scilab/modules/fileio/src/c/pathconvert.c
new file mode 100644 (file)
index 0000000..e8fe4b0
--- /dev/null
@@ -0,0 +1,259 @@
+/*--------------------------------------------------------------------------*/ 
+/*
+* ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) DIGITEO - 2009 - 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
+* you should have received as part of this distribution.  The terms
+* are also available at    
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+/*--------------------------------------------------------------------------*/ 
+#include "pathconvert.h"
+#include "MALLOC.h"
+#include "expandPathVariable.h"
+#include "splitpath.h"
+#include "charEncoding.h"
+#include "BOOL.h"
+/*--------------------------------------------------------------------------*/ 
+#define CYGWINSTART L"/cygdrive/"
+/*--------------------------------------------------------------------------*/ 
+static wchar_t *cygwintowindowspath(wchar_t *cygwinpath, BOOL *bConverted);
+static wchar_t *windowstocygwinpath(wchar_t *windowspath, BOOL *bConverted);
+/*--------------------------------------------------------------------------*/ 
+wchar_t *pathconvertW(wchar_t* wcpath, BOOL flagtrail, BOOL flagexpand, PathConvertType PType)
+{
+       wchar_t *convertedPath = NULL;
+       if (wcpath)
+       {
+               BOOL bOK = FALSE;
+               BOOL bConvCyg = FALSE;
+               wchar_t *tmppath = NULL;
+               PathConvertType PTypelocal = PType;
+               int i = 0;
+
+               if (PType == AUTO_STYLE)
+               {
+                       #ifdef _MSC_VER
+                               PTypelocal = WINDOWS_STYLE;
+                       #else
+                               PTypelocal = UNIX_STYLE;
+                       #endif
+               }
+
+               if (PTypelocal == WINDOWS_STYLE)
+               {
+                       tmppath = cygwintowindowspath(wcpath, &bConvCyg);
+               }
+               else
+               {
+                       tmppath = windowstocygwinpath(wcpath, &bConvCyg);
+               }
+
+               if (tmppath)
+               {
+                       if (flagexpand)
+                       {
+                               convertedPath = expandPathVariableW(tmppath);
+                       }
+                       else
+                       {
+                               convertedPath = (wchar_t*)MALLOC(sizeof(wchar_t) * ((int)wcslen(tmppath) + 1));
+                               wcscpy(convertedPath, tmppath);
+                       }
+                       if (tmppath) {FREE(tmppath); tmppath = NULL;}
+
+                       if (flagtrail)
+                       {
+                               int currentLen = (int) wcslen(convertedPath);
+                               if ( (convertedPath[currentLen - 1] != L'/') && (convertedPath[currentLen - 1] != L'\\') )
+                               {
+                                       convertedPath = (wchar_t*)REALLOC(convertedPath, (currentLen + 2) * sizeof(wchar_t));
+                                       if (PTypelocal == WINDOWS_STYLE)
+                                       {
+                                               wcscat(convertedPath, L"\\");
+                                       }
+                                       else
+                                       {
+                                               wcscat(convertedPath, L"/");
+                                       }
+                               }
+                       }
+                       else
+                       {
+                               int currentLen = (int) wcslen(convertedPath);
+                               if ( (convertedPath[currentLen - 1] == L'/') || (convertedPath[currentLen - 1] == L'\\') )
+                               {
+                                       convertedPath[currentLen - 1] = L'\0';
+                               }
+                       }
+
+                       for(i = 0; i < (int)wcslen(convertedPath); i++)
+                       {
+                               if (PTypelocal == WINDOWS_STYLE)
+                               {
+                                       if (convertedPath[i] == L'/') convertedPath[i] = L'\\';
+                               }
+                               else
+                               {
+                                       if (convertedPath[i] == L'\\') convertedPath[i] = L'/';
+                               }
+                       }
+               }
+       }
+       return convertedPath;
+}
+/*--------------------------------------------------------------------------*/ 
+char *pathconvert(char* path, BOOL flagtrail, BOOL flagexpand, PathConvertType PType)
+{
+       char *convertedPath = NULL;
+       if (path)
+       {
+               wchar_t *wcpath = to_wide_string(path);
+               if (wcpath)
+               {
+                       wchar_t *wcconvertedPath = pathconvertW(wcpath,flagtrail,flagexpand,PType);
+                       if (wcconvertedPath)
+                       {
+                               convertedPath = wide_string_to_UTF8(wcconvertedPath);
+                               FREE(wcconvertedPath);
+                               wcconvertedPath = NULL;
+                       }
+               }
+       }
+       return convertedPath;
+}
+/*--------------------------------------------------------------------------*/ 
+static wchar_t *cygwintowindowspath(wchar_t *cygwinpath, BOOL *bConverted)
+{
+       wchar_t *windowspath = NULL;
+       *bConverted     = FALSE;
+       if (cygwinpath)
+       {
+               int lenBegin = (int)wcslen(CYGWINSTART);
+               int lenPath = (int)wcslen(cygwinpath);
+
+               windowspath = (wchar_t*)MALLOC(sizeof(wchar_t) * (lenPath + 1));
+
+               if ( wcsncmp(cygwinpath, CYGWINSTART, lenBegin) == 0)
+               {
+                       if (lenBegin == lenPath)
+                       {
+                               if (windowspath)
+                               {
+                                       wcscpy(windowspath, cygwinpath);
+                                       *bConverted     = FALSE;
+                               }
+                       }
+                       else
+                       {
+                               if ( (lenPath > lenBegin) && iswalpha(cygwinpath[lenBegin]) )
+                               {
+                                       if ( (lenPath >= lenBegin + 1) && 
+                                               ((cygwinpath[lenBegin + 1]== L'/') || (cygwinpath[lenBegin + 1]== L'\\')) )
+                                       {
+                                               windowspath[0] = cygwinpath[lenBegin];
+                                               windowspath[1] = L':';
+                                               windowspath[2] = L'\0';
+
+                                               if (lenPath > lenBegin + 1)
+                                               {
+                                                       wcscat(windowspath,&cygwinpath[lenBegin + 1]);
+                                               }
+                                               *bConverted     = TRUE;
+                                       }
+                                       else
+                                       {
+                                               if (windowspath)
+                                               {
+                                                       wcscpy(windowspath, cygwinpath);
+                                               }
+                                               *bConverted     = FALSE;
+                                       }
+                               }
+                               else
+                               {
+                                       if (windowspath)
+                                       {
+                                               wcscpy(windowspath, cygwinpath);
+                                       }
+                                       *bConverted     = FALSE;
+                               }
+                       }
+               }
+               else
+               {
+                       if (windowspath)
+                       {
+                               wcscpy(windowspath, cygwinpath);
+                       }
+                       *bConverted     = FALSE;
+               }
+       }
+       return windowspath;
+}
+/*--------------------------------------------------------------------------*/ 
+static wchar_t *windowstocygwinpath(wchar_t *windowspath, BOOL *bConverted)
+{
+       wchar_t *cygwinpath = NULL;
+       *bConverted = FALSE;
+
+       if (windowspath)
+       {
+               wchar_t *wcdrv = MALLOC(sizeof(wchar_t*) * ((int)wcslen(windowspath) + 1));
+               wchar_t* wcdir = MALLOC(sizeof(wchar_t*) * ((int)wcslen(windowspath) + 1));
+               wchar_t* wcname = MALLOC(sizeof(wchar_t*) * ((int)wcslen(windowspath) + 1));
+               wchar_t* wcext = MALLOC(sizeof(wchar_t*) * ((int)wcslen(windowspath) + 1));
+
+               splitpathW(windowspath, FALSE, wcdrv, wcdir, wcname, wcext);
+               if (wcscmp(wcdrv, L"") != 0)
+               {
+                       int len = (int)wcslen(CYGWINSTART) + (int)wcslen(wcdrv) +
+                                       (int)wcslen(wcdir) + (int)wcslen(wcname) + 
+                                       (int)wcslen(wcext) + 3;
+
+                       cygwinpath = (wchar_t*)MALLOC(sizeof(wchar_t) * len);
+                       if (cygwinpath)
+                       {
+                               wcscpy(cygwinpath, CYGWINSTART);
+                               wcscat(cygwinpath, wcdrv);
+                               len = (int)wcslen(cygwinpath);
+                               if (cygwinpath[len - 1] == L':')
+                               {
+                                       cygwinpath[len - 1] = L'\0';
+                               }
+                               if (wcscmp(wcdir, L"") != 0)    
+                               {
+                                       wcscat(cygwinpath, wcdir);
+                                       
+                                       if (wcscmp(wcname, L"") != 0)   
+                                       {
+                                               wcscat(cygwinpath, wcname);
+                                               if (wcscmp(wcext, L"") != 0)    
+                                               {
+                                                       wcscat(cygwinpath, wcext);
+                                               }
+                                       }
+                               }
+                       }
+                       *bConverted = TRUE;
+               }
+               else
+               {
+                       cygwinpath = (wchar_t*)MALLOC(sizeof(wchar_t) * ((int)wcslen(windowspath) + 1));
+                       if (cygwinpath)
+                       {
+                               wcscpy(cygwinpath, windowspath);
+                       }
+               }
+
+               if (wcdrv){FREE(wcdrv);wcdrv = NULL;}
+               if (wcdir){FREE(wcdir);wcdir = NULL;}
+               if (wcname){FREE(wcname);wcname = NULL;}
+               if (wcext){FREE(wcext);wcext =  NULL;}
+       }
+       return cygwinpath;
+}
+/*--------------------------------------------------------------------------*/ 
diff --git a/scilab/modules/fileio/src/c/pathconvert.h b/scilab/modules/fileio/src/c/pathconvert.h
new file mode 100644 (file)
index 0000000..4e2a664
--- /dev/null
@@ -0,0 +1,31 @@
+/*--------------------------------------------------------------------------*/ 
+/*
+* ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) DIGITEO - 2009 - 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
+* you should have received as part of this distribution.  The terms
+* are also available at    
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+/*--------------------------------------------------------------------------*/ 
+#ifndef __PATHCONVERT_H__
+#define __PATHCONVERT_H__
+
+#include <wchar.h>
+#include "BOOL.h"
+
+typedef enum { 
+WINDOWS_STYLE = 0,
+UNIX_STYLE = 1,
+AUTO_STYLE = 2
+} PathConvertType;
+
+wchar_t *pathconvertW(wchar_t* wcpath, BOOL flagtrail, BOOL flagexpand, PathConvertType PType);
+
+char *pathconvert(char* path, BOOL flagtrail, BOOL flagexpand, PathConvertType PType);
+
+#endif /* PATHCONVERT_H__ */
+/*--------------------------------------------------------------------------*/ 
index c17ff02..2d9abcf 100644 (file)
@@ -15,8 +15,9 @@
 #include "charEncoding.h"
 #include "PATH_MAX.h"
 #include "MALLOC.h"
+#include "expandPathVariable.h"
 /*--------------------------------------------------------------------------*/ 
-void splitpathW(const wchar_t* path, wchar_t* drv, wchar_t* dir, wchar_t* name, wchar_t* ext)
+void splitpathW(const wchar_t* path, BOOL bExpand, wchar_t* drv, wchar_t* dir, wchar_t* name, wchar_t* ext)
 {
        wchar_t* duplicate_path = NULL;
        wchar_t* begin_duplicate_path = NULL;
@@ -34,10 +35,18 @@ void splitpathW(const wchar_t* path, wchar_t* drv, wchar_t* dir, wchar_t* name,
        {
                int i = 0;
 
-               duplicate_path = (wchar_t*)MALLOC(sizeof(wchar_t)* ((int)wcslen(path) + 1));
+               if (bExpand)
+               {
+                       duplicate_path = expandPathVariableW((wchar_t*)path);
+               }
+               else
+               {
+                       duplicate_path = (wchar_t*)MALLOC(sizeof(wchar_t) * ((int)wcslen(path) + 1));
+                       if (duplicate_path) wcscpy(duplicate_path, path);
+               }
+               
                if (duplicate_path == NULL) return;
 
-               wcscpy(duplicate_path, path);
                begin_duplicate_path = duplicate_path;
                
                for(i = 0; i < (int)wcslen(duplicate_path); i++)
@@ -54,13 +63,11 @@ void splitpathW(const wchar_t* path, wchar_t* drv, wchar_t* dir, wchar_t* name,
                return;
        }
 
-
-#ifdef _MSC_VER
        if (duplicate_path)
        {
-               if (wcslen(duplicate_path) > 3)
+               if (wcslen(duplicate_path) > 2)
                {
-                       if (duplicate_path[0] && duplicate_path[1]==L':' && duplicate_path[2]==L'\\')
+                       if (duplicate_path[0] && duplicate_path[1]==L':' && ( (duplicate_path[2]==L'\\') || (duplicate_path[2]==L'/') ) )
                        {
                                if (drv)
                                {
@@ -71,7 +78,7 @@ void splitpathW(const wchar_t* path, wchar_t* drv, wchar_t* dir, wchar_t* name,
                        }
                }
        }
-#endif
+
 
        /* find the last slash in the path */
        #ifdef _MSC_VER
@@ -125,7 +132,7 @@ void splitpathW(const wchar_t* path, wchar_t* drv, wchar_t* dir, wchar_t* name,
        }
 }
 /*--------------------------------------------------------------------------*/ 
-void splitpath(const char* path, char* drv, char* dir, char* name, char* ext)
+void splitpath(const char* path, BOOL bExpand, char* drv, char* dir, char* name, char* ext)
 {
        wchar_t *wcpath = to_wide_string((char*)path);
        wchar_t *wcdrv = to_wide_string((char*)path);
@@ -135,7 +142,7 @@ void splitpath(const char* path, char* drv, char* dir, char* name, char* ext)
 
        char *buffer = NULL;
 
-       splitpathW(wcpath, wcdrv, wcdir, wcname, wcext);
+       splitpathW(wcpath, bExpand, wcdrv, wcdir, wcname, wcext);
 
        buffer = wide_string_to_UTF8(wcdrv);
        if (buffer)
index 962ca9d..32fbada 100644 (file)
@@ -11,12 +11,12 @@ ref = 'SCI\modules\fileio\macros\foo.sci';
 r = pathconvert('SCI/modules/fileio\macros/foo.sci',%f,%f,'w');
 if r <> ref then bugmes();quit;end
 if MSDOS then
-  ref = WSCI + '\modules\fileio\macros\foo.sci';
+  ref = WSCI + '\modules\fileio\macros\cd.sci';
 else
-  ref = SCI + '\modules\fileio\macros\foo.sci';
+  ref = SCI + '\modules\fileio\macros\cd.sci';
   ref = strsubst(ref,filesep(),'\');
 end
-r = pathconvert('SCI/modules/fileio/macros/foo.sci',%f,%t,'w');
+r = pathconvert('SCI/modules/fileio/macros/cd.sci',%f,%t,'w');
 if r <> ref then bugmes();quit;end
 ref = home + '\modules\fileio\macros\foo.sci';
 if ~MSDOS then
index e608f4b..f196267 100644 (file)
@@ -14,12 +14,12 @@ r = pathconvert('SCI/modules/fileio\macros/foo.sci',%f,%f,'w');
 if r <> ref then pause, end
 
 if MSDOS then
-  ref = WSCI + '\modules\fileio\macros\foo.sci';
+  ref = WSCI + '\modules\fileio\macros\cd.sci';
 else
-  ref = SCI + '\modules\fileio\macros\foo.sci';
+  ref = SCI + '\modules\fileio\macros\cd.sci';
   ref = strsubst(ref,filesep(),'\');
 end
-r = pathconvert('SCI/modules/fileio/macros/foo.sci',%f,%t,'w');
+r = pathconvert('SCI/modules/fileio/macros/cd.sci',%f,%t,'w');
 if r <> ref then pause, end
 
 ref = home + '\modules\fileio\macros\foo.sci';
index 63d20d8..50fa551 100644 (file)
 // Warning : order !!
 // list of  : filename , module
 
-listmacrostoload = ['pathconvert','fileio';
-  'listfiles','fileio'
+listmacrostoload = ['listfiles','fileio'
   '%c_a_c','overloading';
-  'basename','fileio';
   'mputl','fileio';
   'genlib','functions';
   ];