add isdir function 02/1802/4
Antoine ELIAS [Fri, 3 Sep 2010 15:35:48 +0000 (17:35 +0200)]
Change-Id: If3c6829ab805e3bbb73f0a1405151b391d3c3672

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_isdir.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_isdir.cpp [new file with mode: 0644]

index 2993204..b85e428 100644 (file)
@@ -66,7 +66,6 @@ sci_gateway/c/sci_filesep.c \
 sci_gateway/c/sci_getshortpathname.c \
 sci_gateway/c/sci_getlongpathname.c \
 sci_gateway/c/sci_fileext.c \
-sci_gateway/c/sci_isdir.c \
 sci_gateway/c/sci_removedir.c \
 sci_gateway/c/sci_createdir.c \
 sci_gateway/c/sci_chdir.c \
@@ -96,7 +95,8 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_mput.cpp \
        sci_gateway/cpp/sci_mputl.cpp \
        sci_gateway/cpp/sci_mgetl.cpp \
-       sci_gateway/cpp/sci_pathconvert.cpp
+       sci_gateway/cpp/sci_pathconvert.cpp \
+       sci_gateway/cpp/sci_isdir.cpp
 
 FILEIO_CPP_SOURCES = \
        src/cpp/expandPathVariable.cpp \
index c047ed9..c1c0310 100644 (file)
@@ -162,7 +162,7 @@ am__objects_3 = libscifileio_la-gw_fileio.lo \
        libscifileio_la-sci_pathsep.lo libscifileio_la-sci_filesep.lo \
        libscifileio_la-sci_getshortpathname.lo \
        libscifileio_la-sci_getlongpathname.lo \
-       libscifileio_la-sci_fileext.lo libscifileio_la-sci_isdir.lo \
+       libscifileio_la-sci_fileext.lo \
        libscifileio_la-sci_removedir.lo \
        libscifileio_la-sci_createdir.lo libscifileio_la-sci_chdir.lo \
        libscifileio_la-sci_pwd.lo libscifileio_la-sci_mclearerr.lo \
@@ -180,7 +180,8 @@ am__objects_4 = libscifileio_la-fileio_gw.lo \
        libscifileio_la-sci_mopen.lo libscifileio_la-sci_mclose.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_pathconvert.lo \
+       libscifileio_la-sci_isdir.lo
 am_libscifileio_la_OBJECTS = $(am__objects_1) $(am__objects_2) \
        $(am__objects_3) $(am__objects_4)
 libscifileio_la_OBJECTS = $(am_libscifileio_la_OBJECTS)
@@ -528,7 +529,6 @@ sci_gateway/c/sci_filesep.c \
 sci_gateway/c/sci_getshortpathname.c \
 sci_gateway/c/sci_getlongpathname.c \
 sci_gateway/c/sci_fileext.c \
-sci_gateway/c/sci_isdir.c \
 sci_gateway/c/sci_removedir.c \
 sci_gateway/c/sci_createdir.c \
 sci_gateway/c/sci_chdir.c \
@@ -558,7 +558,8 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_mput.cpp \
        sci_gateway/cpp/sci_mputl.cpp \
        sci_gateway/cpp/sci_mgetl.cpp \
-       sci_gateway/cpp/sci_pathconvert.cpp
+       sci_gateway/cpp/sci_pathconvert.cpp \
+       sci_gateway/cpp/sci_isdir.cpp
 
 FILEIO_CPP_SOURCES = \
        src/cpp/expandPathVariable.cpp \
@@ -1304,13 +1305,6 @@ libscifileio_la-sci_fileext.lo: sci_gateway/c/sci_fileext.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_fileext.lo `test -f 'sci_gateway/c/sci_fileext.c' || echo '$(srcdir)/'`sci_gateway/c/sci_fileext.c
 
-libscifileio_la-sci_isdir.lo: sci_gateway/c/sci_isdir.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_isdir.lo -MD -MP -MF $(DEPDIR)/libscifileio_la-sci_isdir.Tpo -c -o libscifileio_la-sci_isdir.lo `test -f 'sci_gateway/c/sci_isdir.c' || echo '$(srcdir)/'`sci_gateway/c/sci_isdir.c
-@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscifileio_la-sci_isdir.Tpo $(DEPDIR)/libscifileio_la-sci_isdir.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='sci_gateway/c/sci_isdir.c' object='libscifileio_la-sci_isdir.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_isdir.lo `test -f 'sci_gateway/c/sci_isdir.c' || echo '$(srcdir)/'`sci_gateway/c/sci_isdir.c
-
 libscifileio_la-sci_removedir.lo: sci_gateway/c/sci_removedir.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_removedir.lo -MD -MP -MF $(DEPDIR)/libscifileio_la-sci_removedir.Tpo -c -o libscifileio_la-sci_removedir.lo `test -f 'sci_gateway/c/sci_removedir.c' || echo '$(srcdir)/'`sci_gateway/c/sci_removedir.c
 @am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscifileio_la-sci_removedir.Tpo $(DEPDIR)/libscifileio_la-sci_removedir.Plo
@@ -1584,6 +1578,13 @@ libscifileio_la-sci_pathconvert.lo: sci_gateway/cpp/sci_pathconvert.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_pathconvert.lo `test -f 'sci_gateway/cpp/sci_pathconvert.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_pathconvert.cpp
 
+libscifileio_la-sci_isdir.lo: sci_gateway/cpp/sci_isdir.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_isdir.lo -MD -MP -MF $(DEPDIR)/libscifileio_la-sci_isdir.Tpo -c -o libscifileio_la-sci_isdir.lo `test -f 'sci_gateway/cpp/sci_isdir.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_isdir.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscifileio_la-sci_isdir.Tpo $(DEPDIR)/libscifileio_la-sci_isdir.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_isdir.cpp' object='libscifileio_la-sci_isdir.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_isdir.lo `test -f 'sci_gateway/cpp/sci_isdir.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_isdir.cpp
+
 mostlyclean-libtool:
        -rm -f *.lo
 
index 1ce4fec..07ae032 100644 (file)
                                >
                        </File>
                        <File
-                               RelativePath=".\sci_gateway\c\sci_isdir.c"
-                               >
-                       </File>
-                       <File
                                RelativePath=".\sci_gateway\c\sci_isfile.c"
                                >
                        </File>
index 1e8de0a..4371d11 100644 (file)
@@ -43,5 +43,6 @@ CPP_GATEWAY_PROTOTYPE(sci_mget);
 CPP_GATEWAY_PROTOTYPE(sci_mputl);
 CPP_GATEWAY_PROTOTYPE(sci_mgetl);
 CPP_GATEWAY_PROTOTYPE(sci_pathconvert);
+CPP_GATEWAY_PROTOTYPE(sci_isdir);
 
 #endif /* !__FILEIO_GW_HXX__ */
index 3b5ede9..b12cc89 100644 (file)
@@ -49,7 +49,6 @@ FILEIO_IMPEXP int sci_get_absolute_file_path(char *fname,unsigned long fname_len
 
 //YaSp
 FILEIO_IMPEXP int sci_pwd(char *fname, int* _piKey);
-FILEIO_IMPEXP int sci_isdir(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);
diff --git a/scilab/modules/fileio/sci_gateway/c/sci_isdir.c b/scilab/modules/fileio/sci_gateway/c/sci_isdir.c
deleted file mode 100644 (file)
index d36aee3..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2007 - INRIA - Sylvestre LEDRU
- * 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
- *
- */
-/*--------------------------------------------------------------------------*/ 
-/*
- * Provides is_dir to scilab
- *
- */
-/*--------------------------------------------------------------------------*/ 
-#include "gw_fileio.h"
-#include "stack-c.h"
-#include "MALLOC.h"
-#include "localization.h"
-#include "api_scilab.h"
-#include "Scierror.h"
-#include "expandPathVariable.h"
-#include "isdir.h"
-#include "freeArrayOfString.h"
-#include "BOOL.h"
-/*--------------------------------------------------------------------------*/
-int sci_isdir(char *fname, int* _piKey)
-{
-       SciErr sciErr;
-       int *piAddressVarOne = NULL;
-       wchar_t **pStVarOne = NULL;
-       int iType = 0;
-       int *lenStVarOne = NULL;
-       int m1 = 0, n1 = 0;
-
-       BOOL *results = NULL;
-       int m_out = 0, n_out = 0;
-       int i = 0;
-
-       /* Check Input & Output parameters */
-       CheckRhs(1,1);
-       CheckLhs(1,1);
-
-       sciErr = getVarAddressFromPosition(_piKey, 1, &piAddressVarOne);
-       if(sciErr.iErr)
-       {
-               printError(&sciErr, 0);
-               return 0;
-       }
-
-       sciErr = getVarType(_piKey, piAddressVarOne, &iType);
-       if(sciErr.iErr)
-       {
-               printError(&sciErr, 0);
-               return 0;
-       }
-
-       if (iType != sci_strings)
-       {
-               Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
-               return 0;
-       }
-
-       sciErr = getVarDimension(_piKey, piAddressVarOne, &m1, &n1);
-       if(sciErr.iErr)
-       {
-               printError(&sciErr, 0);
-               return 0;
-       }
-
-       lenStVarOne = (int*)MALLOC(sizeof(int) * (m1 * n1));
-       if (lenStVarOne == NULL)
-       {
-               Scierror(999,_("%s: Memory allocation error.\n"),fname);
-               return 0;
-       }
-
-       results = (BOOL*)MALLOC(sizeof(BOOL) * (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;
-       }
-
-       sciErr = getMatrixOfWideString(_piKey, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
-       if(sciErr.iErr)
-       {
-               printError(&sciErr, 0);
-               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;
-       }
-
-       for (i = 0; i < m1 * n1; i++)
-       {
-               pStVarOne[i] = (wchar_t*)MALLOC(sizeof(wchar_t)* (lenStVarOne[i] + 1));
-               if (pStVarOne[i] == NULL)
-               {
-                       freeArrayOfWideString(pStVarOne, m1 * n1);
-                       if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
-                       Scierror(999,_("%s: Memory allocation error.\n"),fname);
-                       return 0;
-               }
-       }
-
-       sciErr = getMatrixOfWideString(_piKey, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
-       if(sciErr.iErr)
-       {
-               freeArrayOfWideString(pStVarOne, m1 * n1);
-               if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
-               printError(&sciErr, 0);
-               return 0;
-       }
-
-       for (i = 0; i < m1 * n1; i++)
-       {
-               wchar_t *expandedPath = expandPathVariableW(pStVarOne[i]);
-               if (expandedPath)
-               {
-                       results[i] = isdirW(expandedPath);
-                       FREE(expandedPath);
-                       expandedPath = NULL;
-               }
-               else
-               {
-                       results[i] = FALSE;
-               }
-       }
-
-       if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
-       freeArrayOfWideString(pStVarOne, m1 * n1);
-
-       sciErr = createMatrixOfBoolean(_piKey, Rhs + 1, m1, n1, results);
-       if(sciErr.iErr)
-       {
-               printError(&sciErr, 0);
-               return 0;
-       }
-
-       LhsVar(1) = Rhs + 1;
-
-       if (results) {FREE(results); results = NULL;}
-
-       C2F(putlhsvar)();
-       return 0;
-}
-/*--------------------------------------------------------------------------*/
index 5dc1f41..c3644ab 100644 (file)
@@ -32,5 +32,6 @@ bool FileioModule::Load()
     symbol::Context::getInstance()->AddFunction(Function::createFunction(L"mputl", &sci_mputl, MODULE_NAME));
     symbol::Context::getInstance()->AddFunction(Function::createFunction(L"mgetl", &sci_mgetl, MODULE_NAME));
     symbol::Context::getInstance()->AddFunction(Function::createFunction(L"pathconvert", &sci_pathconvert, MODULE_NAME));
+    symbol::Context::getInstance()->AddFunction(Function::createFunction(L"isdir", &sci_isdir, MODULE_NAME));
     return true;
 }
index d9e34b9..75da90f 100644 (file)
                                >
                        </File>
                        <File
+                               RelativePath=".\sci_isdir.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\sci_mclose.cpp"
                                >
                        </File>
diff --git a/scilab/modules/fileio/sci_gateway/cpp/sci_isdir.cpp b/scilab/modules/fileio/sci_gateway/cpp/sci_isdir.cpp
new file mode 100644 (file)
index 0000000..01b01eb
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2007 - INRIA - Sylvestre LEDRU
+ * 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
+ *
+ */
+/*--------------------------------------------------------------------------*/ 
+/*
+ * Provides is_dir to scilab
+ *
+ */
+/*--------------------------------------------------------------------------*/ 
+#include "alltypes.hxx"
+#include "funcmanager.hxx"
+#include "filemanager.hxx"
+#include "fileio_gw.hxx"
+
+extern "C"
+{
+#include "localization.h"
+#include "Scierror.h"
+#include "expandPathVariable.h"
+#include "isdir.h"
+}
+
+/*--------------------------------------------------------------------------*/
+Function::ReturnValue sci_isdir(typed_list &in, int _iRetCount, typed_list &out)
+{
+    if(in.size() != 1)
+    {
+        ScierrorW(999, _W("%ls: Wrong number of input arguments: %d expected.\n"), L"isdir" , 1);
+        return Function::Error;
+    }
+
+    if(_iRetCount != 1)
+    {
+        ScierrorW(78,_W("%ls: Wrong number of output argument(s): %d expected.\n"), L"isdir", 1);
+        return Function::Error;
+    }
+
+    if(in[0]->isString() == false)
+    {
+        ScierrorW(999, _W("%ls: Wrong type for input argument #%d: Matrix of strings expected.\n"), L"pathconvert", 1);
+        return Function::Error;
+    }
+
+    String* pS  = in[0]->getAsString();
+    Bool* pOut  = new Bool(pS->rows_get(), pS->cols_get());
+
+    for(int i = 0 ; i < pS->size_get() ; i++)
+    {
+        wchar_t *expandedPath = expandPathVariableW(pS->string_get(i));
+               if(expandedPath)
+               {
+                       pOut->bool_get()[i] = isdirW(expandedPath);
+                       FREE(expandedPath);
+                       expandedPath = NULL;
+               }
+               else
+               {
+                       pOut->bool_get()[i] = FALSE;
+               }
+       }
+
+    out.push_back(pOut);
+    return Function::OK;
+}
+/*--------------------------------------------------------------------------*/