Mercurial > octave
annotate libinterp/corefcn/gzfstream.cc @ 31706:597f3ee61a48 stable
update Octave Project Developers copyright for the new year
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 06 Jan 2023 13:11:27 -0500 |
parents | 796f54d4ddbf |
children | 2e484f9f1f18 |
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 // |
31706
597f3ee61a48
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
3 // Copyright (C) 2005-2023 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 //////////////////////////////////////////////////////////////////////// |
5269 | 25 |
26 /* | |
27 | |
28 This file is adapted from the zlib 1.2.2 contrib/iostream3 code, | |
29 written by | |
30 | |
31 Ludwig Schwardt <schwardt@sun.ac.za> | |
32 original version by Kevin Ruland <kevin@rodin.wustl.edu> | |
33 | |
34 */ | |
35 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
36 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
37 # include "config.h" |
8025
60e938e1459b
zfstream.cc: include <config.h>
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
38 #endif |
60e938e1459b
zfstream.cc: include <config.h>
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
39 |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
40 #include <iomanip> |
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
41 #include <istream> |
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
42 #include <ostream> |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
43 |
30118
d809b99f1280
maint: rename "zfstream.[h|cc]" to "gzfstream.[h|cc]" to match class name.
Rik <rik@octave.org>
parents:
30117
diff
changeset
|
44 #include "gzfstream.h" |
5269 | 45 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
46 #if defined (HAVE_ZLIB) |
5269 | 47 |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
48 // For strcpy, strcat, strlen (mode strings). |
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
49 #include <cstring> |
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
50 // For BUFSIZ. |
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
51 #include <cstdio> |
5269 | 52 |
53 // Internal buffer sizes (default and "unbuffered" versions) | |
6783 | 54 #define STASHED_CHARACTERS 16 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
55 #define BIGBUFSIZE (256 * 1024 + STASHED_CHARACTERS) |
5269 | 56 #define SMALLBUFSIZE 1 |
57 | |
58 // Default constructor | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
59 gzfilebuf::gzfilebuf () |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
60 : m_file(nullptr), m_io_mode(std::ios_base::openmode(0)), m_own_fd(false), |
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
61 m_buffer(nullptr), m_buffer_size(BIGBUFSIZE), m_own_buffer(true) |
5269 | 62 { |
63 // No buffers to start with | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
64 this->disable_buffer (); |
5269 | 65 } |
66 | |
67 // Destructor | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
68 gzfilebuf::~gzfilebuf () |
5269 | 69 { |
70 // Sync output buffer and close only if responsible for file | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
71 // (i.e., attached streams should be left open at this stage) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
72 this->sync (); |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
73 if (m_own_fd) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
74 this->close (); |
5269 | 75 // Make sure internal buffer is deallocated |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
76 this->disable_buffer (); |
5269 | 77 } |
78 | |
79 // Set compression level and strategy | |
80 int | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
81 gzfilebuf::setcompression (int comp_level, int comp_strategy) |
5269 | 82 { |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
83 return gzsetparams (m_file, comp_level, comp_strategy); |
5269 | 84 } |
85 | |
86 // Open gzipped file | |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30163
diff
changeset
|
87 gzfilebuf * |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
88 gzfilebuf::open (const char *name, std::ios_base::openmode mode) |
5269 | 89 { |
90 // Fail if file already open | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
91 if (this->is_open ()) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
92 return nullptr; |
5269 | 93 // Don't support simultaneous read/write access (yet) |
94 if ((mode & std::ios_base::in) && (mode & std::ios_base::out)) | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
95 return nullptr; |
5269 | 96 |
97 // Build mode string for gzopen and check it [27.8.1.3.2] | |
98 char char_mode[6] = "\0\0\0\0\0"; | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
99 if (! this->open_mode (mode, char_mode)) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
100 return nullptr; |
5269 | 101 |
102 // Attempt to open file | |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
103 if ((m_file = gzopen (name, char_mode)) == nullptr) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
104 return nullptr; |
5269 | 105 |
106 // On success, allocate internal buffer and set flags | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
107 this->enable_buffer (); |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
108 m_io_mode = mode; |
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
109 m_own_fd = true; |
5269 | 110 return this; |
111 } | |
112 | |
113 // Attach to gzipped file | |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30163
diff
changeset
|
114 gzfilebuf * |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
115 gzfilebuf::attach (int fd, std::ios_base::openmode mode) |
5269 | 116 { |
117 // Fail if file already open | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
118 if (this->is_open ()) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
119 return nullptr; |
5269 | 120 // Don't support simultaneous read/write access (yet) |
121 if ((mode & std::ios_base::in) && (mode & std::ios_base::out)) | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
122 return nullptr; |
5269 | 123 |
124 // Build mode string for gzdopen and check it [27.8.1.3.2] | |
125 char char_mode[6] = "\0\0\0\0\0"; | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
126 if (! this->open_mode (mode, char_mode)) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
127 return nullptr; |
5269 | 128 |
129 // Attempt to attach to file | |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
130 if ((m_file = gzdopen (fd, char_mode)) == nullptr) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
131 return nullptr; |
5269 | 132 |
133 // On success, allocate internal buffer and set flags | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
134 this->enable_buffer (); |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
135 m_io_mode = mode; |
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
136 m_own_fd = false; |
5269 | 137 return this; |
138 } | |
139 | |
140 // Close gzipped file | |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30163
diff
changeset
|
141 gzfilebuf * |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
142 gzfilebuf::close () |
5269 | 143 { |
144 // Fail immediately if no file is open | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
145 if (! this->is_open ()) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
146 return nullptr; |
5269 | 147 // Assume success |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
148 gzfilebuf *retval = this; |
5269 | 149 // Attempt to sync and close gzipped file |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
150 if (this->sync () == -1) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
151 retval = nullptr; |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
152 if (gzclose (m_file) < 0) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
153 retval = nullptr; |
5269 | 154 // File is now gone anyway (postcondition [27.8.1.3.8]) |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
155 m_file = nullptr; |
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
156 m_own_fd = false; |
5269 | 157 // Destroy internal buffer if it exists |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
158 this->disable_buffer (); |
5269 | 159 return retval; |
160 } | |
161 | |
162 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
163 | |
164 // Convert int open mode to mode string | |
165 bool | |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
166 gzfilebuf::open_mode (std::ios_base::openmode mode, char *c_mode) const |
5269 | 167 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
168 // FIXME: do we need testb? |
6959 | 169 // bool testb = mode & std::ios_base::binary; |
5269 | 170 bool testi = mode & std::ios_base::in; |
171 bool testo = mode & std::ios_base::out; | |
172 bool testt = mode & std::ios_base::trunc; | |
173 bool testa = mode & std::ios_base::app; | |
174 | |
175 // Check for valid flag combinations - see [27.8.1.3.2] (Table 92) | |
176 // Original zfstream hardcoded the compression level to maximum here... | |
177 // Double the time for less than 1% size improvement seems | |
178 // excessive though - keeping it at the default level | |
179 // To change back, just append "9" to the next three mode strings | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
180 if (! testi && testo && ! testt && ! testa) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
181 strcpy (c_mode, "w"); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
182 if (! testi && testo && ! testt && testa) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
183 strcpy (c_mode, "a"); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
184 if (! testi && testo && testt && ! testa) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
185 strcpy (c_mode, "w"); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
186 if (testi && ! testo && ! testt && ! testa) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
187 strcpy (c_mode, "r"); |
5269 | 188 // No read/write mode yet |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
189 // if (testi && testo && ! testt && ! testa) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
190 // strcpy(c_mode, "r+"); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
191 // if (testi && testo && testt && ! testa) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
192 // strcpy(c_mode, "w+"); |
5269 | 193 |
194 // Mode string should be empty for invalid combination of flags | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
195 if (strlen (c_mode) == 0) |
5269 | 196 return false; |
6275 | 197 |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
198 strcat (c_mode, "b"); |
6275 | 199 |
5269 | 200 return true; |
201 } | |
202 | |
203 // Determine number of characters in internal get buffer | |
204 std::streamsize | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
205 gzfilebuf::showmanyc () |
5269 | 206 { |
207 // Calls to underflow will fail if file not opened for reading | |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
208 if (! this->is_open () || ! (m_io_mode & std::ios_base::in)) |
5269 | 209 return -1; |
210 // Make sure get area is in use | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
211 if (this->gptr () && (this->gptr () < this->egptr ())) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
212 return std::streamsize (this->egptr () - this->gptr ()); |
5269 | 213 else |
214 return 0; | |
215 } | |
216 | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
217 // Puts back a character to the stream in two cases. Firstly, when there |
6777 | 218 // is no putback position available, and secondly when the character putback |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
219 // differs from the one in the file. We can only support the first case |
6777 | 220 // with gzipped files. |
221 gzfilebuf::int_type | |
222 gzfilebuf::pbackfail (gzfilebuf::int_type c) | |
223 { | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
224 if (this->is_open ()) |
6777 | 225 { |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
226 if (gzseek (m_file, this->gptr () - this->egptr () - 1, SEEK_CUR) < 0) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
227 return traits_type::eof (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
228 |
6777 | 229 // Invalidates contents of the buffer |
230 enable_buffer (); | |
231 | |
232 // Attempt to fill internal buffer from gzipped file | |
233 // (buffer must be guaranteed to exist...) | |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
234 int bytes_read = gzread (m_file, m_buffer, m_buffer_size); |
6777 | 235 // Indicates error or EOF |
236 if (bytes_read <= 0) | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
237 { |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
238 // Reset get area |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
239 this->setg (m_buffer, m_buffer, m_buffer); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
240 return traits_type::eof (); |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
241 } |
6777 | 242 |
243 // Make all bytes read from file available as get area | |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
244 this->setg (m_buffer, m_buffer, m_buffer + bytes_read); |
6777 | 245 |
246 // If next character in get area differs from putback character | |
247 // flag a failure | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
248 gzfilebuf::int_type ret = traits_type::to_int_type (*(this->gptr ())); |
6777 | 249 if (ret != c) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
250 return traits_type::eof (); |
6777 | 251 else |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
252 return ret; |
6777 | 253 } |
254 else | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
255 return traits_type::eof (); |
6777 | 256 } |
257 | |
5269 | 258 // Fill get area from gzipped file |
259 gzfilebuf::int_type | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
260 gzfilebuf::underflow () |
5269 | 261 { |
262 // If something is left in the get area by chance, return it | |
263 // (this shouldn't normally happen, as underflow is only supposed | |
264 // to be called when gptr >= egptr, but it serves as error check) | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
265 if (this->gptr () && (this->gptr () < this->egptr ())) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
266 return traits_type::to_int_type (*(this->gptr ())); |
5269 | 267 |
268 // If the file hasn't been opened for reading, produce error | |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
269 if (! this->is_open () || ! (m_io_mode & std::ios_base::in)) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
270 return traits_type::eof (); |
5269 | 271 |
6783 | 272 // Copy the final characters to the front of the buffer |
273 int stash = 0; | |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
274 if (this->eback () && m_buffer && m_buffer_size > STASHED_CHARACTERS) |
6783 | 275 { |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
276 char_type *ptr1 = m_buffer; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
277 char_type *ptr2 = this->egptr () - STASHED_CHARACTERS + 1; |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
278 if (ptr2 > this->eback ()) |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
279 while (stash++ <= STASHED_CHARACTERS) |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
280 *ptr1++ = *ptr2++; |
6783 | 281 } |
282 | |
5269 | 283 // Attempt to fill internal buffer from gzipped file |
284 // (buffer must be guaranteed to exist...) | |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
285 int bytes_read = gzread (m_file, m_buffer + stash, m_buffer_size - stash); |
6783 | 286 |
5269 | 287 // Indicates error or EOF |
288 if (bytes_read <= 0) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
289 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
290 // Reset get area |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
291 this->setg (m_buffer, m_buffer, m_buffer); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
292 return traits_type::eof (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
293 } |
6783 | 294 // Make all bytes read from file plus the stash available as get area |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
295 this->setg (m_buffer, m_buffer + stash, m_buffer + bytes_read + stash); |
5269 | 296 |
297 // Return next character in get area | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
298 return traits_type::to_int_type (*(this->gptr ())); |
5269 | 299 } |
300 | |
301 // Write put area to gzipped file | |
302 gzfilebuf::int_type | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
303 gzfilebuf::overflow (int_type c) |
5269 | 304 { |
305 // Determine whether put area is in use | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
306 if (this->pbase ()) |
5269 | 307 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
308 // Double-check pointer range |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
309 if (this->pptr () > this->epptr () || this->pptr () < this->pbase ()) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
310 return traits_type::eof (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
311 // Add extra character to buffer if not EOF |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
312 if (! traits_type::eq_int_type (c, traits_type::eof ())) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
313 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
314 *(this->pptr ()) = traits_type::to_char_type (c); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
315 this->pbump (1); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
316 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
317 // Number of characters to write to file |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
318 int bytes_to_write = this->pptr () - this->pbase (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
319 // Overflow doesn't fail if nothing is to be written |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
320 if (bytes_to_write > 0) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
321 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
322 // If the file hasn't been opened for writing, produce error |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
323 if (! this->is_open () || ! (m_io_mode & std::ios_base::out)) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
324 return traits_type::eof (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
325 // If gzipped file won't accept all bytes written to it, fail |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
326 if (gzwrite (m_file, this->pbase (), bytes_to_write) |
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
327 != bytes_to_write) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
328 return traits_type::eof (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
329 // Reset next pointer to point to pbase on success |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
330 this->pbump (-bytes_to_write); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
331 } |
5269 | 332 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
333 // Write extra character to file if not EOF |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
334 else if (! traits_type::eq_int_type (c, traits_type::eof ())) |
5269 | 335 { |
336 // If the file hasn't been opened for writing, produce error | |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
337 if (! this->is_open () || ! (m_io_mode & std::ios_base::out)) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
338 return traits_type::eof (); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
339 // Impromptu char buffer (allows "unbuffered" output) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
340 char_type last_char = traits_type::to_char_type (c); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
341 // If gzipped file won't accept this character, fail |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
342 if (gzwrite (m_file, &last_char, 1) != 1) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
343 return traits_type::eof (); |
5269 | 344 } |
345 | |
346 // If you got here, you have succeeded (even if c was EOF) | |
347 // The return value should therefore be non-EOF | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
348 if (traits_type::eq_int_type (c, traits_type::eof ())) |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
349 return traits_type::not_eof (c); |
5269 | 350 else |
351 return c; | |
352 } | |
353 | |
354 // Assign new buffer | |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30163
diff
changeset
|
355 std::streambuf * |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
356 gzfilebuf::setbuf (char_type *p, std::streamsize n) |
5269 | 357 { |
358 // First make sure stuff is sync'ed, for safety | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
359 if (this->sync () == -1) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
360 return nullptr; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
361 // If buffering is turned off on purpose via setbuf(0,0), still allocate one. |
5269 | 362 // "Unbuffered" only really refers to put [27.8.1.4.10], while get needs at |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
363 // least a buffer of size 1 (very inefficient though, therefore make it |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
364 // bigger?). This follows from [27.5.2.4.3]/12 (gptr needs to point at |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
365 // something, it seems). |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
366 if (! p || ! n) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
367 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
368 // Replace existing buffer (if any) with small internal buffer |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
369 this->disable_buffer (); |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
370 m_buffer = nullptr; |
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
371 m_buffer_size = 0; |
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
372 m_own_buffer = true; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
373 this->enable_buffer (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
374 } |
5269 | 375 else |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
376 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
377 // Replace existing buffer (if any) with external buffer |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
378 this->disable_buffer (); |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
379 m_buffer = p; |
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
380 m_buffer_size = n; |
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
381 m_own_buffer = false; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
382 this->enable_buffer (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
383 } |
5269 | 384 return this; |
385 } | |
386 | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
387 // Write put area to gzipped file (i.e., ensures that put area is empty) |
5269 | 388 int |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
389 gzfilebuf::sync () |
5269 | 390 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
391 return traits_type::eq_int_type (this->overflow (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
392 traits_type::eof ()) ? -1 : 0; |
5269 | 393 } |
394 | |
395 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
396 | |
397 // Allocate internal buffer | |
398 void | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
399 gzfilebuf::enable_buffer () |
5269 | 400 { |
401 // If internal buffer required, allocate one | |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
402 if (m_own_buffer && ! m_buffer) |
5269 | 403 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
404 // Check for buffered vs. "unbuffered" |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
405 if (m_buffer_size > 0) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
406 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
407 // Allocate internal buffer |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
408 m_buffer = new char_type [m_buffer_size]; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
409 // Get area starts empty and will be expanded by underflow as needed |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
410 this->setg (m_buffer, m_buffer, m_buffer); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
411 // Setup entire internal buffer as put area. |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
412 // The one-past-end pointer actually points to the last element of |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
413 // the buffer, so that overflow(c) can safely add the extra character |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
414 // c to the sequence. These pointers remain in place for the |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
415 // duration of the buffer |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
416 this->setp (m_buffer, m_buffer + m_buffer_size - 1); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
417 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
418 else |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
419 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
420 // Even in "unbuffered" case, (small?) get buffer is still required |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
421 m_buffer_size = SMALLBUFSIZE; |
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
422 m_buffer = new char_type [m_buffer_size]; |
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
423 this->setg (m_buffer, m_buffer, m_buffer); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
424 // "Unbuffered" means no put buffer |
23796
4f12819a634f
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
425 this->setp (nullptr, nullptr); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
426 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
427 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
428 else |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
429 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
430 // If buffer already allocated, reset buffer pointers just to make sure no |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
431 // stale chars are lying around |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
432 this->setg (m_buffer, m_buffer, m_buffer); |
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
433 this->setp (m_buffer, m_buffer + m_buffer_size - 1); |
5269 | 434 } |
435 } | |
436 | |
437 // Destroy internal buffer | |
438 void | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
439 gzfilebuf::disable_buffer () |
5269 | 440 { |
441 // If internal buffer exists, deallocate it | |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
442 if (m_own_buffer && m_buffer) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
443 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
444 // Preserve unbuffered status by zeroing size |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
445 if (! this->pbase ()) |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
446 m_buffer_size = 0; |
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
447 delete [] m_buffer; |
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
448 m_buffer = nullptr; |
23796
4f12819a634f
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
449 this->setg (nullptr, nullptr, nullptr); |
4f12819a634f
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
450 this->setp (nullptr, nullptr); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
451 } |
5269 | 452 else |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
453 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
454 // Reset buffer pointers to initial state if external buffer exists |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
455 this->setg (m_buffer, m_buffer, m_buffer); |
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
456 if (m_buffer) |
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
457 this->setp (m_buffer, m_buffer + m_buffer_size - 1); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
458 else |
23796
4f12819a634f
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
459 this->setp (nullptr, nullptr); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
460 } |
5269 | 461 } |
462 | |
463 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
464 | |
465 // Seek functions | |
466 gzfilebuf::pos_type | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
467 gzfilebuf::seekoff (off_type off, std::ios_base::seekdir way, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
468 std::ios_base::openmode) |
5269 | 469 { |
470 pos_type ret = pos_type (off_type (-1)); | |
471 | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
472 if (this->is_open ()) |
5269 | 473 { |
474 off_type computed_off = off; | |
475 | |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
476 if ((m_io_mode & std::ios_base::in) && way == std::ios_base::cur) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
477 computed_off += this->gptr () - this->egptr (); |
5269 | 478 |
15510
c1c5b3cc2996
Avoid inefficient seeks in gzfilebuf (bug #37509)
Mike Miller <mtmiller@ieee.org>
parents:
14138
diff
changeset
|
479 // Handle tellg/tellp as a special case up front, no need to seek |
c1c5b3cc2996
Avoid inefficient seeks in gzfilebuf (bug #37509)
Mike Miller <mtmiller@ieee.org>
parents:
14138
diff
changeset
|
480 // or invalidate get/put buffers |
c1c5b3cc2996
Avoid inefficient seeks in gzfilebuf (bug #37509)
Mike Miller <mtmiller@ieee.org>
parents:
14138
diff
changeset
|
481 if (off == 0 && way == std::ios_base::cur) |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
482 return pos_type (gztell (m_file) + computed_off); |
15510
c1c5b3cc2996
Avoid inefficient seeks in gzfilebuf (bug #37509)
Mike Miller <mtmiller@ieee.org>
parents:
14138
diff
changeset
|
483 |
5269 | 484 if (way == std::ios_base::beg) |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
485 ret = pos_type (gzseek (m_file, computed_off, SEEK_SET)); |
5269 | 486 else if (way == std::ios_base::cur) |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
487 ret = pos_type (gzseek (m_file, computed_off, SEEK_CUR)); |
5269 | 488 else |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
489 // Can't seek from end of a gzipped file, so this will give -1 |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
490 ret = pos_type (gzseek (m_file, computed_off, SEEK_END)); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
491 |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
492 if (m_io_mode & std::ios_base::in) |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
493 // Invalidates contents of the buffer |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
494 enable_buffer (); |
5269 | 495 else |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
496 // flush contents of buffer to file |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
497 overflow (); |
5269 | 498 } |
499 | |
500 return ret; | |
501 } | |
502 | |
503 gzfilebuf::pos_type | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
504 gzfilebuf::seekpos (pos_type sp, std::ios_base::openmode) |
5269 | 505 { |
506 pos_type ret = pos_type (off_type (-1)); | |
507 | |
508 if (this->is_open ()) | |
509 { | |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
510 ret = pos_type (gzseek (m_file, sp, SEEK_SET)); |
5269 | 511 |
30117
a7813409b8c6
maint: use "m_" prefix for member variables in class gzfilebuf.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
512 if (m_io_mode & std::ios_base::in) |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
513 // Invalidates contents of the buffer |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
514 enable_buffer (); |
5269 | 515 else |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
516 // flush contents of buffer to file |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
517 overflow (); |
5269 | 518 } |
519 | |
520 return ret; | |
521 } | |
522 | |
523 // Default constructor initializes stream buffer | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
524 gzifstream::gzifstream () |
30163
4412f57132c4
maint: use "m_" prefix for member variables in classes gzifstream, gzofstream.
Rik <rik@octave.org>
parents:
30118
diff
changeset
|
525 : std::istream (nullptr), m_sb () |
4412f57132c4
maint: use "m_" prefix for member variables in classes gzifstream, gzofstream.
Rik <rik@octave.org>
parents:
30118
diff
changeset
|
526 { this->init (&m_sb); } |
5269 | 527 |
528 // Initialize stream buffer and open file | |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
529 gzifstream::gzifstream (const char *name, std::ios_base::openmode mode) |
30163
4412f57132c4
maint: use "m_" prefix for member variables in classes gzifstream, gzofstream.
Rik <rik@octave.org>
parents:
30118
diff
changeset
|
530 : std::istream (nullptr), m_sb () |
5269 | 531 { |
30163
4412f57132c4
maint: use "m_" prefix for member variables in classes gzifstream, gzofstream.
Rik <rik@octave.org>
parents:
30118
diff
changeset
|
532 this->init (&m_sb); |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
533 this->open (name, mode); |
5269 | 534 } |
535 | |
536 // Initialize stream buffer and attach to file | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
537 gzifstream::gzifstream (int fd, std::ios_base::openmode mode) |
30163
4412f57132c4
maint: use "m_" prefix for member variables in classes gzifstream, gzofstream.
Rik <rik@octave.org>
parents:
30118
diff
changeset
|
538 : std::istream (nullptr), m_sb () |
5269 | 539 { |
30163
4412f57132c4
maint: use "m_" prefix for member variables in classes gzifstream, gzofstream.
Rik <rik@octave.org>
parents:
30118
diff
changeset
|
540 this->init (&m_sb); |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
541 this->attach (fd, mode); |
5269 | 542 } |
543 | |
544 // Open file and go into fail() state if unsuccessful | |
545 void | |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
546 gzifstream::open (const char *name, std::ios_base::openmode mode) |
5269 | 547 { |
30163
4412f57132c4
maint: use "m_" prefix for member variables in classes gzifstream, gzofstream.
Rik <rik@octave.org>
parents:
30118
diff
changeset
|
548 if (! m_sb.open (name, mode | std::ios_base::in)) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
549 this->setstate (std::ios_base::failbit); |
5269 | 550 else |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
551 this->clear (); |
5269 | 552 } |
553 | |
554 // Attach to file and go into fail() state if unsuccessful | |
555 void | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
556 gzifstream::attach (int fd, std::ios_base::openmode mode) |
5269 | 557 { |
30163
4412f57132c4
maint: use "m_" prefix for member variables in classes gzifstream, gzofstream.
Rik <rik@octave.org>
parents:
30118
diff
changeset
|
558 if (! m_sb.attach (fd, mode | std::ios_base::in)) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
559 this->setstate (std::ios_base::failbit); |
5269 | 560 else |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
561 this->clear (); |
5269 | 562 } |
563 | |
564 // Close file | |
565 void | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
566 gzifstream::close () |
5269 | 567 { |
30163
4412f57132c4
maint: use "m_" prefix for member variables in classes gzifstream, gzofstream.
Rik <rik@octave.org>
parents:
30118
diff
changeset
|
568 if (! m_sb.close ()) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
569 this->setstate (std::ios_base::failbit); |
5269 | 570 } |
571 | |
572 // Default constructor initializes stream buffer | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
573 gzofstream::gzofstream () |
30163
4412f57132c4
maint: use "m_" prefix for member variables in classes gzifstream, gzofstream.
Rik <rik@octave.org>
parents:
30118
diff
changeset
|
574 : std::ostream (nullptr), m_sb () |
4412f57132c4
maint: use "m_" prefix for member variables in classes gzifstream, gzofstream.
Rik <rik@octave.org>
parents:
30118
diff
changeset
|
575 { this->init (&m_sb); } |
5269 | 576 |
577 // Initialize stream buffer and open file | |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
578 gzofstream::gzofstream (const char *name, std::ios_base::openmode mode) |
30163
4412f57132c4
maint: use "m_" prefix for member variables in classes gzifstream, gzofstream.
Rik <rik@octave.org>
parents:
30118
diff
changeset
|
579 : std::ostream (nullptr), m_sb () |
5269 | 580 { |
30163
4412f57132c4
maint: use "m_" prefix for member variables in classes gzifstream, gzofstream.
Rik <rik@octave.org>
parents:
30118
diff
changeset
|
581 this->init (&m_sb); |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
582 this->open (name, mode); |
5269 | 583 } |
584 | |
585 // Initialize stream buffer and attach to file | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
586 gzofstream::gzofstream (int fd, std::ios_base::openmode mode) |
30163
4412f57132c4
maint: use "m_" prefix for member variables in classes gzifstream, gzofstream.
Rik <rik@octave.org>
parents:
30118
diff
changeset
|
587 : std::ostream (nullptr), m_sb () |
5269 | 588 { |
30163
4412f57132c4
maint: use "m_" prefix for member variables in classes gzifstream, gzofstream.
Rik <rik@octave.org>
parents:
30118
diff
changeset
|
589 this->init (&m_sb); |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
590 this->attach (fd, mode); |
5269 | 591 } |
592 | |
593 // Open file and go into fail() state if unsuccessful | |
594 void | |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
595 gzofstream::open (const char *name, std::ios_base::openmode mode) |
5269 | 596 { |
30163
4412f57132c4
maint: use "m_" prefix for member variables in classes gzifstream, gzofstream.
Rik <rik@octave.org>
parents:
30118
diff
changeset
|
597 if (! m_sb.open (name, mode | std::ios_base::out)) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
598 this->setstate (std::ios_base::failbit); |
5269 | 599 else |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
600 this->clear (); |
5269 | 601 } |
602 | |
603 // Attach to file and go into fail() state if unsuccessful | |
604 void | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
605 gzofstream::attach (int fd, std::ios_base::openmode mode) |
5269 | 606 { |
30163
4412f57132c4
maint: use "m_" prefix for member variables in classes gzifstream, gzofstream.
Rik <rik@octave.org>
parents:
30118
diff
changeset
|
607 if (! m_sb.attach (fd, mode | std::ios_base::out)) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
608 this->setstate (std::ios_base::failbit); |
5269 | 609 else |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
610 this->clear (); |
5269 | 611 } |
612 | |
613 // Close file | |
614 void | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
615 gzofstream::close () |
5269 | 616 { |
30163
4412f57132c4
maint: use "m_" prefix for member variables in classes gzifstream, gzofstream.
Rik <rik@octave.org>
parents:
30118
diff
changeset
|
617 if (! m_sb.close ()) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
618 this->setstate (std::ios_base::failbit); |
5269 | 619 } |
620 | |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
621 #endif |