summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Vas Crabb <cuavas@users.noreply.github.com>2016-07-30 12:25:22 +1000
committer GitHub <noreply@github.com>2016-07-30 12:25:22 +1000
commit9c9ee49c9f29c340422bee31ba04bd19f1754924 (patch)
tree178419acccd6ffcec59c5ddc20330fd0f9867de6
parent3d6f79ffeab41b2da5f4d6afa4ac62c134fc6970 (diff)
parentbfbc8d38f1713dacc440134e5ceb710ed3c6a0d1 (diff)
Merge pull request #1156 from npwoods/zippath_strstring
Converted a number of zippath calls that took 'const char *' to std::string
-rw-r--r--src/devices/imagedev/floppy.cpp2
-rw-r--r--src/emu/diimage.cpp4
-rw-r--r--src/frontend/mame/ui/filesel.cpp7
-rw-r--r--src/frontend/mame/ui/floppycntrl.cpp4
-rw-r--r--src/frontend/mame/ui/imgcntrl.cpp4
-rw-r--r--src/lib/util/zippath.cpp70
-rw-r--r--src/lib/util/zippath.h16
7 files changed, 53 insertions, 54 deletions
diff --git a/src/devices/imagedev/floppy.cpp b/src/devices/imagedev/floppy.cpp
index b9f5ea19767..44b80e6629a 100644
--- a/src/devices/imagedev/floppy.cpp
+++ b/src/devices/imagedev/floppy.cpp
@@ -363,7 +363,7 @@ floppy_image_format_t *floppy_image_device::identify(std::string filename)
util::core_file::ptr fd;
std::string revised_path;
- osd_file::error err = util::zippath_fopen(filename.c_str(), OPEN_FLAG_READ, fd, revised_path);
+ osd_file::error err = util::zippath_fopen(filename, OPEN_FLAG_READ, fd, revised_path);
if(err != osd_file::error::NONE) {
seterror(IMAGE_ERROR_INVALIDIMAGE, "Unable to open the image file");
return nullptr;
diff --git a/src/emu/diimage.cpp b/src/emu/diimage.cpp
index e5497120f5e..862058063dc 100644
--- a/src/emu/diimage.cpp
+++ b/src/emu/diimage.cpp
@@ -350,7 +350,7 @@ bool device_image_interface::try_change_working_directory(const char *subdir)
// did we successfully identify the directory?
if (success)
- m_working_directory = util::zippath_combine(m_working_directory.c_str(), subdir);
+ m_working_directory = util::zippath_combine(m_working_directory, subdir);
return success;
}
@@ -652,7 +652,7 @@ image_error_t device_image_interface::load_image_by_path(UINT32 open_flags, cons
std::string revised_path;
// attempt to read the file
- auto const filerr = util::zippath_fopen(path.c_str(), open_flags, m_file, revised_path);
+ auto const filerr = util::zippath_fopen(path, open_flags, m_file, revised_path);
// did the open succeed?
switch(filerr)
diff --git a/src/frontend/mame/ui/filesel.cpp b/src/frontend/mame/ui/filesel.cpp
index 21a0d35c28f..3f26d3cf562 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
- buffer = util::zippath_combine(m_current_directory.c_str(), dirent->name);
+ buffer = util::zippath_combine(m_current_directory, dirent->name);
// create the file selector entry
entry = &append_entry(
@@ -296,10 +296,9 @@ void menu_file_selector::populate()
const file_selector_entry *selected_entry = nullptr;
int i;
const char *volume_name;
- const char *path = m_current_directory.c_str();
// open the directory
- err = util::zippath_opendir(path, &directory);
+ err = util::zippath_opendir(m_current_directory, &directory);
// clear out the menu entries
m_entrylist.clear();
@@ -409,7 +408,7 @@ void menu_file_selector::handle()
case SELECTOR_ENTRY_TYPE_DRIVE:
case SELECTOR_ENTRY_TYPE_DIRECTORY:
// drive/directory - first check the path
- err = util::zippath_opendir(entry->fullpath.c_str(), nullptr);
+ err = util::zippath_opendir(entry->fullpath, nullptr);
if (err != osd_file::error::NONE)
{
// this path is problematic; present the user with an error and bail
diff --git a/src/frontend/mame/ui/floppycntrl.cpp b/src/frontend/mame/ui/floppycntrl.cpp
index eeebd5981ef..1208f0b1181 100644
--- a/src/frontend/mame/ui/floppycntrl.cpp
+++ b/src/frontend/mame/ui/floppycntrl.cpp
@@ -87,7 +87,7 @@ void menu_control_floppy_image::hook_load(std::string filename, bool softlist)
std::string tmp_path;
util::core_file::ptr tmp_file;
// attempt to open the file for writing but *without* create
- filerr = util::zippath_fopen(filename.c_str(), OPEN_FLAG_READ | OPEN_FLAG_WRITE, tmp_file, tmp_path);
+ filerr = util::zippath_fopen(filename, OPEN_FLAG_READ | OPEN_FLAG_WRITE, tmp_file, tmp_path);
if(filerr == osd_file::error::NONE)
tmp_file.reset();
else
@@ -131,7 +131,7 @@ void menu_control_floppy_image::handle()
m_state = START_FILE;
handle();
} else {
- output_filename = util::zippath_combine(m_current_directory.c_str(), m_current_file.c_str());
+ output_filename = util::zippath_combine(m_current_directory, m_current_file);
output_format = format_array[m_submenu_result.i];
do_load_create();
stack_pop();
diff --git a/src/frontend/mame/ui/imgcntrl.cpp b/src/frontend/mame/ui/imgcntrl.cpp
index ee93381d52a..8e370509a1c 100644
--- a/src/frontend/mame/ui/imgcntrl.cpp
+++ b/src/frontend/mame/ui/imgcntrl.cpp
@@ -69,7 +69,7 @@ menu_control_device_image::menu_control_device_image(mame_ui_manager &mui, rende
}
// check to see if the path exists; if not clear it
- if (util::zippath_opendir(m_current_directory.c_str(), nullptr) != osd_file::error::NONE)
+ if (util::zippath_opendir(m_current_directory, nullptr) != osd_file::error::NONE)
m_current_directory.clear();
}
}
@@ -91,7 +91,7 @@ menu_control_device_image::~menu_control_device_image()
void menu_control_device_image::test_create(bool &can_create, bool &need_confirm)
{
// assemble the full path
- auto path = util::zippath_combine(m_current_directory.c_str(), m_current_file.c_str());
+ auto path = util::zippath_combine(m_current_directory, m_current_file);
// does a file or a directory exist at the path
auto entry = osd_stat(path.c_str());
diff --git a/src/lib/util/zippath.cpp b/src/lib/util/zippath.cpp
index 0494a96def5..1eb2eba9274 100644
--- a/src/lib/util/zippath.cpp
+++ b/src/lib/util/zippath.cpp
@@ -102,7 +102,7 @@ int is_path_separator(char c)
// -------------------------------------------------
/**
- * @fn static void parse_parent_path(const char *path, int *beginpos, int *endpos)
+ * @fn static void parse_parent_path(const std::string &path, std::string::size_type *beginpos, std::string::size_type *endpos)
*
* @brief Parse parent path.
*
@@ -111,25 +111,25 @@ int is_path_separator(char c)
* @param [in,out] endpos If non-null, the endpos.
*/
-static void parse_parent_path(const char *path, int *beginpos, int *endpos)
+static void parse_parent_path(const std::string &path, std::string::size_type *beginpos, std::string::size_type *endpos)
{
- int length = strlen(path);
- int pos;
+ std::string::size_type length = path.length();
+ std::string::size_type pos;
- /* skip over trailing path separators */
- pos = length - 1;
- while((pos > 0) && is_path_separator(path[pos]))
+ // skip over trailing path separators
+ pos = length ? (length - 1) : std::string::npos;
+ while ((pos > 0) && (pos != std::string::npos) && is_path_separator(path[pos]))
pos--;
- /* return endpos */
+ // return endpos
if (endpos != nullptr)
*endpos = pos;
- /* now skip until we find a path separator */
- while((pos >= 0) && !is_path_separator(path[pos]))
- pos--;
+ // now skip until we find a path separator
+ while ((pos != std::string::npos) && !is_path_separator(path[pos]))
+ pos = (pos > 0) ? pos - 1 : std::string::npos;
- /* return beginpos */
+ // return beginpos
if (beginpos != nullptr)
*beginpos = pos;
}
@@ -140,13 +140,13 @@ 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(std::string &dst, const std::string &path)
{
- int pos;
+ std::string::size_type pos;
parse_parent_path(path, &pos, nullptr);
- if (pos >= 0)
- dst.assign(path, pos + 1);
+ if (pos != std::string::npos)
+ dst = path.substr(0, pos + 1);
else
dst.clear();
return dst;
@@ -158,7 +158,7 @@ std::string &zippath_parent(std::string &dst, const char *path)
// zippath_parent - retrieves the parent directory
// -------------------------------------------------
-std::string zippath_parent(const char *path)
+std::string zippath_parent(const std::string &path)
{
std::string result;
zippath_parent(result, path);
@@ -173,7 +173,7 @@ std::string zippath_parent(const char *path)
// -------------------------------------------------
/**
- * @fn std::string &zippath_parent_basename(std::string &dst, const char *path)
+ * @fn std::string &zippath_parent_basename(std::string &dst, const std::string &path)
*
* @brief Zippath parent basename.
*
@@ -183,11 +183,11 @@ std::string zippath_parent(const char *path)
* @return A std::string&amp;
*/
-std::string &zippath_parent_basename(std::string &dst, const char *path)
+std::string &zippath_parent_basename(std::string &dst, const std::string &path)
{
- int beginpos, endpos;
+ std::string::size_type beginpos, endpos;
parse_parent_path(path, &beginpos, &endpos);
- dst.copy((char*)(path + beginpos + 1), endpos - beginpos);
+ dst.copy((char*)(path.c_str() + beginpos + 1), endpos - beginpos);
return dst;
}
@@ -198,7 +198,7 @@ std::string &zippath_parent_basename(std::string &dst, const char *path)
// directory basename
// -------------------------------------------------
-std::string zippath_parent_basename(const char *path)
+std::string zippath_parent_basename(const std::string &path)
{
std::string result;
zippath_parent_basename(result, path);
@@ -223,13 +223,13 @@ std::string zippath_parent_basename(const char *path)
* @return A std::string&amp;
*/
-std::string &zippath_combine(std::string &dst, const char *path1, const char *path2)
+std::string &zippath_combine(std::string &dst, const std::string &path1, const std::string &path2)
{
- if (!strcmp(path2, "."))
+ if (path2 == ".")
{
dst.assign(path1);
}
- else if (!strcmp(path2, ".."))
+ else if (path2 == "..")
{
dst = zippath_parent(path1);
}
@@ -237,7 +237,7 @@ std::string &zippath_combine(std::string &dst, const char *path1, const char *pa
{
dst.assign(path2);
}
- else if ((path1[0] != '\0') && !is_path_separator(path1[strlen(path1) - 1]))
+ else if (!path1.empty() && !is_path_separator(*path1.rbegin()))
{
dst.assign(path1).append(PATH_SEPARATOR).append(path2);
}
@@ -254,7 +254,7 @@ std::string &zippath_combine(std::string &dst, const char *path1, const char *pa
// zippath_combine - combines two paths
// -------------------------------------------------
-std::string zippath_combine(const char *path1, const char *path2)
+std::string zippath_combine(const std::string &path1, const std::string &path2)
{
std::string result;
zippath_combine(result, path1, path2);
@@ -363,7 +363,7 @@ done:
// -------------------------------------------------
/**
- * @fn osd_file::error zippath_fopen(const char *filename, UINT32 openflags, util::core_file::ptr &file, std::string &revised_path)
+ * @fn osd_file::error zippath_fopen(const std::string &filename, UINT32 openflags, util::core_file::ptr &file, std::string &revised_path)
*
* @brief Zippath fopen.
*
@@ -375,7 +375,7 @@ done:
* @return A osd_file::error.
*/
-osd_file::error zippath_fopen(const char *filename, UINT32 openflags, util::core_file::ptr &file, std::string &revised_path)
+osd_file::error zippath_fopen(const std::string &filename, UINT32 openflags, util::core_file::ptr &file, std::string &revised_path)
{
osd_file::error filerr = osd_file::error::NOT_FOUND;
archive_file::error ziperr;
@@ -441,7 +441,7 @@ osd_file::error zippath_fopen(const char *filename, UINT32 openflags, util::core
if (filerr != osd_file::error::NONE)
{
/* go up a directory */
- auto temp = zippath_parent(mainpath.c_str());
+ auto temp = zippath_parent(mainpath);
/* append to the sub path */
if (subpath.length() > 0)
@@ -753,7 +753,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;
- apath = zippath_parent(apath.c_str());
+ apath = zippath_parent(apath);
}
}
while ((current_entry_type == osd::directory::entry::entry_type::NONE) && !is_root(apath.c_str()));
@@ -797,7 +797,7 @@ static osd_file::error zippath_resolve(const char *path, osd::directory::entry::
// -------------------------------------------------
/**
- * @fn osd_file::error zippath_opendir(const char *path, zippath_directory **directory)
+ * @fn osd_file::error zippath_opendir(const std::string &path, zippath_directory **directory)
*
* @brief Zippath opendir.
*
@@ -807,7 +807,7 @@ static osd_file::error zippath_resolve(const char *path, osd::directory::entry::
* @return A osd_file::error.
*/
-osd_file::error zippath_opendir(const char *path, zippath_directory **directory)
+osd_file::error zippath_opendir(const std::string &path, zippath_directory **directory)
{
osd_file::error err;
@@ -824,7 +824,7 @@ osd_file::error zippath_opendir(const char *path, zippath_directory **directory)
}
/* resolve the path */
osd::directory::entry::entry_type entry_type;
- err = zippath_resolve(path, entry_type, result->zipfile, result->zipprefix);
+ err = zippath_resolve(path.c_str(), entry_type, result->zipfile, result->zipprefix);
if (err != osd_file::error::NONE)
goto done;
@@ -847,7 +847,7 @@ osd_file::error zippath_opendir(const char *path, zippath_directory **directory)
}
/* is this path the root? if so, pretend we've already returned the parent */
- if (is_root(path))
+ if (is_root(path.c_str()))
result->returned_parent = true;
}
diff --git a/src/lib/util/zippath.h b/src/lib/util/zippath.h
index d0b017f86eb..9c5b361b076 100644
--- a/src/lib/util/zippath.h
+++ b/src/lib/util/zippath.h
@@ -34,28 +34,28 @@ 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);
+std::string &zippath_parent(std::string &dst, const std::string &path);
+std::string zippath_parent(const std::string &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);
+std::string &zippath_parent_basename(std::string &dst, const std::string &path);
+std::string zippath_parent_basename(const std::string &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);
+std::string &zippath_combine(std::string &dst, const std::string &path1, const std::string &path2);
+std::string zippath_combine(const std::string &path1, const std::string &path2);
// ----- file operations -----
// opens a zip path file
-osd_file::error zippath_fopen(const char *filename, UINT32 openflags, util::core_file::ptr &file, std::string &revised_path);
+osd_file::error zippath_fopen(const std::string &filename, UINT32 openflags, util::core_file::ptr &file, std::string &revised_path);
// ----- directory operations ----- */
// opens a directory
-osd_file::error zippath_opendir(const char *path, zippath_directory **directory);
+osd_file::error zippath_opendir(const std::string &path, zippath_directory **directory);
// closes a directory
void zippath_closedir(zippath_directory *directory);