Integrate the csv_readwrite toolbox into Scilab 67/8967/13
Sylvestre Ledru [Mon, 10 Sep 2012 07:52:40 +0000 (09:52 +0200)]
Change-Id: Iac2f0659fde14cb8cf2ef45bfc3e16d7c7e60d8b

162 files changed:
scilab/modules/core/help/en_US/variables/predefined/percentnan.xml
scilab/modules/spreadsheet/Makefile.am
scilab/modules/spreadsheet/Makefile.in
scilab/modules/spreadsheet/help/en_US/csvDefault.xml [new file with mode: 0644]
scilab/modules/spreadsheet/help/en_US/csvRead.xml [new file with mode: 0644]
scilab/modules/spreadsheet/help/en_US/csvTextscan.xml [new file with mode: 0644]
scilab/modules/spreadsheet/help/en_US/csvWrite.xml [new file with mode: 0644]
scilab/modules/spreadsheet/help/en_US/read_csv.xml
scilab/modules/spreadsheet/help/en_US/readxls.xml
scilab/modules/spreadsheet/help/en_US/write_csv.xml
scilab/modules/spreadsheet/help/en_US/xls_open.xml
scilab/modules/spreadsheet/help/en_US/xls_read.xml
scilab/modules/spreadsheet/help/ja_JP/write_csv.xml
scilab/modules/spreadsheet/help/ru_RU/write_csv.xml
scilab/modules/spreadsheet/includes/gw_spreadsheet.h
scilab/modules/spreadsheet/license.txt
scilab/modules/spreadsheet/macros/read_csv.sci [deleted file]
scilab/modules/spreadsheet/macros/write_csv.sci [deleted file]
scilab/modules/spreadsheet/sci_gateway/c/gw_spreadsheet.c
scilab/modules/spreadsheet/sci_gateway/cpp/gw_csv_helpers.cpp [new file with mode: 0644]
scilab/modules/spreadsheet/sci_gateway/cpp/gw_csv_helpers.h [new file with mode: 0644]
scilab/modules/spreadsheet/sci_gateway/cpp/gw_csv_tools.h [new file with mode: 0644]
scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvDefault.cpp [new file with mode: 0644]
scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvIsnum.cpp [new file with mode: 0644]
scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvRead.cpp [new file with mode: 0644]
scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvStringToDouble.cpp [new file with mode: 0644]
scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvTextScan.cpp [new file with mode: 0644]
scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvWrite.cpp [new file with mode: 0644]
scilab/modules/spreadsheet/sci_gateway/spreadsheet_gateway.xml
scilab/modules/spreadsheet/spreadsheet.vcxproj
scilab/modules/spreadsheet/spreadsheet.vcxproj.filters
scilab/modules/spreadsheet/src/cpp/checkCsvWriteFormat.c [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/checkCsvWriteFormat.h [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/csvDefault.c [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/csvDefault.h [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/csvIsnum.c [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/csvIsnum.h [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/csvRead.c [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/csvRead.h [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/csvWrite.c [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/csvWrite.h [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/csv_complex.c [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/csv_complex.h [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/csv_strsubst.cpp [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/csv_strsubst.h [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/getRange.c [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/getRange.h [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/latintoutf.c [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/latintoutf.h [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/splitLine.c [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/splitLine.h [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/stringToComplex.c [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/stringToComplex.h [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/stringsToDoubles.c [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/stringsToDoubles.h [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/utftolatin.c [new file with mode: 0644]
scilab/modules/spreadsheet/src/cpp/utftolatin.h [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_1.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_1.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_1.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_10556.tst
scilab/modules/spreadsheet/tests/nonreg_tests/bug_2.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_2.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_2.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_3.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_3.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_3.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_4.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_4.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_4_longline_1.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_4_longline_2.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_4_shortline_1.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_4_shortline_2.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_5.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_5.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_5.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_6.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_6.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_6734.dia.ref
scilab/modules/spreadsheet/tests/nonreg_tests/bug_6734.tst
scilab/modules/spreadsheet/tests/nonreg_tests/bug_7003.tst
scilab/modules/spreadsheet/tests/nonreg_tests/bug_8532.tst
scilab/modules/spreadsheet/tests/nonreg_tests/bug_8651.dia.ref
scilab/modules/spreadsheet/tests/nonreg_tests/bug_8651.tst
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_194.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_245.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_245.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_275.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_275.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_281.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_281.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_297.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_297.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_298.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_298.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_299.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_299.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_350.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_350.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_351.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_351.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_352.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_352.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_353.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_353.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_360.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_360.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_472.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_472.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_481.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_481.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_644.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_644.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_644.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_674.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_674.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_684.txt [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_715.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_715.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_715.txt [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_745.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_745.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/K_1.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/K_2.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/K_3.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/K_4.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/M_1.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/M_2.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/M_3.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/M_4.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/N_1.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/N_2.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/N_3.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/N_4.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/S_1.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/S_2.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/S_3.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/S_4.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/complexdata.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/csvDefault.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/csvDefault.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/csvIsnum.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/csvRead.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/csvRead.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/csvRead_regexp.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/csvRead_regexp.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/csvTextScan.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/csvTextScan.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/csvWrite.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/csvWrite.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/csv_regexp.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/csv_stringToDouble.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/csv_stringToDouble.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/csv_tools.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/csv_tools.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/data.csv [new file with mode: 0644]
scilab/modules/string/includes/pcre_private.h [moved from scilab/modules/string/src/c/pcre_private.h with 100% similarity]
scilab/modules/string/includes/stringToDouble.h
scilab/modules/string/src/c/string.vcxproj
scilab/modules/string/src/c/string.vcxproj.filters
scilab/modules/string/src/c/stringToDouble.c
scilab/modules/string/tests/unit_tests/isnum.tst

index f4483b8..b66b688 100644 (file)
@@ -27,7 +27,8 @@
     </refsection>
     <refsection>
         <title>Example</title>
-        <programlisting role="example">A = %nan
+        <programlisting role="example">
+            A = %nan
             B = %nan
             A == B
             isnan(A)
index 6d1be14..76771c7 100644 (file)
@@ -4,7 +4,20 @@
 # This file is distributed under the same license as the Scilab package.
 
 
-SPREADSHEET_C_SOURCES = src/c/xls.c
+SPREADSHEET_C_SOURCES = src/c/xls.c \
+src/cpp/checkCsvWriteFormat.c \
+src/cpp/csv_complex.c \
+src/cpp/csvDefault.c \
+src/cpp/csvIsnum.c \
+src/cpp/csvRead.c \
+src/cpp/csv_strsubst.cpp \
+src/cpp/csvWrite.c \
+src/cpp/getRange.c \
+src/cpp/latintoutf.c \
+src/cpp/splitLine.c \
+src/cpp/stringsToDoubles.c \
+src/cpp/stringToComplex.c \
+src/cpp/utftolatin.c
 
 RIPOLE_SOURCES = src/c/ripole/olestream-unwrap.c \
 src/c/ripole/pldstr.c \
@@ -19,13 +32,24 @@ GATEWAY_C_SOURCES = sci_gateway/c/gw_spreadsheet.c \
 sci_gateway/c/sci_xls_read.c \
 sci_gateway/c/sci_xls_open.c
 
+GATEWAY_CPP_SOURCES = sci_gateway/cpp/gw_csv_helpers.cpp \
+sci_gateway/cpp/sci_csvDefault.cpp \
+sci_gateway/cpp/sci_csvIsnum.cpp \
+sci_gateway/cpp/sci_csvRead.cpp \
+sci_gateway/cpp/sci_csvStringToDouble.cpp \
+sci_gateway/cpp/sci_csvTextScan.cpp \
+sci_gateway/cpp/sci_csvWrite.cpp
+
 libscispreadsheet_la_CPPFLAGS = -I$(srcdir)/includes/ \
                                -I$(srcdir)/src/c/ \
+                               -I$(srcdir)/src/cpp/ \
                                -I$(srcdir)/src/c/ripole \
                                -I$(top_srcdir)/libs/MALLOC/includes/ \
                                -I$(top_srcdir)/modules/localization/includes/ \
                                -I$(top_srcdir)/modules/output_stream/includes/ \
                                -I$(top_srcdir)/modules/io/includes/ \
+                               -I$(top_srcdir)/modules/string/src/c/ \
+                               -I$(top_srcdir)/modules/string/includes/ \
                                -I$(top_srcdir)/modules/api_scilab/includes/ \
                                -I$(top_srcdir)/modules/fileio/includes/ \
                                $(AM_CPPFLAGS)
@@ -34,8 +58,8 @@ pkglib_LTLIBRARIES = libscispreadsheet.la
 noinst_LTLIBRARIES = libscispreadsheet-algo.la
 
 
-libscispreadsheet_algo_la_SOURCES = $(SPREADSHEET_C_SOURCES) $(RIPOLE_SOURCES)
-libscispreadsheet_la_SOURCES = $(GATEWAY_C_SOURCES)
+libscispreadsheet_algo_la_SOURCES = $(SPREADSHEET_C_SOURCES) $(RIPOLE_SOURCES) $(SPREADSHEET_CPP_SOURCES)
+libscispreadsheet_la_SOURCES = $(GATEWAY_C_SOURCES) $(GATEWAY_CPP_SOURCES)
 libscispreadsheet_algo_la_CPPFLAGS = $(libscispreadsheet_la_CPPFLAGS)
 
 # For the code check (splint)
index 30bec0d..069125d 100644 (file)
@@ -133,7 +133,20 @@ am__installdirs = "$(DESTDIR)$(pkglibdir)" \
        "$(DESTDIR)$(libscispreadsheet_la_sci_gatewaydir)"
 LTLIBRARIES = $(noinst_LTLIBRARIES) $(pkglib_LTLIBRARIES)
 libscispreadsheet_algo_la_LIBADD =
-am__objects_1 = libscispreadsheet_algo_la-xls.lo
+am__objects_1 = libscispreadsheet_algo_la-xls.lo \
+       libscispreadsheet_algo_la-checkCsvWriteFormat.lo \
+       libscispreadsheet_algo_la-csv_complex.lo \
+       libscispreadsheet_algo_la-csvDefault.lo \
+       libscispreadsheet_algo_la-csvIsnum.lo \
+       libscispreadsheet_algo_la-csvRead.lo \
+       libscispreadsheet_algo_la-csv_strsubst.lo \
+       libscispreadsheet_algo_la-csvWrite.lo \
+       libscispreadsheet_algo_la-getRange.lo \
+       libscispreadsheet_algo_la-latintoutf.lo \
+       libscispreadsheet_algo_la-splitLine.lo \
+       libscispreadsheet_algo_la-stringsToDoubles.lo \
+       libscispreadsheet_algo_la-stringToComplex.lo \
+       libscispreadsheet_algo_la-utftolatin.lo
 am__objects_2 = libscispreadsheet_algo_la-olestream-unwrap.lo \
        libscispreadsheet_algo_la-pldstr.lo \
        libscispreadsheet_algo_la-ole.lo \
@@ -149,7 +162,14 @@ libscispreadsheet_la_DEPENDENCIES = libscispreadsheet-algo.la
 am__objects_3 = libscispreadsheet_la-gw_spreadsheet.lo \
        libscispreadsheet_la-sci_xls_read.lo \
        libscispreadsheet_la-sci_xls_open.lo
-am_libscispreadsheet_la_OBJECTS = $(am__objects_3)
+am__objects_4 = libscispreadsheet_la-gw_csv_helpers.lo \
+       libscispreadsheet_la-sci_csvDefault.lo \
+       libscispreadsheet_la-sci_csvIsnum.lo \
+       libscispreadsheet_la-sci_csvRead.lo \
+       libscispreadsheet_la-sci_csvStringToDouble.lo \
+       libscispreadsheet_la-sci_csvTextScan.lo \
+       libscispreadsheet_la-sci_csvWrite.lo
+am_libscispreadsheet_la_OBJECTS = $(am__objects_3) $(am__objects_4)
 libscispreadsheet_la_OBJECTS = $(am_libscispreadsheet_la_OBJECTS)
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/modules/core/includes
 depcomp = $(SHELL) $(top_srcdir)/config/depcomp
@@ -164,6 +184,15 @@ CCLD = $(CC)
 LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
        --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
        $(LDFLAGS) -o $@
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+       $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+       --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+       $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+CXXLD = $(CXX)
+CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+       --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \
+       $(LDFLAGS) -o $@
 SOURCES = $(libscispreadsheet_algo_la_SOURCES) \
        $(libscispreadsheet_la_SOURCES)
 DIST_SOURCES = $(libscispreadsheet_algo_la_SOURCES) \
@@ -431,7 +460,21 @@ target_alias = @target_alias@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
-SPREADSHEET_C_SOURCES = src/c/xls.c
+SPREADSHEET_C_SOURCES = src/c/xls.c \
+src/cpp/checkCsvWriteFormat.c \
+src/cpp/csv_complex.c \
+src/cpp/csvDefault.c \
+src/cpp/csvIsnum.c \
+src/cpp/csvRead.c \
+src/cpp/csv_strsubst.cpp \
+src/cpp/csvWrite.c \
+src/cpp/getRange.c \
+src/cpp/latintoutf.c \
+src/cpp/splitLine.c \
+src/cpp/stringsToDoubles.c \
+src/cpp/stringToComplex.c \
+src/cpp/utftolatin.c
+
 RIPOLE_SOURCES = src/c/ripole/olestream-unwrap.c \
 src/c/ripole/pldstr.c \
 src/c/ripole/ole.c \
@@ -444,21 +487,32 @@ GATEWAY_C_SOURCES = sci_gateway/c/gw_spreadsheet.c \
 sci_gateway/c/sci_xls_read.c \
 sci_gateway/c/sci_xls_open.c
 
+GATEWAY_CPP_SOURCES = sci_gateway/cpp/gw_csv_helpers.cpp \
+sci_gateway/cpp/sci_csvDefault.cpp \
+sci_gateway/cpp/sci_csvIsnum.cpp \
+sci_gateway/cpp/sci_csvRead.cpp \
+sci_gateway/cpp/sci_csvStringToDouble.cpp \
+sci_gateway/cpp/sci_csvTextScan.cpp \
+sci_gateway/cpp/sci_csvWrite.cpp
+
 libscispreadsheet_la_CPPFLAGS = -I$(srcdir)/includes/ \
                                -I$(srcdir)/src/c/ \
+                               -I$(srcdir)/src/cpp/ \
                                -I$(srcdir)/src/c/ripole \
                                -I$(top_srcdir)/libs/MALLOC/includes/ \
                                -I$(top_srcdir)/modules/localization/includes/ \
                                -I$(top_srcdir)/modules/output_stream/includes/ \
                                -I$(top_srcdir)/modules/io/includes/ \
+                               -I$(top_srcdir)/modules/string/src/c/ \
+                               -I$(top_srcdir)/modules/string/includes/ \
                                -I$(top_srcdir)/modules/api_scilab/includes/ \
                                -I$(top_srcdir)/modules/fileio/includes/ \
                                $(AM_CPPFLAGS)
 
 pkglib_LTLIBRARIES = libscispreadsheet.la
 noinst_LTLIBRARIES = libscispreadsheet-algo.la
-libscispreadsheet_algo_la_SOURCES = $(SPREADSHEET_C_SOURCES) $(RIPOLE_SOURCES)
-libscispreadsheet_la_SOURCES = $(GATEWAY_C_SOURCES)
+libscispreadsheet_algo_la_SOURCES = $(SPREADSHEET_C_SOURCES) $(RIPOLE_SOURCES) $(SPREADSHEET_CPP_SOURCES)
+libscispreadsheet_la_SOURCES = $(GATEWAY_C_SOURCES) $(GATEWAY_CPP_SOURCES)
 libscispreadsheet_algo_la_CPPFLAGS = $(libscispreadsheet_la_CPPFLAGS)
 
 # For the code check (splint)
@@ -556,7 +610,7 @@ HELP_CHAPTERLANG = en_US fr_FR pt_BR
 all: all-am
 
 .SUFFIXES:
-.SUFFIXES: .sci .bin .c .lo .o .obj
+.SUFFIXES: .sci .bin .c .cpp .lo .o .obj
 $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir)/Makefile.incl.am $(am__configure_deps)
        @for dep in $?; do \
          case '$(am__configure_deps)' in \
@@ -630,9 +684,9 @@ clean-pkglibLTLIBRARIES:
          rm -f "$${dir}/so_locations"; \
        done
 libscispreadsheet-algo.la: $(libscispreadsheet_algo_la_OBJECTS) $(libscispreadsheet_algo_la_DEPENDENCIES) $(EXTRA_libscispreadsheet_algo_la_DEPENDENCIES) 
-       $(LINK)  $(libscispreadsheet_algo_la_OBJECTS) $(libscispreadsheet_algo_la_LIBADD) $(LIBS)
+       $(CXXLINK)  $(libscispreadsheet_algo_la_OBJECTS) $(libscispreadsheet_algo_la_LIBADD) $(LIBS)
 libscispreadsheet.la: $(libscispreadsheet_la_OBJECTS) $(libscispreadsheet_la_DEPENDENCIES) $(EXTRA_libscispreadsheet_la_DEPENDENCIES) 
-       $(LINK) -rpath $(pkglibdir) $(libscispreadsheet_la_OBJECTS) $(libscispreadsheet_la_LIBADD) $(LIBS)
+       $(CXXLINK) -rpath $(pkglibdir) $(libscispreadsheet_la_OBJECTS) $(libscispreadsheet_la_LIBADD) $(LIBS)
 
 mostlyclean-compile:
        -rm -f *.$(OBJEXT)
@@ -642,13 +696,33 @@ distclean-compile:
 
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-bt-int.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-bytedecoders.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-checkCsvWriteFormat.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-csv_complex.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-csvDefault.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-csvIsnum.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-csvRead.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-csv_strsubst.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-csvWrite.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-getRange.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-latintoutf.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-logger.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-ole.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-olestream-unwrap.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-pldstr.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-ripole.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-splitLine.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-stringToComplex.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-stringsToDoubles.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-utftolatin.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-xls.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_la-gw_csv_helpers.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_la-gw_spreadsheet.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_la-sci_csvDefault.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_la-sci_csvIsnum.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_la-sci_csvRead.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_la-sci_csvStringToDouble.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_la-sci_csvTextScan.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_la-sci_csvWrite.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_la-sci_xls_open.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_la-sci_xls_read.Plo@am__quote@
 
@@ -680,6 +754,90 @@ libscispreadsheet_algo_la-xls.lo: src/c/xls.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) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libscispreadsheet_algo_la-xls.lo `test -f 'src/c/xls.c' || echo '$(srcdir)/'`src/c/xls.c
 
+libscispreadsheet_algo_la-checkCsvWriteFormat.lo: src/cpp/checkCsvWriteFormat.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libscispreadsheet_algo_la-checkCsvWriteFormat.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_algo_la-checkCsvWriteFormat.Tpo -c -o libscispreadsheet_algo_la-checkCsvWriteFormat.lo `test -f 'src/cpp/checkCsvWriteFormat.c' || echo '$(srcdir)/'`src/cpp/checkCsvWriteFormat.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscispreadsheet_algo_la-checkCsvWriteFormat.Tpo $(DEPDIR)/libscispreadsheet_algo_la-checkCsvWriteFormat.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='src/cpp/checkCsvWriteFormat.c' object='libscispreadsheet_algo_la-checkCsvWriteFormat.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) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libscispreadsheet_algo_la-checkCsvWriteFormat.lo `test -f 'src/cpp/checkCsvWriteFormat.c' || echo '$(srcdir)/'`src/cpp/checkCsvWriteFormat.c
+
+libscispreadsheet_algo_la-csv_complex.lo: src/cpp/csv_complex.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libscispreadsheet_algo_la-csv_complex.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_algo_la-csv_complex.Tpo -c -o libscispreadsheet_algo_la-csv_complex.lo `test -f 'src/cpp/csv_complex.c' || echo '$(srcdir)/'`src/cpp/csv_complex.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscispreadsheet_algo_la-csv_complex.Tpo $(DEPDIR)/libscispreadsheet_algo_la-csv_complex.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='src/cpp/csv_complex.c' object='libscispreadsheet_algo_la-csv_complex.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) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libscispreadsheet_algo_la-csv_complex.lo `test -f 'src/cpp/csv_complex.c' || echo '$(srcdir)/'`src/cpp/csv_complex.c
+
+libscispreadsheet_algo_la-csvDefault.lo: src/cpp/csvDefault.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libscispreadsheet_algo_la-csvDefault.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_algo_la-csvDefault.Tpo -c -o libscispreadsheet_algo_la-csvDefault.lo `test -f 'src/cpp/csvDefault.c' || echo '$(srcdir)/'`src/cpp/csvDefault.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscispreadsheet_algo_la-csvDefault.Tpo $(DEPDIR)/libscispreadsheet_algo_la-csvDefault.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='src/cpp/csvDefault.c' object='libscispreadsheet_algo_la-csvDefault.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) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libscispreadsheet_algo_la-csvDefault.lo `test -f 'src/cpp/csvDefault.c' || echo '$(srcdir)/'`src/cpp/csvDefault.c
+
+libscispreadsheet_algo_la-csvIsnum.lo: src/cpp/csvIsnum.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libscispreadsheet_algo_la-csvIsnum.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_algo_la-csvIsnum.Tpo -c -o libscispreadsheet_algo_la-csvIsnum.lo `test -f 'src/cpp/csvIsnum.c' || echo '$(srcdir)/'`src/cpp/csvIsnum.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscispreadsheet_algo_la-csvIsnum.Tpo $(DEPDIR)/libscispreadsheet_algo_la-csvIsnum.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='src/cpp/csvIsnum.c' object='libscispreadsheet_algo_la-csvIsnum.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) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libscispreadsheet_algo_la-csvIsnum.lo `test -f 'src/cpp/csvIsnum.c' || echo '$(srcdir)/'`src/cpp/csvIsnum.c
+
+libscispreadsheet_algo_la-csvRead.lo: src/cpp/csvRead.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libscispreadsheet_algo_la-csvRead.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_algo_la-csvRead.Tpo -c -o libscispreadsheet_algo_la-csvRead.lo `test -f 'src/cpp/csvRead.c' || echo '$(srcdir)/'`src/cpp/csvRead.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscispreadsheet_algo_la-csvRead.Tpo $(DEPDIR)/libscispreadsheet_algo_la-csvRead.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='src/cpp/csvRead.c' object='libscispreadsheet_algo_la-csvRead.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) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libscispreadsheet_algo_la-csvRead.lo `test -f 'src/cpp/csvRead.c' || echo '$(srcdir)/'`src/cpp/csvRead.c
+
+libscispreadsheet_algo_la-csvWrite.lo: src/cpp/csvWrite.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libscispreadsheet_algo_la-csvWrite.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_algo_la-csvWrite.Tpo -c -o libscispreadsheet_algo_la-csvWrite.lo `test -f 'src/cpp/csvWrite.c' || echo '$(srcdir)/'`src/cpp/csvWrite.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscispreadsheet_algo_la-csvWrite.Tpo $(DEPDIR)/libscispreadsheet_algo_la-csvWrite.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='src/cpp/csvWrite.c' object='libscispreadsheet_algo_la-csvWrite.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) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libscispreadsheet_algo_la-csvWrite.lo `test -f 'src/cpp/csvWrite.c' || echo '$(srcdir)/'`src/cpp/csvWrite.c
+
+libscispreadsheet_algo_la-getRange.lo: src/cpp/getRange.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libscispreadsheet_algo_la-getRange.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_algo_la-getRange.Tpo -c -o libscispreadsheet_algo_la-getRange.lo `test -f 'src/cpp/getRange.c' || echo '$(srcdir)/'`src/cpp/getRange.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscispreadsheet_algo_la-getRange.Tpo $(DEPDIR)/libscispreadsheet_algo_la-getRange.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='src/cpp/getRange.c' object='libscispreadsheet_algo_la-getRange.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) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libscispreadsheet_algo_la-getRange.lo `test -f 'src/cpp/getRange.c' || echo '$(srcdir)/'`src/cpp/getRange.c
+
+libscispreadsheet_algo_la-latintoutf.lo: src/cpp/latintoutf.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libscispreadsheet_algo_la-latintoutf.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_algo_la-latintoutf.Tpo -c -o libscispreadsheet_algo_la-latintoutf.lo `test -f 'src/cpp/latintoutf.c' || echo '$(srcdir)/'`src/cpp/latintoutf.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscispreadsheet_algo_la-latintoutf.Tpo $(DEPDIR)/libscispreadsheet_algo_la-latintoutf.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='src/cpp/latintoutf.c' object='libscispreadsheet_algo_la-latintoutf.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) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libscispreadsheet_algo_la-latintoutf.lo `test -f 'src/cpp/latintoutf.c' || echo '$(srcdir)/'`src/cpp/latintoutf.c
+
+libscispreadsheet_algo_la-splitLine.lo: src/cpp/splitLine.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libscispreadsheet_algo_la-splitLine.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_algo_la-splitLine.Tpo -c -o libscispreadsheet_algo_la-splitLine.lo `test -f 'src/cpp/splitLine.c' || echo '$(srcdir)/'`src/cpp/splitLine.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscispreadsheet_algo_la-splitLine.Tpo $(DEPDIR)/libscispreadsheet_algo_la-splitLine.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='src/cpp/splitLine.c' object='libscispreadsheet_algo_la-splitLine.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) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libscispreadsheet_algo_la-splitLine.lo `test -f 'src/cpp/splitLine.c' || echo '$(srcdir)/'`src/cpp/splitLine.c
+
+libscispreadsheet_algo_la-stringsToDoubles.lo: src/cpp/stringsToDoubles.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libscispreadsheet_algo_la-stringsToDoubles.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_algo_la-stringsToDoubles.Tpo -c -o libscispreadsheet_algo_la-stringsToDoubles.lo `test -f 'src/cpp/stringsToDoubles.c' || echo '$(srcdir)/'`src/cpp/stringsToDoubles.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscispreadsheet_algo_la-stringsToDoubles.Tpo $(DEPDIR)/libscispreadsheet_algo_la-stringsToDoubles.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='src/cpp/stringsToDoubles.c' object='libscispreadsheet_algo_la-stringsToDoubles.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) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libscispreadsheet_algo_la-stringsToDoubles.lo `test -f 'src/cpp/stringsToDoubles.c' || echo '$(srcdir)/'`src/cpp/stringsToDoubles.c
+
+libscispreadsheet_algo_la-stringToComplex.lo: src/cpp/stringToComplex.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libscispreadsheet_algo_la-stringToComplex.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_algo_la-stringToComplex.Tpo -c -o libscispreadsheet_algo_la-stringToComplex.lo `test -f 'src/cpp/stringToComplex.c' || echo '$(srcdir)/'`src/cpp/stringToComplex.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscispreadsheet_algo_la-stringToComplex.Tpo $(DEPDIR)/libscispreadsheet_algo_la-stringToComplex.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='src/cpp/stringToComplex.c' object='libscispreadsheet_algo_la-stringToComplex.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) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libscispreadsheet_algo_la-stringToComplex.lo `test -f 'src/cpp/stringToComplex.c' || echo '$(srcdir)/'`src/cpp/stringToComplex.c
+
+libscispreadsheet_algo_la-utftolatin.lo: src/cpp/utftolatin.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libscispreadsheet_algo_la-utftolatin.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_algo_la-utftolatin.Tpo -c -o libscispreadsheet_algo_la-utftolatin.lo `test -f 'src/cpp/utftolatin.c' || echo '$(srcdir)/'`src/cpp/utftolatin.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscispreadsheet_algo_la-utftolatin.Tpo $(DEPDIR)/libscispreadsheet_algo_la-utftolatin.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='src/cpp/utftolatin.c' object='libscispreadsheet_algo_la-utftolatin.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) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libscispreadsheet_algo_la-utftolatin.lo `test -f 'src/cpp/utftolatin.c' || echo '$(srcdir)/'`src/cpp/utftolatin.c
+
 libscispreadsheet_algo_la-olestream-unwrap.lo: src/c/ripole/olestream-unwrap.c
 @am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libscispreadsheet_algo_la-olestream-unwrap.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_algo_la-olestream-unwrap.Tpo -c -o libscispreadsheet_algo_la-olestream-unwrap.lo `test -f 'src/c/ripole/olestream-unwrap.c' || echo '$(srcdir)/'`src/c/ripole/olestream-unwrap.c
 @am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscispreadsheet_algo_la-olestream-unwrap.Tpo $(DEPDIR)/libscispreadsheet_algo_la-olestream-unwrap.Plo
@@ -750,6 +908,83 @@ libscispreadsheet_la-sci_xls_open.lo: sci_gateway/c/sci_xls_open.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) $(libscispreadsheet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libscispreadsheet_la-sci_xls_open.lo `test -f 'sci_gateway/c/sci_xls_open.c' || echo '$(srcdir)/'`sci_gateway/c/sci_xls_open.c
 
+.cpp.o:
+@am__fastdepCXX_TRUE@  $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $<
+
+.cpp.obj:
+@am__fastdepCXX_TRUE@  $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.cpp.lo:
+@am__fastdepCXX_TRUE@  $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $<
+
+libscispreadsheet_algo_la-csv_strsubst.lo: src/cpp/csv_strsubst.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscispreadsheet_algo_la-csv_strsubst.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_algo_la-csv_strsubst.Tpo -c -o libscispreadsheet_algo_la-csv_strsubst.lo `test -f 'src/cpp/csv_strsubst.cpp' || echo '$(srcdir)/'`src/cpp/csv_strsubst.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscispreadsheet_algo_la-csv_strsubst.Tpo $(DEPDIR)/libscispreadsheet_algo_la-csv_strsubst.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='src/cpp/csv_strsubst.cpp' object='libscispreadsheet_algo_la-csv_strsubst.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) $(libscispreadsheet_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscispreadsheet_algo_la-csv_strsubst.lo `test -f 'src/cpp/csv_strsubst.cpp' || echo '$(srcdir)/'`src/cpp/csv_strsubst.cpp
+
+libscispreadsheet_la-gw_csv_helpers.lo: sci_gateway/cpp/gw_csv_helpers.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscispreadsheet_la-gw_csv_helpers.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_la-gw_csv_helpers.Tpo -c -o libscispreadsheet_la-gw_csv_helpers.lo `test -f 'sci_gateway/cpp/gw_csv_helpers.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/gw_csv_helpers.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscispreadsheet_la-gw_csv_helpers.Tpo $(DEPDIR)/libscispreadsheet_la-gw_csv_helpers.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/gw_csv_helpers.cpp' object='libscispreadsheet_la-gw_csv_helpers.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) $(libscispreadsheet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscispreadsheet_la-gw_csv_helpers.lo `test -f 'sci_gateway/cpp/gw_csv_helpers.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/gw_csv_helpers.cpp
+
+libscispreadsheet_la-sci_csvDefault.lo: sci_gateway/cpp/sci_csvDefault.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscispreadsheet_la-sci_csvDefault.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_la-sci_csvDefault.Tpo -c -o libscispreadsheet_la-sci_csvDefault.lo `test -f 'sci_gateway/cpp/sci_csvDefault.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_csvDefault.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscispreadsheet_la-sci_csvDefault.Tpo $(DEPDIR)/libscispreadsheet_la-sci_csvDefault.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_csvDefault.cpp' object='libscispreadsheet_la-sci_csvDefault.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) $(libscispreadsheet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscispreadsheet_la-sci_csvDefault.lo `test -f 'sci_gateway/cpp/sci_csvDefault.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_csvDefault.cpp
+
+libscispreadsheet_la-sci_csvIsnum.lo: sci_gateway/cpp/sci_csvIsnum.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscispreadsheet_la-sci_csvIsnum.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_la-sci_csvIsnum.Tpo -c -o libscispreadsheet_la-sci_csvIsnum.lo `test -f 'sci_gateway/cpp/sci_csvIsnum.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_csvIsnum.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscispreadsheet_la-sci_csvIsnum.Tpo $(DEPDIR)/libscispreadsheet_la-sci_csvIsnum.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_csvIsnum.cpp' object='libscispreadsheet_la-sci_csvIsnum.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) $(libscispreadsheet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscispreadsheet_la-sci_csvIsnum.lo `test -f 'sci_gateway/cpp/sci_csvIsnum.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_csvIsnum.cpp
+
+libscispreadsheet_la-sci_csvRead.lo: sci_gateway/cpp/sci_csvRead.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscispreadsheet_la-sci_csvRead.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_la-sci_csvRead.Tpo -c -o libscispreadsheet_la-sci_csvRead.lo `test -f 'sci_gateway/cpp/sci_csvRead.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_csvRead.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscispreadsheet_la-sci_csvRead.Tpo $(DEPDIR)/libscispreadsheet_la-sci_csvRead.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_csvRead.cpp' object='libscispreadsheet_la-sci_csvRead.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) $(libscispreadsheet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscispreadsheet_la-sci_csvRead.lo `test -f 'sci_gateway/cpp/sci_csvRead.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_csvRead.cpp
+
+libscispreadsheet_la-sci_csvStringToDouble.lo: sci_gateway/cpp/sci_csvStringToDouble.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscispreadsheet_la-sci_csvStringToDouble.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_la-sci_csvStringToDouble.Tpo -c -o libscispreadsheet_la-sci_csvStringToDouble.lo `test -f 'sci_gateway/cpp/sci_csvStringToDouble.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_csvStringToDouble.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscispreadsheet_la-sci_csvStringToDouble.Tpo $(DEPDIR)/libscispreadsheet_la-sci_csvStringToDouble.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_csvStringToDouble.cpp' object='libscispreadsheet_la-sci_csvStringToDouble.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) $(libscispreadsheet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscispreadsheet_la-sci_csvStringToDouble.lo `test -f 'sci_gateway/cpp/sci_csvStringToDouble.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_csvStringToDouble.cpp
+
+libscispreadsheet_la-sci_csvTextScan.lo: sci_gateway/cpp/sci_csvTextScan.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscispreadsheet_la-sci_csvTextScan.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_la-sci_csvTextScan.Tpo -c -o libscispreadsheet_la-sci_csvTextScan.lo `test -f 'sci_gateway/cpp/sci_csvTextScan.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_csvTextScan.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscispreadsheet_la-sci_csvTextScan.Tpo $(DEPDIR)/libscispreadsheet_la-sci_csvTextScan.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_csvTextScan.cpp' object='libscispreadsheet_la-sci_csvTextScan.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) $(libscispreadsheet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscispreadsheet_la-sci_csvTextScan.lo `test -f 'sci_gateway/cpp/sci_csvTextScan.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_csvTextScan.cpp
+
+libscispreadsheet_la-sci_csvWrite.lo: sci_gateway/cpp/sci_csvWrite.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscispreadsheet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscispreadsheet_la-sci_csvWrite.lo -MD -MP -MF $(DEPDIR)/libscispreadsheet_la-sci_csvWrite.Tpo -c -o libscispreadsheet_la-sci_csvWrite.lo `test -f 'sci_gateway/cpp/sci_csvWrite.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_csvWrite.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscispreadsheet_la-sci_csvWrite.Tpo $(DEPDIR)/libscispreadsheet_la-sci_csvWrite.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_csvWrite.cpp' object='libscispreadsheet_la-sci_csvWrite.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) $(libscispreadsheet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscispreadsheet_la-sci_csvWrite.lo `test -f 'sci_gateway/cpp/sci_csvWrite.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_csvWrite.cpp
+
 mostlyclean-libtool:
        -rm -f *.lo
 
diff --git a/scilab/modules/spreadsheet/help/en_US/csvDefault.xml b/scilab/modules/spreadsheet/help/en_US/csvDefault.xml
new file mode 100644 (file)
index 0000000..0decfb7
--- /dev/null
@@ -0,0 +1,236 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Copyright (C) 2010-2011 - INRIA - Allan CORNET
+ * Copyright (C) 2011 - INRIA - Michael Baudin
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ -->
+<refentry version="5.0-subset Scilab" xml:id="csvDefault" xml:lang="en"
+          xmlns="http://docbook.org/ns/docbook"
+          xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg"
+          xmlns:ns3="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML"
+          xmlns:db="http://docbook.org/ns/docbook">
+    <refnamediv>
+        <refname>csvDefault</refname>
+        
+        <refpurpose>Get or set defaults for csv files.</refpurpose>
+    </refnamediv>
+    
+    <refsynopsisdiv>
+        <title>Calling Sequence</title>
+        
+        <synopsis>allvalues = csvDefault() </synopsis>
+        
+        <synopsis>value = csvDefault(field) </synopsis>
+        
+        <synopsis>bRes = csvDefault(field, value) </synopsis>
+    </refsynopsisdiv>
+    
+    <refsection>
+        <title>Parameters</title>
+        
+        <variablelist>
+            <varlistentry>
+                <term>allvalues</term>
+                
+                <listitem>
+                    <para>a 6-by-2 matrix of strings, the values of all the fields. The
+                        first column contains the available fields, while the second column
+                        contains the current values.
+                    </para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>field</term>
+                
+                <listitem>
+                    <para>a 1-by-1 matrix of strings, the name of the field to get or
+                        set. The available values of <literal>field</literal> are
+                        "separator", "decimal", "conversion", "precision", "regexp", "eol",
+                        "encoding", "blank".
+                    </para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>value</term>
+                
+                <listitem>
+                    <para>a 1-by-1 matrix of strings, the value of the field to get or
+                        set.
+                    </para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>bRes</term>
+                
+                <listitem>
+                    <para>a 1-by-1 matrix of booleans, bRes is true if the value was
+                        correctly set, bRes is wrong is the value was not correct.
+                    </para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    
+    <refsection>
+        <title>Description</title>
+        
+        <para>This function allows to quiery or configure the options of the csv
+            files. These options are used by the read and write function when the user
+            does not specify them in the calling sequence.
+        </para>
+        
+        <para>
+            The <literal>allvalues = csvDefault()</literal> calling sequence
+            returns the value of all the fields.
+        </para>
+        
+        <para>
+            The <literal>value = csvDefault(field)</literal> calling sequence
+            returns the value corresponding to the given field.
+        </para>
+        
+        <para>
+            The <literal>bRes = csvDefault(field, value)</literal> calling
+            sequence allows to set the value of the given field. <itemizedlist>
+                <listitem>
+                    <para>If the function cannot set the field to the given value, then
+                        <literal>bRes</literal> is false. In this case, the value of the
+                        field is unchanged.
+                    </para>
+                </listitem>
+                
+                <listitem>
+                    <para>If the function is able to change the field to the given
+                        value, then <literal>bRes</literal> is true.
+                    </para>
+                </listitem>
+            </itemizedlist>
+        </para>
+        
+        <para>The available fields are the following. <itemizedlist>
+                <listitem>
+                    <para>field = "separator": the separator of the columns of the csv
+                        files. Default separator = ",".
+                    </para>
+                </listitem>
+                
+                <listitem>
+                    <para>field = "decimal": the decimal point used in the csv files.
+                        The available values are "." or ",". Default decimal = ".".
+                    </para>
+                </listitem>
+                
+                <listitem>
+                    <para>field = "conversion": the type of the output of the
+                        <literal>csvRead</literal>function. Possible values are "string" or
+                        "double". Default conversion = "double". If conversion = "string",
+                        then the <literal>csvRead</literal> function returns a matrix of
+                        strings. If conversion = "double", then the
+                        <literal>csvRead</literal> function returns a matrix of
+                        doubles.
+                    </para>
+                </listitem>
+                
+                <listitem>
+                    <para>field = "precision": the C format used to create the strings
+                        from the doubles in the <literal>csvWrite</literal> function. The
+                        default value is <literal>precision="%.17lg"</literal>. This format
+                        allows to perform write-read error-free cycles. This means that we
+                        can save a double into a .csv, then read the double and get the
+                        exact same value. The supported format is: %type or
+                        %[width].[precision]type. <itemizedlist>
+                            <listitem>
+                                <para>type: lf, lg, d, i, e, f, g</para>
+                            </listitem>
+                            
+                            <listitem>
+                                <para>width: Optional number that specifies the minimum number
+                                    of characters output.
+                                </para>
+                            </listitem>
+                            
+                            <listitem>
+                                <para>precision: Optional number that specifies the maximum
+                                    number of characters printed for all or part of the output
+                                    field, or the minimum number of digits printed for integer
+                                    values.
+                                </para>
+                            </listitem>
+                        </itemizedlist>
+                    </para>
+                </listitem>
+                
+                <listitem>
+                    <para>field = "regexp": regular expression used to extract comments
+                        of the <literal>csvRead</literal>function.
+                    </para>
+                    
+                    <para>by default, this value is '' (no regexp).</para>
+                </listitem>
+                
+                <listitem>
+                    <para>field = "eol": end of line used to write lines of the
+                        <literal>csvWrite</literal>function.
+                    </para>
+                    
+                    <para>Possible values are "linux", "windows", "macos9".</para>
+                    
+                    <para>by default, this value is platform-dependant.</para>
+                </listitem>
+                
+                <listitem>
+                    <para>field = "encoding":</para>
+                    
+                    <para>Possible values are "utf-8", "iso-latin".</para>
+                    
+                    <para>by default, this value is "utf-8".</para>
+                </listitem>
+                
+                <listitem>
+                    <para>field = "blank": remove all blank lines before to parse
+                        text
+                    </para>
+                    
+                    <para>Possible values are "on", "off".</para>
+                    
+                    <para>by default, this value is "off".</para>
+                </listitem>
+            </itemizedlist>
+        </para>
+    </refsection>
+    
+    <refsection>
+        <title>Examples</title>
+        
+        <programlisting role="example">// See all the available fields
+            allvalues = csvDefault()
+            // Get the value of the "precision" field
+            value = csvDefault("precision")
+            // Set the value of the "precision" field
+            bRes = csvDefault("precision","%.17e") // Expected = %t
+            // Set the value of the "precision" field to 
+            // an impossible value
+            bRes = csvDefault("precision","Ouch!") // Expected = %f    
+        </programlisting>
+    </refsection>
+    
+    <refsection>
+        <title>See Also</title>
+        
+        <simplelist type="inline">
+            <member>
+                <link linkend="csvRead">csvRead</link>
+            </member>
+            
+            <member>
+                <link linkend="csvWrite">csvWrite</link>
+            </member>
+        </simplelist>
+    </refsection>
+</refentry>
+
diff --git a/scilab/modules/spreadsheet/help/en_US/csvRead.xml b/scilab/modules/spreadsheet/help/en_US/csvRead.xml
new file mode 100644 (file)
index 0000000..3a6c12d
--- /dev/null
@@ -0,0 +1,377 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Copyright (C) 2010-2011 - INRIA - Allan CORNET
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ -->
+<refentry version="5.0-subset Scilab" xml:id="csvRead" xml:lang="en"
+          xmlns="http://docbook.org/ns/docbook"
+          xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg"
+          xmlns:ns3="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML"
+          xmlns:db="http://docbook.org/ns/docbook">
+    <info>
+        <pubdate>$LastChangedDate$</pubdate>
+    </info>
+    
+    <refnamediv>
+        <refname>csvRead</refname>
+        
+        <refpurpose>Read comma-separated value file</refpurpose>
+    </refnamediv>
+    
+    <refsynopsisdiv>
+        <title>Calling Sequence</title>
+        
+        <synopsis>
+            M = csvRead(filename)
+            M = csvRead(filename, separator)
+            M = csvRead(filename, separator, decimal)
+            M = csvRead(filename, separator, decimal, conversion)
+            M = csvRead(filename, separator, decimal, conversion, substitute)
+            M = csvRead(filename, separator, decimal, conversion, substitute, rexgepcomments, range)
+            [M, comments] = csvRead(filename, separator, decimal, conversion, substitute, rexgepcomments, range)
+        </synopsis>
+    </refsynopsisdiv>
+    
+    <refsection>
+        <title>Parameters</title>
+        
+        <variablelist>
+            <varlistentry>
+                <term>filename</term>
+                
+                <listitem>
+                    <para>a 1-by-1 matrix of strings, the file path.</para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>separator</term>
+                
+                <listitem>
+                    <para>a 1-by-1 matrix of strings, the field separator used.</para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>decimal</term>
+                
+                <listitem>
+                    <para>a 1-by-1 matrix of strings, the decimal used.</para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>conversion</term>
+                
+                <listitem>
+                    <para>a 1-by-1 matrix of strings, the type of the output
+                        <literal>M</literal>. Available values are "string" or "double"
+                        (default).
+                    </para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>substitute</term>
+                
+                <listitem>
+                    <para>a m-by-2 matrix of strings, a replacing map (default = [],
+                        meaning no replacements). The first column
+                        <literal>substitute(:,1)</literal> contains the searched strings and
+                        the second column <literal>substitute(:,2)</literal> contains the
+                        replace strings. Every occurence of a searched string in the file is
+                        replaced.
+                    </para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>rexgepcomments</term>
+                
+                <listitem>
+                    <para>a string: a regexp to remove lines which match. (default:
+                        [])
+                    </para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>range</term>
+                
+                <listitem>
+                    <para>a 1-by-4 matrix of floating point integers, the range of rows
+                        and columns which must be read (default range=[], meaning that all
+                        the rows and columns). Specify range using the format <literal>[R1
+                            C1 R2 C2]
+                        </literal>
+                        where (R1,C1) is the upper left corner of the
+                        data to be read and (R2,C2) is the lower right corner.
+                    </para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>M</term>
+                
+                <listitem>
+                    <para>a m-by-n matrix of strings or double.</para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>comments</term>
+                
+                <listitem>
+                    <para>a m-by-n matrix of strings matched by regexp.</para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    
+    <refsection>
+        <title>Description</title>
+        
+        <para>Given an ascii file with comma separated values delimited fields,
+            this function returns the corresponding Scilab matrix of strings or
+            doubles.
+        </para>
+        
+        <para>For example, the .csv data file may have been created by a
+            spreadsheet software using "Text and comma" format.
+        </para>
+        
+        <para>It might happen that the columns are separated by a non-comma
+            separator. In this case, use csvRead(filename, separator) for another
+            choice of separator.
+        </para>
+        
+        <para>The default value of the optional input arguments are defined by the
+            <literal>csvDefault</literal> function.
+        </para>
+        
+        <para>Any optional input argument equal to the empty matrix
+            <literal>[]</literal> is set to its default value.
+        </para>
+        
+        <para>When the input argument "conversion" is equal to "double", the
+            non-numeric fields within the .csv (e.g. strings) are converted into
+            NaN.
+        </para>
+    </refsection>
+    
+    <refsection>
+        <title>Examples</title>
+        
+        <para>The following script presents some basic uses of the
+            <literal>csvRead</literal> function.
+        </para>
+        
+        <programlisting role="example">// Create a file with some data separated with tabs.
+            M = 1:50;
+            filename = fullfile(TMPDIR, "data.csv");
+            csvWrite(M, filename, ascii(9), '.');
+            
+            // read csv file
+            M1 = csvRead(filename,ascii(9), [], 'string')
+            
+            // Returns a double
+            M2 = csvRead(filename,ascii(9), '.', 'double')
+            
+            // Compares original data and result.
+            and(M == M2)
+            
+            // Use the substitude argument to manage
+            // special data files.
+            content = [
+            "1"
+            "Not-A-Number"
+            "2"
+            "Not-A-Number"
+            ];
+            
+            substitute = [
+            "Not-A-Number" "Nan"
+            ];
+            
+            mputl(content,filename);
+            M = csvRead(filename,",",".","double",substitute)
+            isnan(M(2,1)) // Expected=%t
+            isnan(M(4,1)) // Expected=%t
+            
+        </programlisting>
+        
+        <para>The following script presents more practical uses of the
+            <literal>csvRead</literal> function.
+        </para>
+        
+        <programlisting role="example">// Define a matrix of strings
+            Astr = [
+            "1" "8" "15" "22" "29" "36" "43" "50"
+            "2" "9" "16" "23" "30" "37" "44" "51"
+            "3" "10" "17" "6+3*I" "31" "38" "45" "52"
+            "4" "11" "18" "25" "32" "39" "46" "53"
+            "5" "12" "19" "26" "33" "40" "47" "54"
+            "6" "13" "20" "27" "34" "41" "48" "55"
+            "+0" "-0" "Inf" "-Inf" "Nan" "1.D+308" "1.e-308" "1.e-323"
+            ];
+            
+            // Create a file with some data separated with commas
+            filename = fullfile(TMPDIR , 'foo.csv');
+            sep = ",";
+            fd = mopen(filename,'wt');
+            for i = 1 : size(Astr,"r")
+            mfprintf(fd,"%s\n",strcat(Astr(i,:),sep));
+            end
+            mclose(fd);
+            // To see the file : edit(filename)
+            
+            // Read this file
+            Bstr = csvRead ( filename )
+            
+            // Create a file with a particular separator: here ";"
+            filename = fullfile(TMPDIR , 'foo.csv');
+            sep = ";";
+            fd = mopen(filename,'wt');
+            for i = 1 : size(Astr,"r")
+            mfprintf(fd,"%s\n",strcat(Astr(i,:),sep));
+            end
+            mclose(fd);
+            
+            //
+            // Read the file and customize the separator
+            csvRead ( filename , sep )   
+        </programlisting>
+        
+        <para>The following script shows how to remove lines with regexp argument
+            of the <literal>csvRead</literal> function.
+        </para>
+        
+        <programlisting role="example">CSV = ["// tata"; ..
+            "1,0,0,0,0"; ..
+            "// titi"; ..
+            "0,1,0,0,0"; ..
+            "// toto"; ..
+            "0,0,1,0,0"; ..
+            "// tutu"];
+            filename = fullfile(TMPDIR , 'foo.csv');
+            mputl(CSV, filename);
+            
+            // remove lines with // @ beginning
+            [M, comments] = csvRead(filename, [], [], [], [], '/\/\//')
+        </programlisting>
+    </refsection>
+    
+    <refsection>
+        <para>Empty field are managed by csvRead</para>
+        
+        <programlisting role="example">
+            csvWrite(['1','','3';'','','6'], TMPDIR + "/example.csv")
+            csvRead(TMPDIR + "/example.csv", [], [], "string")
+            csvRead(TMPDIR + "/example.csv", [], [], "double")
+        </programlisting>
+    </refsection>
+    
+    <programlisting role="example">
+        // Define a matrix of strings
+        Astr = [
+        "1" "8" "15" "22" "29" "36" "43" "50"
+        "2" "9" "16" "23" "30" "37" "44" "51"
+        "3" "10" "17" "6+3*I" "31" "38" "45" "52"
+        "4" "11" "18" "25" "32" "39" "46" "53"
+        "5" "12" "19" "26" "33" "40" "47" "54"
+        "6" "13" "20" "27" "34" "41" "48" "55"
+        "+0" "-0" "Inf" "-Inf" "Nan" "1.D+308" "1.e-308" "1.e-323"
+        ];
+        
+        // Create a file with some data separated with commas
+        filename = fullfile(TMPDIR , 'foo.csv');
+        sep = ",";
+        fd = mopen(filename,'wt');
+        for i = 1 : size(Astr,"r")
+        mfprintf(fd,"%s\n",strcat(Astr(i,:),sep));
+        end
+        mclose(fd);
+        // To see the file : edit(filename)
+        
+        // Read this file
+        Bstr = csvRead ( filename )
+        
+        // Create a file with a particular separator: here ";"
+        filename = fullfile(TMPDIR , 'foo.csv');
+        sep = ";";
+        fd = mopen(filename,'wt');
+        for i = 1 : size(Astr,"r")
+        mfprintf(fd,"%s\n",strcat(Astr(i,:),sep));
+        end
+        mclose(fd);
+        //
+        // Read the file and customize the separator
+        csvRead ( filename , sep )
+    </programlisting>
+    
+    <refsection>
+        <para>In the following script, the file "filename" is read by blocks of
+            5000 rows. The algorithm stops when the number of rows actually read from
+            the file differ from 5000, i.e. when the end of the file has been
+            reached.
+        </para>
+        
+        <programlisting role="example">blocksize = 5000;
+            C1 = 1;
+            C2 = 3;
+            iblock = 1
+            while (%t)
+            R1 = (iblock-1) * blocksize + 1;
+            R2 = blocksize + R1-1;
+            irange = [R1 C1 R2 C2];
+            mprintf("Block #%d, rows #%d to #%d\n",iblock,R1,R2);
+            tic();
+            M=csvRead(filename , [] , [] , [] , [] , [] , [] , irange );
+            t = toc();
+            nrows = size(M,"r");
+            ncols = size(M,"c");
+            if ( nrows &gt; 0 ) then
+            p = t/(nrows*ncols)*1.e6;
+            mprintf("  Actual #rows=%d\n",nrows);
+            mprintf("  T=%.3f (s)\n",t);
+            mprintf("  T=%.1f (ms/cell)\n",p);
+            end
+            if ( nrows &lt; blocksize ) then
+            mprintf("... End of the file.\n");
+            break
+            end
+            iblock = iblock + 1;
+            end
+        </programlisting>
+        
+        <para>This produces :</para>
+        
+        <programlisting role="no-scilab-exec">Block #1, rows #1 to #5000
+            Actual #rows=5000
+            T=3.135 (s)
+            T=209.0 (ms/cell)
+            Block #2, rows #5001 to #10000
+            Actual #rows=5000
+            T=3.139 (s)
+            T=209.3 (ms/cell)
+            Block #3, rows #10001 to #15000
+            Actual #rows=5000
+            T=3.151 (s)
+            T=210.1 (ms/cell)
+            etc....
+        </programlisting>
+    </refsection>
+    
+    <refsection>
+        <title>See Also</title>
+        
+        <simplelist type="inline">
+            <member>
+                <link linkend="csvWrite">csvWrite</link>
+            </member>
+        </simplelist>
+    </refsection>
+</refentry>
+
diff --git a/scilab/modules/spreadsheet/help/en_US/csvTextscan.xml b/scilab/modules/spreadsheet/help/en_US/csvTextscan.xml
new file mode 100644 (file)
index 0000000..a1f6e1a
--- /dev/null
@@ -0,0 +1,154 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Copyright (C) 2010-2011 - INRIA - Allan CORNET
+ * Copyright (C) 2011 - INRIA - Michael Baudin
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ -->
+<refentry version="5.0-subset Scilab" xml:id="csvTextScan" xml:lang="en"
+          xmlns="http://docbook.org/ns/docbook"
+          xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg"
+          xmlns:ns3="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML"
+          xmlns:db="http://docbook.org/ns/docbook">
+    <refnamediv>
+        <refname>csvTextScan</refname>
+        
+        <refpurpose>Read comma-separated value in a matrix of strings</refpurpose>
+    </refnamediv>
+    
+    <refsynopsisdiv>
+        <title>Calling Sequence</title>
+        
+        <synopsis>
+            A = csvTextScan(M)
+            A = csvTextScan(M, separator)
+            A = csvTextScan(M, separator, decimal)
+            A = csvTextScan(M, separator, decimal, conversion)
+            A = csvTextScan(M, separator, decimal, conversion, range)
+        </synopsis>
+    </refsynopsisdiv>
+    
+    <refsection>
+        <title>Parameters</title>
+        
+        <variablelist>
+            <varlistentry>
+                <term>M</term>
+                
+                <listitem>
+                    <para>a m-by-1 or 1-by-m matrix of strings.</para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>separator</term>
+                
+                <listitem>
+                    <para>a 1-by-1 matrix of strings, the column separator mark.</para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>decimal</term>
+                
+                <listitem>
+                    <para>a 1-by-1 matrix of strings, the decimal mark. The available
+                        values are "." or ",".
+                    </para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>conversion</term>
+                
+                <listitem>
+                    <para>a 1-by-1 matrix of strings, the type of the output
+                        <literal>A</literal>. Available values are "string" or
+                        "double".
+                    </para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>range</term>
+                
+                <listitem>
+                    <para>a 1-by-4 or 4-by-1 matrix of floating point integers, the
+                        range of rows and columns which must be read (default range=[],
+                        meaning that all the rows and columns). Specify range using the
+                        format <literal>[R1 C1 R2 C2]</literal> where (R1,C1) is the upper
+                        left corner of the data to be read and (R2,C2) is the lower right
+                        corner.
+                    </para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>A</term>
+                
+                <listitem>
+                    <para>a m-by-n matrix of strings or double.</para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    
+    <refsection>
+        <title>Description</title>
+        
+        <para>Given an ascii file with delimited fields, this function returns the
+            corresponding Scilab matrix of strings or doubles.
+        </para>
+        
+        <para>
+            The <literal>csvTextScan</literal> function has the same purpose as
+            <literal>csvRead</literal>, except that <literal>csvTextScan</literal>
+            reads in a string, while <literal>csvRead</literal> reads in a
+            file.
+        </para>
+        
+        <para>The default value of the optional input arguments are defined by the
+            <literal>csvDefault</literal> function.
+        </para>
+        
+        <para>Any optional input argument equal to the empty matrix
+            <literal>[]</literal> is set to its default value.
+        </para>
+        
+        <para>When input argument "conversion" is equal to "double", strings are
+            converted as NaN.
+        </para>
+    </refsection>
+    
+    <refsection>
+        <title>Examples</title>
+        
+        <programlisting role="example">      // convert a csv string matrix to splitted string or double matrix
+            A = ["1;3 + i"; "Nan;-Inf"]
+            B = csvTextScan(A,';')
+            C = csvTextScan(A,';',[],'double')
+            //
+            // Configure the decimal mark.
+            Atext = [
+            " 1,000000000D+00; 0,000000000D+00; 2,000000000D+02;             Inf; 0,000000000D+00";
+            " 1,000000000D+00; 1,00000000D-300; 2,000000000D+02;             Inf; 0,000000000D+00";
+            " 1,000000000D+00; 1,00000000D-200; 2,000000000D+02; 3,15000000D+300; 1,020000000D+02";
+            " 9,999999999D-01; 1,00000000D-100; 2,000000000D+02; 2,960000000D+02; 1,170000000D+02";
+            " 1,000000000D+00;             Inf;            -Inf;             Nan; 0,000000000D+00"
+            ];
+            csvTextScan( Atext , ";" , "," )    
+        </programlisting>
+    </refsection>
+    
+    <refsection>
+        <title>See Also</title>
+        
+        <simplelist type="inline">
+            <member>
+                <link linkend="csvRead">csvRead</link>
+            </member>
+        </simplelist>
+    </refsection>
+</refentry>
+
diff --git a/scilab/modules/spreadsheet/help/en_US/csvWrite.xml b/scilab/modules/spreadsheet/help/en_US/csvWrite.xml
new file mode 100644 (file)
index 0000000..75b7d13
--- /dev/null
@@ -0,0 +1,193 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Copyright (C) 2010-2011 - INRIA - Allan CORNET
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ -->
+<refentry version="5.0-subset Scilab" xml:id="csvWrite" xml:lang="en"
+          xmlns="http://docbook.org/ns/docbook"
+          xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg"
+          xmlns:ns3="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML"
+          xmlns:db="http://docbook.org/ns/docbook">
+    <refnamediv>
+        <refname>csvWrite</refname>
+        
+        <refpurpose>Write comma-separated value file</refpurpose>
+    </refnamediv>
+    
+    <refsynopsisdiv>
+        <title>Calling Sequence</title>
+        
+        <synopsis>
+            csvWrite(M, filename)
+            csvWrite(M, filename, separator)
+            csvWrite(M, filename, separator, decimal)
+            csvWrite(M, filename, separator, decimal, precision)
+            csvWrite(M, filename, separator, decimal, precision, comments)
+        </synopsis>
+    </refsynopsisdiv>
+    
+    <refsection>
+        <title>Parameters</title>
+        
+        <variablelist>
+            <varlistentry>
+                <term>filename</term>
+                
+                <listitem>
+                    <para>a 1-by-1 matrix of strings, the file path.</para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>M</term>
+                
+                <listitem>
+                    <para>a m-by-n matrix of strings or double (complex
+                        supported).
+                    </para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>separator</term>
+                
+                <listitem>
+                    <para>a 1-by-1 matrix of strings, the column separator mark.</para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>decimal</term>
+                
+                <listitem>
+                    <para>a 1-by-1 matrix of strings, the decimal mark. The available
+                        values are "." or ",".
+                    </para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>precision</term>
+                
+                <listitem>
+                    <para>a 1-by-1 matrix of strings, the C format.</para>
+                </listitem>
+            </varlistentry>
+            
+            <varlistentry>
+                <term>comments</term>
+                
+                <listitem>
+                    <para>a m-by-1 matrix of strings, the comments stored at the
+                        beginning of the file. This option may be used, for example, to put
+                        a licence header in a data file.
+                    </para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    
+    <refsection>
+        <title>Description</title>
+        
+        <para>This function writes matrix M into filename as comma-separated
+            values.
+        </para>
+        
+        <para>The default value of the optional input arguments are defined by the
+            <literal>csvDefault</literal> function.
+        </para>
+        
+        <para>Any optional input argument equal to the empty matrix
+            <literal>[]</literal> is set to its default value.
+        </para>
+        
+        <para>
+            If the file <literal>filename</literal> already exists, it is
+            overwritten.
+        </para>
+    </refsection>
+    
+    <refsection>
+        <title>Examples</title>
+        
+        <para>In the following example, we combine the
+            <literal>csvWrite</literal> and <literal>csvRead</literal>
+            functions.
+        </para>
+        
+        <programlisting role="example">// Save a matrix as csv file format
+            M = [1:10] * 0.1;
+            filename = fullfile(TMPDIR, "data.csv");
+            csvWrite(M, filename);
+            
+            // Read as text
+            mgetl(filename)
+            
+            r = csvRead(filename);    
+        </programlisting>
+        
+        <para>In the following example, we use various options of the
+            <literal>csvWrite</literal> function.
+        </para>
+        
+        <programlisting role="example">// Save a matrix as csv file format
+            M = rand(2,3);
+            filename = fullfile(TMPDIR, "data.csv");
+            //
+            // Use tabs as the separator
+            csvWrite(M, filename,ascii(9));
+            mgetl(filename)
+            //
+            // Use the "," as the decimal point
+            // (and blank space as the separator).
+            csvWrite(M, filename," ",",");
+            mgetl(filename)
+            //
+            // Configure the precision.
+            // Caution: this lower precision may generate 
+            // errors in a write-read cycle!
+            csvWrite(M, filename,[],[],"%.8e");
+            mgetl(filename)
+            //
+            // Configure the comments
+            comments = [
+            "// Copyright (C) INRIA"
+            "//  This file must be used under the terms of the CeCILL."
+            ];
+            csvWrite(M, filename,[],[],[],comments);
+            mgetl(filename)   
+        </programlisting>
+        
+        <para>The following examples are more advanced uses of the
+            <literal>csvWrite</literal> function.
+        </para>
+        
+        <programlisting role="example">A = [
+            1 0 200 %inf 0
+            1 1.e-300 200 %inf 0
+            9.99999999999990010e-001 9.99999999999999980e-201 200 3.15e300 102
+            9.99999999899999990e-001 1.e-100 200 296 117
+            1 %inf -%inf %nan 0
+            ];
+            
+            // Write into a file
+            filename=fullfile(TMPDIR,"foo.csv");
+            csvWrite ( A , filename );
+            edit(filename)   
+        </programlisting>
+    </refsection>
+    
+    <refsection>
+        <title>See Also</title>
+        
+        <simplelist type="inline">
+            <member>
+                <link linkend="csvRead">csvRead</link>
+            </member>
+        </simplelist>
+    </refsection>
+</refentry>
+
index 217c847..9d127dd 100644 (file)
@@ -83,7 +83,7 @@
             write_csv(A, TMPDIR + '/datas.tsv');
             
             //coma-separated values
-            write_csv(A, TMPDIR + '/datas.csv', ';'); 
+            write_csv(A, TMPDIR + '/data.csv', ';'); 
             
         </programlisting>
     </refsection>
         </simplelist>
     </refsection>
 </refentry>
+
index bda9552..f071ea9 100644 (file)
@@ -84,7 +84,7 @@
             write_csv(A, TMPDIR + '/datas.tsv');
             
             //coma-separated values
-            write_csv(A, TMPDIR + '/datas.csv', ';');
+            write_csv(A, TMPDIR + '/data.csv', ';');
         </programlisting>
     </refsection>
     <refsection role="see also">
index 2ef481a..1a27735 100644 (file)
       write_csv(A, TMPDIR + '/datas.tsv');
       
       //значения, разделённые запятыми
-      write_csv(A, TMPDIR + '/datas.csv', ';'); 
+      write_csv(A, TMPDIR + '/data.csv', ';'); 
       
      ]]></programlisting>
         
index 4cbdc11..ac5b93a 100644 (file)
 
 #ifndef __GW_SPREADSHEET_H__
 #define __GW_SPREADSHEET_H__
-/*--------------------------------------------------------------------------*/ 
+/*--------------------------------------------------------------------------*/
 #include "dynlib_spreadsheet.h"
-/*--------------------------------------------------------------------------*/ 
+/*--------------------------------------------------------------------------*/
 SPREADSHEET_IMPEXP int gw_spreadsheet(void);
-/*--------------------------------------------------------------------------*/ 
-SPREADSHEET_IMPEXP int sci_xls_read(char *fname,unsigned long fname_len);
-SPREADSHEET_IMPEXP int sci_xls_open(char *fname,unsigned long fname_len);
-/*--------------------------------------------------------------------------*/ 
+/*--------------------------------------------------------------------------*/
+SPREADSHEET_IMPEXP int sci_xls_read(char *fname, unsigned long fname_len);
+SPREADSHEET_IMPEXP int sci_xls_open(char *fname, unsigned long fname_len);
+SPREADSHEET_IMPEXP int sci_csvDefault(char *fname, unsigned long fname_len);
+SPREADSHEET_IMPEXP int sci_csvIsnum(char *fname, unsigned long fname_len);
+SPREADSHEET_IMPEXP int sci_csvRead(char *fname, unsigned long fname_len);
+SPREADSHEET_IMPEXP int sci_csvStringToDouble(char *fname, unsigned long fname_len);
+SPREADSHEET_IMPEXP int sci_csvTextScan(char *fname, unsigned long fname_len);
+SPREADSHEET_IMPEXP int sci_csvWrite(char *fname, unsigned long fname_len);
+
+/*--------------------------------------------------------------------------*/
 #endif /*  __GW_SPREADSHEET_H__ */
 /*--------------------------------------------------------------------------*/
index 2941a81..95dc3a9 100644 (file)
@@ -50,3 +50,29 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 POSSIBILITY OF SUCH DAMAGE.
 
+
+Various files:
+==============
+
+Some files are published under a double license GPL V3 / CeCILL.
+
+Files: sci_gateway/cpp/gw_csv_helpers.cpp
+sci_gateway/cpp/sci_csvStringToDouble.cpp
+sci_gateway/cpp/gw_csv_helpers.h
+sci_gateway/cpp/sci_csvWrite.cpp
+sci_gateway/cpp/sci_csvTextScan.cpp
+sci_gateway/cpp/gw_csv_tools.h
+sci_gateway/cpp/sci_csvRead.cpp
+sci_gateway/cpp/sci_csvDefault.cpp
+sci_gateway/cpp/sci_csvIsnum.cpp
+src/cpp/stringToComplex.h
+src/cpp/stringsToDoubles.h
+src/cpp/stringToComplex.c
+src/cpp/stringToDouble.c
+src/cpp/stringsToDoubles.c
+src/cpp/stringToDouble.h
+
+
+Copyright: Allan Cornet - 2012
+
+License: GPL V3
diff --git a/scilab/modules/spreadsheet/macros/read_csv.sci b/scilab/modules/spreadsheet/macros/read_csv.sci
deleted file mode 100644 (file)
index d2db711..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2008 - INRIA
-// Copyright (C) 2009-2010 - DIGITEO - Allan CORNET
-//
-// This file must be used under the terms of the CeCILL.
-// This source file is licensed as described in the file COPYING, which
-// you should have received as part of this distribution.  The terms
-// are also available at
-// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
-
-
-function mat = read_csv(fname, sep)
-// Given an ascii  file created by Excel using "Text and comma" format
-// read_csv(fname) returns the corresponding Scilab matrix of strings.
-
-  if (type(fname) <> 10) then
-    error(msprintf(gettext("%s: Wrong type for input argument #%d: a string expected.\n"), "read_csv", 1));
-  end
-
-  if (size(fname,"*")<> 1) then
-    error(msprintf(gettext("%s: Wrong size for input argument #%d: a string expected.\n"), "read_csv", 1));
-  end
-
-  if argn(2)<2 then
-    sep = ",";
-  end
-
-  if (type(sep) <> 10) then
-    error(msprintf(gettext("%s: Wrong type for input argument #%d: a string expected.\n"), "read_csv", 2));
-  end
-
-  if (size(sep, "*")<> 1) then
-    error(msprintf(gettext("%s: Wrong size for input argument #%d: a string expected.\n"), "read_csv", 2));
-  end
-
-  if sep == "\t" then
-    sep = ascii(9);
-  end
-
-  if ~isfile(fname) then
-    error(msprintf(gettext("%s: file %s does not exist.\n"), "read_csv", fname));
-  end
-
-  v = mgetl(fname);
-  v(v == "") = [];
-  ns = length(sep);
-  mat = [];
-  ki = 1;
-  for i = 1 : size(v,"*")
-    line = v(i);
-    K = [strindex(line, sep)];
-    ki = 1;
-    row = [];
-    for k = K
-      row = [row, part(line,ki:k-1)];
-      ki = k + ns;
-    end
-    row = [row, part(line, ki:length(line))];
-    if (i > 1) then
-      if size(row,2) > size(mat,2) then
-        mat($,size(row,2)) = "";
-      elseif size(row,2) < size(mat,2) then
-        row(1, size(mat,2)) = "";
-      end
-    end
-    mat = [mat; row];
-  end
-endfunction
diff --git a/scilab/modules/spreadsheet/macros/write_csv.sci b/scilab/modules/spreadsheet/macros/write_csv.sci
deleted file mode 100644 (file)
index 0f54877..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2008 - INRIA
-// Copyright (C) 2009-2012 - DIGITEO - Allan CORNET
-//
-// This file must be used under the terms of the CeCILL.
-// This source file is licensed as described in the file COPYING, which
-// you should have received as part of this distribution.  The terms
-// are also available at
-// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
-
-
-function write_csv(var, fname, sep, dec)
-// var : a matrix of numbers or a matrix of strings
-// fname : a character string, the path of the file to create
-// sep   : the column separator mark, a tab by default
-// dec   : the decimal mark . or ,
-// Example
-// a = rand(3,5);
-// write_csv(a,'/tmp/foo.txt',sep=',')
-
-  if exists('sep','local') == 0 then
-    sep = ascii(9);
-  end
-  
-  if sep == '\t' then
-    sep = ascii(9);
-  end
-  
-  if exists('dec','local') == 0 then
-    dec = ',';
-  end
-  
-  if ( (type(var) <> 10) & (type(var) <> 1) ) then
-    error(msprintf(gettext("%s: Wrong type for input argument #%d: ''%s'' or ''%s'' expected.\n"), 'write_csv', 1, 'real', 'string'));
-  end
-
-  if (type(fname) <> 10) then
-    error(msprintf(gettext("%s: Wrong type for input argument #%d: a string expected.\n"), 'write_csv', 2));
-  end
-  
-  if (size(fname,'*')<> 1) then
-    error(msprintf(gettext("%s: Wrong size for input argument #%d: a string expected.\n"), 'write_csv', 2));  
-  end
-
-  if (type(dec) <> 10) then
-    error(msprintf(gettext("%s: Wrong type for input argument #%d: a string expected.\n"), 'write_csv', 3));
-  end
-
-  if (size(dec,'*')<> 1) then
-    error(msprintf(gettext("%s: Wrong size for input argument #%d: a string expected.\n"), 'write_csv', 3));  
-  end
-
-  if dec <> ['.',','] then 
-    error(msprintf(gettext("%s: Wrong value for input argument #%d: ''%s'' or ''%s'' expected.\n"), 'write_csv', 4, '.', ','));
-  end
-
-  if type(var) == 1 then
-    var = string(var);
-    if dec <> '.' then 
-      var = strsubst(var,'.',',');
-    end
-  end
-
-  t = var(:, 1);
-  for k=2:size(var, 2)
-    t = t + sep + var(:, k);
-  end
-  
-  mputl(t,fname);
-  
-endfunction
index f8a8f9c..6e76c13 100644 (file)
 #include "api_scilab.h"
 #include "MALLOC.h"
 #include "callFunctionFromGateway.h"
-/*--------------------------------------------------------------------------*/ 
-static gw_generic_table Tab[] = 
+/*--------------------------------------------------------------------------*/
+static gw_generic_table Tab[] =
 {
-       {sci_xls_open,"xls_open"},
-       {sci_xls_read,"xls_read"}
+    {sci_xls_open, "xls_open"},
+    {sci_xls_read, "xls_read"},
+    {sci_csvDefault, "csvDefault"},
+    {sci_csvIsnum, "csvIsnum"},
+    {sci_csvRead, "csvRead"},
+    {sci_csvStringToDouble, "csvStringToDouble"},
+    {sci_csvTextScan, "csvTextScan"},
+    {sci_csvWrite, "csvWrite"},
+    {sci_csvWrite, "write_csv"},
+    {sci_csvRead, "read_csv"}
 };
-/*--------------------------------------------------------------------------*/ 
+/*--------------------------------------------------------------------------*/
 int gw_spreadsheet(void)
-{  
-       Rhs = Max(0, Rhs);
+{
+    Rhs = Max(0, Rhs);
 
-    if(pvApiCtx == NULL)
-       {
-               pvApiCtx = (StrCtx*)MALLOC(sizeof(StrCtx));
-       }
+    if (pvApiCtx == NULL)
+    {
+        pvApiCtx = (StrCtx*)MALLOC(sizeof(StrCtx));
+    }
 
-       pvApiCtx->pstName = (char*)Tab[Fin-1].name;
-       callFunctionFromGateway(Tab, SIZE_CURRENT_GENERIC_TABLE(Tab));
-       return 0;
+    pvApiCtx->pstName = (char*)Tab[Fin - 1].name;
+    callFunctionFromGateway(Tab, SIZE_CURRENT_GENERIC_TABLE(Tab));
+    return 0;
 }
-/*--------------------------------------------------------------------------*/ 
+/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/spreadsheet/sci_gateway/cpp/gw_csv_helpers.cpp b/scilab/modules/spreadsheet/sci_gateway/cpp/gw_csv_helpers.cpp
new file mode 100644 (file)
index 0000000..bb62226
--- /dev/null
@@ -0,0 +1,430 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - 2012 - INRIA - Allan CORNET
+ * Copyright (C) 2011 - INRIA - Michael Baudin
+ *
+ * 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
+ *
+ * This code is also published under the GPL v3 license.
+ *
+ */
+#include <string.h>
+#include "api_scilab.h"
+#include "sci_types.h"
+#include "Scierror.h"
+#include "MALLOC.h"
+#include "localization.h"
+#include "gw_csv_helpers.h"
+#ifdef _MSC_VER
+#include "strdup_windows.h"
+#endif
+#include "freeArrayOfString.h"
+// =============================================================================
+char *csv_getArgumentAsStringWithEmptyManagement(void* _pvCtx, int _iVar, const char *fname,
+        const char *defaultValue,
+        int *iErr)
+{
+    SciErr sciErr;
+    char *returnedValue = NULL;
+    int *piAddressVar = NULL;
+    int iType = 0;
+    int m = 0, n = 0;
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddressVar);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        *iErr = sciErr.iErr;
+        return NULL;
+    }
+
+    sciErr = getVarType(pvApiCtx, piAddressVar, &iType);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        *iErr = sciErr.iErr;
+        return NULL;
+    }
+
+    if (iType != sci_strings)
+    {
+        if (isEmptyMatrix(pvApiCtx, piAddressVar))
+        {
+            /* [] equals default value */
+            if (defaultValue)
+            {
+                *iErr = 0;
+                returnedValue = strdup(defaultValue);
+            }
+            else
+            {
+                *iErr = 0;
+                returnedValue = NULL;
+            }
+        }
+        else
+        {
+            *iErr = API_ERROR_INVALID_TYPE;
+            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, _iVar);
+            return NULL;
+        }
+    }
+    else
+    {
+        *iErr = checkVarDimension(pvApiCtx, piAddressVar, 1, 1);
+
+        if (*iErr == 0 )
+        {
+            *iErr = API_ERROR_CHECK_VAR_DIMENSION;
+            Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, _iVar);
+            return NULL;
+        }
+
+        *iErr = getAllocatedSingleString(pvApiCtx, piAddressVar, &returnedValue);
+        if (*iErr)
+        {
+            Scierror(999, _("%s: Memory allocation error.\n"), fname);
+            return NULL;
+        }
+    }
+    return returnedValue;
+}
+// =============================================================================
+
+char *csv_getArgumentAsString(void* _pvCtx, int _iVar,
+                              const char *fname, int *iErr)
+{
+    SciErr sciErr;
+
+    int *piAddressVar = NULL;
+    int m = 0, n = 0;
+    int iType = 0;
+
+    char *returnedValue = NULL;
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddressVar);
+    if (sciErr.iErr)
+    {
+        *iErr = sciErr.iErr;
+        printError(&sciErr, 0);
+        return NULL;
+    }
+
+    sciErr = getVarType(pvApiCtx, piAddressVar, &iType);
+    if (sciErr.iErr)
+    {
+        *iErr = sciErr.iErr;
+        printError(&sciErr, 0);
+        return NULL;
+    }
+
+    if (iType != sci_strings)
+    {
+        *iErr = API_ERROR_INVALID_TYPE;
+        Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
+        return NULL;
+    }
+
+    *iErr = checkVarDimension(pvApiCtx, piAddressVar, 1, 1);
+
+    if (*iErr == 0 )
+    {
+        *iErr = API_ERROR_CHECK_VAR_DIMENSION;
+        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, _iVar);
+        return NULL;
+    }
+
+    *iErr = getAllocatedSingleString(pvApiCtx, piAddressVar, &returnedValue);
+    if (*iErr)
+    {
+        Scierror(999, _("%s: Memory allocation error.\n"), fname);
+        return NULL;
+    }
+    return returnedValue;
+}
+// =============================================================================
+double csv_getArgumentAsScalarDouble(void* _pvCtx, int _iVar,
+                                     const char *fname, int *iErr)
+{
+    SciErr sciErr;
+    double dValue = 0.;
+    int *piAddressVar = NULL;
+    int m = 0, n = 0;
+    int iType = 0;
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddressVar);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        *iErr = sciErr.iErr;
+        return 0;
+    }
+
+    sciErr = getVarType(pvApiCtx, piAddressVar, &iType);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        *iErr = sciErr.iErr;
+        return 0;
+    }
+
+    if (iType != sci_matrix)
+    {
+        Scierror(999, _("%s: Wrong type for input argument #%d: A double expected.\n"), fname, _iVar);
+        *iErr =  API_ERROR_INVALID_TYPE;
+        return 0;
+    }
+
+    *iErr = checkVarDimension(pvApiCtx, piAddressVar, 1, 1);
+
+    if (*iErr == 0 )
+    {
+        *iErr = API_ERROR_CHECK_VAR_DIMENSION;
+        Scierror(999, _("%s: Wrong size for input argument #%d: A double expected.\n"), fname, _iVar);
+        return 0;
+    }
+
+    *iErr = getScalarDouble(pvApiCtx, piAddressVar, &dValue);
+    return dValue;
+}
+// =============================================================================
+int csv_getArgumentAsScalarBoolean(void* _pvCtx, int _iVar,
+                                   const char *fname, int *iErr)
+{
+    SciErr sciErr;
+    int bValue = 0;
+    int *piAddressVar = NULL;
+    int m = 0, n = 0;
+    int iType = 0;
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddressVar);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        *iErr = sciErr.iErr;
+        return 0;
+    }
+
+    sciErr = getVarType(pvApiCtx, piAddressVar, &iType);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        *iErr = sciErr.iErr;
+        return 0;
+    }
+
+    if (iType != sci_boolean)
+    {
+        Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, _iVar);
+        *iErr =  API_ERROR_INVALID_TYPE;
+        return 0;
+    }
+
+    *iErr = checkVarDimension(pvApiCtx, piAddressVar, 1, 1);
+
+    if (*iErr == 0 )
+    {
+        *iErr = API_ERROR_CHECK_VAR_DIMENSION;
+        Scierror(999, _("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, _iVar);
+        return 0;
+    }
+
+    *iErr = getScalarBoolean(pvApiCtx, piAddressVar, &bValue);
+    return bValue;
+}
+// =============================================================================
+char **csv_getArgumentAsMatrixOfString(void* _pvCtx, int _iVar,
+                                       const char *fname,
+                                       int *m, int *n, int *iErr)
+{
+    SciErr sciErr;
+    char **pStringValues = NULL;
+    int *piAddressVar = NULL;
+    int m_ = 0, n_ = 0;
+    int iType = 0;
+    int *lengthStringValues = NULL;
+    int i = 0;
+
+    *m = 0;
+    *n = 0;
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddressVar);
+    if (sciErr.iErr)
+    {
+        *iErr = sciErr.iErr;
+        printError(&sciErr, 0);
+        return NULL;
+    }
+
+    sciErr = getVarType(pvApiCtx, piAddressVar, &iType);
+    if (sciErr.iErr)
+    {
+        *iErr = sciErr.iErr;
+        printError(&sciErr, 0);
+        return NULL;
+    }
+
+    if (iType != sci_strings)
+    {
+        *iErr =  API_ERROR_INVALID_TYPE;
+        Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, _iVar);
+        return NULL;
+    }
+
+    *iErr = getAllocatedMatrixOfString(pvApiCtx, piAddressVar, &m_, &n_, &pStringValues);
+    if (*iErr != 0)
+    {
+        return NULL;
+    }
+
+    *iErr = 0;
+    *m = m_;
+    *n = n_;
+
+    return pStringValues;
+}
+// =============================================================================
+int csv_isRowVector(void* _pvCtx, int _iVar)
+{
+    SciErr sciErr;
+    int *piAddressVar = NULL;
+    sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddressVar);
+    if (sciErr.iErr) return 0;
+    return isRowVector(pvApiCtx, piAddressVar);
+}
+// =============================================================================
+int csv_isColumnVector(void* _pvCtx, int _iVar)
+{
+    SciErr sciErr;
+    int *piAddressVar = NULL;
+    sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddressVar);
+    if (sciErr.iErr) return 0;
+    return isColumnVector(pvApiCtx, piAddressVar);
+}
+// =============================================================================
+int csv_isScalar(void* _pvCtx, int _iVar)
+{
+    SciErr sciErr;
+    int *piAddressVar = NULL;
+    sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddressVar);
+    if (sciErr.iErr) return 0;
+    return isScalar(pvApiCtx, piAddressVar);
+}
+// =============================================================================
+int csv_isDoubleScalar(void* _pvCtx, int _iVar)
+{
+    SciErr sciErr;
+    int *piAddressVar = NULL;
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddressVar);
+    if (sciErr.iErr) return 0;
+
+    if (csv_isScalar(_pvCtx, _iVar))
+    {
+        int iType = 0;
+        sciErr = getVarType(pvApiCtx, piAddressVar, &iType);
+        if (sciErr.iErr) return 0;
+
+        if (isVarComplex(pvApiCtx, piAddressVar) == 0)
+        {
+            return (iType == sci_matrix);
+        }
+    }
+    return 0;
+}
+// =============================================================================
+int csv_isEmpty(void* _pvCtx, int _iVar)
+{
+    SciErr sciErr;
+    int *piAddressVar = NULL;
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddressVar);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        if (sciErr.iErr) return 0;
+    }
+
+    return isEmptyMatrix(pvApiCtx, piAddressVar);
+}
+// =============================================================================
+int *csv_getArgumentAsMatrixofIntFromDouble(void* _pvCtx, int _iVar,
+        const char *fname,
+        int *m, int *n, int *iErr)
+{
+    int *iReturnedArray = NULL;
+    double *dArray = NULL;
+    SciErr sciErr;
+    int *piAddressVar = NULL;
+    int iType = 0;
+    int m_ = 0;
+    int n_ = 0;
+    int i = 0;
+    int j = 0;
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddressVar);
+    if (sciErr.iErr)
+    {
+        *iErr = sciErr.iErr;
+        printError(&sciErr, 0);
+        return NULL;
+    }
+
+    sciErr = getVarType(pvApiCtx, piAddressVar, &iType);
+    if (sciErr.iErr)
+    {
+        *iErr = sciErr.iErr;
+        printError(&sciErr, 0);
+        return NULL;
+    }
+
+    if (iType != sci_matrix)
+    {
+        *iErr =  API_ERROR_INVALID_TYPE;
+        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of double expected.\n"), fname, _iVar);
+        return NULL;
+    }
+
+    sciErr = getMatrixOfDouble(pvApiCtx, piAddressVar, &m_, &n_, &dArray);
+    if (sciErr.iErr)
+    {
+        *iErr = sciErr.iErr;
+        printError(&sciErr, 0);
+        return NULL;
+    }
+
+    for (j = 0; j < m_ * n_; j++)
+    {
+        int iVal = (int)dArray[j];
+        if ((double)iVal != dArray[j])
+        {
+            *iErr = API_ERROR_GET_DOUBLE;
+            Scierror(999, _("%s: Wrong value for input argument #%d: A matrix of double, with integer values, expected.\n"), fname, _iVar);
+            return NULL;
+        }
+    }
+
+    iReturnedArray = (int*)MALLOC(sizeof(int) * (m_ * n_));
+    if (iReturnedArray == NULL)
+    {
+        *iErr = API_ERROR_ALLOC_DOUBLE;
+        Scierror(999, _("%s: Memory allocation error.\n"), fname);
+        return NULL;
+    }
+
+    for (j = 0; j < m_ * n_; j++)
+    {
+        iReturnedArray[j] = (int)dArray[j];
+    }
+
+    *iErr = 0;
+    *m = m_;
+    *n = n_;
+
+    return iReturnedArray;
+}
+// =============================================================================
diff --git a/scilab/modules/spreadsheet/sci_gateway/cpp/gw_csv_helpers.h b/scilab/modules/spreadsheet/sci_gateway/cpp/gw_csv_helpers.h
new file mode 100644 (file)
index 0000000..1fc34fc
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - 2012 - INRIA - Allan CORNET
+ * Copyright (C) 2011 - INRIA - Michael Baudin
+ *
+ * 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
+ *
+ * This code is also published under the GPL v3 license.
+ *
+ */
+
+#ifndef __GW_CSV_HELPERS_H__
+#define __GW_CSV_HELPERS_H__
+
+
+char *csv_getArgumentAsStringWithEmptyManagement(void* _pvCtx, int _iVar,
+        const char *fname, const char *defaultValue,
+        int *iErr);
+
+char *csv_getArgumentAsString(void* _pvCtx, int _iVar,
+                              const char *fname, int *iErr);
+
+int csv_getArgumentAsScalarBoolean(void* _pvCtx, int _iVar,
+                                   const char *fname, int *iErr);
+
+char **csv_getArgumentAsMatrixOfString(void* _pvCtx, int _iVar,
+                                       const char *fname,
+                                       int *m, int *n, int *iErr);
+
+int *csv_getArgumentAsMatrixofIntFromDouble(void* _pvCtx, int _iVar,
+        const char *fname,
+        int *m, int *n, int *iErr);
+
+double csv_getArgumentAsScalarDouble(void* _pvCtx, int _iVar,
+                                     const char *fname, int *iErr);
+
+
+int csv_isRowVector(void* _pvCtx, int _iVar);
+int csv_isColumnVector(void* _pvCtx, int _iVar);
+int csv_isScalar(void* _pvCtx, int _iVar);
+int csv_isDoubleScalar(void* _pvCtx, int _iVar);
+int csv_isEmpty(void* _pvCtx, int _iVar);
+
+#endif /* __GW_CSV_HELPERS_H__ */
+// =============================================================================
+
diff --git a/scilab/modules/spreadsheet/sci_gateway/cpp/gw_csv_tools.h b/scilab/modules/spreadsheet/sci_gateway/cpp/gw_csv_tools.h
new file mode 100644 (file)
index 0000000..5700643
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - 2012 - INRIA - Allan CORNET
+ * Copyright (C) 2011 - INRIA - Michael Baudin
+ *
+ * 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
+ *
+ * This code is also published under the GPL v3 license.
+ *
+ */
+#ifndef __GW_CSV_TOOLS_H__
+#define __GW_CSV_TOOLS_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+    int sci_csvDefault(char *fname);
+    int sci_csvIsnum(char *fname);
+    int sci_csvRead(char *fname);
+    int sci_csvStringToDouble(char *fname);
+    int sci_csvTextScan(char *fname);
+    int sci_csvWrite(char *fname);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __GW_CSV_TOOLS_H__ */
+// =============================================================================
+
diff --git a/scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvDefault.cpp b/scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvDefault.cpp
new file mode 100644 (file)
index 0000000..9083b02
--- /dev/null
@@ -0,0 +1,436 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - 2012 - INRIA - Allan CORNET
+ * Copyright (C) 2011 - INRIA - Michael Baudin
+ *
+ * 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
+ *
+ * This code is also published under the GPL v3 license.
+ *
+ */
+#include <string.h>
+#include <stdio.h>
+#include "gw_csv_tools.h"
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "MALLOC.h"
+#include "Scierror.h"
+#include "localization.h"
+extern "C" {
+#include "freeArrayOfString.h"
+};
+#ifdef _MSC_VER
+#include "strdup_windows.h"
+#endif
+#include "csvDefault.h"
+#include "gw_csv_helpers.h"
+// =============================================================================
+#define SEPARATOR_FIELDNAME "separator"
+#define DECIMAL_FIELDNAME "decimal"
+#define CONVERSION_FIELDNAME "conversion"
+#define PRECISION_FIELDNAME "precision"
+#define COMMENTSREGEXP_FIELDNAME "regexp"
+#define EOL_FIELDNAME "eol"
+#define ENCODING_FIELDNAME "encoding"
+#define RESET_PARAMATERS "reset"
+#define BLANK_FIELDNAME "blank"
+// =============================================================================
+#define MACOS9_EOL_STRING "macos9"
+#define MACOS9_EOL "\r"
+#define WINDOWS_EOL_STRING "windows"
+#define WINDOWS_EOL "\r\n"
+#define LINUX_EOL_STRING "linux"
+#define LINUX_EOL "\n"
+// =============================================================================
+#define NUMBER_FIELD 8
+// =============================================================================
+static int sci_csvDefault_no_rhs(char *fname);
+static int sci_csvDefault_one_rhs(char *fname);
+static int sci_csvDefault_two_rhs(char *fname);
+// =============================================================================
+int sci_csvDefault(char *fname)
+{
+    Rhs = Max(0, Rhs);
+    CheckRhs(0, 2);
+    CheckLhs(1, 1);
+
+    switch (Rhs)
+    {
+        case 0:
+            return sci_csvDefault_no_rhs(fname);
+        case 1:
+            return sci_csvDefault_one_rhs(fname);
+        case 2:
+            return sci_csvDefault_two_rhs(fname);
+    }
+    return 0;
+}
+// =============================================================================
+static int sci_csvDefault_no_rhs(char *fname)
+{
+    int sizeArray = NUMBER_FIELD * 2;
+    char **arrayOut = (char**)MALLOC(sizeof(char*) * sizeArray);
+
+    if (arrayOut)
+    {
+        SciErr sciErr;
+
+        int nbRows = NUMBER_FIELD;
+        int nbCols = 2;
+        const char *currentEol = getCsvDefaultEOL();
+
+        arrayOut[0] = strdup(SEPARATOR_FIELDNAME);
+        arrayOut[1] = strdup(DECIMAL_FIELDNAME);
+        arrayOut[2] = strdup(CONVERSION_FIELDNAME);
+        arrayOut[3] = strdup(PRECISION_FIELDNAME);
+        arrayOut[4] = strdup(COMMENTSREGEXP_FIELDNAME);
+        arrayOut[5] = strdup(EOL_FIELDNAME);
+        arrayOut[6] = strdup(ENCODING_FIELDNAME);
+        arrayOut[7] = strdup(BLANK_FIELDNAME);
+
+        arrayOut[8] = strdup(getCsvDefaultSeparator());
+        arrayOut[9] = strdup(getCsvDefaultDecimal());
+        arrayOut[10] = strdup(getCsvDefaultConversion());
+        arrayOut[11] = strdup(getCsvDefaultPrecision());
+        arrayOut[12] = strdup(getCsvDefaultCommentsRegExp());
+
+        if (currentEol)
+        {
+            if (strcmp(currentEol, MACOS9_EOL) == 0)
+            {
+                arrayOut[13] = strdup(MACOS9_EOL_STRING);
+            }
+            else if (strcmp(currentEol, WINDOWS_EOL) == 0)
+            {
+                arrayOut[13] = strdup(WINDOWS_EOL_STRING);
+            }
+            else if (strcmp(currentEol, LINUX_EOL) == 0)
+            {
+                arrayOut[13] = strdup(LINUX_EOL_STRING);
+            }
+            else
+            {
+                arrayOut[13] = strdup("ERROR");
+            }
+        }
+        else
+        {
+            arrayOut[13] = strdup("ERROR");
+        }
+
+        arrayOut[14] = strdup(getCsvDefaultEncoding());
+        arrayOut[15] = strdup(getCsvDefaultCsvIgnoreBlankLine());
+
+        sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, nbRows, nbCols, arrayOut);
+        freeArrayOfString(arrayOut, sizeArray);
+        if (sciErr.iErr)
+        {
+            printError(&sciErr, 0);
+            return 0;
+        }
+
+        LhsVar(1) = Rhs + 1;
+        PutLhsVar();
+    }
+    else
+    {
+        Scierror(999, _("%s: Memory allocation error.\n"), fname);
+    }
+
+    return 0;
+}
+// =============================================================================
+static int sci_csvDefault_one_rhs(char *fname)
+{
+    int iErr = 0;
+
+    char *fieldname = NULL;
+    char *fieldvalue = NULL;
+
+    fieldname = csv_getArgumentAsString(pvApiCtx, 1, fname, &iErr);
+    if (iErr) return 0;
+
+    if (strcmp(fieldname, SEPARATOR_FIELDNAME) == 0)
+    {
+        fieldvalue = strdup(getCsvDefaultSeparator());
+    }
+    else if (strcmp(fieldname, DECIMAL_FIELDNAME) == 0)
+    {
+        fieldvalue = strdup(getCsvDefaultDecimal());
+    }
+    else if (strcmp(fieldname, CONVERSION_FIELDNAME) == 0)
+    {
+        fieldvalue = strdup(getCsvDefaultConversion());
+    }
+    else if (strcmp(fieldname, PRECISION_FIELDNAME) == 0)
+    {
+        fieldvalue = strdup(getCsvDefaultPrecision());
+    }
+    else if (strcmp(fieldname, COMMENTSREGEXP_FIELDNAME) == 0)
+    {
+        fieldvalue = strdup(getCsvDefaultCommentsRegExp());
+    }
+    else if (strcmp(fieldname, EOL_FIELDNAME) == 0)
+    {
+        const char *currentEol = getCsvDefaultEOL();
+        if (currentEol)
+        {
+            if (strcmp(currentEol, MACOS9_EOL) == 0)
+            {
+                fieldvalue = strdup(MACOS9_EOL_STRING);
+            }
+            else if (strcmp(currentEol, WINDOWS_EOL) == 0)
+            {
+                fieldvalue = strdup(WINDOWS_EOL_STRING);
+            }
+            else if (strcmp(currentEol, LINUX_EOL) == 0)
+            {
+                fieldvalue = strdup(LINUX_EOL_STRING);
+            }
+            else
+            {
+                fieldvalue = strdup("ERROR");
+            }
+        }
+        else
+        {
+            fieldvalue = strdup("ERROR");
+        }
+    }
+    else if (strcmp(fieldname, ENCODING_FIELDNAME) == 0)
+    {
+        fieldvalue = strdup(getCsvDefaultEncoding());
+    }
+    else if (strcmp(fieldname, BLANK_FIELDNAME) == 0)
+    {
+        fieldvalue = strdup(getCsvDefaultCsvIgnoreBlankLine());
+    }
+    else if (strcmp(fieldname, RESET_PARAMATERS) == 0)
+    {
+        if (fieldname)
+        {
+            FREE(fieldname);
+            fieldname = NULL;
+        }
+        if (fieldvalue)
+        {
+            FREE(fieldvalue);
+            fieldvalue = NULL;
+        }
+
+        setCsvDefaultReset();
+
+        createEmptyMatrix(pvApiCtx, Rhs + 1);
+
+        LhsVar(1) = Rhs + 1;
+        PutLhsVar();
+        return 0;
+    }
+    else
+    {
+        Scierror(999, _("%s: Wrong value for input argument #%d: '%s', '%s' , '%s', '%s' '%s' or '%s' expected.\n"), fname, 1, SEPARATOR_FIELDNAME, DECIMAL_FIELDNAME, CONVERSION_FIELDNAME, COMMENTSREGEXP_FIELDNAME, EOL_FIELDNAME, BLANK_FIELDNAME);
+        if (fieldname)
+        {
+            FREE(fieldname);
+            fieldname = NULL;
+        }
+        return 0;
+    }
+
+    if (fieldname)
+    {
+        FREE(fieldname);
+        fieldname = NULL;
+    }
+
+    createSingleString(pvApiCtx, Rhs + 1, fieldvalue);
+
+    if (fieldvalue)
+    {
+        FREE(fieldvalue);
+        fieldvalue = NULL;
+    }
+
+    LhsVar(1) = Rhs + 1;
+    PutLhsVar();
+
+    return 0;
+}
+// =============================================================================
+static int sci_csvDefault_two_rhs(char *fname)
+{
+    int iErr = 0;
+    int resultSet = 0;
+
+    char *fieldname = NULL;
+    char *fieldvalue = NULL;
+    int  ifieldvalue = 0;
+
+    fieldname = csv_getArgumentAsString(pvApiCtx, 1, fname, &iErr);
+    if (iErr) return 0;
+
+    if (strcmp(fieldname, PRECISION_FIELDNAME) == 0)
+    {
+        if (csv_isEmpty(pvApiCtx, 2))
+        {
+            if (fieldname)
+            {
+                FREE(fieldname);
+                fieldname = NULL;
+            }
+            Scierror(999, _("%s: Wrong type for input argument #%d: A double expected.\n"), fname, 2);
+            return 0;
+        }
+
+        if (csv_isDoubleScalar(pvApiCtx, 2))
+        {
+#define FORMAT_FIELDVALUESTR "%%.%dlg"
+            ifieldvalue = (int) csv_getArgumentAsScalarDouble(pvApiCtx, 2, fname, &iErr);
+            if (iErr)
+            {
+                if (fieldname)
+                {
+                    FREE(fieldname);
+                    fieldname = NULL;
+                }
+                return 0;
+            }
+
+            if ((ifieldvalue < 1) || (ifieldvalue > 17))
+            {
+                if (fieldname)
+                {
+                    FREE(fieldname);
+                    fieldname = NULL;
+                }
+                Scierror(999, _("%s: Wrong value for input argument #%d: A double (value 1 to 17) expected.\n"), fname, 2);
+                return 0;
+            }
+
+            fieldvalue = (char*)MALLOC(sizeof(char) * ((int)strlen(FORMAT_FIELDVALUESTR) + 1));
+            if (fieldvalue == NULL)
+            {
+                if (fieldname)
+                {
+                    FREE(fieldname);
+                    fieldname = NULL;
+                }
+                Scierror(999, _("%s: Memory allocation error.\n"), fname);
+                return 0;
+            }
+            sprintf(fieldvalue, FORMAT_FIELDVALUESTR, ifieldvalue);
+        }
+        else
+        {
+            fieldvalue = csv_getArgumentAsString(pvApiCtx, 2, fname, &iErr);
+            if (iErr)
+            {
+                if (fieldname)
+                {
+                    FREE(fieldname);
+                    fieldname = NULL;
+                }
+                return 0;
+            }
+        }
+    }
+    else
+    {
+        fieldvalue = csv_getArgumentAsString(pvApiCtx, 2, fname, &iErr);
+        if (iErr)
+        {
+            if (fieldname)
+            {
+                FREE(fieldname);
+                fieldname = NULL;
+            }
+            return 0;
+        }
+    }
+
+    if (strcmp(fieldname, SEPARATOR_FIELDNAME) == 0)
+    {
+        resultSet = setCsvDefaultSeparator(fieldvalue);
+    }
+    else if (strcmp(fieldname, DECIMAL_FIELDNAME) == 0)
+    {
+        resultSet = setCsvDefaultDecimal(fieldvalue);
+    }
+    else if (strcmp(fieldname, CONVERSION_FIELDNAME) == 0)
+    {
+        resultSet = setCsvDefaultConversion(fieldvalue);
+    }
+    else if (strcmp(fieldname, PRECISION_FIELDNAME) == 0)
+    {
+        resultSet = setCsvDefaultPrecision(fieldvalue);
+    }
+    else if (strcmp(fieldname, COMMENTSREGEXP_FIELDNAME) == 0)
+    {
+        resultSet = setCsvDefaultCommentsRegExp(fieldvalue);
+    }
+    else if (strcmp(fieldname, EOL_FIELDNAME) == 0)
+    {
+        if (strcmp(fieldvalue, MACOS9_EOL_STRING) == 0)
+        {
+            resultSet = setCsvDefaultEOL(MACOS9_EOL);
+        }
+        else if (strcmp(fieldvalue, WINDOWS_EOL_STRING) == 0)
+        {
+            resultSet = setCsvDefaultEOL(WINDOWS_EOL);
+        }
+        else if (strcmp(fieldvalue, LINUX_EOL_STRING) == 0)
+        {
+            resultSet = setCsvDefaultEOL(LINUX_EOL);
+        }
+        else
+        {
+            resultSet = 1;
+        }
+    }
+    else if (strcmp(fieldname, ENCODING_FIELDNAME) == 0)
+    {
+        resultSet = setCsvDefaultEncoding(fieldvalue);
+    }
+    else if (strcmp(fieldname, BLANK_FIELDNAME) == 0)
+    {
+        resultSet = setCsvDefaultCsvIgnoreBlankLine(fieldvalue);
+    }
+    else
+    {
+        Scierror(999, _("%s: Wrong value for input argument #%d: '%s', '%s' ,'%s' , '%s', '%s', '%s', '%s' or '%s' expected.\n"), fname, 1, SEPARATOR_FIELDNAME, DECIMAL_FIELDNAME, CONVERSION_FIELDNAME, PRECISION_FIELDNAME, COMMENTSREGEXP_FIELDNAME, EOL_FIELDNAME, ENCODING_FIELDNAME, BLANK_FIELDNAME);
+        if (fieldname)
+        {
+            FREE(fieldname);
+            fieldname = NULL;
+        }
+        if (fieldvalue)
+        {
+            FREE(fieldvalue);
+            fieldvalue = NULL;
+        }
+        return 0;
+    }
+
+    createScalarBoolean(pvApiCtx, Rhs + 1, (resultSet == 0));
+
+    if (fieldname)
+    {
+        FREE(fieldname);
+        fieldname = NULL;
+    }
+    if (fieldvalue)
+    {
+        FREE(fieldvalue);
+        fieldvalue = NULL;
+    }
+
+    LhsVar(1) = Rhs + 1;
+    PutLhsVar();
+
+    return 0;
+}
+// =============================================================================
diff --git a/scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvIsnum.cpp b/scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvIsnum.cpp
new file mode 100644 (file)
index 0000000..c6f6bf1
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - 2012 - INRIA - Allan CORNET
+ * Copyright (C) 2011 - INRIA - Michael Baudin
+ *
+ * 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
+ *
+ * This code is also published under the GPL v3 license.
+ *
+ */
+#include "gw_csv_tools.h"
+#include "api_scilab.h"
+#include "localization.h"
+#include "Scierror.h"
+#include "csvIsnum.h"
+#include "MALLOC.h"
+// =============================================================================
+int sci_csvIsnum(char *fname)
+{
+    SciErr sciErr;
+    int *piAddressVarOne = NULL;
+    int mOne = 0, nOne = 0;
+    char **pStrs = NULL;
+    BOOL *bRESULT = NULL;
+
+    CheckRhs(1, 1);
+    CheckLhs(0, 1);
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return 0;
+    }
+
+    if (!isStringType(pvApiCtx, piAddressVarOne))
+    {
+        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of string expected.\n"), fname, 1);
+        return 0;
+    }
+
+    if (getAllocatedMatrixOfString(pvApiCtx, piAddressVarOne, &mOne, &nOne, &pStrs) != 0)
+    {
+        Scierror(999, _("%s: No more memory.\n"), fname);
+        return 0;
+    }
+
+    bRESULT = csv_isNumMatrix((const char**)pStrs, mOne, nOne);
+
+    freeAllocatedMatrixOfString(mOne, nOne, pStrs);
+    pStrs = NULL;
+
+    if (bRESULT == NULL)
+    {
+        Scierror(999, _("%s: No more memory.\n"), fname);
+        return 0;
+    }
+
+    sciErr = createMatrixOfBoolean(pvApiCtx, Rhs + 1, mOne, nOne, (const int*)bRESULT);
+    FREE(bRESULT);
+    bRESULT = NULL;
+
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return 0;
+    }
+
+    LhsVar(1) = Rhs + 1;
+    PutLhsVar();
+    return 0;
+}
+// =============================================================================
diff --git a/scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvRead.cpp b/scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvRead.cpp
new file mode 100644 (file)
index 0000000..ae50a34
--- /dev/null
@@ -0,0 +1,552 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - 2012 - INRIA - Allan CORNET
+ * Copyright (C) 2011 - INRIA - Michael Baudin
+ *
+ * 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
+ *
+ * This code is also published under the GPL v3 license.
+ *
+ */
+#include <string.h>
+#include "gw_csv_tools.h"
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "localization.h"
+extern "C" {
+#include "freeArrayOfString.h"
+};
+#include "MALLOC.h"
+#include "csvRead.h"
+#ifdef _MSC_VER
+#include "strdup_windows.h"
+#endif
+#include "stringToComplex.h"
+#include "csvDefault.h"
+#include "csv_complex.h"
+#include "gw_csv_helpers.h"
+#include "getRange.h"
+/* ==================================================================== */
+#define CONVTOSTR "string"
+#define CONVTODOUBLE "double"
+/* ==================================================================== */
+/* csvRead(filename, separator, decimal, conversion, substitute, range)*/
+/* ==================================================================== */
+int sci_csvRead(char *fname)
+{
+    SciErr sciErr;
+    int iErr = 0;
+
+    char *filename = NULL;
+    char *separator = NULL;
+    char *decimal = NULL;
+    char *conversion = NULL;
+    int *iRange = NULL;
+    int haveRange = 0;
+
+    char **toreplace = NULL;
+    int nbElementsToReplace = 0;
+
+    char *regexp = NULL;
+
+    csvResult *result = NULL;
+
+    double *dRealValues = NULL;
+
+    CheckRhs(1, 7);
+    CheckLhs(1, 2);
+
+    if (Rhs == 7)
+    {
+        int m7 = 0, n7 = 0;
+
+        iRange = csv_getArgumentAsMatrixofIntFromDouble(pvApiCtx, 7, fname, &m7, &n7, &iErr);
+        if (iErr) return 0;
+
+        if ((m7 * n7 != SIZE_RANGE_SUPPORTED) )
+        {
+            if (iRange)
+            {
+                FREE(iRange);
+                iRange = NULL;
+            }
+            Scierror(999, _("%s: Wrong size for input argument #%d: Four entries expected.\n"), fname, 7);
+            return 0;
+        }
+
+        if ((m7 != 1) && (n7 != 1))
+        {
+            if (iRange)
+            {
+                FREE(iRange);
+                iRange = NULL;
+            }
+            Scierror(999, _("%s: Wrong size for input argument #%d: A column or row vector expected.\n"), fname, 7);
+            return 0;
+        }
+
+        if (isValidRange(iRange, m7 * n7))
+        {
+            haveRange = 1;
+        }
+        else
+        {
+            if (iRange)
+            {
+                FREE(iRange);
+                iRange = NULL;
+            }
+            Scierror(999, _("%s: Wrong value for input argument #%d: Unconsistent range.\n"), fname, 7);
+            return 0;
+        }
+    }
+
+
+    if (Rhs >= 6)
+    {
+        regexp = csv_getArgumentAsStringWithEmptyManagement(pvApiCtx, 6, fname, getCsvDefaultCommentsRegExp(), &iErr);
+        if (regexp)
+        {
+            if (strcmp(regexp, "") == 0)
+            {
+                FREE(regexp);
+                regexp = NULL;
+            }
+        }
+        if (iErr) return 0;
+    }
+    else
+    {
+        regexp = strdup(getCsvDefaultCommentsRegExp());
+        if (regexp)
+        {
+            if (strcmp(regexp, "") == 0)
+            {
+                FREE(regexp);
+                regexp = NULL;
+            }
+        }
+    }
+
+    if (Rhs >= 5)
+    {
+        if (csv_isEmpty(pvApiCtx, 5))
+        {
+            toreplace = NULL;
+            nbElementsToReplace = 0;
+        }
+        else
+        {
+            int m5 = 0, n5 = 0;
+            toreplace = csv_getArgumentAsMatrixOfString(pvApiCtx, 5, fname, &m5, &n5, &iErr);
+            if (iErr)
+            {
+                if (regexp)
+                {
+                    FREE(regexp);
+                    regexp = NULL;
+                }
+                return 0;
+            }
+
+            if (n5 != 2)
+            {
+                if (regexp)
+                {
+                    FREE(regexp);
+                    regexp = NULL;
+                }
+                freeArrayOfString(toreplace, m5 * n5);
+                toreplace = NULL;
+                Scierror(999, _("%s: Wrong size for input argument #%d.\n"), fname, 5);
+                return 0;
+            }
+            nbElementsToReplace = m5;
+        }
+    }
+    else
+    {
+        toreplace = NULL;
+        nbElementsToReplace = 0;
+    }
+
+    if (Rhs >= 4)
+    {
+        int iErr = 0;
+        conversion = csv_getArgumentAsStringWithEmptyManagement(pvApiCtx, 4, fname, getCsvDefaultConversion(), &iErr);
+        if (iErr) return 0;
+        if (!((strcmp(conversion, CONVTOSTR) == 0) || (strcmp(conversion, CONVTODOUBLE) == 0)))
+        {
+            if (regexp)
+            {
+                FREE(regexp);
+                regexp = NULL;
+            }
+            if (toreplace)
+            {
+                freeArrayOfString(toreplace, nbElementsToReplace * 2);
+                toreplace = NULL;
+            }
+            if (conversion)
+            {
+                FREE(conversion);
+                conversion = NULL;
+            }
+            Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' string expected.\n"), fname, 4, "double", "string");
+            return 0;
+        }
+    }
+    else
+    {
+        conversion = strdup(getCsvDefaultConversion());
+    }
+
+    if (Rhs >= 3)
+    {
+        int iErr = 0;
+        decimal = csv_getArgumentAsStringWithEmptyManagement(pvApiCtx, 3, fname, getCsvDefaultDecimal(), &iErr);
+        if (iErr)
+        {
+            if (regexp)
+            {
+                FREE(regexp);
+                regexp = NULL;
+            }
+            if (conversion)
+            {
+                FREE(conversion);
+                conversion = NULL;
+            }
+            if (toreplace)
+            {
+                freeArrayOfString(toreplace, nbElementsToReplace * 2);
+                toreplace = NULL;
+            }
+            return 0;
+        }
+    }
+    else
+    {
+        decimal = strdup(getCsvDefaultDecimal());
+    }
+
+    if (Rhs >= 2)
+    {
+        int iErr = 0;
+        separator = csv_getArgumentAsStringWithEmptyManagement(pvApiCtx, 2, fname, getCsvDefaultSeparator(), &iErr);
+        if (iErr)
+        {
+            if (regexp)
+            {
+                FREE(regexp);
+                regexp = NULL;
+            }
+            if (toreplace)
+            {
+                freeArrayOfString(toreplace, nbElementsToReplace * 2);
+                toreplace = NULL;
+            }
+            if (conversion)
+            {
+                FREE(conversion);
+                conversion = NULL;
+            }
+            if (decimal)
+            {
+                FREE(decimal);
+                decimal = NULL;
+            }
+            return 0;
+        }
+    }
+    else
+    {
+        separator = strdup(getCsvDefaultSeparator());
+    }
+
+    if (strcmp(separator, "\\t") == 0)
+    {
+        /* In Scilab, if the user is providing \t as separator, transform it to a real
+           tab. Example: read_csv(filename,"\t");
+        */
+        strcpy(separator, "\t");
+    }
+
+
+    filename = csv_getArgumentAsString(pvApiCtx, 1, fname, &iErr);
+    if (iErr)
+    {
+        if (regexp)
+        {
+            FREE(regexp);
+            regexp = NULL;
+        }
+        if (toreplace)
+        {
+            freeArrayOfString(toreplace, nbElementsToReplace * 2);
+            toreplace = NULL;
+        }
+        if (separator)
+        {
+            FREE(separator);
+            separator = NULL;
+        }
+        if (conversion)
+        {
+            FREE(conversion);
+            conversion = NULL;
+        }
+        if (decimal)
+        {
+            FREE(decimal);
+            decimal = NULL;
+        }
+        return 0;
+    }
+
+    result = csvRead(filename, separator, decimal, (const char**)toreplace, nbElementsToReplace * 2, regexp);
+    if (regexp)
+    {
+        FREE(regexp);
+        regexp = NULL;
+    }
+    if (toreplace)
+    {
+        freeArrayOfString(toreplace, nbElementsToReplace * 2);
+        toreplace = NULL;
+    }
+    if (separator)
+    {
+        FREE(separator);
+        separator = NULL;
+    }
+    if (decimal)
+    {
+        FREE(decimal);
+        decimal = NULL;
+    }
+
+    if (result)
+    {
+        switch (result->err)
+        {
+            case CSV_READ_REGEXP_ERROR:
+            {
+                Scierror(999, _("%s: Wrong value for input argument #%d.\n"), fname, 6);
+            }
+            break;
+
+            case CSV_READ_SEPARATOR_DECIMAL_EQUAL:
+            {
+                Scierror(999, _("%s: separator and decimal must have different values.\n"), fname);
+            }
+            break;
+
+            case CSV_READ_NO_ERROR:
+            {
+                if (strcmp(conversion, CONVTOSTR) == 0)
+                {
+                    if (haveRange)
+                    {
+                        int newM = 0;
+                        int newN = 0;
+
+                        char **pStrRange = getRangeAsString((const char**)result->pstrValues, result->m, result->n, iRange, &newM, &newN);
+                        if (pStrRange)
+                        {
+                            sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, newM, newN, pStrRange);
+                            freeArrayOfString(pStrRange, newM * newN);
+                        }
+                        else
+                        {
+                            Scierror(999, _("%s: Memory allocation error.\n"), fname);
+                        }
+                    }
+                    else
+                    {
+                        sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, result->m, result->n, result->pstrValues);
+                    }
+                }
+                else /* to double */
+                {
+                    stringToComplexError ierr = STRINGTOCOMPLEX_ERROR;
+                    csv_complexArray *ptrCsvComplexArray = stringsToCvsComplexArray((const char**)result->pstrValues, result->m * result->n, decimal, TRUE, &ierr);
+
+                    if (ptrCsvComplexArray == NULL)
+                    {
+                        freeCsvResult(result);
+                        if (filename)
+                        {
+                            FREE(filename);
+                            filename = NULL;
+                        }
+                        if (conversion)
+                        {
+                            FREE(conversion);
+                            conversion = NULL;
+                        }
+                        if (ierr == STRINGTOCOMPLEX_ERROR)
+                        {
+                            Scierror(999, _("%s: can not convert data.\n"), fname);
+                        }
+                        else
+                        {
+                            Scierror(999, _("%s: Memory allocation error.\n"), fname);
+                        }
+                        return 0;
+                    }
+
+                    switch (ierr)
+                    {
+                        case STRINGTOCOMPLEX_NOT_A_NUMBER:
+                        case STRINGTOCOMPLEX_NO_ERROR:
+                        {
+                            if (haveRange)
+                            {
+                                int newM = 0;
+                                int newN = 0;
+                                csv_complexArray *csvComplexRange = getRangeAsCsvComplexArray(ptrCsvComplexArray, result->m, result->n, iRange, &newM, &newN);
+                                if (csvComplexRange)
+                                {
+                                    if (csvComplexRange->isComplex)
+                                    {
+                                        sciErr = createComplexMatrixOfDouble(pvApiCtx, Rhs + 1, newM, newN, ptrCsvComplexArray->realPart, ptrCsvComplexArray->imagPart);
+                                    }
+                                    else
+                                    {
+                                        sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, newM, newN, csvComplexRange->realPart);
+                                    }
+                                    freeCsvComplexArray(csvComplexRange);
+                                    csvComplexRange = NULL;
+                                }
+                                else
+                                {
+                                    Scierror(999, _("%s: Memory allocation error.\n"), fname);
+                                }
+                            }
+                            else
+                            {
+                                if (ptrCsvComplexArray->isComplex)
+                                {
+                                    sciErr = createComplexMatrixOfDouble(pvApiCtx, Rhs + 1, result->m, result->n, ptrCsvComplexArray->realPart, ptrCsvComplexArray->imagPart);
+                                }
+                                else
+                                {
+                                    sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, result->m, result->n, ptrCsvComplexArray->realPart);
+                                }
+                                freeCsvComplexArray(ptrCsvComplexArray);
+                                ptrCsvComplexArray = NULL;
+                            }
+                        }
+                        break;
+
+                        case STRINGTOCOMPLEX_MEMORY_ALLOCATION:
+                        {
+                            Scierror(999, _("%s: Memory allocation error.\n"), fname);
+                        }
+                        default:
+                        case STRINGTOCOMPLEX_ERROR:
+                        {
+                            Scierror(999, _("%s: can not convert data.\n"), fname);
+                        }
+                    }
+                }
+
+                if (sciErr.iErr)
+                {
+                    freeCsvResult(result);
+                    if (filename)
+                    {
+                        FREE(filename);
+                        filename = NULL;
+                    }
+                    if (conversion)
+                    {
+                        FREE(conversion);
+                        conversion = NULL;
+                    }
+                    printError(&sciErr, 0);
+                    Scierror(17, _("%s: Memory allocation error.\n"), fname);
+                    return 0;
+                }
+                else
+                {
+                    LhsVar(1) = Rhs + 1;
+
+                    if (Lhs == 2)
+                    {
+                        sciErr = createMatrixOfString(pvApiCtx, Rhs + 2, result->nbComments, 1, result->pstrComments);
+                        if (sciErr.iErr)
+                        {
+                            freeCsvResult(result);
+                            if (filename)
+                            {
+                                FREE(filename);
+                                filename = NULL;
+                            }
+                            if (conversion)
+                            {
+                                FREE(conversion);
+                                conversion = NULL;
+                            }
+                            printError(&sciErr, 0);
+                            Scierror(17, _("%s: Memory allocation error.\n"), fname);
+                            return 0;
+                        }
+                        LhsVar(2) = Rhs + 2;
+                    }
+                    PutLhsVar();
+                }
+            }
+            break;
+
+            case CSV_READ_FILE_NOT_EXIST:
+            {
+                Scierror(999, _("%s: %s does not exist.\n"), fname, filename);
+            }
+            break;
+
+            case CSV_READ_MOPEN_ERROR:
+            {
+                Scierror(999, _("%s: can not open file %s.\n"), fname, filename);
+            }
+            break;
+
+            case CSV_READ_MEMORY_ALLOCATION:
+            {
+                Scierror(999, _("%s: Memory allocation error.\n"), fname);
+            }
+            break;
+
+            case CSV_READ_READLINES_ERROR:
+            case CSV_READ_COLUMNS_ERROR:
+            case CSV_READ_ERROR:
+            {
+                Scierror(999, _("%s: can not read file %s.\n"), fname, filename);
+            }
+            break;
+        }
+    }
+    else
+    {
+        Scierror(999, _("%s: Memory allocation error.\n"), fname);
+    }
+    freeCsvResult(result);
+    if (filename)
+    {
+        FREE(filename);
+        filename = NULL;
+    }
+    if (conversion)
+    {
+        FREE(conversion);
+        conversion = NULL;
+    }
+
+    return 0;
+}
+/* ==================================================================== */
diff --git a/scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvStringToDouble.cpp b/scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvStringToDouble.cpp
new file mode 100644 (file)
index 0000000..56b63c2
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - 2012 - INRIA - Allan CORNET
+ * Copyright (C) 2011 - INRIA - Michael Baudin
+ *
+ * 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
+ *
+ * This code is also published under the GPL v3 license.
+ *
+ */
+#include <string.h>
+#include "gw_csv_tools.h"
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "MALLOC.h"
+#include "Scierror.h"
+#include "localization.h"
+extern "C" {
+#include "freeArrayOfString.h"
+};
+#ifdef _MSC_VER
+#include "strdup_windows.h"
+#endif
+#include "stringToComplex.h"
+#include "csvDefault.h"
+#include "gw_csv_helpers.h"
+#include "csv_complex.h"
+// =============================================================================
+int sci_csvStringToDouble(char *fname)
+{
+    SciErr sciErr;
+    int iErr = 0;
+    int m1 = 0, n1 = 0;
+    char **pStringValues = NULL;
+
+    BOOL bConvertToNan = TRUE;
+
+    csv_complexArray *ptrCsvComplexArray = NULL;
+    stringToComplexError ierr = STRINGTOCOMPLEX_ERROR;
+
+    CheckRhs(1, 2);
+    CheckLhs(1, 1);
+
+    if (Rhs == 1)
+    {
+        bConvertToNan = TRUE;
+    }
+    else /* Rhs == 2 */
+    {
+        bConvertToNan = (BOOL)csv_getArgumentAsScalarBoolean(pvApiCtx, 2, fname, &iErr);
+        if (iErr) return 0;
+    }
+
+    pStringValues = csv_getArgumentAsMatrixOfString(pvApiCtx, 1, fname, &m1, &n1, &iErr);
+    if (iErr) return 0;
+
+    ptrCsvComplexArray = stringsToCvsComplexArray((const char**)pStringValues, m1 * n1, getCsvDefaultDecimal(), bConvertToNan, &ierr);
+
+    freeArrayOfString(pStringValues, m1 * n1);
+    pStringValues = NULL;
+
+    if (ptrCsvComplexArray == NULL)
+    {
+        switch (ierr)
+        {
+            case STRINGTOCOMPLEX_NOT_A_NUMBER:
+            case STRINGTOCOMPLEX_ERROR:
+                Scierror(999, _("%s: can not convert data.\n"), fname);
+                return 0;
+
+            default:
+                Scierror(999, _("%s: Memory allocation error.\n"), fname);
+                return 0;
+        }
+    }
+
+    switch (ierr)
+    {
+        case STRINGTOCOMPLEX_NOT_A_NUMBER:
+        case STRINGTOCOMPLEX_NO_ERROR:
+        {
+            if (ptrCsvComplexArray->isComplex)
+            {
+                sciErr = createComplexMatrixOfDouble(pvApiCtx, Rhs + 1, m1, n1, ptrCsvComplexArray->realPart, ptrCsvComplexArray->imagPart);
+            }
+            else
+            {
+                sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, m1, n1, ptrCsvComplexArray->realPart);
+            }
+            freeCsvComplexArray(ptrCsvComplexArray);
+            ptrCsvComplexArray = NULL;
+        }
+        break;
+
+        case STRINGTOCOMPLEX_MEMORY_ALLOCATION:
+        {
+            Scierror(999, _("%s: Memory allocation error.\n"), fname);
+        }
+
+        default:
+        case STRINGTOCOMPLEX_ERROR:
+        {
+            Scierror(999, _("%s: can not convert data.\n"), fname);
+        }
+    }
+
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+    }
+    else
+    {
+        LhsVar(1) = Rhs + 1;
+        PutLhsVar();
+    }
+
+    return 0;
+}
+// =============================================================================
+
diff --git a/scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvTextScan.cpp b/scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvTextScan.cpp
new file mode 100644 (file)
index 0000000..072560c
--- /dev/null
@@ -0,0 +1,463 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - 2012 - INRIA - Allan CORNET
+ * Copyright (C) 2011 - INRIA - Michael Baudin
+ *
+ * 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
+ *
+ * This code is also published under the GPL v3 license.
+ *
+ */
+#include <string.h>
+#include "gw_csv_tools.h"
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "MALLOC.h"
+#include "Scierror.h"
+#include "localization.h"
+extern "C" {
+#include "freeArrayOfString.h"
+};
+#ifdef _MSC_VER
+#include "strdup_windows.h"
+#endif
+#include "stringToComplex.h"
+#include "csvDefault.h"
+#include "csvRead.h"
+#include "getRange.h"
+#include "gw_csv_helpers.h"
+// =============================================================================
+#define CONVTOSTR "string"
+#define CONVTODOUBLE "double"
+// =============================================================================
+int sci_csvTextScan(char *fname)
+{
+    SciErr sciErr;
+    int iErr = 0;
+    int i = 0;
+
+    int *piAddressVarOne = NULL;
+    int m1 = 0, n1 = 0;
+    int iType1 = 0;
+
+    char **text = NULL;
+    int *lengthText = NULL;
+    int nbLines = 0;
+
+    char *separator = NULL;
+    char *decimal = NULL;
+    char *conversion = NULL;
+
+    double * dRealValues = NULL;
+
+    int *iRange = NULL;
+    int haveRange = 0;
+
+    csvResult *result = NULL;
+
+    CheckRhs(1, 5);
+    CheckLhs(1, 1);
+
+    if (Rhs == 5)
+    {
+        int m5 = 0, n5 = 0;
+
+        iRange = csv_getArgumentAsMatrixofIntFromDouble(pvApiCtx, 5, fname, &m5, &n5, &iErr);
+        if (iErr) return 0;
+
+        if ((m5 * n5 != SIZE_RANGE_SUPPORTED) )
+        {
+            if (iRange)
+            {
+                FREE(iRange);
+                iRange = NULL;
+            }
+            Scierror(999, _("%s: Wrong size for input argument #%d: Four entries expected.\n"), fname, 5);
+            return 0;
+        }
+
+        if ((m5 != 1) && (n5 != 1))
+        {
+            if (iRange)
+            {
+                FREE(iRange);
+                iRange = NULL;
+            }
+            Scierror(999, _("%s: Wrong size for input argument #%d: A column or row vector expected.\n"), fname, 5);
+            return 0;
+        }
+
+        if (isValidRange(iRange, m5 * n5))
+        {
+            haveRange = 1;
+        }
+        else
+        {
+            if (iRange)
+            {
+                FREE(iRange);
+                iRange = NULL;
+            }
+            Scierror(999, _("%s: Wrong value for input argument #%d: Unconsistent range.\n"), fname, 5);
+            return 0;
+        }
+    }
+
+    if (Rhs >= 4)
+    {
+        conversion = csv_getArgumentAsStringWithEmptyManagement(pvApiCtx, 4, fname, getCsvDefaultConversion(), &iErr);
+        if (iErr)
+        {
+            if (iRange)
+            {
+                FREE(iRange);
+                iRange = NULL;
+            }
+            return 0;
+        }
+
+        if (!((strcmp(conversion, CONVTOSTR) == 0) || (strcmp(conversion, CONVTODOUBLE) == 0)))
+        {
+            if (iRange)
+            {
+                FREE(iRange);
+                iRange = NULL;
+            }
+            if (conversion)
+            {
+                FREE(conversion);
+                conversion = NULL;
+            }
+
+            Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' string expected.\n"), fname, 4, "double", "string");
+            return 0;
+        }
+    }
+    else
+    {
+        conversion = strdup(getCsvDefaultConversion());
+    }
+
+    if (Rhs >= 3)
+    {
+        decimal = csv_getArgumentAsStringWithEmptyManagement(pvApiCtx, 3, fname, getCsvDefaultDecimal(), &iErr);
+        if (iErr)
+        {
+            if (iRange)
+            {
+                FREE(iRange);
+                iRange = NULL;
+            }
+            if (conversion)
+            {
+                FREE(conversion);
+                conversion = NULL;
+            }
+            return 0;
+        }
+    }
+    else
+    {
+        decimal = strdup(getCsvDefaultDecimal());
+    }
+
+    if (Rhs >= 2)
+    {
+        separator = csv_getArgumentAsStringWithEmptyManagement(pvApiCtx, 2, fname, getCsvDefaultSeparator(), &iErr);
+        if (iErr)
+        {
+            if (iRange)
+            {
+                FREE(iRange);
+                iRange = NULL;
+            }
+            if (decimal)
+            {
+                FREE(decimal);
+                decimal = NULL;
+            }
+            if (conversion)
+            {
+                FREE(conversion);
+                conversion = NULL;
+            }
+            return 0;
+        }
+    }
+    else
+    {
+        separator = strdup(getCsvDefaultSeparator());
+    }
+
+    if (!csv_isRowVector(pvApiCtx, 1) &&
+            !csv_isColumnVector(pvApiCtx, 1) &&
+            !csv_isScalar(pvApiCtx, 1))
+    {
+        if (iRange)
+        {
+            FREE(iRange);
+            iRange = NULL;
+        }
+        if (separator)
+        {
+            FREE(separator);
+            separator = NULL;
+        }
+        if (decimal)
+        {
+            FREE(decimal);
+            decimal = NULL;
+        }
+        if (conversion)
+        {
+            FREE(conversion);
+            conversion = NULL;
+        }
+        Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 1);
+        return 0;
+    }
+
+    text = csv_getArgumentAsMatrixOfString(pvApiCtx, 1, fname, &m1, &n1, &iErr);
+    if (iErr)
+    {
+        if (iRange)
+        {
+            FREE(iRange);
+            iRange = NULL;
+        }
+        if (separator)
+        {
+            FREE(separator);
+            separator = NULL;
+        }
+        if (decimal)
+        {
+            FREE(decimal);
+            decimal = NULL;
+        }
+        if (conversion)
+        {
+            FREE(conversion);
+            conversion = NULL;
+        }
+        return 0;
+    }
+
+    nbLines = m1 * n1;
+    result = csvTextScan((const char**)text, nbLines, separator, decimal);
+
+    if (text)
+    {
+        if (separator)
+        {
+            FREE(separator);
+            separator = NULL;
+        }
+        freeArrayOfString(text, nbLines);
+        text = NULL;
+    }
+
+    if (separator)
+    {
+        FREE(separator);
+        separator = NULL;
+    }
+
+    if (result)
+    {
+        switch (result->err)
+        {
+            case CSV_READ_SEPARATOR_DECIMAL_EQUAL:
+            {
+                Scierror(999, _("%s: separator and decimal must have different values.\n"), fname);
+            }
+            break;
+
+            case CSV_READ_NO_ERROR:
+            {
+                if (strcmp(conversion, CONVTOSTR) == 0)
+                {
+                    if (haveRange)
+                    {
+                        int newM = 0;
+                        int newN = 0;
+
+                        char **pStrRange = getRangeAsString((const char**)result->pstrValues, result->m, result->n, iRange, &newM, &newN);
+                        if (pStrRange)
+                        {
+                            sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, newM, newN, pStrRange);
+                            freeArrayOfString(pStrRange, newM * newN);
+                        }
+                        else
+                        {
+                            Scierror(999, _("%s: Memory allocation error.\n"), fname);
+                        }
+
+                    }
+                    else
+                    {
+                        sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, result->m, result->n, result->pstrValues);
+                    }
+                }
+                else /* to double */
+                {
+                    stringToComplexError ierr = STRINGTOCOMPLEX_ERROR;
+                    csv_complexArray *ptrCsvComplexArray = stringsToCvsComplexArray((const char**)result->pstrValues, result->m * result->n, decimal, TRUE, &ierr);
+                    if (ptrCsvComplexArray == NULL)
+                    {
+                        freeCsvResult(result);
+                        if (decimal)
+                        {
+                            FREE(decimal);
+                            decimal = NULL;
+                        }
+                        if (conversion)
+                        {
+                            FREE(conversion);
+                            conversion = NULL;
+                        }
+                        if (iRange)
+                        {
+                            FREE(iRange);
+                            iRange = NULL;
+                        }
+                        if (ierr == STRINGTOCOMPLEX_ERROR)
+                        {
+                            Scierror(999, _("%s: can not convert data.\n"), fname);
+                        }
+                        else
+                        {
+                            Scierror(999, _("%s: Memory allocation error.\n"), fname);
+                        }
+                        return 0;
+                    }
+
+                    switch (ierr)
+                    {
+                        case STRINGTOCOMPLEX_NOT_A_NUMBER:
+                        case STRINGTOCOMPLEX_NO_ERROR:
+                        {
+                            if (haveRange)
+                            {
+                                int newM = 0;
+                                int newN = 0;
+                                csv_complexArray *csvComplexRange = getRangeAsCsvComplexArray(ptrCsvComplexArray, result->m, result->n, iRange, &newM, &newN);
+                                if (csvComplexRange)
+                                {
+                                    if (csvComplexRange->isComplex)
+                                    {
+                                        sciErr = createComplexMatrixOfDouble(pvApiCtx, Rhs + 1, newM, newN, ptrCsvComplexArray->realPart, ptrCsvComplexArray->imagPart);
+                                    }
+                                    else
+                                    {
+                                        sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, newM, newN, csvComplexRange->realPart);
+                                    }
+                                    freeCsvComplexArray(csvComplexRange);
+                                    csvComplexRange = NULL;
+                                }
+                                else
+                                {
+                                    Scierror(999, _("%s: Memory allocation error.\n"), fname);
+                                }
+                            }
+                            else
+                            {
+                                if (ptrCsvComplexArray->isComplex)
+                                {
+                                    sciErr = createComplexMatrixOfDouble(pvApiCtx, Rhs + 1, result->m, result->n, ptrCsvComplexArray->realPart, ptrCsvComplexArray->imagPart);
+                                }
+                                else
+                                {
+                                    sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, result->m, result->n, ptrCsvComplexArray->realPart);
+                                }
+                            }
+                            freeCsvComplexArray(ptrCsvComplexArray);
+                            ptrCsvComplexArray = NULL;
+                        }
+                        break;
+
+                        case STRINGTOCOMPLEX_MEMORY_ALLOCATION:
+                        {
+                            Scierror(999, _("%s: Memory allocation error.\n"), fname);
+                        }
+                        default:
+                        case STRINGTOCOMPLEX_ERROR:
+                        {
+                            Scierror(999, _("%s: can not convert data.\n"), fname);
+                        }
+                    }
+                }
+
+                if (sciErr.iErr)
+                {
+                    freeCsvResult(result);
+                    if (decimal)
+                    {
+                        FREE(decimal);
+                        decimal = NULL;
+                    }
+                    if (conversion)
+                    {
+                        FREE(conversion);
+                        conversion = NULL;
+                    }
+                    if (iRange)
+                    {
+                        FREE(iRange);
+                        iRange = NULL;
+                    }
+                    printError(&sciErr, 0);
+                    Scierror(17, _("%s: Memory allocation error.\n"), fname);
+                    return 0;
+                }
+                else
+                {
+                    LhsVar(1) = Rhs + 1;
+                    PutLhsVar();
+                }
+            }
+            break;
+
+            case CSV_READ_MEMORY_ALLOCATION:
+            {
+                Scierror(999, _("%s: Memory allocation error.\n"), fname);
+            }
+            break;
+
+            case CSV_READ_READLINES_ERROR:
+            case CSV_READ_COLUMNS_ERROR:
+            case CSV_READ_ERROR:
+            {
+                Scierror(999, _("%s: can not read text.\n"), fname);
+            }
+            break;
+        }
+    }
+    else
+    {
+        Scierror(999, _("%s: Memory allocation error.\n"), fname);
+    }
+    freeCsvResult(result);
+    if (decimal)
+    {
+        FREE(decimal);
+        decimal = NULL;
+    }
+    if (conversion)
+    {
+        FREE(conversion);
+        conversion = NULL;
+    }
+    if (iRange)
+    {
+        FREE(iRange);
+        iRange = NULL;
+    }
+
+    return 0;
+}
+// =============================================================================
diff --git a/scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvWrite.cpp b/scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvWrite.cpp
new file mode 100644 (file)
index 0000000..de07b22
--- /dev/null
@@ -0,0 +1,504 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - 2012 - INRIA - Allan CORNET
+ * Copyright (C) 2011 - INRIA - Michael Baudin
+ *
+ * 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
+ *
+ * This code is also published under the GPL v3 license.
+ *
+ */
+#include <string.h>
+#include <stdio.h>
+#include "gw_csv_tools.h"
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "MALLOC.h"
+#include "csvWrite.h"
+#include "localization.h"
+extern "C" {
+#include "freeArrayOfString.h"
+};
+#ifdef _MSC_VER
+#include "strdup_windows.h"
+#endif
+#include "csvDefault.h"
+#include "checkCsvWriteFormat.h"
+#include "gw_csv_helpers.h"
+// =============================================================================
+// csvWrite(M, filename[, separator, decimal, precision]) */
+// with M string or double (not complex)
+// =============================================================================
+int sci_csvWrite(char *fname)
+{
+    SciErr sciErr;
+    int iErr = 0;
+    csvWriteError csvError = CSV_WRITE_ERROR;
+
+    char *separator = NULL;
+    char *decimal = NULL;
+    char *filename = NULL;
+    char *precisionFormat = NULL;
+    char **pHeadersLines = NULL;
+    int nbHeadersLines = 0;
+
+    char **pStringValues = NULL;
+    double *pDoubleValuesReal = NULL;
+    double *pDoubleValuesImag = NULL;
+    int bIsComplex = 0;
+    int mValues = 0;
+    int nValues = 0;
+
+    int *piAddressVarTwo = NULL;
+    int m2 = 0, n2 = 0;
+    int iType2 = 0;
+
+    int *piAddressVarOne = NULL;
+    int m1 = 0, n1 = 0;
+    int iType1 = 0;
+
+    CheckRhs(2, 6);
+    CheckLhs(1, 1);
+
+    if (Rhs > 5)
+    {
+        int isOnlyRowOrCol = 0;
+        int m6 = 0;
+        int n6 = 0;
+        pHeadersLines = csv_getArgumentAsMatrixOfString(pvApiCtx, 6, fname, &m6, &n6, &iErr);
+        if (iErr) return 0;
+        isOnlyRowOrCol = ((m6 > 1) && (n6 == 1)) || ((m6 == 1) && (n6 > 1)) || ((m6 == 1) && (n6 == 1));
+        if (!isOnlyRowOrCol)
+        {
+            if (pHeadersLines)
+            {
+                freeArrayOfString(pHeadersLines, nbHeadersLines);
+                pHeadersLines = NULL;
+            }
+            Scierror(999, _("%s: Wrong size for input argument #%d: A 1-by-n or m-by-1 array of strings expected.\n"), fname, 6);
+            return 0;
+        }
+        nbHeadersLines = m6 * n6;
+    }
+
+    if (Rhs > 4)
+    {
+        if (csv_isDoubleScalar(pvApiCtx, 5))
+        {
+#define FORMAT_FIELDVALUESTR "%%.%dlg"
+            int iFormatValue = (int) csv_getArgumentAsScalarDouble(pvApiCtx, 5, fname, &iErr);
+            if (iErr)
+            {
+                if (pHeadersLines)
+                {
+                    freeArrayOfString(pHeadersLines, nbHeadersLines);
+                    pHeadersLines = NULL;
+                }
+                return 0;
+            }
+
+            if ((iFormatValue < 1) || (iFormatValue > 17))
+            {
+                Scierror(999, _("%s: Wrong value for input argument #%d: A double (value 1 to 17) expected.\n"), fname, 5);
+                if (pHeadersLines)
+                {
+                    freeArrayOfString(pHeadersLines, nbHeadersLines);
+                    pHeadersLines = NULL;
+                }
+                return 0;
+            }
+
+            precisionFormat = (char*)MALLOC(sizeof(char) * ((int)strlen(FORMAT_FIELDVALUESTR) + 1));
+            if (precisionFormat == NULL)
+            {
+                Scierror(999, _("%s: Memory allocation error.\n"), fname);
+                if (pHeadersLines)
+                {
+                    freeArrayOfString(pHeadersLines, nbHeadersLines);
+                    pHeadersLines = NULL;
+                }
+                return 0;
+            }
+            sprintf(precisionFormat, FORMAT_FIELDVALUESTR, iFormatValue);
+        }
+        else
+        {
+            precisionFormat = csv_getArgumentAsStringWithEmptyManagement(pvApiCtx, 5, fname, getCsvDefaultPrecision(), &iErr);
+            if (iErr) return 0;
+            if (checkCsvWriteFormat(precisionFormat))
+            {
+                Scierror(999, _("%s: Not supported format %s.\n"), fname, precisionFormat);
+                if (precisionFormat)
+                {
+                    FREE(precisionFormat);
+                    precisionFormat = NULL;
+                }
+                if (pHeadersLines)
+                {
+                    freeArrayOfString(pHeadersLines, nbHeadersLines);
+                    pHeadersLines = NULL;
+                }
+                return 0;
+            }
+        }
+    }
+    else
+    {
+        precisionFormat = strdup(getCsvDefaultPrecision());
+    }
+
+    if (Rhs > 3)
+    {
+        decimal = csv_getArgumentAsStringWithEmptyManagement(pvApiCtx, 4, fname, getCsvDefaultDecimal(), &iErr);
+        if (iErr)
+        {
+            if (precisionFormat)
+            {
+                FREE(precisionFormat);
+                precisionFormat = NULL;
+            }
+            if (pHeadersLines)
+            {
+                freeArrayOfString(pHeadersLines, nbHeadersLines);
+                pHeadersLines = NULL;
+            }
+            return 0;
+        }
+
+        if (strcmp(decimal, ".") && strcmp(decimal, ","))
+        {
+            //invalid value
+            Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), "write_csv", 4, ".", ",");
+            return 1;
+        }
+    }
+    else
+    {
+        decimal = strdup(getCsvDefaultDecimal());
+    }
+
+    if (Rhs > 2)
+    {
+        separator = csv_getArgumentAsStringWithEmptyManagement(pvApiCtx, 3, fname, getCsvDefaultSeparator(), &iErr);
+        if (iErr)
+        {
+            if (pHeadersLines)
+            {
+                freeArrayOfString(pHeadersLines, nbHeadersLines);
+                pHeadersLines = NULL;
+            }
+            if (precisionFormat)
+            {
+                FREE(precisionFormat);
+                precisionFormat = NULL;
+            }
+            if (decimal)
+            {
+                FREE(decimal);
+                decimal = NULL;
+            }
+            return 0;
+        }
+    }
+    else
+    {
+        separator = strdup(getCsvDefaultSeparator());
+    }
+
+    filename = csv_getArgumentAsString(pvApiCtx, 2, fname, &iErr);
+    if (iErr)
+    {
+        if (pHeadersLines)
+        {
+            freeArrayOfString(pHeadersLines, nbHeadersLines);
+            pHeadersLines = NULL;
+        }
+        if (separator)
+        {
+            FREE(separator);
+            separator = NULL;
+        }
+        if (precisionFormat)
+        {
+            FREE(precisionFormat);
+            precisionFormat = NULL;
+        }
+        if (decimal)
+        {
+            FREE(decimal);
+            decimal = NULL;
+        }
+        return 0;
+    }
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
+    if (sciErr.iErr)
+    {
+        if (pHeadersLines)
+        {
+            freeArrayOfString(pHeadersLines, nbHeadersLines);
+            pHeadersLines = NULL;
+        }
+        if (filename)
+        {
+            FREE(filename);
+            filename = NULL;
+        }
+        if (precisionFormat)
+        {
+            FREE(precisionFormat);
+            precisionFormat = NULL;
+        }
+        if (decimal)
+        {
+            FREE(decimal);
+            decimal = NULL;
+        }
+        if (separator)
+        {
+            FREE(separator);
+            separator = NULL;
+        }
+        printError(&sciErr, 0);
+        return 0;
+    }
+
+    sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType1);
+    if (sciErr.iErr)
+    {
+        if (pHeadersLines)
+        {
+            freeArrayOfString(pHeadersLines, nbHeadersLines);
+            pHeadersLines = NULL;
+        }
+        if (filename)
+        {
+            FREE(filename);
+            filename = NULL;
+        }
+        if (precisionFormat)
+        {
+            FREE(precisionFormat);
+            precisionFormat = NULL;
+        }
+        if (decimal)
+        {
+            FREE(decimal);
+            decimal = NULL;
+        }
+        if (separator)
+        {
+            FREE(separator);
+            separator = NULL;
+        }
+        printError(&sciErr, 0);
+        return 0;
+    }
+
+    if (iType1 == sci_strings)
+    {
+        pStringValues = csv_getArgumentAsMatrixOfString(pvApiCtx, 1, fname, &m1, &n1, &iErr);
+        if (iErr)
+        {
+            if (pHeadersLines)
+            {
+                freeArrayOfString(pHeadersLines, nbHeadersLines);
+                pHeadersLines = NULL;
+            }
+            if (filename)
+            {
+                FREE(filename);
+                filename = NULL;
+            }
+            if (precisionFormat)
+            {
+                FREE(precisionFormat);
+                precisionFormat = NULL;
+            }
+            if (decimal)
+            {
+                FREE(decimal);
+                decimal = NULL;
+            }
+            if (separator)
+            {
+                FREE(separator);
+                separator = NULL;
+            }
+            return 0;
+        }
+    }
+    else if (iType1 == sci_matrix)
+    {
+        if (isVarComplex(pvApiCtx, piAddressVarOne))
+        {
+            bIsComplex = 1;
+            sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddressVarOne, &m1, &n1, &pDoubleValuesReal, &pDoubleValuesImag);
+        }
+        else
+        {
+            sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarOne, &m1, &n1, &pDoubleValuesReal);
+        }
+
+        if (sciErr.iErr)
+        {
+            if (pHeadersLines)
+            {
+                freeArrayOfString(pHeadersLines, nbHeadersLines);
+                pHeadersLines = NULL;
+            }
+            if (precisionFormat)
+            {
+                FREE(precisionFormat);
+                precisionFormat = NULL;
+            }
+            if (filename)
+            {
+                FREE(filename);
+                filename = NULL;
+            }
+            if (decimal)
+            {
+                FREE(decimal);
+                decimal = NULL;
+            }
+            if (separator)
+            {
+                FREE(separator);
+                separator = NULL;
+            }
+            printError(&sciErr, 0);
+            return 0;
+        }
+    }
+    else
+    {
+        if (pHeadersLines)
+        {
+            freeArrayOfString(pHeadersLines, nbHeadersLines);
+            pHeadersLines = NULL;
+        }
+        if (precisionFormat)
+        {
+            FREE(precisionFormat);
+            precisionFormat = NULL;
+        }
+        if (filename)
+        {
+            FREE(filename);
+            filename = NULL;
+        }
+        if (decimal)
+        {
+            FREE(decimal);
+            decimal = NULL;
+        }
+        if (separator)
+        {
+            FREE(separator);
+            separator = NULL;
+        }
+
+        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of string or a matrix of real expected.\n"), fname, 1);
+        return 0;
+    }
+
+    if (pStringValues)
+    {
+        csvError = csvWrite_string(filename,
+                                   (const char**)pStringValues, m1, n1,
+                                   separator,
+                                   decimal,
+                                   (const char**)pHeadersLines, nbHeadersLines);
+    }
+    else
+    {
+        if (bIsComplex)
+        {
+            csvError = csvWrite_complex(filename,
+                                        pDoubleValuesReal,
+                                        pDoubleValuesImag,
+                                        m1, n1,
+                                        separator,
+                                        decimal,
+                                        precisionFormat,
+                                        (const char**)pHeadersLines, nbHeadersLines);
+        }
+        else
+        {
+            csvError = csvWrite_double(filename,
+                                       pDoubleValuesReal, m1, n1,
+                                       separator,
+                                       decimal,
+                                       precisionFormat,
+                                       (const char**)pHeadersLines, nbHeadersLines);
+        }
+    }
+
+    if (pHeadersLines)
+    {
+        freeArrayOfString(pHeadersLines, nbHeadersLines);
+        pHeadersLines = NULL;
+    }
+    if (pStringValues)
+    {
+        freeArrayOfString(pStringValues, m1 * n1);
+        pStringValues = NULL;
+    }
+    if (decimal)
+    {
+        FREE(decimal);
+        decimal = NULL;
+    }
+    if (separator)
+    {
+        FREE(separator);
+        separator = NULL;
+    }
+    if (precisionFormat)
+    {
+        FREE(precisionFormat);
+        precisionFormat = NULL;
+    }
+
+    switch (csvError)
+    {
+        case CSV_WRITE_SEPARATOR_DECIMAL_EQUAL:
+        {
+            Scierror(999, _("%s: separator and decimal must have different values.\n"), fname);
+        }
+        break;
+        case CSV_WRITE_NO_ERROR:
+        {
+            LhsVar(1) = 0;
+            PutLhsVar();
+        }
+        break;
+
+        case CSV_WRITE_FOPEN_ERROR:
+        {
+            Scierror(999, _("%s: can not open file %s.\n"), fname, filename);
+        }
+        break;
+        default:
+        case CSV_WRITE_ERROR:
+        {
+            Scierror(999, _("%s: error.\n"), fname);
+        }
+        break;
+    }
+
+    if (filename)
+    {
+        FREE(filename);
+        filename = NULL;
+    }
+
+    return 0;
+}
+// =============================================================================
+
index 1d59d5b..e3582b0 100644 (file)
 
 <!DOCTYPE GATEWAY SYSTEM "../../functions/xml/gateway.dtd">
 <GATEWAY name="spreadsheet">
-<PRIMITIVE gatewayId="56" primitiveId="1" primitiveName="xls_open" />
-<PRIMITIVE gatewayId="56" primitiveId="2" primitiveName="xls_read" />
+    <PRIMITIVE gatewayId="56" primitiveId="1" primitiveName="xls_open" />
+    <PRIMITIVE gatewayId="56" primitiveId="2" primitiveName="xls_read" />
+    <PRIMITIVE gatewayId="56" primitiveId="3" primitiveName="csvDefault" />
+    <PRIMITIVE gatewayId="56" primitiveId="4" primitiveName="csvIsnum" />
+    <PRIMITIVE gatewayId="56" primitiveId="5" primitiveName="csvRead" />
+    <PRIMITIVE gatewayId="56" primitiveId="6" primitiveName="csvStringToDouble" />
+    <PRIMITIVE gatewayId="56" primitiveId="7" primitiveName="csvTextScan" />
+    <PRIMITIVE gatewayId="56" primitiveId="8" primitiveName="csvWrite" />
+    <PRIMITIVE gatewayId="56" primitiveId="9" primitiveName="write_csv" />
+    <PRIMITIVE gatewayId="56" primitiveId="10" primitiveName="read_csv" />
 </GATEWAY>
index 4541af9..c951d6c 100644 (file)
@@ -76,7 +76,7 @@
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>includes;src/c/ripole;src/c;../core/includes;../fileio/includes;../io/includes;../windows_tools/includes;../output_stream/includes;../localization/includes;../../libs/MALLOC/includes;../../libs/intl;../api_scilab/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>includes;src/c/ripole;src/c;sci_gateway/cpp;src/cpp;../core/includes;../fileio/includes;../io/includes;../windows_tools/includes;../output_stream/includes;../localization/includes;../../libs/MALLOC/includes;../../libs/intl;../api_scilab/includes;../string/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>FORDLL;_DEBUG;_WINDOWS;_USRDLL;SPREADSHEET_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
       <WarningLevel>Level3</WarningLevel>
     </Midl>
     <ClCompile>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>includes;src/c/ripole;src/c;../core/includes;../fileio/includes;../io/includes;../windows_tools/includes;../output_stream/includes;../localization/includes;../../libs/MALLOC/includes;../../libs/intl;../api_scilab/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>includes;src/c/ripole;src/c;sci_gateway/cpp;src/cpp;../core/includes;../fileio/includes;../io/includes;../windows_tools/includes;../output_stream/includes;../localization/includes;../../libs/MALLOC/includes;../../libs/intl;../api_scilab/includes;../string/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>FORDLL;_DEBUG;_WINDOWS;_USRDLL;SPREADSHEET_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
       <WarningLevel>Level3</WarningLevel>
     <ClCompile>
       <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
       <WholeProgramOptimization>false</WholeProgramOptimization>
-      <AdditionalIncludeDirectories>includes;src/c/ripole;src/c;../core/includes;../fileio/includes;../io/includes;../windows_tools/includes;../output_stream/includes;../localization/includes;../../libs/MALLOC/includes;../../libs/intl;../api_scilab/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>includes;src/c/ripole;src/c;sci_gateway/cpp;src/cpp;../core/includes;../fileio/includes;../io/includes;../windows_tools/includes;../output_stream/includes;../localization/includes;../../libs/MALLOC/includes;../../libs/intl;../api_scilab/includes;../string/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>FORDLL;NDEBUG;_WINDOWS;_USRDLL;SPREADSHEET_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <StringPooling>true</StringPooling>
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
     <ClCompile>
       <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
       <WholeProgramOptimization>false</WholeProgramOptimization>
-      <AdditionalIncludeDirectories>includes;src/c/ripole;src/c;../core/includes;../fileio/includes;../io/includes;../windows_tools/includes;../output_stream/includes;../localization/includes;../../libs/MALLOC/includes;../../libs/intl;../api_scilab/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>includes;src/c/ripole;src/c;sci_gateway/cpp;src/cpp;../core/includes;../fileio/includes;../io/includes;../windows_tools/includes;../output_stream/includes;../localization/includes;../../libs/MALLOC/includes;../../libs/intl;../api_scilab/includes;../string/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>FORDLL;NDEBUG;_WINDOWS;_USRDLL;SPREADSHEET_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <StringPooling>true</StringPooling>
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="sci_gateway\cpp\gw_csv_helpers.cpp" />
+    <ClCompile Include="sci_gateway\cpp\sci_csvDefault.cpp" />
+    <ClCompile Include="sci_gateway\cpp\sci_csvIsnum.cpp" />
+    <ClCompile Include="sci_gateway\cpp\sci_csvRead.cpp" />
+    <ClCompile Include="sci_gateway\cpp\sci_csvStringToDouble.cpp" />
+    <ClCompile Include="sci_gateway\cpp\sci_csvTextScan.cpp" />
+    <ClCompile Include="sci_gateway\cpp\sci_csvWrite.cpp" />
+    <ClCompile Include="src\cpp\checkCsvWriteFormat.c" />
+    <ClCompile Include="src\cpp\csv_complex.c" />
+    <ClCompile Include="src\cpp\csvDefault.c" />
+    <ClCompile Include="src\cpp\csvIsnum.c" />
+    <ClCompile Include="src\cpp\csvRead.c" />
+    <ClCompile Include="src\cpp\csv_strsubst.cpp" />
+    <ClCompile Include="src\cpp\csvWrite.c" />
+    <ClCompile Include="src\cpp\getRange.c" />
+    <ClCompile Include="src\cpp\latintoutf.c" />
+    <ClCompile Include="src\cpp\splitLine.c" />
+    <ClCompile Include="src\cpp\stringsToDoubles.c" />
+    <ClCompile Include="src\cpp\stringToComplex.c" />
+    <ClCompile Include="src\cpp\utftolatin.c" />
     <ClCompile Include="src\c\ripole\bt-int.c" />
     <ClCompile Include="src\c\ripole\bytedecoders.c" />
     <ClCompile Include="src\c\DllmainSpreadsheet.c" />
     <ClCompile Include="src\c\xls.c" />
   </ItemGroup>
   <ItemGroup>
+    <ClInclude Include="sci_gateway\cpp\gw_csv_helpers.h" />
+    <ClInclude Include="sci_gateway\cpp\gw_csv_tools.h" />
+    <ClInclude Include="src\cpp\checkCsvWriteFormat.h" />
+    <ClInclude Include="src\cpp\csv_complex.h" />
+    <ClInclude Include="src\cpp\csvDefault.h" />
+    <ClInclude Include="src\cpp\csvIsnum.h" />
+    <ClInclude Include="src\cpp\csvRead.h" />
+    <ClInclude Include="src\cpp\csv_strsubst.h" />
+    <ClInclude Include="src\cpp\csvWrite.h" />
+    <ClInclude Include="src\cpp\getRange.h" />
+    <ClInclude Include="src\cpp\latintoutf.h" />
+    <ClInclude Include="src\cpp\splitLine.h" />
+    <ClInclude Include="src\cpp\stringsToDoubles.h" />
+    <ClInclude Include="src\cpp\stringToComplex.h" />
+    <ClInclude Include="src\cpp\utftolatin.h" />
     <ClInclude Include="src\c\ripole\bt-int.h" />
     <ClInclude Include="src\c\ripole\bytedecoders.h" />
     <ClInclude Include="includes\dynlib_spreadsheet.h" />
       <Project>{a5911cd7-f8e8-440c-a23e-4843a0636f3a}</Project>
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
     </ProjectReference>
+    <ProjectReference Include="..\string\src\c\string.vcxproj">
+      <Project>{8d45767a-9b03-4905-97f6-d2f3f79141ea}</Project>
+    </ProjectReference>
     <ProjectReference Include="..\windows_tools\src\c\scilab_windows\scilab_windows.vcxproj">
       <Project>{8028f371-6a94-4a26-8804-6e7f05f1d1aa}</Project>
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
index bca2c3b..c63bf5d 100644 (file)
     <ClCompile Include="src\c\xls.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="sci_gateway\cpp\gw_csv_helpers.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="sci_gateway\cpp\sci_csvDefault.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="sci_gateway\cpp\sci_csvIsnum.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="sci_gateway\cpp\sci_csvRead.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="sci_gateway\cpp\sci_csvStringToDouble.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="sci_gateway\cpp\sci_csvTextScan.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="sci_gateway\cpp\sci_csvWrite.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="src\cpp\checkCsvWriteFormat.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="src\cpp\csv_complex.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="src\cpp\csvDefault.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="src\cpp\csvIsnum.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="src\cpp\csvRead.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="src\cpp\csvWrite.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="src\cpp\getRange.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="src\cpp\latintoutf.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="src\cpp\splitLine.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="src\cpp\stringsToDoubles.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="src\cpp\stringToComplex.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="src\cpp\utftolatin.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="src\cpp\csv_strsubst.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="src\c\ripole\bt-int.h">
     <ClInclude Include="src\c\xls.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="sci_gateway\cpp\gw_csv_helpers.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="sci_gateway\cpp\gw_csv_tools.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="src\cpp\checkCsvWriteFormat.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="src\cpp\csv_complex.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="src\cpp\csvDefault.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="src\cpp\csvIsnum.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="src\cpp\csvRead.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="src\cpp\csv_strsubst.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="src\cpp\csvWrite.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="src\cpp\getRange.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="src\cpp\latintoutf.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="src\cpp\splitLine.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="src\cpp\stringsToDoubles.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="src\cpp\stringToComplex.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="src\cpp\utftolatin.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="src\c\spreadsheet.rc">
diff --git a/scilab/modules/spreadsheet/src/cpp/checkCsvWriteFormat.c b/scilab/modules/spreadsheet/src/cpp/checkCsvWriteFormat.c
new file mode 100644 (file)
index 0000000..4378725
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - 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 <string.h>
+#include <ctype.h>
+#include "csvDefault.h"
+#include "MALLOC.h"
+#ifdef _MSC_VER
+#include "strdup_windows.h"
+#endif
+#include "checkCsvWriteFormat.h"
+// =============================================================================
+#define NB_FORMAT_SUPPORTED 7
+static const char *supportedFormat[NB_FORMAT_SUPPORTED] =
+{"lf", "lg", "d", "i", "e", "f", "g"};
+// =============================================================================
+static char *replaceInFormat(const char *format);
+static char *getCleanedFormat(const char *format);
+// =============================================================================
+int checkCsvWriteFormat(const char *format)
+{
+    if (format)
+    {
+        char *tokenPercent1 = strchr((char*)format, '%');
+        char *tokenPercent2 = strrchr((char*)format, '%');
+        if ((tokenPercent2 && tokenPercent1) && (tokenPercent1 == tokenPercent2))
+        {
+            char *cleanedFormat = getCleanedFormat(format);
+            if (cleanedFormat)
+            {
+                FREE(cleanedFormat);
+                cleanedFormat = NULL;
+                return 0;
+            }
+        }
+    }
+    return 1;
+}
+// =============================================================================
+static char *replaceInFormat(const char *format)
+{
+    char *newFormat = NULL;
+    if (format)
+    {
+        int i = 0;
+        for (i = 0; i < NB_FORMAT_SUPPORTED; i++)
+        {
+            char *cleanedFormat = getCleanedFormat(format);
+            if (cleanedFormat)
+            {
+                newFormat = strdup("%s");
+                FREE(cleanedFormat);
+                cleanedFormat = NULL;
+            }
+        }
+    }
+    return newFormat;
+}
+// =============================================================================
+static char *getCleanedFormat(const char *format)
+{
+    char *cleanedFormat = NULL;
+    if (format)
+    {
+        char *percent = strchr((char*)format, '%');
+        if (percent)
+        {
+            int i = 0;
+            for (i = 0; i < NB_FORMAT_SUPPORTED; i++)
+            {
+                char *token = strstr(percent, supportedFormat[i]);
+                if (token)
+                {
+                    size_t nbcharacters = strlen(percent) - strlen(token);
+                    cleanedFormat = strdup(percent);
+                    cleanedFormat[nbcharacters] = 0;
+                    if ( ((nbcharacters - 1 > 0) && (isdigit(cleanedFormat[nbcharacters - 1])) ||
+                            (cleanedFormat[nbcharacters - 1]) == '.') ||
+                            (cleanedFormat[nbcharacters - 1]) == '%')
+                    {
+                        strcat(cleanedFormat, supportedFormat[i]);
+                        return cleanedFormat;
+                    }
+                    else
+                    {
+                        FREE(cleanedFormat);
+                        cleanedFormat = NULL;
+                    }
+                }
+            }
+        }
+    }
+    return cleanedFormat;
+}
+// =============================================================================
diff --git a/scilab/modules/spreadsheet/src/cpp/checkCsvWriteFormat.h b/scilab/modules/spreadsheet/src/cpp/checkCsvWriteFormat.h
new file mode 100644 (file)
index 0000000..56fabfe
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - DIGITEO - Allan CORNET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+#ifndef __CHECKCSVWRITEFORMAT_H__
+#define __CHECKCSVWRITEFORMAT_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+    int checkCsvWriteFormat(const char *format);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __CHECKCSVWRITEFORMAT_H__ */
+// =============================================================================
diff --git a/scilab/modules/spreadsheet/src/cpp/csvDefault.c b/scilab/modules/spreadsheet/src/cpp/csvDefault.c
new file mode 100644 (file)
index 0000000..707e14a
--- /dev/null
@@ -0,0 +1,342 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - 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 <string.h>
+#include "csvDefault.h"
+#include "MALLOC.h"
+#ifdef _MSC_VER
+#include "strdup_windows.h"
+#endif
+#include "checkCsvWriteFormat.h"
+// =============================================================================
+#define DEFAULT_CSV_SEPARATOR ","
+#define DEFAULT_CSV_DECIMAL "."
+#define DEFAULT_CSV_PRECISION "%.17lg"
+#define DEFAULT_CSV_COMMENTS_REGEXP ""
+#ifdef _MSC_VER
+#define DEFAULT_CSV_EOL "\r\n"
+#else
+#define DEFAULT_CSV_EOL "\n"
+#endif
+#define CSV_DECIMAL_MODE_1 DEFAULT_CSV_DECIMAL
+#define CSV_DECIMAL_MODE_2 ","
+#define DEFAULT_CSV_CONVERSION "double"
+#define CSV_CONVERSION_MODE_1 DEFAULT_CSV_CONVERSION
+#define CSV_CONVERSION_MODE_2 "string"
+#define DEFAULT_CSV_ENCODING "utf-8"
+#define DEFAULT_CSV_ENCODING_MODE1 "utf-8"
+#define DEFAULT_CSV_ENCODING_MODE2 "iso-latin"
+#define CSV_IGNORE_BLANK_LINE_MODE_1 "off"
+#define CSV_IGNORE_BLANK_LINE_MODE_2 "on"
+#define DEFAULT_IGNORE_BLANK_LINE CSV_IGNORE_BLANK_LINE_MODE_1
+// =============================================================================
+static char *defaultCsvSeparator = NULL;
+static char *defaultCsvDecimal = NULL;
+static char *defaultCsvConversion = NULL;
+static char *defaultCsvPrecision = NULL;
+static char *defaultCsvCommentsRegExp = NULL;
+static char *defaultCsvEOL = NULL;
+static char *defaultCsvEncoding = NULL;
+static char *defaultCsvIgnoreBlankLine = NULL;
+// =============================================================================
+static int initializeCsvDefaultValues(void);
+// =============================================================================
+const char *getCsvDefaultSeparator(void)
+{
+    initializeCsvDefaultValues();
+    return defaultCsvSeparator;
+}
+// =============================================================================
+const char *getCsvDefaultDecimal(void)
+{
+    initializeCsvDefaultValues();
+    return defaultCsvDecimal;
+}
+// =============================================================================
+const char *getCsvDefaultConversion(void)
+{
+    initializeCsvDefaultValues();
+    return defaultCsvConversion;
+}
+// =============================================================================
+const char *getCsvDefaultPrecision(void)
+{
+    initializeCsvDefaultValues();
+    return defaultCsvPrecision;
+}
+// =============================================================================
+const char *getCsvDefaultCommentsRegExp(void)
+{
+    initializeCsvDefaultValues();
+    return defaultCsvCommentsRegExp;
+}
+// =============================================================================
+const char *getCsvDefaultEOL(void)
+{
+    initializeCsvDefaultValues();
+    return defaultCsvEOL;
+}
+// =============================================================================
+const char *getCsvDefaultEncoding(void)
+{
+    initializeCsvDefaultValues();
+    return defaultCsvEncoding;
+}
+// =============================================================================
+const char *getCsvDefaultCsvIgnoreBlankLine(void)
+{
+    initializeCsvDefaultValues();
+    return defaultCsvIgnoreBlankLine;
+}
+// =============================================================================
+int setCsvDefaultSeparator(const char *separator)
+{
+    if (initializeCsvDefaultValues()) return 1;
+    if (separator == NULL) return 1;
+
+    if (strcmp(separator, getCsvDefaultDecimal()) == 0) return 1;
+
+    if (defaultCsvSeparator) FREE(defaultCsvSeparator);
+    defaultCsvSeparator = strdup(separator);
+    if (defaultCsvSeparator == NULL) return 1;
+
+    return 0;
+}
+// =============================================================================
+int setCsvDefaultDecimal(const char *decimal)
+{
+    if (initializeCsvDefaultValues()) return 1;
+    if (decimal == NULL) return 1;
+
+    /* decimal separator supported . and , */
+    if ((strcmp(decimal, CSV_DECIMAL_MODE_1) == 0) ||
+            (strcmp(decimal, CSV_DECIMAL_MODE_2) == 0))
+    {
+        if (strcmp(decimal, getCsvDefaultSeparator()) == 0) return 1;
+        if (defaultCsvDecimal) FREE(defaultCsvDecimal);
+        defaultCsvDecimal = strdup(decimal);
+        if (defaultCsvDecimal == NULL) return 1;
+        return 0;
+    }
+    return 1;
+}
+// =============================================================================
+int setCsvDefaultConversion(const char *conversion)
+{
+    if (initializeCsvDefaultValues()) return 1;
+    if (conversion == NULL) return 1;
+
+    if ((strcmp(conversion, CSV_CONVERSION_MODE_1) == 0) ||
+            (strcmp(conversion, CSV_CONVERSION_MODE_2) == 0))
+    {
+        if (defaultCsvConversion) FREE(defaultCsvConversion);
+        defaultCsvConversion = strdup(conversion);
+        if (defaultCsvConversion) return 0;
+    }
+
+    return 1;
+}
+// =============================================================================
+int setCsvDefaultPrecision(const char *precision)
+{
+    if (initializeCsvDefaultValues()) return 1;
+    if (precision == NULL) return 1;
+    if (checkCsvWriteFormat(precision) == 0)
+    {
+        if (defaultCsvPrecision) FREE(defaultCsvPrecision);
+        defaultCsvPrecision = strdup(precision);
+        if (defaultCsvPrecision) return 0;
+    }
+    return 1;
+}
+// =============================================================================
+int setCsvDefaultCsvIgnoreBlankLine(const char *blankMode)
+{
+    if (initializeCsvDefaultValues()) return 1;
+    if (blankMode == NULL) return 1;
+    if ((strcmp(blankMode, CSV_IGNORE_BLANK_LINE_MODE_1) == 0) ||
+            (strcmp(blankMode, CSV_IGNORE_BLANK_LINE_MODE_2) == 0))
+    {
+        if (defaultCsvIgnoreBlankLine) FREE(defaultCsvIgnoreBlankLine);
+        defaultCsvIgnoreBlankLine = strdup(blankMode);
+        if (defaultCsvIgnoreBlankLine) return 0;
+    }
+    return 1;
+}
+// =============================================================================
+static int initializeCsvDefaultValues(void)
+{
+    if (defaultCsvSeparator == NULL)
+    {
+        defaultCsvSeparator = strdup(DEFAULT_CSV_SEPARATOR);
+    }
+
+    if (defaultCsvDecimal == NULL)
+    {
+        defaultCsvDecimal = strdup(DEFAULT_CSV_DECIMAL);
+    }
+
+    if (defaultCsvConversion == NULL)
+    {
+        defaultCsvConversion = strdup(DEFAULT_CSV_CONVERSION);
+    }
+
+    if (defaultCsvPrecision == NULL)
+    {
+        defaultCsvPrecision = strdup(DEFAULT_CSV_PRECISION);
+    }
+
+    if (defaultCsvCommentsRegExp == NULL)
+    {
+        defaultCsvCommentsRegExp = strdup(DEFAULT_CSV_COMMENTS_REGEXP);
+    }
+
+    if (defaultCsvEOL == NULL)
+    {
+        defaultCsvEOL = strdup(DEFAULT_CSV_EOL);
+    }
+
+    if (defaultCsvEncoding == NULL)
+    {
+        defaultCsvEncoding = strdup(DEFAULT_CSV_ENCODING);
+    }
+
+    if (defaultCsvIgnoreBlankLine == NULL)
+    {
+        defaultCsvIgnoreBlankLine =  strdup(DEFAULT_IGNORE_BLANK_LINE);
+    }
+
+    if ((defaultCsvSeparator == NULL) ||
+            (defaultCsvDecimal == NULL) ||
+            (defaultCsvConversion == NULL) ||
+            (defaultCsvPrecision == NULL) ||
+            (defaultCsvCommentsRegExp == NULL) ||
+            (defaultCsvEOL == NULL) ||
+            (defaultCsvEncoding == NULL) ||
+            (defaultCsvIgnoreBlankLine == NULL))
+    {
+        return 1;
+    }
+
+    return 0;
+}
+// =============================================================================
+int setCsvDefaultReset(void)
+{
+    if (defaultCsvSeparator)
+    {
+        FREE(defaultCsvSeparator);
+        defaultCsvSeparator = NULL;
+    }
+    if (defaultCsvDecimal)
+    {
+        FREE(defaultCsvDecimal);
+        defaultCsvDecimal = NULL;
+    }
+    if (defaultCsvConversion)
+    {
+        FREE(defaultCsvConversion);
+        defaultCsvConversion = NULL;
+    }
+    if (defaultCsvPrecision)
+    {
+        FREE(defaultCsvPrecision);
+        defaultCsvPrecision = NULL;
+    }
+    if (defaultCsvCommentsRegExp)
+    {
+        FREE(defaultCsvCommentsRegExp);
+        defaultCsvCommentsRegExp = NULL;
+    }
+    if (defaultCsvEOL)
+    {
+        FREE(defaultCsvEOL);
+        defaultCsvEOL = NULL;
+    }
+    if (defaultCsvEncoding)
+    {
+        FREE(defaultCsvEncoding);
+        defaultCsvEncoding = NULL;
+    }
+    if (defaultCsvIgnoreBlankLine)
+    {
+        FREE(defaultCsvIgnoreBlankLine);
+        defaultCsvIgnoreBlankLine = NULL;
+    }
+    return initializeCsvDefaultValues();
+}
+// =============================================================================
+int setCsvDefaultCommentsRegExp(const char *commentsRegExp)
+{
+    if (initializeCsvDefaultValues()) return 1;
+    if (commentsRegExp == NULL) return 1;
+
+    if (strcmp(commentsRegExp, getCsvDefaultCommentsRegExp()) == 0) return 1;
+
+    if (defaultCsvCommentsRegExp)
+    {
+        FREE(defaultCsvCommentsRegExp);
+        defaultCsvCommentsRegExp = NULL;
+    }
+
+    defaultCsvCommentsRegExp = strdup(commentsRegExp);
+
+    if (defaultCsvDecimal == NULL) return 1;
+
+    return 0;
+}
+// =============================================================================
+int setCsvDefaultEOL(const char *eol)
+{
+    if (initializeCsvDefaultValues()) return 1;
+    if (eol == NULL) return 1;
+
+    if (strcmp(eol, getCsvDefaultEOL()) == 0) return 0;
+
+    if (defaultCsvEOL)
+    {
+        FREE(defaultCsvEOL);
+        defaultCsvEOL = NULL;
+    }
+
+    defaultCsvEOL = strdup(eol);
+
+    if (defaultCsvEOL == NULL) return 1;
+
+    return 0;
+}
+// =============================================================================
+int setCsvDefaultEncoding(const char *encoding)
+{
+    if (initializeCsvDefaultValues()) return 1;
+    if (encoding == NULL) return 1;
+
+    if (strcmp(encoding, getCsvDefaultEncoding()) == 0) return 1;
+
+    if ((strcmp(encoding, DEFAULT_CSV_ENCODING_MODE1) != 0) &&
+            (strcmp(encoding, DEFAULT_CSV_ENCODING_MODE2) != 0))
+    {
+        return 1;
+    }
+
+    if (defaultCsvEncoding)
+    {
+        FREE(defaultCsvEncoding);
+        defaultCsvEncoding = NULL;
+    }
+
+    defaultCsvEncoding = strdup(encoding);
+
+    if (defaultCsvEncoding == NULL) return 1;
+
+    return 0;
+}
+// =============================================================================
diff --git a/scilab/modules/spreadsheet/src/cpp/csvDefault.h b/scilab/modules/spreadsheet/src/cpp/csvDefault.h
new file mode 100644 (file)
index 0000000..279c84c
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - DIGITEO - Allan CORNET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+#ifndef __CSV_DEFAULT_H__
+#define __CSV_DEFAULT_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+    const char *getCsvDefaultSeparator(void);
+    const char *getCsvDefaultDecimal(void);
+    const char *getCsvDefaultConversion(void);
+    const char *getCsvDefaultPrecision(void);
+    const char *getCsvDefaultCommentsRegExp(void);
+    const char *getCsvDefaultEOL(void);
+    const char *getCsvDefaultEncoding(void);
+    const char *getCsvDefaultCsvIgnoreBlankLine(void);
+
+    int setCsvDefaultSeparator(const char *separator);
+    int setCsvDefaultDecimal(const char *decimal);
+    int setCsvDefaultConversion(const char *conversion);
+    int setCsvDefaultPrecision(const char *precision);
+    int setCsvDefaultCommentsRegExp(const char *commentsRegExp);
+    int setCsvDefaultEOL(const char *eol);
+    int setCsvDefaultEncoding(const char *encoding);
+    int setCsvDefaultCsvIgnoreBlankLine(const char *blankMode);
+
+    int setCsvDefaultReset(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __CSV_DEFAULT_H__ */
+// =============================================================================
diff --git a/scilab/modules/spreadsheet/src/cpp/csvIsnum.c b/scilab/modules/spreadsheet/src/cpp/csvIsnum.c
new file mode 100644 (file)
index 0000000..8203cd4
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - 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 "csvIsnum.h"
+#include "csvDefault.h"
+#include "stringToComplex.h"
+#include "MALLOC.h"
+// =============================================================================
+BOOL csv_isNum(const char *pStr)
+{
+    if (pStr)
+    {
+        stringToComplexError ierr = STRINGTOCOMPLEX_NO_ERROR;
+        stringToComplex(pStr, getCsvDefaultDecimal(), FALSE, &ierr);
+        return (BOOL)(ierr == STRINGTOCOMPLEX_NO_ERROR);
+    }
+    return FALSE;
+}
+// =============================================================================
+BOOL *csv_isNumMatrix(const char **pStrs, int nbRows, int nbCols)
+{
+    BOOL *pResults = NULL;
+    if (pStrs)
+    {
+        pResults = (BOOL*)MALLOC(sizeof(BOOL) * (nbCols * nbRows));
+        if (pResults)
+        {
+            int i = 0;
+            for (i = 0; i < nbRows * nbCols; i++)
+            {
+                pResults[i] = csv_isNum(pStrs[i]);
+            }
+        }
+    }
+    return pResults;
+}
+// =============================================================================
+
+
diff --git a/scilab/modules/spreadsheet/src/cpp/csvIsnum.h b/scilab/modules/spreadsheet/src/cpp/csvIsnum.h
new file mode 100644 (file)
index 0000000..f0cfce8
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - DIGITEO - Allan CORNET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+#ifndef __CSV_ISNUM_H__
+#define __CSV_ISNUM_H__
+
+#include "BOOL.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+    BOOL csv_isNum(const char *pStr);
+
+    BOOL *csv_isNumMatrix(const char **pStrs, int nbRows, int nbCols);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __CSV_ISNUM_H__ */
+// =============================================================================
diff --git a/scilab/modules/spreadsheet/src/cpp/csvRead.c b/scilab/modules/spreadsheet/src/cpp/csvRead.c
new file mode 100644 (file)
index 0000000..8d9405d
--- /dev/null
@@ -0,0 +1,709 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - 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 <string.h>
+#include <stdio.h>
+#include "csvRead.h"
+#include "MALLOC.h"
+#include "freeArrayOfString.h"
+#include "mopen.h"
+#include "mgetl.h"
+#include "expandPathVariable.h"
+#include "FileExist.h"
+#include "mclose.h"
+#include "pcre_private.h"
+#include "splitLine.h"
+#include "csv_strsubst.h"
+#if _MSC_VER
+#include "strdup_windows.h"
+#endif
+#include "csvDefault.h"
+// =============================================================================
+#if _MSC_VER
+#define READ_ONLY_TEXT_MODE "rt"
+#else
+#define READ_ONLY_TEXT_MODE "r"
+#endif
+// =============================================================================
+static int getNumbersOfColumnsInLines(const char **lines, int sizelines,
+                                      const char *separator);
+static int getNumbersOfColumnsInLine(const char *line, const char *separator);
+static char **getStringsFromLines(const char **lines, int sizelines,
+                                  const char *separator, const char *decimal,
+                                  int m, int n);
+static char **removeEmptyLinesAtTheEnd(const char **lines, int *sizelines);
+static char *stripCharacters(const char *line);
+static char **replaceStrings(const char **lines, int nbLines, const char **toreplace, int sizetoreplace);
+static char **extractComments(const char **lines, int nbLines, const char *regexpcomments, int *nbcomments, int *iErr);
+static char **removeComments(const char **lines, int nbLines, const char *regexpcomments, int *nbNewLine, int *iErr);
+static char **removeAllBlankLines(const char **lines, int *sizelines);
+// =============================================================================
+csvResult* csvRead(const char *filename, const char *separator, const char *decimal, const char **toreplace, int sizetoreplace, const char *regexpcomments)
+{
+    char *expandedFilename = NULL;
+    csvResult *result = NULL;
+    int fd = 0;
+    int f_swap = 0;
+    double res = 0.0;
+    int errMOPEN = MOPEN_INVALID_STATUS;
+    int errMGETL = MGETL_ERROR;
+    double dErrClose = 0.;
+    char **lines = NULL;
+    int nblines = 0;
+    char **replacedInLines = NULL;
+    char **pComments = NULL;
+    int nbComments = 0;
+
+    if ((filename == NULL) || (separator == NULL) || (decimal == NULL))
+    {
+        return NULL;
+    }
+
+    expandedFilename = expandPathVariable((char*)filename);
+    if (!FileExist(expandedFilename))
+    {
+        result = (csvResult*)(MALLOC(sizeof(csvResult)));
+        if (result)
+        {
+            result->err = CSV_READ_FILE_NOT_EXIST;
+            result->m = 0;
+            result->n = 0;
+            result->pstrValues = NULL;
+            result->pstrComments = NULL;
+            result->nbComments = 0;
+        }
+        if (expandedFilename)
+        {
+            FREE(expandedFilename);
+            expandedFilename = NULL;
+        }
+        return result;
+    }
+
+    C2F(mopen)(&fd, expandedFilename, (char*)READ_ONLY_TEXT_MODE, &f_swap, &res, &errMOPEN);
+    if (expandedFilename)
+    {
+        FREE(expandedFilename);
+        expandedFilename = NULL;
+    }
+    if (errMOPEN != MOPEN_NO_ERROR)
+    {
+        result = (csvResult*)(MALLOC(sizeof(csvResult)));
+        if (result)
+        {
+            result->err = CSV_READ_MOPEN_ERROR;
+            result->m = 0;
+            result->n = 0;
+            result->pstrValues = NULL;
+            result->pstrComments = NULL;
+            result->nbComments = 0;
+
+        }
+        return result;
+    }
+
+    lines = mgetl(fd, -1, &nblines, &errMGETL);
+
+    C2F(mclose)(&fd, &dErrClose);
+
+    if (errMGETL != MGETL_NO_ERROR)
+    {
+        if (lines)
+        {
+            freeArrayOfString(lines, nblines);
+            lines = NULL;
+        }
+
+        result = (csvResult*)(MALLOC(sizeof(csvResult)));
+        if (result)
+        {
+            result->err = CSV_READ_READLINES_ERROR;
+            result->m = 0;
+            result->n = 0;
+            result->pstrValues = NULL;
+            result->pstrComments = NULL;
+            result->nbComments = 0;
+        }
+        return result;
+    }
+
+    if (regexpcomments)
+    {
+        int iErr = 0;
+
+        pComments = extractComments((const char**)lines, nblines, (const char*)regexpcomments, &nbComments, &iErr);
+
+        if ((iErr == CAN_NOT_COMPILE_PATTERN) || (iErr == DELIMITER_NOT_ALPHANUMERIC))
+        {
+            result = (csvResult*)(MALLOC(sizeof(csvResult)));
+            if (result)
+            {
+                if ((iErr == CAN_NOT_COMPILE_PATTERN) || (iErr == DELIMITER_NOT_ALPHANUMERIC))
+                {
+                    iErr = CSV_READ_REGEXP_ERROR;
+                }
+                result->err = (csvReadError)iErr;
+                result->m = 0;
+                result->n = 0;
+                result->pstrValues = NULL;
+                result->pstrComments = NULL;
+                result->nbComments = 0;
+            }
+            return result;
+        }
+
+        if (pComments)
+        {
+            char **pCleanedLines = NULL;
+            int nbCleanedLines = 0;
+            int i = 0;
+
+            pCleanedLines = removeComments((const char**)lines, nblines, (const char*)regexpcomments, &nbCleanedLines, &iErr);
+            if (pCleanedLines)
+            {
+                FREE(lines);
+                lines = pCleanedLines;
+                nblines = nbCleanedLines;
+            }
+
+        }
+    }
+
+    if (toreplace && (sizetoreplace > 0))
+    {
+        replacedInLines = replaceStrings((const char**)lines, nblines, toreplace, sizetoreplace);
+        if (replacedInLines)
+        {
+            freeArrayOfString(lines, nblines);
+            lines = replacedInLines;
+        }
+    }
+
+    result = csvTextScan((const char**)lines, nblines, (const char*)separator, (const char*)decimal);
+    if (lines)
+    {
+        freeArrayOfString(lines, nblines);
+        lines = NULL;
+    }
+
+    if (result)
+    {
+        result->pstrComments = pComments;
+        result->nbComments = nbComments;
+    }
+
+    return result;
+}
+// =============================================================================
+csvResult* csvTextScan(const char **lines, int numberOfLines, const char *separator, const char *decimal)
+{
+    csvResult *result = NULL;
+    int nbRows = 0;
+    int nbColumns = 0;
+    char **cellsStrings = NULL;
+    char **cleanedLines = NULL;
+    int nbLines = numberOfLines;
+
+    if (strcmp(separator, decimal) == 0)
+    {
+        result = (csvResult*)(MALLOC(sizeof(csvResult)));
+        if (result)
+        {
+            result->err = CSV_READ_SEPARATOR_DECIMAL_EQUAL;
+            result->m = 0;
+            result->n = 0;
+            result->pstrValues = NULL;
+            result->pstrComments = NULL;
+            result->nbComments = 0;
+        }
+        return result;
+    }
+
+    // ticket 472
+    {
+        const char *blankMode = getCsvDefaultCsvIgnoreBlankLine();
+        if (strcmp(blankMode, "on") == 0)
+        {
+            int nbLinesBackup = nbLines;
+            char **tmpLines = removeAllBlankLines(lines, &nbLines);
+            if (tmpLines)
+            {
+                freeArrayOfString(cleanedLines, nbLines);
+                cleanedLines = tmpLines;
+            }
+        }
+        else
+        {
+            /* remove last lines empty (bug 7003 in scilab)*/
+            cleanedLines = removeEmptyLinesAtTheEnd(lines, &nbLines);
+        }
+    }
+
+    nbColumns = getNumbersOfColumnsInLines((const char **)cleanedLines, nbLines, separator);
+    if (nbColumns == 0)
+    {
+        result = (csvResult*)(MALLOC(sizeof(csvResult)));
+        if (result)
+        {
+            result->err = CSV_READ_COLUMNS_ERROR;
+            result->m = 0;
+            result->n = 0;
+            result->pstrValues = NULL;
+            result->pstrComments = NULL;
+            result->nbComments = 0;
+        }
+        return result;
+    }
+    else
+    {
+        nbRows = nbLines;
+    }
+
+    cellsStrings = getStringsFromLines((const char **)cleanedLines, nbLines, separator, decimal, nbColumns, nbRows);
+    if (cleanedLines)
+    {
+        freeArrayOfString(cleanedLines, nbLines);
+        cleanedLines = NULL;
+    }
+
+    if (cellsStrings)
+    {
+        result = (csvResult*)(MALLOC(sizeof(csvResult)));
+        if (result)
+        {
+            result->err = CSV_READ_NO_ERROR;
+            result->m = nbRows;
+            result->n = nbColumns;
+            result->pstrValues = cellsStrings;
+            result->pstrComments = NULL;
+            result->nbComments = 0;
+        }
+    }
+    else
+    {
+        result = (csvResult*)(MALLOC(sizeof(csvResult)));
+        if (result)
+        {
+            result->err = CSV_READ_COLUMNS_ERROR;
+            result->m = 0;
+            result->n = 0;
+            result->pstrValues = NULL;
+            result->pstrComments = NULL;
+            result->nbComments = 0;
+        }
+    }
+    return result;
+}
+// =============================================================================
+void freeCsvResult(csvResult *result)
+{
+    if (result)
+    {
+        if (result->pstrValues)
+        {
+            freeArrayOfString(result->pstrValues, result->m * result->n);
+            result->pstrValues = NULL;
+        }
+        result->m = 0;
+        result->n = 0;
+
+        if (result->pstrComments)
+        {
+            freeArrayOfString(result->pstrComments, result->nbComments);
+            result->pstrComments = NULL;
+        }
+        result->err = CSV_READ_ERROR;
+        FREE(result);
+        result = NULL;
+    }
+}
+// =============================================================================
+static int getNumbersOfColumnsInLines(const char **lines, int sizelines,
+                                      const char *separator)
+{
+    int previousNbColumns = 0;
+    int NbColumns = 0;
+    BOOL firstLine = TRUE;
+    if (lines)
+    {
+        int i = 0;
+        for (i = 0; i < sizelines; i++)
+        {
+            NbColumns = getNumbersOfColumnsInLine(lines[i], separator);
+            if (firstLine)
+            {
+                previousNbColumns = NbColumns;
+                firstLine = FALSE;
+            }
+            else
+            {
+                if (previousNbColumns != NbColumns)
+                {
+                    return 0;
+                }
+            }
+        }
+    }
+    return NbColumns;
+}
+// =============================================================================
+static int getNumbersOfColumnsInLine(const char *line, const char *separator)
+{
+    if (line && separator)
+    {
+        int i = 0;
+        int nbTokens = 0;
+        char **splittedStr = splitLine(line, separator, &nbTokens, 0);
+        if (splittedStr)
+        {
+            if (nbTokens > 0)
+            {
+                if ( (nbTokens > 1) && ((int)strlen(splittedStr[nbTokens - 1]) == 0) )
+                {
+                    nbTokens--;
+                }
+            }
+            freeArrayOfString(splittedStr, nbTokens);
+
+            return nbTokens;
+        }
+        else
+        {
+            int len = (int)strlen(line);
+            if (len > 0)
+            {
+                nbTokens = 1;
+                return nbTokens;
+            }
+        }
+    }
+    return 0;
+}
+// =============================================================================
+static char **getStringsFromLines(const char **lines, int sizelines,
+                                  const char *separator,
+                                  const char *decimal,
+                                  int m, int n)
+{
+    char **results = NULL;
+
+    if (lines == NULL) return NULL;
+    if (separator == NULL) return NULL;
+    if (m == 0 || n == 0) return NULL;
+
+    results = (char**) MALLOC(sizeof(char*) * (m * n));
+    if (results)
+    {
+        int i = 0;
+        for (i = 0; i < sizelines; i++)
+        {
+            int nbTokens = 0;
+            char **lineStrings = splitLine(lines[i], separator, &nbTokens, 0);
+            int j = 0;
+
+            if (lineStrings)
+            {
+                if (nbTokens > 0)
+                {
+                    if ((nbTokens > 1) && ((int)strlen(lineStrings[nbTokens - 1]) == 0))
+                    {
+                        nbTokens--;
+                    }
+                }
+            }
+            else
+            {
+                lineStrings = (char**)MALLOC(sizeof(char*) * 1);
+                lineStrings[0] = strdup(lines[i]);
+                nbTokens = 1;
+            }
+
+            if (m != nbTokens)
+            {
+                freeArrayOfString(results, m * n);
+                FREE(lineStrings);
+                return NULL;
+            }
+
+            for (j = 0; j < m; j++)
+            {
+                if (decimal)
+                {
+                    results[i + n * j] = strdup(lineStrings[j]);
+                }
+                else
+                {
+                    results[i + n * j] = csv_strsubst(lineStrings[j], decimal, getCsvDefaultDecimal());
+                }
+
+                if (lineStrings[j])
+                {
+                    FREE(lineStrings[j]);
+                    lineStrings[j] = NULL;
+                }
+            }
+        }
+    }
+    return results;
+}
+// =============================================================================
+static char **removeEmptyLinesAtTheEnd(const char **lines, int *sizelines)
+{
+    char **returnedLines = NULL;
+    int nbLinesToRemove = 0;
+
+    if (lines)
+    {
+        int i = 0;
+        if (*sizelines >= 1)
+        {
+            for (i = *sizelines - 1; i >= 0; i--)
+            {
+                char *cleanedLine = stripCharacters(lines[i]);
+                if (cleanedLine)
+                {
+                    int len = (int) strlen(cleanedLine);
+                    FREE(cleanedLine);
+                    cleanedLine = NULL;
+                    if (len == 0)
+                    {
+                        nbLinesToRemove++;
+                        FREE((char*)lines[i]);
+                        lines[i] = NULL;
+                    }
+                    else
+                    {
+                        break;
+                    }
+                }
+            }
+
+            if (nbLinesToRemove > 0)
+            {
+                *sizelines = *sizelines - nbLinesToRemove;
+            }
+            returnedLines = (char **)MALLOC(sizeof(char *) * (*sizelines));
+            if (returnedLines)
+            {
+                for (i = 0; i < *sizelines; i++)
+                {
+                    returnedLines[i] = strdup(lines[i]);
+                }
+            }
+        }
+    }
+
+    return returnedLines;
+}
+// =============================================================================
+static char **removeAllBlankLines(const char **lines, int *sizelines)
+{
+    char **returnedLines = NULL;
+    int nbLines = 0;
+    if (lines)
+    {
+        int i = 0;
+        for (i = 0; i < *sizelines; i++)
+        {
+            char *cleanedLine = stripCharacters(lines[i]);
+            if (cleanedLine)
+            {
+                int len = (int) strlen(cleanedLine);
+                FREE(cleanedLine);
+                cleanedLine = NULL;
+                if (len != 0)
+                {
+                    if (nbLines == 0)
+                    {
+                        nbLines++;
+                        returnedLines = (char**)MALLOC(sizeof(char*) * nbLines);
+                    }
+                    else
+                    {
+                        nbLines++;
+                        returnedLines = (char**)REALLOC(returnedLines, sizeof(char*) * nbLines);
+                    }
+
+                    if (returnedLines)
+                    {
+                        returnedLines[nbLines - 1] = strdup(lines[i]);
+                    }
+                    else
+                    {
+                        *sizelines = 0;
+                        return NULL;
+                    }
+                }
+            }
+        }
+        *sizelines = nbLines;
+    }
+    return returnedLines;
+}
+// =============================================================================
+static char *stripCharacters(const char *line)
+{
+    char *returnedLine = NULL;
+    if (line)
+    {
+        char *tmpLineWithoutTab = csv_strsubst((char*)line, "\t", "");
+        if (tmpLineWithoutTab)
+        {
+            char *tmpLineWithoutLF = csv_strsubst(tmpLineWithoutTab, "\r", "");
+            if (tmpLineWithoutLF)
+            {
+                char *tmpLineWithoutCR = csv_strsubst(tmpLineWithoutTab, "\n", "");
+                if (tmpLineWithoutCR)
+                {
+                    returnedLine = csv_strsubst(tmpLineWithoutCR, " ", "");
+                }
+                else
+                {
+                    returnedLine = strdup(line);
+                }
+                FREE(tmpLineWithoutLF);
+                tmpLineWithoutLF = NULL;
+            }
+            else
+            {
+                returnedLine = strdup(line);
+            }
+            FREE(tmpLineWithoutTab);
+            tmpLineWithoutTab = NULL;
+        }
+        else
+        {
+            returnedLine = strdup(line);
+        }
+    }
+
+    return returnedLine;
+}
+// =============================================================================
+static char **replaceStrings(const char **lines, int nbLines, const char **toreplace, int sizetoreplace)
+{
+    char **replacedStrings = NULL;
+    int nr = 0;
+
+    nr = sizetoreplace / 2;
+
+    if (lines)
+    {
+        int i = 0;
+
+        replacedStrings = (char**)MALLOC(sizeof(char*) * nbLines);
+        if (replacedStrings)
+        {
+            // Copy the source lines to the target replacedStrings.
+            int j = 0;
+            for (j = 0; j < nbLines; j++)
+            {
+                replacedStrings[j] = strdup(lines[j]);
+            }
+            // Make replacements within the target replacedStrings.
+            for (i = 0; i < nr; i = i++)
+            {
+                for (j = 0; j < nbLines; j++)
+                {
+                    replacedStrings[j] = csv_strsubst(replacedStrings[j], toreplace[i], toreplace[nr + i]);
+                }
+            }
+        }
+    }
+    return replacedStrings;
+}
+// =============================================================================
+static char **extractComments(const char **lines, int nbLines,
+                              const char *regexpcomments, int *nbcomments, int *iErr)
+{
+    char **pComments = NULL;
+    int i = 0;
+
+    for (i = 0; i < nbLines; i++)
+    {
+        int Output_Start = 0;
+        int Output_End = 0;
+        pcre_error_code answer = pcre_private((char*)lines[i], (char*)regexpcomments, &Output_Start, &Output_End);
+
+        if ( (answer == CAN_NOT_COMPILE_PATTERN) || (answer == DELIMITER_NOT_ALPHANUMERIC))
+        {
+            *nbcomments = 0;
+            *iErr = answer;
+            return NULL;
+        }
+        if ( answer == PCRE_FINISHED_OK )
+        {
+            (*nbcomments)++;
+            if (pComments == NULL)
+            {
+                pComments = (char **)MALLOC(sizeof(char*) * (*nbcomments));
+            }
+            else
+            {
+                pComments = (char **)REALLOC(pComments, sizeof(char*) * (*nbcomments));
+            }
+
+            if (pComments == NULL)
+            {
+                *nbcomments = 0;
+                *iErr = 1;
+                return NULL;
+            }
+            pComments[(*nbcomments) - 1] = strdup(lines[i]);
+        }
+    }
+
+    return pComments;
+}
+// =============================================================================
+static char **removeComments(const char **lines, int nbLines,
+                             const char *regexpcomments, int *newNbLines, int *iErr)
+{
+    char **pLinesCleaned = NULL;
+
+    int i = 0;
+    *newNbLines = 0;
+
+    for (i = 0; i < nbLines; i++)
+    {
+        int Output_Start = 0;
+        int Output_End = 0;
+        pcre_error_code answer = pcre_private((char*)lines[i], (char*)regexpcomments, &Output_Start, &Output_End);
+        if ( answer == PCRE_FINISHED_OK )
+        {
+            FREE((char*)lines[i]);
+            lines[i] = NULL;
+        }
+        else
+        {
+            (*newNbLines)++;
+            if (pLinesCleaned == NULL)
+            {
+                pLinesCleaned = (char **)MALLOC(sizeof(char*) * (*newNbLines));
+            }
+            else
+            {
+                pLinesCleaned = (char **)REALLOC(pLinesCleaned, sizeof(char*) * (*newNbLines));
+            }
+
+            if (pLinesCleaned == NULL)
+            {
+                *newNbLines = 0;
+                *iErr = 1;
+                return NULL;
+            }
+
+            pLinesCleaned[(*newNbLines) - 1] = (char*)lines[i];
+        }
+    }
+    return pLinesCleaned;
+}
+// =============================================================================
diff --git a/scilab/modules/spreadsheet/src/cpp/csvRead.h b/scilab/modules/spreadsheet/src/cpp/csvRead.h
new file mode 100644 (file)
index 0000000..aafe985
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - DIGITEO - Allan CORNET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+#ifndef __CSV_READ_H__
+#define __CSV_READ_H__
+
+typedef enum
+{
+    CSV_READ_NO_ERROR = 0,
+    CSV_READ_MOPEN_ERROR = 1,
+    CSV_READ_FILE_NOT_EXIST = 2,
+    CSV_READ_MEMORY_ALLOCATION = 3,
+    CSV_READ_READLINES_ERROR = 4,
+    CSV_READ_COLUMNS_ERROR = 5,
+    CSV_READ_ERROR = 6,
+    CSV_READ_SEPARATOR_DECIMAL_EQUAL = 7,
+    CSV_READ_REGEXP_ERROR = 8
+} csvReadError;
+
+typedef struct
+{
+    char **pstrValues;
+    int m;
+    int n;
+    char **pstrComments;
+    int nbComments;
+    csvReadError err;
+} csvResult;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+    csvResult* csvRead(const char *filename, const char *separator, const char *decimal,
+                       const char **toreplace, int sizetoreplace, const char *regexpcomments);
+
+    csvResult* csvTextScan(const char **lines, int numberOfLines, const char *separator, const char *decimal);
+
+    void freeCsvResult(csvResult *result);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __CSV_READ_H__ */
+
diff --git a/scilab/modules/spreadsheet/src/cpp/csvWrite.c b/scilab/modules/spreadsheet/src/cpp/csvWrite.c
new file mode 100644 (file)
index 0000000..46c2031
--- /dev/null
@@ -0,0 +1,463 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - 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
+ *
+ */
+#if defined(__linux__)
+#define _GNU_SOURCE /* Bug 5673 fix: avoid dependency on GLIBC_2.7 */
+#endif
+// =============================================================================
+#include <stdio.h>
+#include <string.h>
+#include "stringToDouble.h"
+#include "csvWrite.h"
+#include "mopen.h"
+#include "mgetl.h"
+#include "expandPathVariable.h"
+#include "FileExist.h"
+#include "mclose.h"
+#include "MALLOC.h"
+#include "core_math.h"
+#ifdef _MSC_VER
+#include "strdup_windows.h"
+#endif
+#include "csv_strsubst.h"
+#include "csvDefault.h"
+#include "utftolatin.h"
+// =============================================================================
+#define DEFAULT_CSV_WRITE_STRING_FORMAT "%s"
+#define DEFAULT_CSV_WRITE_DOUBLE_FORMAT "%.lg"
+#define PlusStr "+"
+#define LessStr "+"
+#define ComplexStr "i"
+#define EMPTY_STRING ""
+#if _MSC_VER
+#define MODEWFD "wt"
+#else
+#define MODEWFD "w"
+#endif
+// =============================================================================
+#ifndef signbit
+static int signbit(double x)
+{
+    union
+    {
+        double d;
+        short s[4];
+        int i[2];
+    } u;
+
+    u.d = x;
+#if SIZEOF_INT == 4
+    return u.i[1] < 0;
+#else
+    return u.s[3] < 0;
+#endif
+}
+#endif /* signbit */
+// =============================================================================
+static int doConvertToLatin(void)
+{
+    const char *encoding = getCsvDefaultEncoding();
+    if (encoding)
+    {
+        return (strcmp(encoding, "iso-latin") == 0) ? 1 : 0;
+    }
+    return 0;
+}
+// =============================================================================
+csvWriteError csvWrite_double(const char *filename,
+                              const double *pdValues, int m, int n,
+                              const char *separator,
+                              const char *decimal,
+                              const char *precisionFormat,
+                              const char **headersLines,
+                              int nbHeadersLines)
+{
+    FILE  *fd = NULL;
+    int i = 0, j = 0;
+    char *expandedFilename = NULL;
+    int isIsoLatin = 0;
+
+    if (filename == NULL) return CSV_WRITE_ERROR;
+    if (pdValues == NULL) return CSV_WRITE_ERROR;
+    if (m < 0 || n < 0) return CSV_WRITE_ERROR;
+    if (separator == NULL) return CSV_WRITE_ERROR;
+    if (decimal == NULL) return CSV_WRITE_ERROR;
+    if (precisionFormat == NULL) return CSV_WRITE_ERROR;
+
+    if (strcmp(separator, decimal) == 0) return CSV_WRITE_SEPARATOR_DECIMAL_EQUAL;
+
+    expandedFilename = expandPathVariable((char*)filename);
+    wcfopen(fd , filename, MODEWFD);
+    if (expandedFilename)
+    {
+        FREE(expandedFilename);
+        expandedFilename = NULL;
+    }
+    if ( fd == (FILE *)NULL ) return CSV_WRITE_FOPEN_ERROR;
+
+    isIsoLatin = doConvertToLatin();
+
+    if ((headersLines) && (nbHeadersLines > 0))
+    {
+        for (i = 0; i < nbHeadersLines; i++)
+        {
+            if (isIsoLatin)
+            {
+                char *converted = utftolatin((char*)headersLines[i]);
+                if (converted)
+                {
+                    fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, converted);
+                    FREE(converted);
+                }
+                else
+                {
+                    fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, headersLines[i]);
+                }
+            }
+            else
+            {
+                fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, headersLines[i]);
+            }
+            fprintf(fd, "%s", getCsvDefaultEOL());
+        }
+    }
+
+    for (i = 0; i < m; i++)
+    {
+        for (j = 0; j < n; j++)
+        {
+            if (ISNAN(pdValues[i + m * j]))
+            {
+                fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, NanString);
+            }
+            else if (finite(pdValues[i + m * j]))
+            {
+                char buffer[65535];
+                char *result = NULL;
+                sprintf(buffer, precisionFormat, pdValues[i + m * j]);
+                result = csv_strsubst(buffer, getCsvDefaultDecimal(), decimal);
+                if (result)
+                {
+                    fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, result);
+                    FREE(result);
+                    result = NULL;
+                }
+                else
+                {
+                    fprintf(fd, DEFAULT_CSV_WRITE_DOUBLE_FORMAT, pdValues[i + m * j]);
+                }
+            }
+            else
+            {
+                if ( signbit(pdValues[i + m * j]) )
+                {
+                    fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, NegInfString);
+                }
+                else
+                {
+                    fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, InfString);
+                }
+            }
+            if (j + 1 < n) fprintf(fd, "%s", separator);
+        }
+        fprintf(fd, "%s", getCsvDefaultEOL());
+    }
+
+    fclose(fd);
+    return CSV_WRITE_NO_ERROR;
+}
+// =============================================================================
+csvWriteError csvWrite_complex(const char *filename,
+                               const double *pdValuesReal,
+                               const double *pdValuesImag,
+                               int m, int n,
+                               const char *separator,
+                               const char *decimal,
+                               const char *precisionFormat,
+                               const char **headersLines,
+                               int nbHeadersLines)
+{
+    FILE  *fd = NULL;
+    int i = 0, j = 0;
+    char *expandedFilename = NULL;
+    int isIsoLatin = 0;
+
+    if (filename == NULL) return CSV_WRITE_ERROR;
+    if (pdValuesReal == NULL) return CSV_WRITE_ERROR;
+    if (pdValuesImag == NULL) return CSV_WRITE_ERROR;
+    if (m < 0 || n < 0) return CSV_WRITE_ERROR;
+    if (separator == NULL) return CSV_WRITE_ERROR;
+    if (decimal == NULL) return CSV_WRITE_ERROR;
+    if (precisionFormat == NULL) return CSV_WRITE_ERROR;
+
+    if (strcmp(separator, decimal) == 0) return CSV_WRITE_SEPARATOR_DECIMAL_EQUAL;
+
+    expandedFilename = expandPathVariable((char*)filename);
+    wcfopen(fd , filename, MODEWFD);
+    if (expandedFilename)
+    {
+        FREE(expandedFilename);
+        expandedFilename = NULL;
+    }
+    if ( fd == (FILE *)NULL ) return CSV_WRITE_FOPEN_ERROR;
+
+    isIsoLatin = doConvertToLatin();
+
+    if ((headersLines) && (nbHeadersLines > 0))
+    {
+        for (i = 0; i < nbHeadersLines; i++)
+        {
+            if (isIsoLatin)
+            {
+                const char *converted = utftolatin((char*)headersLines[i]);
+                if (converted)
+                {
+                    fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, converted);
+                    FREE((char*)converted);
+                    converted = NULL;
+                }
+                else
+                {
+                    fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, headersLines[i]);
+                }
+            }
+            else
+            {
+                fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, headersLines[i]);
+            }
+            fprintf(fd, "%s", getCsvDefaultEOL());
+        }
+    }
+
+    for (i = 0; i < m; i++)
+    {
+        for (j = 0; j < n; j++)
+        {
+            char StringValue[65535];
+            if (ISNAN(pdValuesReal[i + m * j]))
+            {
+                strcpy(StringValue, NanString);
+            }
+            else if (finite(pdValuesReal[i + m * j]))
+            {
+                char buffer[65535];
+                char *result = NULL;
+                sprintf(buffer, precisionFormat, pdValuesReal[i + m * j]);
+                result = csv_strsubst(buffer, getCsvDefaultDecimal(), decimal);
+                if (result)
+                {
+                    strcpy(StringValue, result);
+                    FREE(result);
+                    result = NULL;
+                }
+                else
+                {
+                    sprintf(StringValue, DEFAULT_CSV_WRITE_DOUBLE_FORMAT, pdValuesReal[i + m * j]);
+                }
+            }
+            else
+            {
+                if ( signbit(pdValuesReal[i + m * j]) )
+                {
+                    // NegInfString
+                    strcpy(StringValue, NegInfString);
+                }
+                else
+                {
+                    // InfString
+                    strcpy(StringValue, InfString);
+                }
+            }
+
+            if (ISNAN(pdValuesImag[i + m * j]))
+            {
+                strcat(StringValue, PlusStr);
+                strcat(StringValue, NanString);
+                strcat(StringValue, ComplexStr);
+            }
+            else if (finite(pdValuesImag[i + m * j]))
+            {
+                char buffer[65535];
+                char *result = NULL;
+
+                if (pdValuesImag[i + m * j] >= 0)
+                {
+                    strcat(StringValue, PlusStr);
+                }
+                else
+                {
+                    strcat(StringValue, LessStr);
+                }
+
+                sprintf(buffer, precisionFormat, fabs(pdValuesImag[i + m * j]));
+                result = csv_strsubst(buffer, getCsvDefaultDecimal(), decimal);
+
+                if (result)
+                {
+                    strcat(StringValue, result);
+                    FREE(result);
+                    result = NULL;
+                }
+                else
+                {
+                    sprintf(buffer, DEFAULT_CSV_WRITE_DOUBLE_FORMAT, fabs(pdValuesImag[i + m * j]));
+                    strcat(StringValue, buffer);
+                }
+                strcat(StringValue, ComplexStr);
+            }
+            else
+            {
+                if ( signbit(pdValuesImag[i + m * j]) )
+                {
+                    // NegInfString
+                    strcat(StringValue, LessStr);
+                }
+                else
+                {
+                    // InfString
+                    strcat(StringValue, PlusStr);
+                }
+                strcat(StringValue, InfString);
+                strcat(StringValue, ComplexStr);
+            }
+            fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, StringValue);
+            if (j + 1 < n) fprintf(fd, "%s", separator);
+        }
+        fprintf(fd, "%s", getCsvDefaultEOL());
+    }
+
+    fclose(fd);
+    return CSV_WRITE_NO_ERROR;
+}
+// =============================================================================
+csvWriteError csvWrite_string(const char *filename,
+                              const char **pStrValues, int m, int n,
+                              const char *separator,
+                              const char *decimal,
+                              const char **headersLines,
+                              int nbHeadersLines)
+{
+    FILE  *fd = NULL;
+    int i = 0, j = 0;
+    char *expandedFilename = NULL;
+    int isIsoLatin = 0;
+
+    if (filename == NULL) return CSV_WRITE_ERROR;
+    if (pStrValues == NULL) return CSV_WRITE_ERROR;
+    if (m < 0 || n < 0) return CSV_WRITE_ERROR;
+    if (separator == NULL) return CSV_WRITE_ERROR;
+
+    if (strcmp(separator, decimal) == 0) return CSV_WRITE_SEPARATOR_DECIMAL_EQUAL;
+
+    expandedFilename = expandPathVariable((char*)filename);
+    wcfopen(fd , filename, MODEWFD);
+    if (expandedFilename)
+    {
+        FREE(expandedFilename);
+        expandedFilename = NULL;
+    }
+    if ( fd == (FILE *)NULL ) return CSV_WRITE_FOPEN_ERROR;
+
+    isIsoLatin = doConvertToLatin();
+
+    if ((headersLines) && (nbHeadersLines > 0))
+    {
+        for (i = 0; i < nbHeadersLines; i++)
+        {
+            if (isIsoLatin)
+            {
+                const char *converted = utftolatin((char*)headersLines[i]);
+                if (converted)
+                {
+                    fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, converted);
+                    FREE((char*)converted);
+                    converted = NULL;
+                }
+                else
+                {
+                    fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, headersLines[i]);
+                }
+            }
+            else
+            {
+                fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, headersLines[i]);
+            }
+            fprintf(fd, "%s", getCsvDefaultEOL());
+        }
+    }
+
+    for (i = 0 ; i < m ; i++ )
+    {
+        for ( j = 0 ; j < n ; j++)
+        {
+            if (decimal == NULL)
+            {
+                if (isIsoLatin)
+                {
+                    const char *converted = utftolatin((char*)pStrValues[i + m * j]);
+                    if (converted)
+                    {
+                        fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, converted);
+                        FREE((char*)converted);
+                        converted = NULL;
+                    }
+                    else
+                    {
+                        fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, pStrValues[i + m * j]);
+                    }
+                }
+                else
+                {
+                    fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, pStrValues[i + m * j]);
+                }
+            }
+            else
+            {
+                char *result = NULL;
+                result = csv_strsubst((char*)(pStrValues[i + m * j]), getCsvDefaultDecimal(), decimal);
+                if (result)
+                {
+                    if (isIsoLatin)
+                    {
+                        char *converted = utftolatin(result);
+                        if (converted)
+                        {
+                            fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, converted);
+                            FREE(converted);
+                            converted = NULL;
+                        }
+                        else
+                        {
+                            fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, result);
+                        }
+                    }
+                    else
+                    {
+                        fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, result);
+                    }
+                    FREE(result);
+                    result = NULL;
+                }
+                else
+                {
+                    fprintf(fd, DEFAULT_CSV_WRITE_STRING_FORMAT, pStrValues[i + m * j]);
+                }
+            }
+            if (j + 1 < n) fprintf(fd, "%s", separator);
+        }
+        fprintf(fd, "%s", getCsvDefaultEOL());
+    }
+
+    fclose(fd);
+    return CSV_WRITE_NO_ERROR;
+}
+// =============================================================================
+
diff --git a/scilab/modules/spreadsheet/src/cpp/csvWrite.h b/scilab/modules/spreadsheet/src/cpp/csvWrite.h
new file mode 100644 (file)
index 0000000..bf39f67
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - DIGITEO - Allan CORNET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#ifndef __CSV_WRITE_H__
+#define __CSV_WRITE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+    typedef enum {
+        CSV_WRITE_NO_ERROR = 0,
+        CSV_WRITE_FOPEN_ERROR = 1,
+        CSV_WRITE_ERROR = 2,
+        CSV_WRITE_SEPARATOR_DECIMAL_EQUAL = 3
+    }
+                                        csvWriteError;
+
+
+    csvWriteError csvWrite_double(const char *filename,
+                                  const double *pdValues, int m, int n,
+                                  const char *separator,
+                                  const char *decimal,
+                                  const char *precisionFormat,
+                                  const char **headersLines,
+                                  int nbHeadersLines);
+
+    csvWriteError csvWrite_complex(const char *filename,
+                                   const double *pdValuesReal,
+                                   const double *pdValuesImag,
+                                   int m, int n,
+                                   const char *separator,
+                                   const char *decimal,
+                                   const char *precisionFormat,
+                                   const char **headersLines,
+                                   int nbHeadersLines);
+
+    csvWriteError csvWrite_string(const char *filename,
+                                  const char **pStrValues, int m, int n,
+                                  const char *separator,
+                                  const char *decimal,
+                                  const char **headersLines,
+                                  int nbHeadersLines);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CSV_WRITE_H__ */
+// =============================================================================
+
diff --git a/scilab/modules/spreadsheet/src/cpp/csv_complex.c b/scilab/modules/spreadsheet/src/cpp/csv_complex.c
new file mode 100644 (file)
index 0000000..e14c9d2
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - 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 <string.h>
+#include "csv_complex.h"
+#include "MALLOC.h"
+// =============================================================================
+csv_complexArray *createCsvComplexArrayEmpty(int nbSize)
+{
+    csv_complexArray *pCsvComplexArray = NULL;
+    pCsvComplexArray = (csv_complexArray *) MALLOC(sizeof(csv_complexArray));
+    if (pCsvComplexArray)
+    {
+        pCsvComplexArray->realPart = (double *)MALLOC(sizeof(double) * nbSize);
+        if (pCsvComplexArray->realPart == NULL)
+        {
+            FREE(pCsvComplexArray);
+            return NULL;
+        }
+
+        pCsvComplexArray->imagPart = (double *)MALLOC(sizeof(double) * nbSize);
+        if (pCsvComplexArray->imagPart == NULL)
+        {
+            FREE(pCsvComplexArray->realPart);
+            pCsvComplexArray->realPart = NULL;
+            FREE(pCsvComplexArray);
+            return NULL;
+        }
+
+        memset(pCsvComplexArray->realPart, 0, sizeof(double) * nbSize);
+        memset(pCsvComplexArray->imagPart, 0, sizeof(double) * nbSize);
+        pCsvComplexArray->isComplex = 1;
+        pCsvComplexArray->nbElements = nbSize;
+    }
+    return pCsvComplexArray;
+}
+// =============================================================================
+csv_complexArray *createCsvComplexArray(const double *realpart, const double *imagpart, int nbSize)
+{
+    csv_complexArray *pCsvComplexArray = NULL;
+
+    if (realpart == NULL)
+    {
+        return pCsvComplexArray;
+    }
+
+    if (nbSize <= 0)
+    {
+        return pCsvComplexArray;
+    }
+
+    pCsvComplexArray = (csv_complexArray *) MALLOC(sizeof(csv_complexArray));
+    if (pCsvComplexArray)
+    {
+        if (imagpart == NULL)
+        {
+            pCsvComplexArray->isComplex = 0;
+        }
+        else
+        {
+            int i = 0;
+            pCsvComplexArray->isComplex = 0;
+            for (i = 0; i < nbSize; i++)
+            {
+                if (imagpart[i] != 0)
+                {
+                    pCsvComplexArray->isComplex = 1;
+                    break;
+                }
+            }
+        }
+
+        pCsvComplexArray->realPart = (double *)MALLOC(sizeof(double) * nbSize);
+        if (pCsvComplexArray->realPart)
+        {
+            memcpy(pCsvComplexArray->realPart, realpart, nbSize);
+            pCsvComplexArray->nbElements = nbSize;
+        }
+        if (pCsvComplexArray->isComplex)
+        {
+            pCsvComplexArray->imagPart = (double *)MALLOC(sizeof(double) * nbSize);
+            if (pCsvComplexArray->imagPart)
+            {
+                memcpy(pCsvComplexArray->imagPart, imagpart, nbSize);
+            }
+        }
+        else
+        {
+            pCsvComplexArray->imagPart = NULL;
+        }
+    }
+    return pCsvComplexArray;
+}
+// =============================================================================
+void freeCsvComplexArray(csv_complexArray *pCsvComplexArray)
+{
+    if (pCsvComplexArray)
+    {
+        if (pCsvComplexArray->realPart)
+        {
+            FREE(pCsvComplexArray->realPart);
+            pCsvComplexArray->realPart = NULL;
+        }
+
+        if (pCsvComplexArray->imagPart)
+        {
+            FREE(pCsvComplexArray->imagPart);
+            pCsvComplexArray->imagPart = NULL;
+        }
+        pCsvComplexArray->isComplex = 0;
+        pCsvComplexArray->nbElements = 0;
+
+        FREE(pCsvComplexArray);
+        pCsvComplexArray = NULL;
+    }
+}
+// =============================================================================
+int cleanImagPartCsvComplexArray(csv_complexArray *pCsvComplexArray)
+{
+    if (pCsvComplexArray)
+    {
+        if (pCsvComplexArray->imagPart)
+        {
+            int i = 0;
+            int isComplex = 0;
+            for (i = 0; i < pCsvComplexArray->nbElements; i++)
+            {
+                if (pCsvComplexArray->imagPart[i] != 0)
+                {
+                    isComplex = 1;
+                    break;
+                }
+            }
+
+            if (isComplex)
+            {
+                pCsvComplexArray->isComplex = 1;
+            }
+            else
+            {
+                pCsvComplexArray->isComplex = 0;
+            }
+        }
+        else
+        {
+            return 1;
+        }
+    }
+    return 0;
+}
+// =============================================================================
diff --git a/scilab/modules/spreadsheet/src/cpp/csv_complex.h b/scilab/modules/spreadsheet/src/cpp/csv_complex.h
new file mode 100644 (file)
index 0000000..2621438
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - DIGITEO - Allan CORNET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+#ifndef __CSV_COMPLEX_H__
+#define __CSV_COMPLEX_H__
+
+typedef struct
+{
+    double *realPart;
+    double *imagPart;
+    int nbElements;
+    int isComplex;
+} csv_complexArray;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+    csv_complexArray *createCsvComplexArray(const double *realpart, const double *imagpart, int nbSize);
+    csv_complexArray *createCsvComplexArrayEmpty(int nbSize);
+    int cleanImagPartCsvComplexArray(csv_complexArray *pCsvComplexArray);
+    void freeCsvComplexArray(csv_complexArray *pCsvComplexArray);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __CSV_COMPLEX_H__ */
+
diff --git a/scilab/modules/spreadsheet/src/cpp/csv_strsubst.cpp b/scilab/modules/spreadsheet/src/cpp/csv_strsubst.cpp
new file mode 100644 (file)
index 0000000..82fb39e
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - 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 <string.h>
+#ifndef _MSC_VER
+#include <cstddef>
+#endif
+#include "csv_strsubst.h"
+#include "MALLOC.h"
+#ifdef _MSC_VER
+#include "strdup_windows.h"
+#endif
+// =============================================================================
+char *csv_strsubst(const char *input_string, const char *string_to_search, const char *replacement_string)
+{
+    char *result = NULL, *r = NULL;
+    const char *p = NULL, *q = NULL;
+
+    size_t string_to_searchlen = 0;
+    size_t count = 0, resultlen = 0, replacement_stringlen = 0;
+
+    if (input_string == NULL) return NULL;
+    if (string_to_search == NULL) return strdup(input_string);
+    if (replacement_string == NULL) return strdup(input_string);
+
+    string_to_searchlen = strlen(string_to_search);
+    replacement_stringlen = strlen(replacement_string);
+
+    if (string_to_searchlen != replacement_stringlen)
+    {
+        for (count = 0, p = input_string; (q = strstr(p, string_to_search)) != NULL; p = q + string_to_searchlen)
+        {
+            count++;
+        }
+        resultlen = p - input_string + strlen(p) + count * (replacement_stringlen - string_to_searchlen);
+    }
+    else
+    {
+        resultlen = strlen(input_string);
+    }
+
+    if (resultlen + 1 > 0) result = (char*)CALLOC(resultlen + 1, sizeof(char));
+    if (result)
+    {
+        for (r = result, p = input_string; (q = strstr(p, string_to_search)) != NULL; p = q + string_to_searchlen)
+        {
+
+            ptrdiff_t l = q - p;
+            memcpy(r, p, l);
+            r += l;
+            memcpy(r, replacement_string, replacement_stringlen);
+            r += replacement_stringlen;
+        }
+        strcpy(r, p);
+    }
+
+    return result;
+}
+// =============================================================================
diff --git a/scilab/modules/spreadsheet/src/cpp/csv_strsubst.h b/scilab/modules/spreadsheet/src/cpp/csv_strsubst.h
new file mode 100644 (file)
index 0000000..7395c1a
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - DIGITEO - Allan CORNET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+#ifndef __CSV_STRSUBST_H__
+#define __CSV_STRSUBST_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+    char * csv_strsubst(const char* input_string,
+                        const char* string_to_search,
+                        const char* replacement_string);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __CSV_STRSUBST_H__ */
+// =============================================================================
diff --git a/scilab/modules/spreadsheet/src/cpp/getRange.c b/scilab/modules/spreadsheet/src/cpp/getRange.c
new file mode 100644 (file)
index 0000000..08ced60
--- /dev/null
@@ -0,0 +1,241 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - 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 <string.h>
+#include "MALLOC.h"
+#include "getRange.h"
+#ifdef _MSC_VER
+#include "strdup_windows.h"
+#endif
+// =============================================================================
+#define SIZE_ARRAY_RANGE 4
+// =============================================================================
+static int getSizeRange(const int *iRange, int nbRows, int nbCols);
+static int getSizeRows(const int *iRange, int nbRows);
+static int getSizeCols(const int *iRange, int nbCols);
+// =============================================================================
+void getSubIndices(const int *iRange, int * R1, int * R2, int * C1, int * C2 )
+{
+    *R1 = iRange[0];
+    *C1 = iRange[1];
+    *R2 = iRange[2];
+    *C2 = iRange[3];
+
+    return;
+}
+// =============================================================================
+int isValidRange(const int *iRange, int sizeArray)
+{
+    int i = 0;
+    int R1 = 0, C1 = 0, R2 = 0, C2 = 0;
+
+    if (iRange == NULL)
+    {
+        return 0;
+    }
+
+    getSubIndices(iRange, &R1, &R2, &C1, &C2 );
+
+    if (sizeArray != SIZE_ARRAY_RANGE)
+    {
+        return 0;
+    }
+
+    if (R1 <= 0)
+    {
+        return 0;
+    }
+    if (R2 <= 0)
+    {
+        return 0;
+    }
+    if (C1 <= 0)
+    {
+        return 0;
+    }
+    if (C2 <= 0)
+    {
+        return 0;
+    }
+    if (R1 > R2)
+    {
+        return 0;
+    }
+    if (C1 > C2)
+    {
+        return 0;
+    }
+
+    return 1;
+}
+// =============================================================================
+char **getRangeAsString(const char **pStrsValues,
+                        int nbRows, int nbCols,
+                        const int *iRange,
+                        int *returnedNbRows, int *returnedNbCols)
+{
+    if (isValidRange(iRange, SIZE_ARRAY_RANGE))
+    {
+        char **newStrArray = NULL;
+        int sizeRange = getSizeRange(iRange, nbRows, nbCols);
+        int R1, C1, R2, C2;
+
+        getSubIndices(iRange, &R1, &R2, &C1, &C2 );
+
+        *returnedNbRows = getSizeRows(iRange, nbRows);
+        *returnedNbCols = getSizeCols(iRange, nbCols);
+
+        newStrArray = (char**)MALLOC(sizeof(char*) * sizeRange);
+        if (newStrArray == NULL)
+        {
+            *returnedNbCols = 0;
+            *returnedNbRows = 0;
+        }
+        else
+        {
+            int i = 0;
+            int j = 0;
+            int k = 0;
+
+            if ( C2 > nbCols )
+            {
+                C2 = nbCols;
+            }
+            if ( R2 > nbRows )
+            {
+                R2 = nbRows;
+            }
+
+            for ( j = C1 - 1 ; j < C2 ; j++)
+            {
+                for (i = R1 - 1 ; i < R2 ; i++ )
+                {
+                    newStrArray[k] = strdup(pStrsValues[i + nbRows * j]);
+                    k++;
+                }
+            }
+        }
+        return newStrArray;
+    }
+    return NULL;
+}
+// =============================================================================
+csv_complexArray *getRangeAsCsvComplexArray(const csv_complexArray *pComplex,
+        int nbRows, int nbCols,
+        const int *iRange,
+        int *returnedNbRows, int *returnedNbCols)
+{
+    if (isValidRange(iRange, SIZE_ARRAY_RANGE))
+    {
+        csv_complexArray *newComplexArray = NULL;
+        int sizeRange = getSizeRange(iRange, nbRows, nbCols);
+        int R1 = 0, C1 = 0, R2 = 0, C2 = 0;
+
+        getSubIndices(iRange, &R1, &R2, &C1, &C2 );
+
+        *returnedNbRows = getSizeRows(iRange, nbRows);
+        *returnedNbCols = getSizeCols(iRange, nbCols);
+
+        newComplexArray = createCsvComplexArrayEmpty(sizeRange);
+        if (newComplexArray == NULL)
+        {
+            *returnedNbCols = 0;
+            *returnedNbRows = 0;
+        }
+        else
+        {
+            int i = 0;
+            int j = 0;
+            int k = 0;
+
+            if ( C2 > nbCols )
+            {
+                C2 = nbCols;
+            }
+            if ( R2 > nbRows )
+            {
+                R2 = nbRows;
+            }
+
+            newComplexArray->isComplex = pComplex->isComplex;
+
+            for ( j = C1 - 1 ; j < C2 ; j++)
+            {
+                for (i = R1 - 1 ; i < R2 ; i++)
+                {
+                    newComplexArray->realPart[k] = pComplex->realPart[i + (nbRows * j)];
+                    if (pComplex->isComplex)
+                    {
+                        newComplexArray->imagPart[k] = pComplex->imagPart[i + (nbRows * j)];
+                    }
+                    k++;
+                }
+            }
+        }
+
+        return newComplexArray;
+    }
+    return NULL;
+}
+// =============================================================================
+static int getSizeRange(const int *iRange, int nbRows, int nbCols)
+{
+    int sizeRange;
+    if (iRange)
+    {
+        sizeRange = getSizeRows(iRange, nbRows) * getSizeCols(iRange, nbCols);
+    }
+    else
+    {
+        sizeRange = 0;
+    }
+    return sizeRange;
+}
+// =============================================================================
+static int getSizeRows(const int *iRange, int nbRows)
+{
+    int sizeRows = 0;
+    int R1, R2, C1, C2;
+
+    getSubIndices(iRange, &R1, &R2, &C1, &C2 );
+
+    if (iRange == NULL)
+    {
+        return 0;
+    }
+    if ( R2 > nbRows )
+    {
+        R2 = nbRows;
+    }
+    sizeRows = R2 - R1 + 1;
+    return sizeRows;
+}
+// =============================================================================
+static int getSizeCols(const int *iRange, int nbCols)
+{
+    int sizeCols = 0;
+    int R1, R2, C1, C2;
+
+    getSubIndices(iRange, &R1, &R2, &C1, &C2 );
+
+    if (iRange == NULL)
+    {
+        return 0;
+    }
+    if ( C2 > nbCols )
+    {
+        C2 = nbCols;
+    }
+    sizeCols = C2 - C1 + 1;
+
+    return sizeCols;
+}
+// =============================================================================
diff --git a/scilab/modules/spreadsheet/src/cpp/getRange.h b/scilab/modules/spreadsheet/src/cpp/getRange.h
new file mode 100644 (file)
index 0000000..f8744b8
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - DIGITEO - Allan CORNET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+#ifndef __GETRANGE_H__
+#define __GETRANGE_H__
+
+#include "doublecomplex.h"
+#include "csv_complex.h"
+
+#define SIZE_RANGE_SUPPORTED 4
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+    // Extract the strings in pStrsValues which are in the range.
+    char **getRangeAsString(const char **pStrsValues,
+                            int nbRows, int nbCols,
+                            const int *iRange,
+                            int *returnedNbRows, int *returnedNbCols);
+
+
+    // Extract the double complexes in pComplex which are in the range.
+    csv_complexArray *getRangeAsCsvComplexArray(const csv_complexArray *pComplex,
+            int nbRows, int nbCols,
+            const int *iRange,
+            int *returnedNbRows, int *returnedNbCols);
+
+
+    // Returns 1 if the range is valid, returns 0 if not.
+    int isValidRange(const int *range, int sizeArray);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __GETRANGE_H__ */
+// =============================================================================
diff --git a/scilab/modules/spreadsheet/src/cpp/latintoutf.c b/scilab/modules/spreadsheet/src/cpp/latintoutf.c
new file mode 100644 (file)
index 0000000..d0ec1df
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - 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 <string.h>
+#ifdef _MSC_VER
+#include <windows.h>
+#include "strdup_windows.h"
+#endif
+#include "latintoutf.h"
+#include "charEncoding.h"
+#include "MALLOC.h"
+// =============================================================================
+#ifdef _MSC_VER
+#pragma comment(lib,"oleaut32.lib")
+#endif
+// =============================================================================
+#define LINE_MAX 4096
+#define EMPTYSTR ""
+// =============================================================================
+char *latintoutf(char *_inString)
+{
+    char *outString = NULL;
+    if (_inString)
+    {
+#ifdef _MSC_VER
+        if (IsValidUTF8(_inString))
+        {
+            outString = strdup(_inString);
+        }
+        else
+        {
+            /* conversion ANSI to UTF */
+            int Len = 0;
+            int newLen = 0;
+            BSTR bstrCode = NULL;
+
+            Len = MultiByteToWideChar(CP_ACP, 0, _inString, lstrlen(_inString), NULL, NULL);
+            bstrCode = SysAllocStringLen(NULL, Len);
+            if (bstrCode)
+            {
+                if (MultiByteToWideChar(CP_ACP, 0, _inString, lstrlen(_inString), bstrCode, Len) == 0)
+                {
+                    return strdup(_inString);
+                }
+
+                newLen = WideCharToMultiByte(CP_UTF8, 0, bstrCode, -1, outString, 0, NULL, NULL);
+                outString = (char*) MALLOC(newLen + 1);
+                if (outString)
+                {
+                    if (WideCharToMultiByte(CP_UTF8, 0, bstrCode, -1, outString, newLen, NULL, NULL) == 0)
+                    {
+                        SysFreeString(bstrCode);
+                        FREE(outString);
+                        return strdup(_inString);
+                    }
+                }
+                else
+                {
+                    outString = strdup(_inString);
+                }
+                SysFreeString(bstrCode);
+                bstrCode = NULL;
+            }
+            else
+            {
+                outString = strdup(_inString);
+            }
+        }
+#else
+        if (IsValidUTF8(_inString))
+        {
+            outString = strdup(_inString);
+        }
+        else
+        {
+            int len = (int)strlen(_inString);
+            int i = 0;
+
+            outString = (char*)MALLOC(((len * 3) + 1) * sizeof(char));
+            if (outString == NULL) return NULL;
+            strcpy(outString, EMPTYSTR);
+
+            for (i = 0; i < len; i++)
+            {
+                unsigned char *outUtfChar = NULL;
+                unsigned char inAnsiChar = 0;
+
+                if (_inString[i] < 0) inAnsiChar = 256 + _inString[i];
+                else inAnsiChar = _inString[i];
+
+                if (inAnsiChar < 128)
+                {
+                    outUtfChar = (unsigned char *)CALLOC(2, sizeof(unsigned char));
+                    if (outUtfChar)
+                    {
+                        outUtfChar[0] = inAnsiChar;
+                        outUtfChar[1] = 0;
+                    }
+                }
+                else
+                {
+                    outUtfChar = (unsigned char *)CALLOC(3, sizeof(unsigned char));
+                    if (outUtfChar)
+                    {
+                        outUtfChar[0] = (inAnsiChar >> 6) | 0xC0;
+                        outUtfChar[1] = (inAnsiChar & 0x3F) | 0x80;
+                        outUtfChar[2] = 0;
+                    }
+                }
+
+                if (outUtfChar)
+                {
+                    strcat(outString, (char*)outUtfChar);
+                    FREE(outUtfChar);
+                    outUtfChar = NULL;
+                }
+            }
+        }
+#endif
+    }
+    return outString;
+}
+/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/spreadsheet/src/cpp/latintoutf.h b/scilab/modules/spreadsheet/src/cpp/latintoutf.h
new file mode 100644 (file)
index 0000000..b645d93
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - DIGITEO - Allan CORNET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+#ifndef __LATINTOUTF_H__
+#define __LATINTOUTF_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+    char *latintoutf(char *_inString);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __LATINTOUTF_H__ */
+// =============================================================================
diff --git a/scilab/modules/spreadsheet/src/cpp/splitLine.c b/scilab/modules/spreadsheet/src/cpp/splitLine.c
new file mode 100644 (file)
index 0000000..d40b8c4
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - 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 <string.h>
+#include <stdio.h>
+#include "splitLine.h"
+#include "csv_strsubst.h"
+#include "MALLOC.h"
+/* ==================================================================== */
+char **splitLine(const char *str, const char *sep, int *toks, char meta)
+{
+#define emptyfield "__EMPTY_FIELD_CSV__"
+    char **retstr = NULL;
+    const char *idx = NULL;
+    const char *end = NULL;
+    const char *sep_end = NULL;
+    const char *sep_idx = NULL;
+    int len = 0;
+    int curr_str = 0;
+    char last_char = 0xFF;
+
+    char tokenstring_to_search[64] = ",,";
+    char tokenreplacement_string[64] = ",,";
+    char *substitutedstring = NULL;
+
+    sprintf(tokenstring_to_search, "%s%s", sep, sep);
+    sprintf(tokenreplacement_string, "%s%s%s", sep, emptyfield, sep);
+    substitutedstring = csv_strsubst(str, tokenstring_to_search, tokenreplacement_string);
+    if (strncmp(substitutedstring, sep, strlen(sep)) == 0)
+    {
+        char *tmp = NULL;
+        size_t l = strlen(substitutedstring) + strlen(emptyfield) + strlen(sep) + 1;
+        tmp = (char*)MALLOC(sizeof(char) * l);
+        sprintf(tmp, "%s%s%s", emptyfield, sep, &substitutedstring[1]);
+        FREE(substitutedstring);
+        substitutedstring = tmp;
+    }
+
+    if (substitutedstring[strlen(substitutedstring) - 1] == sep[0])
+    {
+        char *tmp = NULL;
+        size_t l = strlen(substitutedstring) + strlen(emptyfield) + 1;
+        tmp = (char*)MALLOC(sizeof(char) * l);
+        sprintf(tmp, "%s%s", substitutedstring, emptyfield);
+        FREE(substitutedstring);
+        substitutedstring = tmp;
+
+    }
+
+    sep_end = sep + strlen(sep);
+    end = substitutedstring + strlen(substitutedstring);
+
+    sep_idx = sep;
+    idx = substitutedstring;
+
+    if (strstr(substitutedstring, sep) == NULL)
+    {
+        *toks = 0;
+        FREE(substitutedstring);
+        substitutedstring = NULL;
+        return NULL;
+    }
+
+    retstr = (char **) MALLOC((sizeof(char *) * (int)strlen(substitutedstring)));
+    if (retstr == NULL)
+    {
+        *toks = 0;
+        FREE(substitutedstring);
+        substitutedstring = NULL;
+        return NULL;
+    }
+
+    while (idx < end)
+    {
+        while (sep_idx < sep_end)
+        {
+            if ((*idx == *sep_idx) && (last_char != meta))
+            {
+                if (len > 0)
+                {
+                    if (curr_str < (int)strlen(substitutedstring))
+                    {
+                        retstr[curr_str] = (char *) MALLOC((sizeof(char) * len) + 1);
+
+                        if (retstr[curr_str] == NULL)
+                        {
+                            *toks = 0;
+                            FREE(substitutedstring);
+                            substitutedstring = NULL;
+                            return NULL;
+                        }
+                        memcpy(retstr[curr_str], (idx - len), len);
+                        retstr[curr_str][len] = 0;
+                        if (strcmp(retstr[curr_str], emptyfield) == 0)
+                        {
+                            strcpy(retstr[curr_str], "");
+                        }
+                        len = 0;
+                        curr_str++;
+                        last_char = *idx;
+                        idx++;
+                    }
+
+                    if (curr_str >= (int)strlen(substitutedstring))
+                    {
+                        *toks = curr_str + 1;
+                        FREE(substitutedstring);
+                        substitutedstring = NULL;
+                        return retstr;
+                    }
+                }
+                else
+                {
+                    last_char = *idx;
+                    idx++;
+                    sep_idx = sep;
+                    len = 0;
+                }
+            }
+            else
+            {
+                sep_idx++;
+            }
+        }
+
+        sep_idx = sep;
+        len++;
+        last_char = *idx;
+        idx++;
+    }
+
+    if (len > 0)
+    {
+        retstr[curr_str] = (char *) MALLOC((sizeof(char) * len) + 1);
+
+        if (retstr[curr_str] == NULL)
+        {
+            *toks = 0;
+            if (substitutedstring)
+            {
+                FREE(substitutedstring);
+                substitutedstring = NULL;
+            }
+            return NULL;
+        }
+
+        memcpy(retstr[curr_str], (idx - len), len);
+        retstr[curr_str][len] = 0;
+        if (strcmp(retstr[curr_str], emptyfield) == 0)
+        {
+            strcpy(retstr[curr_str], "");
+        }
+
+        *toks = curr_str + 1;
+    }
+
+    if (substitutedstring)
+    {
+        FREE(substitutedstring);
+        substitutedstring = NULL;
+    }
+
+    return retstr;
+}
+/* ==================================================================== */
diff --git a/scilab/modules/spreadsheet/src/cpp/splitLine.h b/scilab/modules/spreadsheet/src/cpp/splitLine.h
new file mode 100644 (file)
index 0000000..787a391
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - DIGITEO - Allan CORNET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+#ifndef __SPLITLINE_H__
+#define __SPLITLINE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+    /**
+    * split a line by separator
+    */
+    char **splitLine(const char *str, const char *sep, int *toks, char meta);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __SPLITLINE_H__ */
+/* ==================================================================== */
diff --git a/scilab/modules/spreadsheet/src/cpp/stringToComplex.c b/scilab/modules/spreadsheet/src/cpp/stringToComplex.c
new file mode 100644 (file)
index 0000000..9663d93
--- /dev/null
@@ -0,0 +1,498 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010-2011 - 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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <ctype.h>
+#include "stringToComplex.h"
+#include "stringToDouble.h"
+#include "MALLOC.h"
+#ifdef  _MSC_VER
+#include "strdup_windows.h"
+#endif
+#include "BOOL.h"
+#include "csv_strsubst.h"
+/* ========================================================================== */
+#define PlusChar '+'
+#define LessChar '-'
+#define ComplexCharI 'i'
+#define ComplexCharJ 'j'
+#define ComplexScilab "%i"
+#define ComplexI "i"
+/* ========================================================================== */
+#ifndef _MSC_VER
+#ifndef strnicmp
+#define strnicmp strncasecmp
+#endif
+#else
+#define stricmp _stricmp
+#endif
+#ifdef _MSC_VER
+#undef strnicmp
+#define strnicmp _strnicmp
+#endif
+/* ========================================================================== */
+static int ParseNumber(const char* tx);
+static stringToComplexError ParseComplexValue(const char *tx, BOOL bConvertByNAN, double *real, double *imag);
+static char *midstring(const char *tx, size_t pos, int nb);
+static char *leftstring(const char *tx, size_t pos);
+static BOOL is_unit_imaginary (const char *src, double *im);
+static double returnNAN(void);
+/* ========================================================================== */
+csv_complexArray *stringsToCvsComplexArray(const char **pSTRs, int nbElements,
+        const char *decimal,
+        BOOL bConvertByNAN,
+        stringToComplexError *ierr)
+{
+    csv_complexArray *pCsvComplexArray = NULL;
+
+    *ierr = STRINGTOCOMPLEX_ERROR;
+    if (nbElements <= 0)
+    {
+        return NULL;
+    }
+
+    if (pSTRs == NULL)
+    {
+        *ierr = STRINGTOCOMPLEX_MEMORY_ALLOCATION;
+    }
+    else
+    {
+        pCsvComplexArray = createCsvComplexArrayEmpty(nbElements);
+        if (pCsvComplexArray)
+        {
+            int i = 0;
+            for (i = 0; i < nbElements; i++)
+            {
+                doublecomplex dComplexValue = stringToComplex(pSTRs[i], decimal, bConvertByNAN, ierr);
+                if (*ierr != STRINGTOCOMPLEX_NO_ERROR)
+                {
+                    freeCsvComplexArray(pCsvComplexArray);
+                    return NULL;
+                }
+                else
+                {
+                    pCsvComplexArray->realPart[i] = dComplexValue.r;
+                    pCsvComplexArray->imagPart[i] = dComplexValue.i;
+                }
+            }
+            cleanImagPartCsvComplexArray(pCsvComplexArray);
+        }
+        else
+        {
+            *ierr = STRINGTOCOMPLEX_MEMORY_ALLOCATION;
+        }
+    }
+    return pCsvComplexArray;
+}
+/* ========================================================================== */
+doublecomplex stringToComplex(const char *pSTR, const char *decimal, BOOL bConvertByNAN, stringToComplexError *ierr)
+{
+    doublecomplex dComplexValue;
+    *ierr = STRINGTOCOMPLEX_ERROR;
+
+    dComplexValue.r = 0.;
+    dComplexValue.i = 0.;
+
+    if (pSTR)
+    {
+        double real = 0.;
+        double imag = 0.;
+        char * pStrWithOutBlanks = csv_strsubst(pSTR, " ", "");
+
+        pStrWithO