add fileparts function 22/1822/3
antoine ELIAS [Mon, 6 Sep 2010 15:10:28 +0000 (17:10 +0200)]
Change-Id: I6048aa562dcaa4d653cdbb0db336bffcd9487a18

scilab/modules/fileio/Makefile.am
scilab/modules/fileio/Makefile.in
scilab/modules/fileio/fileio.vcproj
scilab/modules/fileio/includes/fileio_gw.hxx
scilab/modules/fileio/includes/gw_fileio.h
scilab/modules/fileio/sci_gateway/c/sci_fileparts.c [deleted file]
scilab/modules/fileio/sci_gateway/cpp/fileio_gw.cpp
scilab/modules/fileio/sci_gateway/cpp/fileio_gw.vcproj
scilab/modules/fileio/sci_gateway/cpp/sci_fileparts.cpp [new file with mode: 0644]

index 7d3f4d4..c4ec101 100644 (file)
@@ -81,7 +81,6 @@ sci_gateway/c/sci_newest.c \
 sci_gateway/c/sci_get_absolute_file_path.c  \
 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_isfile.c
@@ -96,7 +95,8 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_mgetl.cpp \
        sci_gateway/cpp/sci_pathconvert.cpp \
        sci_gateway/cpp/sci_isdir.cpp \
-       sci_gateway/cpp/sci_filesep.cpp
+       sci_gateway/cpp/sci_filesep.cpp \
+       sci_gateway/cpp/sci_fileparts.cpp
 
 FILEIO_CPP_SOURCES = \
        src/cpp/expandPathVariable.cpp \
index 1745725..1890044 100644 (file)
@@ -173,7 +173,6 @@ am__objects_3 = libscifileio_la-gw_fileio.lo \
        libscifileio_la-sci_get_absolute_file_path.lo \
        libscifileio_la-sci_getrelativefilename.lo \
        libscifileio_la-sci_copyfile.lo \
-       libscifileio_la-sci_fileparts.lo \
        libscifileio_la-sci_movefile.lo \
        libscifileio_la-sci_basename.lo libscifileio_la-sci_isfile.lo
 am__objects_4 = libscifileio_la-fileio_gw.lo \
@@ -181,7 +180,8 @@ am__objects_4 = libscifileio_la-fileio_gw.lo \
        libscifileio_la-sci_mget.lo libscifileio_la-sci_mput.lo \
        libscifileio_la-sci_mputl.lo libscifileio_la-sci_mgetl.lo \
        libscifileio_la-sci_pathconvert.lo \
-       libscifileio_la-sci_isdir.lo libscifileio_la-sci_filesep.lo
+       libscifileio_la-sci_isdir.lo libscifileio_la-sci_filesep.lo \
+       libscifileio_la-sci_fileparts.lo
 am_libscifileio_la_OBJECTS = $(am__objects_1) $(am__objects_2) \
        $(am__objects_3) $(am__objects_4)
 libscifileio_la_OBJECTS = $(am_libscifileio_la_OBJECTS)
@@ -544,7 +544,6 @@ sci_gateway/c/sci_newest.c \
 sci_gateway/c/sci_get_absolute_file_path.c  \
 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_isfile.c
@@ -559,7 +558,8 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_mgetl.cpp \
        sci_gateway/cpp/sci_pathconvert.cpp \
        sci_gateway/cpp/sci_isdir.cpp \
-       sci_gateway/cpp/sci_filesep.cpp
+       sci_gateway/cpp/sci_filesep.cpp \
+       sci_gateway/cpp/sci_fileparts.cpp
 
 FILEIO_CPP_SOURCES = \
        src/cpp/expandPathVariable.cpp \
@@ -1410,13 +1410,6 @@ libscifileio_la-sci_copyfile.lo: sci_gateway/c/sci_copyfile.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifileio_la_CPPFLAGS) $(CPPFLAGS) $(libscifileio_la_CFLAGS) $(CFLAGS) -c -o libscifileio_la-sci_copyfile.lo `test -f 'sci_gateway/c/sci_copyfile.c' || echo '$(srcdir)/'`sci_gateway/c/sci_copyfile.c
 
-libscifileio_la-sci_fileparts.lo: sci_gateway/c/sci_fileparts.c
-@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifileio_la_CPPFLAGS) $(CPPFLAGS) $(libscifileio_la_CFLAGS) $(CFLAGS) -MT libscifileio_la-sci_fileparts.lo -MD -MP -MF $(DEPDIR)/libscifileio_la-sci_fileparts.Tpo -c -o libscifileio_la-sci_fileparts.lo `test -f 'sci_gateway/c/sci_fileparts.c' || echo '$(srcdir)/'`sci_gateway/c/sci_fileparts.c
-@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscifileio_la-sci_fileparts.Tpo $(DEPDIR)/libscifileio_la-sci_fileparts.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='sci_gateway/c/sci_fileparts.c' object='libscifileio_la-sci_fileparts.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifileio_la_CPPFLAGS) $(CPPFLAGS) $(libscifileio_la_CFLAGS) $(CFLAGS) -c -o libscifileio_la-sci_fileparts.lo `test -f 'sci_gateway/c/sci_fileparts.c' || echo '$(srcdir)/'`sci_gateway/c/sci_fileparts.c
-
 libscifileio_la-sci_movefile.lo: sci_gateway/c/sci_movefile.c
 @am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifileio_la_CPPFLAGS) $(CPPFLAGS) $(libscifileio_la_CFLAGS) $(CFLAGS) -MT libscifileio_la-sci_movefile.lo -MD -MP -MF $(DEPDIR)/libscifileio_la-sci_movefile.Tpo -c -o libscifileio_la-sci_movefile.lo `test -f 'sci_gateway/c/sci_movefile.c' || echo '$(srcdir)/'`sci_gateway/c/sci_movefile.c
 @am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscifileio_la-sci_movefile.Tpo $(DEPDIR)/libscifileio_la-sci_movefile.Plo
@@ -1585,6 +1578,13 @@ libscifileio_la-sci_filesep.lo: sci_gateway/cpp/sci_filesep.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifileio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscifileio_la-sci_filesep.lo `test -f 'sci_gateway/cpp/sci_filesep.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_filesep.cpp
 
+libscifileio_la-sci_fileparts.lo: sci_gateway/cpp/sci_fileparts.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifileio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscifileio_la-sci_fileparts.lo -MD -MP -MF $(DEPDIR)/libscifileio_la-sci_fileparts.Tpo -c -o libscifileio_la-sci_fileparts.lo `test -f 'sci_gateway/cpp/sci_fileparts.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_fileparts.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscifileio_la-sci_fileparts.Tpo $(DEPDIR)/libscifileio_la-sci_fileparts.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_fileparts.cpp' object='libscifileio_la-sci_fileparts.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifileio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscifileio_la-sci_fileparts.lo `test -f 'sci_gateway/cpp/sci_fileparts.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_fileparts.cpp
+
 mostlyclean-libtool:
        -rm -f *.lo
 
index d424971..90afda9 100644 (file)
                                >
                        </File>
                        <File
-                               RelativePath=".\sci_gateway\c\sci_fileparts.c"
-                               >
-                       </File>
-                       <File
                                RelativePath=".\sci_gateway\c\sci_findfiles.c"
                                >
                        </File>
index ccd0996..8de9075 100644 (file)
@@ -45,5 +45,6 @@ CPP_GATEWAY_PROTOTYPE(sci_mgetl);
 CPP_GATEWAY_PROTOTYPE(sci_pathconvert);
 CPP_GATEWAY_PROTOTYPE(sci_isdir);
 CPP_GATEWAY_PROTOTYPE(sci_filesep);
+CPP_GATEWAY_PROTOTYPE(sci_fileparts);
 
 #endif /* !__FILEIO_GW_HXX__ */
index 7b346f3..36c7236 100644 (file)
@@ -50,7 +50,6 @@ FILEIO_IMPEXP int sci_get_absolute_file_path(char *fname,unsigned long fname_len
 FILEIO_IMPEXP int sci_pwd(char *fname, int* _piKey);
 FILEIO_IMPEXP int sci_chdir(char *fname, int* _piKey);
 FILEIO_IMPEXP int sci_copyfile(char *fname,int* _piKey);
-FILEIO_IMPEXP int sci_fileparts(char *fname, int* _piKey);
 FILEIO_IMPEXP int sci_movefile(char *fname, int* _piKey);
 FILEIO_IMPEXP int sci_basename(char *fname, int* _piKey);
 FILEIO_IMPEXP int sci_isfile(char *fname, int* _piKey);
diff --git a/scilab/modules/fileio/sci_gateway/c/sci_fileparts.c b/scilab/modules/fileio/sci_gateway/c/sci_fileparts.c
deleted file mode 100644 (file)
index a9d9588..0000000
+++ /dev/null
@@ -1,306 +0,0 @@
-/*
-* 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_scilab.h"
-#include "Scierror.h"
-#include "freeArrayOfString.h"
-#include "splitpath.h"
-/*--------------------------------------------------------------------------*/
-#define FILEPARTS_PATH_SELECTOR L"path"
-#define FILEPARTS_FNAME_SELECTOR L"fname"
-#define FILEPARTS_EXTENSION_SELECTOR L"extension"
-/*--------------------------------------------------------------------------*/
-int sci_fileparts(char *fname, int* _piKey)
-{
-       SciErr sciErr;
-       int m1 = 0, n1 = 0;
-       int *piAddressVarOne = NULL;
-       int iType1      = 0;
-       wchar_t *pStVarOne = NULL;
-       int lenStVarOne = 0;
-
-       int m2 = 0, n2 = 0;
-       int *piAddressVarTwo = NULL;
-       int iType2      = 0;
-       wchar_t *pStVarTwo = NULL;
-       int lenStVarTwo = 0;
-
-       wchar_t* drv = NULL;
-       wchar_t* dir = NULL;
-       wchar_t* name = NULL;
-       wchar_t* ext = NULL;
-       wchar_t* path_out = NULL;
-
-       CheckLhs(1,3); 
-       CheckRhs(1,2); 
-
-       if ( (Rhs == 2) && (Lhs != 1) )
-       {
-               Scierror(78,_("%s: Wrong number of output arguments: %d expected.\n"), fname, 1);
-               return 0;
-       }
-
-       sciErr = getVarAddressFromPosition(_piKey, 1, &piAddressVarOne);
-       if(sciErr.iErr)
-       {
-               printError(&sciErr, 0);
-               return 0;
-       }
-
-       sciErr = getVarType(_piKey, piAddressVarOne, &iType1);
-       if(sciErr.iErr)
-       {
-               printError(&sciErr, 0);
-               return 0;
-       }
-
-       if (iType1  != sci_strings )
-       {
-               Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"),fname,1);
-               return 0;
-       }
-
-       // get value of lenStVarOne
-       sciErr = getMatrixOfWideString(_piKey, piAddressVarOne,&m1,&n1,&lenStVarOne,&pStVarOne);
-       if(sciErr.iErr)
-       {
-               printError(&sciErr, 0);
-               return 0;
-       }
-
-       if ( (m1 != n1) && (n1 != 1) ) 
-       {
-               Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"),fname,1);
-               return 0;
-       }
-
-       pStVarOne = (wchar_t*)MALLOC(sizeof(wchar_t)*(lenStVarOne + 1));
-       if (pStVarOne == NULL)
-       {
-               Scierror(999,_("%s: Memory allocation error.\n"),fname);
-               return 0;
-       }
-
-       sciErr = getMatrixOfWideString(_piKey, piAddressVarOne, &m1, &n1, &lenStVarOne, &pStVarOne);
-       if(sciErr.iErr)
-       {
-               printError(&sciErr, 0);
-               if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
-               return 0;
-       }
-
-       if (Rhs == 2)
-       {
-               sciErr = getVarAddressFromPosition(_piKey, 2, &piAddressVarTwo);
-               if(sciErr.iErr)
-               {
-                       printError(&sciErr, 0);
-                       if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
-                       return 0;
-               }
-
-               sciErr = getVarType(_piKey, piAddressVarTwo, &iType2);
-               if(sciErr.iErr)
-               {
-                       printError(&sciErr, 0);
-                       if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
-                       return 0;
-               }
-
-               if (iType2  != sci_strings )
-               {
-                       Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"),fname,2);
-                       if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
-                       return 0;
-               }
-
-               // get value of lenStVarTwo
-               sciErr = getMatrixOfWideString(_piKey, piAddressVarTwo, &m2, &n2, &lenStVarTwo, &pStVarTwo);
-               if(sciErr.iErr)
-               {
-                       printError(&sciErr, 0);
-                       if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
-                       return 0;
-               }
-
-               if ( (m2 != n2) && (n2 != 1) ) 
-               {
-                       Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"),fname,2);
-                       if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
-                       return 0;
-               }
-
-               pStVarTwo = (wchar_t*)MALLOC(sizeof(wchar_t)*(lenStVarTwo + 1));
-               if (pStVarTwo == NULL)
-               {
-                       Scierror(999,_("%s: Memory allocation error.\n"),fname);
-                       if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
-                       return 0;
-               }
-               
-               sciErr = getMatrixOfWideString(_piKey, piAddressVarTwo, &m2, &n2, &lenStVarTwo, &pStVarTwo);
-               if(sciErr.iErr)
-               {
-                       printError(&sciErr, 0);
-                       if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
-                       if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
-                       return 0;
-               }
-       }
-
-       drv = (wchar_t*)MALLOC(sizeof(wchar_t)*(lenStVarOne + 1));
-       dir = (wchar_t*)MALLOC(sizeof(wchar_t)*(lenStVarOne + 1));
-       name = (wchar_t*)MALLOC(sizeof(wchar_t)*(lenStVarOne + 1));
-       ext = (wchar_t*)MALLOC(sizeof(wchar_t)*(lenStVarOne + 1));
-       path_out = (wchar_t*)MALLOC(sizeof(wchar_t)*(lenStVarOne + 1));
-
-       if ( (drv == NULL) || (dir == NULL) || (name == NULL) || (ext == NULL) || (path_out == NULL) )
-       {
-               if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
-               if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
-               if (drv) {FREE(drv); drv = NULL;}
-               if (dir) {FREE(dir); dir = NULL;}
-               if (name) {FREE(name); name = NULL;}
-               if (ext) {FREE(ext); ext = NULL;}
-               if (path_out) {FREE(path_out); path_out = NULL;}
-
-               Scierror(999,_("%s: Memory allocation error.\n"), fname);
-               return 0;
-       }
-
-       splitpathW(pStVarOne, FALSE, drv, dir, name, ext);
-
-       if (pStVarTwo) /* Rhs == 2 */
-       {
-               wchar_t *output_value = NULL;
-               int m_out = 0, n_out = 0;
-
-               if (wcscmp(pStVarTwo, FILEPARTS_PATH_SELECTOR) == 0)
-               {
-                       output_value = path_out;
-                       wcscpy(output_value, drv);
-                       wcscat(output_value, dir);
-               }
-               else if (wcscmp(pStVarTwo, FILEPARTS_FNAME_SELECTOR) == 0)
-               {
-                       output_value = name;
-               }
-               else if (wcscmp(pStVarTwo, FILEPARTS_EXTENSION_SELECTOR) == 0)
-               {
-                       output_value = ext;
-               }
-               else
-               {
-                       if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
-                       if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
-                       if (drv) {FREE(drv); drv = NULL;}
-                       if (dir) {FREE(dir); dir = NULL;}
-                       if (name) {FREE(name); name = NULL;}
-                       if (ext) {FREE(ext); ext = NULL;}
-                       if (path_out) {FREE(path_out); path_out = NULL;}
-
-                       Scierror(999,_("%s: Wrong value for input argument #%d.\n"), fname, 2);
-                       return 0;
-               }
-
-               m_out = 1; n_out = 1;
-               sciErr = createMatrixOfWideString(_piKey, Rhs + 1, m_out, n_out, &output_value);
-               if(sciErr.iErr)
-               {
-                       printError(&sciErr, 0);
-                       if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
-                       if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
-                       if (drv) {FREE(drv); drv = NULL;}
-                       if (dir) {FREE(dir); dir = NULL;}
-                       if (name) {FREE(name); name = NULL;}
-                       if (ext) {FREE(ext); ext = NULL;}
-                       if (path_out) {FREE(path_out); path_out = NULL;}
-                       return 0;
-               }
-
-               LhsVar(1) = Rhs + 1;
-               C2F(putlhsvar)();
-       }
-       else
-       {
-               int m_out = 1, n_out = 1;
-
-               wcscpy(path_out, drv);
-               wcscat(path_out, dir);
-
-               sciErr = createMatrixOfWideString(_piKey, Rhs + 1, m_out, n_out, &path_out);
-               if(sciErr.iErr)
-               {
-                       printError(&sciErr, 0);
-                       if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
-                       if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
-                       if (drv) {FREE(drv); drv = NULL;}
-                       if (dir) {FREE(dir); dir = NULL;}
-                       if (name) {FREE(name); name = NULL;}
-                       if (ext) {FREE(ext); ext = NULL;}
-                       if (path_out) {FREE(path_out); path_out = NULL;}
-                       return 0;
-               }
-
-               LhsVar(1) = Rhs + 1;
-
-               sciErr = createMatrixOfWideString(_piKey, Rhs + 2, m_out, n_out, &name);
-               if(sciErr.iErr)
-               {
-                       printError(&sciErr, 0);
-                       if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
-                       if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
-                       if (drv) {FREE(drv); drv = NULL;}
-                       if (dir) {FREE(dir); dir = NULL;}
-                       if (name) {FREE(name); name = NULL;}
-                       if (ext) {FREE(ext); ext = NULL;}
-                       if (path_out) {FREE(path_out); path_out = NULL;}
-                       return 0;
-               }
-
-               LhsVar(2) = Rhs + 2;
-
-               sciErr = createMatrixOfWideString(_piKey, Rhs + 3, m_out, n_out, &ext);
-               if(sciErr.iErr)
-               {
-                       printError(&sciErr, 0);
-                       if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
-                       if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
-                       if (drv) {FREE(drv); drv = NULL;}
-                       if (dir) {FREE(dir); dir = NULL;}
-                       if (name) {FREE(name); name = NULL;}
-                       if (ext) {FREE(ext); ext = NULL;}
-                       if (path_out) {FREE(path_out); path_out = NULL;}
-                       return 0;
-               }
-
-               LhsVar(3) = Rhs + 3;
-
-               C2F(putlhsvar)();
-       }
-
-
-       if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
-       if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
-       if (drv) {FREE(drv); drv = NULL;}
-       if (dir) {FREE(dir); dir = NULL;}
-       if (name) {FREE(name); name = NULL;}
-       if (ext) {FREE(ext); ext = NULL;}
-       if (path_out) {FREE(path_out); path_out = NULL;}
-
-       return 0;
-}
-/*--------------------------------------------------------------------------*/
index bc0d275..100c185 100644 (file)
@@ -34,5 +34,6 @@ bool FileioModule::Load()
     symbol::Context::getInstance()->AddFunction(Function::createFunction(L"pathconvert", &sci_pathconvert, MODULE_NAME));
     symbol::Context::getInstance()->AddFunction(Function::createFunction(L"isdir", &sci_isdir, MODULE_NAME));
     symbol::Context::getInstance()->AddFunction(Function::createFunction(L"filesep", &sci_filesep, MODULE_NAME));
+    symbol::Context::getInstance()->AddFunction(Function::createFunction(L"fileparts", &sci_fileparts, MODULE_NAME));
     return true;
 }
index 13ae450..2b2df9b 100644 (file)
                                >
                        </File>
                        <File
+                               RelativePath=".\sci_fileparts.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\sci_filesep.cpp"
                                >
                        </File>
diff --git a/scilab/modules/fileio/sci_gateway/cpp/sci_fileparts.cpp b/scilab/modules/fileio/sci_gateway/cpp/sci_fileparts.cpp
new file mode 100644 (file)
index 0000000..bab6cba
--- /dev/null
@@ -0,0 +1,431 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2009 - DIGITEO - Allan CORNET
+* Copyright (C) 2010 - DIGITEO - Antoine ELIAS
+*
+* 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 "alltypes.hxx"
+#include "funcmanager.hxx"
+#include "filemanager.hxx"
+#include "fileio_gw.hxx"
+
+extern "C"
+{
+#include "localization.h"
+#include "Scierror.h"
+#include "splitpath.h"
+}
+
+enum PartialPart
+{
+    PathPart,
+    NamePart,
+    ExtensionPart,
+    AllPart = -1
+};
+/*--------------------------------------------------------------------------*/
+#define FILEPARTS_PATH_SELECTOR L"path"
+#define FILEPARTS_FNAME_SELECTOR L"fname"
+#define FILEPARTS_EXTENSION_SELECTOR L"extension"
+/*--------------------------------------------------------------------------*/
+Function::ReturnValue sci_fileparts(typed_list &in, int _iRetCount, typed_list &out)
+{
+    bool bPartialValue  = false;
+    PartialPart iPartialPart = AllPart;
+
+    if(in.size() < 1 || in.size() > 2)
+    {
+        ScierrorW(77, _W("%ls: Wrong number of input argument(s): %d to %d expected.\n"), L"fileparts", 1, 2);
+        return Function::Error;
+    }
+
+    if(in.size() == 2 && _iRetCount != 1 && _iRetCount != -1)
+    {
+        ScierrorW(78, _W("%ls: Wrong number of output arguments: %d expected.\n"), L"fileparts", 1);
+        return Function::Error;
+    }
+
+    if(in.size() == 1 && _iRetCount != 3)
+    {
+        ScierrorW(78, _W("%ls: Wrong number of output arguments: %d expected.\n"), L"fileparts", 3);
+        return Function::Error;
+    }
+
+    if(in[0]->isString() == false && in[0]->getAsString()->size_get() != 1)
+    {
+        ScierrorW(999, _W("%ls: Wrong type for input argument #%d: A string expected.\n"), L"fileparts", 1);
+        return Function::Error;
+    }
+
+    if(in.size() == 2)
+    {
+        if(in[1]->isString() == false && in[1]->getAsString()->size_get() != 1)
+        {
+            ScierrorW(999, _W("%ls: Wrong type for input argument #%d: A string expected.\n"), L"fileparts", 2);
+            return Function::Error;
+        }
+
+        wchar_t* pParts = in[1]->getAsString()->string_get()[0];
+
+        if(wcscmp(pParts, FILEPARTS_PATH_SELECTOR) == 0)
+        {
+            bPartialValue   = true;
+            iPartialPart    = PathPart;
+        }
+        else if(wcscmp(pParts, FILEPARTS_FNAME_SELECTOR) == 0)
+        {
+            bPartialValue   = true;
+            iPartialPart    = NamePart;
+        }
+        else if(wcscmp(pParts, FILEPARTS_EXTENSION_SELECTOR) == 0)
+        {
+            bPartialValue   = true;
+            iPartialPart    = ExtensionPart;
+        }
+        else
+        {
+            ScierrorW(999, _W("%ls: Wrong value for input argument #%d.\n"), L"fileparts", 2);
+            return Function::Error;
+        }
+    }
+
+    wchar_t* pPath = in[0]->getAsString()->string_get()[0];
+
+    wchar_t* pwstDrive      = new wchar_t[wcslen(pPath) + 1];
+    wchar_t* pwstDirectory  = new wchar_t[wcslen(pPath) + 1];
+    wchar_t* pwstName       = new wchar_t[wcslen(pPath) + 1];
+    wchar_t* pwstExtension  = new wchar_t[wcslen(pPath) + 1];
+
+    splitpathW(pPath, FALSE, pwstDrive, pwstDirectory, pwstName, pwstExtension);
+    wcscat(pwstDrive, pwstDirectory);
+
+    if(in.size() == 2)
+    {
+        String* pOut = NULL;
+        switch(iPartialPart)
+        {
+        case PathPart : 
+            {
+                pOut = new String(pwstDrive);
+            }
+        case NamePart : 
+            {
+                pOut = new String(pwstName);
+            }
+        case ExtensionPart : 
+            {
+                pOut = new String(pwstExtension);
+            }
+        default : 
+            {
+                //Never occur
+            }
+        }
+
+
+        out.push_back(pOut);
+    }
+    else
+    {//standard case, 3 outputs
+        String* pOut1 = new String(pwstDrive);
+        out.push_back(pOut1);
+
+        String* pOut2 = new String(pwstName);
+        out.push_back(pOut2);
+
+        String* pOut3 = new String(pwstExtension);
+        out.push_back(pOut3);
+    }
+
+    delete[] pwstDirectory;
+    delete[] pwstDrive;
+    delete[] pwstExtension;
+    delete[] pwstName;
+
+    return Function::OK;
+       //SciErr sciErr;
+       //int m1 = 0, n1 = 0;
+       //int *piAddressVarOne = NULL;
+       //int iType1    = 0;
+       //wchar_t *pStVarOne = NULL;
+       //int lenStVarOne = 0;
+
+       //int m2 = 0, n2 = 0;
+       //int *piAddressVarTwo = NULL;
+       //int iType2    = 0;
+       //wchar_t *pStVarTwo = NULL;
+       //int lenStVarTwo = 0;
+
+       //wchar_t* drv = NULL;
+       //wchar_t* dir = NULL;
+       //wchar_t* name = NULL;
+       //wchar_t* ext = NULL;
+       //wchar_t* path_out = NULL;
+
+       //CheckLhs(1,3); 
+       //CheckRhs(1,2); 
+
+       //if ( (Rhs == 2) && (Lhs != 1) )
+       //{
+       //      Scierror(78,_("%s: Wrong number of output arguments: %d expected.\n"), fname, 1);
+       //      return 0;
+       //}
+
+       //sciErr = getVarAddressFromPosition(_piKey, 1, &piAddressVarOne);
+       //if(sciErr.iErr)
+       //{
+       //      printError(&sciErr, 0);
+       //      return 0;
+       //}
+
+       //sciErr = getVarType(_piKey, piAddressVarOne, &iType1);
+       //if(sciErr.iErr)
+       //{
+       //      printError(&sciErr, 0);
+       //      return 0;
+       //}
+
+       //if (iType1  != sci_strings )
+       //{
+       //      Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"),fname,1);
+       //      return 0;
+       //}
+
+       //// get value of lenStVarOne
+       //sciErr = getMatrixOfWideString(_piKey, piAddressVarOne,&m1,&n1,&lenStVarOne,&pStVarOne);
+       //if(sciErr.iErr)
+       //{
+       //      printError(&sciErr, 0);
+       //      return 0;
+       //}
+
+       //if ( (m1 != n1) && (n1 != 1) ) 
+       //{
+       //      Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"),fname,1);
+       //      return 0;
+       //}
+
+       //pStVarOne = (wchar_t*)MALLOC(sizeof(wchar_t)*(lenStVarOne + 1));
+       //if (pStVarOne == NULL)
+       //{
+       //      Scierror(999,_("%s: Memory allocation error.\n"),fname);
+       //      return 0;
+       //}
+
+       //sciErr = getMatrixOfWideString(_piKey, piAddressVarOne, &m1, &n1, &lenStVarOne, &pStVarOne);
+       //if(sciErr.iErr)
+       //{
+       //      printError(&sciErr, 0);
+       //      if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
+       //      return 0;
+       //}
+
+       //if (Rhs == 2)
+       //{
+       //      sciErr = getVarAddressFromPosition(_piKey, 2, &piAddressVarTwo);
+       //      if(sciErr.iErr)
+       //      {
+       //              printError(&sciErr, 0);
+       //              if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
+       //              return 0;
+       //      }
+
+       //      sciErr = getVarType(_piKey, piAddressVarTwo, &iType2);
+       //      if(sciErr.iErr)
+       //      {
+       //              printError(&sciErr, 0);
+       //              if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
+       //              return 0;
+       //      }
+
+       //      if (iType2  != sci_strings )
+       //      {
+       //              Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"),fname,2);
+       //              if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
+       //              return 0;
+       //      }
+
+       //      // get value of lenStVarTwo
+       //      sciErr = getMatrixOfWideString(_piKey, piAddressVarTwo, &m2, &n2, &lenStVarTwo, &pStVarTwo);
+       //      if(sciErr.iErr)
+       //      {
+       //              printError(&sciErr, 0);
+       //              if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
+       //              return 0;
+       //      }
+
+       //      if ( (m2 != n2) && (n2 != 1) ) 
+       //      {
+       //              Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"),fname,2);
+       //              if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
+       //              return 0;
+       //      }
+
+       //      pStVarTwo = (wchar_t*)MALLOC(sizeof(wchar_t)*(lenStVarTwo + 1));
+       //      if (pStVarTwo == NULL)
+       //      {
+       //              Scierror(999,_("%s: Memory allocation error.\n"),fname);
+       //              if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
+       //              return 0;
+       //      }
+       //      
+       //      sciErr = getMatrixOfWideString(_piKey, piAddressVarTwo, &m2, &n2, &lenStVarTwo, &pStVarTwo);
+       //      if(sciErr.iErr)
+       //      {
+       //              printError(&sciErr, 0);
+       //              if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
+       //              if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
+       //              return 0;
+       //      }
+       //}
+
+       //drv = (wchar_t*)MALLOC(sizeof(wchar_t)*(lenStVarOne + 1));
+       //dir = (wchar_t*)MALLOC(sizeof(wchar_t)*(lenStVarOne + 1));
+       //name = (wchar_t*)MALLOC(sizeof(wchar_t)*(lenStVarOne + 1));
+       //ext = (wchar_t*)MALLOC(sizeof(wchar_t)*(lenStVarOne + 1));
+       //path_out = (wchar_t*)MALLOC(sizeof(wchar_t)*(lenStVarOne + 1));
+
+       //if ( (drv == NULL) || (dir == NULL) || (name == NULL) || (ext == NULL) || (path_out == NULL) )
+       //{
+       //      if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
+       //      if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
+       //      if (drv) {FREE(drv); drv = NULL;}
+       //      if (dir) {FREE(dir); dir = NULL;}
+       //      if (name) {FREE(name); name = NULL;}
+       //      if (ext) {FREE(ext); ext = NULL;}
+       //      if (path_out) {FREE(path_out); path_out = NULL;}
+
+       //      Scierror(999,_("%s: Memory allocation error.\n"), fname);
+       //      return 0;
+       //}
+
+       //splitpathW(pStVarOne, FALSE, drv, dir, name, ext);
+
+       //if (pStVarTwo) /* Rhs == 2 */
+       //{
+       //      wchar_t *output_value = NULL;
+       //      int m_out = 0, n_out = 0;
+
+       //      if (wcscmp(pStVarTwo, FILEPARTS_PATH_SELECTOR) == 0)
+       //      {
+       //              output_value = path_out;
+       //              wcscpy(output_value, drv);
+       //              wcscat(output_value, dir);
+       //      }
+       //      else if (wcscmp(pStVarTwo, FILEPARTS_FNAME_SELECTOR) == 0)
+       //      {
+       //              output_value = name;
+       //      }
+       //      else if (wcscmp(pStVarTwo, FILEPARTS_EXTENSION_SELECTOR) == 0)
+       //      {
+       //              output_value = ext;
+       //      }
+       //      else
+       //      {
+       //              if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
+       //              if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
+       //              if (drv) {FREE(drv); drv = NULL;}
+       //              if (dir) {FREE(dir); dir = NULL;}
+       //              if (name) {FREE(name); name = NULL;}
+       //              if (ext) {FREE(ext); ext = NULL;}
+       //              if (path_out) {FREE(path_out); path_out = NULL;}
+
+       //              Scierror(999,_("%s: Wrong value for input argument #%d.\n"), fname, 2);
+       //              return 0;
+       //      }
+
+       //      m_out = 1; n_out = 1;
+       //      sciErr = createMatrixOfWideString(_piKey, Rhs + 1, m_out, n_out, &output_value);
+       //      if(sciErr.iErr)
+       //      {
+       //              printError(&sciErr, 0);
+       //              if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
+       //              if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
+       //              if (drv) {FREE(drv); drv = NULL;}
+       //              if (dir) {FREE(dir); dir = NULL;}
+       //              if (name) {FREE(name); name = NULL;}
+       //              if (ext) {FREE(ext); ext = NULL;}
+       //              if (path_out) {FREE(path_out); path_out = NULL;}
+       //              return 0;
+       //      }
+
+       //      LhsVar(1) = Rhs + 1;
+       //      C2F(putlhsvar)();
+       //}
+       //else
+       //{
+       //      int m_out = 1, n_out = 1;
+
+       //      wcscpy(path_out, drv);
+       //      wcscat(path_out, dir);
+
+       //      sciErr = createMatrixOfWideString(_piKey, Rhs + 1, m_out, n_out, &path_out);
+       //      if(sciErr.iErr)
+       //      {
+       //              printError(&sciErr, 0);
+       //              if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
+       //              if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
+       //              if (drv) {FREE(drv); drv = NULL;}
+       //              if (dir) {FREE(dir); dir = NULL;}
+       //              if (name) {FREE(name); name = NULL;}
+       //              if (ext) {FREE(ext); ext = NULL;}
+       //              if (path_out) {FREE(path_out); path_out = NULL;}
+       //              return 0;
+       //      }
+
+       //      LhsVar(1) = Rhs + 1;
+
+       //      sciErr = createMatrixOfWideString(_piKey, Rhs + 2, m_out, n_out, &name);
+       //      if(sciErr.iErr)
+       //      {
+       //              printError(&sciErr, 0);
+       //              if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
+       //              if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
+       //              if (drv) {FREE(drv); drv = NULL;}
+       //              if (dir) {FREE(dir); dir = NULL;}
+       //              if (name) {FREE(name); name = NULL;}
+       //              if (ext) {FREE(ext); ext = NULL;}
+       //              if (path_out) {FREE(path_out); path_out = NULL;}
+       //              return 0;
+       //      }
+
+       //      LhsVar(2) = Rhs + 2;
+
+       //      sciErr = createMatrixOfWideString(_piKey, Rhs + 3, m_out, n_out, &ext);
+       //      if(sciErr.iErr)
+       //      {
+       //              printError(&sciErr, 0);
+       //              if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
+       //              if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
+       //              if (drv) {FREE(drv); drv = NULL;}
+       //              if (dir) {FREE(dir); dir = NULL;}
+       //              if (name) {FREE(name); name = NULL;}
+       //              if (ext) {FREE(ext); ext = NULL;}
+       //              if (path_out) {FREE(path_out); path_out = NULL;}
+       //              return 0;
+       //      }
+
+       //      LhsVar(3) = Rhs + 3;
+
+       //      C2F(putlhsvar)();
+       //}
+
+
+       //if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}
+       //if (pStVarTwo) {FREE(pStVarTwo); pStVarTwo = NULL;}
+       //if (drv) {FREE(drv); drv = NULL;}
+       //if (dir) {FREE(dir); dir = NULL;}
+       //if (name) {FREE(name); name = NULL;}
+       //if (ext) {FREE(ext); ext = NULL;}
+       //if (path_out) {FREE(path_out); path_out = NULL;}
+
+       //return 0;
+}
+/*--------------------------------------------------------------------------*/