add findfiles function 46/1846/2
antoine ELIAS [Wed, 8 Sep 2010 09:36:46 +0000 (11:36 +0200)]
Change-Id: I046fa89ee0399e3c3d619084d10b0cefcc978a2a

scilab/Scilab.sln
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/gw_fileio.c
scilab/modules/fileio/sci_gateway/c/sci_findfiles.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_findfiles.cpp [new file with mode: 0644]

index 9a24ab3..e09cb22 100644 (file)
@@ -1463,6 +1463,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fileio_gw", "modules\fileio
                {2C60033B-0DBD-4CA4-80D3-176C9BE9CE2F} = {2C60033B-0DBD-4CA4-80D3-176C9BE9CE2F}
                {4FC72D4A-80EE-4B1A-8724-0201C1A35621} = {4FC72D4A-80EE-4B1A-8724-0201C1A35621}
                {0D3FA25B-8116-44EC-A45E-260789DAA3D9} = {0D3FA25B-8116-44EC-A45E-260789DAA3D9}
+               {64BC155E-292F-484F-9404-76EE6AE67A43} = {64BC155E-292F-484F-9404-76EE6AE67A43}
                {8028F371-6A94-4A26-8804-6E7F05F1D1AA} = {8028F371-6A94-4A26-8804-6E7F05F1D1AA}
                {43C5BAB1-1DCA-4743-A183-77E0D42FE7D0} = {43C5BAB1-1DCA-4743-A183-77E0D42FE7D0}
                {A5911CD7-F8E8-440C-A23E-4843A0636F3A} = {A5911CD7-F8E8-440C-A23E-4843A0636F3A}
index c4ec101..dec1e05 100644 (file)
@@ -56,7 +56,6 @@ sci_gateway/c/sci_msscanf.c \
 sci_gateway/c/sci_mfscanf.c \
 sci_gateway/c/sci_fprintfMat.c \
 sci_gateway/c/sci_fscanfMat.c \
-sci_gateway/c/sci_findfiles.c \
 sci_gateway/c/sci_maxfiles.c \
 sci_gateway/c/sci_getdrives.c \
 sci_gateway/c/sci_fullpath.c \
@@ -96,7 +95,8 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_pathconvert.cpp \
        sci_gateway/cpp/sci_isdir.cpp \
        sci_gateway/cpp/sci_filesep.cpp \
-       sci_gateway/cpp/sci_fileparts.cpp
+       sci_gateway/cpp/sci_fileparts.cpp \
+       sci_gateway/cpp/sci_findfiles.cpp
 
 FILEIO_CPP_SOURCES = \
        src/cpp/expandPathVariable.cpp \
index 1890044..01400c4 100644 (file)
@@ -154,7 +154,6 @@ am__objects_3 = libscifileio_la-gw_fileio.lo \
        libscifileio_la-sci_msscanf.lo libscifileio_la-sci_mfscanf.lo \
        libscifileio_la-sci_fprintfMat.lo \
        libscifileio_la-sci_fscanfMat.lo \
-       libscifileio_la-sci_findfiles.lo \
        libscifileio_la-sci_maxfiles.lo \
        libscifileio_la-sci_getdrives.lo \
        libscifileio_la-sci_fullpath.lo \
@@ -181,7 +180,8 @@ am__objects_4 = libscifileio_la-fileio_gw.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_fileparts.lo
+       libscifileio_la-sci_fileparts.lo \
+       libscifileio_la-sci_findfiles.lo
 am_libscifileio_la_OBJECTS = $(am__objects_1) $(am__objects_2) \
        $(am__objects_3) $(am__objects_4)
 libscifileio_la_OBJECTS = $(am_libscifileio_la_OBJECTS)
@@ -519,7 +519,6 @@ sci_gateway/c/sci_msscanf.c \
 sci_gateway/c/sci_mfscanf.c \
 sci_gateway/c/sci_fprintfMat.c \
 sci_gateway/c/sci_fscanfMat.c \
-sci_gateway/c/sci_findfiles.c \
 sci_gateway/c/sci_maxfiles.c \
 sci_gateway/c/sci_getdrives.c \
 sci_gateway/c/sci_fullpath.c \
@@ -559,7 +558,8 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_pathconvert.cpp \
        sci_gateway/cpp/sci_isdir.cpp \
        sci_gateway/cpp/sci_filesep.cpp \
-       sci_gateway/cpp/sci_fileparts.cpp
+       sci_gateway/cpp/sci_fileparts.cpp \
+       sci_gateway/cpp/sci_findfiles.cpp
 
 FILEIO_CPP_SOURCES = \
        src/cpp/expandPathVariable.cpp \
@@ -1235,13 +1235,6 @@ libscifileio_la-sci_fscanfMat.lo: sci_gateway/c/sci_fscanfMat.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_fscanfMat.lo `test -f 'sci_gateway/c/sci_fscanfMat.c' || echo '$(srcdir)/'`sci_gateway/c/sci_fscanfMat.c
 
-libscifileio_la-sci_findfiles.lo: sci_gateway/c/sci_findfiles.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_findfiles.lo -MD -MP -MF $(DEPDIR)/libscifileio_la-sci_findfiles.Tpo -c -o libscifileio_la-sci_findfiles.lo `test -f 'sci_gateway/c/sci_findfiles.c' || echo '$(srcdir)/'`sci_gateway/c/sci_findfiles.c
-@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscifileio_la-sci_findfiles.Tpo $(DEPDIR)/libscifileio_la-sci_findfiles.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='sci_gateway/c/sci_findfiles.c' object='libscifileio_la-sci_findfiles.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_findfiles.lo `test -f 'sci_gateway/c/sci_findfiles.c' || echo '$(srcdir)/'`sci_gateway/c/sci_findfiles.c
-
 libscifileio_la-sci_maxfiles.lo: sci_gateway/c/sci_maxfiles.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_maxfiles.lo -MD -MP -MF $(DEPDIR)/libscifileio_la-sci_maxfiles.Tpo -c -o libscifileio_la-sci_maxfiles.lo `test -f 'sci_gateway/c/sci_maxfiles.c' || echo '$(srcdir)/'`sci_gateway/c/sci_maxfiles.c
 @am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscifileio_la-sci_maxfiles.Tpo $(DEPDIR)/libscifileio_la-sci_maxfiles.Plo
@@ -1585,6 +1578,13 @@ libscifileio_la-sci_fileparts.lo: sci_gateway/cpp/sci_fileparts.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_fileparts.lo `test -f 'sci_gateway/cpp/sci_fileparts.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_fileparts.cpp
 
+libscifileio_la-sci_findfiles.lo: sci_gateway/cpp/sci_findfiles.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_findfiles.lo -MD -MP -MF $(DEPDIR)/libscifileio_la-sci_findfiles.Tpo -c -o libscifileio_la-sci_findfiles.lo `test -f 'sci_gateway/cpp/sci_findfiles.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_findfiles.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscifileio_la-sci_findfiles.Tpo $(DEPDIR)/libscifileio_la-sci_findfiles.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_findfiles.cpp' object='libscifileio_la-sci_findfiles.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_findfiles.lo `test -f 'sci_gateway/cpp/sci_findfiles.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_findfiles.cpp
+
 mostlyclean-libtool:
        -rm -f *.lo
 
index 90afda9..64390c5 100644 (file)
                                >
                        </File>
                        <File
-                               RelativePath=".\sci_gateway\c\sci_findfiles.c"
-                               >
-                       </File>
-                       <File
                                RelativePath=".\sci_gateway\c\sci_fprintfMat.c"
                                >
                        </File>
index 8de9075..906cf71 100644 (file)
@@ -46,5 +46,6 @@ CPP_GATEWAY_PROTOTYPE(sci_pathconvert);
 CPP_GATEWAY_PROTOTYPE(sci_isdir);
 CPP_GATEWAY_PROTOTYPE(sci_filesep);
 CPP_GATEWAY_PROTOTYPE(sci_fileparts);
+CPP_GATEWAY_PROTOTYPE(sci_findfiles);
 
 #endif /* !__FILEIO_GW_HXX__ */
index 36c7236..c30315e 100644 (file)
@@ -30,7 +30,6 @@ FILEIO_IMPEXP int sci_scanf(char *fname,unsigned long fname_len);
 FILEIO_IMPEXP int sci_fprintfMat(char *fname,unsigned long fname_len);
 FILEIO_IMPEXP int sci_sscanf(char *fname,unsigned long fname_len);
 FILEIO_IMPEXP int sci_fscanf(char *fname,unsigned long fname_len);
-FILEIO_IMPEXP int sci_findfiles(char *fname,unsigned long fname_len);
 FILEIO_IMPEXP int sci_maxfiles(char *fname,unsigned long fname_len);
 FILEIO_IMPEXP int sci_getdrives(char *fname,unsigned long fname_len);
 FILEIO_IMPEXP int sci_fullpath(char *fname,unsigned long fname_len);
index 41e9638..fc7de2f 100644 (file)
@@ -36,7 +36,7 @@ static gw_generic_table Tab[]={
        {sci_fscanfMat,"fscanfMat"},
        {sci_fprintfMat,"fprintfMat"},
        {sci_merror, "merror"},
-       {sci_findfiles,"findfiles"},
+       {NULL, ""}, //findfiles
        {sci_maxfiles,"maxfiles"},
        {sci_getdrives,"getdrives"},
        {sci_fullpath,"fullpath"},
diff --git a/scilab/modules/fileio/sci_gateway/c/sci_findfiles.c b/scilab/modules/fileio/sci_gateway/c/sci_findfiles.c
deleted file mode 100644 (file)
index d753c54..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2007 - INRIA - 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 <string.h>
-#include "gw_fileio.h"
-#include "findfiles.h"
-#include "stack-c.h"
-#include "MALLOC.h"
-#include "localization.h"
-#include "scicurdir.h" /* scigetcwd */
-#include "Scierror.h"
-#include "expandPathVariable.h"
-#include "PATH_MAX.h"
-#include "os_strdup.h"
-#include "freeArrayOfString.h"
-/*--------------------------------------------------------------------------*/
-#define DEFAULT_FILESPEC "*.*"
-/*--------------------------------------------------------------------------*/
-int sci_findfiles(char *fname,unsigned long fname_len)
-{
-       static int l1 = 0, n1 = 0, m1 = 0;
-       char *pathextented = NULL;
-       int out_n = 0;
-       char *path = NULL;
-       char *filespec = NULL;
-       char **FilesList = NULL;
-       int sizeListReturned = 0;
-
-       Rhs = Max(Rhs,0);
-       CheckRhs(0,2) ;
-       CheckLhs(0,1) ;
-
-       switch(Rhs)
-       {
-       default: case 0:
-               {
-                       int ierr = 0;
-                       int lpath = 0;
-
-                       path = scigetcwd(&ierr);
-
-                       if (ierr)
-                       {
-                               Scierror(999,_("%s: Error while trying to retrieve the name of the current directory.\n"),fname);
-                               return 0;
-                       }
-                       else
-                       {
-                               filespec = os_strdup(DEFAULT_FILESPEC);
-                       }
-               }
-               break;
-
-       case 1:
-               {
-                       if (GetType(1) == sci_strings)
-                       {
-                               GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
-                               path = os_strdup(cstk(l1));
-                               filespec = os_strdup(DEFAULT_FILESPEC);
-                       }
-                       else
-                       {
-                               Scierror(999,_("%s: Wrong type for input argument #%d: String expected.\n"),fname,1);
-                               return 0;
-                       }
-
-               }
-               break;
-
-       case 2:
-               {
-                       if ( (GetType(1) == sci_strings) && (GetType(2) == sci_strings) )
-                       {
-                               GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
-                               path = os_strdup(cstk(l1));
-
-                               GetRhsVar(2,STRING_DATATYPE,&m1,&n1,&l1);
-                               filespec = os_strdup(cstk(l1));
-                       }
-                       else
-                       {
-                               Scierror(999,_("%s: Wrong type for input arguments: Strings expected.\n"),fname); 
-                               return 0;
-                       }
-               }
-               break;
-       }
-
-       pathextented = expandPathVariable(path);
-       if (path) {FREE(path); path = NULL;}
-       FilesList = findfiles(pathextented, filespec, &sizeListReturned, FALSE);
-       if (pathextented) {FREE(pathextented); pathextented = NULL;}
-       if (filespec) {FREE(filespec); filespec = NULL;}
-
-       if (FilesList)
-       {
-               int ncol = 0, nrow = 0;
-
-               ncol = 1;
-               nrow = sizeListReturned;
-
-               CreateVarFromPtr(Rhs+1,MATRIX_OF_STRING_DATATYPE, &nrow, &ncol, FilesList);
-               LhsVar(1) = Rhs+1;
-       }
-       else
-       {
-               n1 = 0; m1 = 0; l1 = 0;
-               CreateVarFromPtr(Rhs+ 1,MATRIX_OF_DOUBLE_DATATYPE,&n1,&m1,&l1);
-               LhsVar(1) = Rhs+1;
-       }
-
-       freeArrayOfString(FilesList,sizeListReturned);
-
-       C2F(putlhsvar)();
-       return 0;
-}
-/*--------------------------------------------------------------------------*/
index 100c185..b50e984 100644 (file)
@@ -35,5 +35,6 @@ bool FileioModule::Load()
     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));
+    symbol::Context::getInstance()->AddFunction(Function::createFunction(L"findfiles", &sci_findfiles, MODULE_NAME));
     return true;
 }
index 2b2df9b..8df64b9 100644 (file)
                                >
                        </File>
                        <File
+                               RelativePath=".\sci_findfiles.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\sci_isdir.cpp"
                                >
                        </File>
diff --git a/scilab/modules/fileio/sci_gateway/cpp/sci_findfiles.cpp b/scilab/modules/fileio/sci_gateway/cpp/sci_findfiles.cpp
new file mode 100644 (file)
index 0000000..f9d41a4
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2007 - INRIA - 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 "funcmanager.hxx"
+#include "filemanager.hxx"
+#include "fileio_gw.hxx"
+
+extern "C"
+{
+#include "findfiles.h"
+#include "localization.h"
+#include "Scierror.h"
+#include "expandPathVariable.h"
+#include "PATH_MAX.h"
+#include "os_wcsdup.h"
+#include "scicurdir.h"
+#include "freeArrayOfString.h"
+}
+/*--------------------------------------------------------------------------*/
+#define DEFAULT_FILESPEC L"*.*"
+/*--------------------------------------------------------------------------*/
+Function::ReturnValue sci_findfiles(typed_list &in, int _iRetCount, typed_list &out)
+{
+    wchar_t* pwstPath   = NULL;
+    wchar_t* pwstSpec   = NULL;
+    bool bAllocatedSpec = false;
+
+    if(in.size() < 0 || in.size() > 2)
+    {
+        ScierrorW(77, _W("%ls: Wrong number of input argument(s): %d to %d expected.\n"), L"findfiles", 0, 2);
+        return Function::Error;
+    }
+
+    if(in.size() == 0)
+    {//default path and default file spec
+        int ierr        = 0;
+
+        pwstPath        = scigetcwdW(&ierr);
+        pwstSpec        = os_wcsdup(DEFAULT_FILESPEC);
+        bAllocatedSpec  = true;
+    }
+    else
+    {//user path
+        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"findfiles", 1);
+            return Function::Error;
+        }
+
+        pwstPath = expandPathVariableW(in[0]->getAsString()->string_get()[0]);
+
+        if(in.size() == 2)
+        {//user file spec
+            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"findfiles", 2);
+                return Function::Error;
+            }
+
+            pwstSpec = in[1]->getAsString()->string_get()[0];
+        }
+        else
+        {//default file spec
+            pwstSpec        = os_wcsdup(DEFAULT_FILESPEC);
+            bAllocatedSpec  = true;
+        }
+    }
+
+    int iSize               = 0;
+    wchar_t** pwstFilesList = NULL;
+
+    pwstFilesList = findfilesW(pwstPath, pwstSpec, &iSize, 0);
+    if(pwstFilesList)
+    {
+        String* pS = new String(iSize, 1);
+        pS->string_set(pwstFilesList);
+        freeArrayOfWideString(pwstFilesList, iSize);
+        out.push_back(pS);
+    }
+    else
+    {
+        out.push_back(Double::Empty());
+    }
+
+    FREE(pwstPath);
+    if(bAllocatedSpec)
+    {
+        FREE(pwstSpec);
+    }
+
+    return Function::OK;
+}
+/*--------------------------------------------------------------------------*/