archiveExtract wrappers, sources, help, tests added 23/16723/2
Kartik Gupta [Wed, 24 Jun 2015 13:28:40 +0000 (18:28 +0530)]
Change-Id: I4b77ac17b565a83862dda9c7900f8b29eb39d0a8

14 files changed:
scilab/modules/fileio/Makefile.am
scilab/modules/fileio/Makefile.in
scilab/modules/fileio/fileio.vcxproj
scilab/modules/fileio/fileio.vcxproj.filters
scilab/modules/fileio/help/en_US/archiveExtract.xml [new file with mode: 0644]
scilab/modules/fileio/includes/archive_extract.h [new file with mode: 0644]
scilab/modules/fileio/includes/gw_fileio.h
scilab/modules/fileio/sci_gateway/c/gw_fileio.c
scilab/modules/fileio/sci_gateway/c/sci_archive_extract.c [new file with mode: 0644]
scilab/modules/fileio/sci_gateway/fileio_gateway.xml
scilab/modules/fileio/src/c/archive_extract.c [new file with mode: 0644]
scilab/modules/fileio/src/c/archive_extract.h [new file with mode: 0644]
scilab/modules/fileio/tests/unit_tests/archiveExtract.dia.ref [new file with mode: 0644]
scilab/modules/fileio/tests/unit_tests/archiveExtract.tst [new file with mode: 0644]

index 0b4e92a..2ce8437 100644 (file)
@@ -58,7 +58,8 @@ src/c/fprintfMat.c \
 src/c/createtempfilename.c \
 src/c/dlManager.c \
 src/c/convert_tools.c \
-src/c/archive_list.c 
+src/c/archive_list.c \
+src/c/archive_extract.c
 
 GATEWAY_SOURCES = \
 sci_gateway/c/gw_fileio.c \
@@ -109,7 +110,8 @@ sci_gateway/c/sci_mputl.c \
 sci_gateway/c/sci_tempname.c \
 sci_gateway/c/sci_getURL.c \
 sci_gateway/c/sci_splitURL.c \
-sci_gateway/c/sci_archive_list.c 
+sci_gateway/c/sci_archive_list.c \
+sci_gateway/c/sci_archive_extract.c
 
 libscifileio_la_CPPFLAGS = -I$(srcdir)/includes/ \
                                -I$(srcdir)/src/c/ \
index b306a67..855bf48 100644 (file)
@@ -223,7 +223,8 @@ am__objects_1 = src/c/libscifileio_algo_la-FileExist.lo \
        src/c/libscifileio_algo_la-createtempfilename.lo \
        src/c/libscifileio_algo_la-dlManager.lo \
        src/c/libscifileio_algo_la-convert_tools.lo \
-       src/c/libscifileio_algo_la-archive_list.lo
+       src/c/libscifileio_algo_la-archive_list.lo \
+       src/c/libscifileio_algo_la-archive_extract.lo
 am_libscifileio_algo_la_OBJECTS = $(am__objects_1)
 libscifileio_algo_la_OBJECTS = $(am_libscifileio_algo_la_OBJECTS)
 AM_V_lt = $(am__v_lt_@AM_V@)
@@ -282,7 +283,8 @@ am__objects_2 = sci_gateway/c/libscifileio_la-gw_fileio.lo \
        sci_gateway/c/libscifileio_la-sci_tempname.lo \
        sci_gateway/c/libscifileio_la-sci_getURL.lo \
        sci_gateway/c/libscifileio_la-sci_splitURL.lo \
-       sci_gateway/c/libscifileio_la-sci_archive_list.lo
+       sci_gateway/c/libscifileio_la-sci_archive_list.lo \
+       sci_gateway/c/libscifileio_la-sci_archive_extract.lo
 am_libscifileio_la_OBJECTS = $(am__objects_2)
 libscifileio_la_OBJECTS = $(am_libscifileio_la_OBJECTS)
 @MAINTAINER_MODE_FALSE@am_libscifileio_la_rpath =
@@ -684,7 +686,8 @@ src/c/fprintfMat.c \
 src/c/createtempfilename.c \
 src/c/dlManager.c \
 src/c/convert_tools.c \
-src/c/archive_list.c 
+src/c/archive_list.c \
+src/c/archive_extract.c
 
 GATEWAY_SOURCES = \
 sci_gateway/c/gw_fileio.c \
@@ -735,7 +738,8 @@ sci_gateway/c/sci_mputl.c \
 sci_gateway/c/sci_tempname.c \
 sci_gateway/c/sci_getURL.c \
 sci_gateway/c/sci_splitURL.c \
-sci_gateway/c/sci_archive_list.c 
+sci_gateway/c/sci_archive_list.c \
+sci_gateway/c/sci_archive_extract.c
 
 libscifileio_la_CPPFLAGS = -I$(srcdir)/includes/ \
                                -I$(srcdir)/src/c/ \
@@ -1055,6 +1059,8 @@ src/c/libscifileio_algo_la-convert_tools.lo: src/c/$(am__dirstamp) \
        src/c/$(DEPDIR)/$(am__dirstamp)
 src/c/libscifileio_algo_la-archive_list.lo: src/c/$(am__dirstamp) \
        src/c/$(DEPDIR)/$(am__dirstamp)
+src/c/libscifileio_algo_la-archive_extract.lo: src/c/$(am__dirstamp) \
+       src/c/$(DEPDIR)/$(am__dirstamp)
 
 libscifileio-algo.la: $(libscifileio_algo_la_OBJECTS) $(libscifileio_algo_la_DEPENDENCIES) $(EXTRA_libscifileio_algo_la_DEPENDENCIES) 
        $(AM_V_CCLD)$(LINK) $(am_libscifileio_algo_la_rpath) $(libscifileio_algo_la_OBJECTS) $(libscifileio_algo_la_LIBADD) $(LIBS)
@@ -1211,6 +1217,9 @@ sci_gateway/c/libscifileio_la-sci_splitURL.lo:  \
 sci_gateway/c/libscifileio_la-sci_archive_list.lo:  \
        sci_gateway/c/$(am__dirstamp) \
        sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/c/libscifileio_la-sci_archive_extract.lo:  \
+       sci_gateway/c/$(am__dirstamp) \
+       sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
 
 libscifileio.la: $(libscifileio_la_OBJECTS) $(libscifileio_la_DEPENDENCIES) $(EXTRA_libscifileio_la_DEPENDENCIES) 
        $(AM_V_CCLD)$(LINK) $(am_libscifileio_la_rpath) $(libscifileio_la_OBJECTS) $(libscifileio_la_LIBADD) $(LIBS)
@@ -1226,6 +1235,7 @@ distclean-compile:
        -rm -f *.tab.c
 
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscifileio_la-gw_fileio.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_archive_extract.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_archive_list.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_basename.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_chdir.Plo@am__quote@
@@ -1279,6 +1289,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscifileio_algo_la-Status2Mode.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscifileio_algo_la-URIFileToFilename.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscifileio_algo_la-addfile.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscifileio_algo_la-archive_extract.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscifileio_algo_la-archive_list.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscifileio_algo_la-basename.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscifileio_algo_la-cluni0.Plo@am__quote@
@@ -1739,6 +1750,13 @@ src/c/libscifileio_algo_la-archive_list.lo: src/c/archive_list.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifileio_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/c/libscifileio_algo_la-archive_list.lo `test -f 'src/c/archive_list.c' || echo '$(srcdir)/'`src/c/archive_list.c
 
+src/c/libscifileio_algo_la-archive_extract.lo: src/c/archive_extract.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifileio_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/c/libscifileio_algo_la-archive_extract.lo -MD -MP -MF src/c/$(DEPDIR)/libscifileio_algo_la-archive_extract.Tpo -c -o src/c/libscifileio_algo_la-archive_extract.lo `test -f 'src/c/archive_extract.c' || echo '$(srcdir)/'`src/c/archive_extract.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) src/c/$(DEPDIR)/libscifileio_algo_la-archive_extract.Tpo src/c/$(DEPDIR)/libscifileio_algo_la-archive_extract.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='src/c/archive_extract.c' object='src/c/libscifileio_algo_la-archive_extract.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifileio_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/c/libscifileio_algo_la-archive_extract.lo `test -f 'src/c/archive_extract.c' || echo '$(srcdir)/'`src/c/archive_extract.c
+
 sci_gateway/c/libscifileio_la-gw_fileio.lo: sci_gateway/c/gw_fileio.c
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifileio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sci_gateway/c/libscifileio_la-gw_fileio.lo -MD -MP -MF sci_gateway/c/$(DEPDIR)/libscifileio_la-gw_fileio.Tpo -c -o sci_gateway/c/libscifileio_la-gw_fileio.lo `test -f 'sci_gateway/c/gw_fileio.c' || echo '$(srcdir)/'`sci_gateway/c/gw_fileio.c
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) sci_gateway/c/$(DEPDIR)/libscifileio_la-gw_fileio.Tpo sci_gateway/c/$(DEPDIR)/libscifileio_la-gw_fileio.Plo
@@ -2082,6 +2100,13 @@ sci_gateway/c/libscifileio_la-sci_archive_list.lo: sci_gateway/c/sci_archive_lis
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifileio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sci_gateway/c/libscifileio_la-sci_archive_list.lo `test -f 'sci_gateway/c/sci_archive_list.c' || echo '$(srcdir)/'`sci_gateway/c/sci_archive_list.c
 
+sci_gateway/c/libscifileio_la-sci_archive_extract.lo: sci_gateway/c/sci_archive_extract.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifileio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sci_gateway/c/libscifileio_la-sci_archive_extract.lo -MD -MP -MF sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_archive_extract.Tpo -c -o sci_gateway/c/libscifileio_la-sci_archive_extract.lo `test -f 'sci_gateway/c/sci_archive_extract.c' || echo '$(srcdir)/'`sci_gateway/c/sci_archive_extract.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_archive_extract.Tpo sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_archive_extract.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='sci_gateway/c/sci_archive_extract.c' object='sci_gateway/c/libscifileio_la-sci_archive_extract.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifileio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sci_gateway/c/libscifileio_la-sci_archive_extract.lo `test -f 'sci_gateway/c/sci_archive_extract.c' || echo '$(srcdir)/'`sci_gateway/c/sci_archive_extract.c
+
 mostlyclean-libtool:
        -rm -f *.lo
 
index d569f37..7083165 100644 (file)
@@ -208,11 +208,14 @@ lib /DEF:"$(ProjectDir)Preferences_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Pla
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="sci_gateway\c\sci_archive_extract.c" />
     <ClCompile Include="sci_gateway\c\sci_archive_list.c" />
     <ClCompile Include="sci_gateway\c\sci_getURL.c" />
     <ClCompile Include="sci_gateway\c\sci_splitURL.c" />
     <ClCompile Include="sci_gateway\c\sci_tempname.c" />
     <ClCompile Include="src\c\addfile.c" />
+    <ClCompile Include="src\c\archive_extract.c" />
+    <ClCompile Include="src\c\archive_list.c" />
     <ClCompile Include="src\c\basename.c" />
     <ClCompile Include="src\c\cluni0.c" />
     <ClCompile Include="src\c\convert_tools.c" />
@@ -317,7 +320,9 @@ lib /DEF:"$(ProjectDir)Preferences_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Pla
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="includes\addfile.h" />
+    <ClInclude Include="includes\archive_extract.h" />
     <ClInclude Include="includes\archive_list.h" />
+    <ClInclude Include="src\c\archive_extract.h" />
     <ClInclude Include="src\c\archive_list.h" />
     <ClInclude Include="includes\createtempfilename.h" />
     <ClInclude Include="includes\deleteafile.h" />
index 261fa11..5832c31 100644 (file)
     </Filter>
   </ItemGroup>
   <ItemGroup>
-    <ClCompile Include="src\c\archive_list.c">
+    <ClCompile Include="src\c\addfile.c">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="src\c\addfile.c">
+    <ClCompile Include="src\c\archive_extract.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="src\c\archive_list.c">
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClCompile Include="src\c\basename.c">
     <ClCompile Include="src\c\scanf_functions.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="sci_gateway\c\sci_archive_extract.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
     <ClCompile Include="sci_gateway\c\sci_archive_list.c">
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClInclude Include="includes\addfile.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="includes\archive_extract.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="src\c\archive_extract.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
     <ClInclude Include="includes\archive_list.h">
       <Filter>Header Files</Filter>
     </ClInclude>
diff --git a/scilab/modules/fileio/help/en_US/archiveExtract.xml b/scilab/modules/fileio/help/en_US/archiveExtract.xml
new file mode 100644 (file)
index 0000000..a2f9afb
--- /dev/null
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2015 - Kartik Gupta
+ * ...
+ *
+ * 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.1-en.txt
+ *
+ -->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="archiveExtract" xml:lang="en">
+    <refnamediv>
+        <refname>archiveExtract</refname>
+        <refpurpose>Extracts an archive of the formats tar, tar.gz, tar.bz2 or zip</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Calling Sequence</title>
+        <synopsis>processedfiles = basename(archive[,permissions_flag [,destination_folder]])</synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+            <varlistentry>
+                <term>archive</term>
+                <listitem>
+                    <para>Absolute or relative path to an archive</para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>flag</term>
+                <listitem>
+                    <para>optional boolean, used to set the permissions flag for the extracttion.
+                        Default value is False (<constant>%f</constant>).
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>destination_folder</term>
+                <listitem>
+                    <para>optional string argument, giving the absolute or relative path to the destination folder.
+                    </para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Description</title>
+        <para>
+            <code>archiveExtract(archive)</code> Extracts the given <varname>archive</varname>. The path can be absolute or relative. Returns 0 on success and -1 on failure.
+        </para>
+        <para>
+            If <varname>flag</varname> If this variable is passed as true then then permissions for the extracted files are preserved.
+        </para>
+        <para>
+            if <varname>destination_folder</varname> is given then the archive is extracted in the given folder
+        </para>
+    </refsection>
+    <refsection>
+        <title>Examples</title>
+        <programlisting role="example"><![CDATA[
+x = archiveExtract("example.tar")
+y = archiveExtract("example.tar.gz",%t)
+z = archiveExtract("example.zip",%f,"example2")
+ ]]></programlisting>
+    </refsection>
+    <refsection>
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>5.6.0</revnumber>
+                <revremark>
+                    Function <literal>archiveExtract</literal> introduced
+                </revremark>
+            </revision>
+        </revhistory>
+    </refsection>
+</refentry>
diff --git a/scilab/modules/fileio/includes/archive_extract.h b/scilab/modules/fileio/includes/archive_extract.h
new file mode 100644 (file)
index 0000000..9ab6070
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2015 - Kartik Gupta
+*
+* 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.1-en.txt
+*
+*/
+/*------------------------------------------------------------------*/
+#ifndef __ARCHIVE_EXTRACT_H__
+#define __ARCHIVE_EXTRACT_H__
+
+#include "dynlib_fileio.h"
+
+/**
+* Returns a list of files in the archive
+* @param[filename] The absolute or relative path to the archive.
+* @param[perm_flag] The flag for the permissions
+* @param[error] The error code for error detection
+* @return returns a 0 on success and -1 on failure
+*/
+
+FILEIO_IMPEXP int archive_extract(char *filename, int perm_flag, int *error);
+
+
+#endif
+/*--------------------------------------------------------------------------*/
index dfe1069..9f26af1 100644 (file)
@@ -64,7 +64,7 @@ int sci_tempname(char *fname, unsigned long fname_len);
 int sci_getURL(char *fname, unsigned long fname_len);
 int sci_splitURL(char *fname, unsigned long fname_len);
 int sci_archive_list(char *fname, unsigned long fname_len);
-
+int sci_archive_extract(char *fname, unsigned long fname_len);
 /*--------------------------------------------------------------------------*/
 #endif /* __GW_FILEIO_H__ */
 /*--------------------------------------------------------------------------*/
index c71eba8..4e7e521 100644 (file)
@@ -68,7 +68,8 @@ static gw_generic_table Tab[] =
     {sci_tempname, "tempname"},
     {sci_getURL, "getURL"},
     {sci_splitURL, "splitURL"},
-    {sci_archive_list,"archiveList"}
+    {sci_archive_list, "archiveList"},
+    {sci_archive_extract, "archiveExtract"}
 };
 /*--------------------------------------------------------------------------*/
 int gw_fileio(void)
diff --git a/scilab/modules/fileio/sci_gateway/c/sci_archive_extract.c b/scilab/modules/fileio/sci_gateway/c/sci_archive_extract.c
new file mode 100644 (file)
index 0000000..1a5fce7
--- /dev/null
@@ -0,0 +1,240 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2015 - Kartik Gupta
+*
+* 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.1-en.txt
+*
+*/
+/*--------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include <string.h>
+#include "gw_fileio.h"
+#include "api_scilab.h"
+#include "MALLOC.h"
+#include "Scierror.h"
+#include "localization.h"
+#include "PATH_MAX.h"
+#include "archive_extract.h"
+#include "freeArrayOfString.h"
+#include "expandPathVariable.h"
+#ifdef _MSC_VER
+#include "strdup_windows.h"
+#endif
+#include <unistd.h>
+#include "isdir.h"
+#include "createdirectory.h"
+#include "scicurdir.h"
+/*--------------------------------------------------------------------------*/
+int sci_archive_extract(char *fname, unsigned long fname_len)
+{
+    SciErr sciErr;
+    BOOL perm_flag = FALSE; /* default */
+
+    int *piAddressVarOne = NULL;
+    char **pStVarOne = NULL;
+    char *pathextended = NULL;
+    char **pStVarThree = NULL;
+    char *pathextended_destination = NULL;
+    char *current_directory;
+    int error;
+    int m1 = 0;
+    int n1 = 0;
+
+    int result;
+    /* Check Input & Output parameters */
+    CheckRhs(1, 3);
+    CheckLhs(1, 1);
+    if (Rhs > 2)
+    {
+        int *piAddressVarThree = NULL;
+        sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarThree);
+        if (sciErr.iErr)
+        {
+            printError(&sciErr, 0);
+            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
+            return 0;
+        }
+        if (!isStringType(pvApiCtx, piAddressVarThree))
+        {
+            if (isEmptyMatrix(pvApiCtx, piAddressVarThree))
+            {
+                createEmptyMatrix(pvApiCtx, Rhs + 1);
+                LhsVar(1) = Rhs + 1;
+                PutLhsVar()
+            }
+            else
+            {
+                Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1);
+            }
+            return 0;
+        }
+        if (getAllocatedMatrixOfString(pvApiCtx, piAddressVarThree, &m1, &n1, &pStVarThree) != 0)
+        {
+            freeAllocatedMatrixOfString(m1, n1, pStVarThree);
+            Scierror(999, _("%s: No more memory.\n"), fname);
+            return 0;
+        }
+
+    }
+    if (Rhs > 1)
+    {
+        int *piAddressVarTwo = NULL;
+        sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo);
+        if (sciErr.iErr)
+        {
+            printError(&sciErr, 0);
+            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
+            return 0;
+        }
+
+        if (isBooleanType(pvApiCtx, piAddressVarTwo) == 0 || isScalar(pvApiCtx, piAddressVarTwo) == 0)
+        {
+            Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 2);
+            return 0;
+        }
+
+        if (getScalarBoolean(pvApiCtx, piAddressVarTwo, &perm_flag))
+        {
+            printError(&sciErr, 0);
+            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
+            return 0;
+        }
+    }
+    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
+        return 0;
+    }
+
+    if (!isStringType(pvApiCtx, piAddressVarOne))
+    {
+        if (isEmptyMatrix(pvApiCtx, piAddressVarOne))
+        {
+            createEmptyMatrix(pvApiCtx, Rhs + 1);
+            LhsVar(1) = Rhs + 1;
+            PutLhsVar()
+        }
+        else
+        {
+            Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1);
+        }
+        return 0;
+    }
+    if (getAllocatedMatrixOfString(pvApiCtx, piAddressVarOne, &m1, &n1, &pStVarOne) != 0)
+    {
+        freeAllocatedMatrixOfString(m1, n1, pStVarOne);
+        Scierror(999, _("%s: No more memory.\n"), fname);
+        return 0;
+    }
+
+    pathextended = expandPathVariable(pStVarOne[0]);
+    if (pStVarThree != NULL)
+    {
+        char pathextended_temp[1024];
+        pathextended_temp[0] = '\0';
+        current_directory = scigetcwd(&error);
+        if (error != 0)
+        {
+            Scierror(999, _("%s: Sorry the current working directory could not be found.\n"), fname);
+            return 0;
+        }
+        error = 0;
+#ifdef _WIN32
+        if (pathextended[1] != ':' || pathextended[2] != '\')       //Checking if the path is absolute or relative for windows
+                {
+                strcat(pathextended_temp,current_directory);
+                strcat(pathextended_temp,'\');
+                strcat(pathextended_temp,pathextended);
+                pathextended = pathextended_temp;
+            }
+#else
+        if(!(pathextended[0] == ' / '))          //Checking if the path is absolute or relative for linux
+        {
+            strcat(pathextended_temp,current_directory);
+            strcat(pathextended_temp,"/");
+            strcat(pathextended_temp,pathextended);
+            pathextended = pathextended_temp;
+        }
+#endif
+                pathextended_destination = expandPathVariable(pStVarThree[0]);
+                if(!isdir(pathextended_destination))
+                {
+                if(!createdirectory(pathextended_destination))
+                {
+                Scierror(999, _("%s: Sorry the destinations folder could not be created.\n"), fname);
+                return 0;
+            }
+            }
+                if(chdir(pathextended_destination)!=0)
+                {
+                Scierror(999, _("%s: Sorry the destination folder could not be opened.\n"), fname);
+                return 0;
+            }
+
+            }
+                if(perm_flag == FALSE)
+                {
+                result = archive_extract(pathextended,0,&error);
+            }
+                else if(perm_flag == TRUE)
+                {
+                result = archive_extract(pathextended,1,&error);
+            }
+                if(error == 1)
+                {
+                Scierror(999, _("%s: Sorry the archive could not be opened.\n"), fname);
+                return 0;
+            }
+                if(error == 2)
+                {
+                Scierror(999, _("%s: Sorry the archive header could not be read.\n"), fname);
+                return 0;
+            }
+                if(error == 3)
+                {
+                Scierror(999, _("%s: Sorry the archive header could not be written.\n"), fname);
+                return 0;
+            }
+                if(error == 4)
+                {
+                Scierror(999, _("%s: Sorry the file data could not be read.\n"), fname);
+                return 0;
+            }
+                if(error == 5)
+                {
+                Scierror(999, _("%s: Sorry the file data could not be written.\n"), fname);
+                return 0;
+            }
+                if(error == 6)
+                {
+                Scierror(999, _("%s: Sorry the archive header could not be closed.\n"), fname);
+                return 0;
+            }
+
+
+                if(pStVarThree!=NULL)
+                {
+                if(chdir(current_directory)!=0)
+                {
+                Scierror(999, _("%s: Sorry could not return to the current directory.\n"), fname);
+                return 0;
+            }
+                freeAllocatedMatrixOfString(m1, n1, pStVarThree);
+            }
+
+                freeAllocatedMatrixOfString(m1, n1, pStVarOne);
+                createScalarInteger32(pvApiCtx, Rhs + 1, result);
+                LhsVar(1) = Rhs + 1;
+                PutLhsVar();
+                return 0;
+
+            }
+                /*--------------------------------------------------------------------------*/
+
+
index 1e717e2..af16455 100644 (file)
@@ -82,4 +82,5 @@
     <PRIMITIVE gatewayId="34" primitiveId="47" primitiveName="getURL" />
     <PRIMITIVE gatewayId="34" primitiveId="48" primitiveName="splitURL" />
     <PRIMITIVE gatewayId="34" primitiveId="49" primitiveName="archiveList" />
+    <PRIMITIVE gatewayId="34" primitiveId="50" primitiveName="archiveExtract" />
 </GATEWAY>
diff --git a/scilab/modules/fileio/src/c/archive_extract.c b/scilab/modules/fileio/src/c/archive_extract.c
new file mode 100644 (file)
index 0000000..c3e6807
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2015 - Kartik Gupta
+*
+* 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.1-en.txt
+*
+*/
+
+#include<sys/types.h>
+#include<sys/stat.h>
+#include<archive.h>
+#include<archive_entry.h>
+#include<fcntl.h>
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#include<unistd.h>
+
+int archive_extract(char *filename, int perm_flag, int* error)
+{
+    *error = 0;
+    int flags;
+    flags = ARCHIVE_EXTRACT_TIME;
+    if (perm_flag == 1)
+    {
+        flags |= ARCHIVE_EXTRACT_PERM;
+        flags |= ARCHIVE_EXTRACT_ACL;
+        flags |= ARCHIVE_EXTRACT_FFLAGS;
+    }
+    int do_extract = 1;
+    struct archive *to_be_read;
+    struct archive *to_write;
+    struct archive_entry *entry;
+    int r;
+
+    to_be_read = archive_read_new();
+    archive_read_support_format_all(to_be_read);
+    archive_read_support_compression_all(to_be_read);
+    to_write = archive_write_disk_new();
+    archive_write_disk_set_options(to_write, flags);
+    archive_write_disk_set_standard_lookup(to_write);
+
+    if ((r = archive_read_open_filename(to_be_read, filename, 10240)))
+    {
+        *error = 1;
+        return -1;
+    }
+    for (;;)
+    {
+        r = archive_read_next_header(to_be_read, &entry);
+        if (r == ARCHIVE_EOF)
+        {
+            break;
+        }
+        if (r < ARCHIVE_OK)
+        {
+            *error = 2;
+            return -1;
+        }
+        if (r < ARCHIVE_WARN)
+        {
+            *error = 2;
+            return -1;
+        }
+        r = archive_write_header(to_write, entry);
+        if (r < ARCHIVE_OK)
+        {
+            *error = 3;
+            return -1;
+        }
+        else if (archive_entry_size(entry) > 0)
+        {
+            const void *buff;
+            size_t size;
+            off_t offset;
+
+            while (1)
+            {
+                r = archive_read_data_block(to_be_read, &buff, &size, &offset);
+                if (r == ARCHIVE_EOF)
+                {
+                    break;
+                }
+                if (r < ARCHIVE_OK)
+                {
+                    *error = 4;
+                    return -1;
+                }
+                r = archive_write_data_block(to_write, buff, size, offset);
+                if (r < ARCHIVE_OK)
+                {
+                    *error = 5;
+                    return -1;
+                }
+            }
+
+            if (r < ARCHIVE_OK)
+            {
+                *error = 5;
+                return -1;
+            }
+            if (r < ARCHIVE_WARN)
+            {
+                *error = 5;
+                return -1;
+            }
+            r = archive_write_finish_entry(to_write);
+            if (r < ARCHIVE_OK)
+            {
+                *error = 6;
+                return -1;
+            }
+            if (r < ARCHIVE_WARN)
+            {
+                *error = 6;
+                return -1;
+            }
+        }
+    }
+    archive_read_close(to_be_read);
+    archive_read_free(to_be_read);
+    archive_write_close(to_write);
+    archive_write_free(to_write);
+    return 0;
+}
+
+
+
+
diff --git a/scilab/modules/fileio/src/c/archive_extract.h b/scilab/modules/fileio/src/c/archive_extract.h
new file mode 100644 (file)
index 0000000..074eb6f
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2015 - Kartik Gupta
+*
+* 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.1-en.txt
+*
+*/
+
+#ifndef __ARCHIVE_EXTRACT_H__
+#define __ARCHIVE_EXTRACT_H__
+
+#include<sys/types.h>
+#include<sys/stat.h>
+#include<archive.h>
+#include<archive_entry.h>
+#include<fcntl.h>
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#include<unistd.h>
+
+int archive_extract(char *filename, int perm_flag, int* error);
+
+#endif
diff --git a/scilab/modules/fileio/tests/unit_tests/archiveExtract.dia.ref b/scilab/modules/fileio/tests/unit_tests/archiveExtract.dia.ref
new file mode 100644 (file)
index 0000000..2a1cc75
--- /dev/null
@@ -0,0 +1,25 @@
+// ============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Kartik Gupta
+//
+//  This file is distributed under the same license as the Scilab package.
+// ============================================================================
+// <-- CLI SHELL MODE -->
+// ============================================================================
+// Unitary tests for archiveExtract function
+// ============================================================================
+x = archiveExtract("SCI/modules/fileio/tests/unit_tests/example.tar");
+if (~isfile("example1.txt") | ~isfile("example2.txt"))  then bugmes();quit;end
+deletefile("example1.txt");
+deletefile("example2.txt");
+x = archiveExtract("SCI/modules/fileio/tests/unit_tests/example.tar",%f);
+if (~isfile("example1.txt") | ~isfile("example2.txt"))  then bugmes();quit;end
+deletefile("example1.txt");
+deletefile("example2.txt");
+x = archiveExtract("SCI/modules/fileio/tests/unit_tests/example.tar",%t,"archiveExtract");
+if (~isfile("archiveExtract/example1.txt") | ~isfile("archiveExtract/example2.txt"))  then bugmes();quit;end
+removedir("archiveExtract");
+ierr = execstr("archiveExtract(SCI)","errcatch");
+if ierr <> 999 then bugmes();quit;end
+ierr = execstr("archiveExtract(SCI,1)","errcatch");
+if ierr <> 999 then bugmes();quit;end
diff --git a/scilab/modules/fileio/tests/unit_tests/archiveExtract.tst b/scilab/modules/fileio/tests/unit_tests/archiveExtract.tst
new file mode 100644 (file)
index 0000000..f4f8ebe
--- /dev/null
@@ -0,0 +1,36 @@
+// ============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Kartik Gupta
+//
+//  This file is distributed under the same license as the Scilab package.
+// ============================================================================
+
+// <-- CLI SHELL MODE -->
+
+// ============================================================================
+// Unitary tests for archiveExtract function
+// ============================================================================
+
+x = archiveExtract("SCI/modules/fileio/tests/unit_tests/example.tar");
+if (~isfile("example1.txt") | ~isfile("example2.txt"))  then pause,end
+
+deletefile("example1.txt");
+deletefile("example2.txt");
+
+x = archiveExtract("SCI/modules/fileio/tests/unit_tests/example.tar",%f);
+if (~isfile("example1.txt") | ~isfile("example2.txt"))  then pause,end
+
+deletefile("example1.txt");
+deletefile("example2.txt");
+
+x = archiveExtract("SCI/modules/fileio/tests/unit_tests/example.tar",%t,"archiveExtract");
+if (~isfile("archiveExtract/example1.txt") | ~isfile("archiveExtract/example2.txt"))  then pause,end
+
+removedir("archiveExtract");
+
+ierr = execstr("archiveExtract(SCI)","errcatch");
+if ierr <> 999 then pause,end
+
+ierr = execstr("archiveExtract(SCI,1)","errcatch");
+if ierr <> 999 then pause,end
+