annotate libinterp/dldfcn/gzip.cc @ 25103:078b795c5219 stable

maint: style check C++ ahead of 4.4 release. * ButtonGroup.cc, Canvas.cc, Figure.cc, GLCanvas.cc, GLCanvas.h, ListBoxControl.cc, ObjectProxy.cc, QTerminal.h, dialog.cc, documentation.cc, files-dock-widget.cc, history-dock-widget.cc, file-editor-tab.cc, file-editor.h, find-dialog.cc, marker.h, octave-qscintilla.cc, octave-qscintilla.h, main-window.cc, webinfo.cc, resource-manager.h, settings-dialog.cc, shortcut-manager.cc, shortcut-manager.h, variable-editor.cc, workspace-view.cc, build-env.in.cc, __ilu__.cc, cellfun.cc, data.cc, dirfns.cc, dynamic-ld.h, environment.cc, error.cc, fcn-info.cc, gl-render.cc, gl2ps-print.cc, graphics.cc, graphics.in.h, help.cc, interpreter.cc, load-path.cc, load-save.cc, ls-mat5.cc, mex.cc, oct-stream.cc, oct-stream.h, qz.cc, sighandlers.cc, sparse-xpow.cc, svd.cc, symscope.h, symtab.cc, symtab.h, sysdep.cc, url-handle-manager.h, utils.cc, variables.cc, __init_fltk__.cc, __ode15__.cc, gzip.cc, ov-base.cc, ov-builtin.h, ov-cell.cc, ov-class.cc, ov-dld-fcn.h, ov-fcn-handle.cc, ov-java.cc, ov-re-diag.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-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-fcdm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.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-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.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, bp-table.cc, comment-list.h, jit-ir.h, jit-typeinfo.cc, jit-typeinfo.h, lex.h, parse.h, pt-binop.h, pt-decl.h, pt-eval.cc, pt-jit.cc, pt-jit.h, pt-misc.h, token.h, CMatrix.cc, CMatrix.h, CSparse.cc, CSparse.h, dMatrix.h, fCMatrix.cc, fCMatrix.h, fMatrix.h, Faddeeva.cc, gepbalance.cc, hess.cc, oct-fftw.cc, oct-fftw.h, file-stat.cc, lo-sysinfo.cc, action-container.h, f77-fcn.h, lo-regexp.cc, oct-mutex.h, oct-shlib.cc: Use Octave coding conventions in C++ files.
author Rik <rik@octave.org>
date Tue, 03 Apr 2018 13:52:07 -0700
parents 6652d3823428
children 8945a6a6c0eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
1 /*
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
2
25054
6652d3823428 maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 24624
diff changeset
3 Copyright (C) 2016-2018 Carnë Draug
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
4
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
5 This file is part of Octave.
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
6
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23812
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
8 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23812
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
10 (at your option) any later version.
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
11
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
15 GNU General Public License for more details.
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
16
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
17 You should have received a copy of the GNU General Public License
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
18 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23812
diff changeset
19 <https://www.gnu.org/licenses/>.
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
20
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
21 */
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
22
24624
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
23 //! @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
24 //! 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
25 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
26 //! 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
27 //! 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
28 //! 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
29 //! file:
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
30 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
31 //! - 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
32 //! - 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
33 //! - 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
34 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
35 //! 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
36 //! 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
37 //! filenames.
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
38 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
39 //! 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
40 //! filenames. However, that solution causes:
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 //! # 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
43 //! # 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
44 //! # 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
45 //! # 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
46
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
47 #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
48 # 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
49 #endif
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
50
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
51 #include <cstdio>
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
52 #include <cstring>
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
53
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
54 #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
55 #include <list>
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
56 #include <stdexcept>
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
57 #include <string>
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
58
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
59 #include "Array.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
60 #include "dir-ops.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
61 #include "file-ops.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
62 #include "file-stat.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
63 #include "glob-match.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
64 #include "oct-env.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
65 #include "str-vec.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
66
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
67 #include "Cell.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
68 #include "defun-dld.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
69 #include "defun-int.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
70 #include "errwarn.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
71 #include "ov.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22923
diff changeset
72 #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
73
22188
1344509a480c style fixes
John W. Eaton <jwe@octave.org>
parents: 22187
diff changeset
74 #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
75 # 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
76 #endif
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_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
79 # 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
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
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
82 namespace octave
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
83 {
24624
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
84 //! RIIA wrapper for std::FILE*.
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
85 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
86 //! 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
87 //! the close method which throws.
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
88 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
89 //! 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
90 //! 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
91 //! after fclose.
22188
1344509a480c style fixes
John W. Eaton <jwe@octave.org>
parents: 22187
diff changeset
92
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
93 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
94 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
95 public:
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
96
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
97 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
98
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
99 CFile (const std::string& path, const std::string& mode)
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
100 : m_fp (std::fopen (path.c_str (), mode.c_str ()))
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
101 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
102 if (! m_fp)
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
103 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
104 }
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 CFile (const CFile&) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
107
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
108 CFile& operator = (const CFile&) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
109
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
110 ~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
111 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
112 if (m_fp)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
113 std::fclose (m_fp);
22187
2aae8894885b xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents: 22173
diff changeset
114 }
2aae8894885b xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents: 22173
diff changeset
115
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
116 void close (void)
22187
2aae8894885b xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents: 22173
diff changeset
117 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
118 if (std::fclose (m_fp))
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
119 throw std::runtime_error ("unable to close file");
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
120
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
121 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
122 }
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
123
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
124 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
125 };
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
126
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
127 #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
128
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
129 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
130 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
131 public:
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
132
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
133 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
134
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
135 static void zip (const std::string& source_path,
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
136 const std::string& dest_path)
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
137 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
138 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
139 z.deflate ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
140 z.close ();
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
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
143 private:
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
144
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
145 class zipper
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
146 {
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
147 public:
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 zipper (void) = delete;
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 zipper (const std::string& source_path, const std::string& dest_path)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
152 : m_status (BZ_OK), m_source (source_path, "rb"),
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
153 m_dest (dest_path, "wb"),
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
154 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
155 {
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
156 if (m_status != BZ_OK)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
157 throw std::runtime_error ("failed to open bzip2 stream");
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
158 }
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 zipper (const zipper&) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
161
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
162 zipper& operator = (const zipper&) = delete;
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 (void)
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 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
167 BZ2_bzWriteClose (&m_status, m_bz, 1, nullptr, nullptr);
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
168 }
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 void deflate (void)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
171 {
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
172 const std::size_t buf_len = 8192;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
173 char buf[buf_len];
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
174 std::size_t n_read;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
175 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
176 {
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
177 if (std::ferror (m_source.m_fp))
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
178 throw std::runtime_error ("failed to read from source file");
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
179 BZ2_bzWrite (&m_status, m_bz, buf, n_read);
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
180 if (m_status == BZ_IO_ERROR)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
181 throw std::runtime_error ("failed to write or compress");
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
182 }
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
183 if (std::ferror (m_source.m_fp))
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
184 throw std::runtime_error ("failed to read from source file");
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
185 }
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 void close (void)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
188 {
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
189 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
190 BZ2_bzWriteClose (&m_status, m_bz, abandon, nullptr, nullptr);
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
191 if (m_status != BZ_OK)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
192 throw std::runtime_error ("failed to close bzip2 stream");
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
193 m_bz = nullptr;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
194
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
195 // We have no error handling for failing to close source, let
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
196 // the destructor close it.
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
197 m_dest.close ();
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
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
200 private:
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
201
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
202 int m_status;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
203 CFile m_source;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
204 CFile m_dest;
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
205 BZFILE *m_bz;
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
206 };
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
207 };
22188
1344509a480c style fixes
John W. Eaton <jwe@octave.org>
parents: 22187
diff changeset
208
1344509a480c style fixes
John W. Eaton <jwe@octave.org>
parents: 22187
diff changeset
209 #endif
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
210
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
211 // Note about zlib and gzip
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
212 //
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
213 // 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
214 // 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
215 // 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
216 // has different headers and trailers.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
217 //
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
218 // 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
219 // 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
220 //
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
221 // 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
222 // a file name or modification date), nor will inflate tell you what
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
223 // was in the gzip header. If you need to customize the header or
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
224 // 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
225 // operations and the crc32() function and roll your own gzip
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
226 // encoding and decoding. Read the gzip RFC 1952 for details of the
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
227 // header and trailer format.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
228 // zlib FAQ
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
229 //
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
230 // 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
231 // 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
232 // ourselves though.
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 // 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
235 // 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
236
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
237
22188
1344509a480c style fixes
John W. Eaton <jwe@octave.org>
parents: 22187
diff changeset
238 #if defined (HAVE_Z)
1344509a480c style fixes
John W. Eaton <jwe@octave.org>
parents: 22187
diff changeset
239
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
240 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
241 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
242 public:
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
243
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
244 static const constexpr char *extension = ".gz";
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
245
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
246 static void zip (const std::string& source_path,
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
247 const std::string& dest_path)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
248 {
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
249 gz::zipper z (source_path, dest_path);
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
250 z.deflate ();
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
251 z.close ();
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
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
254 private:
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
255
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
256 // 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
257 class uchar_array
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
258 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
259 public:
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
260
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
261 // 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
262 unsigned char *p;
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
263
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
264 uchar_array (void) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
265
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
266 uchar_array (const std::string& str)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
267 {
23812
057a894914df Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents: 23795
diff changeset
268 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
269 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
270 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
271
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
272 uchar_array (const uchar_array&) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
273
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
274 uchar_array& operator = (const uchar_array&) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
275
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
276 ~uchar_array (void) { delete[] p; }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
277 };
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
278
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
279 class gzip_header : public gz_header
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
280 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
281 public:
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
282
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
283 gzip_header (void) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
284
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
285 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
286 : 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
287 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23691
diff changeset
288 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
289 if (! source_stat)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
290 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
291
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
292 // 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
293 // 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
294 // unix_time really never be negative?
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
295 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
296
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
297 // 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
298 // 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
299 // 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
300 // 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
301 // 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
302 // 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
303 // 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
304 // 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
305 // forced to lower case.
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
306 name = m_basename.p;
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
307
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
308 // 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
309 // 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
310 comment = Z_NULL;
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 // 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
313 extra = Z_NULL;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
314
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
315 // 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
316 // 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
317 // 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
318 hcrc = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
319
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
320 // OS (Operating System):
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
321 // 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
322 // 1 - Amiga
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
323 // 2 - VMS (or OpenVMS)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
324 // 3 - Unix
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
325 // 4 - VM/CMS
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
326 // 5 - Atari TOS
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
327 // 6 - HPFS filesystem (OS/2, NT)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
328 // 7 - Macintosh
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
329 // 8 - Z-System
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
330 // 9 - CP/M
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
331 // 10 - TOPS-20
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
332 // 11 - NTFS filesystem (NT)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
333 // 12 - QDOS
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
334 // 13 - Acorn RISCOS
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
335 // 255 - unknown
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
336 //
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
337 // 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
338 // 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
339 // destination file.
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 #if defined (__WIN32__)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
342 // Or should it be 11?
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
343 os = 0;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
344 #elif defined (__APPLE__)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
345 os = 7;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
346 #else
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
347 // Unix by default?
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
348 os = 3;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
349 #endif
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
350 }
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
351
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
352 gzip_header (const gzip_header&) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
353
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
354 gzip_header& operator = (const gzip_header&) = delete;
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 (void) = default;
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 private:
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 // This must be kept for gz_header.name
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
361 uchar_array m_basename;
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
362 };
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
363
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
364 class zipper
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
365 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
366 public:
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
367
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
368 zipper (void) = delete;
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
369
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
370 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
371 : m_source (source_path, "rb"), m_dest (dest_path, "wb"),
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
372 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
373 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
374 m_strm->zalloc = Z_NULL;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
375 m_strm->zfree = Z_NULL;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
376 m_strm->opaque = Z_NULL;
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
377 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
378
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
379 zipper (const zipper&) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
380
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
381 zipper& operator = (const zipper&) = delete;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
382
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
383 ~zipper (void)
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
384 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
385 if (m_strm)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
386 deflateEnd (m_strm);
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
387 delete m_strm;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
388 }
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
389
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
390 void deflate (void)
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
391 {
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
392 // 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
393 // 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
394 // int method,
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
395 // 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
396 // 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
397 // int strategy);
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
398 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
399 Z_DEFAULT_STRATEGY);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
400 if (status != Z_OK)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
401 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
402
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
403 deflateSetHeader (m_strm, &m_header);
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
404
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
405 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
406 unsigned char buf_in[buf_len];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
407 unsigned char buf_out[buf_len];
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
408
22922
426325aa8ee9 Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents: 22489
diff changeset
409 int flush;
426325aa8ee9 Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents: 22489
diff changeset
410
426325aa8ee9 Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents: 22489
diff changeset
411 do
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
412 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
413 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
414 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
415
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
416 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
417 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
418
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
419 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
420 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
421
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
422 // 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
423 // 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
424 // there might be more output pending.
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
425 do
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
426 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
427 m_strm->avail_out = buf_len;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
428 m_strm->next_out = buf_out;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
429 status = ::deflate (m_strm, flush);
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
430 if (status == Z_STREAM_ERROR)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
431 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
432
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
433 std::fwrite (buf_out, sizeof (buf_out[0]),
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
434 buf_len - m_strm->avail_out, m_dest.m_fp);
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
435 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
436 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
437 }
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
438 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
439
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
440 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
441 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
442
426325aa8ee9 Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents: 22489
diff changeset
443 } while (flush != Z_FINISH);
426325aa8ee9 Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents: 22489
diff changeset
444
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
445 if (status != Z_STREAM_END)
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
446 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
447 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
448
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
449 void close (void)
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
450 {
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
451 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
452 throw std::runtime_error ("failed to close zlib stream");
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
453 m_strm = nullptr;
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
454
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
455 // 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
456 // the destructor close it.
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
457 m_dest.close ();
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
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
460 private:
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
461
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
462 CFile m_source;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
463 CFile m_dest;
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
464 gzip_header m_header;
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
465 z_stream *m_strm;
23098
03f817ed37c5 style fixes
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
466 };
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
467 };
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
468
22188
1344509a480c style fixes
John W. Eaton <jwe@octave.org>
parents: 22187
diff changeset
469 #endif
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
470
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
471
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
472 template<typename X>
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
473 string_vector
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
474 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
475 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
476 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
477 std::list<std::string> dest_paths;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
478
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
479 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
480 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
481 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23691
diff changeset
482 const sys::file_stat fs (path);
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
483 // 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
484 if (fs.is_dir ())
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 sys::dir_entry dir (path);
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
487 if (dir)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
488 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
489 // Collect the whole list of filenames first, before recursion
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
490 // to avoid issues with infinite loop if the action generates
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
491 // files in the same directory (highly likely).
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
492 string_vector dirlist = dir.read ();
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
493 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
494 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
495 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
496 }
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
497 // Note that we skip any problem with directories.
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
498 }
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
499 else if (fs.is_reg ())
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
500 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
501 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
502 try
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 X::zip (path, dest_path);
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 catch (...)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
507 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
508 // Error "handling" is not including filename on the output list.
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
509 // Also remove created file which maybe was not even created
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
510 // in the first place. Note that it is possible for the file
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
511 // to exist in the first place and for X::zip to not have
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
512 // clobber it yet but we remove it anyway by design.
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23691
diff changeset
513 sys::unlink (dest_path);
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
514 return;
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
515 }
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
516 dest_paths.push_front (dest_path);
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
517 }
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
518 // Skip all other file types and errors.
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
519 return;
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22365
diff changeset
520 };
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
521
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
522 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
523 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23691
diff changeset
524 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
525 const string_vector filepaths = pattern.glob ();
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
526 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
527 walk (filepaths(j));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
528 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
529 return string_vector (dest_paths);
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
530 }
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
531
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
532
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
533 template<typename X>
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
534 string_vector
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
535 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
536 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
537 const std::string ext = X::extension;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
538 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
539 = [&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
540 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
541 return source_path + ext;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
542 };
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
543 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
544 }
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 template<typename X>
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
547 string_vector
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
548 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
549 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
550 const std::string ext = X::extension;
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
551 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
552 = [&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
553 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23691
diff changeset
554 const std::string basename = sys::env::base_pathname (source_path);
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23691
diff changeset
555 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
556 };
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
557
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
558 // We don't care if mkdir fails. Maybe it failed because it already
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
559 // exists, or maybe it can't bre created. If the first, then there's
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
560 // 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
561 // 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
562 sys::mkdir (out_dir, 0777);
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
563 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
564 }
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
565
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
566 template<typename X>
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
567 static octave_value_list
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
568 xzip (const std::string& func_name, const octave_value_list& args)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
569 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
570 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
571 if (nargin < 1 || nargin > 2)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
572 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
573
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
574 const Array<std::string> source_patterns
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
575 = args(0).xcellstr_value ("%s: FILES must be a character array or cellstr",
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
576 func_name.c_str ());
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
577 if (nargin == 1)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
578 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
579 else // nargin == 2
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
580 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
581 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
582 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
583 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
584 }
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
585 }
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
586
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
587 DEFUN_DLD (gzip, args, ,
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
588 doc: /* -*- texinfo -*-
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
589 @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
590 @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
591 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
592
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
593 @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
594 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
595 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
596 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
597 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
598 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
599 directory.
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
600
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
601 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
602 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
603 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
604 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
605 same name.
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
606
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
607 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
608
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
609 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
610 @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
611 @end deftypefn */)
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
612 {
22265
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
613 #if defined (HAVE_Z)
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
614
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
615 return octave::xzip<octave::gz> ("gzip", args);
22265
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
616
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
617 #else
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
618
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
619 octave_unused_parameter (args);
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
620
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
621 err_disabled_feature ("gzip", "gzip");
22265
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
622
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
623 #endif
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
624 }
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
625
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
626 /*
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
627 %!error gzip ()
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
628 %!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
629 %!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
630 */
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
631
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
632 DEFUN_DLD (bzip2, args, ,
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
633 doc: /* -*- texinfo -*-
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
634 @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
635 @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
636 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
637
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
638 @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
639 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
640 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
641 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
642 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
643
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
644 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
645 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
646 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
647 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
648 same name.
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
649
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
650 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
651
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
652 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
653 @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
654 @end deftypefn */)
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
655 {
22265
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
656 #if defined (HAVE_BZ2)
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
657
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22299
diff changeset
658 return octave::xzip<octave::bz2> ("bzip2", args);
22265
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
659
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
660 #else
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
661
22269
a76b931d2c4b * xzip.cc (Fbzip2): Fix typo of "octave_unused_parameter".
Mike Miller <mtmiller@octave.org>
parents: 22265
diff changeset
662 octave_unused_parameter (args);
22265
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
663
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
664 err_disabled_feature ("bzip2", "bzip2");
22265
15b9d7cb3098 eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents: 22194
diff changeset
665
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
666 #endif
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
667 }
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
668
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
669 // 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
670 /*
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
671
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
672 ## 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
673 ## 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
674 ## 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
675
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
676 %!function run_test_function (test_function)
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
677 %! 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
678 %! if (__octave_config_info__ ().build_features.BZ2)
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
679 %! enabled_zippers(end+1).zip = @bzip2;
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
680 %! enabled_zippers(end).unzip = @bunzip2;
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
681 %! 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
682 %! endif
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
683 %! if (__octave_config_info__ ().build_features.Z)
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
684 %! enabled_zippers(end+1).zip = @gzip;
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
685 %! enabled_zippers(end).unzip = @gunzip;
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
686 %! 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
687 %! endif
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 %! 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
690 %! 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
691 %! 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
692 %! 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
693 %! endif
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
694 %! unwind_protect
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
695 %! 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
696 %! 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
697 %! confirm_recursive_rmdir (false, "local");
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
698 %! rmdir (test_dir, "s");
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
699 %! 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
700 %! endfor
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
701 %!endfunction
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
702
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
703 %!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
704 %! 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
705 %! 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
706 %! 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
707 %! endif
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
708 %! 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
709 %! 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
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 %! 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
712 %! 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
713 %! endif
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
714 %!endfunction
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
715
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
716 %!function unlink_or_error (filepath)
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
717 %! [err, msg] = unlink (filepath);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
718 %! if (err)
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
719 %! 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
720 %! endif
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
721 %!endfunction
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
722
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
723 ## 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
724 %!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
725 %! 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
726 %! 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
727 %! 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
728 %!
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
729 %! z_file = [test_file z.ext];
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
730 %! z_filelist = z.zip (test_file);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
731 %! assert (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
732 %!
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
733 %! unlink_or_error (test_file);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
734 %! uz_filelist = z.unzip (z_file);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
735 %! assert (uz_filelist, {test_file})
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
736 %!
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
737 %! 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
738 %!endfunction
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
739 %!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
740
22352
d71ae2cd510b build: Change known failures to xtest so that 'make check' produces a clean run.
Rik <rik@octave.org>
parents: 22339
diff changeset
741 ## Test that xzipped files are rexzipped (hits bug #48597, #48598)
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
742 %!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
743 %! 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
744 %! 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
745 %! 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
746 %!
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
747 %! z_file = [ori_file z.ext];
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
748 %! z_filelist = z.zip (ori_file);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
749 %! assert (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
750 %! 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
751 %! 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
752 %!
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
753 %! unlink_or_error (ori_file);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
754 %! uz_filelist = z.unzip (z_file);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
755 %! assert (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
756 %! 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
757 %! 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
758 %!
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
759 %! ## xzip should dutifully re-xzip files even if they already are zipped
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
760 %! z_z_file = [z_file z.ext];
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
761 %! z_z_filelist = z.zip (z_file);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
762 %! assert (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
763 %! 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
764 %! 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
765 %!
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
766 %! md5_z = hash ("md5", fileread (z_file));
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
767 %! unlink_or_error (z_file);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
768 %! uz_z_filelist = z.unzip (z_z_file);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
769 %! assert (uz_z_filelist, {z_file}) # bug #48598
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
770 %! assert (exist (z_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
771 %! 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
772 %!endfunction
23691
2fa6013799fa * gzip.cc: Tag %!xtest with bug number.
John W. Eaton <jwe@octave.org>
parents: 23591
diff changeset
773 %!test <48597> 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
774
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
775 %!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
776 %! 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
777 %! md5s = cell (1, 3);
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
778 %! for idx = 1:numel(fpaths)
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
779 %! 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
780 %! 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
781 %! endfor
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 %! test_dir = [test_dir filesep()];
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
784 %!
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
785 %! z_files = strcat (fpaths, z.ext);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
786 %! z_filelist = z.zip (test_dir);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
787 %! assert (sort (z_filelist), z_files(:))
22160
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
788 %! for idx = 1:numel(fpaths)
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
789 %! assert (exist (z_files{idx}), 2)
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
790 %! 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
791 %! endfor
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
792 %!
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
793 %! ## only gunzip handles directory (bunzip2 should too though)
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
794 %! if (z.unzip == @gunzip)
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
795 %! uz_filelist = z.unzip (test_dir);
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
796 %! else
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
797 %! uz_filelist = cell (1, numel (z_filelist));
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
798 %! for idx = 1:numel(z_filelist)
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
799 %! uz_filelist(idx) = z.unzip (z_filelist{idx});
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
800 %! endfor
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
801 %! endif
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
802 %! assert (sort (uz_filelist), fpaths(:)) # 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
803 %! for idx = 1:numel(fpaths)
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
804 %! 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
805 %! endfor
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
806 %!endfunction
23691
2fa6013799fa * gzip.cc: Tag %!xtest with bug number.
John W. Eaton <jwe@octave.org>
parents: 23591
diff changeset
807 %!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
808
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
809 %!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
810 %! 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
811 %! 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
812 %! 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
813 %! 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
814 %!
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
815 %! ## 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
816 %! 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
817 %! 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
818 %! 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
819 %! endif
22365
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
820 %! unwind_protect
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
821 %! for idx = 1:numel(out_dirs)
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
822 %! out_dir = out_dirs{idx};
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
823 %! uz_file = fullfile (out_dir, filename);
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
824 %! z_file = [uz_file z.ext];
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
825 %!
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
826 %! 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
827 %! assert (z_filelist, {z_file})
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
828 %! assert (exist (z_file, "file"), 2)
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
829 %!
22365
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
830 %! uz_filelist = z.unzip (z_file);
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
831 %! assert (uz_filelist, {uz_file}) # bug #48598
22194
b1ebad209360 xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents: 22188
diff changeset
832 %!
22365
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
833 %! 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
834 %! endfor
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
835 %! unwind_protect_cleanup
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
836 %! confirm_recursive_rmdir (false, "local");
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
837 %! for idx = 1:numel(out_dirs)
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
838 %! rmdir (out_dirs{idx}, "s");
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
839 %! endfor
119f408f2dd1 Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents: 22352
diff changeset
840 %! 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
841 %!endfunction
766f934db568 Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
842 %!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
843 */