Skip to content

Commit

Permalink
MelderFile_peekPath, MelderFolder_peekPath
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulBoersma committed Nov 16, 2024
1 parent d87014c commit f0ea980
Show file tree
Hide file tree
Showing 29 changed files with 76 additions and 76 deletions.
8 changes: 4 additions & 4 deletions dwsys/FileInMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ autoFileInMemory FileInMemory_create (MelderFile file) {
const integer length = MelderFile_length (file);

autoFileInMemory me = Thing_new (FileInMemory);
my string = Melder_dup (Melder_fileToPath (file));
my string = Melder_dup (MelderFile_peekPath (file));
my d_numberOfBytes = length;
my _dontOwnData = false;
my d_data = newvectorzero <byte> (my d_numberOfBytes + 1); // includes room for a final null byte in case the file happens to contain only text
Expand All @@ -68,7 +68,7 @@ autoFileInMemory FileInMemory_create (MelderFile file) {
MelderFile_close (file);
return me;
} catch (MelderError) {
Melder_throw (U"FileInMemory not created from \"", Melder_fileToPath (file), U"\".");
Melder_throw (U"FileInMemory not created from file ", file, U".");
}
}

Expand Down Expand Up @@ -828,8 +828,8 @@ static void testOneFile (
Full paths should not work:
*/
MelderInfo_writeLine (U"Testing fopen...");
MelderInfo_writeLine (U"\tTrying to open file-in-memory via full path:\n\t\t\"", Melder_fileToPath (& theTestFile), U"\"...");
theTestFim = FileInMemorySet_fopen (theTestFileInMemorySet.get(), Melder_peek32to8_fileSystem (Melder_fileToPath (& theTestFile)), "rb");
MelderInfo_writeLine (U"\tTrying to open file-in-memory via full path:\n\t\t\"", MelderFile_peekPath (& theTestFile), U"\"...");
theTestFim = FileInMemorySet_fopen (theTestFileInMemorySet.get(), Melder_peek32to8_fileSystem (MelderFile_peekPath (& theTestFile)), "rb");
Melder_require (theTestFim == nullptr,
U"FileInMemory should have been null.");
/*
Expand Down
2 changes: 1 addition & 1 deletion dwtools/Sound_extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ autoSound Sound_readFromOggVorbisFile (MelderFile file) {
autoSound Sound_readFromOggOpusFile (MelderFile file) {
try {
int error;
OggOpusFile *opusFile = op_open_file (Melder_peek32to8_fileSystem (Melder_fileToPath (file)), & error);
OggOpusFile *opusFile = op_open_file (Melder_peek32to8_fileSystem (MelderFile_peekPath (file)), & error);
if (error != 0) {
if (error == OP_EREAD)
Melder_throw (U"Reading error.");
Expand Down
4 changes: 2 additions & 2 deletions dwtools/VowelEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,8 @@ static void menu_cb_vowelMarksFromTableFile (VowelEditor me, EDITOR_ARGS) {
EDITOR_FORM_READ (U"VowelEditor: Show vowel marks from Table file", U"VowelEditor: Show vowel marks from Table file...");
EDITOR_DO_READ
Melder_require (isValidVowelMarksTableFile (file, nullptr),
U"File '", Melder_fileToPath (file), U"' does not contain valid Table data.");
my setInstancePref_marks_fileName (Melder_fileToPath (file));
U"File ", file, U" does not contain valid Table data.");
my setInstancePref_marks_fileName (MelderFile_peekPath (file));
my setInstancePref_marks_speakerType (kVowelEditor_speakerType::UNKNOWN);
my setInstancePref_marks_dataSet (kVowelEditor_marksDataSet::OTHER);
VowelEditor_getVowelMarksFromFile (me);
Expand Down
2 changes: 1 addition & 1 deletion fon/LongSound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void structLongSound :: v1_info () {
U"IEEE float 64 bit big-endian", U"IEEE float 64 bit little-endian",
U"FLAC", U"FLAC", U"FLAC", U"MP3", U"MP3", U"MP3" };
MelderInfo_writeLine (U"Duration: ", xmax - xmin, U" seconds");
MelderInfo_writeLine (U"File name: ", Melder_fileToPath (& file));
MelderInfo_writeLine (U"File name: ", MelderFile_peekPath (& file));
MelderInfo_writeLine (U"File type: ", audioFileType > Melder_NUMBER_OF_AUDIO_FILE_TYPES ? U"unknown" : Melder_audioFileTypeString (audioFileType));
MelderInfo_writeLine (U"Number of channels: ", numberOfChannels);
MelderInfo_writeLine (U"Encoding: ", encoding > 20 ? U"unknown" : encodingStrings [encoding]);
Expand Down
6 changes: 3 additions & 3 deletions fon/Movie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ autoMovie Movie_openFromSoundFile (MelderFile file)
autoMovie me = Thing_new (Movie);
autoSound sound = Sound_readFromSoundFile (file);
autoMelderString fileNameHead;
MelderString_copy (& fileNameHead, Melder_fileToPath (file));
MelderString_copy (& fileNameHead, MelderFile_peekPath (file));
char32 *extensionLocation = str32rchr (fileNameHead.string, U'.');
if (! extensionLocation)
extensionLocation = & fileNameHead.string [fileNameHead.length];
Expand All @@ -74,7 +74,7 @@ autoMovie Movie_openFromSoundFile (MelderFile file)
autoStrings strings = Strings_createAsFileList (Melder_cat (fileNameHead.string, U"*.png"));
structMelderFolder folder { };
MelderFile_getParentFolder (file, & folder);
Movie_init (me.get(), sound.move(), Melder_folderToPath (& folder), strings.move());
Movie_init (me.get(), sound.move(), MelderFolder_peekPath (& folder), strings.move());
return me;
} catch (MelderError) {
Melder_throw (U"Movie object not read from file ", file, U".");
Expand All @@ -94,7 +94,7 @@ void Movie_paintOneImageInside (Movie me, Graphics graphics, integer frameNumber
Melder_pathToFolder (my d_folderName.get(), & folder);
structMelderFile file { };
MelderFolder_getFile (& folder, my d_fileNames -> strings [frameNumber].get(), & file);
Graphics_imageFromFile (graphics, Melder_fileToPath (& file), xmin, xmax, ymin, ymax);
Graphics_imageFromFile (graphics, MelderFile_peekPath (& file), xmin, xmax, ymin, ymax);
} catch (MelderError) {
Melder_throw (me, U": image ", frameNumber, U" not painted.");
}
Expand Down
14 changes: 7 additions & 7 deletions fon/Photo.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Photo.cpp
*
* Copyright (C) 2013-2023 Paul Boersma
* Copyright (C) 2013-2024 Paul Boersma
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -102,7 +102,7 @@ autoPhoto Photo_createSimple (integer numberOfRows, integer numberOfColumns) {
autoPhoto Photo_readFromImageFile (MelderFile file) {
try {
#if defined (linux) && ! defined (NO_GRAPHICS)
cairo_surface_t *surface = cairo_image_surface_create_from_png (Melder_peek32to8_fileSystem (Melder_fileToPath (file)));
cairo_surface_t *surface = cairo_image_surface_create_from_png (Melder_peek32to8_fileSystem (MelderFile_peekPath (file)));
//if (cairo_surface_status)
// Melder_throw (U"Error opening PNG file.");
integer width = cairo_image_surface_get_width (surface);
Expand Down Expand Up @@ -142,7 +142,7 @@ autoPhoto Photo_readFromImageFile (MelderFile file) {
cairo_surface_destroy (surface);
return me;
#elif defined (_WIN32)
Gdiplus::Bitmap gdiplusBitmap (Melder_peek32toW_fileSystem (Melder_fileToPath (file)));
Gdiplus::Bitmap gdiplusBitmap (Melder_peek32toW_fileSystem (MelderFile_peekPath (file)));
integer width = gdiplusBitmap. GetWidth ();
integer height = gdiplusBitmap. GetHeight ();
if (width == 0 || height == 0)
Expand All @@ -161,7 +161,7 @@ autoPhoto Photo_readFromImageFile (MelderFile file) {
return me;
#elif defined (macintosh)
autoPhoto me;
CFStringRef path = CFStringCreateWithCString (nullptr, Melder_peek32to8_fileSystem (Melder_fileToPath (file)), kCFStringEncodingUTF8);
CFStringRef path = CFStringCreateWithCString (nullptr, Melder_peek32to8_fileSystem (MelderFile_peekPath (file)), kCFStringEncodingUTF8);
CFURLRef url = CFURLCreateWithFileSystemPath (nullptr, path, kCFURLPOSIXPathStyle, false);
CFRelease (path);
CGImageSourceRef imageSource = CGImageSourceCreateWithURL (url, nullptr);
Expand Down Expand Up @@ -236,7 +236,7 @@ autoPhoto Photo_readFromImageFile (MelderFile file) {
}
cairo_surface_t *surface = cairo_image_surface_create_for_data (imageData,
format, my nx, my ny, bytesPerRow);
cairo_surface_write_to_png (surface, Melder_peek32to8_fileSystem (Melder_fileToPath (file)));
cairo_surface_write_to_png (surface, Melder_peek32to8_fileSystem (MelderFile_peekPath (file)));
cairo_surface_destroy (surface);
}
#endif
Expand Down Expand Up @@ -278,7 +278,7 @@ autoPhoto Photo_readFromImageFile (MelderFile file) {
encoderParameters. Parameter [0]. Value = & quality;
p = & encoderParameters;
}
gdiplusBitmap. Save (Melder_peek32toW_fileSystem (Melder_fileToPath (file)),
gdiplusBitmap. Save (Melder_peek32toW_fileSystem (MelderFile_peekPath (file)),
& imageEncoderInfos [iencoder]. Clsid, p);
Melder_free (imageEncoderInfos);
return;
Expand Down Expand Up @@ -317,7 +317,7 @@ autoPhoto Photo_readFromImageFile (MelderFile file) {
8, 32, integer_to_uinteger (bytesPerRow), colourSpace, kCGImageAlphaNone, dataProvider, nullptr, false, kCGRenderingIntentDefault);
CGDataProviderRelease (dataProvider);
Melder_assert (image);
NSString *path = (NSString *) Melder_peek32toCfstring (Melder_fileToPath (file));
NSString *path = (NSString *) Melder_peek32toCfstring (MelderFile_peekPath (file));
CFURLRef url = (CFURLRef) [NSURL fileURLWithPath: path isDirectory: NO];
CGImageDestinationRef destination = CGImageDestinationCreateWithURL (url, (CFStringRef) which, 1, nullptr);
CGImageDestinationAddImage (destination, image, nil);
Expand Down
4 changes: 2 additions & 2 deletions fon/praat_uvafon_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2617,7 +2617,7 @@ FORM (NEW1_Strings_createAsFileList, U"Create Strings as file list", U"Create St
SENTENCE (name, U"Name", U"fileList")
static structMelderFolder defaultFolder { };
Melder_getHomeDir (& defaultFolder);
static conststring32 homeDirectory = Melder_folderToPath (& defaultFolder);
static conststring32 homeDirectory = MelderFolder_peekPath (& defaultFolder);
static char32 defaultPath [kMelder_MAXPATH+1];
#if defined (UNIX)
Melder_sprint (defaultPath,kMelder_MAXPATH+1, homeDirectory, U"/*.wav");
Expand All @@ -2642,7 +2642,7 @@ FORM (NEW1_Strings_createAsFolderList, U"Create Strings as folder list", U"Creat
SENTENCE (name, U"Name", U"folderList")
static structMelderFolder defaultFolder { };
Melder_getHomeDir (& defaultFolder);
static conststring32 homeDirectory = Melder_folderToPath (& defaultFolder);
static conststring32 homeDirectory = MelderFolder_peekPath (& defaultFolder);
static char32 defaultPath [kMelder_MAXPATH+1];
#if defined (UNIX)
Melder_sprint (defaultPath,kMelder_MAXPATH+1, homeDirectory, U"/*");
Expand Down
2 changes: 1 addition & 1 deletion foned/RunnerMFC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static void drawNow (RunnerMFC me) {
if (str32nequ (textToDraw, U"\\FI", 3)) {
structMelderFile file { };
MelderFolder_relativePathToFile (& my experiment -> rootDirectory, textToDraw + 3, & file);
Graphics_imageFromFile (my graphics.get(), Melder_fileToPath (& file), response -> left, response -> right, response -> bottom, response -> top);
Graphics_imageFromFile (my graphics.get(), MelderFile_peekPath (& file), response -> left, response -> right, response -> bottom, response -> top);
} else {
Graphics_setColour (my graphics.get(),
response -> name [0] == U'\0' ? Melder_SILVER :
Expand Down
2 changes: 1 addition & 1 deletion melder/melder_audiofiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ static void Melder_checkNistFile (FILE *f, integer *numberOfChannels, int *encod
static void Melder_checkFlacFile (MelderFile file, integer *numberOfChannels_out, int *encoding_out,
double *sampleRate_out, integer *startOfData_out, integer *numberOfSamples_out)
{
const conststring8 fileName_utf8 = Melder_peek32to8_fileSystem (Melder_fileToPath (file));
const conststring8 fileName_utf8 = Melder_peek32to8_fileSystem (MelderFile_peekPath (file));
FLAC__StreamMetadata metadata;
if (! FLAC__metadata_get_streaminfo (fileName_utf8, & metadata)) // Unicode-savvy (test/fon/soundFiles.praat 2024-08-11)
Melder_throw (U"Invalid FLAC file");
Expand Down
6 changes: 3 additions & 3 deletions melder/melder_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static char32 theShellDirectory [kMelder_MAXPATH+1];
void Melder_rememberShellDirectory () {
structMelderFolder shellFolder { };
Melder_getCurrentFolder (& shellFolder);
str32cpy (theShellDirectory, Melder_folderToPath (& shellFolder));
str32cpy (theShellDirectory, MelderFolder_peekPath (& shellFolder));
}
conststring32 Melder_getShellDirectory () {
return & theShellDirectory [0];
Expand Down Expand Up @@ -307,11 +307,11 @@ void Melder_relativePathToFolder (conststring32 path, MelderFolder folder) {
#endif
}

conststring32 Melder_fileToPath (MelderFile file) {
conststring32 MelderFile_peekPath (MelderFile file) {
return & file -> path [0];
}

conststring32 Melder_folderToPath (MelderFolder folder) {
conststring32 MelderFolder_peekPath (MelderFolder folder) {
return & folder -> path [0];
}

Expand Down
4 changes: 2 additions & 2 deletions melder/melder_files.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ void Melder_pathToFile (conststring32 path, MelderFile file);
void Melder_pathToFolder (conststring32 path, MelderFolder folder);
void Melder_relativePathToFile (conststring32 path, MelderFile file);
void Melder_relativePathToFolder (conststring32 path, MelderFolder folder);
conststring32 Melder_folderToPath (MelderFolder folder);
conststring32 MelderFolder_peekPath (MelderFolder folder);
/* Returns a pointer internal to 'folder', like "/u/paul/praats" or "D:\Paul\Praats" */
conststring32 Melder_fileToPath (MelderFile file);
conststring32 MelderFile_peekPath (MelderFile file);
void MelderFile_copy (constMelderFile file, MelderFile copy);
void MelderFolder_copy (constMelderFolder folder, MelderFolder copy);
bool MelderFile_equal (MelderFile file1, MelderFile file2);
Expand Down
2 changes: 1 addition & 1 deletion sys/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static GuiMenuItem EditorMenu_addCommandScript (EditorMenu me, conststring32 ite
} else {
structMelderFile file { };
Melder_relativePathToFile (script, & file);
cmd -> script = Melder_dup (Melder_fileToPath (& file));
cmd -> script = Melder_dup (MelderFile_peekPath (& file));
}
GuiMenuItem result = cmd -> itemWidget;
my commands. addItem_move (cmd.move());
Expand Down
10 changes: 5 additions & 5 deletions sys/GraphicsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void structGraphicsScreen :: v9_destroy () noexcept {
cairo_surface_flush (d_cairoSurface);
if (d_isPng) {
#if 1
cairo_surface_write_to_png (d_cairoSurface, Melder_peek32to8_fileSystem (Melder_fileToPath (& d_file)));
cairo_surface_write_to_png (d_cairoSurface, Melder_peek32to8_fileSystem (MelderFile_peekPath (& d_file)));
#else
unsigned char *bitmap = cairo_image_surface_get_data (my d_cairoSurface); // peeking into the internal bits
// copy bitmap to PNG structure created with the PNG library
Expand Down Expand Up @@ -138,7 +138,7 @@ void structGraphicsScreen :: v9_destroy () noexcept {
Gdiplus::GetImageEncoders (numberOfImageEncoders, sizeOfImageEncoderArray, imageEncoderInfos);
for (int iencoder = 0; iencoder < numberOfImageEncoders; iencoder ++) {
if (! wcscmp (imageEncoderInfos [iencoder]. MimeType, L"image/png")) {
gdiplusBitmap. Save (Melder_peek32toW_fileSystem (Melder_fileToPath (& our d_file)),
gdiplusBitmap. Save (Melder_peek32toW_fileSystem (MelderFile_peekPath (& our d_file)),
& imageEncoderInfos [iencoder]. Clsid, nullptr);
}
}
Expand Down Expand Up @@ -185,7 +185,7 @@ void structGraphicsScreen :: v9_destroy () noexcept {
Melder_assert (properties);

CFURLRef url = CFURLCreateWithFileSystemPath (nullptr,
(CFStringRef) Melder_peek32toCfstring (Melder_fileToPath (& d_file)), kCFURLPOSIXPathStyle, false);
(CFStringRef) Melder_peek32toCfstring (MelderFile_peekPath (& d_file)), kCFURLPOSIXPathStyle, false);
CGImageDestinationRef imageDestination = CGImageDestinationCreateWithURL (url, kUTTypePNG, 1, nullptr);
if (imageDestination) {
CGImageDestinationAddImage (imageDestination, image, properties);
Expand Down Expand Up @@ -598,7 +598,7 @@ autoGraphics Graphics_create_pdffile (MelderFile file, int resolution,
#endif
Graphics_init (me.get(), resolution);
#if cairo
my d_cairoSurface = cairo_pdf_surface_create (Melder_peek32to8_fileSystem (Melder_fileToPath (file)),
my d_cairoSurface = cairo_pdf_surface_create (Melder_peek32to8_fileSystem (MelderFile_peekPath (file)),
( isdefined (x1inches) ? x2inches - x1inches : x2inches ) * 72.0,
( isdefined (y1inches) ? y2inches - y1inches : y2inches ) * 72.0);
my d_cairoGraphicsContext = cairo_create (my d_cairoSurface);
Expand All @@ -615,7 +615,7 @@ autoGraphics Graphics_create_pdffile (MelderFile file, int resolution,
( isdefined (x1inches) ? - x1inches : 0.0 ) * resolution,
( isdefined (y1inches) ? (y2inches - 12.0) : 0.0 ) * resolution);
#elif quartz
CFURLRef url = CFURLCreateWithFileSystemPath (nullptr, (CFStringRef) Melder_peek32toCfstring (Melder_fileToPath (file)), kCFURLPOSIXPathStyle, false);
CFURLRef url = CFURLCreateWithFileSystemPath (nullptr, (CFStringRef) Melder_peek32toCfstring (MelderFile_peekPath (file)), kCFURLPOSIXPathStyle, false);
CGRect rect = CGRectMake (0, 0,
( isdefined (x1inches) ? x2inches - x1inches : x2inches ) * 72.0,
( isdefined (y1inches) ? y2inches - y1inches : y2inches ) * 72.0); // don't tire PDF viewers with funny origins
Expand Down
4 changes: 2 additions & 2 deletions sys/Graphics_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ static void _GraphicsScreen_imageFromFile (GraphicsScreen me, conststring32 rela
if (my d_useGdiplus) {
structMelderFile file { };
Melder_relativePathToFile (relativeFileName, & file);
Gdiplus::Bitmap image (Melder_peek32toW_fileSystem (Melder_fileToPath (& file)));
Gdiplus::Bitmap image (Melder_peek32toW_fileSystem (MelderFile_peekPath (& file)));
if (x1 == x2 && y1 == y2) {
width = image. GetWidth (), x1DC -= width / 2, x2DC = x1DC + width;
height = image. GetHeight (), y2DC -= height / 2, y1DC = y2DC + height;
Expand All @@ -852,7 +852,7 @@ static void _GraphicsScreen_imageFromFile (GraphicsScreen me, conststring32 rela
#elif quartz
structMelderFile file { };
Melder_relativePathToFile (relativeFileName, & file);
CFStringRef path = CFStringCreateWithCString (nullptr, Melder_peek32to8_fileSystem (Melder_fileToPath (& file)), kCFStringEncodingUTF8);
CFStringRef path = CFStringCreateWithCString (nullptr, Melder_peek32to8_fileSystem (MelderFile_peekPath (& file)), kCFStringEncodingUTF8);
CFURLRef url = CFURLCreateWithFileSystemPath (nullptr, path, kCFURLPOSIXPathStyle, false);
CFRelease (path);
CGImageSourceRef imageSource = CGImageSourceCreateWithURL (url, nullptr);
Expand Down
Loading

0 comments on commit f0ea980

Please sign in to comment.