| 1 |
/* melder_files.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 1992-2008,2010-2026 Paul Boersma, 2013 Tom Naughton |
| 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 |
#if defined (UNIX) |
| 20 |
#include <unistd.h> |
| 21 |
#include <sys/stat.h> |
| 22 |
#endif |
| 23 |
#ifdef _WIN32 |
| 24 |
#include <windows.h> |
| 25 |
#endif |
| 26 |
#if defined (macintosh) |
| 27 |
#include "macport_on.h" |
| 28 |
#include <CoreFoundation/CoreFoundation.h> |
| 29 |
#include "macport_off.h" |
| 30 |
#endif |
| 31 |
#include <errno.h> |
| 32 |
#include "melder.h" |
| 33 |
#include "../kar/UnicodeData.h" |
| 34 |
|
| 35 |
//#include "flac_FLAC_stream_encoder.h" |
| 36 |
extern "C" int FLAC__stream_encoder_finish (FLAC__StreamEncoder *); |
| 37 |
extern "C" void FLAC__stream_encoder_delete (FLAC__StreamEncoder *); |
| 38 |
|
| 39 |
#if defined (macintosh) |
| 40 |
#include <sys/stat.h> |
| 41 |
#define UNIX |
| 42 |
#include <unistd.h> |
| 43 |
#endif |
| 44 |
|
| 45 |
static char32 theShellDirectory [kMelder_MAXPATH+1]; |
| 46 |
void Melder_rememberShellDirectory () { |
| 47 |
structMelderFolder shellFolder { }; |
| 48 |
Melder_getCurrentFolder (& shellFolder); |
| 49 |
str32cpy (theShellDirectory, MelderFolder_peekPath (& shellFolder)); |
| 50 |
} |
| 51 |
conststring32 Melder_getShellDirectory () { |
| 52 |
return & theShellDirectory [0]; |
| 53 |
} |
| 54 |
|
| 55 |
#if defined (UNIX) |
| 56 |
void Melder_8bitFileRepresentationToStr32_inplace (const char *path8, char32 *path32) { |
| 57 |
#if defined (macintosh) |
| 58 |
CFStringRef cfpath = CFStringCreateWithCString (nullptr, path8, kCFStringEncodingUTF8); |
| 59 |
if (! cfpath) { |
| 60 |
/* |
| 61 |
Probably something wrong, like a disk was disconnected in the meantime. |
| 62 |
*/ |
| 63 |
try { |
| 64 |
Melder_8to32_inplace_e (path8, path32, kMelder_textInputEncoding::UTF8); |
| 65 |
} catch (MelderError) { |
| 66 |
Melder_8to32_inplace_e (path8, path32, kMelder_textInputEncoding::MACROMAN); // cannot fail |
| 67 |
Melder_throw (U"Unusual error finding or creating file <<", path32, U">> (MacRoman)."); |
| 68 |
} |
| 69 |
Melder_throw (U"Unusual error finding or creating file ", path32, U"."); |
| 70 |
} |
| 71 |
CFMutableStringRef cfpath2 = CFStringCreateMutableCopy (nullptr, 0, cfpath); |
| 72 |
CFRelease (cfpath); |
| 73 |
CFStringNormalize (cfpath2, kCFStringNormalizationFormC); // Praat requires composed characters |
| 74 |
integer n_utf16 = CFStringGetLength (cfpath2); |
| 75 |
integer n_utf32 = 0; |
| 76 |
for (integer i = 0; i < n_utf16; i ++) { |
| 77 |
char32 kar1 = CFStringGetCharacterAtIndex (cfpath2, i); |
| 78 |
if (kar1 >= 0x00'D800 && kar1 <= 0x00'DBFF) { |
| 79 |
char32 kar2 = (char32) CFStringGetCharacterAtIndex (cfpath2, ++ i); // convert up |
| 80 |
if (kar2 >= 0x00'DC00 && kar2 <= 0x00'DFFF) { |
| 81 |
kar1 = (((kar1 & 0x3FF) << 10) | (kar2 & 0x3FF)) + 0x01'0000; |
| 82 |
} else { |
| 83 |
kar1 = UNICODE_REPLACEMENT_CHARACTER; |
| 84 |
} |
| 85 |
} |
| 86 |
path32 [n_utf32 ++] = kar1; |
| 87 |
} |
| 88 |
path32 [n_utf32] = U'\0'; |
| 89 |
CFRelease (cfpath2); |
| 90 |
#else |
| 91 |
Melder_8to32_inplace_e (path8, path32, kMelder_textInputEncoding::UTF8); |
| 92 |
#endif |
| 93 |
} |
| 94 |
#endif |
| 95 |
|
| 96 |
conststring32 MelderFile_name (MelderFile file) { |
| 97 |
#if defined (UNIX) |
| 98 |
char32 *slash = str32rchr (file -> path, U'/'); |
| 99 |
return slash ? slash + 1 : file -> path; |
| 100 |
#elif defined (_WIN32) |
| 101 |
char32 *backslash = str32rchr (file -> path, U'\\'); |
| 102 |
return backslash ? backslash + 1 : file -> path; |
| 103 |
#else |
| 104 |
return nullptr; |
| 105 |
#endif |
| 106 |
} |
| 107 |
|
| 108 |
conststring32 MelderFolder_name (MelderFolder folder) { |
| 109 |
#if defined (UNIX) |
| 110 |
char32 *slash = str32rchr (folder -> path, U'/'); |
| 111 |
return slash ? slash + 1 : folder -> path; |
| 112 |
#elif defined (_WIN32) |
| 113 |
char32 *backslash = str32rchr (folder -> path, U'\\'); |
| 114 |
return backslash ? backslash + 1 : folder -> path; |
| 115 |
#else |
| 116 |
return nullptr; |
| 117 |
#endif |
| 118 |
} |
| 119 |
|
| 120 |
void Melder_pathToFolder (conststring32 path, MelderFolder folder) { |
| 121 |
/* |
| 122 |
FIXME: document that this function can be used to keep folder names relative and generic |
| 123 |
*/ |
| 124 |
Melder_sprint (folder -> path,kMelder_MAXPATH+1, path); |
| 125 |
} |
| 126 |
|
| 127 |
void Melder_pathToFile (conststring32 path, MelderFile file) { |
| 128 |
/* |
| 129 |
This handles complete path names only. |
| 130 |
|
| 131 |
Used if we know for sure that we have a complete path name, |
| 132 |
i.e. if the program determined the name (fileselector, printing, prefs). |
| 133 |
|
| 134 |
FIXME: document that this function can also be used to keep file names relative and generic |
| 135 |
*/ |
| 136 |
Melder_sprint (file -> path,kMelder_MAXPATH+1, path); |
| 137 |
} |
| 138 |
|
| 139 |
void Melder_relativePathToFile (conststring32 path, MelderFile file) { |
| 140 |
/* |
| 141 |
This handles complete and partial path names, |
| 142 |
and translates slashes to native folder separators. |
| 143 |
|
| 144 |
Used if we do not know for sure that we have a complete path name, |
| 145 |
i.e. if the user determined the name (scripting). |
| 146 |
*/ |
| 147 |
#if defined (UNIX) |
| 148 |
/* |
| 149 |
We assume that Unix complete path names start with a slash. |
| 150 |
*/ |
| 151 |
if (path [0] == U'~' && path [1] == U'/') { |
| 152 |
Melder_sprint (file -> path,kMelder_MAXPATH+1, Melder_peek8to32_u (getenv ("HOME")), & path [1]); |
| 153 |
} else if (path [0] == U'/' || str32equ (path, U"<stdout>") || str32str (path, U"://")) { |
| 154 |
Melder_sprint (file -> path,kMelder_MAXPATH+1, path); |
| 155 |
} else { |
| 156 |
structMelderFolder currentFolder { }; |
| 157 |
Melder_getCurrentFolder (& currentFolder); // BUG |
| 158 |
if (currentFolder. path [0] == U'/' && currentFolder. path [1] == U'\0') |
| 159 |
Melder_sprint (file -> path,kMelder_MAXPATH+1, U"/", path); |
| 160 |
else |
| 161 |
Melder_sprint (file -> path,kMelder_MAXPATH+1, currentFolder. path, U"/", path); |
| 162 |
} |
| 163 |
#elif defined (_WIN32) |
| 164 |
/* |
| 165 |
We assume that Win32 complete path names look like: |
| 166 |
C:\WINDOWS\CTRL32.DLL |
| 167 |
LPT1: |
| 168 |
\\host\path |
| 169 |
*/ |
| 170 |
structMelderFolder currentFolder { }; |
| 171 |
if (path [0] == U'~' && path [1] == U'/') { |
| 172 |
Melder_getHomeDir (& currentFolder); |
| 173 |
Melder_sprint (file -> path,kMelder_MAXPATH+1, currentFolder. path, & path [1]); |
| 174 |
for (;;) { |
| 175 |
char32 *slash = str32chr (file -> path, U'/'); |
| 176 |
if (! slash) |
| 177 |
break; |
| 178 |
*slash = U'\\'; |
| 179 |
} |
| 180 |
return; |
| 181 |
} |
| 182 |
if (str32chr (path, U'/') && ! str32str (path, U"://")) { |
| 183 |
char32 winPath [kMelder_MAXPATH+1]; |
| 184 |
Melder_sprint (winPath,kMelder_MAXPATH+1, path); |
| 185 |
for (;;) { |
| 186 |
char32 *slash = str32chr (winPath, U'/'); |
| 187 |
if (! slash) |
| 188 |
break; |
| 189 |
*slash = U'\\'; |
| 190 |
} |
| 191 |
Melder_relativePathToFile (winPath, file); |
| 192 |
return; |
| 193 |
} |
| 194 |
if (str32chr (path, U':') || path [0] == U'\\' && path [1] == U'\\' || str32equ (path, U"<stdout>")) { |
| 195 |
Melder_sprint (file -> path,kMelder_MAXPATH+1, path); |
| 196 |
} else { |
| 197 |
Melder_getCurrentFolder (& currentFolder); // BUG |
| 198 |
Melder_sprint (file -> path,kMelder_MAXPATH+1, |
| 199 |
currentFolder. path, |
| 200 |
currentFolder. path [0] != U'\0' && currentFolder. path [Melder_length (currentFolder. path) - 1] == U'\\' ? U"" : U"\\", |
| 201 |
path |
| 202 |
); |
| 203 |
} |
| 204 |
#endif |
| 205 |
} |
| 206 |
|
| 207 |
void Melder_relativePathToFolder (conststring32 path, MelderFolder folder) { |
| 208 |
/* |
| 209 |
This handles complete, partial and home-relative path names, |
| 210 |
and translates slashes to native folder separators. |
| 211 |
|
| 212 |
Used if we do not know for sure that we have a complete path name, |
| 213 |
i.e. if the user determined the name (scripting). |
| 214 |
*/ |
| 215 |
#if defined (UNIX) |
| 216 |
if (const bool pathIsHomeRelative = ( path [0] == U'~' && (path [1] == U'/' || path [1] == U'\0') )) { |
| 217 |
Melder_sprint (folder -> path,kMelder_MAXPATH+1, Melder_peek8to32_u (getenv ("HOME")), & path [1]); |
| 218 |
} else if (const bool pathIsAbsolute = ( |
| 219 |
path [0] == U'/' // path is on local disk |
| 220 |
|| |
| 221 |
str32str (path, U"://") // path is on a service through a URL; is this needed and/or safe? |
| 222 |
)) |
| 223 |
{ |
| 224 |
Melder_sprint (folder -> path,kMelder_MAXPATH+1, path); |
| 225 |
} else { |
| 226 |
/* |
| 227 |
Remaining case: the path must be current-folder-relative. |
| 228 |
*/ |
| 229 |
structMelderFolder currentFolder { }; |
| 230 |
Melder_getCurrentFolder (& currentFolder); // BUG if in library? check in Python, for instance |
| 231 |
const bool weAreInTheRootFolder = ( currentFolder. path [0] == U'/' && currentFolder. path [1] == U'\0' ); |
| 232 |
conststring32 folderSeparator = ( weAreInTheRootFolder ? nullptr : U"/" ); // prevent a double slash |
| 233 |
Melder_sprint (folder -> path,kMelder_MAXPATH+1, currentFolder. path, folderSeparator, path); |
| 234 |
} |
| 235 |
#elif defined (_WIN32) |
| 236 |
/* |
| 237 |
We assume that Win32 complete path names look like: |
| 238 |
C:\WINDOWS\CTRL32.DLL |
| 239 |
LPT1: |
| 240 |
\\host\path |
| 241 |
*/ |
| 242 |
structMelderFolder currentFolder { }; |
| 243 |
if (path [0] == U'~' && path [1] == U'\0') { |
| 244 |
Melder_getHomeDir (& currentFolder); |
| 245 |
Melder_sprint (folder -> path,kMelder_MAXPATH+1, currentFolder. path); |
| 246 |
return; |
| 247 |
} |
| 248 |
if (path [0] == U'~' && path [1] == U'/') { |
| 249 |
Melder_getHomeDir (& currentFolder); |
| 250 |
Melder_sprint (folder -> path,kMelder_MAXPATH+1, currentFolder. path, & path [1]); |
| 251 |
for (;;) { |
| 252 |
char32 *slash = str32chr (folder -> path, U'/'); |
| 253 |
if (! slash) |
| 254 |
break; |
| 255 |
*slash = U'\\'; |
| 256 |
} |
| 257 |
return; |
| 258 |
} |
| 259 |
if (str32chr (path, U'/') && ! str32str (path, U"://")) { |
| 260 |
char32 winPath [kMelder_MAXPATH+1]; |
| 261 |
Melder_sprint (winPath,kMelder_MAXPATH+1, path); |
| 262 |
for (;;) { |
| 263 |
char32 *slash = str32chr (winPath, U'/'); |
| 264 |
if (! slash) |
| 265 |
break; |
| 266 |
*slash = U'\\'; |
| 267 |
} |
| 268 |
Melder_relativePathToFolder (winPath, folder); |
| 269 |
return; |
| 270 |
} |
| 271 |
if (str32chr (path, U':') || path [0] == U'\\' && path [1] == U'\\') { |
| 272 |
Melder_sprint (folder -> path,kMelder_MAXPATH+1, path); |
| 273 |
} else { |
| 274 |
Melder_getCurrentFolder (& currentFolder); // BUG |
| 275 |
Melder_sprint (folder -> path,kMelder_MAXPATH+1, |
| 276 |
currentFolder. path, |
| 277 |
currentFolder. path [0] != U'\0' && currentFolder. path [Melder_length (currentFolder. path) - 1] == U'\\' ? U"" : U"\\", |
| 278 |
path |
| 279 |
); |
| 280 |
} |
| 281 |
#endif |
| 282 |
} |
| 283 |
|
| 284 |
conststring32 MelderFile_peekPath (MelderFile file) { |
| 285 |
return & file -> path [0]; |
| 286 |
} |
| 287 |
conststring32 MelderFolder_peekPath (MelderFolder folder) { |
| 288 |
return & folder -> path [0]; |
| 289 |
} |
| 290 |
|
| 291 |
conststring8 MelderFile_peekPath8 (MelderFile file) { |
| 292 |
return Melder_peek32to8_fileSystem (MelderFile_peekPath (file)); |
| 293 |
} |
| 294 |
conststring8 MelderFolder_peekPath8 (MelderFolder folder) { |
| 295 |
return Melder_peek32to8_fileSystem (MelderFolder_peekPath (folder)); |
| 296 |
} |
| 297 |
|
| 298 |
#ifdef _WIN32 |
| 299 |
conststringW MelderFile_peekPathW (MelderFile file) { |
| 300 |
return Melder_peek32toW_fileSystem (MelderFile_peekPath (file)); |
| 301 |
} |
| 302 |
conststringW MelderFolder_peekPathW (MelderFolder folder) { |
| 303 |
return Melder_peek32toW_fileSystem (MelderFolder_peekPath (folder)); |
| 304 |
} |
| 305 |
#endif |
| 306 |
|
| 307 |
#ifdef macintosh |
| 308 |
const void * MelderFile_peekPathCfstring (MelderFile file) { |
| 309 |
return Melder_peek32toCfstring_fileSystem (MelderFile_peekPath (file)); |
| 310 |
} |
| 311 |
const void * MelderFolder_peekPathCfstring (MelderFolder folder) { |
| 312 |
return Melder_peek32toCfstring_fileSystem (MelderFolder_peekPath (folder)); |
| 313 |
} |
| 314 |
#endif |
| 315 |
|
| 316 |
void MelderFile_copy (constMelderFile file, MelderFile copy) { |
| 317 |
str32cpy (copy -> path, file -> path); |
| 318 |
} |
| 319 |
|
| 320 |
void MelderFolder_copy (constMelderFolder folder, MelderFolder copy) { |
| 321 |
str32cpy (copy -> path, folder -> path); |
| 322 |
} |
| 323 |
|
| 324 |
bool MelderFile_equal (MelderFile file1, MelderFile file2) { |
| 325 |
return str32equ (file1 -> path, file2 -> path); |
| 326 |
} |
| 327 |
|
| 328 |
bool MelderFolder_equal (MelderFolder folder1, MelderFolder folder2) { |
| 329 |
return str32equ (folder1 -> path, folder2 -> path); |
| 330 |
} |
| 331 |
|
| 332 |
void MelderFile_setToNull (MelderFile file) { |
| 333 |
file -> path [0] = U'\0'; |
| 334 |
} |
| 335 |
|
| 336 |
bool MelderFile_isNull (MelderFile file) { |
| 337 |
return ! file || file -> path [0] == U'\0'; |
| 338 |
} |
| 339 |
|
| 340 |
void MelderFolder_setToNull (MelderFolder folder) { |
| 341 |
folder -> path [0] = U'\0'; |
| 342 |
} |
| 343 |
|
| 344 |
bool MelderFolder_isNull (MelderFolder folder) { |
| 345 |
return folder -> path [0] == U'\0'; |
| 346 |
} |
| 347 |
|
| 348 |
void MelderFolder_getFile (MelderFolder parent, conststring32 fileName, MelderFile file) { |
| 349 |
#if defined (UNIX) |
| 350 |
if (parent -> path [0] == U'/' && parent -> path [1] == U'\0') |
| 351 |
Melder_sprint (file -> path,kMelder_MAXPATH+1, U"/", fileName); |
| 352 |
else |
| 353 |
Melder_sprint (file -> path,kMelder_MAXPATH+1, parent -> path, U"/", fileName); |
| 354 |
#elif defined (_WIN32) |
| 355 |
if (str32rchr (file -> path, U'\\') - file -> path == Melder_length (file -> path) - 1) |
| 356 |
Melder_sprint (file -> path,kMelder_MAXPATH+1, parent -> path, fileName); |
| 357 |
else |
| 358 |
Melder_sprint (file -> path,kMelder_MAXPATH+1, parent -> path, U"\\", fileName); |
| 359 |
#endif |
| 360 |
} |
| 361 |
|
| 362 |
void MelderFolder_relativePathToFile (MelderFolder folder, conststring32 path, MelderFile file) { |
| 363 |
autoMelderSetCurrentFolder saveFolder (folder); |
| 364 |
Melder_relativePathToFile (path, file); |
| 365 |
} |
| 366 |
|
| 367 |
#ifndef UNIX |
| 368 |
static void Melder_getDesktop (MelderFolder folder) { |
| 369 |
folder -> path [0] = U'\0'; |
| 370 |
} |
| 371 |
#endif |
| 372 |
|
| 373 |
void MelderFile_getParentFolder (MelderFile file, MelderFolder parent) { |
| 374 |
#if defined (UNIX) |
| 375 |
/* |
| 376 |
The parent of /usr/hello.txt is /usr. |
| 377 |
The parent of /hello.txt is /. |
| 378 |
*/ |
| 379 |
str32cpy (parent -> path, file -> path); |
| 380 |
char32 *slash = str32rchr (parent -> path, U'/'); |
| 381 |
if (slash) |
| 382 |
*slash = U'\0'; |
| 383 |
if (parent -> path [0] == U'\0') |
| 384 |
str32cpy (parent -> path, U"/"); |
| 385 |
#elif defined (_WIN32) |
| 386 |
/* |
| 387 |
The parent of C:\WINDOWS\CTRL.DLL is C:\WINDOWS. |
| 388 |
The parent of E:\Praat.exe is E:\. |
| 389 |
The parent of \\Swine\Apps\init.txt is \\Swine\Apps. |
| 390 |
The parent of \\Swine\init.txt is \\Swine\. (BUG ?) |
| 391 |
*/ |
| 392 |
str32cpy (parent -> path, file -> path); |
| 393 |
char32 *colon = str32chr (parent -> path, U':'); |
| 394 |
if (colon) { |
| 395 |
char32 *backslash = str32rchr (parent -> path, U'\\'); |
| 396 |
if (backslash) { // C:\WINDOWS\CTRL.DLL or C:\AUTOEXEC.BAT |
| 397 |
if (backslash - colon == 1) { // C:\AUTOEXEC.BAT |
| 398 |
* (backslash + 1) = U'\0'; // C:\ - !!! aargh this was a bug after converting this line to line comments |
| 399 |
} else { // C:\WINDOWS\CTRL.DLL |
| 400 |
*backslash = U'\0'; // C:\WINDOWS |
| 401 |
} |
| 402 |
} else { /* ??? */ |
| 403 |
Melder_getDesktop (parent); // empty string |
| 404 |
} |
| 405 |
} else if (parent -> path [0] == U'\\' && parent -> path [1] == U'\\') { |
| 406 |
char32 *backslash = str32rchr (parent -> path + 2, U'\\'); |
| 407 |
if (backslash) { // \\Swine\Apps\init.txt or \\Swine\init.txt |
| 408 |
char32 *leftBackslash = str32chr (parent -> path + 2, U'\\'); |
| 409 |
if (backslash - leftBackslash == 0) { // \\Swine\init.txt |
| 410 |
* (backslash + 1) = U'\0'; // \\Swine\ - !!! dear developer, don't delete this hyphen, lest the line ends in a backslash |
| 411 |
} else { // \\Swine\Apps\init.txt |
| 412 |
*backslash = U'\0'; // \\Swine\Apps |
| 413 |
} |
| 414 |
} else { // \\init.txt ??? |
| 415 |
Melder_getDesktop (parent); // empty string |
| 416 |
} |
| 417 |
} else { // unknown path type |
| 418 |
Melder_getDesktop (parent); // empty string |
| 419 |
} |
| 420 |
#endif |
| 421 |
} |
| 422 |
|
| 423 |
void MelderFolder_getParentFolder (MelderFolder subfolder, MelderFolder parentFolder) { |
| 424 |
#if defined (UNIX) |
| 425 |
/* |
| 426 |
The parent of /usr/local is /usr. |
| 427 |
The parent of /usr is /. |
| 428 |
The parent of / is "". |
| 429 |
*/ |
| 430 |
str32cpy (parentFolder -> path, subfolder -> path); |
| 431 |
char32 *slash = str32rchr (parentFolder -> path, U'/'); |
| 432 |
if (slash) { |
| 433 |
if (slash - parentFolder -> path == 0) { |
| 434 |
if (slash [1] == U'\0') { // child is "/" |
| 435 |
parentFolder -> path [0] = U'\0'; // parent is "" |
| 436 |
} else { // child is "/usr" |
| 437 |
slash [1] = '\0'; // parent is "/" |
| 438 |
} |
| 439 |
} else { // child is "/usr/local" |
| 440 |
*slash = U'\0'; // parent is "/usr" |
| 441 |
} |
| 442 |
} else { |
| 443 |
parentFolder -> path [0] = U'\0'; // some failure; desktop |
| 444 |
} |
| 445 |
#elif defined (_WIN32) |
| 446 |
/* |
| 447 |
The parent of C:\WINDOWS is C:\. |
| 448 |
The parent of E:\ is the desktop. |
| 449 |
The parent of \\Swine\ is the desktop. (BUG ?) |
| 450 |
*/ |
| 451 |
str32cpy (parentFolder -> path, subfolder -> path); |
| 452 |
char32 *colon = str32chr (parentFolder -> path, U':'); |
| 453 |
if (colon) { |
| 454 |
const integer length = Melder_length (parentFolder -> path); |
| 455 |
char32 *backslash = str32rchr (parentFolder -> path, U'\\'); |
| 456 |
if (backslash) { // C:\WINDOWS\FONTS or C:\WINDOWS or C:\ - (cannot add a line comment with a backslash) |
| 457 |
if (backslash - parentFolder -> path == length - 1) { // C:\ - |
| 458 |
Melder_getDesktop (parentFolder); // empty string |
| 459 |
} else if (backslash - colon == 1) { // C:\WINDOWS |
| 460 |
* (backslash + 1) = U'\0'; // C:\ - |
| 461 |
} else { // C:\WINDOWS\FONTS |
| 462 |
*backslash = U'\0'; // C:\WINDOWS |
| 463 |
} |
| 464 |
} else { // LPT1: ??? |
| 465 |
Melder_getDesktop (parentFolder); // empty string |
| 466 |
} |
| 467 |
} else if (parentFolder -> path [0] == U'\\' && parentFolder -> path [1] == U'\\') { |
| 468 |
const integer length = Melder_length (parentFolder -> path); |
| 469 |
char32 *backslash = str32rchr (parentFolder -> path + 2, U'\\'); |
| 470 |
if (backslash) { // \\Swine\Apps\Praats or \\Swine\Apps or \\Swine\ - |
| 471 |
if (backslash - parentFolder -> path == length - 1) { // \\Swine\ - |
| 472 |
Melder_getDesktop (parentFolder); // empty string |
| 473 |
} else { // \\Swine\Apps\Praats or \\Swine\Apps |
| 474 |
char32 *leftBackslash = str32chr (parentFolder -> path + 2, U'\\'); |
| 475 |
if (backslash - leftBackslash == 0) { // \\Swine\Apps |
| 476 |
* (backslash + 1) = U'\0'; // \\Swine\ - |
| 477 |
} else { // \\Swine\Apps\Praats |
| 478 |
*backslash = U'\0'; // \\Swine\Apps |
| 479 |
} |
| 480 |
} |
| 481 |
} else { // \\Swine ??? |
| 482 |
Melder_getDesktop (parentFolder); // empty string |
| 483 |
} |
| 484 |
} else { // unknown path type. |
| 485 |
Melder_getDesktop (parentFolder); // empty string |
| 486 |
} |
| 487 |
#endif |
| 488 |
} |
| 489 |
|
| 490 |
bool MelderFolder_isDesktop (MelderFolder folder) { |
| 491 |
return folder -> path [0] == U'\0'; |
| 492 |
} |
| 493 |
|
| 494 |
void MelderFolder_getSubfolder (MelderFolder parentFolder, conststring32 subfolderName, MelderFolder subfolder) { |
| 495 |
#if defined (UNIX) |
| 496 |
if (parentFolder -> path [0] == U'/' && parentFolder -> path [1] == U'\0') { |
| 497 |
Melder_sprint (subfolder -> path,kMelder_MAXPATH+1, U"/", subfolderName); |
| 498 |
} else { |
| 499 |
Melder_sprint (subfolder -> path,kMelder_MAXPATH+1, parentFolder -> path, U"/", subfolderName); |
| 500 |
} |
| 501 |
#elif defined (_WIN32) |
| 502 |
const integer length = Melder_length (parentFolder -> path); |
| 503 |
char32 *backslash = str32rchr (parentFolder -> path, U'\\'); |
| 504 |
if (backslash && backslash - parentFolder -> path == length - 1) { // C:\ or \\Swine\ - |
| 505 |
Melder_sprint (subfolder -> path, kMelder_MAXPATH+1, parentFolder -> path, subfolderName); |
| 506 |
} else { // C:\WINDOWS or \\Swine\Apps or even C: |
| 507 |
Melder_sprint (subfolder -> path,kMelder_MAXPATH+1, parentFolder -> path, U"\\", subfolderName); |
| 508 |
} |
| 509 |
#endif |
| 510 |
} |
| 511 |
|
| 512 |
void Melder_getHomeDir (MelderFolder homeDir) { |
| 513 |
#if defined (UNIX) |
| 514 |
char *home = getenv ("HOME"); |
| 515 |
Melder_sprint (homeDir -> path,kMelder_MAXPATH+1, home ? Melder_peek8to32_u (home) : U"/"); |
| 516 |
#elif defined (_WIN32) |
| 517 |
WCHAR driveW [kMelder_MAXPATH+1], pathW [kMelder_MAXPATH+1]; |
| 518 |
DWORD n = GetEnvironmentVariableW (L"USERPROFILE", pathW, kMelder_MAXPATH+1); |
| 519 |
if (n > kMelder_MAXPATH) |
| 520 |
Melder_throw (U"Home folder name too long."); |
| 521 |
if (n > 0) { |
| 522 |
Melder_sprint (homeDir -> path,kMelder_MAXPATH+1, Melder_peekWto32 (pathW)); |
| 523 |
return; |
| 524 |
} |
| 525 |
n = GetEnvironmentVariableW (L"HOMEDRIVE", driveW, kMelder_MAXPATH+1); |
| 526 |
if (n > kMelder_MAXPATH) |
| 527 |
Melder_throw (U"Home drive name too long."); |
| 528 |
if (n > 0) { |
| 529 |
GetEnvironmentVariable (L"HOMEPATH", pathW, kMelder_MAXPATH+1); |
| 530 |
Melder_sprint (homeDir -> path,kMelder_MAXPATH+1, Melder_peekWto32 (driveW), Melder_peekWto32 (pathW)); |
| 531 |
return; |
| 532 |
} |
| 533 |
MelderFolder_setToNull (homeDir); // Windows 95 and 98: alas |
| 534 |
#endif |
| 535 |
} |
| 536 |
|
| 537 |
static structMelderFolder thePreferencesFolder; |
| 538 |
void Melder_setPreferencesFolder (conststring32 path) { |
| 539 |
Melder_pathToFolder (path, & thePreferencesFolder); |
| 540 |
} |
| 541 |
MelderFolder Melder_preferencesFolder() { |
| 542 |
return & thePreferencesFolder; |
| 543 |
} |
| 544 |
MelderFolder Melder_preferencesFolder5() { |
| 545 |
static structMelderFolder thePreferencesFolder5; |
| 546 |
if (MelderFolder_isNull (& thePreferencesFolder5)) { |
| 547 |
structMelderFolder homeFolder { }; |
| 548 |
Melder_getHomeDir (& homeFolder); |
| 549 |
#if defined (macintosh) |
| 550 |
Melder_sprint (thePreferencesFolder5. path,kMelder_MAXPATH+1, homeFolder. path, |
| 551 |
U"/Library/Preferences/", Melder_upperCaseAppName(), U" Prefs"); |
| 552 |
#elif defined (UNIX) |
| 553 |
Melder_sprint (thePreferencesFolder5. path,kMelder_MAXPATH+1, homeFolder. path, |
| 554 |
U"/.", Melder_lowerCaseAppName(), U"-dir"); |
| 555 |
#elif defined (_WIN32) |
| 556 |
Melder_sprint (thePreferencesFolder5. path,kMelder_MAXPATH+1, homeFolder. path, |
| 557 |
U"\\", Melder_upperCaseAppName()); |
| 558 |
#endif |
| 559 |
} |
| 560 |
return & thePreferencesFolder5; |
| 561 |
} |
| 562 |
MelderFolder Melder_preferencesFolder7() { |
| 563 |
static structMelderFolder thePreferencesFolder7; |
| 564 |
if (MelderFolder_isNull (& thePreferencesFolder7)) { |
| 565 |
structMelderFolder homeFolder { }; |
| 566 |
Melder_getHomeDir (& homeFolder); |
| 567 |
#if defined (macintosh) |
| 568 |
Melder_sprint (thePreferencesFolder7. path,kMelder_MAXPATH+1, homeFolder. path, |
| 569 |
U"/Library/Application Support/", Melder_upperCaseAppName()); |
| 570 |
#elif defined (UNIX) |
| 571 |
const conststring32 xdgConfigHome = Melder_getenv (U"XDG_CONFIG_HOME"); |
| 572 |
if (xdgConfigHome) |
| 573 |
Melder_sprint (thePreferencesFolder7. path,kMelder_MAXPATH+1, xdgConfigHome, |
| 574 |
U"/", Melder_lowerCaseAppName()); |
| 575 |
else |
| 576 |
Melder_sprint (thePreferencesFolder7. path,kMelder_MAXPATH+1, homeFolder. path, |
| 577 |
U"/.config/", Melder_lowerCaseAppName()); |
| 578 |
#elif defined (_WIN32) |
| 579 |
Melder_sprint (thePreferencesFolder7. path,kMelder_MAXPATH+1, homeFolder. path, |
| 580 |
U"\\AppData\\Roaming\\", Melder_upperCaseAppName()); |
| 581 |
#endif |
| 582 |
} |
| 583 |
return & thePreferencesFolder7; |
| 584 |
} |
| 585 |
|
| 586 |
void Melder_getTempDir (MelderFolder temporaryFolder) { |
| 587 |
#if defined (macintosh) |
| 588 |
Melder_sprint (temporaryFolder -> path,kMelder_MAXPATH+1, Melder_peek8to32_u (getenv ("TMPDIR"))); // or append /TemporaryItems |
| 589 |
// confstr with _CS_DARWIN_USER_TEMP_DIR |
| 590 |
#else |
| 591 |
(void) temporaryFolder; |
| 592 |
#endif |
| 593 |
} |
| 594 |
|
| 595 |
FILE * Melder_fopen (MelderFile file, const char *type) { |
| 596 |
if (MelderFile_isNull (file)) |
| 597 |
Melder_throw (U"Cannot open null file."); |
| 598 |
if (! Melder_isTracingGlobally) |
| 599 |
Melder_assert (str32equ (Melder_double (1.5), U"1.5")); // check locale settings; because of the required file portability Praat cannot stand "1,5" |
| 600 |
/* |
| 601 |
On the Unix-like systems (including MacOS), the path has to be converted to 8-bit characters in UTF-8 encoding. |
| 602 |
On MacOS, the characters also have to be decomposed. |
| 603 |
On Windows, the characters have to be precomposed. |
| 604 |
*/ |
| 605 |
bool isFolder = false; |
| 606 |
char utf8path [kMelder_MAXPATH+1]; |
| 607 |
Melder_32to8_fileSystem_inplace (file -> path, utf8path); |
| 608 |
FILE *f; |
| 609 |
file -> openForWriting = ( type [0] == 'w' || type [0] == 'a' || strchr (type, '+') ); |
| 610 |
if (str32equ (file -> path, U"<stdout>") && file -> openForWriting) { |
| 611 |
f = Melder_stdout; |
| 612 |
} else { |
| 613 |
//TRACE |
| 614 |
#if defined (_WIN32) && ! defined (__CYGWIN__) |
| 615 |
f = _wfopen (MelderFile_peekPathW (file), Melder_peek32toW (Melder_peek8to32_u (type))); |
| 616 |
#else |
| 617 |
struct stat statbuf; |
| 618 |
int status = stat ((char *) utf8path, & statbuf); |
| 619 |
if (status == -1) { |
| 620 |
if (type [0] == 'r') |
| 621 |
f = nullptr; // and wait for errno to tell us why |
| 622 |
else |
| 623 |
f = fopen ((char *) utf8path, type); |
| 624 |
} else if (S_ISDIR (statbuf. st_mode)) { |
| 625 |
isFolder = true; |
| 626 |
trace (U"A folder is not a file!"); |
| 627 |
f = nullptr; |
| 628 |
} else { |
| 629 |
f = fopen ((char *) utf8path, type); |
| 630 |
} |
| 631 |
#endif |
| 632 |
} |
| 633 |
if (! f) { |
| 634 |
char32 *path = file -> path; |
| 635 |
Melder_appendError ( |
| 636 |
( errno == EPERM || errno == EACCES ? U"No permission to " : U"Cannot " ), |
| 637 |
( type [0] == 'r' ? U"open" : type [0] == 'a' ? U"append to" : U"create" ), |
| 638 |
U" file ", file, U"." |
| 639 |
); |
| 640 |
if (errno == EIO) |
| 641 |
Melder_appendError (U"Not-so-useful hint: an error occurred while reading from the file system."); |
| 642 |
else if (errno == ELOOP) |
| 643 |
Melder_appendError (U"Hint: the file path contains a loop of symbolic links."); |
| 644 |
else if (errno == ENAMETOOLONG) |
| 645 |
Melder_appendError (U"Not-so-useful hint: the file path may be too long. This should not occur."); |
| 646 |
else if (errno == ENOENT) |
| 647 |
if (file -> openForWriting) |
| 648 |
Melder_appendError (U"Hint: one of the folders in this file path does not exist."); |
| 649 |
else |
| 650 |
Melder_appendError (U"Hint: one of the folders or files in this file path does not exist."); |
| 651 |
else if (errno == ENOTDIR) |
| 652 |
Melder_appendError (U"Hint: a component of the file path is not a folder."); |
| 653 |
else if (errno == EOVERFLOW) |
| 654 |
Melder_appendError (U"Not-so-useful hint: the file size is too big."); |
| 655 |
else if (errno != 0) |
| 656 |
#ifdef _WIN32 |
| 657 |
Melder_appendError (U"Not-so-useful hint: unexpected error ", errno, U" (", _doserrno, U")."); |
| 658 |
#else |
| 659 |
Melder_appendError (U"Not-so-useful hint: unexpected error ", errno, U"."); |
| 660 |
#endif |
| 661 |
if (isFolder) |
| 662 |
Melder_appendError (U"Hint: this is a folder, not a file."); |
| 663 |
else if (path [0] == U'\0') |
| 664 |
Melder_appendError (U"Hint: empty file name."); |
| 665 |
else if (path [0] == U' ' || path [0] == U'\t') |
| 666 |
Melder_appendError (U"Hint: file name starts with a space or tab."); |
| 667 |
else if (path [Melder_length (path) - 1] == U' ' || path [Melder_length (path) - 1] == U'\t') |
| 668 |
Melder_appendError (U"Hint: file name ends in a space or tab."); |
| 669 |
else if (str32chr (path, U'\n')) |
| 670 |
Melder_appendError (U"Hint: file name contains a newline symbol."); |
| 671 |
throw MelderError (); |
| 672 |
return nullptr; |
| 673 |
} |
| 674 |
return f; |
| 675 |
} |
| 676 |
|
| 677 |
void Melder_fclose (MelderFile file, FILE *f) { |
| 678 |
if (! f) |
| 679 |
return; |
| 680 |
if (f != Melder_stdout && fclose (f) == EOF) |
| 681 |
Melder_throw (U"Error closing file ", file, U"."); |
| 682 |
} |
| 683 |
|
| 684 |
bool MelderFile_exists (MelderFile file) { |
| 685 |
#if defined (UNIX) |
| 686 |
struct stat fileOrFolderStatus; |
| 687 |
const bool exists = ( stat (MelderFile_peekPath8 (file), & fileOrFolderStatus) == 0 ); |
| 688 |
if (! exists) |
| 689 |
return false; |
| 690 |
return ! S_ISDIR (fileOrFolderStatus. st_mode); |
| 691 |
#else |
| 692 |
DWORD fileOrFolderAttributes = GetFileAttributesW (MelderFile_peekPathW (file)); |
| 693 |
if (fileOrFolderAttributes == INVALID_FILE_ATTRIBUTES) |
| 694 |
return false; |
| 695 |
return (fileOrFolderAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0; |
| 696 |
#endif |
| 697 |
} |
| 698 |
|
| 699 |
bool MelderFolder_exists (MelderFolder folder) { |
| 700 |
#if defined (UNIX) |
| 701 |
struct stat fileOrFolderStatus; |
| 702 |
const bool exists = ( stat (MelderFolder_peekPath8 (folder), & fileOrFolderStatus) == 0 ); |
| 703 |
if (! exists) |
| 704 |
return false; |
| 705 |
return S_ISDIR (fileOrFolderStatus. st_mode); |
| 706 |
#else |
| 707 |
DWORD fileOrFolderAttributes = GetFileAttributesW (MelderFolder_peekPathW (folder)); |
| 708 |
if (fileOrFolderAttributes == INVALID_FILE_ATTRIBUTES) |
| 709 |
return false; |
| 710 |
return (fileOrFolderAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; |
| 711 |
#endif |
| 712 |
} |
| 713 |
|
| 714 |
bool MelderFile_readable (MelderFile file) { |
| 715 |
try { |
| 716 |
autofile f = Melder_fopen (file, "rb"); |
| 717 |
f.close (file); |
| 718 |
return true; |
| 719 |
} catch (MelderError) { |
| 720 |
Melder_clearError (); |
| 721 |
return false; |
| 722 |
} |
| 723 |
} |
| 724 |
|
| 725 |
bool Melder_tryToWriteFile (MelderFile file) { |
| 726 |
try { |
| 727 |
autofile f = Melder_fopen (file, "wb"); |
| 728 |
f.close (file); |
| 729 |
return true; |
| 730 |
} catch (MelderError) { |
| 731 |
Melder_clearError (); |
| 732 |
return false; |
| 733 |
} |
| 734 |
} |
| 735 |
|
| 736 |
bool Melder_tryToAppendFile (MelderFile file) { |
| 737 |
try { |
| 738 |
autofile f = Melder_fopen (file, "ab"); |
| 739 |
f.close (file); |
| 740 |
return true; |
| 741 |
} catch (MelderError) { |
| 742 |
Melder_clearError (); |
| 743 |
return false; |
| 744 |
} |
| 745 |
} |
| 746 |
|
| 747 |
integer MelderFile_length (MelderFile file) { |
| 748 |
#if defined (UNIX) |
| 749 |
struct stat statistics; |
| 750 |
if (stat (MelderFile_peekPath8 (file), & statistics) != 0) |
| 751 |
return -1; |
| 752 |
return statistics. st_size; |
| 753 |
#else |
| 754 |
try { |
| 755 |
autofile f = Melder_fopen (file, "r"); |
| 756 |
fseek (f, 0, SEEK_END); |
| 757 |
integer length = ftell (f); |
| 758 |
f.close (file); |
| 759 |
return length; |
| 760 |
} catch (MelderError) { |
| 761 |
Melder_clearError (); |
| 762 |
return -1; |
| 763 |
} |
| 764 |
#endif |
| 765 |
} |
| 766 |
|
| 767 |
void MelderFile_delete (MelderFile file) { |
| 768 |
if (! file) |
| 769 |
return; |
| 770 |
#if defined (UNIX) |
| 771 |
remove (MelderFile_peekPath8 (file)); |
| 772 |
#elif defined (_WIN32) |
| 773 |
DeleteFile (MelderFile_peekPathW (file)); |
| 774 |
#endif |
| 775 |
} |
| 776 |
|
| 777 |
void MelderFile_moveAndOrRename (MelderFile fromFile, MelderFile toFile) { |
| 778 |
if (! fromFile || ! toFile) |
| 779 |
return; |
| 780 |
try { |
| 781 |
#if defined (UNIX) |
| 782 |
static char fromPath8 [1 + kMelder_MAXPATH], toPath8 [1 + kMelder_MAXPATH]; |
| 783 |
Melder_32to8_fileSystem_inplace (MelderFile_peekPath (fromFile), fromPath8); // not MelderFile_peekPath8, because of static |
| 784 |
Melder_32to8_fileSystem_inplace (MelderFile_peekPath (toFile), toPath8); |
| 785 |
const int result = rename (fromPath8, toPath8); |
| 786 |
#elif defined (_WIN32) |
| 787 |
autostringW fromPathW = Melder_32toW_fileSystem (MelderFile_peekPath (fromFile)); |
| 788 |
autostringW toPathW = Melder_32toW_fileSystem (MelderFile_peekPath (toFile)); |
| 789 |
const int result = _wrename (fromPathW.get(), toPathW.get()); |
| 790 |
#endif |
| 791 |
if (result == 0) |
| 792 |
return; // success |
| 793 |
switch (errno) { |
| 794 |
case EACCES: |
| 795 |
Melder_throw (U"A folder in one of the paths doesn’t allow reading and/or writing access."); |
| 796 |
case EBUSY: |
| 797 |
Melder_throw (U"A folder in one of the paths is busy."); |
| 798 |
case EINVAL: |
| 799 |
Melder_throw (U"Invalid path (recursive? dots?)."); |
| 800 |
case EIO: |
| 801 |
Melder_throw (U"Physical I/O error."); |
| 802 |
case EISDIR: |
| 803 |
Melder_throw (U"Cannot move an/or rename a file to a folder name."); |
| 804 |
#if ! defined (UNIX) && ! defined (_WIN32) |
| 805 |
case EMLOOP: |
| 806 |
Melder_throw (U"Loop in symbolic links."); |
| 807 |
#endif |
| 808 |
case EMLINK: |
| 809 |
Melder_throw (U"Too many links."); |
| 810 |
case ENAMETOOLONG: |
| 811 |
Melder_throw (U"Name too long."); |
| 812 |
case ENOENT: |
| 813 |
Melder_throw (U"A folder or file in the path does not exist."); |
| 814 |
case ENOSPC: |
| 815 |
Melder_throw (U"Folder cannot be extended."); |
| 816 |
case ENOTDIR: |
| 817 |
Melder_throw (U"A part of the path is not a folder (hint: look at the slahes)."); |
| 818 |
case EPERM: |
| 819 |
Melder_throw (U"No permission to read and/or write in one of the paths."); |
| 820 |
case EROFS: |
| 821 |
Melder_throw (U"Cannot do links between file systems."); |
| 822 |
#if ! defined (UNIX) && ! defined (_WIN32) |
| 823 |
case ETXTBUSY: |
| 824 |
Melder_throw (U"Busy pure procedure file."); |
| 825 |
#endif |
| 826 |
default: |
| 827 |
Melder_throw (U"Unknown error ", errno, U"."); |
| 828 |
} |
| 829 |
} catch (MelderError) { |
| 830 |
Melder_throw (U"Could not rename ", fromFile, U" to ", toFile, U"."); |
| 831 |
} |
| 832 |
} |
| 833 |
|
| 834 |
char32 * Melder_peekExpandBackslashes (conststring32 message) { |
| 835 |
static char32 names [11] [kMelder_MAXPATH+1]; |
| 836 |
static int index = 0; |
| 837 |
if (++ index == 11) |
| 838 |
index = 0; |
| 839 |
char32 *to = & names [index] [0]; |
| 840 |
for (const char32 *from = & message [0]; *from != '\0'; from ++, to ++) { |
| 841 |
*to = *from; |
| 842 |
if (*from == U'\\') { |
| 843 |
* ++ to = U'b'; |
| 844 |
* ++ to = U's'; |
| 845 |
} |
| 846 |
} |
| 847 |
*to = U'\0'; |
| 848 |
return & names [index] [0]; |
| 849 |
} |
| 850 |
|
| 851 |
conststring32 MelderFile_messageName (MelderFile file) { |
| 852 |
return Melder_cat (U"“", file -> path, U"”"); // BUG: is cat allowed here? |
| 853 |
} |
| 854 |
|
| 855 |
conststring32 MelderFolder_messageName (MelderFolder folder) { |
| 856 |
return Melder_cat (U"“", folder -> path, U"”"); // BUG: is cat allowed here? |
| 857 |
} |
| 858 |
|
| 859 |
#if defined (UNIX) |
| 860 |
/* |
| 861 |
From macOS 10.15 Catalina on, getcwd() has failed if a part of the path |
| 862 |
is inaccessible, such as when you open a script that is attached to an email message. |
| 863 |
*/ |
| 864 |
static structMelderFolder theDefaultDir; |
| 865 |
#endif |
| 866 |
|
| 867 |
void Melder_getCurrentFolder (MelderFolder folder) { |
| 868 |
#if defined (UNIX) |
| 869 |
char path [kMelder_MAXPATH+1]; |
| 870 |
char *pathResult = getcwd (path, kMelder_MAXPATH+1); |
| 871 |
if (pathResult) |
| 872 |
Melder_8bitFileRepresentationToStr32_inplace (path, folder -> path); |
| 873 |
else if (errno == EPERM) |
| 874 |
str32cpy (folder -> path, theDefaultDir. path); |
| 875 |
else |
| 876 |
Melder_throw (Melder_peek8to32_u (strerror (errno))); |
| 877 |
Melder_assert (Melder_length (folder -> path) <= kMelder_MAXPATH); |
| 878 |
#elif defined (_WIN32) |
| 879 |
static WCHAR folderPathW [kMelder_MAXPATH+1]; |
| 880 |
GetCurrentDirectory (kMelder_MAXPATH+1, folderPathW); |
| 881 |
Melder_sprint (folder -> path,kMelder_MAXPATH+1, Melder_peekWto32 (folderPathW)); |
| 882 |
#endif |
| 883 |
} |
| 884 |
|
| 885 |
void Melder_setCurrentFolder (MelderFolder folder) { |
| 886 |
#if defined (UNIX) |
| 887 |
chdir (MelderFolder_peekPath8 (folder)); |
| 888 |
str32cpy (theDefaultDir. path, folder -> path); |
| 889 |
#elif defined (_WIN32) |
| 890 |
SetCurrentDirectory (MelderFolder_peekPathW (folder)); |
| 891 |
#endif |
| 892 |
} |
| 893 |
|
| 894 |
void MelderFile_setDefaultDir (MelderFile file) { |
| 895 |
structMelderFolder folder { }; |
| 896 |
MelderFile_getParentFolder (file, & folder); |
| 897 |
Melder_setCurrentFolder (& folder); |
| 898 |
} |
| 899 |
|
| 900 |
MelderFolder Melder_peekWorkingDirectory () { |
| 901 |
static structMelderFolder s_workingDirectory; |
| 902 |
Melder_getCurrentFolder (& s_workingDirectory); |
| 903 |
return & s_workingDirectory; |
| 904 |
} |
| 905 |
|
| 906 |
void Melder_createDirectory (MelderFolder parent, conststring32 folderName, int mode) { |
| 907 |
#if defined (UNIX) |
| 908 |
structMelderFile file { }; |
| 909 |
if (folderName [0] == U'/') { |
| 910 |
Melder_sprint (file. path,kMelder_MAXPATH+1, folderName); // absolute path |
| 911 |
} else if (parent -> path [0] == U'/' && parent -> path [1] == U'\0') { |
| 912 |
Melder_sprint (file. path,kMelder_MAXPATH+1, U"/", folderName); // relative path in root folder |
| 913 |
} else { |
| 914 |
Melder_sprint (file. path,kMelder_MAXPATH+1, parent -> path, U"/", folderName); // relative path |
| 915 |
} |
| 916 |
if (mkdir (MelderFile_peekPath8 (& file), mode) == -1 && errno != EEXIST) // ignore if folder already exists |
| 917 |
Melder_throw (U"Cannot create directory ", & file, U"."); |
| 918 |
#elif defined (_WIN32) |
| 919 |
structMelderFile file { }; |
| 920 |
SECURITY_ATTRIBUTES sa; |
| 921 |
(void) mode; |
| 922 |
sa. nLength = sizeof (SECURITY_ATTRIBUTES); |
| 923 |
sa. lpSecurityDescriptor = nullptr; |
| 924 |
sa. bInheritHandle = false; |
| 925 |
if (str32chr (folderName, U':') || folderName [0] == U'/' && folderName [1] == U'/') { |
| 926 |
Melder_sprint (file. path,kMelder_MAXPATH+1, folderName); // absolute path |
| 927 |
} else { |
| 928 |
Melder_sprint (file. path,kMelder_MAXPATH+1, parent -> path, U"/", folderName); // relative path |
| 929 |
} |
| 930 |
if (! CreateDirectoryW (MelderFile_peekPathW (& file), & sa) && GetLastError () != ERROR_ALREADY_EXISTS) // ignore if folder already exists |
| 931 |
Melder_throw (U"Cannot create directory ", & file, U"."); |
| 932 |
#else |
| 933 |
//#error Unsupported operating system. |
| 934 |
#endif |
| 935 |
} |
| 936 |
|
| 937 |
void MelderFolder_create (MelderFolder folder) { |
| 938 |
#if defined (UNIX) |
| 939 |
const int status = mkdir (MelderFolder_peekPath8 (folder), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); |
| 940 |
if (status == 0) |
| 941 |
return; // successfully created a new folder |
| 942 |
if (errno == EEXIST) |
| 943 |
return; // it is no failure if the folder already existed |
| 944 |
Melder_throw (U"Cannot create folder ", folder, U"."); |
| 945 |
#elif defined (_WIN32) |
| 946 |
SECURITY_ATTRIBUTES securityAttributes; |
| 947 |
securityAttributes. nLength = sizeof (SECURITY_ATTRIBUTES); |
| 948 |
securityAttributes. lpSecurityDescriptor = nullptr; |
| 949 |
securityAttributes. bInheritHandle = false; |
| 950 |
const int status = CreateDirectoryW (MelderFolder_peekPathW (folder), & securityAttributes); |
| 951 |
if (status != 0) |
| 952 |
return; // successfully created a new folder |
| 953 |
if (GetLastError () == ERROR_ALREADY_EXISTS) |
| 954 |
return; // it is no failure if the folder already existed |
| 955 |
Melder_throw (U"Cannot create folder ", folder, U"."); |
| 956 |
#else |
| 957 |
#error Unsupported operating system. |
| 958 |
#endif |
| 959 |
} |
| 960 |
void Melder_createFolder (conststring32 path) { |
| 961 |
structMelderFolder folder { }; |
| 962 |
Melder_relativePathToFolder (path, & folder); |
| 963 |
MelderFolder_create (& folder); |
| 964 |
} |
| 965 |
|
| 966 |
static size_t fread_multi (char *buffer, size_t numberOfBytes, FILE *f) { |
| 967 |
off_t offset = 0; |
| 968 |
size_t numberOfBytesRead = 0; |
| 969 |
const size_t chunkSize = 1'000'000'000; |
| 970 |
while (numberOfBytes > chunkSize) { |
| 971 |
size_t numberOfBytesReadInChunk = fread (buffer + offset, sizeof (char), chunkSize, f); |
| 972 |
numberOfBytesRead += numberOfBytesReadInChunk; |
| 973 |
if (numberOfBytesReadInChunk < chunkSize) |
| 974 |
return numberOfBytesRead; |
| 975 |
numberOfBytes -= chunkSize; |
| 976 |
offset += chunkSize; |
| 977 |
} |
| 978 |
size_t numberOfBytesReadInLastChunk = fread (buffer + offset, sizeof (char), numberOfBytes, f); |
| 979 |
numberOfBytesRead += numberOfBytesReadInLastChunk; |
| 980 |
return numberOfBytesRead; |
| 981 |
} |
| 982 |
|
| 983 |
autostring32 MelderFile_readText (MelderFile file, autostring8 *string8) { |
| 984 |
try { |
| 985 |
int type = 0; // 8-bit |
| 986 |
autostring32 text; |
| 987 |
autofile f = Melder_fopen (file, "rb"); |
| 988 |
if (fseeko (f, 0, SEEK_END) < 0) |
| 989 |
Melder_throw (U"Cannot count the bytes in the file."); |
| 990 |
Melder_assert (sizeof (off_t) >= 8); |
| 991 |
int64 length = ftello (f); |
| 992 |
rewind (f); |
| 993 |
if (length >= 2) { |
| 994 |
int firstByte = fgetc (f), secondByte = fgetc (f); |
| 995 |
if (firstByte == 0xFE && secondByte == 0xFF) { |
| 996 |
type = 1; // big-endian 16-bit |
| 997 |
} else if (firstByte == 0xFF && secondByte == 0xFE) { |
| 998 |
type = 2; // little-endian 16-bit |
| 999 |
} else if (firstByte == 0xEF && secondByte == 0xBB && length >= 3) { |
| 1000 |
int thirdByte = fgetc (f); |
| 1001 |
if (thirdByte == 0xBF) |
| 1002 |
type = -1; // UTF-8 with BOM |
| 1003 |
} |
| 1004 |
} |
| 1005 |
if (type <= 0) { |
| 1006 |
if (type == -1) { |
| 1007 |
length -= 3; |
| 1008 |
fseeko (f, 3, SEEK_SET); |
| 1009 |
} else { |
| 1010 |
rewind (f); // length and type already set correctly |
| 1011 |
} |
| 1012 |
autostring8 text8bit (length); |
| 1013 |
Melder_assert (text8bit); |
| 1014 |
size_t numberOfBytesRead = fread_multi (text8bit.get(), (size_t) length, f); |
| 1015 |
Melder_require ((int64) numberOfBytesRead == length, |
| 1016 |
U"The file contains ", length, U" bytes", |
| 1017 |
type == -1 ? U" after the byte-order mark" : U"", |
| 1018 |
U", but we could read only ", numberOfBytesRead, U" of them." |
| 1019 |
); |
| 1020 |
text8bit [length] = '\0'; |
| 1021 |
/* |
| 1022 |
Count and repair null bytes. |
| 1023 |
*/ |
| 1024 |
if (length > 0) { |
| 1025 |
int64 numberOfNullBytes = 0; |
| 1026 |
char *q = & text8bit [0]; |
| 1027 |
for (integer i = 0; i < length; i ++) |
| 1028 |
if (text8bit [i] != '\0') |
| 1029 |
* (q ++) = text8bit [i]; |
| 1030 |
else |
| 1031 |
numberOfNullBytes ++; |
| 1032 |
*q = '\0'; |
| 1033 |
if (numberOfNullBytes > 0) |
| 1034 |
Melder_warning (U"Ignored ", numberOfNullBytes, U" null bytes in text file ", file, U"."); |
| 1035 |
} |
| 1036 |
if (string8) { |
| 1037 |
*string8 = text8bit.move(); |
| 1038 |
(void) Melder_killReturns_inplace (string8->get()); |
| 1039 |
return autostring32(); // OK |
| 1040 |
} else { |
| 1041 |
text = Melder_8to32_e (text8bit.get(), kMelder_textInputEncoding::UNDEFINED); |
| 1042 |
} |
| 1043 |
} else { |
| 1044 |
length = length / 2 - 1; // Byte Order Mark subtracted. Length = number of UTF-16 codes |
| 1045 |
text = autostring32 (length + 1); |
| 1046 |
if (type == 1) { |
| 1047 |
for (int64 i = 0; i < length; i ++) { |
| 1048 |
const char16 kar1 = bingetu16 (f); |
| 1049 |
if (kar1 < 0xD800) { |
| 1050 |
text [i] = (const char32) kar1; // convert up without sign extension |
| 1051 |
} else if (kar1 < 0xDC00) { |
| 1052 |
length --; |
| 1053 |
const char16 kar2 = bingetu16 (f); |
| 1054 |
if (kar2 >= 0xDC00 && kar2 <= 0xDFFF) { |
| 1055 |
text [i] = (const char32) (0x010000 + |
| 1056 |
(const char32) (((const char32) kar1 & 0x0003FF) << 10) + |
| 1057 |
(const char32) ((const char32) kar2 & 0x0003FF)); |
| 1058 |
} else { |
| 1059 |
text [i] = UNICODE_REPLACEMENT_CHARACTER; |
| 1060 |
} |
| 1061 |
} else if (kar1 < 0xE000) { |
| 1062 |
text [i] = UNICODE_REPLACEMENT_CHARACTER; |
| 1063 |
} else { |
| 1064 |
text [i] = (const char32) kar1; // convert up without sign extension |
| 1065 |
} |
| 1066 |
} |
| 1067 |
} else { |
| 1068 |
for (int64 i = 0; i < length; i ++) { |
| 1069 |
const char16 kar1 = bingetu16LE (f); |
| 1070 |
if (kar1 < 0xD800) { |
| 1071 |
text [i] = (const char32) kar1; // convert up without sign extension |
| 1072 |
} else if (kar1 < 0xDC00) { |
| 1073 |
length --; |
| 1074 |
const char16 kar2 = bingetu16LE (f); |
| 1075 |
if (kar2 >= 0xDC00 && kar2 <= 0xDFFF) { |
| 1076 |
text [i] = (const char32) (0x01'0000 + |
| 1077 |
(const char32) (((const char32) kar1 & 0x00'03FF) << 10) + |
| 1078 |
(const char32) ((const char32) kar2 & 0x00'03FF)); |
| 1079 |
} else { |
| 1080 |
text [i] = UNICODE_REPLACEMENT_CHARACTER; |
| 1081 |
} |
| 1082 |
} else if (kar1 < 0xE000) { |
| 1083 |
text [i] = UNICODE_REPLACEMENT_CHARACTER; |
| 1084 |
} else if (kar1 <= 0xFFFF) { |
| 1085 |
text [i] = (const char32) kar1; // convert up without sign extension |
| 1086 |
} else { |
| 1087 |
Melder_crash (U"MelderFile_readText: unsigned short greater than 0xFFFF: should not occur."); |
| 1088 |
} |
| 1089 |
} |
| 1090 |
} |
| 1091 |
text [length] = U'\0'; |
| 1092 |
(void) Melder_killReturns_inplace (text.get()); |
| 1093 |
} |
| 1094 |
f.close (file); |
| 1095 |
return text; |
| 1096 |
} catch (MelderError) { |
| 1097 |
Melder_throw (U"Error reading file ", file, U"."); |
| 1098 |
} |
| 1099 |
} |
| 1100 |
|
| 1101 |
void Melder_fwrite32to8 (conststring32 string, FILE *f) { |
| 1102 |
/* |
| 1103 |
* Precondition: |
| 1104 |
* the string's encoding is UTF-32. |
| 1105 |
* Failure: |
| 1106 |
* if the precondition does not hold, we don't crash, |
| 1107 |
* but the characters that are written may be incorrect. |
| 1108 |
*/ |
| 1109 |
for (const char32* p = string; *p != U'\0'; p ++) { |
| 1110 |
const char32 kar = *p; |
| 1111 |
if (kar <= 0x00'007F) { |
| 1112 |
#ifdef _WIN32 |
| 1113 |
if (kar == U'\n') |
| 1114 |
fputc (13, f); |
| 1115 |
#endif |
| 1116 |
fputc ((int) kar, f); // because fputc wants an int instead of an uint8 (guarded conversion) |
| 1117 |
} else if (kar <= 0x00'07FF) { |
| 1118 |
fputc (0xC0 | (kar >> 6), f); |
| 1119 |
fputc (0x80 | (kar & 0x00'003F), f); |
| 1120 |
} else if (kar <= 0x00FFFF) { |
| 1121 |
fputc (0xE0 | (kar >> 12), f); |
| 1122 |
fputc (0x80 | ((kar >> 6) & 0x00'003F), f); |
| 1123 |
fputc (0x80 | (kar & 0x00'003F), f); |
| 1124 |
} else { |
| 1125 |
fputc (0xF0 | (kar >> 18), f); |
| 1126 |
fputc (0x80 | ((kar >> 12) & 0x00'003F), f); |
| 1127 |
fputc (0x80 | ((kar >> 6) & 0x00'003F), f); |
| 1128 |
fputc (0x80 | (kar & 0x00'003F), f); |
| 1129 |
} |
| 1130 |
} |
| 1131 |
} |
| 1132 |
|
| 1133 |
void MelderFile_writeText_e (MelderFile file, conststring32 text, kMelder_textOutputEncoding outputEncoding) { |
| 1134 |
if (! text) |
| 1135 |
text = U""; |
| 1136 |
autofile f = Melder_fopen (file, "wb"); |
| 1137 |
if (outputEncoding == kMelder_textOutputEncoding::UTF8) { |
| 1138 |
Melder_fwrite32to8 (text, f); |
| 1139 |
} else if ((outputEncoding == kMelder_textOutputEncoding::ASCII_THEN_UTF16 && Melder_isValidAscii (text)) || |
| 1140 |
(outputEncoding == kMelder_textOutputEncoding::ISO_LATIN1_THEN_UTF16 && Melder_isEncodable (text, kMelder_textOutputEncoding_ISO_LATIN1))) |
| 1141 |
{ |
| 1142 |
#ifdef _WIN32 |
| 1143 |
#define flockfile(f) (void) 0 |
| 1144 |
#define funlockfile(f) (void) 0 |
| 1145 |
#define putc_unlocked putc |
| 1146 |
#endif |
| 1147 |
flockfile (f); |
| 1148 |
const integer n = Melder_length (text); |
| 1149 |
for (integer i = 0; i < n; i ++) { |
| 1150 |
char32 kar = text [i]; |
| 1151 |
#ifdef _WIN32 |
| 1152 |
if (kar == U'\n') |
| 1153 |
putc_unlocked (13, f); |
| 1154 |
#endif |
| 1155 |
putc_unlocked (kar, f); |
| 1156 |
} |
| 1157 |
funlockfile (f); |
| 1158 |
} else { |
| 1159 |
binputu16 (0xFEFF, f); // Byte Order Mark |
| 1160 |
const integer n = Melder_length (text); |
| 1161 |
for (integer i = 0; i < n; i ++) { |
| 1162 |
char32 kar = text [i]; |
| 1163 |
#ifdef _WIN32 |
| 1164 |
if (kar == U'\n') |
| 1165 |
binputu16 (13, f); |
| 1166 |
#endif |
| 1167 |
if (kar <= 0x00'FFFF) { |
| 1168 |
binputu16 ((char16) kar, f); // guarded conversion down |
| 1169 |
} else if (kar <= 0x10'FFFF) { |
| 1170 |
kar -= 0x010000; |
| 1171 |
binputu16 (0xD800 | (uint16) (kar >> 10), f); |
| 1172 |
binputu16 (0xDC00 | (uint16) ((char16) kar & 0x3ff), f); |
| 1173 |
} else { |
| 1174 |
binputu16 (UNICODE_REPLACEMENT_CHARACTER, f); |
| 1175 |
} |
| 1176 |
} |
| 1177 |
} |
| 1178 |
f.close (file); |
| 1179 |
} |
| 1180 |
void MelderFile_writeText_i (MelderFile file, conststring32 text, kMelder_textOutputEncoding outputEncoding) { |
| 1181 |
try { |
| 1182 |
MelderFile_writeText_e (file, text, outputEncoding); |
| 1183 |
} catch (MelderError) { |
| 1184 |
Melder_clearError (); |
| 1185 |
} |
| 1186 |
} |
| 1187 |
|
| 1188 |
void MelderFile_appendText_e (MelderFile file, conststring32 text) { |
| 1189 |
if (! text) text = U""; |
| 1190 |
autofile f1; |
| 1191 |
try { |
| 1192 |
f1 = Melder_fopen (file, "rb"); |
| 1193 |
} catch (MelderError) { |
| 1194 |
Melder_clearError (); // it's OK if the file didn't exist yet... |
| 1195 |
MelderFile_writeText_e (file, text, Melder_getOutputEncoding ()); // because then we just "write" |
| 1196 |
return; |
| 1197 |
} |
| 1198 |
/* |
| 1199 |
The file already exists and is open. Determine its type. |
| 1200 |
*/ |
| 1201 |
int firstByte = fgetc (f1), secondByte = fgetc (f1); |
| 1202 |
f1.close (file); |
| 1203 |
int type = 0; |
| 1204 |
if (firstByte == 0xfe && secondByte == 0xff) { |
| 1205 |
type = 1; // big-endian 16-bit |
| 1206 |
} else if (firstByte == 0xff && secondByte == 0xfe) { |
| 1207 |
type = 2; // little-endian 16-bit |
| 1208 |
} |
| 1209 |
if (type == 0) { |
| 1210 |
kMelder_textOutputEncoding outputEncoding = Melder_getOutputEncoding (); |
| 1211 |
if (outputEncoding == kMelder_textOutputEncoding::UTF8) { // TODO: read as file's encoding |
| 1212 |
autofile f2 = Melder_fopen (file, "ab"); |
| 1213 |
Melder_fwrite32to8 (text, f2); |
| 1214 |
f2.close (file); |
| 1215 |
} else if ((outputEncoding == kMelder_textOutputEncoding::ASCII_THEN_UTF16 && Melder_isEncodable (text, kMelder_textOutputEncoding_ASCII)) |
| 1216 |
|| (outputEncoding == kMelder_textOutputEncoding::ISO_LATIN1_THEN_UTF16 && Melder_isEncodable (text, kMelder_textOutputEncoding_ISO_LATIN1))) |
| 1217 |
{ |
| 1218 |
/* |
| 1219 |
Append ASCII or ISOLatin1 text to ASCII or ISOLatin1 file. |
| 1220 |
*/ |
| 1221 |
autofile f2 = Melder_fopen (file, "ab"); |
| 1222 |
const integer n = Melder_length (text); |
| 1223 |
for (integer i = 0; i < n; i ++) { |
| 1224 |
const char32 kar = text [i]; |
| 1225 |
#ifdef _WIN32 |
| 1226 |
if (kar == U'\n') |
| 1227 |
fputc (13, f2); |
| 1228 |
#endif |
| 1229 |
fputc ((char8) kar, f2); |
| 1230 |
} |
| 1231 |
f2.close (file); |
| 1232 |
} else { |
| 1233 |
/* |
| 1234 |
Convert to wide character file. |
| 1235 |
*/ |
| 1236 |
autostring32 oldText = MelderFile_readText (file); |
| 1237 |
autofile f2 = Melder_fopen (file, "wb"); |
| 1238 |
binputu16 (0xfeff, f2); |
| 1239 |
integer n = Melder_length (oldText.get()); |
| 1240 |
for (int64 i = 0; i < n; i ++) { |
| 1241 |
char32 kar = oldText [i]; |
| 1242 |
#ifdef _WIN32 |
| 1243 |
if (kar == U'\n') |
| 1244 |
binputu16 (13, f2); |
| 1245 |
#endif |
| 1246 |
if (kar <= 0x00'FFFF) { |
| 1247 |
binputu16 ((uint16) kar, f2); // guarded conversion down |
| 1248 |
} else if (kar <= 0x10'FFFF) { |
| 1249 |
kar -= 0x01'0000; |
| 1250 |
binputu16 ((uint16) (0x00'D800 | (kar >> 10)), f2); |
| 1251 |
binputu16 ((uint16) (0x00'DC00 | (kar & 0x00'03ff)), f2); |
| 1252 |
} else { |
| 1253 |
binputu16 (UNICODE_REPLACEMENT_CHARACTER, f2); |
| 1254 |
} |
| 1255 |
} |
| 1256 |
n = Melder_length (text); |
| 1257 |
for (integer i = 0; i < n; i ++) { |
| 1258 |
char32 kar = text [i]; |
| 1259 |
#ifdef _WIN32 |
| 1260 |
if (kar == U'\n') |
| 1261 |
binputu16 (13, f2); |
| 1262 |
#endif |
| 1263 |
if (kar <= 0x00'FFFF) { |
| 1264 |
binputu16 ((uint16) kar, f2); // guarded conversion down |
| 1265 |
} else if (kar <= 0x10'FFFF) { |
| 1266 |
kar -= 0x01'0000; |
| 1267 |
binputu16 ((uint16) (0x00'D800 | (kar >> 10)), f2); |
| 1268 |
binputu16 ((uint16) (0x00'DC00 | (kar & 0x00'03ff)), f2); |
| 1269 |
} else { |
| 1270 |
binputu16 (UNICODE_REPLACEMENT_CHARACTER, f2); |
| 1271 |
} |
| 1272 |
} |
| 1273 |
f2.close (file); |
| 1274 |
} |
| 1275 |
} else { |
| 1276 |
autofile f2 = Melder_fopen (file, "ab"); |
| 1277 |
const integer n = Melder_length (text); |
| 1278 |
for (integer i = 0; i < n; i ++) { |
| 1279 |
if (type == 1) { |
| 1280 |
char32 kar = text [i]; |
| 1281 |
#ifdef _WIN32 |
| 1282 |
if (kar == U'\n') |
| 1283 |
binputu16 (13, f2); |
| 1284 |
#endif |
| 1285 |
if (kar <= 0x00'FFFF) { |
| 1286 |
binputu16 ((uint16) kar, f2); // guarded conversion down |
| 1287 |
} else if (kar <= 0x10'FFFF) { |
| 1288 |
kar -= 0x01'0000; |
| 1289 |
binputu16 ((uint16) (0x00'D800 | (kar >> 10)), f2); |
| 1290 |
binputu16 ((uint16) (0x00'DC00 | (kar & 0x00'03ff)), f2); |
| 1291 |
} else { |
| 1292 |
binputu16 (UNICODE_REPLACEMENT_CHARACTER, f2); |
| 1293 |
} |
| 1294 |
} else { |
| 1295 |
char32 kar = text [i]; |
| 1296 |
#ifdef _WIN32 |
| 1297 |
if (kar == U'\n') |
| 1298 |
binputu16LE (13, f2); |
| 1299 |
#endif |
| 1300 |
if (kar <= 0x00'FFFF) { |
| 1301 |
binputu16LE ((uint16) kar, f2); // guarded conversion down |
| 1302 |
} else if (kar <= 0x10FFFF) { |
| 1303 |
kar -= 0x01'0000; |
| 1304 |
binputu16LE ((uint16) (0x00'D800 | (kar >> 10)), f2); |
| 1305 |
binputu16LE ((uint16) (0x00'DC00 | (kar & 0x00'03ff)), f2); |
| 1306 |
} else { |
| 1307 |
binputu16LE (UNICODE_REPLACEMENT_CHARACTER, f2); |
| 1308 |
} |
| 1309 |
} |
| 1310 |
} |
| 1311 |
f2.close (file); |
| 1312 |
} |
| 1313 |
} |
| 1314 |
|
| 1315 |
/* End of file melder_files.cpp */ |