Debian Codegraph @

melder/abcio.cpp

raw symbols SCIP
1 /* abcio.cpp
2 *
3 * Copyright (C) 1992-2011,2015,2017-2020,2022,2024,2025 Paul Boersma
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "melder.h"cxx . . $ `<file>/melder/melder.h`/
20 #ifdef macintosh
21 #include <TargetConditionals.h>
22 #endif
23
24 /********** text I/O **********/
25
26 static int64cxx . . $ int64# getIntegercxx . . $ getInteger(c4cc05fb41712971). (MelderReadTextcxx . . $ MelderReadText# me) {
27 char buffer [41];
28 char32cxx . . $ char32# c;
29 /*
30 * Look for the first numeric character.
31 */
32 for (c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me); c != U'-' && ! Melder_isAsciiDecimalNumbercxx . . $ Melder_isAsciiDecimalNumber(b8d0204ce8416907). (c) && c != U'+'; c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me)) {
33 if (c == U'\0')
34 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected while looking for an integer (line ", MelderReadText_getLineNumber (me), U").");
35 if (c == U'!') { // end-of-line comment?
36 while ((c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me)) != U'\n' && c != U'\r') {
37 if (c == 0)
38 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected in comment while looking for an integer (line ", MelderReadText_getLineNumber (me), U").");
39 }
40 }
41 if (c == U'\"')
42 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found a string while looking for an integer in text (line ", MelderReadText_getLineNumber (me), U").");
43 if (c == U'<')
44 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found an enumerated value while looking for an integer in text (line ", MelderReadText_getLineNumber (me), U").");
45 while (! Melder_isHorizontalOrVerticalSpacecxx . . $ Melder_isHorizontalOrVerticalSpace(b8d0204ce8416907). (c)) {
46 if (c == U'\0')
47 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected in comment (line ", MelderReadText_getLineNumber (me), U").");
48 c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me);
49 }
50 }
51 int i = 0;
52 for (; i < 40; i ++) {
53 if (c > 127)
54 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found strange text while looking for an integer in text (line ", MelderReadText_getLineNumber (me), U").");
55 buffer [i] = (char) (char8cxx . . $ char8#) c; // guarded conversion down
56 c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me);
57 if (c == U'\0') { break; } // this may well be OK here
58 if (Melder_isHorizontalOrVerticalSpacecxx . . $ Melder_isHorizontalOrVerticalSpace(b8d0204ce8416907). (c)) break;
59 }
60 if (i >= 40)
61 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found long text while looking for an integer in text (line ", MelderReadText_getLineNumber (me), U").");
62 buffer [i + 1] = '\0';
63 return strtoll (buffer, nullptr, 10);
64 }
65
66 static uint64cxx . . $ uint64# getUnsignedcxx . . $ getUnsigned(18eb8ce736120c74). (MelderReadTextcxx . . $ MelderReadText# me) {
67 char buffer [41];
68 char32cxx . . $ char32# c;
69 for (c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me); ! Melder_isAsciiDecimalNumbercxx . . $ Melder_isAsciiDecimalNumber(b8d0204ce8416907). (c) && c != U'+'; c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me)) {
70 if (c == U'\0')
71 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected while looking for an unsigned integer (line ", MelderReadText_getLineNumber (me), U").");
72 if (c == U'!') { // end-of-line comment?
73 while ((c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me)) != '\n' && c != '\r') {
74 if (c == U'\0')
75 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected in comment while looking for an unsigned integer (line ", MelderReadText_getLineNumber (me), U").");
76 }
77 }
78 if (c == U'\"')
79 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found a string while looking for an unsigned integer in text (line ", MelderReadText_getLineNumber (me), U").");
80 if (c == U'<')
81 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found an enumerated value while looking for an unsigned integer in text (line ", MelderReadText_getLineNumber (me), U").");
82 if (c == U'-')
83 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found a negative value while looking for an unsigned integer in text (line ", MelderReadText_getLineNumber (me), U").");
84 while (! Melder_isHorizontalOrVerticalSpacecxx . . $ Melder_isHorizontalOrVerticalSpace(b8d0204ce8416907). (c)) {
85 if (c == U'\0')
86 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected in comment (line ", MelderReadText_getLineNumber (me), U").");
87 c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me);
88 }
89 }
90 int i = 0;
91 for (i = 0; i < 40; i ++) {
92 if (c > 127)
93 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found strange text while looking for an unsigned integer in text (line ", MelderReadText_getLineNumber (me), U").");
94 buffer [i] = (char) (char8cxx . . $ char8#) c; // guarded conversion down
95 c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me);
96 if (c == U'\0') { break; } // this may well be OK here
97 if (Melder_isHorizontalOrVerticalSpacecxx . . $ Melder_isHorizontalOrVerticalSpace(b8d0204ce8416907). (c)) break;
98 }
99 if (i >= 40)
100 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found long text while searching for an unsigned integer in text (line ", MelderReadText_getLineNumber (me), U").");
101 buffer [i + 1] = '\0';
102 return strtoull (buffer, nullptr, 10);
103 }
104
105 static double getRealcxx . . $ getReal(8233d77bc64f583c). (MelderReadTextcxx . . $ MelderReadText# me) {
106 int i;
107 char buffer [41], *slash;
108 char32cxx . . $ char32# c;
109 do {
110 for (c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me); c != U'-' && ! Melder_isAsciiDecimalNumbercxx . . $ Melder_isAsciiDecimalNumber(b8d0204ce8416907). (c) && c != U'+'; c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me)) {
111 if (c == U'\0')
112 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected while looking for a real number (line ", MelderReadText_getLineNumber (me), U").");
113 if (c == U'!') { // end-of-line comment?
114 while ((c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me)) != U'\n' && c != U'\r') {
115 if (c == U'\0')
116 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected in comment while looking for a real number (line ", MelderReadText_getLineNumber (me), U").");
117 }
118 }
119 if (c == U'\"')
120 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found a string while looking for a real number in text (line ", MelderReadText_getLineNumber (me), U").");
121 if (c == U'<')
122 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found an enumerated value while looking for a real number in text (line ", MelderReadText_getLineNumber (me), U").");
123 while (! Melder_isHorizontalOrVerticalSpacecxx . . $ Melder_isHorizontalOrVerticalSpace(b8d0204ce8416907). (c)) {
124 if (c == U'\0')
125 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected in comment while looking for a real number (line ", MelderReadText_getLineNumber (me), U").");
126 c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me);
127 }
128 }
129 for (i = 0; i < 40; i ++) {
130 if (c > 127)
131 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found strange text while looking for a real number in text (line ", MelderReadText_getLineNumber (me), U").");
132 buffer [i] = (char) (char8cxx . . $ char8#) c; // guarded conversion down
133 c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me);
134 if (c == U'\0') { break; } // this may well be OK here
135 if (Melder_isHorizontalOrVerticalSpacecxx . . $ Melder_isHorizontalOrVerticalSpace(b8d0204ce8416907). (c)) break;
136 }
137 if (i >= 40)
138 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found long text while searching for a real number in text (line ", MelderReadText_getLineNumber (me), U").");
139 } while (i == 0 && buffer [0] == '+'); // guard against single '+' symbols, which occur in complex numbers
140 buffer [i + 1] = '\0';
141 slash = strchr (buffer, '/');
142 if (slash) {
143 *slash = '\0';
144 double numerator = Melder_a8tofcxx . . $ Melder_a8tof(9a18bdb0e56c1bc2). (buffer), denominator = Melder_a8tofcxx . . $ Melder_a8tof(9a18bdb0e56c1bc2). (slash + 1);
145 if (isundefcxx . . $ isundef(f8197d536af80c96). (numerator) || isundefcxx . . $ isundef(f8197d536af80c96). (denominator) || denominator == 0.0)
146 return undefinedcxx . . $ undefined.;
147 return numerator / denominator;
148 }
149 return Melder_a8tofcxx . . $ Melder_a8tof(9a18bdb0e56c1bc2). (buffer);
150 }
151
152 static dcomplexcxx . . $ dcomplex# getComplexcxx . . $ getComplex(973f5e238341d394). (MelderReadTextcxx . . $ MelderReadText# me) {
153 dcomplexcxx . . $ dcomplex# resultcxx . . $ std/complex#complex(bc12c9ec15586e6a).;
154 char realBuffer [41], imaginaryBuffer [41];
155 integercxx . . $ integer# ireal = 0, iimag = 0;
156 char32cxx . . $ char32# c;
157 bool inExponent = false, inExponentNumber = false, separatorIsMinus = false;
158 for (c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me); c != U'-' && ! Melder_isAsciiDecimalNumbercxx . . $ Melder_isAsciiDecimalNumber(b8d0204ce8416907). (c) && c != U'+'; c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me)) {
159 if (c == U'\0')
160 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected while looking for a complex number (line ", MelderReadText_getLineNumber (me), U").");
161 if (c == U'!') { // end-of-line comment?
162 while ((c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me)) != U'\n' && c != U'\r') {
163 if (c == U'\0')
164 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected in comment while looking for a complex number (line ", MelderReadText_getLineNumber (me), U").");
165 }
166 }
167 if (c == U'\"')
168 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found a string while looking for a complex number in text (line ", MelderReadText_getLineNumber (me), U").");
169 if (c == U'<')
170 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found an enumerated value while looking for a complex number in text (line ", MelderReadText_getLineNumber (me), U").");
171 while (! Melder_isHorizontalOrVerticalSpacecxx . . $ Melder_isHorizontalOrVerticalSpace(b8d0204ce8416907). (c)) {
172 if (c == U'\0')
173 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected in comment while looking for a complex number (line ", MelderReadText_getLineNumber (me), U").");
174 c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me);
175 }
176 }
177 for (; ireal < 40; ireal ++) {
178 if (c > 127)
179 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found strange text while looking for a complex number in text (line ", MelderReadText_getLineNumber (me), U").");
180 if (inExponent) {
181 if (c == U'+' || c == U'-') {
182 if (inExponentNumber) {
183 /*
184 This must be the beginning of the imaginary part.
185 */
186 separatorIsMinus = ( c == U'-' );
187 realBuffer [ireal] = U'\0';
188 break;
189 } else {
190 inExponentNumber = true;
191 }
192 } else if (Melder_isAsciiDecimalNumbercxx . . $ Melder_isAsciiDecimalNumber(b8d0204ce8416907). (c)) {
193 inExponentNumber = true;
194 } else if (inExponentNumber) { // typically a space
195 realBuffer [ireal] = U'\0';
196 break;
197 } else {
198 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found unexpected symbol in the exponent of a complex number (line ", MelderReadText_getLineNumber (me), U").");
199 }
200 } else if (ireal > 0 && (c == U'+' || c == U'-')) { // note: initial signs are not separators
201 separatorIsMinus = ( c == U'-' );
202 realBuffer [ireal] = U'\0';
203 break;
204 }
205 if (c == 'e' || c == 'E')
206 inExponent = true;
207 realBuffer [ireal] = (char) (char8cxx . . $ char8#) c; // guarded conversion down
208 c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me);
209 if (c == U'\0')
210 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Missing imaginary part in complex number (line ", MelderReadText_getLineNumber (me), U").");
211 if (Melder_isHorizontalOrVerticalSpacecxx . . $ Melder_isHorizontalOrVerticalSpace(b8d0204ce8416907). (c))
212 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found a space within a complex number (line ", MelderReadText_getLineNumber (me), U").");
213 }
214 if (ireal >= 40)
215 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found long text while searching for a complex number in text (line ", MelderReadText_getLineNumber (me), U").");
216 realBuffer [ireal + 1] = '\0';
217 result. realcxx . . $ std/complex#real(ba8836b59fb42830). (Melder_a8tofcxx . . $ Melder_a8tof(9a18bdb0e56c1bc2). (realBuffer));
218 c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me);
219 if (c != U'-' && ! Melder_isAsciiDecimalNumbercxx . . $ Melder_isAsciiDecimalNumber(b8d0204ce8416907). (c) && c != U'+')
220 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found strange text while looking for the imaginary part of a complex number in text (line ", MelderReadText_getLineNumber (me), U").");
221 if (c == U'\0')
222 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected while looking for the imaginary part of a complex number (line ", MelderReadText_getLineNumber (me), U").");
223 if (Melder_isHorizontalOrVerticalSpacecxx . . $ Melder_isHorizontalOrVerticalSpace(b8d0204ce8416907). (c))
224 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found a space within a complex number (line ", MelderReadText_getLineNumber (me), U").");
225 if (c == U'!') { // end-of-line comment?
226 while ((c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me)) != U'\n' && c != U'\r') {
227 if (c == U'\0')
228 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected in comment while looking for the imaginary part of a complex number (line ", MelderReadText_getLineNumber (me), U").");
229 }
230 }
231 if (c == U'\"')
232 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found a string while looking for the imaginary part of a complex number in text (line ", MelderReadText_getLineNumber (me), U").");
233 if (c == U'<')
234 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found an enumerated value while looking for the imaginary part of a complex number in text (line ", MelderReadText_getLineNumber (me), U").");
235 for (; iimag < 40; iimag ++) {
236 if (c > 127)
237 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found strange text while looking for the imaginary part of a complex number in text (line ", MelderReadText_getLineNumber (me), U").");
238 imaginaryBuffer [iimag] = (char) (char8cxx . . $ char8#) c; // guarded conversion down
239 c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me);
240 if (c == U'\0')
241 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Missing i in a complex number in text (line ", MelderReadText_getLineNumber (me), U").");
242 if (Melder_isHorizontalOrVerticalSpacecxx . . $ Melder_isHorizontalOrVerticalSpace(b8d0204ce8416907). (c))
243 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Missing i in a complex number in text (line ", MelderReadText_getLineNumber (me), U").");
244 if (c == U'i')
245 break;
246 }
247 if (iimag >= 40)
248 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found long text while searching for the imaginary part of a complex number in text (line ", MelderReadText_getLineNumber (me), U").");
249 imaginaryBuffer [iimag + 1] = '\0';
250 result. imagcxx . . $ std/complex#imag(ba8836b59fb42830). (Melder_a8tofcxx . . $ Melder_a8tof(9a18bdb0e56c1bc2). (imaginaryBuffer) * ( separatorIsMinus ? -1.0 : 1.0 ));
251 return resultcxx . . $ std/complex#complex(20ef1611af677bca).;
252 }
253
254 static int getEnumcxx . . $ getEnum(5d13c7fbeaf5c6ca). (MelderReadTextcxx . . $ MelderReadText# me, int (*getValue) (conststring32cxx . . $ conststring32#)) {
255 char32cxx . . $ char32# buffer [41], c;
256 for (c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me); c != U'<'; c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me)) {
257 if (c == U'\0')
258 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected while looking for an enumerated value (line ", MelderReadText_getLineNumber (me), U").");
259 if (c == U'!') { /* End-of-line comment? */
260 while ((c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me)) != U'\n' && c != U'\r') {
261 if (c == U'\0')
262 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected in comment while looking for an enumerated value (line ", MelderReadText_getLineNumber (me), U").");
263 }
264 }
265 if (c == U'-' || Melder_isAsciiDecimalNumbercxx . . $ Melder_isAsciiDecimalNumber(b8d0204ce8416907). (c) || c == U'+')
266 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found a number while looking for an enumerated value in text (line ", MelderReadText_getLineNumber (me), U").");
267 if (c == U'\"')
268 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found a string while looking for an enumerated value in text (line ", MelderReadText_getLineNumber (me), U").");
269 while (! Melder_isHorizontalOrVerticalSpacecxx . . $ Melder_isHorizontalOrVerticalSpace(b8d0204ce8416907). (c)) {
270 if (c == U'\0')
271 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected in comment while looking for an enumerated value (line ", MelderReadText_getLineNumber (me), U").");
272 c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me);
273 }
274 }
275 int i = 0;
276 for (; i < 40; i ++) {
277 c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me); // read past first '<'
278 if (c == U'\0')
279 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected while reading an enumerated value (line ", MelderReadText_getLineNumber (me), U").");
280 constexpr char32cxx . . $ char32# theOnlySpaceAllowedInAnEnum = U' ';
281 if (Melder_isHorizontalOrVerticalSpacecxx . . $ Melder_isHorizontalOrVerticalSpace(b8d0204ce8416907). (c) && c != theOnlySpaceAllowedInAnEnum)
282 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No matching '>' while reading an enumerated value (line ", MelderReadText_getLineNumber (me), U").");
283 if (c == U'>')
284 break; // the expected closing bracket; not added to the buffer
285 buffer [i] = c;
286 }
287 if (i >= 40)
288 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found strange text while reading an enumerated value in text (line ", MelderReadText_getLineNumber (me), U").");
289 buffer [i] = U'\0';
290 int value = getValue (buffer);
291 if (value < 0)
292 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"\"", buffer, U"\" is not a value of the enumerated type.");
293 return value;
294 }
295
296 static char32cxx . . $ char32# * peekStringcxx . . $ peekString(f4aa1d9b94177768). (MelderReadTextcxx . . $ MelderReadText# me) {
297 static MelderStringcxx . . $ MelderString# buffer;
298 MelderString_emptycxx . . $ MelderString_empty(93db1090f27e5462). (& buffer);
299 for (char32cxx . . $ char32# c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me); c != U'\"'; c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me)) {
300 if (c == U'\0')
301 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected while looking for a string (line ", MelderReadText_getLineNumber (me), U").");
302 if (c == U'!') { // end-of-line comment?
303 while ((c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me)) != '\n' && c != '\r') {
304 if (c == U'\0')
305 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected in comment while looking for a string (line ", MelderReadText_getLineNumber (me), U").");
306 }
307 }
308 if (c == U'-' || Melder_isAsciiDecimalNumbercxx . . $ Melder_isAsciiDecimalNumber(b8d0204ce8416907). (c) || c == U'+')
309 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found a number while looking for a string in text (line ", MelderReadText_getLineNumber (me), U").");
310 if (c == U'<')
311 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found an enumerated value while looking for a string in text (line ", MelderReadText_getLineNumber (me), U").");
312 while (! Melder_isHorizontalOrVerticalSpacecxx . . $ Melder_isHorizontalOrVerticalSpace(b8d0204ce8416907). (c)) {
313 if (c == U'\0')
314 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected while looking for a string (line ", MelderReadText_getLineNumber (me), U").");
315 c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me);
316 }
317 }
318 for (int i = 0; 1; i ++) {
319 char32cxx . . $ char32# c = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me); // read past first '"'
320 if (c == U'\0')
321 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Early end of text detected while reading a string (line ", MelderReadText_getLineNumber (me), U").");
322 if (c == U'\"') {
323 char32cxx . . $ char32# next = MelderReadText_getCharcxx . . $ MelderReadText_getChar(c643827765aac06e). (me);
324 if (next == U'\0') { break; } // closing quote is last character in file: OK
325 if (next != U'\"') {
326 if (Melder_isHorizontalOrVerticalSpacecxx . . $ Melder_isHorizontalOrVerticalSpace(b8d0204ce8416907). (next)) {
327 // closing quote is followed by whitespace: it is OK to skip this whitespace (no need to "ungetChar")
328 } else {
329 char32cxx . . $ char32# kar2 [2] = { next, U'\0' };
330 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Character ", kar2, U" following quote (line ", MelderReadText_getLineNumber (me), U"). End of string or undoubled quote?");
331 }
332 break; // the expected closing double quote; not added to the buffer
333 } // else: add only one of the two quotes to the buffer
334 }
335 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& buffer, c);
336 }
337 return buffer.stringcxx . . $ MelderString#string.;
338 }
339
340 #include "enums_getText.h"cxx . . $ `<file>/melder/enums_getText.h`/
341 #include "abcio_enums.h"cxx . . $ `<file>/melder/abcio_enums.h`/
342 #include "enums_getValue.h"cxx . . $ `<file>/melder/enums_getValue.h`/
343 #include "abcio_enums.h"cxx . . $ `<file>/melder/abcio_enums.h`/
344
345 int texgeti8cxx . . $ texgeti8(2ccfb320b77fcecd). (MelderReadTextcxx . . $ MelderReadText# text) {
346 try {
347 int64cxx . . $ int64# externalValue = getIntegercxx . . $ getInteger(c4cc05fb41712971). (text);
348 if (externalValue < INT8_MINcxx . . $ `<external>/3415975807581488833/stdint.h:105:10`! || externalValue > INT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:110:10`!)
349 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Value (", externalValue, U") out of range (-128 .. +127).");
350 return (int) externalValue;
351 } catch (MelderErrorcxx . . $ MelderError#) {
352 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed small integer not read from text file.");
353 }
354 }
355
356 int16cxx . . $ int16# texgeti16cxx . . $ texgeti16(df2c8a7d80e92f0e). (MelderReadTextcxx . . $ MelderReadText# text) {
357 try {
358 int64cxx . . $ int64# externalValue = getIntegercxx . . $ getInteger(c4cc05fb41712971). (text);
359 if (externalValue < INT16_MINcxx . . $ `<external>/3415975807581488833/stdint.h:106:10`! || externalValue > INT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:111:10`!)
360 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Value (", externalValue, U") out of range (-32768 .. +32767).");
361 return (int16cxx . . $ int16#) externalValue;
362 } catch (MelderErrorcxx . . $ MelderError#) {
363 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed short integer not read from text file.");
364 }
365 }
366
367 int32cxx . . $ int32# texgeti32cxx . . $ texgeti32(2ccfb320b77fcecd). (MelderReadTextcxx . . $ MelderReadText# text) {
368 try {
369 int64cxx . . $ int64# externalValue = getIntegercxx . . $ getInteger(c4cc05fb41712971). (text);
370 if (externalValue < INT32_MINcxx . . $ `<external>/3415975807581488833/stdint.h:107:10`! || externalValue > INT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:112:10`!)
371 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Value (", externalValue, U") out of range (-2147483648 .. +2147483647).");
372 return (int32cxx . . $ int32#) externalValue;
373 } catch (MelderErrorcxx . . $ MelderError#) {
374 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not read from text file.");
375 }
376 }
377
378 integercxx . . $ integer# texgetintegercxx . . $ texgetinteger(c4cc05fb41712971). (MelderReadTextcxx . . $ MelderReadText# text) {
379 try {
380 int64cxx . . $ int64# externalValue = getIntegercxx . . $ getInteger(c4cc05fb41712971). (text);
381 if (externalValue < INT32_MINcxx . . $ `<external>/3415975807581488833/stdint.h:107:10`! || externalValue > INT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:112:10`!)
382 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Value (", externalValue, U") out of range (-2147483648 .. +2147483647)."); // this will change
383 return (integercxx . . $ integer#) externalValue;
384 } catch (MelderErrorcxx . . $ MelderError#) {
385 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not read from text file.");
386 }
387 }
388
389 unsigned int texgetu8cxx . . $ texgetu8(275f9a74c1f6a9e1). (MelderReadTextcxx . . $ MelderReadText# text) {
390 try {
391 uint64cxx . . $ uint64# externalValue = getUnsignedcxx . . $ getUnsigned(18eb8ce736120c74). (text);
392 if (externalValue > UINT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:116:10`!)
393 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Value (", externalValue, U") out of range (0 .. 255).");
394 return (unsigned int) externalValue;
395 } catch (MelderErrorcxx . . $ MelderError#) {
396 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Unsigned small integer not read from text file.");
397 }
398 }
399
400 uint16cxx . . $ uint16# texgetu16cxx . . $ texgetu16(704c7e169c71fecc). (MelderReadTextcxx . . $ MelderReadText# text) {
401 try {
402 uint64cxx . . $ uint64# externalValue = getUnsignedcxx . . $ getUnsigned(18eb8ce736120c74). (text);
403 if (externalValue > UINT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:117:10`!)
404 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Value (", externalValue, U") out of range (0 .. 65535).");
405 return (uint16cxx . . $ uint16#) externalValue;
406 } catch (MelderErrorcxx . . $ MelderError#) {
407 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Unsigned short integer not read from text file.");
408 }
409 }
410
411 uint32cxx . . $ uint32# texgetu32cxx . . $ texgetu32(275f9a74c1f6a9e1). (MelderReadTextcxx . . $ MelderReadText# text) {
412 try {
413 uint64cxx . . $ uint64# externalValue = getUnsignedcxx . . $ getUnsigned(18eb8ce736120c74). (text);
414 if (externalValue > UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:118:10`!)
415 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Value (", externalValue, U") out of range (0 .. 4294967295).");
416 return (uint32cxx . . $ uint32#) externalValue;
417 } catch (MelderErrorcxx . . $ MelderError#) {
418 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Unsigned integer not read from text file.");
419 }
420 }
421
422 double texgetr32cxx . . $ texgetr32(8233d77bc64f583c). (MelderReadTextcxx . . $ MelderReadText# text) { return getRealcxx . . $ getReal(8233d77bc64f583c). (text); }
423 double texgetr64cxx . . $ texgetr64(8233d77bc64f583c). (MelderReadTextcxx . . $ MelderReadText# text) { return getRealcxx . . $ getReal(8233d77bc64f583c). (text); }
424 double texgetr80cxx . . $ texgetr80(8233d77bc64f583c). (MelderReadTextcxx . . $ MelderReadText# text) { return getRealcxx . . $ getReal(8233d77bc64f583c). (text); }
425 dcomplexcxx . . $ dcomplex# texgetc64cxx . . $ texgetc64(973f5e238341d394). (MelderReadTextcxx . . $ MelderReadText# text) { return getComplexcxx . . $ getComplex(973f5e238341d394). (text); }
426 dcomplexcxx . . $ dcomplex# texgetc128cxx . . $ texgetc128(973f5e238341d394). (MelderReadTextcxx . . $ MelderReadText# text) { return getComplexcxx . . $ getComplex(973f5e238341d394). (text); }
427
428 int texgete8cxx . . $ texgete8(5d13c7fbeaf5c6ca). (MelderReadTextcxx . . $ MelderReadText# text, enum_generic_getValuecxx . . $ enum_generic_getValue# getValue) { return getEnumcxx . . $ getEnum(5d13c7fbeaf5c6ca). (text, getValue); }
429 int texgete16cxx . . $ texgete16(5d13c7fbeaf5c6ca). (MelderReadTextcxx . . $ MelderReadText# text, enum_generic_getValuecxx . . $ enum_generic_getValue# getValue) { return getEnumcxx . . $ getEnum(5d13c7fbeaf5c6ca). (text, getValue); }
430 bool texgetebcxx . . $ texgeteb(38d4372a0347f2a3). (MelderReadTextcxx . . $ MelderReadText# text) { return getEnumcxx . . $ getEnum(5d13c7fbeaf5c6ca). (text, (enum_generic_getValuecxx . . $ enum_generic_getValue#) kBoolean_getValue); }
431 bool texgeteqcxx . . $ texgeteq(38d4372a0347f2a3). (MelderReadTextcxx . . $ MelderReadText# text) { return getEnumcxx . . $ getEnum(5d13c7fbeaf5c6ca). (text, (enum_generic_getValuecxx . . $ enum_generic_getValue#) kQuestion_getValue); }
432 bool texgetexcxx . . $ texgetex(38d4372a0347f2a3). (MelderReadTextcxx . . $ MelderReadText# text) { return getEnumcxx . . $ getEnum(5d13c7fbeaf5c6ca). (text, (enum_generic_getValuecxx . . $ enum_generic_getValue#) kExistence_getValue); }
433 autostring32cxx . . $ autostring32# texgetw16cxx . . $ texgetw16(6d8daa32ac6455b9). (MelderReadTextcxx . . $ MelderReadText# text) { return Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (peekStringcxx . . $ peekString(f4aa1d9b94177768). (text)); }
434 autostring32cxx . . $ autostring32# texgetw32cxx . . $ texgetw32(6d8daa32ac6455b9). (MelderReadTextcxx . . $ MelderReadText# text) { return Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (peekStringcxx . . $ peekString(f4aa1d9b94177768). (text)); }
435
436 void texindentcxx . . $ texindent(1145552d769d7b5d). (MelderFilecxx . . $ MelderFile# file) { file -> indentcxx . . $ structMelderFile#indent. += 4; }
437 void texexdentcxx . . $ texexdent(1145552d769d7b5d). (MelderFilecxx . . $ MelderFile# file) { file -> indentcxx . . $ structMelderFile#indent. -= 4; }
438 void texresetindentcxx . . $ texresetindent(1145552d769d7b5d). (MelderFilecxx . . $ MelderFile# file) { file -> indentcxx . . $ structMelderFile#indent. = 0; }
439
440 #define texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`! \
441 conststring32 s1, conststring32 s2, conststring32 s3, \
442 conststring32 s4, conststring32 s5, conststring32 s6, \
443 conststring32 s7, conststring32 s8, conststring32 s9
444
445 void texputintrocxx . . $ texputintro(ca2e4f9dca357a80). (MelderFilecxx . . $ MelderFile# file, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
446 if (file -> verbosecxx . . $ structMelderFile#verbose.) {
447 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U"\n");
448 for (int iindent = 1; iindent <= file -> indentcxx . . $ structMelderFile#indent.; iindent ++) {
449 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U" ");
450 }
451 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file,
452 s1 && s1 [0] == U'd' && s1 [1] == U'_' ? & s1 [2] : & s1 [0],
453 s2 && s2 [0] == U'd' && s2 [1] == U'_' ? & s2 [2] : & s2 [0],
454 s3 && s3 [0] == U'd' && s3 [1] == U'_' ? & s3 [2] : & s3 [0],
455 s4 && s4 [0] == U'd' && s4 [1] == U'_' ? & s4 [2] : & s4 [0],
456 s5 && s5 [0] == U'd' && s5 [1] == U'_' ? & s5 [2] : & s5 [0],
457 s6 && s6 [0] == U'd' && s6 [1] == U'_' ? & s6 [2] : & s6 [0],
458 s7 && s7 [0] == U'd' && s7 [1] == U'_' ? & s7 [2] : & s7 [0],
459 s8 && s8 [0] == U'd' && s8 [1] == U'_' ? & s8 [2] : & s8 [0],
460 s9 && s9 [0] == U'd' && s9 [1] == U'_' ? & s9 [2] : & s9 [0]);
461 }
462 file -> indentcxx . . $ structMelderFile#indent. += 4;
463 }
464
465 #define PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`! \
466 MelderFile_write (file, U"\n"); \
467 if (file -> verbose) { \
468 for (int iindent = 1; iindent <= file -> indent; iindent ++) { \
469 MelderFile_write (file, U" "); \
470 } \
471 MelderFile_write (file, \
472 s1 && s1 [0] == U'd' && s1 [1] == U'_' ? & s1 [2] : & s1 [0], \
473 s2 && s2 [0] == U'd' && s2 [1] == U'_' ? & s2 [2] : & s2 [0], \
474 s3 && s3 [0] == U'd' && s3 [1] == U'_' ? & s3 [2] : & s3 [0], \
475 s4 && s4 [0] == U'd' && s4 [1] == U'_' ? & s4 [2] : & s4 [0], \
476 s5 && s5 [0] == U'd' && s5 [1] == U'_' ? & s5 [2] : & s5 [0], \
477 s6 && s6 [0] == U'd' && s6 [1] == U'_' ? & s6 [2] : & s6 [0], \
478 s7 && s7 [0] == U'd' && s7 [1] == U'_' ? & s7 [2] : & s7 [0], \
479 s8 && s8 [0] == U'd' && s8 [1] == U'_' ? & s8 [2] : & s8 [0], \
480 s9 && s9 [0] == U'd' && s9 [1] == U'_' ? & s9 [2] : & s9 [0]); \
481 }
482
483 void texputi8cxx . . $ texputi8(79cf16150f57996b). (MelderFilecxx . . $ MelderFile# file, int i, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
484 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
485 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = " : nullptr, i, file -> verbosecxx . . $ structMelderFile#verbose. ? U" " : nullptr);
486 }
487 void texputi16cxx . . $ texputi16(79cf16150f57996b). (MelderFilecxx . . $ MelderFile# file, int i, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
488 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
489 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = " : nullptr, i, file -> verbosecxx . . $ structMelderFile#verbose. ? U" " : nullptr);
490 }
491 void texputi32cxx . . $ texputi32(7d66e869d177be0). (MelderFilecxx . . $ MelderFile# file, long i, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
492 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
493 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = " : nullptr, i, file -> verbosecxx . . $ structMelderFile#verbose. ? U" " : nullptr);
494 }
495 void texputintegercxx . . $ texputinteger(7d66e869d177be0). (MelderFilecxx . . $ MelderFile# file, integercxx . . $ integer# number, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
496 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
497 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = " : nullptr, number, file -> verbosecxx . . $ structMelderFile#verbose. ? U" " : nullptr);
498 }
499 void texputu8cxx . . $ texputu8(16a828011950446e). (MelderFilecxx . . $ MelderFile# file, unsigned int u, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
500 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
501 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = " : nullptr, u, file -> verbosecxx . . $ structMelderFile#verbose. ? U" " : nullptr);
502 }
503 void texputu16cxx . . $ texputu16(16a828011950446e). (MelderFilecxx . . $ MelderFile# file, unsigned int u, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
504 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
505 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = " : nullptr, u, file -> verbosecxx . . $ structMelderFile#verbose. ? U" " : nullptr);
506 }
507 void texputu32cxx . . $ texputu32(4e03ad187d1582a7). (MelderFilecxx . . $ MelderFile# file, unsigned long u, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
508 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
509 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = " : nullptr, u, file -> verbosecxx . . $ structMelderFile#verbose. ? U" " : nullptr);
510 }
511 void texputr32cxx . . $ texputr32(e74c4a2aaf5f7438). (MelderFilecxx . . $ MelderFile# file, double x, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
512 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
513 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = " : nullptr, Melder_singlecxx . . $ Melder_single(f05d861d9dbec9b2). (x), file -> verbosecxx . . $ structMelderFile#verbose. ? U" " : nullptr);
514 }
515 void texputr64cxx . . $ texputr64(e74c4a2aaf5f7438). (MelderFilecxx . . $ MelderFile# file, double x, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
516 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
517 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = " : nullptr, x, file -> verbosecxx . . $ structMelderFile#verbose. ? U" " : nullptr);
518 }
519 void texputc64cxx . . $ texputc64(345afc904cfef26b). (MelderFilecxx . . $ MelderFile# file, dcomplexcxx . . $ dcomplex# z, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
520 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
521 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = " : nullptr, zcxx . . $ std/complex#complex(20ef1611af677bca)., file -> verbosecxx . . $ structMelderFile#verbose. ? U" " : nullptr);
522 }
523 void texputc128cxx . . $ texputc128(345afc904cfef26b). (MelderFilecxx . . $ MelderFile# file, dcomplexcxx . . $ dcomplex# z, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
524 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
525 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = " : nullptr, zcxx . . $ std/complex#complex(20ef1611af677bca)., file -> verbosecxx . . $ structMelderFile#verbose. ? U" " : nullptr);
526 }
527 void texpute8cxx . . $ texpute8(ec74f58c867c0215). (MelderFilecxx . . $ MelderFile# file, int i, conststring32cxx . . $ conststring32# (*getText) (int), texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
528 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
529 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = <" : U"<", getText (i), file -> verbosecxx . . $ structMelderFile#verbose. ? U"> " : U">");
530 }
531 void texpute16cxx . . $ texpute16(ec74f58c867c0215). (MelderFilecxx . . $ MelderFile# file, int i, conststring32cxx . . $ conststring32# (*getText) (int), texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
532 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
533 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = <" : U"<", getText (i), file -> verbosecxx . . $ structMelderFile#verbose. ? U"> " : U">");
534 }
535 void texputebcxx . . $ texputeb(df7eef0320334cb9). (MelderFilecxx . . $ MelderFile# file, bool i, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
536 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
537 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = " : nullptr, i ? U"<true>" : U"<false>", file -> verbosecxx . . $ structMelderFile#verbose. ? U" " : nullptr);
538 }
539 void texputeqcxx . . $ texputeq(df7eef0320334cb9). (MelderFilecxx . . $ MelderFile# file, bool i, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
540 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
541 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U"? " : nullptr, i ? U"<yes>" : U"<no>", file -> verbosecxx . . $ structMelderFile#verbose. ? U" " : nullptr);
542 }
543 void texputexcxx . . $ texputex(df7eef0320334cb9). (MelderFilecxx . . $ MelderFile# file, bool i, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
544 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
545 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U"? " : nullptr, i ? U"<exists>" : U"<absent>", file -> verbosecxx . . $ structMelderFile#verbose. ? U" " : nullptr);
546 }
547 void texputs8cxx . . $ texputs8(65c6b20d12993863). (MelderFilecxx . . $ MelderFile# file, const char *s, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
548 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
549 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = \"" : U"\"");
550 if (s) {
551 char c;
552 while ((c = *s ++) != '\0') {
553 MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, (char32cxx . . $ char32#) (char8cxx . . $ char8#) c);
554 if (c == U'\"') MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, (char32cxx . . $ char32#) (char8cxx . . $ char8#) c); // double any internal quotes
555 }
556 }
557 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U"\" " : U"\"");
558 }
559 void texputs16cxx . . $ texputs16(65c6b20d12993863). (MelderFilecxx . . $ MelderFile# file, const char *s, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
560 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
561 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = \"" : U"\"");
562 if (s) {
563 char c;
564 while ((c = *s ++) != '\0') {
565 MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, (char32cxx . . $ char32#) (char8cxx . . $ char8#) c);
566 if (c == '\"') MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, (char32cxx . . $ char32#) (char8cxx . . $ char8#) c); // double any internal quotes
567 }
568 }
569 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U"\" " : U"\"");
570 }
571 void texputs32cxx . . $ texputs32(65c6b20d12993863). (MelderFilecxx . . $ MelderFile# file, const char *s, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
572 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
573 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = \"" : U"\"");
574 if (s) {
575 char c;
576 while ((c = *s ++) != '\0') {
577 MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, (char32cxx . . $ char32#) (char8cxx . . $ char8#) c);
578 if (c == '\"') MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, (char32cxx . . $ char32#) (char8cxx . . $ char8#) c); // double any internal quotes
579 }
580 }
581 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U"\" " : U"\"");
582 }
583 void texputw16cxx . . $ texputw16(44d267b8842e4934). (MelderFilecxx . . $ MelderFile# file, conststring32cxx . . $ conststring32# s, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
584 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
585 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = \"" : U"\"");
586 if (s) {
587 char32cxx . . $ char32# c;
588 while ((c = *s ++) != U'\0') {
589 MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, c);
590 if (c == U'\"') MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, c); // double any internal quotes
591 }
592 }
593 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U"\" " : U"\"");
594 }
595 void texputw32cxx . . $ texputw32(44d267b8842e4934). (MelderFilecxx . . $ MelderFile# file, conststring32cxx . . $ conststring32# s, texput_UP_TO_NINE_NULLABLE_STRINGScxx . . $ `melder/abcio.cpp:440:9`!) {
596 PUTLEADERcxx . . $ `melder/abcio.cpp:465:9`!
597 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U" = \"" : U"\"");
598 if (s) {
599 char32cxx . . $ char32# c;
600 while ((c = *s ++) != U'\0') {
601 MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, c);
602 if (c == U'\"') MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, c); // double any internal quotes
603 }
604 }
605 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, file -> verbosecxx . . $ structMelderFile#verbose. ? U"\" " : U"\"");
606 }
607
608 /********** machine-independent binary I/O **********/
609
610 /* Optimizations for machines for which some of the formats are native. */
611
612 /* On which machines is "short" a two's complement Big-Endian (MSB-first) 2-byte word? */
613
614 #if defined (macintosh) && TARGET_RT_BIG_ENDIAN == 1
615 #define binario_16bitBE 1
616 #define binario_16bitLE 0
617 #elif defined (_WIN32) || defined (macintosh) && TARGET_RT_LITTLE_ENDIAN == 1
618 #define binario_16bitBE 0
619 #define binario_16bitLE 1
620 #else
621 #define binario_16bitBEcxx . . $ `melder/abcio.cpp:621:10`! 0
622 #define binario_16bitLEcxx . . $ `melder/abcio.cpp:622:10`! 0
623 #endif
624
625 /* On which machines is "long" a two's complement Big-Endian (MSB-first) 4-byte word? */
626
627 #if defined (macintosh) && TARGET_RT_BIG_ENDIAN == 1
628 #define binario_32bitBE 1
629 #define binario_32bitLE 0
630 #elif defined (_WIN32) || defined (macintosh) && TARGET_RT_LITTLE_ENDIAN == 1
631 #define binario_32bitBE 0
632 #define binario_32bitLE 1
633 #else
634 #define binario_32bitBEcxx . . $ `melder/abcio.cpp:634:10`! 0
635 #define binario_32bitLEcxx . . $ `melder/abcio.cpp:635:10`! 0
636 #endif
637
638 /* On which machines is "float" IEEE, four bytes, Most Significant Bit first? */
639
640 #if defined (macintosh) && TARGET_RT_BIG_ENDIAN == 1
641 #define binario_floatIEEE4msb (sizeof (float) == 4)
642 #define binario_floatIEEE4lsb 0
643 #elif defined (_WIN32) || defined (macintosh) && TARGET_RT_LITTLE_ENDIAN == 1
644 #define binario_floatIEEE4msb 0
645 #define binario_floatIEEE4lsb (sizeof (float) == 4)
646 #else
647 #define binario_floatIEEE4msbcxx . . $ `melder/abcio.cpp:647:10`! 0
648 #define binario_floatIEEE4lsbcxx . . $ `melder/abcio.cpp:648:10`! 0
649 #endif
650
651 /* On which machines is "double" IEEE, eight bytes, Most Significant Bit first? */
652
653 #if defined (macintosh) && TARGET_RT_BIG_ENDIAN == 1
654 #define binario_doubleIEEE8msb (sizeof (double) == 8)
655 #define binario_doubleIEEE8lsb 0
656 #elif defined (_WIN32) || defined (macintosh) && TARGET_RT_LITTLE_ENDIAN == 1
657 #define binario_doubleIEEE8msb 0
658 #define binario_doubleIEEE8lsb (sizeof (double) == 8)
659 #else
660 #define binario_doubleIEEE8msbcxx . . $ `melder/abcio.cpp:660:10`! 0
661 #define binario_doubleIEEE8lsbcxx . . $ `melder/abcio.cpp:661:10`! 0
662 #endif
663
664 /*
665 The routines bingetr32, bingetr64, binputr32, and binputr64,
666 were implemented by Paul Boersma from the descriptions of the IEEE floating-point formats,
667 as found in the MC68881/MC68882 User's Manual by Motorola (second edition, 1989).
668 The following copyright notice only refers to the code of bingetr10 and binputr10.
669 */
670
671 /* Copyright (C) 1988-1991 Apple Computer, Inc.
672 * All rights reserved.
673 *
674 * Warranty Information
675 * Even though Apple has reviewed this software, Apple makes no warranty
676 * or representation, either express or implied, with respect to this
677 * software, its quality, accuracy, merchantability, or fitness for a
678 * particular purpose. As a result, this software is provided "as is,"
679 * and you, its user, are assuming the entire risk as to its quality
680 * and accuracy.
681 *
682 * This code may be used and freely distributed as long as it includes
683 * this copyright notice and the above warranty information.
684 *
685 * Machine-independent I/O routines for IEEE floating-point numbers.
686 *
687 * NaN's and infinities are converted to HUGE_VAL or HUGE, which
688 * happens to be infinity on IEEE machines. Unfortunately, it is
689 * impossible to preserve NaN's in a machine-independent way.
690 * Infinities are, however, preserved on IEEE machines.
691 *
692 * These routines have been tested on the following machines:
693 * Apple Macintosh, MPW 3.1 C compiler
694 * Apple Macintosh, THINK C compiler
695 * Silicon Graphics IRIS, MIPS compiler
696 * Cray X/MP and Y/MP
697 * Digital Equipment VAX
698 *
699 * Implemented by Malcolm Slaney and Ken Turkowski.
700 *
701 * Malcolm Slaney contributions during 1988-1990 include big- and little-
702 * endian file I/O, conversion to and from Motorola's extended 80-bit
703 * floating-point format, and conversions to and from IEEE single-
704 * precision floating-point format.
705 *
706 * In 1991, Ken Turkowski implemented the conversions to and from
707 * IEEE double-precision format, added more precision to the extended
708 * conversions, and accommodated conversions involving +/- infinity,
709 * NaN's, and denormalized numbers.
710 */
711
712 /****************************************************************
713 * Extended precision IEEE floating-point conversion routines.
714 ****************************************************************/
715
716 /*
717 * C O N V E R T T O I E E E E X T E N D E D
718 */
719
720 /*
721 * C O N V E R T F R O M I E E E E X T E N D E D
722 */
723
724 /*************** End of Apple Computer intermezzo. ***************/
725
726 static void readErrorcxx . . $ readError(6e3c8643bca295e0). (FILE *f, conststring32cxx . . $ conststring32# text) {
727 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (feof (f) ? U"Reached end of file" : U"Error in file", U" while trying to read ", text);
728 }
729
730 static void writeErrorcxx . . $ writeError(ff00d524ab0355ec). (conststring32cxx . . $ conststring32# text) {
731 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Error in file while trying to write ", text);
732 }
733
734 uint32cxx . . $ uint32# bingetu8cxx . . $ bingetu8(9eef1996c458a0e7). (FILE *f) {
735 try {
736 int32cxx . . $ int32# externalValue = getc (f); // either -1 (EOF) or in the range 0..255
737 if (externalValue < 0)
738 readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"a byte.");
739 return (uint32cxx . . $ uint32#) externalValue;
740 } catch (MelderErrorcxx . . $ MelderError#) {
741 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Unsigned integer not read from 1 byte in binary file.");
742 }
743 }
744
745 void binputu8cxx . . $ binputu8(60af6e60da050086). (uint32cxx . . $ uint32# u, FILE *f) {
746 try {
747 if (putc ((int32cxx . . $ int32#) u, f) < 0)
748 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"a byte.");
749 } catch (MelderErrorcxx . . $ MelderError#) {
750 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Unsigned integer not written to 1 byte in binary file.");
751 }
752 }
753
754 int32cxx . . $ int32# bingeti8cxx . . $ bingeti8(89bc1efcdac0ca22). (FILE *f) {
755 try {
756 int32cxx . . $ int32# externalValue = getc (f);
757 if (externalValue < 0)
758 readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"a byte.");
759 return (signed char) externalValue; // this converts e.g. 200 to -56
760 } catch (MelderErrorcxx . . $ MelderError#) {
761 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not read from 1 byte in binary file.");
762 }
763 }
764
765 void binputi8cxx . . $ binputi8(44487f0f82292376). (int32cxx . . $ int32# u, FILE *f) {
766 try {
767 if (putc (u, f) < 0)
768 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"a byte.");
769 } catch (MelderErrorcxx . . $ MelderError#) {
770 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not written to 1 byte in binary file.");
771 }
772 }
773
774 bool bingetbool8cxx . . $ bingetbool8(dc9e5a301483124c). (FILE *f) {
775 try {
776 int32cxx . . $ int32# externalValue = getc (f);
777 if (externalValue < 0)
778 readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"a byte.");
779 return (bool) externalValue; // this converts e.g. 200 to true
780 } catch (MelderErrorcxx . . $ MelderError#) {
781 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Boolean not read from 1 byte in binary file.");
782 }
783 }
784
785 void binputbool8cxx . . $ binputbool8(d129c1ec250bee9e). (bool value, FILE *f) {
786 try {
787 if (putc (value, f) < 0)
788 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"a byte.");
789 } catch (MelderErrorcxx . . $ MelderError#) {
790 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Boolean not written to 1 byte in binary file.");
791 }
792 }
793
794 int32cxx . . $ int32# bingete8cxx . . $ bingete8(fe4021e40d52d7a9). (FILE *f, int min, int max, conststring32cxx . . $ conststring32# type) {
795 try {
796 int32cxx . . $ int32# externalValue = getc (f);
797 if (externalValue < 0)
798 readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"a byte.");
799 int32cxx . . $ int32# result = (signed char) externalValue; // this converts e.g. 200 to -56, so the enumerated type is signed
800 if (result < min || result > max)
801 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (result, U" is not a value of enumerated type <", type, U">.");
802 return result;
803 } catch (MelderErrorcxx . . $ MelderError#) {
804 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Enumerated type not read from 1 byte in binary file.");
805 }
806 }
807
808 void binpute8cxx . . $ binpute8(44487f0f82292376). (int32cxx . . $ int32# value, FILE *f) {
809 try {
810 if (putc (value, f) < 0)
811 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"a byte.");
812 } catch (MelderErrorcxx . . $ MelderError#) {
813 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Enumerated type not written to 1 byte in binary file.");
814 }
815 }
816
817 int16cxx . . $ int16# bingeti16cxx . . $ bingeti16(2dcfca5714bad490). (FILE *f) {
818 try {
819 if (binario_16bitBEcxx . . $ `melder/abcio.cpp:621:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
820 int16cxx . . $ int16# s;
821 if (fread (& s, sizeof (int16cxx . . $ int16#), 1, f) != 1) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"a signed 16-bit integer.");
822 return s;
823 } else {
824 uint8cxx . . $ uint8# bytes [2];
825 if (fread (bytes, sizeof (uint8cxx . . $ uint8#), 2, f) != 2) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"two bytes.");
826 return (int16cxx . . $ int16#) // reinterpret sign bit
827 ((uint16cxx . . $ uint16#) ((uint16cxx . . $ uint16#) bytes [0] << 8) |
828 (uint16cxx . . $ uint16#) bytes [1]);
829 }
830 } catch (MelderErrorcxx . . $ MelderError#) {
831 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not read from 2 bytes in binary file.");
832 }
833 }
834
835 int16cxx . . $ int16# bingeti16LEcxx . . $ bingeti16LE(2dcfca5714bad490). (FILE *f) {
836 try {
837 if (binario_16bitLEcxx . . $ `melder/abcio.cpp:622:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
838 int16cxx . . $ int16# s;
839 if (fread (& s, sizeof (int16cxx . . $ int16#), 1, f) != 1) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"a signed 16-bit integer.");
840 return s;
841 } else {
842 uint8cxx . . $ uint8# bytes [2];
843 if (fread (bytes, sizeof (uint8cxx . . $ uint8#), 2, f) != 2) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"two bytes.");
844 return (int16cxx . . $ int16#) // reinterpret sign bit
845 ((uint16cxx . . $ uint16#) ((uint16cxx . . $ uint16#) bytes [1] << 8) |
846 (uint16cxx . . $ uint16#) bytes [0]);
847 }
848 } catch (MelderErrorcxx . . $ MelderError#) {
849 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not read from 2 bytes in binary file.");
850 }
851 }
852
853 integercxx . . $ integer# bingetinteger16BEcxx . . $ bingetinteger16BE(1dcafcd8ef4c6e6c). (FILE *f) {
854 try {
855 if (binario_16bitBEcxx . . $ `melder/abcio.cpp:621:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
856 int16cxx . . $ int16# s;
857 if (fread (& s, sizeof (int16cxx . . $ int16#), 1, f) != 1) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"a signed 16-bit integer.");
858 return s;
859 } else {
860 uint8cxx . . $ uint8# bytes [2];
861 if (fread (bytes, sizeof (uint8cxx . . $ uint8#), 2, f) != 2) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"two bytes.");
862 return (int16cxx . . $ int16#) // reinterpret sign bit
863 ((uint16cxx . . $ uint16#) ((uint16cxx . . $ uint16#) bytes [0] << 8) |
864 (uint16cxx . . $ uint16#) bytes [1]);
865 }
866 } catch (MelderErrorcxx . . $ MelderError#) {
867 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not read from 2 bytes in binary file.");
868 }
869 }
870
871 uint16cxx . . $ uint16# bingetu16cxx . . $ bingetu16(38a7f6633dfbdb53). (FILE *f) {
872 try {
873 if (binario_16bitBEcxx . . $ `melder/abcio.cpp:621:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
874 uint16cxx . . $ uint16# s;
875 if (fread (& s, sizeof (uint16cxx . . $ uint16#), 1, f) != 1) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"an unsigned 16-bit integer.");
876 return s; // without sign extension
877 } else {
878 uint8cxx . . $ uint8# bytes [2];
879 if (fread (bytes, sizeof (uint8cxx . . $ uint8#), 2, f) != 2) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"two bytes.");
880 return
881 (uint16cxx . . $ uint16#) ((uint16cxx . . $ uint16#) bytes [0] << 8) |
882 (uint16cxx . . $ uint16#) bytes [1];
883 }
884 } catch (MelderErrorcxx . . $ MelderError#) {
885 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Unsigned integer not read from 2 bytes in binary file.");
886 }
887 }
888
889 uint16cxx . . $ uint16# bingetu16LEcxx . . $ bingetu16LE(38a7f6633dfbdb53). (FILE *f) {
890 try {
891 if (binario_16bitLEcxx . . $ `melder/abcio.cpp:622:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
892 uint16cxx . . $ uint16# s;
893 if (fread (& s, sizeof (uint16cxx . . $ uint16#), 1, f) != 1) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"an unsigned 16-bit integer.");
894 return s; // without sign extension
895 } else {
896 uint8cxx . . $ uint8# bytes [2];
897 if (fread (bytes, sizeof (uint8cxx . . $ uint8#), 2, f) != 2) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"two bytes.");
898 return
899 (uint16cxx . . $ uint16#) ((uint16cxx . . $ uint16#) bytes [1] << 8) |
900 (uint16cxx . . $ uint16#) bytes [0];
901 }
902 } catch (MelderErrorcxx . . $ MelderError#) {
903 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Unsigned integer not read from 2 bytes in binary file.");
904 }
905 }
906
907 int32cxx . . $ int32# bingete16cxx . . $ bingete16(fe4021e40d52d7a9). (FILE *f, int min, int max, conststring32cxx . . $ conststring32# type) {
908 try {
909 int16cxx . . $ int16# result;
910 if (binario_16bitBEcxx . . $ `melder/abcio.cpp:621:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
911 if (fread (& result, sizeof (int16cxx . . $ int16#), 1, f) != 1) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"a signed 16-bit integer.");
912 } else {
913 uint8cxx . . $ uint8# bytes [2];
914 if (fread (bytes, sizeof (uint8cxx . . $ uint8#), 2, f) != 2) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"two bytes.");
915 uint16cxx . . $ uint16# externalValue =
916 (uint16cxx . . $ uint16#) ((uint16cxx . . $ uint16#) bytes [0] << 8) |
917 (uint16cxx . . $ uint16#) bytes [1];
918 result = (int16cxx . . $ int16#) externalValue;
919 }
920 if (result < min || result > max)
921 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (result, U" is not a value of enumerated type \"", type, U"\".");
922 return (int32cxx . . $ int32#) result;
923 } catch (MelderErrorcxx . . $ MelderError#) {
924 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Enumerated value not read from 2 bytes in binary file.");
925 }
926 }
927
928 int32cxx . . $ int32# bingeti24cxx . . $ bingeti24(89bc1efcdac0ca22). (FILE *f) {
929 try {
930 uint8cxx . . $ uint8# bytes [3];
931 if (fread (bytes, sizeof (uint8cxx . . $ uint8#), 3, f) != 3) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"three bytes.");
932 uint32cxx . . $ uint32# externalValue =
933 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [0] << 16) |
934 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [1] << 8) |
935 (uint32cxx . . $ uint32#) bytes [2];
936 if ((bytes [0] & 128) != 0) // is the 24-bit sign bit on?
937 externalValue |= 0xFF00'0000; // extend negative sign to 32 bits
938 return (int32cxx . . $ int32#) externalValue; // reinterpret sign bit
939 } catch (MelderErrorcxx . . $ MelderError#) {
940 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not read from 3 bytes in binary file.");
941 }
942 }
943
944 int32cxx . . $ int32# bingeti24LEcxx . . $ bingeti24LE(89bc1efcdac0ca22). (FILE *f) {
945 try {
946 uint8cxx . . $ uint8# bytes [3];
947 if (fread (bytes, sizeof (uint8cxx . . $ uint8#), 3, f) != 3) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"three bytes.");
948 uint32cxx . . $ uint32# externalValue =
949 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [2] << 16) |
950 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [1] << 8) |
951 (uint32cxx . . $ uint32#) bytes [0];
952 if ((bytes [2] & 128) != 0) // is the 24-bit sign bit on?
953 externalValue |= 0xFF00'0000; // extend negative sign to 32 bits
954 return (int32cxx . . $ int32#) externalValue; // reinterpret sign bit
955 } catch (MelderErrorcxx . . $ MelderError#) {
956 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not read from 3 bytes in binary file.");
957 }
958 }
959
960 int32cxx . . $ int32# bingeti32cxx . . $ bingeti32(89bc1efcdac0ca22). (FILE *f) {
961 try {
962 if (binario_32bitBEcxx . . $ `melder/abcio.cpp:634:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
963 int32cxx . . $ int32# l;
964 if (fread (& l, sizeof (int32cxx . . $ int32#), 1, f) != 1) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"a signed 32-bit integer.");
965 return l;
966 } else {
967 uint8cxx . . $ uint8# bytes [4];
968 if (fread (bytes, sizeof (uint8cxx . . $ uint8#), 4, f) != 4) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"four bytes.");
969 return (int32cxx . . $ int32#)
970 ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [0] << 24) |
971 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [1] << 16) |
972 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [2] << 8) |
973 (uint32cxx . . $ uint32#) bytes [3]);
974 }
975 } catch (MelderErrorcxx . . $ MelderError#) {
976 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not read from 4 bytes in binary file.");
977 }
978 }
979
980 int32cxx . . $ int32# bingeti32LEcxx . . $ bingeti32LE(89bc1efcdac0ca22). (FILE *f) {
981 try {
982 if (binario_32bitLEcxx . . $ `melder/abcio.cpp:635:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
983 int32cxx . . $ int32# l;
984 if (fread (& l, sizeof (int32cxx . . $ int32#), 1, f) != 1) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"a signed 32-bit integer.");
985 return l;
986 } else {
987 uint8cxx . . $ uint8# bytes [4];
988 if (fread (bytes, sizeof (uint8cxx . . $ uint8#), 4, f) != 4) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"four bytes.");
989 return (int32cxx . . $ int32#) // reinterpret sign bit
990 ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [3] << 24) |
991 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [2] << 16) |
992 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [1] << 8) |
993 (uint32cxx . . $ uint32#) bytes [0]);
994 }
995 } catch (MelderErrorcxx . . $ MelderError#) {
996 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not read from 4 bytes in binary file.");
997 }
998 }
999
1000 integercxx . . $ integer# bingetinteger32BEcxx . . $ bingetinteger32BE(1dcafcd8ef4c6e6c). (FILE *f) {
1001 try {
1002 if (binario_32bitBEcxx . . $ `melder/abcio.cpp:634:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
1003 int32cxx . . $ int32# l;
1004 if (fread (& l, sizeof (int32cxx . . $ int32#), 1, f) != 1) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"a signed 32-bit integer.");
1005 return (integercxx . . $ integer#) l;
1006 } else {
1007 uint8cxx . . $ uint8# bytes [4];
1008 if (fread (bytes, sizeof (uint8cxx . . $ uint8#), 4, f) != 4) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"four bytes.");
1009 return (integercxx . . $ integer#) (int32cxx . . $ int32#)
1010 ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [0] << 24) |
1011 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [1] << 16) |
1012 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [2] << 8) |
1013 (uint32cxx . . $ uint32#) bytes [3]);
1014 }
1015 } catch (MelderErrorcxx . . $ MelderError#) {
1016 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not read from 4 bytes in binary file.");
1017 }
1018 }
1019
1020 uint32cxx . . $ uint32# bingetu32cxx . . $ bingetu32(9eef1996c458a0e7). (FILE *f) {
1021 try {
1022 if (binario_32bitBEcxx . . $ `melder/abcio.cpp:634:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
1023 uint32cxx . . $ uint32# l;
1024 if (fread (& l, sizeof (uint32cxx . . $ uint32#), 1, f) != 1) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"an unsigned 32-bit integer.");
1025 return l;
1026 } else {
1027 uint8cxx . . $ uint8# bytes [4];
1028 if (fread (bytes, sizeof (uint8cxx . . $ uint8#), 4, f) != 4) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"four bytes.");
1029 return
1030 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [0] << 24) |
1031 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [1] << 16) |
1032 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [2] << 8) |
1033 (uint32cxx . . $ uint32#) bytes [3];
1034 }
1035 } catch (MelderErrorcxx . . $ MelderError#) {
1036 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Unsigned integer not read from 4 bytes in binary file.");
1037 }
1038 }
1039
1040 uint32cxx . . $ uint32# bingetu32LEcxx . . $ bingetu32LE(9eef1996c458a0e7). (FILE *f) {
1041 try {
1042 if (binario_32bitLEcxx . . $ `melder/abcio.cpp:635:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
1043 uint32cxx . . $ uint32# l;
1044 if (fread (& l, sizeof (uint32cxx . . $ uint32#), 1, f) != 1) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"an unsigned 32-bit integer.");
1045 return l;
1046 } else {
1047 uint8cxx . . $ uint8# bytes [4];
1048 if (fread (bytes, sizeof (uint8cxx . . $ uint8#), 4, f) != 4) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"four bytes.");
1049 return
1050 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [3] << 24) |
1051 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [2] << 16) |
1052 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [1] << 8) |
1053 (uint32cxx . . $ uint32#) bytes [0];
1054 }
1055 } catch (MelderErrorcxx . . $ MelderError#) {
1056 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Unsigned integer not read from 4 bytes in binary file.");
1057 }
1058 }
1059
1060 double bingetr32cxx . . $ bingetr32(aa8fd5995df79f3e). (FILE *f) {
1061 try {
1062 if (binario_floatIEEE4msbcxx . . $ `melder/abcio.cpp:647:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
1063 float x;
1064 if (fread (& x, sizeof (float), 1, f) != 1) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"a 32-bit floating-point number.");
1065 return x;
1066 } else {
1067 uint8cxx . . $ uint8# bytes [4];
1068 if (fread (bytes, sizeof (uint8cxx . . $ uint8#), 4, f) != 4) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"four bytes.");
1069 int32cxx . . $ int32# exponent = (int32cxx . . $ int32#)
1070 ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [0] & 0x0000'007F) << 1) |
1071 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [1] & 0x0000'0080) >> 7)); // between 0 and 255 (it's signed because we're going to subtract something)
1072 uint32cxx . . $ uint32# mantissa =
1073 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [1] & 0x0000'007F) << 16) |
1074 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [2] << 8) |
1075 (uint32cxx . . $ uint32#) bytes [3];
1076 double x;
1077 if (exponent == 0)
1078 if (mantissa == 0) x = 0.0;
1079 else x = ldexpcxx . . $ ldexp(3921ddda63966cf9). ((double) mantissa, exponent - 149); // denormalized
1080 else if (exponent == 0x0000'00FF) // Infinity or Not-a-Number
1081 return undefinedcxx . . $ undefined.;
1082 else // finite
1083 x = ldexpcxx . . $ ldexp(3921ddda63966cf9). ((double) (mantissa | 0x0080'0000), exponent - 150);
1084 return bytes [0] & 0x80 ? - x : x;
1085 }
1086 } catch (MelderErrorcxx . . $ MelderError#) {
1087 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Floating-point number not read from 4 bytes in binary file.");
1088 }
1089 }
1090
1091 double bingetr32LEcxx . . $ bingetr32LE(aa8fd5995df79f3e). (FILE *f) {
1092 try {
1093 if (binario_floatIEEE4lsbcxx . . $ `melder/abcio.cpp:648:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
1094 float x;
1095 if (fread (& x, sizeof (float), 1, f) != 1) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"a 32-bit floating-point number.");
1096 return x;
1097 } else {
1098 uint8cxx . . $ uint8# bytes [4];
1099 if (fread (bytes, sizeof (uint8cxx . . $ uint8#), 4, f) != 4) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"four bytes.");
1100 int32cxx . . $ int32# exponent = (int32cxx . . $ int32#)
1101 ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [3] & 0x0000'007F) << 1) |
1102 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [2] & 0x0000'0080) >> 7));
1103 uint32cxx . . $ uint32# mantissa =
1104 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [2] & 0x0000'007F) << 16) |
1105 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [1] << 8) |
1106 (uint32cxx . . $ uint32#) bytes [0];
1107 double x;
1108 if (exponent == 0)
1109 if (mantissa == 0) x = 0.0;
1110 else x = ldexpcxx . . $ ldexp(3921ddda63966cf9). ((double) mantissa, exponent - 149); // denormalized
1111 else if (exponent == 0x0000'00FF) // Infinity or Not-a-Number
1112 return undefinedcxx . . $ undefined.;
1113 else // finite
1114 x = ldexpcxx . . $ ldexp(3921ddda63966cf9). ((double) (mantissa | 0x0080'0000), exponent - 150);
1115 return bytes [3] & 0x80 ? - x : x;
1116 }
1117 } catch (MelderErrorcxx . . $ MelderError#) {
1118 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Floating-point number not read from 4 bytes in binary file.");
1119 }
1120 }
1121
1122 double bingetr64cxx . . $ bingetr64(aa8fd5995df79f3e). (FILE *f) {
1123 try {
1124 if (binario_doubleIEEE8msbcxx . . $ `melder/abcio.cpp:660:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18) || Melder_debugcxx . . $ Melder_debug. == 181) {
1125 double x;
1126 if (fread (& x, sizeof (double), 1, f) != 1) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"a 64-bit floating-point number.");
1127 return x;
1128 } else {
1129 uint8cxx . . $ uint8# bytes [8];
1130 if (fread (bytes, sizeof (uint8cxx . . $ uint8#), 8, f) != 8) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"eight bytes.");
1131 int32cxx . . $ int32# exponent = (int32cxx . . $ int32#)
1132 ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [0] & 0x0000'007F) << 4) |
1133 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [1] & 0x0000'00F0) >> 4));
1134 uint32cxx . . $ uint32# highMantissa =
1135 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [1] & 0x0000'000F) << 16) |
1136 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [2] << 8) |
1137 (uint32cxx . . $ uint32#) bytes [3];
1138 uint32cxx . . $ uint32# lowMantissa =
1139 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [4] << 24) |
1140 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [5] << 16) |
1141 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [6] << 8) |
1142 (uint32cxx . . $ uint32#) bytes [7];
1143 double x;
1144 if (exponent == 0)
1145 if (highMantissa == 0 && lowMantissa == 0) x = 0.0;
1146 else x = ldexpcxx . . $ ldexp(3921ddda63966cf9). ((double) highMantissa, exponent - 1042) +
1147 ldexpcxx . . $ ldexp(3921ddda63966cf9). ((double) lowMantissa, exponent - 1074); // denormalized
1148 else if (exponent == 0x0000'07FF) // Infinity or Not-a-Number
1149 return undefinedcxx . . $ undefined.;
1150 else
1151 x = ldexpcxx . . $ ldexp(3921ddda63966cf9). ((double) (highMantissa | 0x0010'0000), exponent - 1043) +
1152 ldexpcxx . . $ ldexp(3921ddda63966cf9). ((double) lowMantissa, exponent - 1075);
1153 return bytes [0] & 0x80 ? - x : x;
1154 }
1155 } catch (MelderErrorcxx . . $ MelderError#) {
1156 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Floating-point number not read from 8 bytes in binary file.");
1157 }
1158 }
1159
1160 double bingetr64LEcxx . . $ bingetr64LE(aa8fd5995df79f3e). (FILE *f) {
1161 try {
1162 if (binario_doubleIEEE8lsbcxx . . $ `melder/abcio.cpp:661:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18) || Melder_debugcxx . . $ Melder_debug. == 181) {
1163 double x;
1164 if (fread (& x, sizeof (double), 1, f) != 1) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"a 64-bit floating-point number.");
1165 return x;
1166 } else {
1167 uint8cxx . . $ uint8# bytes [8];
1168 if (fread (bytes, sizeof (uint8cxx . . $ uint8#), 8, f) != 8) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"eight bytes.");
1169 int32cxx . . $ int32# exponent = (int32cxx . . $ int32#)
1170 ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [7] & 0x0000'007F) << 4) |
1171 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [6] & 0x0000'00F0) >> 4));
1172 uint32cxx . . $ uint32# highMantissa =
1173 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [6] & 0x0000'000F) << 16) |
1174 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [5] << 8) |
1175 (uint32cxx . . $ uint32#) bytes [4];
1176 uint32cxx . . $ uint32# lowMantissa =
1177 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [3] << 24) |
1178 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [2] << 16) |
1179 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [1] << 8) |
1180 (uint32cxx . . $ uint32#) bytes [0];
1181 double x;
1182 if (exponent == 0)
1183 if (highMantissa == 0 && lowMantissa == 0) x = 0.0;
1184 else x = ldexpcxx . . $ ldexp(3921ddda63966cf9). ((double) highMantissa, exponent - 1042) +
1185 ldexpcxx . . $ ldexp(3921ddda63966cf9). ((double) lowMantissa, exponent - 1074); // denormalized
1186 else if (exponent == 0x0000'07FF) // Infinity or Not-a-Number
1187 return undefinedcxx . . $ undefined.;
1188 else
1189 x = ldexpcxx . . $ ldexp(3921ddda63966cf9). ((double) (highMantissa | 0x0010'0000), exponent - 1043) +
1190 ldexpcxx . . $ ldexp(3921ddda63966cf9). ((double) lowMantissa, exponent - 1075);
1191 return bytes [7] & 0x80 ? - x : x;
1192 }
1193 } catch (MelderErrorcxx . . $ MelderError#) {
1194 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Floating-point number not read from 8 bytes in binary file.");
1195 }
1196 }
1197
1198 double bingetr80cxx . . $ bingetr80(aa8fd5995df79f3e). (FILE *f) {
1199 try {
1200 uint8cxx . . $ uint8# bytes [10];
1201 if (fread (bytes, sizeof (uint8cxx . . $ uint8#), 10, f) != 10) readErrorcxx . . $ readError(6e3c8643bca295e0). (f, U"ten bytes.");
1202 int32cxx . . $ int32# exponent = (int32cxx . . $ int32#)
1203 ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [0] & 0x0000'007F) << 8) |
1204 (uint32cxx . . $ uint32#) bytes [1]); // between 0 and 32767
1205 uint32cxx . . $ uint32# highMantissa =
1206 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [2] << 24) |
1207 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [3] << 16) |
1208 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [4] << 8) |
1209 (uint32cxx . . $ uint32#) bytes [5];
1210 uint32cxx . . $ uint32# lowMantissa =
1211 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [6] << 24) |
1212 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [7] << 16) |
1213 (uint32cxx . . $ uint32#) ((uint32cxx . . $ uint32#) bytes [8] << 8) |
1214 (uint32cxx . . $ uint32#) bytes [9];
1215 double x;
1216 if (exponent == 0 && highMantissa == 0 && lowMantissa == 0) x = 0.0;
1217 else if (exponent == 0x0000'7FFF) return undefinedcxx . . $ undefined.; // Infinity or NaN
1218 else {
1219 exponent -= 16'383; // between -16'382 and +16'383
1220 x = ldexpcxx . . $ ldexp(3921ddda63966cf9). ((double) highMantissa, exponent - 31);
1221 x += ldexpcxx . . $ ldexp(3921ddda63966cf9). ((double) lowMantissa, exponent - 63);
1222 }
1223 return bytes [0] & 0x80 ? - x : x;
1224 } catch (MelderErrorcxx . . $ MelderError#) {
1225 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Floating-point number not read from 10 bytes in binary file.");
1226 }
1227 }
1228
1229 void binputi16cxx . . $ binputi16(e1ff1cfdb53a1865). (int16cxx . . $ int16# i, FILE *f) {
1230 try {
1231 if (binario_16bitBEcxx . . $ `melder/abcio.cpp:621:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
1232 if (fwrite (& i, sizeof (short), 1, f) != 1)
1233 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"a signed 16-bit integer.");
1234 } else {
1235 uint8cxx . . $ uint8# bytes [2];
1236 bytes [0] = (uint8cxx . . $ uint8#) (i >> 8); // truncate
1237 bytes [1] = (uint8cxx . . $ uint8#) i; // truncate
1238 if (fwrite (bytes, sizeof (uint8cxx . . $ uint8#), 2, f) != 2)
1239 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"two bytes.");
1240 }
1241 } catch (MelderErrorcxx . . $ MelderError#) {
1242 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not written to 2 bytes in binary file.");
1243 }
1244 }
1245
1246 void binputi16LEcxx . . $ binputi16LE(e1ff1cfdb53a1865). (int16cxx . . $ int16# i, FILE *f) {
1247 try {
1248 if (binario_16bitLEcxx . . $ `melder/abcio.cpp:622:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
1249 if (fwrite (& i, sizeof (short), 1, f) != 1)
1250 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"a signed 16-bit integer.");
1251 } else {
1252 uint8cxx . . $ uint8# bytes [2];
1253 bytes [1] = (uint8cxx . . $ uint8#) (i >> 8); // truncate
1254 bytes [0] = (uint8cxx . . $ uint8#) i; // truncate
1255 if (fwrite (bytes, sizeof (uint8cxx . . $ uint8#), 2, f) != 2)
1256 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"two bytes.");
1257 }
1258 } catch (MelderErrorcxx . . $ MelderError#) {
1259 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not written to 2 bytes in binary file.");
1260 }
1261 }
1262
1263 void binputinteger16BEcxx . . $ binputinteger16BE(791c91cccf3dbd31). (integercxx . . $ integer# i, FILE *f) {
1264 try {
1265 if (i < INT16_MINcxx . . $ `<external>/3415975807581488833/stdint.h:106:10`! || i > INT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:111:10`!)
1266 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The number ", i, U" is too big to fit into 16 bits."); // this will change in the future
1267 uint8cxx . . $ uint8# bytes [2];
1268 bytes [0] = (uint8cxx . . $ uint8#) (i >> 8); // truncate
1269 bytes [1] = (uint8cxx . . $ uint8#) i; // truncate
1270 if (fwrite (bytes, sizeof (uint8cxx . . $ uint8#), 2, f) != 2)
1271 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"two bytes.");
1272 } catch (MelderErrorcxx . . $ MelderError#) {
1273 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not written to 2 bytes in binary file.");
1274 }
1275 }
1276
1277 void binputu16cxx . . $ binputu16(d4e8792de0db7e67). (uint16cxx . . $ uint16# u, FILE *f) {
1278 try {
1279 if (binario_16bitBEcxx . . $ `melder/abcio.cpp:621:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
1280 if (fwrite (& u, sizeof (uint16cxx . . $ uint16#), 1, f) != 1)
1281 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"an unsigned 16-bit integer.");
1282 } else {
1283 uint8cxx . . $ uint8# bytes [2];
1284 bytes [0] = (uint8cxx . . $ uint8#) (u >> 8); // truncate
1285 bytes [1] = (uint8cxx . . $ uint8#) u; // truncate
1286 if (fwrite (bytes, sizeof (uint8cxx . . $ uint8#), 2, f) != 2)
1287 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"two bytes.");
1288 }
1289 } catch (MelderErrorcxx . . $ MelderError#) {
1290 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Unsigned integer not written to 2 bytes in binary file.");
1291 }
1292 }
1293
1294 void binputu16LEcxx . . $ binputu16LE(d4e8792de0db7e67). (uint16cxx . . $ uint16# u, FILE *f) {
1295 try {
1296 if (binario_16bitLEcxx . . $ `melder/abcio.cpp:622:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
1297 if (fwrite (& u, sizeof (uint16cxx . . $ uint16#), 1, f) != 1)
1298 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"an unsigned 16-bit integer.");
1299 } else {
1300 uint8cxx . . $ uint8# bytes [2];
1301 bytes [1] = (uint8cxx . . $ uint8#) (u >> 8); // truncate
1302 bytes [0] = (uint8cxx . . $ uint8#) u; // truncate
1303 if (fwrite (bytes, sizeof (uint8cxx . . $ uint8#), 2, f) != 2)
1304 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"two bytes.");
1305 }
1306 } catch (MelderErrorcxx . . $ MelderError#) {
1307 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Unsigned integer not written to 2 bytes in binary file.");
1308 }
1309 }
1310
1311 void binpute16cxx . . $ binpute16(44487f0f82292376). (int32cxx . . $ int32# value, FILE *f) {
1312 try {
1313 if (binario_16bitBEcxx . . $ `melder/abcio.cpp:621:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
1314 short s = value;
1315 if (fwrite (& s, sizeof (short), 1, f) != 1)
1316 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"a signed 16-bit integer");
1317 } else {
1318 uint8cxx . . $ uint8# bytes [2];
1319 bytes [0] = (uint8cxx . . $ uint8#) (value >> 8); // truncate
1320 bytes [1] = (uint8cxx . . $ uint8#) value; // truncate
1321 if (fwrite (bytes, sizeof (uint8cxx . . $ uint8#), 2, f) != 2)
1322 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"two bytes.");
1323 }
1324 } catch (MelderErrorcxx . . $ MelderError#) {
1325 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Enumerated value not written to 2 bytes in binary file.");
1326 }
1327 }
1328
1329 void binputi24cxx . . $ binputi24(44487f0f82292376). (int32cxx . . $ int32# i, FILE *f) {
1330 try {
1331 uint8cxx . . $ uint8# bytes [3];
1332 bytes [0] = (uint8cxx . . $ uint8#) (i >> 16); // truncate
1333 bytes [1] = (uint8cxx . . $ uint8#) (i >> 8); // truncate
1334 bytes [2] = (uint8cxx . . $ uint8#) i; // truncate
1335 if (fwrite (bytes, sizeof (uint8cxx . . $ uint8#), 3, f) != 3)
1336 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"three bytes");
1337 } catch (MelderErrorcxx . . $ MelderError#) {
1338 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not written to 3 bytes in binary file.");
1339 }
1340 }
1341
1342 void binputi24LEcxx . . $ binputi24LE(44487f0f82292376). (int32cxx . . $ int32# i, FILE *f) {
1343 try {
1344 uint8cxx . . $ uint8# bytes [3];
1345 bytes [2] = (uint8cxx . . $ uint8#) (i >> 16); // truncate
1346 bytes [1] = (uint8cxx . . $ uint8#) (i >> 8); // truncate
1347 bytes [0] = (uint8cxx . . $ uint8#) i; // truncate
1348 if (fwrite (bytes, sizeof (uint8cxx . . $ uint8#), 3, f) != 3)
1349 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"three bytes");
1350 } catch (MelderErrorcxx . . $ MelderError#) {
1351 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not written to 3 bytes in binary file.");
1352 }
1353 }
1354
1355 void binputi32cxx . . $ binputi32(44487f0f82292376). (int32cxx . . $ int32# i, FILE *f) {
1356 try {
1357 if (binario_32bitBEcxx . . $ `melder/abcio.cpp:634:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
1358 if (fwrite (& i, sizeof (int32cxx . . $ int32#), 1, f) != 1)
1359 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"a signed 32-bit integer.");
1360 } else {
1361 uint8cxx . . $ uint8# bytes [4];
1362 bytes [0] = (uint8cxx . . $ uint8#) (i >> 24); // truncate
1363 bytes [1] = (uint8cxx . . $ uint8#) (i >> 16); // truncate
1364 bytes [2] = (uint8cxx . . $ uint8#) (i >> 8); // truncate
1365 bytes [3] = (uint8cxx . . $ uint8#) i; // truncate
1366 if (fwrite (bytes, sizeof (uint8cxx . . $ uint8#), 4, f) != 4)
1367 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"four bytes.");
1368 }
1369 } catch (MelderErrorcxx . . $ MelderError#) {
1370 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not written to 4 bytes in binary file.");
1371 }
1372 }
1373
1374 void binputi32LEcxx . . $ binputi32LE(44487f0f82292376). (int32cxx . . $ int32# i, FILE *f) {
1375 try {
1376 if (binario_32bitLEcxx . . $ `melder/abcio.cpp:635:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
1377 if (fwrite (& i, sizeof (int32cxx . . $ int32#), 1, f) != 1)
1378 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"a signed 32-bit integer.");
1379 } else {
1380 uint8cxx . . $ uint8# bytes [4];
1381 bytes [3] = (uint8cxx . . $ uint8#) (i >> 24); // truncate
1382 bytes [2] = (uint8cxx . . $ uint8#) (i >> 16); // truncate
1383 bytes [1] = (uint8cxx . . $ uint8#) (i >> 8); // truncate
1384 bytes [0] = (uint8cxx . . $ uint8#) i; // truncate
1385 if (fwrite (bytes, sizeof (uint8cxx . . $ uint8#), 4, f) != 4)
1386 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"four bytes.");
1387 }
1388 } catch (MelderErrorcxx . . $ MelderError#) {
1389 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not written to 4 bytes in binary file.");
1390 }
1391 }
1392
1393 void binputinteger32BEcxx . . $ binputinteger32BE(791c91cccf3dbd31). (integercxx . . $ integer# i, FILE *f) {
1394 try {
1395 if (i < INT32_MINcxx . . $ `<external>/3415975807581488833/stdint.h:107:10`! || i > INT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:112:10`!)
1396 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The number ", i, U" is too big to fit into 32 bits."); // this will change in the future
1397 uint8cxx . . $ uint8# bytes [4];
1398 bytes [0] = (uint8cxx . . $ uint8#) (i >> 24); // truncate
1399 bytes [1] = (uint8cxx . . $ uint8#) (i >> 16); // truncate
1400 bytes [2] = (uint8cxx . . $ uint8#) (i >> 8); // truncate
1401 bytes [3] = (uint8cxx . . $ uint8#) i; // truncate
1402 if (fwrite (bytes, sizeof (uint8cxx . . $ uint8#), 4, f) != 4)
1403 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"a signed 32-bit integer.");
1404 } catch (MelderErrorcxx . . $ MelderError#) {
1405 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Signed integer not written to 4 bytes in binary file.");
1406 }
1407 }
1408
1409 void binputu32cxx . . $ binputu32(60af6e60da050086). (uint32cxx . . $ uint32# u, FILE *f) {
1410 try {
1411 if (binario_32bitBEcxx . . $ `melder/abcio.cpp:634:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
1412 if (fwrite (& u, sizeof (uint32cxx . . $ uint32#), 1, f) != 1)
1413 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"an unsigned 32-bit integer.");
1414 } else {
1415 uint8cxx . . $ uint8# bytes [4];
1416 bytes [0] = (uint8cxx . . $ uint8#) (u >> 24); // truncate
1417 bytes [1] = (uint8cxx . . $ uint8#) (u >> 16); // truncate
1418 bytes [2] = (uint8cxx . . $ uint8#) (u >> 8); // truncate
1419 bytes [3] = (uint8cxx . . $ uint8#) u; // truncate
1420 if (fwrite (bytes, sizeof (uint8cxx . . $ uint8#), 4, f) != 4)
1421 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"four bytes.");
1422 }
1423 } catch (MelderErrorcxx . . $ MelderError#) {
1424 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Unsigned integer not written to 4 bytes in binary file.");
1425 }
1426 }
1427
1428 void binputu32LEcxx . . $ binputu32LE(60af6e60da050086). (uint32cxx . . $ uint32# u, FILE *f) {
1429 try {
1430 if (binario_32bitLEcxx . . $ `melder/abcio.cpp:635:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
1431 if (fwrite (& u, sizeof (uint32cxx . . $ uint32#), 1, f) != 1)
1432 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"an unsigned 32-bit integer.");
1433 } else {
1434 uint8cxx . . $ uint8# bytes [4];
1435 bytes [3] = (uint8cxx . . $ uint8#) (u >> 24); // truncate
1436 bytes [2] = (uint8cxx . . $ uint8#) (u >> 16); // truncate
1437 bytes [1] = (uint8cxx . . $ uint8#) (u >> 8); // truncate
1438 bytes [0] = (uint8cxx . . $ uint8#) u; // truncate
1439 if (fwrite (bytes, sizeof (uint8cxx . . $ uint8#), 4, f) != 4)
1440 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"four bytes.");
1441 }
1442 } catch (MelderErrorcxx . . $ MelderError#) {
1443 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Unsigned integer not written to 4 bytes in binary file.");
1444 }
1445 }
1446
1447 void binputr32cxx . . $ binputr32(e2d746ffb56c4827). (double x, FILE *f) {
1448 try {
1449 if (binario_floatIEEE4msbcxx . . $ `melder/abcio.cpp:647:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
1450 float x32 = (float) x; // convert down, with loss of precision
1451 if (fwrite (& x32, sizeof (float), 1, f) != 1)
1452 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"a 32-bit floating-point number.");
1453 } else {
1454 uint8cxx . . $ uint8# bytes [4];
1455 int sign, exponent;
1456 double fMantissa, fsMantissa;
1457 uint32cxx . . $ uint32# mantissa;
1458 if (x < 0.0) {
1459 sign = 0x0100;
1460 x *= -1.0;
1461 } else
1462 sign = 0;
1463 if (x == 0.0) {
1464 exponent = 0;
1465 mantissa = 0;
1466 } else {
1467 fMantissa = frexpcxx . . $ frexp(b891564ff5c4b95f). (x, & exponent);
1468 if ((exponent > 128) || ! (fMantissa < 1.0)) // Infinity or Not-a-Number
1469 { exponent = sign | 0x00FF; mantissa = 0; } // Infinity
1470 else { // finite
1471 exponent += 126; // add bias
1472 if (exponent <= 0) { // denormalized
1473 fMantissa = ldexpcxx . . $ ldexp(3921ddda63966cf9). (fMantissa, exponent - 1);
1474 exponent = 0;
1475 }
1476 exponent |= sign;
1477 fMantissa = ldexpcxx . . $ ldexp(3921ddda63966cf9). (fMantissa, 24);
1478 fsMantissa = floorcxx . . $ floor(fee4f1d22bc8e617). (fMantissa);
1479 mantissa = (uint32cxx . . $ uint32#) fsMantissa & 0x007FFFFF;
1480 }
1481 }
1482 bytes [0] = (uint8cxx . . $ uint8#) (exponent >> 1); // truncate: bits 2 through 9 (bit 9 is the sign bit)
1483 bytes [1] = (uint8cxx . . $ uint8#) ((exponent << 7) | (mantissa >> 16)); // truncate
1484 bytes [2] = (uint8cxx . . $ uint8#) (mantissa >> 8); // truncate
1485 bytes [3] = (uint8cxx . . $ uint8#) mantissa; // truncate
1486 if (fwrite (bytes, sizeof (uint8cxx . . $ uint8#), 4, f) != 4)
1487 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"four bytes.");
1488 }
1489 } catch (MelderErrorcxx . . $ MelderError#) {
1490 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Floating-point number not written to 4 bytes in binary file.");
1491 }
1492 }
1493
1494 void binputr32LEcxx . . $ binputr32LE(e2d746ffb56c4827). (double x, FILE *f) {
1495 try {
1496 if (binario_floatIEEE4lsbcxx . . $ `melder/abcio.cpp:648:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
1497 float x32 = (float) x; // convert down, with loss of precision
1498 if (fwrite (& x32, sizeof (float), 1, f) != 1)
1499 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"a 32-bit floating-point number.");
1500 } else {
1501 uint8cxx . . $ uint8# bytes [4];
1502 int sign, exponent;
1503 double fMantissa, fsMantissa;
1504 uint32cxx . . $ uint32# mantissa;
1505 if (x < 0.0) {
1506 sign = 0x0100;
1507 x *= -1.0;
1508 } else
1509 sign = 0;
1510 if (x == 0.0) {
1511 exponent = 0;
1512 mantissa = 0;
1513 } else {
1514 fMantissa = frexpcxx . . $ frexp(b891564ff5c4b95f). (x, & exponent);
1515 if ((exponent > 128) || ! (fMantissa < 1.0)) // Infinity or Not-a-Number
1516 { exponent = sign | 0x00FF; mantissa = 0; } // Infinity
1517 else { // finite
1518 exponent += 126; // add bias
1519 if (exponent <= 0) { // denormalized
1520 fMantissa = ldexpcxx . . $ ldexp(3921ddda63966cf9). (fMantissa, exponent - 1);
1521 exponent = 0;
1522 }
1523 exponent |= sign;
1524 fMantissa = ldexpcxx . . $ ldexp(3921ddda63966cf9). (fMantissa, 24);
1525 fsMantissa = floorcxx . . $ floor(fee4f1d22bc8e617). (fMantissa);
1526 mantissa = (uint32cxx . . $ uint32#) fsMantissa & 0x007F'FFFF;
1527 }
1528 }
1529 bytes [3] = (uint8cxx . . $ uint8#) (exponent >> 1);
1530 bytes [2] = (uint8cxx . . $ uint8#) ((exponent << 7) | (mantissa >> 16));
1531 bytes [1] = (uint8cxx . . $ uint8#) (mantissa >> 8);
1532 bytes [0] = (uint8cxx . . $ uint8#) mantissa;
1533 if (fwrite (bytes, sizeof (uint8cxx . . $ uint8#), 4, f) != 4)
1534 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"four bytes.");
1535 }
1536 } catch (MelderErrorcxx . . $ MelderError#) {
1537 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Floating-point number not written to 4 bytes in binary file.");
1538 }
1539 }
1540
1541 void binputr64cxx . . $ binputr64(e2d746ffb56c4827). (double x, FILE *f) {
1542 try {
1543 if (binario_doubleIEEE8msbcxx . . $ `melder/abcio.cpp:660:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18) || Melder_debugcxx . . $ Melder_debug. == 181) {
1544 if (fwrite (& x, sizeof (double), 1, f) != 1)
1545 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"a 64-bit floating-point number.");
1546 } else if (binario_doubleIEEE8lsbcxx . . $ `melder/abcio.cpp:661:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
1547 unioncxx . . $ binputr64(e2d746ffb56c4827).$anonymous_type_0# { double xxcxx . . $ binputr64(e2d746ffb56c4827).$anonymous_type_0#xx.; uint8cxx . . $ uint8# bytescxx . . $ binputr64(e2d746ffb56c4827).$anonymous_type_0#bytes. [8]; };
1548 xxcxx . . $ binputr64(e2d746ffb56c4827).$anonymous_type_0#xx. = x;
1549 stdcxx . . $ std/::swapcxx . . $ std/swap(c75b8fd57d7c2e06). (bytescxx . . $ binputr64(e2d746ffb56c4827).$anonymous_type_0#bytes. [0], bytescxx . . $ binputr64(e2d746ffb56c4827).$anonymous_type_0#bytes. [7]);
1550 stdcxx . . $ std/::swapcxx . . $ std/swap(c75b8fd57d7c2e06). (bytescxx . . $ binputr64(e2d746ffb56c4827).$anonymous_type_0#bytes. [1], bytescxx . . $ binputr64(e2d746ffb56c4827).$anonymous_type_0#bytes. [6]);
1551 stdcxx . . $ std/::swapcxx . . $ std/swap(c75b8fd57d7c2e06). (bytescxx . . $ binputr64(e2d746ffb56c4827).$anonymous_type_0#bytes. [2], bytescxx . . $ binputr64(e2d746ffb56c4827).$anonymous_type_0#bytes. [5]);
1552 stdcxx . . $ std/::swapcxx . . $ std/swap(c75b8fd57d7c2e06). (bytescxx . . $ binputr64(e2d746ffb56c4827).$anonymous_type_0#bytes. [3], bytescxx . . $ binputr64(e2d746ffb56c4827).$anonymous_type_0#bytes. [4]);
1553 if (fwrite (& xxcxx . . $ binputr64(e2d746ffb56c4827).$anonymous_type_0#xx., sizeof (double), 1, f) != 1)
1554 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"a 64-bit floating-point number.");
1555 } else {
1556 uint8cxx . . $ uint8# bytes [8];
1557 int sign, exponent;
1558 double fMantissa, fsMantissa;
1559 uint32cxx . . $ uint32# highMantissa, lowMantissa;
1560 if (x < 0.0) {
1561 sign = 0x0800;
1562 x *= -1.0;
1563 } else
1564 sign = 0;
1565 if (x == 0.0) {
1566 exponent = 0;
1567 highMantissa = 0;
1568 lowMantissa = 0;
1569 } else {
1570 fMantissa = frexpcxx . . $ frexp(b891564ff5c4b95f). (x, & exponent);
1571 if (/*(exponent > 1024) ||*/ ! (fMantissa < 1.0)) // Infinity or Not-a-Number
1572 { exponent = sign | 0x07FF; highMantissa = 0; lowMantissa = 0; } // Infinity
1573 else { // finite
1574 exponent += 1022; // add bias
1575 if (exponent <= 0) { // denormalized
1576 fMantissa = ldexpcxx . . $ ldexp(3921ddda63966cf9). (fMantissa, exponent - 1);
1577 exponent = 0;
1578 }
1579 exponent |= sign;
1580 fMantissa = ldexpcxx . . $ ldexp(3921ddda63966cf9). (fMantissa, 21);
1581 fsMantissa = floorcxx . . $ floor(fee4f1d22bc8e617). (fMantissa);
1582 highMantissa = (uint32cxx . . $ uint32#) fsMantissa & 0x000F'FFFF;
1583 fMantissa = ldexpcxx . . $ ldexp(3921ddda63966cf9). (fMantissa - fsMantissa, 32);
1584 fsMantissa = floorcxx . . $ floor(fee4f1d22bc8e617). (fMantissa);
1585 lowMantissa = (uint32cxx . . $ uint32#) fsMantissa;
1586 }
1587 }
1588 bytes [0] = (uint8cxx . . $ uint8#) (exponent >> 4);
1589 bytes [1] = (uint8cxx . . $ uint8#) ((exponent << 4) | (highMantissa >> 16));
1590 bytes [2] = (uint8cxx . . $ uint8#) (highMantissa >> 8);
1591 bytes [3] = (uint8cxx . . $ uint8#) highMantissa;
1592 bytes [4] = (uint8cxx . . $ uint8#) (lowMantissa >> 24);
1593 bytes [5] = (uint8cxx . . $ uint8#) (lowMantissa >> 16);
1594 bytes [6] = (uint8cxx . . $ uint8#) (lowMantissa >> 8);
1595 bytes [7] = (uint8cxx . . $ uint8#) lowMantissa;
1596 if (fwrite (bytes, sizeof (uint8cxx . . $ uint8#), 8, f) != 8)
1597 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"eight bytes.");
1598 }
1599 } catch (MelderErrorcxx . . $ MelderError#) {
1600 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Floating-point number not written to 8 bytes in binary file.");
1601 }
1602 }
1603
1604 void binputr64LEcxx . . $ binputr64LE(e2d746ffb56c4827). (double x, FILE *f) {
1605 try {
1606 if (binario_doubleIEEE8lsbcxx . . $ `melder/abcio.cpp:661:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18) || Melder_debugcxx . . $ Melder_debug. == 181) {
1607 if (fwrite (& x, sizeof (double), 1, f) != 1)
1608 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"a 64-bit floating-point number.");
1609 } else if (binario_doubleIEEE8msbcxx . . $ `melder/abcio.cpp:660:10`! && ! (Melder_debugcxx . . $ Melder_debug. == 18)) {
1610 unioncxx . . $ binputr64LE(e2d746ffb56c4827).$anonymous_type_1# { double xxcxx . . $ binputr64LE(e2d746ffb56c4827).$anonymous_type_1#xx.; uint8cxx . . $ uint8# bytescxx . . $ binputr64LE(e2d746ffb56c4827).$anonymous_type_1#bytes. [8]; };
1611 xxcxx . . $ binputr64LE(e2d746ffb56c4827).$anonymous_type_1#xx. = x;
1612 stdcxx . . $ std/::swapcxx . . $ std/swap(c75b8fd57d7c2e06). (bytescxx . . $ binputr64LE(e2d746ffb56c4827).$anonymous_type_1#bytes. [0], bytescxx . . $ binputr64LE(e2d746ffb56c4827).$anonymous_type_1#bytes. [7]);
1613 stdcxx . . $ std/::swapcxx . . $ std/swap(c75b8fd57d7c2e06). (bytescxx . . $ binputr64LE(e2d746ffb56c4827).$anonymous_type_1#bytes. [1], bytescxx . . $ binputr64LE(e2d746ffb56c4827).$anonymous_type_1#bytes. [6]);
1614 stdcxx . . $ std/::swapcxx . . $ std/swap(c75b8fd57d7c2e06). (bytescxx . . $ binputr64LE(e2d746ffb56c4827).$anonymous_type_1#bytes. [2], bytescxx . . $ binputr64LE(e2d746ffb56c4827).$anonymous_type_1#bytes. [5]);
1615 stdcxx . . $ std/::swapcxx . . $ std/swap(c75b8fd57d7c2e06). (bytescxx . . $ binputr64LE(e2d746ffb56c4827).$anonymous_type_1#bytes. [3], bytescxx . . $ binputr64LE(e2d746ffb56c4827).$anonymous_type_1#bytes. [4]);
1616 if (fwrite (& xxcxx . . $ binputr64LE(e2d746ffb56c4827).$anonymous_type_1#xx., sizeof (double), 1, f) != 1)
1617 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"a 64-bit floating-point number.");
1618 } else {
1619 uint8cxx . . $ uint8# bytes [8];
1620 int sign, exponent;
1621 double fMantissa, fsMantissa;
1622 uint32cxx . . $ uint32# highMantissa, lowMantissa;
1623 if (x < 0.0) {
1624 sign = 0x0800;
1625 x *= -1.0;
1626 } else
1627 sign = 0;
1628 if (x == 0.0) {
1629 exponent = 0;
1630 highMantissa = 0;
1631 lowMantissa = 0;
1632 } else {
1633 fMantissa = frexpcxx . . $ frexp(b891564ff5c4b95f). (x, & exponent);
1634 if (/*(exponent > 1024) ||*/ ! (fMantissa < 1.0)) // Infinity or Not-a-Number
1635 { exponent = sign | 0x07FF; highMantissa = 0; lowMantissa = 0; } // Infinity
1636 else { // finite
1637 exponent += 1022; // add bias
1638 if (exponent <= 0) { // denormalized
1639 fMantissa = ldexpcxx . . $ ldexp(3921ddda63966cf9). (fMantissa, exponent - 1);
1640 exponent = 0;
1641 }
1642 exponent |= sign;
1643 fMantissa = ldexpcxx . . $ ldexp(3921ddda63966cf9). (fMantissa, 21);
1644 fsMantissa = floorcxx . . $ floor(fee4f1d22bc8e617). (fMantissa);
1645 highMantissa = (uint32cxx . . $ uint32#) fsMantissa & 0x000F'FFFF;
1646 fMantissa = ldexpcxx . . $ ldexp(3921ddda63966cf9). (fMantissa - fsMantissa, 32);
1647 fsMantissa = floorcxx . . $ floor(fee4f1d22bc8e617). (fMantissa);
1648 lowMantissa = (uint32cxx . . $ uint32#) fsMantissa;
1649 }
1650 }
1651 bytes [7] = (uint8cxx . . $ uint8#) (exponent >> 4);
1652 bytes [6] = (uint8cxx . . $ uint8#) ((exponent << 4) | (highMantissa >> 16));
1653 bytes [5] = (uint8cxx . . $ uint8#) (highMantissa >> 8);
1654 bytes [4] = (uint8cxx . . $ uint8#) highMantissa;
1655 bytes [3] = (uint8cxx . . $ uint8#) (lowMantissa >> 24);
1656 bytes [2] = (uint8cxx . . $ uint8#) (lowMantissa >> 16);
1657 bytes [1] = (uint8cxx . . $ uint8#) (lowMantissa >> 8);
1658 bytes [0] = (uint8cxx . . $ uint8#) lowMantissa;
1659 if (fwrite (bytes, sizeof (uint8cxx . . $ uint8#), 8, f) != 8)
1660 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"eight bytes.");
1661 }
1662 } catch (MelderErrorcxx . . $ MelderError#) {
1663 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Floating-point number not written to 8 bytes in binary file.");
1664 }
1665 }
1666
1667 void binputr80cxx . . $ binputr80(e2d746ffb56c4827). (double x, FILE *f) {
1668 try {
1669 uint8cxx . . $ uint8# bytes [10];
1670 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (sizeof (int) > 2);
1671 int sign, exponent; // these should be uint16, but frexp() expects an int
1672 double fMantissa, fsMantissa;
1673 uint32cxx . . $ uint32# highMantissa, lowMantissa;
1674 if (x < 0.0) {
1675 sign = 0x8000;
1676 x *= -1.0;
1677 } else
1678 sign = 0;
1679 if (x == 0.0) {
1680 exponent = 0;
1681 highMantissa = 0;
1682 lowMantissa = 0;
1683 } else {
1684 fMantissa = frexpcxx . . $ frexp(b891564ff5c4b95f). (x, & exponent);
1685 if ((exponent > 16384) || ! (fMantissa < 1.0)) // Infinity or Not-a-Number
1686 { exponent = sign | 0x7FFF; highMantissa = 0; lowMantissa = 0; } // Infinity
1687 else { // finite
1688 exponent += 16382; // add bias
1689 if (exponent < 0) { // denormalized
1690 fMantissa = ldexpcxx . . $ ldexp(3921ddda63966cf9). (fMantissa, exponent);
1691 exponent = 0;
1692 }
1693 exponent |= sign;
1694 fMantissa = ldexpcxx . . $ ldexp(3921ddda63966cf9). (fMantissa, 32);
1695 fsMantissa = floorcxx . . $ floor(fee4f1d22bc8e617). (fMantissa);
1696 highMantissa = (uint32cxx . . $ uint32#) fsMantissa;
1697 fMantissa = ldexpcxx . . $ ldexp(3921ddda63966cf9). (fMantissa - fsMantissa, 32);
1698 fsMantissa = floorcxx . . $ floor(fee4f1d22bc8e617). (fMantissa);
1699 lowMantissa = (uint32cxx . . $ uint32#) fsMantissa;
1700 }
1701 }
1702 bytes [0] = (uint8cxx . . $ uint8#) (exponent >> 8);
1703 bytes [1] = (uint8cxx . . $ uint8#) exponent;
1704 bytes [2] = (uint8cxx . . $ uint8#) (highMantissa >> 24);
1705 bytes [3] = (uint8cxx . . $ uint8#) (highMantissa >> 16);
1706 bytes [4] = (uint8cxx . . $ uint8#) (highMantissa >> 8);
1707 bytes [5] = (uint8cxx . . $ uint8#) highMantissa;
1708 bytes [6] = (uint8cxx . . $ uint8#) (lowMantissa >> 24);
1709 bytes [7] = (uint8cxx . . $ uint8#) (lowMantissa >> 16);
1710 bytes [8] = (uint8cxx . . $ uint8#) (lowMantissa >> 8);
1711 bytes [9] = (uint8cxx . . $ uint8#) lowMantissa;
1712 if (fwrite (bytes, sizeof (uint8cxx . . $ uint8#), 10, f) != 10)
1713 writeErrorcxx . . $ writeError(ff00d524ab0355ec). (U"ten bytes.");
1714 } catch (MelderErrorcxx . . $ MelderError#) {
1715 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Floating-point number not written to 10 bytes in binary file.");
1716 }
1717 }
1718
1719 dcomplexcxx . . $ dcomplex# bingetc64cxx . . $ bingetc64(24e0806e0c5ce92). (FILE *f) {
1720 try {
1721 dcomplexcxx . . $ dcomplex# resultcxx . . $ std/complex#complex(bc12c9ec15586e6a).;
1722 result. realcxx . . $ std/complex#real(ba8836b59fb42830). (bingetr32cxx . . $ bingetr32(aa8fd5995df79f3e). (f));
1723 result. imagcxx . . $ std/complex#imag(ba8836b59fb42830). (bingetr32cxx . . $ bingetr32(aa8fd5995df79f3e). (f));
1724 return resultcxx . . $ std/complex#complex(20ef1611af677bca).;
1725 } catch (MelderErrorcxx . . $ MelderError#) {
1726 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Complex number not read from 8 bytes in binary file.");
1727 dcomplexcxx . . $ dcomplex# resultcxx . . $ std/complex#complex(bc12c9ec15586e6a). { };
1728 return resultcxx . . $ std/complex#complex(20ef1611af677bca).;
1729 }
1730 }
1731
1732 dcomplexcxx . . $ dcomplex# bingetc128cxx . . $ bingetc128(24e0806e0c5ce92). (FILE *f) {
1733 try {
1734 dcomplexcxx . . $ dcomplex# resultcxx . . $ std/complex#complex(bc12c9ec15586e6a).;
1735 result. realcxx . . $ std/complex#real(ba8836b59fb42830). (bingetr64cxx . . $ bingetr64(aa8fd5995df79f3e). (f));
1736 result. imagcxx . . $ std/complex#imag(ba8836b59fb42830). (bingetr64cxx . . $ bingetr64(aa8fd5995df79f3e). (f));
1737 return resultcxx . . $ std/complex#complex(20ef1611af677bca).;
1738 } catch (MelderErrorcxx . . $ MelderError#) {
1739 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Complex number not read from 16 bytes in binary file.");
1740 dcomplexcxx . . $ dcomplex# resultcxx . . $ std/complex#complex(bc12c9ec15586e6a). { };
1741 return resultcxx . . $ std/complex#complex(20ef1611af677bca).;
1742 }
1743 }
1744
1745 void binputc64cxx . . $ binputc64(61b44fec29a2c39b). (dcomplexcxx . . $ dcomplex# z, FILE *f) {
1746 try {
1747 binputr32cxx . . $ binputr32(e2d746ffb56c4827). (z.realcxx . . $ std/complex#real(21b6c25e127938e2).(), f);
1748 binputr32cxx . . $ binputr32(e2d746ffb56c4827). (z.imagcxx . . $ std/complex#imag(21b6c25e127938e2).(), f);
1749 } catch (MelderErrorcxx . . $ MelderError#) {
1750 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Complex number not written to 8 bytes in binary file.");
1751 }
1752 }
1753
1754 void binputc128cxx . . $ binputc128(61b44fec29a2c39b). (dcomplexcxx . . $ dcomplex# z, FILE *f) {
1755 try {
1756 binputr64cxx . . $ binputr64(e2d746ffb56c4827). (z.realcxx . . $ std/complex#real(21b6c25e127938e2).(), f);
1757 binputr64cxx . . $ binputr64(e2d746ffb56c4827). (z.imagcxx . . $ std/complex#imag(21b6c25e127938e2).(), f);
1758 } catch (MelderErrorcxx . . $ MelderError#) {
1759 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Complex number not written to 16 bytes in binary file.");
1760 }
1761 }
1762
1763 autostring8cxx . . $ autostring8# bingets8cxx . . $ bingets8(5a336ef3276fb3b5). (FILE *f) {
1764 try {
1765 uint32cxx . . $ uint32# length = bingetu8cxx . . $ bingetu8(9eef1996c458a0e7). (f);
1766 autostring8cxx . . $ autostring8# resultcxx . . $ _autostring#_autostring(f153f132b2bc41c2). (length);
1767 if (fread (result.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), sizeof (char), length, f) != length)
1768 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (feof (f) ? U"Reached end of file" : U"Error in file", U" while trying to read ", length, U" one-byte characters.");
1769 result [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).length] = 0; // trailing null byte
1770 return resultcxx . . $ _autostring#_autostring(39021ecceedcc7d2).;
1771 } catch (MelderErrorcxx . . $ MelderError#) {
1772 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Text not read from a binary file.");
1773 }
1774 }
1775
1776 autostring8cxx . . $ autostring8# bingets16cxx . . $ bingets16(5a336ef3276fb3b5). (FILE *f) {
1777 try {
1778 uint16cxx . . $ uint16# length = bingetu16cxx . . $ bingetu16(38a7f6633dfbdb53). (f);
1779 autostring8cxx . . $ autostring8# resultcxx . . $ _autostring#_autostring(f153f132b2bc41c2). (length);
1780 if (fread (result.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), sizeof (char), length, f) != length)
1781 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (feof (f) ? U"Reached end of file" : U"Error in file", U" while trying to read ", length, U" one-byte characters.");
1782 result [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).length] = 0; // trailing null byte
1783 return resultcxx . . $ _autostring#_autostring(39021ecceedcc7d2).;
1784 } catch (MelderErrorcxx . . $ MelderError#) {
1785 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Text not read from a binary file.");
1786 }
1787 }
1788
1789 autostring8cxx . . $ autostring8# bingets32cxx . . $ bingets32(5a336ef3276fb3b5). (FILE *f) {
1790 try {
1791 uint32cxx . . $ uint32# length = bingetu32cxx . . $ bingetu32(9eef1996c458a0e7). (f);
1792 autostring8cxx . . $ autostring8# resultcxx . . $ _autostring#_autostring(f153f132b2bc41c2). (length);
1793 if (fread (result.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), sizeof (char), length, f) != length)
1794 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (feof (f) ? U"Reached end of file" : U"Error in file", U" while trying to read ", length, U" one-byte characters.");
1795 result [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).length] = 0; // trailing null byte
1796 return resultcxx . . $ _autostring#_autostring(39021ecceedcc7d2).;
1797 } catch (MelderErrorcxx . . $ MelderError#) {
1798 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Text not read from a binary file.");
1799 }
1800 }
1801
1802 autostring32cxx . . $ autostring32# bingetw8cxx . . $ bingetw8(6856a237bc2beebc). (FILE *f) {
1803 try {
1804 autostring32cxx . . $ autostring32# resultcxx . . $ _autostring#_autostring(49f6e7a06ebc5aa8).;
1805 uint32cxx . . $ uint32# length = bingetu8cxx . . $ bingetu8(9eef1996c458a0e7). (f);
1806 if (length == 0xFF) { // an escape for encoding
1807 /*
1808 UTF-16
1809 */
1810 length = bingetu8cxx . . $ bingetu8(9eef1996c458a0e7). (f);
1811 result =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). autostring32cxx . . $ autostring32# (length);
1812 for (unsigned int i = 0; i < length; i ++) {
1813 char32cxx . . $ char32# kar = bingetu16cxx . . $ bingetu16(38a7f6633dfbdb53). (f);
1814 if ((kar & 0x00'F800) == 0x00'D800) {
1815 if (kar > 0x00'DBFF)
1816 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Incorrect Unicode value (first surrogate member ", kar, U").");
1817 char32cxx . . $ char32# kar2 = bingetu16cxx . . $ bingetu16(38a7f6633dfbdb53). (f);
1818 if (kar2 < 0x00'DC'00 || kar2 > 0x00'DF'FF)
1819 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Incorrect Unicode value (second surrogate member ", kar2, U").");
1820 result [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).i] = (((kar & 0x00'03FF) << 10) | (kar2 & 0x00'03FF)) + 0x01'0000;
1821 } else {
1822 result [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).i] = kar;
1823 }
1824 }
1825 } else {
1826 /*
1827 ASCII
1828 */
1829 result =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). autostring32cxx . . $ autostring32# (length);
1830 for (uint32cxx . . $ uint32# i = 0; i < length; i ++)
1831 result [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).i] = bingetu8cxx . . $ bingetu8(9eef1996c458a0e7). (f);
1832 }
1833 result [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).length] = U'\0';
1834 return resultcxx . . $ _autostring#_autostring(39021ecceedcc7d2).;
1835 } catch (MelderErrorcxx . . $ MelderError#) {
1836 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Text not read from a binary file.");
1837 }
1838 }
1839
1840 autostring32cxx . . $ autostring32# bingetw16cxx . . $ bingetw16(6856a237bc2beebc). (FILE *f) {
1841 try {
1842 autostring32cxx . . $ autostring32# resultcxx . . $ _autostring#_autostring(49f6e7a06ebc5aa8).;
1843 uint16cxx . . $ uint16# length = bingetu16cxx . . $ bingetu16(38a7f6633dfbdb53). (f);
1844 if (length == 0xFFFF) { // an escape for encoding
1845 /*
1846 UTF-16
1847 */
1848 length = bingetu16cxx . . $ bingetu16(38a7f6633dfbdb53). (f);
1849 result =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). autostring32cxx . . $ autostring32# (length);
1850 for (uint16cxx . . $ uint16# i = 0; i < length; i ++) {
1851 char32cxx . . $ char32# kar = (char32cxx . . $ char32#) (char16cxx . . $ char16#) bingetu16cxx . . $ bingetu16(38a7f6633dfbdb53). (f);
1852 if ((kar & 0x00'F800) == 0x00'D800) {
1853 if (kar > 0x00'DBFF)
1854 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Incorrect Unicode value (first surrogate member ", kar, U").");
1855 char32cxx . . $ char32# kar2 = (char32cxx . . $ char32#) (char16cxx . . $ char16#) bingetu16cxx . . $ bingetu16(38a7f6633dfbdb53). (f);
1856 if (kar2 < 0x00'DC00 || kar2 > 0x00'DFFF)
1857 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Incorrect Unicode value (second surrogate member ", kar2, U").");
1858 result [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).i] = (((kar & 0x00'03FF) << 10) | (kar2 & 0x00'03FF)) + 0x01'0000;
1859 } else {
1860 result [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).i] = kar;
1861 }
1862 }
1863 } else {
1864 /*
1865 ASCII
1866 */
1867 result =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). autostring32cxx . . $ autostring32# (length);
1868 for (uint16cxx . . $ uint16# i = 0; i < length; i ++)
1869 result [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).i] = (char32cxx . . $ char32#) (char8cxx . . $ char8#) bingetu8cxx . . $ bingetu8(9eef1996c458a0e7). (f);
1870 }
1871 result [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).length] = U'\0';
1872 return resultcxx . . $ _autostring#_autostring(39021ecceedcc7d2).;
1873 } catch (MelderErrorcxx . . $ MelderError#) {
1874 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Text not read from a binary file.");
1875 }
1876 }
1877
1878 autostring32cxx . . $ autostring32# bingetw32cxx . . $ bingetw32(6856a237bc2beebc). (FILE *f) {
1879 try {
1880 autostring32cxx . . $ autostring32# resultcxx . . $ _autostring#_autostring(49f6e7a06ebc5aa8).;
1881 uint32cxx . . $ uint32# length = bingetu32cxx . . $ bingetu32(9eef1996c458a0e7). (f);
1882 if (length == 0xFFFF'FFFF) { // an escape for encoding
1883 /*
1884 UTF-16
1885 */
1886 length = bingetu32cxx . . $ bingetu32(9eef1996c458a0e7). (f);
1887 result =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). autostring32cxx . . $ autostring32# (length);
1888 for (uint32cxx . . $ uint32# i = 0; i < length; i ++) {
1889 char32cxx . . $ char32# kar = bingetu16cxx . . $ bingetu16(38a7f6633dfbdb53). (f);
1890 if ((kar & 0x00'F800) == 0x00'D800) {
1891 if (kar > 0x00'DBFF)
1892 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Incorrect Unicode value (first surrogate member ", kar, U").");
1893 char32cxx . . $ char32# kar2 = bingetu16cxx . . $ bingetu16(38a7f6633dfbdb53). (f);
1894 if (kar2 < 0x00'DC00 || kar2 > 0x00'DFFF)
1895 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Incorrect Unicode value (second surrogate member ", kar2, U").");
1896 result [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).i] = (((kar & 0x00'03FF) << 10) | (kar2 & 0x00'03FF)) + 0x01'0000;
1897 } else {
1898 result [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).i] = kar;
1899 }
1900 }
1901 } else {
1902 /*
1903 ASCII
1904 */
1905 result =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). autostring32cxx . . $ autostring32# (length);
1906 for (uint32cxx . . $ uint32# i = 0; i < length; i ++)
1907 result [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).i] = bingetu8cxx . . $ bingetu8(9eef1996c458a0e7). (f);
1908 }
1909 result [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).length] = U'\0';
1910 return resultcxx . . $ _autostring#_autostring(39021ecceedcc7d2).;
1911 } catch (MelderErrorcxx . . $ MelderError#) {
1912 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Text not read from a binary file.");
1913 }
1914 }
1915
1916 void binputs8cxx . . $ binputs8(949c37aeb559641). (const char *s, FILE *f) {
1917 try {
1918 if (! s) {
1919 binputu8cxx . . $ binputu8(60af6e60da050086). (0, f);
1920 } else {
1921 size_t length = strlen (s);
1922 if (length > UINT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:116:10`!) {
1923 Melder_warningcxx . . $ Melder_warning(6298c93241566110). (U"Text of ", length, U" characters truncated to 255 characters.");
1924 length = UINT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:116:10`!;
1925 }
1926 binputu8cxx . . $ binputu8(60af6e60da050086). ((uint32cxx . . $ uint32#) length, f); // guarded conversion down (or not: `length` may be uint32 or uint64)
1927 if (fwrite (s, sizeof (char), length, f) != length)
1928 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Error in file while trying to write ", length, U" one-byte characters.");
1929 }
1930 } catch (MelderErrorcxx . . $ MelderError#) {
1931 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Text not written to a binary file.");
1932 }
1933 }
1934
1935 void binputs16cxx . . $ binputs16(949c37aeb559641). (const char *s, FILE *f) {
1936 try {
1937 if (! s) {
1938 binputu16cxx . . $ binputu16(d4e8792de0db7e67). (0, f);
1939 } else {
1940 size_t length = strlen (s);
1941 if (length > UINT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:117:10`!) {
1942 Melder_warningcxx . . $ Melder_warning(6298c93241566110). (U"Text of ", length, U" characters truncated to 65535 characters.");
1943 length = UINT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:117:10`!;
1944 }
1945 binputu16cxx . . $ binputu16(d4e8792de0db7e67). ((uint16cxx . . $ uint16#) length, f); // guarded conversion down
1946 if (fwrite (s, sizeof (char), length, f) != length)
1947 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Error in file while trying to write ", length, U" one-byte characters.");
1948 }
1949 } catch (MelderErrorcxx . . $ MelderError#) {
1950 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Text not written to a binary file.");
1951 }
1952 }
1953
1954 void binputs32cxx . . $ binputs32(949c37aeb559641). (const char *s, FILE *f) {
1955 try {
1956 if (! s) {
1957 binputu32cxx . . $ binputu32(60af6e60da050086). (0, f);
1958 } else {
1959 size_t length = strlen (s);
1960 if (length > UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:118:10`!) {
1961 Melder_warningcxx . . $ Melder_warning(6298c93241566110). (U"Text of ", length, U" characters truncated to 4,294,967,295 characters.");
1962 length = UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:118:10`!;
1963 }
1964 binputu32cxx . . $ binputu32(60af6e60da050086). ((uint32cxx . . $ uint32#) length, f); // guarded conversion down (unless size_t is already uint32)
1965 if (fwrite (s, sizeof (char), length, f) != length)
1966 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Error in file while trying to write ", length, U" one-byte characters.");
1967 }
1968 } catch (MelderErrorcxx . . $ MelderError#) {
1969 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Text not written to a binary file.");
1970 }
1971 }
1972
1973 static inline void binpututf16cxx . . $ binpututf16(29cda1a21d40fe46). (char32cxx . . $ char32# kar, FILE *f) {
1974 if (kar <= 0x00FFFF) {
1975 binputu16cxx . . $ binputu16(d4e8792de0db7e67). ((uint16cxx . . $ uint16#) kar, f); // truncate to lower 16 bits
1976 } else if (kar <= 0x10'FFFF) {
1977 kar -= 0x01'0000;
1978 binputu16cxx . . $ binputu16(d4e8792de0db7e67). ((uint16cxx . . $ uint16#) (0x00'D800 | (kar >> 10)), f);
1979 binputu16cxx . . $ binputu16(d4e8792de0db7e67). ((uint16cxx . . $ uint16#) (0x00'DC00 | (kar & 0x00'03FF)), f);
1980 } else {
1981 Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"Impossible Unicode value.");
1982 }
1983 }
1984
1985 void binputw8cxx . . $ binputw8(43ad66ee48fe33fd). (conststring32cxx . . $ conststring32# s, FILE *f) {
1986 try {
1987 if (! s) {
1988 binputu8cxx . . $ binputu8(60af6e60da050086). (0, f);
1989 } else {
1990 integercxx . . $ integer# length = Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (s);
1991 if (length > UINT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:116:10`! - 1) {
1992 Melder_warningcxx . . $ Melder_warning(6298c93241566110). (U"Text of ", length, U" characters truncated to 254 characters.");
1993 length = UINT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:116:10`! - 1;
1994 }
1995 if (Melder_isValidAsciicxx . . $ Melder_isValidAscii(2df281243f91fe91). (s)) {
1996 /*
1997 ASCII
1998 */
1999 binputu8cxx . . $ binputu8(60af6e60da050086). ((uint32cxx . . $ uint32#) length, f); // guarded conversion down
2000 for (integercxx . . $ integer# i = 0; i < length; i ++)
2001 binputu8cxx . . $ binputu8(60af6e60da050086). ((uint32cxx . . $ uint32#) (uint8cxx . . $ uint8#) s [i], f); // guarded conversion down from char32 to uint8
2002 } else {
2003 /*
2004 UTF-16
2005 */
2006 binputu8cxx . . $ binputu8(60af6e60da050086). (0xFF, f); // an escape for multibyte encoding
2007 binputu8cxx . . $ binputu8(60af6e60da050086). ((uint32cxx . . $ uint32#) length, f);
2008 for (integercxx . . $ integer# i = 0; i < length; i ++)
2009 binpututf16cxx . . $ binpututf16(29cda1a21d40fe46). (s [i], f);
2010 }
2011 }
2012 } catch (MelderErrorcxx . . $ MelderError#) {
2013 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Text not written to a binary file.");
2014 }
2015 }
2016
2017 void binputw16cxx . . $ binputw16(43ad66ee48fe33fd). (conststring32cxx . . $ conststring32# s, FILE *f) {
2018 try {
2019 if (! s) {
2020 binputu16cxx . . $ binputu16(d4e8792de0db7e67). (0, f);
2021 } else {
2022 integercxx . . $ integer# length = Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (s);
2023 if (length > UINT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:117:10`! - 1) {
2024 Melder_warningcxx . . $ Melder_warning(6298c93241566110). (U"Text of ", length, U" characters truncated to 65534 characters.");
2025 length = UINT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:117:10`! - 1;
2026 }
2027 if (Melder_isValidAsciicxx . . $ Melder_isValidAscii(2df281243f91fe91). (s)) {
2028 /*
2029 ASCII
2030 */
2031 binputu16cxx . . $ binputu16(d4e8792de0db7e67). ((uint16cxx . . $ uint16#) length, f); // guarded conversion down
2032 for (int64cxx . . $ int64# i = 0; i < length; i ++)
2033 binputu8cxx . . $ binputu8(60af6e60da050086). ((uint32cxx . . $ uint32#) (uint8cxx . . $ uint8#) s [i], f); // guarded conversion down from char32 to uint8
2034 } else {
2035 /*
2036 UTF-16
2037 */
2038 binputu16cxx . . $ binputu16(d4e8792de0db7e67). (0xFFFF, f); // an escape for multibyte encoding
2039 binputu16cxx . . $ binputu16(d4e8792de0db7e67). ((uint16cxx . . $ uint16#) length, f); // guarded conversion down
2040 for (int64cxx . . $ int64# i = 0; i < length; i ++)
2041 binpututf16cxx . . $ binpututf16(29cda1a21d40fe46). (s [i], f);
2042 }
2043 }
2044 } catch (MelderErrorcxx . . $ MelderError#) {
2045 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Text not written to a binary file.");
2046 }
2047 }
2048
2049 void binputw32cxx . . $ binputw32(43ad66ee48fe33fd). (conststring32cxx . . $ conststring32# s, FILE *f) {
2050 try {
2051 if (! s) {
2052 binputu32cxx . . $ binputu32(60af6e60da050086). (0, f);
2053 } else {
2054 integercxx . . $ integer# length = Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (s); // on 32-bit systems the length cannot exceed 2^30 char32s, i.e. `length` must be positive
2055 if (length > UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:118:10`! - 1) {
2056 Melder_warningcxx . . $ Melder_warning(6298c93241566110). (U"Text of ", length, U" characters truncated to 4,294,967,294 characters.");
2057 length = UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:118:10`! - 1;
2058 }
2059 if (Melder_isValidAsciicxx . . $ Melder_isValidAscii(2df281243f91fe91). (s)) {
2060 /*
2061 ASCII
2062 */
2063 binputu32cxx . . $ binputu32(60af6e60da050086). ((uint32cxx . . $ uint32#) length, f); // guarded conversion down on 64-bit systems, and valid even on 32-bit systems
2064 for (integercxx . . $ integer# i = 0; i < length; i ++)
2065 binputu8cxx . . $ binputu8(60af6e60da050086). ((uint32cxx . . $ uint32#) (uint8cxx . . $ uint8#) s [i], f); // guarded conversion down from char32 to uint8
2066 } else {
2067 /*
2068 UTF-16
2069 */
2070 binputu32cxx . . $ binputu32(60af6e60da050086). (0xFFFF'FFFF, f); // an escape for multibyte encoding
2071 binputu32cxx . . $ binputu32(60af6e60da050086). ((uint32cxx . . $ uint32#) length, f); // guarded conversion down
2072 for (integercxx . . $ integer# i = 0; i < length; i ++)
2073 binpututf16cxx . . $ binpututf16(29cda1a21d40fe46). (s [i], f);
2074 }
2075 }
2076 } catch (MelderErrorcxx . . $ MelderError#) {
2077 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Text not written to a binary file.");
2078 }
2079 }
2080
2081 /* End of file abcio.cpp */