From de6bbdf1760fac48b94d40ed50281ccee7f83391 Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Sun, 3 Jul 2016 13:28:09 -0400 Subject: [PATCH] Changed a few zippath related functions to return their strings as a return value, as opposed to passing in a destination buffer --- src/emu/diimage.cpp | 4 ++-- src/frontend/mame/ui/filesel.cpp | 2 +- src/frontend/mame/ui/floppycntrl.cpp | 2 +- src/frontend/mame/ui/imgcntrl.cpp | 8 +++----- src/lib/util/zippath.cpp | 17 +++++++++-------- src/lib/util/zippath.h | 6 +++--- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/emu/diimage.cpp b/src/emu/diimage.cpp index b6c32826a5a..120147a7d79 100644 --- a/src/emu/diimage.cpp +++ b/src/emu/diimage.cpp @@ -156,7 +156,7 @@ void device_image_interface::device_compute_hash(hash_collection &hashes, const image_error_t device_image_interface::set_image_filename(const char *filename) { m_image_name = filename; - util::zippath_parent(m_working_directory, filename); + m_working_directory = util::zippath_parent(filename); m_basename.assign(m_image_name); int loc1 = m_image_name.find_last_of('\\'); @@ -316,7 +316,7 @@ bool device_image_interface::try_change_working_directory(const char *subdir) /* did we successfully identify the directory? */ if (success) - util::zippath_combine(m_working_directory, m_working_directory.c_str(), subdir); + m_working_directory = util::zippath_combine(m_working_directory.c_str(), subdir); return success; } diff --git a/src/frontend/mame/ui/filesel.cpp b/src/frontend/mame/ui/filesel.cpp index b9df1e5984c..4d415f19f37 100644 --- a/src/frontend/mame/ui/filesel.cpp +++ b/src/frontend/mame/ui/filesel.cpp @@ -228,7 +228,7 @@ menu_file_selector::file_selector_entry *menu_file_selector::append_dirent_entry } // determine the full path - util::zippath_combine(buffer, m_current_directory.c_str(), dirent->name); + buffer = util::zippath_combine(m_current_directory.c_str(), dirent->name); // create the file selector entry entry = &append_entry( diff --git a/src/frontend/mame/ui/floppycntrl.cpp b/src/frontend/mame/ui/floppycntrl.cpp index 9bb2abbdcd4..c59a2495871 100644 --- a/src/frontend/mame/ui/floppycntrl.cpp +++ b/src/frontend/mame/ui/floppycntrl.cpp @@ -131,7 +131,7 @@ void menu_control_floppy_image::handle() state = START_FILE; handle(); } else { - util::zippath_combine(output_filename, current_directory.c_str(), current_file.c_str()); + output_filename = util::zippath_combine(current_directory.c_str(), current_file.c_str()); output_format = format_array[submenu_result]; do_load_create(); menu::stack_pop(machine()); diff --git a/src/frontend/mame/ui/imgcntrl.cpp b/src/frontend/mame/ui/imgcntrl.cpp index 167d1145bb3..02015fb5e6b 100644 --- a/src/frontend/mame/ui/imgcntrl.cpp +++ b/src/frontend/mame/ui/imgcntrl.cpp @@ -61,7 +61,7 @@ menu_control_device_image::menu_control_device_image(mame_ui_manager &mui, rende if (image->exists()) { current_file.assign(image->filename()); - util::zippath_parent(current_directory, current_file.c_str()); + current_directory = util::zippath_parent(current_file.c_str()); } else current_directory.assign(image->working_directory()); @@ -87,11 +87,10 @@ menu_control_device_image::~menu_control_device_image() void menu_control_device_image::test_create(bool &can_create, bool &need_confirm) { - std::string path; osd::directory::entry::entry_type file_type; /* assemble the full path */ - util::zippath_combine(path, current_directory.c_str(), current_file.c_str()); + auto path = util::zippath_combine(current_directory.c_str(), current_file.c_str()); /* does a file or a directory exist at the path */ auto entry = osd_stat(path.c_str()); @@ -323,8 +322,7 @@ void menu_control_device_image::handle() break; case DO_CREATE: { - std::string path; - util::zippath_combine(path, current_directory.c_str(), current_file.c_str()); + auto path = util::zippath_combine(current_directory.c_str(), current_file.c_str()); int err = image->create(path.c_str(), nullptr, nullptr); if (err != 0) machine().popmessage("Error: %s", image->error()); diff --git a/src/lib/util/zippath.cpp b/src/lib/util/zippath.cpp index fc9af8f0c9b..9ac9df5979a 100644 --- a/src/lib/util/zippath.cpp +++ b/src/lib/util/zippath.cpp @@ -140,11 +140,12 @@ static void parse_parent_path(const char *path, int *beginpos, int *endpos) // zippath_parent - retrieves the parent directory // ------------------------------------------------- -std::string &zippath_parent(std::string &dst, const char *path) +std::string zippath_parent(const char *path) { int pos; parse_parent_path(path, &pos, nullptr); + std::string dst; if (pos >= 0) dst.assign(path, pos + 1); else @@ -170,8 +171,9 @@ std::string &zippath_parent(std::string &dst, const char *path) * @return A std::string& */ -std::string &zippath_parent_basename(std::string &dst, const char *path) +std::string zippath_parent_basename(const char *path) { + std::string dst; int beginpos, endpos; parse_parent_path(path, &beginpos, &endpos); dst.copy((char*)(path + beginpos + 1), endpos - beginpos); @@ -196,15 +198,16 @@ std::string &zippath_parent_basename(std::string &dst, const char *path) * @return A std::string& */ -std::string &zippath_combine(std::string &dst, const char *path1, const char *path2) +std::string zippath_combine(const char *path1, const char *path2) { + std::string dst; if (!strcmp(path2, ".")) { dst.assign(path1); } else if (!strcmp(path2, "..")) { - zippath_parent(dst, path1); + dst = zippath_parent(path1); } else if (osd_is_absolute_path(path2)) { @@ -401,8 +404,7 @@ osd_file::error zippath_fopen(const char *filename, UINT32 openflags, util::core if (filerr != osd_file::error::NONE) { /* go up a directory */ - std::string temp; - zippath_parent(temp, mainpath.c_str()); + auto temp = zippath_parent(mainpath.c_str()); /* append to the sub path */ if (subpath.length() > 0) @@ -714,8 +716,7 @@ static osd_file::error zippath_resolve(const char *path, osd::directory::entry:: // if we have not found the file or directory, go up current_entry_type = osd::directory::entry::entry_type::NONE; went_up = true; - std::string parent; - apath = zippath_parent(parent, apath.c_str()); + apath = zippath_parent(apath.c_str()); } } while ((current_entry_type == osd::directory::entry::entry_type::NONE) && !is_root(apath.c_str())); diff --git a/src/lib/util/zippath.h b/src/lib/util/zippath.h index 6449d2b5c5d..a22ce873364 100644 --- a/src/lib/util/zippath.h +++ b/src/lib/util/zippath.h @@ -34,13 +34,13 @@ class zippath_directory; // ----- path operations ----- // retrieves the parent directory -std::string &zippath_parent(std::string &dst, const char *path); +std::string zippath_parent(const char *path); // retrieves the parent directory basename -std::string &zippath_parent_basename(std::string &dst, const char *path); +std::string zippath_parent_basename(const char *path); // combines two paths -std::string &zippath_combine(std::string &dst, const char *path1, const char *path2); +std::string zippath_combine(const char *path1, const char *path2); // ----- file operations -----