Changed a few zippath related functions to return their strings as a return value, as opposed to passing in a destination buffer

This commit is contained in:
Nathan Woods 2016-07-03 13:28:09 -04:00
parent 587e9f5e32
commit de6bbdf176
6 changed files with 19 additions and 20 deletions

View File

@ -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;
}

View File

@ -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(

View File

@ -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());

View File

@ -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());

View File

@ -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()));

View File

@ -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 -----