Mercurial > octave
annotate libinterp/dldfcn/gzip.cc @ 32632:2e484f9f1f18 stable
maint: update Octave Project Developers copyright for the new year
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 22 Dec 2023 12:08:17 -0500 |
parents | febd82d1a8de |
children | afca8eb09d65 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31837
diff
changeset
|
3 // Copyright (C) 2016-2024 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
25 |
24624
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
26 //! @file gzip.cc |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
27 //! Octave interface to the compression and uncompression libraries. |
24624
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
28 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
29 //! This was originally implemented as an m file which directly called |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
30 //! bzip2 and gzip applications. This may look simpler but causes some |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
31 //! issues (see bug #43431) because we have no control over the output |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
32 //! file: |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
33 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
34 //! - created file is always in the same directory as the original file; |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
35 //! - automatically skip files that already have gz/bz2/etc extension; |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
36 //! - some older versions lack the --keep option. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
37 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
38 //! In addition, because system() does not have a method that allows |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
39 //! passing a list of arguments, there is the issue of having to escape |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
40 //! filenames. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
41 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
42 //! A solution is to pipe file contents into the applications instead of |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
43 //! filenames. However, that solution causes: |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
44 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
45 //! # missing file header with original file information; |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
46 //! # implementing ourselves the recursive transversion of directories; |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
47 //! # do the above in a m file which will be slow; |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
48 //! # popen2 is frail on windows. |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
49 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
50 #if defined (HAVE_CONFIG_H) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
51 # include "config.h" |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
52 #endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
53 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
54 #include <cstdio> |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
55 #include <cstring> |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
56 |
23024
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22923
diff
changeset
|
57 #include <functional> |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
58 #include <list> |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
59 #include <stdexcept> |
23024
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22923
diff
changeset
|
60 #include <string> |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22923
diff
changeset
|
61 |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22923
diff
changeset
|
62 #include "Array.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22923
diff
changeset
|
63 #include "dir-ops.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22923
diff
changeset
|
64 #include "file-ops.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22923
diff
changeset
|
65 #include "file-stat.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22923
diff
changeset
|
66 #include "glob-match.h" |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25103
diff
changeset
|
67 #include "lo-sysdep.h" |
23024
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22923
diff
changeset
|
68 #include "oct-env.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22923
diff
changeset
|
69 #include "str-vec.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22923
diff
changeset
|
70 |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22923
diff
changeset
|
71 #include "Cell.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22923
diff
changeset
|
72 #include "defun-dld.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22923
diff
changeset
|
73 #include "defun-int.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22923
diff
changeset
|
74 #include "errwarn.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22923
diff
changeset
|
75 #include "ov.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22923
diff
changeset
|
76 #include "ovl.h" |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
77 |
22188 | 78 #if defined (HAVE_BZLIB_H) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
79 # include <bzlib.h> |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
80 #endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
81 |
22188 | 82 #if defined (HAVE_ZLIB_H) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
83 # include <zlib.h> |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
84 #endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
85 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30896
diff
changeset
|
86 OCTAVE_BEGIN_NAMESPACE(octave) |
29960
939bef0b66e0
merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
87 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
88 //! RIIA wrapper for std::FILE*. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
89 //! |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
90 //! If error handling is available for failing to close the file, use |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
91 //! the close method which throws. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
92 //! |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
93 //! If the file has been closed, fp is set to nullptr. Remember that |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
94 //! behavior is undefined if the value of the pointer stream is used |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
95 //! after fclose. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
96 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
97 class CFile |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
98 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
99 public: |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
100 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
101 CFile () = delete; |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
102 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
103 CFile (const std::string& path, const std::string& mode) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
104 : m_fp (sys::fopen (path, mode)) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
105 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
106 if (! m_fp) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
107 throw std::runtime_error ("unable to open file"); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
108 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
109 |
31837
febd82d1a8de
use new macros to consistently delete copy and move member functions
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
110 OCTAVE_DISABLE_COPY_MOVE (CFile) |
22188 | 111 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
112 ~CFile () |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
113 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
114 if (m_fp) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
115 std::fclose (m_fp); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
116 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
117 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
118 void close () |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
119 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
120 if (std::fclose (m_fp)) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
121 throw std::runtime_error ("unable to close file"); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
122 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
123 m_fp = nullptr; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
124 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
125 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
126 std::FILE *m_fp; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
127 }; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
128 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
129 #if defined (HAVE_BZ2) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
130 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
131 class bz2 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
132 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
133 public: |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
134 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
135 static const constexpr char *extension = ".bz2"; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
136 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
137 static void zip (const std::string& source_path, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
138 const std::string& dest_path) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
139 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
140 bz2::zipper z (source_path, dest_path); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
141 z.deflate (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
142 z.close (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
143 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
144 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
145 private: |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
146 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
147 class zipper |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
148 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
149 public: |
23098 | 150 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
151 zipper () = delete; |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
152 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
153 zipper (const std::string& source_path, const std::string& dest_path) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
154 : m_status (BZ_OK), m_source (source_path, "rb"), |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
155 m_dest (dest_path, "wb"), |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
156 m_bz (BZ2_bzWriteOpen (&m_status, m_dest.m_fp, 9, 0, 30)) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
157 { |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
158 if (m_status != BZ_OK) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
159 throw std::runtime_error ("failed to open bzip2 stream"); |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
160 } |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
161 |
31837
febd82d1a8de
use new macros to consistently delete copy and move member functions
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
162 OCTAVE_DISABLE_COPY_MOVE (zipper) |
23098 | 163 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
164 ~zipper () |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
165 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
166 if (m_bz != nullptr) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
167 BZ2_bzWriteClose (&m_status, m_bz, 1, nullptr, nullptr); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
168 } |
23098 | 169 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
170 void deflate () |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
171 { |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
172 const std::size_t buf_len = 8192; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
173 char buf[buf_len]; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
174 std::size_t n_read; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
175 while ((n_read = std::fread (buf, sizeof (buf[0]), buf_len, m_source.m_fp)) != 0) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
176 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
177 if (std::ferror (m_source.m_fp)) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
178 throw std::runtime_error ("failed to read from source file"); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
179 BZ2_bzWrite (&m_status, m_bz, buf, n_read); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
180 if (m_status == BZ_IO_ERROR) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
181 throw std::runtime_error ("failed to write or compress"); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
182 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
183 if (std::ferror (m_source.m_fp)) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
184 throw std::runtime_error ("failed to read from source file"); |
22187
2aae8894885b
xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents:
22173
diff
changeset
|
185 } |
2aae8894885b
xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents:
22173
diff
changeset
|
186 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
187 void close () |
22187
2aae8894885b
xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents:
22173
diff
changeset
|
188 { |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
189 int abandon = (m_status == BZ_IO_ERROR) ? 1 : 0; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
190 BZ2_bzWriteClose (&m_status, m_bz, abandon, nullptr, nullptr); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
191 if (m_status != BZ_OK) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
192 throw std::runtime_error ("failed to close bzip2 stream"); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
193 m_bz = nullptr; |
23098 | 194 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
195 // We have no error handling for failing to close source, let |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
196 // the destructor close it. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
197 m_dest.close (); |
23098 | 198 } |
199 | |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
200 private: |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
201 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
202 int m_status; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
203 CFile m_source; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
204 CFile m_dest; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
205 BZFILE *m_bz; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
206 }; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
207 }; |
23098 | 208 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
209 #endif |
23098 | 210 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
211 // Note about zlib and gzip |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
212 // |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
213 // gzip is a format for compressed single files. zlib is a format |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
214 // designed for in-memory and communication channel applications. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
215 // gzip uses the same format internally for the compressed data but |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
216 // has different headers and trailers. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
217 // |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
218 // zlib is also a library but gzip is not. Very old versions of zlib do |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
219 // not include functions to create useful gzip headers and trailers: |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
220 // |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
221 // Note that you cannot specify special gzip header contents (e.g. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
222 // a file name or modification date), nor will inflate tell you what |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
223 // was in the gzip header. If you need to customize the header or |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
224 // see what's in it, you can use the raw deflate and inflate |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
225 // operations and the crc32() function and roll your own gzip |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
226 // encoding and decoding. Read the gzip RFC 1952 for details of the |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
227 // header and trailer format. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
228 // zlib FAQ |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
229 // |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
230 // Recent versions (on which we are already dependent) have deflateInit2() |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
231 // to do it. We still need to get the right metadata for the header |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
232 // ourselves though. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
233 // |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
234 // The header is defined in RFC #1952 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
235 // GZIP file format specification version 4.3 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
236 |
23098 | 237 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
238 #if defined (HAVE_Z) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
239 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
240 class gz |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
241 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
242 public: |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
243 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
244 static const constexpr char *extension = ".gz"; |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
245 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
246 static void zip (const std::string& source_path, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
247 const std::string& dest_path) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
248 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
249 gz::zipper z (source_path, dest_path); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
250 z.deflate (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
251 z.close (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
252 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
253 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
254 private: |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
255 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
256 // Util class to get a non-const char* |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
257 class uchar_array |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
258 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
259 public: |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
260 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
261 // Bytef is a typedef for unsigned char |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
262 unsigned char *p; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
263 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
264 uchar_array () = delete; |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
265 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
266 uchar_array (const std::string& str) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
267 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
268 p = new Bytef[str.length () + 1]; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
269 std::strcpy (reinterpret_cast<char *> (p), str.c_str ()); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
270 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
271 |
31837
febd82d1a8de
use new macros to consistently delete copy and move member functions
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
272 OCTAVE_DISABLE_COPY_MOVE (uchar_array) |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
273 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
274 ~uchar_array () { delete[] p; } |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
275 }; |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
276 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
277 class gzip_header : public gz_header |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
278 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
279 public: |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
280 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
281 gzip_header () = delete; |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
282 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
283 gzip_header (const std::string& source_path) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
284 : m_basename (sys::env::base_pathname (source_path)) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
285 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
286 const sys::file_stat source_stat (source_path); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
287 if (! source_stat) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
288 throw std::runtime_error ("unable to stat source file"); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
289 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
290 // time_t may be a signed int in which case it will be a |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
291 // positive number so it is safe to uLong. Or is it? Can |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
292 // unix_time really never be negative? |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
293 time = uLong (source_stat.mtime ().unix_time ()); |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
294 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
295 // If FNAME is set, an original file name is present, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
296 // terminated by a zero byte. The name must consist of ISO |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
297 // 8859-1 (LATIN-1) characters; on operating systems using |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
298 // EBCDIC or any other character set for file names, the name |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
299 // must be translated to the ISO LATIN-1 character set. This |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
300 // is the original name of the file being compressed, with any |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
301 // directory components removed, and, if the file being |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
302 // compressed is on a file system with case insensitive names, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
303 // forced to lower case. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
304 name = m_basename.p; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
305 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
306 // If we don't set it to Z_NULL, then it will set FCOMMENT (4th bit) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
307 // on the FLG byte, and then write {0, 3} comment. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
308 comment = Z_NULL; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
309 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
310 // Seems to already be the default but we are not taking chances. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
311 extra = Z_NULL; |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
312 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
313 // We do not want a CRC for the header. That would be only 2 more |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
314 // bytes, and maybe it would be a good thing but we want to generate |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
315 // gz files similar to the default gzip application. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
316 hcrc = 0; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
317 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
318 // OS (Operating System): |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
319 // 0 - FAT filesystem (MS-DOS, OS/2, NT/Win32) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
320 // 1 - Amiga |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
321 // 2 - VMS (or OpenVMS) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
322 // 3 - Unix |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
323 // 4 - VM/CMS |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
324 // 5 - Atari TOS |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
325 // 6 - HPFS filesystem (OS/2, NT) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
326 // 7 - Macintosh |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
327 // 8 - Z-System |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
328 // 9 - CP/M |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
329 // 10 - TOPS-20 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
330 // 11 - NTFS filesystem (NT) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
331 // 12 - QDOS |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
332 // 13 - Acorn RISCOS |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
333 // 255 - unknown |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
334 // |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
335 // The list is problematic because it mixes OS and filesystem. It |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
336 // also does not specify whether filesystem relates to source or |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
337 // destination file. |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
338 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
339 #if defined (__WIN32__) |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
340 // Or should it be 11? |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
341 os = 0; |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
342 #elif defined (__APPLE__) |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
343 os = 7; |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
344 #else |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
345 // Unix by default? |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
346 os = 3; |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
347 #endif |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
348 } |
23098 | 349 |
31837
febd82d1a8de
use new macros to consistently delete copy and move member functions
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
350 OCTAVE_DISABLE_COPY_MOVE (gzip_header) |
23098 | 351 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
352 ~gzip_header () = default; |
23098 | 353 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
354 private: |
23098 | 355 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
356 // This must be kept for gz_header.name |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
357 uchar_array m_basename; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
358 }; |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
359 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
360 class zipper |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
361 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
362 public: |
23098 | 363 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
364 zipper () = delete; |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
365 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
366 zipper (const std::string& source_path, const std::string& dest_path) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
367 : m_source (source_path, "rb"), m_dest (dest_path, "wb"), |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
368 m_header (source_path), m_strm (new z_stream) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
369 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
370 m_strm->zalloc = Z_NULL; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
371 m_strm->zfree = Z_NULL; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
372 m_strm->opaque = Z_NULL; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
373 } |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
374 |
31837
febd82d1a8de
use new macros to consistently delete copy and move member functions
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
375 OCTAVE_DISABLE_COPY_MOVE (zipper) |
23098 | 376 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
377 ~zipper () |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
378 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
379 if (m_strm) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
380 deflateEnd (m_strm); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
381 delete m_strm; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
382 } |
23098 | 383 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
384 void deflate () |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
385 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
386 // int deflateInit2 (z_streamp m_strm, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
387 // int level, // compression level (default is 8) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
388 // int method, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
389 // int windowBits, // 15 (default) + 16 (gzip format) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
390 // int memLevel, // memory usage (default is 8) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
391 // int strategy); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
392 int status = deflateInit2 (m_strm, 8, Z_DEFLATED, 31, 8, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
393 Z_DEFAULT_STRATEGY); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
394 if (status != Z_OK) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
395 throw std::runtime_error ("failed to open zlib stream"); |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
396 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
397 deflateSetHeader (m_strm, &m_header); |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
398 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
399 const std::size_t buf_len = 8192; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
400 unsigned char buf_in[buf_len]; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
401 unsigned char buf_out[buf_len]; |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
402 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
403 int flush; |
22922
426325aa8ee9
Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
404 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
405 do |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
406 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
407 m_strm->avail_in = std::fread (buf_in, sizeof (buf_in[0]), |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
408 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
|
409 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
410 if (std::ferror (m_source.m_fp)) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
411 throw std::runtime_error ("failed to read source file"); |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
412 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
413 m_strm->next_in = buf_in; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
414 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
|
415 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
416 // If deflate returns Z_OK and with zero avail_out, it must be |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
417 // called again after making room in the output buffer because |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
418 // there might be more output pending. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
419 do |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
420 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
421 m_strm->avail_out = buf_len; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
422 m_strm->next_out = buf_out; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
423 status = ::deflate (m_strm, flush); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
424 if (status == Z_STREAM_ERROR) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
425 throw std::runtime_error ("failed to deflate"); |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
426 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
427 std::fwrite (buf_out, sizeof (buf_out[0]), |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
428 buf_len - m_strm->avail_out, m_dest.m_fp); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
429 if (std::ferror (m_dest.m_fp)) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
430 throw std::runtime_error ("failed to write file"); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
431 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
432 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
|
433 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
434 if (m_strm->avail_in != 0) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
435 throw std::runtime_error ("failed to write file"); |
22922
426325aa8ee9
Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
436 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
437 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
438 while (flush != Z_FINISH); |
22922
426325aa8ee9
Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
439 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
440 if (status != Z_STREAM_END) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
441 throw std::runtime_error ("failed to write file"); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
442 } |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
443 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
444 void close () |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
445 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
446 if (deflateEnd (m_strm) != Z_OK) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
447 throw std::runtime_error ("failed to close zlib stream"); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
448 m_strm = nullptr; |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
449 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
450 // We have no error handling for failing to close source, let |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
451 // the destructor close it. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
452 m_dest.close (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
453 } |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
454 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
455 private: |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
456 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
457 CFile m_source; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
458 CFile m_dest; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
459 gzip_header m_header; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
460 z_stream *m_strm; |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
461 }; |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
462 }; |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
463 |
22188 | 464 #endif |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
465 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
466 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
467 template<typename X> |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
468 string_vector |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
469 xzip (const Array<std::string>& source_patterns, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
470 const std::function<std::string(const std::string&)>& mk_dest_path) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
471 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
472 std::list<std::string> dest_paths; |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
473 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
474 std::function<void(const std::string&)> walk; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
475 walk = [&walk, &mk_dest_path, &dest_paths] (const std::string& path) -> void |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
476 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
477 const sys::file_stat fs (path); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
478 // is_dir and is_reg will return false if failed to stat. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
479 if (fs.is_dir ()) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
480 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
481 string_vector dirlist; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
482 std::string msg; |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25103
diff
changeset
|
483 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
484 // Collect the whole list of filenames first, before recursion |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
485 // to avoid issues with infinite loop if the action generates |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
486 // files in the same directory (highly likely). |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
487 if (sys::get_dirlist (path, dirlist, msg)) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
488 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
489 for (octave_idx_type i = 0; i < dirlist.numel (); i++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
490 if (dirlist(i) != "." && dirlist(i) != "..") |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
491 walk (sys::file_ops::concat (path, dirlist(i))); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
492 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
493 // Note that we skip any problem with directories. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
494 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
495 else if (fs.is_reg ()) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
496 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
497 const std::string dest_path = mk_dest_path (path); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
498 try |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
499 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
500 X::zip (path, dest_path); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
501 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
502 catch (const interrupt_exception&) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
503 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
504 throw; // interrupts are special, just re-throw. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
505 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
506 catch (...) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
507 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
508 // Error "handling" is not including filename on the output list. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
509 // Also, remove created file which may not have been created |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
510 // in the first place. Note that it is possible for the file |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
511 // to exist before the call to X::zip and that X::zip has not |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
512 // clobber it yet, but we remove it anyway. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
513 sys::unlink (dest_path); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
514 return; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
515 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
516 dest_paths.push_front (dest_path); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
517 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
518 // Skip all other file types and errors. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
519 return; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
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 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
522 for (octave_idx_type i = 0; i < source_patterns.numel (); i++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
523 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
524 const glob_match pattern (sys::file_ops::tilde_expand (source_patterns(i))); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
525 const string_vector filepaths = pattern.glob (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
526 for (octave_idx_type j = 0; j < filepaths.numel (); j++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
527 walk (filepaths(j)); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
528 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
529 return string_vector (dest_paths); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
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 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
533 template<typename X> |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
534 string_vector |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
535 xzip (const Array<std::string>& source_patterns) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
536 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
537 const std::string ext = X::extension; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
538 const std::function<std::string(const std::string&)> mk_dest_path |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
539 = [&ext] (const std::string& source_path) -> std::string |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
540 { |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
541 return source_path + ext; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
542 }; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
543 return xzip<X> (source_patterns, mk_dest_path); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
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 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
546 template<typename X> |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
547 string_vector |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
548 xzip (const Array<std::string>& source_patterns, const std::string& out_dir) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
549 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
550 const std::string ext = X::extension; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
551 const std::function<std::string(const std::string&)> mk_dest_path |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
552 = [&out_dir, &ext] (const std::string& source_path) -> std::string |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
553 { |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
554 // Strip any relative path (bug #58547) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
555 std::size_t pos = source_path.find_last_of (sys::file_ops::dir_sep_str ()); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
556 const std::string basename = |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
557 (pos == std::string::npos ? source_path : source_path.substr (pos+1)); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
558 return sys::file_ops::concat (out_dir, basename + ext); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
559 }; |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
560 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
561 // We don't care if mkdir fails. Maybe it failed because it already |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
562 // exists, or maybe it can't be created. If the first, then there's |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
563 // nothing to do, if the later, then it will be handled later. Any |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
564 // is to be handled by not listing files in the output. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
565 sys::mkdir (out_dir, 0777); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
566 return xzip<X> (source_patterns, mk_dest_path); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
567 } |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
568 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
569 template<typename X> |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
570 static octave_value_list |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
571 xzip (const std::string& fcn_name, const octave_value_list& args) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
572 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
573 const octave_idx_type nargin = args.length (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
574 if (nargin < 1 || nargin > 2) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
575 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
|
576 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
577 const Array<std::string> source_patterns |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
578 = args(0).xcellstr_value ("%s: FILES must be a character array or cellstr", |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
579 fcn_name.c_str ()); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
580 if (nargin == 1) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
581 return octave_value (Cell (xzip<X> (source_patterns))); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
582 else // nargin == 2 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
583 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
584 const std::string out_dir = args(1).string_value (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
585 return octave_value (Cell (xzip<X> (source_patterns, out_dir))); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
586 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
587 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29720
diff
changeset
|
588 |
30111
4eddc4cba4e9
omit output from gzip or bzip2 if nargout is zero
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
589 DEFUN_DLD (gzip, args, nargout, |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
590 doc: /* -*- texinfo -*- |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
591 @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
|
592 @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
|
593 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
|
594 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
595 @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
|
596 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
|
597 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
|
598 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
|
599 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
|
600 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
|
601 directory. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
602 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
603 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
|
604 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
|
605 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
|
606 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
|
607 same name. |
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 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
|
610 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
611 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
|
612 @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
|
613 @end deftypefn */) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
614 { |
22265
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
615 #if defined (HAVE_Z) |
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
616 |
30111
4eddc4cba4e9
omit output from gzip or bzip2 if nargout is zero
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
617 octave_value_list retval = xzip<gz> ("gzip", args); |
4eddc4cba4e9
omit output from gzip or bzip2 if nargout is zero
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
618 |
4eddc4cba4e9
omit output from gzip or bzip2 if nargout is zero
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
619 return (nargout > 0 ? retval : octave_value_list ()); |
22265
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
620 |
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
621 #else |
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
622 |
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
623 octave_unused_parameter (args); |
30182
ec834eea1b82
gzip.cc: Silence unused parameter warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents:
30113
diff
changeset
|
624 octave_unused_parameter (nargout); |
22265
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
625 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
626 err_disabled_feature ("gzip", "gzip"); |
22265
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
627 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
628 #endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
629 } |
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 %!error gzip () |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
633 %!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
|
634 %!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
|
635 */ |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
636 |
30111
4eddc4cba4e9
omit output from gzip or bzip2 if nargout is zero
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
637 DEFUN_DLD (bzip2, args, nargout, |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
638 doc: /* -*- texinfo -*- |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
639 @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
|
640 @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
|
641 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
|
642 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
643 @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
|
644 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
|
645 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
|
646 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
|
647 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
|
648 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
649 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
|
650 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
|
651 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
|
652 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
|
653 same name. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
654 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
655 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
|
656 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
657 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
|
658 @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
|
659 @end deftypefn */) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
660 { |
22265
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
661 #if defined (HAVE_BZ2) |
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
662 |
30111
4eddc4cba4e9
omit output from gzip or bzip2 if nargout is zero
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
663 octave_value_list retval = xzip<bz2> ("bzip2", args); |
4eddc4cba4e9
omit output from gzip or bzip2 if nargout is zero
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
664 |
4eddc4cba4e9
omit output from gzip or bzip2 if nargout is zero
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
665 return (nargout > 0 ? retval : octave_value_list ()); |
22265
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
666 |
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
667 #else |
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
668 |
22269
a76b931d2c4b
* xzip.cc (Fbzip2): Fix typo of "octave_unused_parameter".
Mike Miller <mtmiller@octave.org>
parents:
22265
diff
changeset
|
669 octave_unused_parameter (args); |
30182
ec834eea1b82
gzip.cc: Silence unused parameter warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents:
30113
diff
changeset
|
670 octave_unused_parameter (nargout); |
22265
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
671 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
672 err_disabled_feature ("bzip2", "bzip2"); |
22265
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
673 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
674 #endif |
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 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
677 // 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
|
678 /* |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
679 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
680 ## 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
|
681 ## 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
|
682 ## 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
|
683 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
684 %!function run_test_function (test_function) |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
685 %! 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
|
686 %! if (__octave_config_info__ ().build_features.BZ2) |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
687 %! enabled_zippers(end+1).zip = @bzip2; |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
688 %! enabled_zippers(end).unzip = @bunzip2; |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
689 %! 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
|
690 %! endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
691 %! if (__octave_config_info__ ().build_features.Z) |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
692 %! enabled_zippers(end+1).zip = @gzip; |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
693 %! enabled_zippers(end).unzip = @gunzip; |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
694 %! 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
|
695 %! endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
696 %! |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
697 %! 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
|
698 %! 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
|
699 %! 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
|
700 %! 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
|
701 %! endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
702 %! unwind_protect |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
703 %! 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
|
704 %! 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
|
705 %! confirm_recursive_rmdir (false, "local"); |
28087
9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27957
diff
changeset
|
706 %! sts = rmdir (test_dir, "s"); |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
707 %! 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
|
708 %! endfor |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
709 %!endfunction |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
710 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
711 %!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
|
712 %! 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
|
713 %! 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
|
714 %! 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
|
715 %! endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
716 %! 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
|
717 %! 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
|
718 %! endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
719 %! 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
|
720 %! 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
|
721 %! endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
722 %!endfunction |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
723 |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
724 %!function unlink_or_error (filepath) |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
725 %! [err, msg] = unlink (filepath); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
726 %! if (err) |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
727 %! 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
|
728 %! endif |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
729 %!endfunction |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
730 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
731 ## 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
|
732 %!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
|
733 %! 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
|
734 %! 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
|
735 %! 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
|
736 %! |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
737 %! z_file = [test_file z.ext]; |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
738 %! z_filelist = z.zip (test_file); |
29720
e1139b820c95
gzip.cc: Use is_same_file in BISTs to assert that files are the same.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29655
diff
changeset
|
739 %! assert (is_same_file (z_filelist, {z_file})) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
740 %! |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
741 %! unlink_or_error (test_file); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
742 %! uz_filelist = z.unzip (z_file); |
29720
e1139b820c95
gzip.cc: Use is_same_file in BISTs to assert that files are the same.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29655
diff
changeset
|
743 %! assert (is_same_file (uz_filelist, {test_file})) |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
744 %! |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
745 %! 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
|
746 %!endfunction |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
747 %!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
|
748 |
30113 | 749 ## Test that xzipped files are rexzipped (hits bug #43206, #48598) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
750 %!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
|
751 %! 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
|
752 %! 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
|
753 %! 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
|
754 %! |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
755 %! z_file = [ori_file z.ext]; |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
756 %! z_filelist = z.zip (ori_file); |
29720
e1139b820c95
gzip.cc: Use is_same_file in BISTs to assert that files are the same.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29655
diff
changeset
|
757 %! assert (is_same_file (z_filelist, {z_file})) # check output |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
758 %! 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
|
759 %! 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
|
760 %! |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
761 %! unlink_or_error (ori_file); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
762 %! uz_filelist = z.unzip (z_file); |
29720
e1139b820c95
gzip.cc: Use is_same_file in BISTs to assert that files are the same.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29655
diff
changeset
|
763 %! assert (is_same_file (uz_filelist, {ori_file})) # bug #48598 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
764 %! 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
|
765 %! 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
|
766 %! |
30113 | 767 %! ## xzip should preserve original files. |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
768 %! z_z_file = [z_file z.ext]; |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
769 %! z_z_filelist = z.zip (z_file); |
29720
e1139b820c95
gzip.cc: Use is_same_file in BISTs to assert that files are the same.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29655
diff
changeset
|
770 %! assert (is_same_file (z_z_filelist, {z_z_file})) # check output |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
771 %! 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
|
772 %! 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
|
773 %! |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
774 %! md5_z = hash ("md5", fileread (z_file)); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
775 %! unlink_or_error (z_file); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
776 %! uz_z_filelist = z.unzip (z_z_file); |
29720
e1139b820c95
gzip.cc: Use is_same_file in BISTs to assert that files are the same.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29655
diff
changeset
|
777 %! assert (is_same_file (uz_z_filelist, {z_file})) # bug #48598 |
30113 | 778 %! assert (exist (z_z_file), 2) # bug #43206 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
779 %! 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
|
780 %!endfunction |
30113 | 781 %!test <43206> run_test_function (@test_z_z) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
782 |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
783 %!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
|
784 %! 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
|
785 %! md5s = cell (1, 3); |
28915
c40a367a84c0
maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents:
28888
diff
changeset
|
786 %! for idx = 1:numel (fpaths) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
787 %! 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
|
788 %! 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
|
789 %! endfor |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
790 %! |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
791 %! test_dir = [test_dir filesep()]; |
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 %! z_files = strcat (fpaths, z.ext); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
794 %! z_filelist = z.zip (test_dir); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
795 %! assert (sort (z_filelist), z_files(:)) |
28915
c40a367a84c0
maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents:
28888
diff
changeset
|
796 %! for idx = 1:numel (fpaths) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
797 %! assert (exist (z_files{idx}), 2) |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
798 %! 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
|
799 %! endfor |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
800 %! |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
801 %! ## only gunzip handles directory (bunzip2 should too though) |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
802 %! if (z.unzip == @gunzip) |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
803 %! uz_filelist = z.unzip (test_dir); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
804 %! else |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
805 %! uz_filelist = cell (1, numel (z_filelist)); |
28915
c40a367a84c0
maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents:
28888
diff
changeset
|
806 %! for idx = 1:numel (z_filelist) |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
807 %! uz_filelist(idx) = z.unzip (z_filelist{idx}); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
808 %! endfor |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
809 %! endif |
30113 | 810 %! uz_filelist = sort (uz_filelist); |
811 %! fpaths = sort (fpaths); | |
812 %! assert (is_same_file (uz_filelist(:), fpaths(:))) # bug #48598 | |
28915
c40a367a84c0
maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents:
28888
diff
changeset
|
813 %! for idx = 1:numel (fpaths) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
814 %! 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
|
815 %! endfor |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
816 %!endfunction |
23691
2fa6013799fa
* gzip.cc: Tag %!xtest with bug number.
John W. Eaton <jwe@octave.org>
parents:
23591
diff
changeset
|
817 %!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
|
818 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
819 %!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
|
820 %! 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
|
821 %! 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
|
822 %! 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
|
823 %! 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
|
824 %! |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
825 %! ## 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
|
826 %! 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
|
827 %! 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
|
828 %! 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
|
829 %! endif |
22365
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
830 %! unwind_protect |
28915
c40a367a84c0
maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents:
28888
diff
changeset
|
831 %! for idx = 1:numel (out_dirs) |
22365
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
832 %! out_dir = out_dirs{idx}; |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
833 %! uz_file = fullfile (out_dir, filename); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
834 %! z_file = [uz_file z.ext]; |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
835 %! |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
836 %! 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
|
837 %! assert (z_filelist, {z_file}) |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
838 %! assert (exist (z_file, "file"), 2) |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
839 %! |
22365
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
840 %! uz_filelist = z.unzip (z_file); |
29720
e1139b820c95
gzip.cc: Use is_same_file in BISTs to assert that files are the same.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29655
diff
changeset
|
841 %! assert (is_same_file (uz_filelist, {uz_file})) # bug #48598 |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
842 %! |
22365
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
843 %! 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
|
844 %! endfor |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
845 %! unwind_protect_cleanup |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
846 %! confirm_recursive_rmdir (false, "local"); |
28915
c40a367a84c0
maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents:
28888
diff
changeset
|
847 %! for idx = 1:numel (out_dirs) |
28087
9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27957
diff
changeset
|
848 %! sts = rmdir (out_dirs{idx}, "s"); |
22365
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
849 %! endfor |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
850 %! 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
|
851 %!endfunction |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
852 %!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
|
853 */ |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29720
diff
changeset
|
854 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30896
diff
changeset
|
855 OCTAVE_END_NAMESPACE(octave) |