add fileinfo function 14/2314/3
antoine ELIAS [Tue, 19 Oct 2010 09:01:39 +0000 (11:01 +0200)]
Change-Id: Id22e306969fdaf3936bb2b9503b250c55c3a4d80

12 files changed:
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_fileinfo.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_fileinfo.cpp [new file with mode: 0644]
scilab/modules/fileio/src/c/fileinfo.c
scilab/modules/fileio/src/c/fileinfo.h

index a625af7..7fd81f0 100644 (file)
@@ -78,7 +78,6 @@ sci_gateway/c/sci_moef.c \
 sci_gateway/c/sci_mputstr.c \
 sci_gateway/c/sci_mseek.c \
 sci_gateway/c/sci_mtell.c \
-sci_gateway/c/sci_fileinfo.c \
 sci_gateway/c/sci_newest.c \
 sci_gateway/c/sci_get_absolute_file_path.c  \
 sci_gateway/c/sci_getrelativefilename.c \
@@ -99,6 +98,7 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_fileparts.cpp \
        sci_gateway/cpp/sci_findfiles.cpp \
        sci_gateway/cpp/sci_basename.cpp \
+       sci_gateway/cpp/sci_fileinfo.cpp \
        sci_gateway/cpp/sci_isfile.cpp
 
 
index 9101572..2aa61ac 100644 (file)
@@ -170,7 +170,7 @@ am__objects_3 = libscifileio_la-gw_fileio.lo \
        libscifileio_la-sci_merror.lo libscifileio_la-sci_mgetstr.lo \
        libscifileio_la-sci_moef.lo libscifileio_la-sci_mputstr.lo \
        libscifileio_la-sci_mseek.lo libscifileio_la-sci_mtell.lo \
-       libscifileio_la-sci_fileinfo.lo libscifileio_la-sci_newest.lo \
+       libscifileio_la-sci_newest.lo \
        libscifileio_la-sci_get_absolute_file_path.lo \
        libscifileio_la-sci_getrelativefilename.lo \
        libscifileio_la-sci_copyfile.lo \
@@ -183,7 +183,8 @@ am__objects_4 = libscifileio_la-fileio_gw.lo \
        libscifileio_la-sci_isdir.lo libscifileio_la-sci_filesep.lo \
        libscifileio_la-sci_fileparts.lo \
        libscifileio_la-sci_findfiles.lo \
-       libscifileio_la-sci_basename.lo libscifileio_la-sci_isfile.lo
+       libscifileio_la-sci_basename.lo \
+       libscifileio_la-sci_fileinfo.lo libscifileio_la-sci_isfile.lo
 am_libscifileio_la_OBJECTS = $(am__objects_1) $(am__objects_2) \
        $(am__objects_3) $(am__objects_4)
 libscifileio_la_OBJECTS = $(am_libscifileio_la_OBJECTS)
@@ -543,7 +544,6 @@ sci_gateway/c/sci_moef.c \
 sci_gateway/c/sci_mputstr.c \
 sci_gateway/c/sci_mseek.c \
 sci_gateway/c/sci_mtell.c \
-sci_gateway/c/sci_fileinfo.c \
 sci_gateway/c/sci_newest.c \
 sci_gateway/c/sci_get_absolute_file_path.c  \
 sci_gateway/c/sci_getrelativefilename.c \
@@ -564,6 +564,7 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_fileparts.cpp \
        sci_gateway/cpp/sci_findfiles.cpp \
        sci_gateway/cpp/sci_basename.cpp \
+       sci_gateway/cpp/sci_fileinfo.cpp \
        sci_gateway/cpp/sci_isfile.cpp
 
 FILEIO_CPP_SOURCES = \
@@ -1395,13 +1396,6 @@ libscifileio_la-sci_mtell.lo: sci_gateway/c/sci_mtell.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_mtell.lo `test -f 'sci_gateway/c/sci_mtell.c' || echo '$(srcdir)/'`sci_gateway/c/sci_mtell.c
 
-libscifileio_la-sci_fileinfo.lo: sci_gateway/c/sci_fileinfo.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_fileinfo.lo -MD -MP -MF $(DEPDIR)/libscifileio_la-sci_fileinfo.Tpo -c -o libscifileio_la-sci_fileinfo.lo `test -f 'sci_gateway/c/sci_fileinfo.c' || echo '$(srcdir)/'`sci_gateway/c/sci_fileinfo.c
-@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscifileio_la-sci_fileinfo.Tpo $(DEPDIR)/libscifileio_la-sci_fileinfo.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='sci_gateway/c/sci_fileinfo.c' object='libscifileio_la-sci_fileinfo.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_fileinfo.lo `test -f 'sci_gateway/c/sci_fileinfo.c' || echo '$(srcdir)/'`sci_gateway/c/sci_fileinfo.c
-
 libscifileio_la-sci_newest.lo: sci_gateway/c/sci_newest.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_newest.lo -MD -MP -MF $(DEPDIR)/libscifileio_la-sci_newest.Tpo -c -o libscifileio_la-sci_newest.lo `test -f 'sci_gateway/c/sci_newest.c' || echo '$(srcdir)/'`sci_gateway/c/sci_newest.c
 @am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscifileio_la-sci_newest.Tpo $(DEPDIR)/libscifileio_la-sci_newest.Plo
@@ -1605,6 +1599,13 @@ libscifileio_la-sci_basename.lo: sci_gateway/cpp/sci_basename.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_basename.lo `test -f 'sci_gateway/cpp/sci_basename.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_basename.cpp
 
+libscifileio_la-sci_fileinfo.lo: sci_gateway/cpp/sci_fileinfo.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_fileinfo.lo -MD -MP -MF $(DEPDIR)/libscifileio_la-sci_fileinfo.Tpo -c -o libscifileio_la-sci_fileinfo.lo `test -f 'sci_gateway/cpp/sci_fileinfo.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_fileinfo.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscifileio_la-sci_fileinfo.Tpo $(DEPDIR)/libscifileio_la-sci_fileinfo.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_fileinfo.cpp' object='libscifileio_la-sci_fileinfo.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_fileinfo.lo `test -f 'sci_gateway/cpp/sci_fileinfo.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_fileinfo.cpp
+
 libscifileio_la-sci_isfile.lo: sci_gateway/cpp/sci_isfile.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_isfile.lo -MD -MP -MF $(DEPDIR)/libscifileio_la-sci_isfile.Tpo -c -o libscifileio_la-sci_isfile.lo `test -f 'sci_gateway/cpp/sci_isfile.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_isfile.cpp
 @am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscifileio_la-sci_isfile.Tpo $(DEPDIR)/libscifileio_la-sci_isfile.Plo
index 9cd23a7..c86a14b 100644 (file)
                                >
                        </File>
                        <File
-                               RelativePath=".\sci_gateway\c\sci_fileinfo.c"
-                               >
-                       </File>
-                       <File
                                RelativePath=".\sci_gateway\c\sci_fprintfMat.c"
                                >
                        </File>
index 1a4ff1a..ac711f3 100644 (file)
@@ -49,5 +49,6 @@ CPP_GATEWAY_PROTOTYPE(sci_fileparts);
 CPP_GATEWAY_PROTOTYPE(sci_findfiles);
 CPP_GATEWAY_PROTOTYPE(sci_basename);
 CPP_GATEWAY_PROTOTYPE(sci_isfile);
+CPP_GATEWAY_PROTOTYPE(sci_fileinfo);
 
 #endif /* !__FILEIO_GW_HXX__ */
index 46e10a0..6310d25 100644 (file)
@@ -38,7 +38,6 @@ FILEIO_IMPEXP int sci_getshortpathname(char *fname,unsigned long fname_len);
 FILEIO_IMPEXP int sci_fileext(char *fname,unsigned long fname_len);
 FILEIO_IMPEXP int sci_createdir(char *fname,unsigned long fname_len);
 FILEIO_IMPEXP int sci_removedir(char *fname,unsigned long fname_len);
-FILEIO_IMPEXP int sci_fileinfo(char *fname,unsigned long fname_len);
 FILEIO_IMPEXP int sci_newest(char *fname,unsigned long fname_len);
 FILEIO_IMPEXP int sci_getrelativefilename(char *fname, unsigned long l);
 FILEIO_IMPEXP int sci_get_absolute_file_path(char *fname,unsigned long fname_len);
index fc7de2f..1045f88 100644 (file)
@@ -51,7 +51,7 @@ static gw_generic_table Tab[]={
        {sci_createdir,"createdir"},
        {NULL, ""}, // pwd
        {NULL, ""}, //chdir
-       {sci_fileinfo,"fileinfo"},
+       {NULL, ""}, //fileinfo
        {sci_newest,"newest"},
        {sci_getrelativefilename,"getrelativefilename"},
        {sci_get_absolute_file_path,"get_absolute_file_path"},
diff --git a/scilab/modules/fileio/sci_gateway/c/sci_fileinfo.c b/scilab/modules/fileio/sci_gateway/c/sci_fileinfo.c
deleted file mode 100644 (file)
index 0f37ff1..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2006 - INRIA - Allan CORNET
- * 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_io.h"
-#include "PATH_MAX.h"
-#include "stack-c.h"
-#include "fileinfo.h"
-#include "MALLOC.h"
-#include "freeArrayOfString.h"
-#include "localization.h"
-#include "Scierror.h"
-#include "transposeMatrix.h"
-/*--------------------------------------------------------------------------*/
-int sci_fileinfo(char *fname,unsigned long fname_len)
-{
-       if (VarType(1) == sci_strings)
-       {
-               char **InputString_Parameter = NULL;
-               int m = 0, n = 0;
-               int mn = 0;
-
-               CheckRhs(1,1);
-               CheckLhs(1,2);
-
-               GetRhsVar(1,MATRIX_OF_STRING_DATATYPE, &m, &n, &InputString_Parameter); 
-               mn = m * n;
-
-               if (mn == 0)
-               {
-                       Scierror(999,"%s: Memory allocation error.\n",fname);
-                       return 0;
-               }
-
-               if (mn == 1)
-               {
-                       int result = 0;
-                       double *infos = fileinfo(InputString_Parameter[0],&result);
-
-                       if (infos)
-                       {
-                               int m_out = 1;
-                               int n_out = FILEINFO_ARRAY_SIZE;
-                               CreateVarFromPtr(Rhs+1,MATRIX_OF_DOUBLE_DATATYPE, &m_out, &n_out, &infos);
-                               LhsVar(1) = Rhs + 1;
-                               FREE(infos);
-                               infos = NULL;
-                       }
-                       else
-                       {
-                               int m_out = 0;
-                               int n_out = 0;
-                               int l_out = 0;
-
-                               /* returns [] */
-
-                CreateVar(Rhs + 1,MATRIX_OF_DOUBLE_DATATYPE,&m_out,&n_out,&l_out);
-                               LhsVar(1) = Rhs + 1;
-                       }
-
-                       freeArrayOfString(InputString_Parameter, mn);
-
-                       if (Lhs == 2)
-                       {
-                               int m_out = 1;
-                               int n_out = 1;
-                               int l_out = 0;
-                               CreateVar(Rhs + 2, MATRIX_OF_DOUBLE_DATATYPE,&m_out,&n_out,&l_out);
-                               *stk(l_out) = (double) result;
-                               LhsVar(2) = Rhs + 2;
-                       }
-
-                       C2F(putlhsvar)();
-               }
-               else
-               {
-                       if ( (m != 1) && (n == 1) )
-                       {
-                               int *results = (int*)MALLOC(sizeof(int) *mn);
-                               double *infos = filesinfo(InputString_Parameter, mn, results);
-                               if (infos)
-                               {
-                                       int m_out = 0;
-                                       int n_out = 0;
-                                       double *transposeInfos = NULL;
-
-                                       m_out = FILEINFO_ARRAY_SIZE;
-                                       n_out = m*n;
-
-                                       transposeInfos = transposeMatrixDouble(FILEINFO_ARRAY_SIZE,m*n,infos);
-                                       FREE(infos); infos = NULL;
-
-                                       n_out = FILEINFO_ARRAY_SIZE;
-                                       m_out = m*n;
-
-                                       CreateVarFromPtr(Rhs+1,MATRIX_OF_DOUBLE_DATATYPE, &m_out, &n_out, &transposeInfos);
-                                       LhsVar(1) = Rhs + 1;
-                                       FREE(transposeInfos); transposeInfos = NULL;
-                               }
-                               else
-                               {
-                                       int m_out = 0;
-                                       int n_out = 0;
-                                       int l_out = 0;
-
-                                       /* returns [] */
-
-                                       CreateVar(Rhs + 1,MATRIX_OF_DOUBLE_DATATYPE,&m_out,&n_out,&l_out);
-                                       LhsVar(1) = Rhs + 1;
-                               }
-
-                               if (Lhs == 2)
-                               {
-                                       int i = 0;
-                                       int m_out = m;
-                                       int n_out = n;
-                                       int l_out = 0;
-
-                                       CreateVar(Rhs + 2, MATRIX_OF_DOUBLE_DATATYPE,&m_out,&n_out,&l_out);
-                                       for (i = 0; i < mn; i++)
-                                       {
-                                               *stk(l_out + i) = (double) results[i];
-                                       }
-                                       LhsVar(2) = Rhs + 2;
-                               }
-
-                               freeArrayOfString(InputString_Parameter, mn);
-                               if (results) {FREE(results); results = NULL;}
-
-                               C2F(putlhsvar)();
-                       }
-                       else
-                       {
-                               freeArrayOfString(InputString_Parameter, mn);
-                               Scierror(999, _("%s: Wrong size for input argument #%d: A m-by-1 array expected.\n"), fname, 1);
-                       }
-               }
-       }
-       else
-       {
-               Scierror(999,_("%s: Wrong type for input argument: A string expected.\n"), fname);
-       }
-       return 0;
-}
-/*--------------------------------------------------------------------------*/
-
index 2575f6d..60c93a3 100644 (file)
@@ -38,5 +38,6 @@ bool FileioModule::Load()
     symbol::Context::getInstance()->AddFunction(Function::createFunction(L"findfiles", &sci_findfiles, MODULE_NAME));
     symbol::Context::getInstance()->AddFunction(Function::createFunction(L"basename", &sci_basename, MODULE_NAME));
     symbol::Context::getInstance()->AddFunction(Function::createFunction(L"isfile", &sci_isfile, MODULE_NAME));
+    symbol::Context::getInstance()->AddFunction(Function::createFunction(L"fileinfo", &sci_fileinfo, MODULE_NAME));
     return true;
 }
index 511e37a..2d059d9 100644 (file)
                                >
                        </File>
                        <File
+                               RelativePath=".\sci_fileinfo.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\sci_fileparts.cpp"
                                >
                        </File>
diff --git a/scilab/modules/fileio/sci_gateway/cpp/sci_fileinfo.cpp b/scilab/modules/fileio/sci_gateway/cpp/sci_fileinfo.cpp
new file mode 100644 (file)
index 0000000..a54575e
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2006 - INRIA - Allan CORNET
+ * 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 "fileinfo.h"
+#include "localization.h"
+#include "Scierror.h"
+}
+
+/*--------------------------------------------------------------------------*/
+Function::ReturnValue sci_fileinfo(typed_list &in, int _iRetCount, typed_list &out)
+{
+    if(in.size() != 1)
+    {
+        ScierrorW(77, _W("%ls: Wrong number of input argument(s): %d expected.\n"), L"fileinfo", 1);
+        return Function::Error;
+    }
+
+    if(in[0]->isString() == false || in[0]->getAsString()->cols_get() != 1)
+    {
+        Scierror(999, _("%ls: Wrong type for input argument: Column vector expected.\n"), L"fileinfo");
+        return Function::Error;
+    }
+
+    if(_iRetCount > 2)
+    {
+        ScierrorW(78, _W("%ls: Wrong number of output arguments: %d or %d expected.\n"), L"fileinfo", 1, 2);
+        return Function::Error;
+    }
+
+    String* pS = in[0]->getAsString();
+
+    int *piErr = new int[pS->rows_get()];
+    double* pData = filesinfoW(pS->string_get(), pS->rows_get(), piErr);
+
+    Double *pOut = new Double(pS->rows_get(), FILEINFO_ARRAY_SIZE);
+    pOut->real_set(pData);
+    out.push_back(pOut);
+
+    if(_iRetCount == 2)
+    {
+        Double* pErr = new Double(pS->rows_get(), 1);
+        pErr->real_set(piErr);
+        out.push_back(pErr);
+    }
+
+    delete[] piErr;
+    FREE(pData);
+    return Function::OK;
+}
+/*--------------------------------------------------------------------------*/
+
index 5122ca9..a9a5b12 100644 (file)
 #include "returnanan.h"
 #include "os_swprintf.h"
 #include "expandPathVariable.h"
-/*--------------------------------------------------------------------------*/
-#define FILEINFO_ARRAY_SIZE 13
-
-#define FILEINFO_TOTAL_SIZE_INDICE 0
-#define FILEINFO_MODE_INDICE       1
-#define FILEINFO_UID_INDICE        2
-#define FILEINFO_GID_INDICE        3
-#define FILEINFO_DEV_INDICE        4
-#define FILEINFO_MTIME_INDICE      5
-#define FILEINFO_CTIME_INDICE      6
-#define FILEINFO_ATIME_INDICE      7
-#define FILEINFO_RDEV_INDICE       8
-#define FILEINFO_BLKSIZE_INDICE    9
-#define FILEINFO_BLOCKS_INDICE    10
-#define FILEINFO_INO_INDICE       11
-#define FILEINFO_NLINK_INDICE     12
 
-#define FILEINFO_DEFAULT_ERROR    -1
 /*--------------------------------------------------------------------------*/
 #ifdef _MSC_VER
-static double *fileinfo_Windows(char *filepathname,int *ierr);
+static double* fileinfo_WindowsW(wchar_t* _pwstFilename, int* _piErr);
 #else
-static double *fileinfo_Others(char *filepathname,int *ierr);
+static double* fileinfo_OthersW(wchar_t* _pwstFilename, int* _piErr);
 #endif
 /*--------------------------------------------------------------------------*/
-double * fileinfo(char *filename, int *ierr)
+double* filesinfoW(wchar_t** _pwstFilename, int _iSize, int* _piErr)
 {
-       char *expandedpath = NULL;
-       double *FILEINFO_ARRAY = NULL;
-       int out_n = 0;
-
-       if (filename == NULL)
-       {
-               *ierr = FILEINFO_DEFAULT_ERROR;
-               return NULL;
-       }
-
-       expandedpath = expandPathVariable(filename);
-       if (expandedpath)
-       {
+    int i = 0, j = 0;
+       double *FILES_INFO_ARRAY = (double*)MALLOC(sizeof(double ) * _iSize * FILEINFO_ARRAY_SIZE);
+    for(i = 0 ; i < _iSize ; i++)
+    {
+        wchar_t* pwstExp = expandPathVariableW(_pwstFilename[i]);
+
+        if (pwstExp)
+        {
+            double *FILEINFO_ARRAY = NULL;
 #ifdef _MSC_VER
-               FILEINFO_ARRAY = fileinfo_Windows(expandedpath,ierr);
+            FILEINFO_ARRAY = fileinfo_WindowsW(pwstExp, &_piErr[i]);
 #else
-               FILEINFO_ARRAY = fileinfo_Others(expandedpath,ierr);
+            FILEINFO_ARRAY = fileinfo_OthersW(pwstExp, &_piErr[i]);
 #endif
-               FREE(expandedpath);
-               expandedpath = NULL;
-       }
-
-       return FILEINFO_ARRAY;
-}
-/*--------------------------------------------------------------------------*/
-double * filesinfo(char **filenames, int dim_filenames, int *ierrs)
-{
-       double *FILES_INFO_ARRAY = NULL;
-
-       if (dim_filenames > 0)
-       {
-               int i = 0;
-               int j = 0;
-               FILES_INFO_ARRAY = (double*)MALLOC(sizeof(double ) * (dim_filenames * FILEINFO_ARRAY_SIZE));
-               for (i = 0; i < dim_filenames; i++)
-               {
-                       int k = 0;
-                       int ierr = 0;
-                       double * FILEINFO_ARRAY = fileinfo(filenames[i],&ierr);
-                       if (FILEINFO_ARRAY == NULL)
-                       {
-                               FILEINFO_ARRAY = (double*)MALLOC(sizeof(double)*FILEINFO_ARRAY_SIZE);
-
-                               FILEINFO_ARRAY[FILEINFO_TOTAL_SIZE_INDICE] = C2F(returnanan)();
-                               FILEINFO_ARRAY[FILEINFO_MODE_INDICE] = C2F(returnanan)();
-                               FILEINFO_ARRAY[FILEINFO_UID_INDICE] =  C2F(returnanan)();
-                               FILEINFO_ARRAY[FILEINFO_GID_INDICE] =  C2F(returnanan)();
-                               FILEINFO_ARRAY[FILEINFO_DEV_INDICE] =  C2F(returnanan)();
-                               FILEINFO_ARRAY[FILEINFO_MTIME_INDICE] =  C2F(returnanan)();
-                               FILEINFO_ARRAY[FILEINFO_CTIME_INDICE] =  C2F(returnanan)();
-                               FILEINFO_ARRAY[FILEINFO_ATIME_INDICE] =  C2F(returnanan)();
-                               FILEINFO_ARRAY[FILEINFO_RDEV_INDICE] =  C2F(returnanan)();
-                               FILEINFO_ARRAY[FILEINFO_BLKSIZE_INDICE] =  C2F(returnanan)();
-                               FILEINFO_ARRAY[FILEINFO_BLOCKS_INDICE] =  C2F(returnanan)();
-                               FILEINFO_ARRAY[FILEINFO_INO_INDICE] =  C2F(returnanan)();
-                               FILEINFO_ARRAY[FILEINFO_NLINK_INDICE] =  C2F(returnanan)();
-                       }
 
-                       for (k = 0;k < FILEINFO_ARRAY_SIZE; k++)
-                       {
-                               FILES_INFO_ARRAY[j+k] = FILEINFO_ARRAY[k];
-                       }
-                       j = j + FILEINFO_ARRAY_SIZE;
-                       FREE(FILEINFO_ARRAY);
-                       FILEINFO_ARRAY = NULL;
-                       ierrs[i] = ierr;
-               }
-       }
-       return FILES_INFO_ARRAY;
+            if(FILEINFO_ARRAY != NULL)
+            {
+                for(j = 0 ; j < FILEINFO_ARRAY_SIZE ; j++)
+                {
+                    FILES_INFO_ARRAY[i + j * _iSize] = FILEINFO_ARRAY[j];
+                }
+            }
+            else
+            {
+                for(j = 0 ; j < FILEINFO_ARRAY_SIZE ; j++)
+                {
+                    FILES_INFO_ARRAY[i + j * _iSize] = C2F(returnanan)();
+                }
+            }
+            FREE(FILEINFO_ARRAY);
+            FREE(pwstExp);
+        }
+    }
+    return FILES_INFO_ARRAY;
 }
 /*--------------------------------------------------------------------------*/
 #ifdef _MSC_VER
-static double *fileinfo_Windows(char *filepathname,int *ierr)
+static double *fileinfo_WindowsW(wchar_t* _pwstFilename, int *_piErr)
 {
        struct _stat buf;
-       wchar_t* wcpath = to_wide_string(filepathname);
        wchar_t DriveTemp[PATH_MAX + FILENAME_MAX + 1];
 
        double *FILEINFO_ARRAY = NULL;
        int result = 0;
 
-       *ierr = 0;
+       *_piErr = 0;
 
-       if (wcpath == NULL)
+       if (_pwstFilename == NULL)
        {
-               *ierr = FILEINFO_DEFAULT_ERROR;
+               *_piErr = FILEINFO_DEFAULT_ERROR;
                return NULL;
        }
 
-       os_swprintf(DriveTemp, wcslen(wcpath)+1, L"%ls", wcpath);
+    FILEINFO_ARRAY = (double*)MALLOC(sizeof(double) * FILEINFO_ARRAY_SIZE);
+       os_swprintf(DriveTemp, PATH_MAX + FILENAME_MAX + 1, L"%ls", _pwstFilename);
        if ( (DriveTemp[wcslen(DriveTemp)-1] == L'/') || (DriveTemp[wcslen(DriveTemp)-1] == L'\\') )
        {
                DriveTemp[wcslen(DriveTemp)-1] = L'\0';
@@ -144,8 +92,6 @@ static double *fileinfo_Windows(char *filepathname,int *ierr)
 
        result = _wstat(DriveTemp, &buf );
 
-       FREE(wcpath); wcpath = NULL;
-
        if( result != 0 ) 
        {
                if ( (wcslen(DriveTemp) == 2) ||(wcslen(DriveTemp) == 3) )
@@ -153,7 +99,7 @@ static double *fileinfo_Windows(char *filepathname,int *ierr)
                        UINT DriveType = GetDriveTypeW(DriveTemp);
                        if ( (DriveType == DRIVE_UNKNOWN) || (DriveType == DRIVE_NO_ROOT_DIR) )
                        {
-                               *ierr = result;
+                               *_piErr = result;
                                return NULL;
                        }
                        else
@@ -174,24 +120,24 @@ static double *fileinfo_Windows(char *filepathname,int *ierr)
                                        FILEINFO_ARRAY[FILEINFO_BLOCKS_INDICE] = 0;
                                        FILEINFO_ARRAY[FILEINFO_INO_INDICE] = 0;
                                        FILEINFO_ARRAY[FILEINFO_NLINK_INDICE] = 0;
-                                       *ierr = result;
+                                       *_piErr = result;
                                }
                                else
                                {
-                                       *ierr = FILEINFO_DEFAULT_ERROR;
+                                       *_piErr = FILEINFO_DEFAULT_ERROR;
                                        return NULL;
                                }
                        }
                }
                else
                {
-                       *ierr = result;
+                       *_piErr = result;
                        return NULL;
                }
        }
        else
        {
-               FILEINFO_ARRAY = (double*)MALLOC(sizeof(double)*FILEINFO_ARRAY_SIZE);
+               FILEINFO_ARRAY = (double*)MALLOC(sizeof(double) * FILEINFO_ARRAY_SIZE);
                if (FILEINFO_ARRAY)
                {
                        FILEINFO_ARRAY[FILEINFO_TOTAL_SIZE_INDICE] = (double) buf.st_size;/* total size, in bytes */
@@ -207,11 +153,11 @@ static double *fileinfo_Windows(char *filepathname,int *ierr)
                        FILEINFO_ARRAY[FILEINFO_BLOCKS_INDICE] = 0;/* number of blocks allocated */
                        FILEINFO_ARRAY[FILEINFO_INO_INDICE] = (double) buf.st_ino;/* inode */
                        FILEINFO_ARRAY[FILEINFO_NLINK_INDICE] = (double) buf.st_nlink;/* number of hard links */
-                       *ierr = result;
+                       *_piErr = result;
                }
                else
                {
-                       *ierr = FILEINFO_DEFAULT_ERROR;
+                       *_piErr = FILEINFO_DEFAULT_ERROR;
                        return NULL;
                }
        }
@@ -219,15 +165,16 @@ static double *fileinfo_Windows(char *filepathname,int *ierr)
 }
 /*--------------------------------------------------------------------------*/
 #else
-static double *fileinfo_Others(char *filepathname,int *ierr)
+static double* fileinfo_OthersW(wchar_t* _pwstFilename, int* _piErr)
 {
        struct stat buf;
        double *FILEINFO_ARRAY = NULL;
        int result = 0;
 
-       *ierr = 0;
+       char* pstFilename = wide_string_to_UTF8(_pwstFilename);
+       *_piErr = 0;
 
-       result = stat(filepathname, &buf );
+       result = stat(pstFilename, &buf );
        if (result == 0)
        {
                FILEINFO_ARRAY = (double*)MALLOC(sizeof(double)*FILEINFO_ARRAY_SIZE);
@@ -249,11 +196,11 @@ static double *fileinfo_Others(char *filepathname,int *ierr)
                }
                else
                {
-                       *ierr = FILEINFO_DEFAULT_ERROR;
+                       *_piErr = FILEINFO_DEFAULT_ERROR;
                        return NULL;
                }
        }
-       *ierr = result;
+       *_piErr = result;
        return FILEINFO_ARRAY;
 }
 #endif
index dee4180..0ce75cd 100644 (file)
 #ifndef __FILEINFO_H__
 #define __FILEINFO_H__
 
+#include "dynlib_fileio.h"
+#include <wchar.h>
 #define FILEINFO_ARRAY_SIZE 13
 
-double * fileinfo(char *filename, int *ierr);
+#define FILEINFO_TOTAL_SIZE_INDICE 0
+#define FILEINFO_MODE_INDICE       1
+#define FILEINFO_UID_INDICE        2
+#define FILEINFO_GID_INDICE        3
+#define FILEINFO_DEV_INDICE        4
+#define FILEINFO_MTIME_INDICE      5
+#define FILEINFO_CTIME_INDICE      6
+#define FILEINFO_ATIME_INDICE      7
+#define FILEINFO_RDEV_INDICE       8
+#define FILEINFO_BLKSIZE_INDICE    9
+#define FILEINFO_BLOCKS_INDICE    10
+#define FILEINFO_INO_INDICE       11
+#define FILEINFO_NLINK_INDICE     12
 
-double * filesinfo(char **filenames, int dim_filenames, int *ierrs);
+#define FILEINFO_DEFAULT_ERROR    -1
+
+FILEIO_IMPEXP double* filesinfoW(wchar_t** _pwstFilename, int _iSize, int* _piErr);
 
 #endif /* __FILEINFO_H__ */
 /*--------------------------------------------------------------------------*/