annotate libinterp/dldfcn/gzip.cc @ 31605:e88a07dec498 stable

maint: Use macros to begin/end C++ namespaces. * oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE, OCTAVE_END_NAMESPACE) that can be used to start/end a namespace. * mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc, __dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc, __ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc, __magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc, auto-shlib.h, balance.cc, base-text-renderer.cc, base-text-renderer.h, besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h, call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc, defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc, display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc, ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h, event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc, fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc, graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc, help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h, interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h, inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc, latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h, lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc, ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h, mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc, oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h, oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h, oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy, ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc, pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h, sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc, sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h, stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h, symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h, text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc, url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc, variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h, __delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc, audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh, mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc, cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h, cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h, cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h, ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc, ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-mi.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc, op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, ops.h, anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h, comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc, oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h, pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h, pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc, pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h, pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h, range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc, chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h, lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h, oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h, oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc, qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc, randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc, sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc, child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc, file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h, mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h, oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h, base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h, file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc, lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h, oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h, oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h, oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h, pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h, url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author Rik <rik@octave.org>
date Thu, 01 Dec 2022 14:23:45 -0800
parents c9788d7f6e65
children aac27ad79be6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30182
diff changeset
3 // Copyright (C) 2016-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
25
24624
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
26 //! @file gzip.cc
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
27 //! Octave interface to the compression and uncompression libraries.
24624
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
28 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
29 //! This was originally implemented as an m file which directly called
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
30 //! bzip2 and gzip applications. This may look simpler but causes some
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
31 //! issues (see bug #43431) because we have no control over the output
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
32 //! file:
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
33 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
34 //! - created file is always in the same directory as the original file;
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
35 //! - automatically skip files that already have gz/bz2/etc extension;
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
36 //! - some older versions lack the --keep option.
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
37 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
38 //! In addition, because system() does not have a method that allows
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
39 //! passing a list of arguments, there is the issue of having to escape
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
40 //! filenames.
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
41 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
42 //! A solution is to pipe file contents into the applications instead of
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
43 //! filenames. However, that solution causes:
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
44 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
45 //! # missing file header with original file information;
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
46 //! # implementing ourselves the recursive transversion of directories;
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
47 //! # do the above in a m file which will be slow;
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
48 //! # popen2 is frail on windows.
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
49
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
50 #if defined (HAVE_CONFIG_H)
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
51 # include "config.h"
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
52 #endif
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
53
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
54 #include <cstdio>
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
55 #include <cstring>
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
56
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
57 #include <functional>
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
58 #include <list>
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
59 #include <stdexcept>
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
60 #include <string>
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
61
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
62 #include "Array.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
63 #include "dir-ops.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
64 #include "file-ops.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
65 #include "file-stat.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
66 #include "glob-match.h"
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25103
diff changeset
67 #include "lo-sysdep.h"
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
68 #include "oct-env.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
69 #include "str-vec.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
70
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
71 #include "Cell.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
72 #include "defun-dld.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
73 #include "defun-int.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
74 #include "errwarn.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
75 #include "ov.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
76 #include "ovl.h"
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
77
22188
1344509a480c style fixes
John W. Eaton <jwe@octave.org>
parents: 22187
diff changeset
78 #if defined (HAVE_BZLIB_H)
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
79 # include <bzlib.h>
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
80 #endif
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
81
22188
1344509a480c style fixes
John W. Eaton <jwe@octave.org>
parents: 22187
diff changeset
82 #if defined (HAVE_ZLIB_H)
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
83 # include <zlib.h>
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
84 #endif
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
85
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30896
diff changeset
86 OCTAVE_BEGIN_NAMESPACE(octave)
29960
939bef0b66e0 merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
87
24624
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
88 //! RIIA wrapper for std::FILE*.
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
89 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
90 //! If error handling is available for failing to close the file, use
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
91 //! the close method which throws.
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
92 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
93 //! If the file has been closed, fp is set to nullptr. Remember that
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
94 //! behavior is undefined if the value of the pointer stream is used
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
95 //! after fclose.
22188
1344509a480c style fixes
John W. Eaton <jwe@octave.org>
parents: 22187
diff changeset
96
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
97 class CFile
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
98 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
99 public:
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
100
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
101 CFile (void) = delete;
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
102
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
103 CFile (const std::string& path, const std::string& mode)
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
104 : m_fp (sys::fopen (path, mode))
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
105 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
106 if (! m_fp)
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
107 throw std::runtime_error ("unable to open file");
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
108 }
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
109
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
110 CFile (const CFile&) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
111
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
112 CFile& operator = (const CFile&) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
113
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
114 ~CFile (void)
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
115 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
116 if (m_fp)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
117 std::fclose (m_fp);
22187
2aae8894885b xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents: 22173
diff changeset
118 }
2aae8894885b xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents: 22173
diff changeset
119
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
120 void close (void)
22187
2aae8894885b xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents: 22173
diff changeset
121 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
122 if (std::fclose (m_fp))
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
123 throw std::runtime_error ("unable to close file");
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
124
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
125 m_fp = nullptr;
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
126 }
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
127
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
128 std::FILE *m_fp;
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
129 };
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
130
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
131 #if defined (HAVE_BZ2)
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
132
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
133 class bz2
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
134 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
135 public:
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
136
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
137 static const constexpr char *extension = ".bz2";
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
138
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
139 static void zip (const std::string& source_path,
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
140 const std::string& dest_path)
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
141 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
142 bz2::zipper z (source_path, dest_path);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
143 z.deflate ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
144 z.close ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
145 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
146
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
147 private:
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
148
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
149 class zipper
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
150 {
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
151 public:
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
152
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
153 zipper (void) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
154
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
155 zipper (const std::string& source_path, const std::string& dest_path)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
156 : m_status (BZ_OK), m_source (source_path, "rb"),
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
157 m_dest (dest_path, "wb"),
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
158 m_bz (BZ2_bzWriteOpen (&m_status, m_dest.m_fp, 9, 0, 30))
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
159 {
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
160 if (m_status != BZ_OK)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
161 throw std::runtime_error ("failed to open bzip2 stream");
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
162 }
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
163
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
164 zipper (const zipper&) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
165
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
166 zipper& operator = (const zipper&) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
167
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
168 ~zipper (void)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
169 {
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
170 if (m_bz != nullptr)
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23696
diff changeset
171 BZ2_bzWriteClose (&m_status, m_bz, 1, nullptr, nullptr);
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
172 }
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
173
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
174 void deflate (void)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
175 {
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
176 const std::size_t buf_len = 8192;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
177 char buf[buf_len];
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
178 std::size_t n_read;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
179 while ((n_read = std::fread (buf, sizeof (buf[0]), buf_len, m_source.m_fp)) != 0)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
180 {
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
181 if (std::ferror (m_source.m_fp))
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
182 throw std::runtime_error ("failed to read from source file");
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
183 BZ2_bzWrite (&m_status, m_bz, buf, n_read);
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
184 if (m_status == BZ_IO_ERROR)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
185 throw std::runtime_error ("failed to write or compress");
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
186 }
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
187 if (std::ferror (m_source.m_fp))
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
188 throw std::runtime_error ("failed to read from source file");
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
189 }
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
190
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
191 void close (void)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
192 {
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
193 int abandon = (m_status == BZ_IO_ERROR) ? 1 : 0;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23696
diff changeset
194 BZ2_bzWriteClose (&m_status, m_bz, abandon, nullptr, nullptr);
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
195 if (m_status != BZ_OK)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
196 throw std::runtime_error ("failed to close bzip2 stream");
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
197 m_bz = nullptr;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
198
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
199 // We have no error handling for failing to close source, let
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
200 // the destructor close it.
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
201 m_dest.close ();
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
202 }
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
203
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
204 private:
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
205
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
206 int m_status;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
207 CFile m_source;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
208 CFile m_dest;
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
209 BZFILE *m_bz;
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
210 };
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
211 };
22188
1344509a480c style fixes
John W. Eaton <jwe@octave.org>
parents: 22187
diff changeset
212
1344509a480c style fixes
John W. Eaton <jwe@octave.org>
parents: 22187
diff changeset
213 #endif
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
214
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
215 // Note about zlib and gzip
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
216 //
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
217 // gzip is a format for compressed single files. zlib is a format
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
218 // designed for in-memory and communication channel applications.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
219 // gzip uses the same format internally for the compressed data but
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
220 // has different headers and trailers.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
221 //
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
222 // zlib is also a library but gzip is not. Very old versions of zlib do
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
223 // not include functions to create useful gzip headers and trailers:
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
224 //
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
225 // Note that you cannot specify special gzip header contents (e.g.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
226 // a file name or modification date), nor will inflate tell you what
27929
265b386f8b20 maint: Use two spaces between sentences in code comments.
Rik <rik@octave.org>
parents: 27923
diff changeset
227 // was in the gzip header. If you need to customize the header or
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
228 // see what's in it, you can use the raw deflate and inflate
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
229 // operations and the crc32() function and roll your own gzip
27929
265b386f8b20 maint: Use two spaces between sentences in code comments.
Rik <rik@octave.org>
parents: 27923
diff changeset
230 // encoding and decoding. Read the gzip RFC 1952 for details of the
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
231 // header and trailer format.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
232 // zlib FAQ
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
233 //
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
234 // Recent versions (on which we are already dependent) have deflateInit2()
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
235 // to do it. We still need to get the right metadata for the header
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
236 // ourselves though.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
237 //
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
238 // The header is defined in RFC #1952
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
239 // GZIP file format specification version 4.3
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
240
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
241
22188
1344509a480c style fixes
John W. Eaton <jwe@octave.org>
parents: 22187
diff changeset
242 #if defined (HAVE_Z)
1344509a480c style fixes
John W. Eaton <jwe@octave.org>
parents: 22187
diff changeset
243
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
244 class gz
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
245 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
246 public:
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
247
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
248 static const constexpr char *extension = ".gz";
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
249
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
250 static void zip (const std::string& source_path,
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
251 const std::string& dest_path)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
252 {
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
253 gz::zipper z (source_path, dest_path);
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
254 z.deflate ();
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
255 z.close ();
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
256 }
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
257
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
258 private:
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
259
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
260 // Util class to get a non-const char*
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
261 class uchar_array
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
262 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
263 public:
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
264
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
265 // Bytef is a typedef for unsigned char
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
266 unsigned char *p;
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
267
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
268 uchar_array (void) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
269
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
270 uchar_array (const std::string& str)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
271 {
23812
057a894914df Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents: 23795
diff changeset
272 p = new Bytef[str.length () + 1];
23447
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
273 std::strcpy (reinterpret_cast<char *> (p), str.c_str ());
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
274 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
275
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
276 uchar_array (const uchar_array&) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
277
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
278 uchar_array& operator = (const uchar_array&) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
279
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
280 ~uchar_array (void) { delete[] p; }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
281 };
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
282
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
283 class gzip_header : public gz_header
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
284 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
285 public:
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
286
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
287 gzip_header (void) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
288
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
289 gzip_header (const std::string& source_path)
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23691
diff changeset
290 : m_basename (sys::env::base_pathname (source_path))
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
291 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23691
diff changeset
292 const sys::file_stat source_stat (source_path);
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
293 if (! source_stat)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
294 throw std::runtime_error ("unable to stat source file");
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
295
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
296 // time_t may be a signed int in which case it will be a
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
297 // positive number so it is safe to uLong. Or is it? Can
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
298 // unix_time really never be negative?
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
299 time = uLong (source_stat.mtime ().unix_time ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
300
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
301 // If FNAME is set, an original file name is present,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
302 // terminated by a zero byte. The name must consist of ISO
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
303 // 8859-1 (LATIN-1) characters; on operating systems using
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
304 // EBCDIC or any other character set for file names, the name
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
305 // must be translated to the ISO LATIN-1 character set. This
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
306 // is the original name of the file being compressed, with any
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
307 // directory components removed, and, if the file being
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
308 // compressed is on a file system with case insensitive names,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
309 // forced to lower case.
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
310 name = m_basename.p;
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
311
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
312 // If we don't set it to Z_NULL, then it will set FCOMMENT (4th bit)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
313 // on the FLG byte, and then write {0, 3} comment.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
314 comment = Z_NULL;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
315
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
316 // Seems to already be the default but we are not taking chances.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
317 extra = Z_NULL;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
318
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
319 // We do not want a CRC for the header. That would be only 2 more
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
320 // bytes, and maybe it would be a good thing but we want to generate
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
321 // gz files similar to the default gzip application.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
322 hcrc = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
323
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
324 // OS (Operating System):
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
325 // 0 - FAT filesystem (MS-DOS, OS/2, NT/Win32)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
326 // 1 - Amiga
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
327 // 2 - VMS (or OpenVMS)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
328 // 3 - Unix
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
329 // 4 - VM/CMS
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
330 // 5 - Atari TOS
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
331 // 6 - HPFS filesystem (OS/2, NT)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
332 // 7 - Macintosh
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
333 // 8 - Z-System
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
334 // 9 - CP/M
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
335 // 10 - TOPS-20
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
336 // 11 - NTFS filesystem (NT)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
337 // 12 - QDOS
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
338 // 13 - Acorn RISCOS
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
339 // 255 - unknown
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
340 //
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
341 // The list is problematic because it mixes OS and filesystem. It
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
342 // also does not specify whether filesystem relates to source or
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
343 // destination file.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
344
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
345 #if defined (__WIN32__)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
346 // Or should it be 11?
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
347 os = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
348 #elif defined (__APPLE__)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
349 os = 7;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
350 #else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
351 // Unix by default?
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
352 os = 3;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
353 #endif
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
354 }
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
355
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
356 gzip_header (const gzip_header&) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
357
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
358 gzip_header& operator = (const gzip_header&) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
359
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
360 ~gzip_header (void) = default;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
361
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
362 private:
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
363
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
364 // This must be kept for gz_header.name
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
365 uchar_array m_basename;
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
366 };
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
367
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
368 class zipper
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
369 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
370 public:
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
371
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
372 zipper (void) = delete;
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
373
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
374 zipper (const std::string& source_path, const std::string& dest_path)
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
375 : m_source (source_path, "rb"), m_dest (dest_path, "wb"),
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
376 m_header (source_path), m_strm (new z_stream)
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
377 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
378 m_strm->zalloc = Z_NULL;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
379 m_strm->zfree = Z_NULL;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
380 m_strm->opaque = Z_NULL;
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
381 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
382
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
383 zipper (const zipper&) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
384
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
385 zipper& operator = (const zipper&) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
386
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
387 ~zipper (void)
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
388 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
389 if (m_strm)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
390 deflateEnd (m_strm);
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
391 delete m_strm;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
392 }
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
393
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
394 void deflate (void)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
395 {
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
396 // int deflateInit2 (z_streamp m_strm,
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
397 // int level, // compression level (default is 8)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
398 // int method,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
399 // int windowBits, // 15 (default) + 16 (gzip format)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
400 // int memLevel, // memory usage (default is 8)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
401 // int strategy);
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
402 int status = deflateInit2 (m_strm, 8, Z_DEFLATED, 31, 8,
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
403 Z_DEFAULT_STRATEGY);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
404 if (status != Z_OK)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
405 throw std::runtime_error ("failed to open zlib stream");
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
406
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
407 deflateSetHeader (m_strm, &m_header);
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
408
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
409 const std::size_t buf_len = 8192;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
410 unsigned char buf_in[buf_len];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
411 unsigned char buf_out[buf_len];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
412
22922
426325aa8ee9 Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents: 22489
diff changeset
413 int flush;
426325aa8ee9 Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents: 22489
diff changeset
414
426325aa8ee9 Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents: 22489
diff changeset
415 do
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
416 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
417 m_strm->avail_in = std::fread (buf_in, sizeof (buf_in[0]),
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
418 buf_len, m_source.m_fp);
22922
426325aa8ee9 Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents: 22489
diff changeset
419
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
420 if (std::ferror (m_source.m_fp))
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
421 throw std::runtime_error ("failed to read source file");
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
422
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
423 m_strm->next_in = buf_in;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
424 flush = (std::feof (m_source.m_fp) ? Z_FINISH : Z_NO_FLUSH);
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
425
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
426 // If deflate returns Z_OK and with zero avail_out, it must be
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
427 // called again after making room in the output buffer because
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
428 // there might be more output pending.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
429 do
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
430 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
431 m_strm->avail_out = buf_len;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
432 m_strm->next_out = buf_out;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
433 status = ::deflate (m_strm, flush);
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
434 if (status == Z_STREAM_ERROR)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
435 throw std::runtime_error ("failed to deflate");
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
436
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
437 std::fwrite (buf_out, sizeof (buf_out[0]),
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
438 buf_len - m_strm->avail_out, m_dest.m_fp);
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
439 if (std::ferror (m_dest.m_fp))
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
440 throw std::runtime_error ("failed to write file");
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
441 }
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
442 while (m_strm->avail_out == 0);
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
443
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
444 if (m_strm->avail_in != 0)
22922
426325aa8ee9 Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents: 22489
diff changeset
445 throw std::runtime_error ("failed to write file");
426325aa8ee9 Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents: 22489
diff changeset
446
426325aa8ee9 Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents: 22489
diff changeset
447 } while (flush != Z_FINISH);
426325aa8ee9 Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents: 22489
diff changeset
448
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
449 if (status != Z_STREAM_END)
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
450 throw std::runtime_error ("failed to write file");
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
451 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
452
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
453 void close (void)
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
454 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
455 if (deflateEnd (m_strm) != Z_OK)
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
456 throw std::runtime_error ("failed to close zlib stream");
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
457 m_strm = nullptr;
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
458
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
459 // We have no error handling for failing to close source, let
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
460 // the destructor close it.
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
461 m_dest.close ();
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
462 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
463
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
464 private:
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
465
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
466 CFile m_source;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
467 CFile m_dest;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
468 gzip_header m_header;
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
469 z_stream *m_strm;
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
470 };
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
471 };
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
472
22188
1344509a480c style fixes
John W. Eaton <jwe@octave.org>
parents: 22187
diff changeset
473 #endif
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
474
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
475
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
476 template<typename X>
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
477 string_vector
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
478 xzip (const Array<std::string>& source_patterns,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
479 const std::function<std::string(const std::string&)>& mk_dest_path)
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
480 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
481 std::list<std::string> dest_paths;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
482
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
483 std::function<void(const std::string&)> walk;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
484 walk = [&walk, &mk_dest_path, &dest_paths] (const std::string& path) -> void
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
485 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23691
diff changeset
486 const sys::file_stat fs (path);
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
487 // is_dir and is_reg will return false if failed to stat.
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
488 if (fs.is_dir ())
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
489 {
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25103
diff changeset
490 string_vector dirlist;
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25103
diff changeset
491 std::string msg;
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25103
diff changeset
492
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25103
diff changeset
493 // Collect the whole list of filenames first, before recursion
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25103
diff changeset
494 // to avoid issues with infinite loop if the action generates
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25103
diff changeset
495 // files in the same directory (highly likely).
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25103
diff changeset
496 if (sys::get_dirlist (path, dirlist, msg))
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
497 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
498 for (octave_idx_type i = 0; i < dirlist.numel (); i++)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
499 if (dirlist(i) != "." && dirlist(i) != "..")
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23691
diff changeset
500 walk (sys::file_ops::concat (path, dirlist(i)));
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
501 }
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
502 // Note that we skip any problem with directories.
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
503 }
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
504 else if (fs.is_reg ())
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
505 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
506 const std::string dest_path = mk_dest_path (path);
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
507 try
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
508 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
509 X::zip (path, dest_path);
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
510 }
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28915
diff changeset
511 catch (const interrupt_exception&)
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28915
diff changeset
512 {
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28915
diff changeset
513 throw; // interrupts are special, just re-throw.
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28915
diff changeset
514 }
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
515 catch (...)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
516 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
517 // Error "handling" is not including filename on the output list.
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28915
diff changeset
518 // Also, remove created file which may not have been created
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
519 // in the first place. Note that it is possible for the file
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28915
diff changeset
520 // to exist before the call to X::zip and that X::zip has not
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28915
diff changeset
521 // clobber it yet, but we remove it anyway.
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23691
diff changeset
522 sys::unlink (dest_path);
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
523 return;
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
524 }
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
525 dest_paths.push_front (dest_path);
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
526 }
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
527 // Skip all other file types and errors.
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
528 return;
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
529 };
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
530
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
531 for (octave_idx_type i = 0; i < source_patterns.numel (); i++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
532 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23691
diff changeset
533 const glob_match pattern (sys::file_ops::tilde_expand (source_patterns(i)));
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
534 const string_vector filepaths = pattern.glob ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
535 for (octave_idx_type j = 0; j < filepaths.numel (); j++)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
536 walk (filepaths(j));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
537 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
538 return string_vector (dest_paths);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
539 }
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
540
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
541
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
542 template<typename X>
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
543 string_vector
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
544 xzip (const Array<std::string>& source_patterns)
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
545 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
546 const std::string ext = X::extension;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
547 const std::function<std::string(const std::string&)> mk_dest_path
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
548 = [&ext] (const std::string& source_path) -> std::string
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
549 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
550 return source_path + ext;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
551 };
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
552 return xzip<X> (source_patterns, mk_dest_path);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
553 }
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
554
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
555 template<typename X>
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
556 string_vector
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
557 xzip (const Array<std::string>& source_patterns, const std::string& out_dir)
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
558 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
559 const std::string ext = X::extension;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
560 const std::function<std::string(const std::string&)> mk_dest_path
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
561 = [&out_dir, &ext] (const std::string& source_path) -> std::string
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
562 {
28475
5a85e42a1be7 Make gzip/bzip2 more Matlab compatible when directory is first argument (bug #58547).
Rik <rik@octave.org>
parents: 27957
diff changeset
563 // Strip any relative path (bug #58547)
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
564 std::size_t pos = source_path.find_last_of (sys::file_ops::dir_sep_str ());
28475
5a85e42a1be7 Make gzip/bzip2 more Matlab compatible when directory is first argument (bug #58547).
Rik <rik@octave.org>
parents: 27957
diff changeset
565 const std::string basename =
5a85e42a1be7 Make gzip/bzip2 more Matlab compatible when directory is first argument (bug #58547).
Rik <rik@octave.org>
parents: 27957
diff changeset
566 (pos == std::string::npos ? source_path : source_path.substr (pos+1));
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23691
diff changeset
567 return sys::file_ops::concat (out_dir, basename + ext);
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
568 };
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
569
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
570 // We don't care if mkdir fails. Maybe it failed because it already
27956
2310164737b3 fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
571 // exists, or maybe it can't be created. If the first, then there's
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
572 // nothing to do, if the later, then it will be handled later. Any
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
573 // is to be handled by not listing files in the output.
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23691
diff changeset
574 sys::mkdir (out_dir, 0777);
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
575 return xzip<X> (source_patterns, mk_dest_path);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
576 }
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
577
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
578 template<typename X>
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
579 static octave_value_list
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30564
diff changeset
580 xzip (const std::string& fcn_name, const octave_value_list& args)
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
581 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
582 const octave_idx_type nargin = args.length ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
583 if (nargin < 1 || nargin > 2)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
584 print_usage ();
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
585
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
586 const Array<std::string> source_patterns
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
587 = args(0).xcellstr_value ("%s: FILES must be a character array or cellstr",
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30564
diff changeset
588 fcn_name.c_str ());
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
589 if (nargin == 1)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
590 return octave_value (Cell (xzip<X> (source_patterns)));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
591 else // nargin == 2
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
592 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
593 const std::string out_dir = args(1).string_value ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
594 return octave_value (Cell (xzip<X> (source_patterns, out_dir)));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
595 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
596 }
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29720
diff changeset
597
30111
4eddc4cba4e9 omit output from gzip or bzip2 if nargout is zero
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
598 DEFUN_DLD (gzip, args, nargout,
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
599 doc: /* -*- texinfo -*-
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
600 @deftypefn {} {@var{filelist} =} gzip (@var{files})
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
601 @deftypefnx {} {@var{filelist} =} gzip (@var{files}, @var{dir})
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
602 Compress the list of files and directories specified in @var{files}.
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
603
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
604 @var{files} is a character array or cell array of strings. Shell wildcards
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
605 in the filename such as @samp{*} or @samp{?} are accepted and expanded.
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
606 Each file is compressed separately and a new file with a @file{".gz"}
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
607 extension is created. The original files are not modified, but existing
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
608 compressed files will be silently overwritten. If a directory is
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
609 specified then @code{gzip} recursively compresses all files in the
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
610 directory.
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
611
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
612 If @var{dir} is defined the compressed files are placed in this directory,
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
613 rather than the original directory where the uncompressed file resides.
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
614 Note that this does not replicate a directory tree in @var{dir} which may
22330
53e246fd8124 doc: Spellcheck documentation ahead of 4.2 release.
Rik <rik@octave.org>
parents: 22326
diff changeset
615 lead to files overwriting each other if there are multiple files with the
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
616 same name.
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
617
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
618 If @var{dir} does not exist it is created.
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
619
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
620 The optional output @var{filelist} is a list of the compressed files.
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
621 @seealso{gunzip, unpack, bzip2, zip, tar}
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
622 @end deftypefn */)
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
623 {
22265
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
624 #if defined (HAVE_Z)
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
625
30111
4eddc4cba4e9 omit output from gzip or bzip2 if nargout is zero
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
626 octave_value_list retval = xzip<gz> ("gzip", args);
4eddc4cba4e9 omit output from gzip or bzip2 if nargout is zero
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
627
4eddc4cba4e9 omit output from gzip or bzip2 if nargout is zero
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
628 return (nargout > 0 ? retval : octave_value_list ());
22265
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
629
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
630 #else
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
631
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
632 octave_unused_parameter (args);
30182
ec834eea1b82 gzip.cc: Silence unused parameter warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30113
diff changeset
633 octave_unused_parameter (nargout);
22265
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
634
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
635 err_disabled_feature ("gzip", "gzip");
22265
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
636
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
637 #endif
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
638 }
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
639
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
640 /*
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
641 %!error gzip ()
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
642 %!error gzip ("1", "2", "3")
22271
16efd0403698 Add %!error test pattern matches for disabled optional features
Mike Miller <mtmiller@octave.org>
parents: 22269
diff changeset
643 %!error <FILES must be a character array or cellstr|was unavailable or disabled> gzip (1)
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
644 */
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
645
30111
4eddc4cba4e9 omit output from gzip or bzip2 if nargout is zero
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
646 DEFUN_DLD (bzip2, args, nargout,
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
647 doc: /* -*- texinfo -*-
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
648 @deftypefn {} {@var{filelist} =} bzip2 (@var{files})
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
649 @deftypefnx {} {@var{filelist} =} bzip2 (@var{files}, @var{dir})
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
650 Compress the list of files specified in @var{files}.
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
651
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
652 @var{files} is a character array or cell array of strings. Shell wildcards
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
653 in the filename such as @samp{*} or @samp{?} are accepted and expanded.
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
654 Each file is compressed separately and a new file with a @file{".bz2"}
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
655 extension is created. The original files are not modified, but existing
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
656 compressed files will be silently overwritten.
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
657
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
658 If @var{dir} is defined the compressed files are placed in this directory,
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
659 rather than the original directory where the uncompressed file resides.
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
660 Note that this does not replicate a directory tree in @var{dir} which may
22330
53e246fd8124 doc: Spellcheck documentation ahead of 4.2 release.
Rik <rik@octave.org>
parents: 22326
diff changeset
661 lead to files overwriting each other if there are multiple files with the
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
662 same name.
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
663
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
664 If @var{dir} does not exist it is created.
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
665
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
666 The optional output @var{filelist} is a list of the compressed files.
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
667 @seealso{bunzip2, unpack, gzip, zip, tar}
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
668 @end deftypefn */)
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
669 {
22265
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
670 #if defined (HAVE_BZ2)
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
671
30111
4eddc4cba4e9 omit output from gzip or bzip2 if nargout is zero
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
672 octave_value_list retval = xzip<bz2> ("bzip2", args);
4eddc4cba4e9 omit output from gzip or bzip2 if nargout is zero
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
673
4eddc4cba4e9 omit output from gzip or bzip2 if nargout is zero
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
674 return (nargout > 0 ? retval : octave_value_list ());
22265
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
675
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
676 #else
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
677
22269
a76b931d2c4b * xzip.cc (Fbzip2): Fix typo of "octave_unused_parameter".
Mike Miller <mtmiller@octave.org>
parents: 22265
diff changeset
678 octave_unused_parameter (args);
30182
ec834eea1b82 gzip.cc: Silence unused parameter warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30113
diff changeset
679 octave_unused_parameter (nargout);
22265
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
680
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
681 err_disabled_feature ("bzip2", "bzip2");
22265
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
682
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
683 #endif
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
684 }
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
685
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
686 // Tests for both gzip/bzip2 and gunzip/bunzip2
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
687 /*
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
688
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
689 ## Takes a single argument, a function handle for the test. This other
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
690 ## function must accept two arguments, a directory for the tests, and
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
691 ## a cell array with zip function, unzip function, and file extension.
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
692
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
693 %!function run_test_function (test_function)
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
694 %! enabled_zippers = struct ("zip", {}, "unzip", {}, "ext", {});
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
695 %! if (__octave_config_info__ ().build_features.BZ2)
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
696 %! enabled_zippers(end+1).zip = @bzip2;
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
697 %! enabled_zippers(end).unzip = @bunzip2;
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
698 %! enabled_zippers(end).ext = ".bz2";
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
699 %! endif
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
700 %! if (__octave_config_info__ ().build_features.Z)
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
701 %! enabled_zippers(end+1).zip = @gzip;
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
702 %! enabled_zippers(end).unzip = @gunzip;
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
703 %! enabled_zippers(end).ext = ".gz";
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
704 %! endif
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
705 %!
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
706 %! for z = enabled_zippers
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
707 %! test_dir = tempname ();
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
708 %! if (! mkdir (test_dir))
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
709 %! error ("unable to create directory for tests");
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
710 %! endif
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
711 %! unwind_protect
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
712 %! test_function (test_dir, z)
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
713 %! unwind_protect_cleanup
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
714 %! confirm_recursive_rmdir (false, "local");
28087
9cb04a9e81ec rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents: 27957
diff changeset
715 %! sts = rmdir (test_dir, "s");
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
716 %! end_unwind_protect
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
717 %! endfor
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
718 %!endfunction
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
719
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
720 %!function create_file (fpath, data)
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
721 %! fid = fopen (fpath, "wb");
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
722 %! if (fid < 0)
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
723 %! error ("unable to open file for writing");
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
724 %! endif
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
725 %! if (fwrite (fid, data, class (data)) != numel (data))
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
726 %! error ("unable to write to file");
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
727 %! endif
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
728 %! if (fflush (fid) || fclose (fid))
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
729 %! error ("unable to flush or close file");
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
730 %! endif
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
731 %!endfunction
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
732
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
733 %!function unlink_or_error (filepath)
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
734 %! [err, msg] = unlink (filepath);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
735 %! if (err)
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
736 %! error ("unable to remove file required for the test");
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
737 %! endif
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
738 %!endfunction
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
739
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
740 ## Test with large files because of varied buffer size
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
741 %!function test_large_file (test_dir, z)
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
742 %! test_file = tempname (test_dir);
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
743 %! create_file (test_file, rand (500000, 1));
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
744 %! md5 = hash ("md5", fileread (test_file));
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
745 %!
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
746 %! z_file = [test_file z.ext];
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
747 %! z_filelist = z.zip (test_file);
29720
e1139b820c95 gzip.cc: Use is_same_file in BISTs to assert that files are the same.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
748 %! assert (is_same_file (z_filelist, {z_file}))
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
749 %!
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
750 %! unlink_or_error (test_file);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
751 %! uz_filelist = z.unzip (z_file);
29720
e1139b820c95 gzip.cc: Use is_same_file in BISTs to assert that files are the same.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
752 %! assert (is_same_file (uz_filelist, {test_file}))
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
753 %!
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
754 %! assert (hash ("md5", fileread (test_file)), md5)
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
755 %!endfunction
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
756 %!test run_test_function (@test_large_file)
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
757
30113
62af50666f62 update gzip.cc tests
John W. Eaton <jwe@octave.org>
parents: 30111
diff changeset
758 ## Test that xzipped files are rexzipped (hits bug #43206, #48598)
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
759 %!function test_z_z (test_dir, z)
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
760 %! ori_file = tempname (test_dir);
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
761 %! create_file (ori_file, rand (100, 1));
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
762 %! md5_ori = hash ("md5", fileread (ori_file));
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
763 %!
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
764 %! z_file = [ori_file z.ext];
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
765 %! z_filelist = z.zip (ori_file);
29720
e1139b820c95 gzip.cc: Use is_same_file in BISTs to assert that files are the same.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
766 %! assert (is_same_file (z_filelist, {z_file})) # check output
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
767 %! assert (exist (z_file), 2) # confirm file exists
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
768 %! assert (exist (ori_file), 2) # and did not remove original file
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
769 %!
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
770 %! unlink_or_error (ori_file);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
771 %! uz_filelist = z.unzip (z_file);
29720
e1139b820c95 gzip.cc: Use is_same_file in BISTs to assert that files are the same.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
772 %! assert (is_same_file (uz_filelist, {ori_file})) # bug #48598
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
773 %! assert (hash ("md5", fileread (ori_file)), md5_ori)
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
774 %! assert (exist (z_file), 2) # bug #48597
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
775 %!
30113
62af50666f62 update gzip.cc tests
John W. Eaton <jwe@octave.org>
parents: 30111
diff changeset
776 %! ## xzip should preserve original files.
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
777 %! z_z_file = [z_file z.ext];
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
778 %! z_z_filelist = z.zip (z_file);
29720
e1139b820c95 gzip.cc: Use is_same_file in BISTs to assert that files are the same.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
779 %! assert (is_same_file (z_z_filelist, {z_z_file})) # check output
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
780 %! assert (exist (z_z_file), 2) # confirm file exists
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
781 %! assert (exist (z_file), 2)
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
782 %!
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
783 %! md5_z = hash ("md5", fileread (z_file));
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
784 %! unlink_or_error (z_file);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
785 %! uz_z_filelist = z.unzip (z_z_file);
29720
e1139b820c95 gzip.cc: Use is_same_file in BISTs to assert that files are the same.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
786 %! assert (is_same_file (uz_z_filelist, {z_file})) # bug #48598
30113
62af50666f62 update gzip.cc tests
John W. Eaton <jwe@octave.org>
parents: 30111
diff changeset
787 %! assert (exist (z_z_file), 2) # bug #43206
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
788 %! assert (hash ("md5", fileread (z_file)), md5_z)
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
789 %!endfunction
30113
62af50666f62 update gzip.cc tests
John W. Eaton <jwe@octave.org>
parents: 30111
diff changeset
790 %!test <43206> run_test_function (@test_z_z)
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
791
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
792 %!function test_xzip_dir (test_dir, z) # bug #43431
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
793 %! fpaths = fullfile (test_dir, {"test1", "test2", "test3"});
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
794 %! md5s = cell (1, 3);
28915
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
795 %! for idx = 1:numel (fpaths)
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
796 %! create_file (fpaths{idx}, rand (100, 1));
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
797 %! md5s(idx) = hash ("md5", fileread (fpaths{idx}));
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
798 %! endfor
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
799 %!
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
800 %! test_dir = [test_dir filesep()];
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
801 %!
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
802 %! z_files = strcat (fpaths, z.ext);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
803 %! z_filelist = z.zip (test_dir);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
804 %! assert (sort (z_filelist), z_files(:))
28915
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
805 %! for idx = 1:numel (fpaths)
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
806 %! assert (exist (z_files{idx}), 2)
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
807 %! unlink_or_error (fpaths{idx});
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
808 %! endfor
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
809 %!
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
810 %! ## only gunzip handles directory (bunzip2 should too though)
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
811 %! if (z.unzip == @gunzip)
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
812 %! uz_filelist = z.unzip (test_dir);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
813 %! else
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
814 %! uz_filelist = cell (1, numel (z_filelist));
28915
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
815 %! for idx = 1:numel (z_filelist)
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
816 %! uz_filelist(idx) = z.unzip (z_filelist{idx});
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
817 %! endfor
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
818 %! endif
30113
62af50666f62 update gzip.cc tests
John W. Eaton <jwe@octave.org>
parents: 30111
diff changeset
819 %! uz_filelist = sort (uz_filelist);
62af50666f62 update gzip.cc tests
John W. Eaton <jwe@octave.org>
parents: 30111
diff changeset
820 %! fpaths = sort (fpaths);
62af50666f62 update gzip.cc tests
John W. Eaton <jwe@octave.org>
parents: 30111
diff changeset
821 %! assert (is_same_file (uz_filelist(:), fpaths(:))) # bug #48598
28915
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
822 %! for idx = 1:numel (fpaths)
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
823 %! assert (hash ("md5", fileread (fpaths{idx})), md5s{idx})
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
824 %! endfor
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
825 %!endfunction
23691
2fa6013799fa * gzip.cc: Tag %!xtest with bug number.
John W. Eaton <jwe@octave.org>
parents: 23591
diff changeset
826 %!test <48598> run_test_function (@test_xzip_dir)
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
827
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
828 %!function test_save_to_dir (test_dir, z)
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
829 %! filename = "test-file";
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
830 %! filepath = fullfile (test_dir, filename);
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
831 %! create_file (filepath, rand (100, 1));
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
832 %! md5 = hash ("md5", fileread (filepath));
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
833 %!
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
834 %! ## test with existing and non-existing directory
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
835 %! out_dirs = {tempname (test_dir), tempname (test_dir)};
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
836 %! if (! mkdir (out_dirs{1}))
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
837 %! error ("unable to create directory for test");
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
838 %! endif
22365
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
839 %! unwind_protect
28915
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
840 %! for idx = 1:numel (out_dirs)
22365
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
841 %! out_dir = out_dirs{idx};
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
842 %! uz_file = fullfile (out_dir, filename);
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
843 %! z_file = [uz_file z.ext];
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
844 %!
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
845 %! z_filelist = z.zip (filepath, out_dir);
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
846 %! assert (z_filelist, {z_file})
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
847 %! assert (exist (z_file, "file"), 2)
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
848 %!
22365
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
849 %! uz_filelist = z.unzip (z_file);
29720
e1139b820c95 gzip.cc: Use is_same_file in BISTs to assert that files are the same.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
850 %! assert (is_same_file (uz_filelist, {uz_file})) # bug #48598
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
851 %!
22365
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
852 %! assert (hash ("md5", fileread (uz_file)), md5)
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
853 %! endfor
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
854 %! unwind_protect_cleanup
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
855 %! confirm_recursive_rmdir (false, "local");
28915
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
856 %! for idx = 1:numel (out_dirs)
28087
9cb04a9e81ec rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents: 27957
diff changeset
857 %! sts = rmdir (out_dirs{idx}, "s");
22365
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
858 %! endfor
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
859 %! end_unwind_protect
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
860 %!endfunction
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
861 %!test run_test_function (@test_save_to_dir)
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
862 */
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29720
diff changeset
863
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30896
diff changeset
864 OCTAVE_END_NAMESPACE(octave)