summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Vas Crabb <cuavas@users.noreply.github.com>2016-09-25 10:57:38 +1000
committer GitHub <noreply@github.com>2016-09-25 10:57:38 +1000
commit651808f6be354b14c2704e2706eb43400038bcbe (patch)
tree465d2873bba86ec73682e850ddb9a85124e29f4c
parent239d09546f8b6c3a907b9edd2359fdc86713f8a6 (diff)
parent89512850bc1b0f2dcb1b3aab0778d66b23543a2d (diff)
Merge pull request #1446 from npwoods/retire_imgtool_basename
Retired imgtool_basename(), in favor of core_filename_extract_base()
-rw-r--r--src/tools/imgtool/imgtool.cpp23
-rw-r--r--src/tools/imgtool/imgtool.h1
-rw-r--r--src/tools/imgtool/main.cpp10
3 files changed, 11 insertions, 23 deletions
diff --git a/src/tools/imgtool/imgtool.cpp b/src/tools/imgtool/imgtool.cpp
index 71aecb39f6e..bda9a0b83bf 100644
--- a/src/tools/imgtool/imgtool.cpp
+++ b/src/tools/imgtool/imgtool.cpp
@@ -164,23 +164,6 @@ static imgtoolerr_t markerrorsource(imgtoolerr_t err)
return err;
}
-char *imgtool_basename(char *filename)
-{
- char *c;
-
- // NULL begets NULL
- if (!filename)
- return nullptr;
-
- // start at the end and return when we hit a slash or colon
- for (c = filename + strlen(filename) - 1; c >= filename; c--)
- if (*c == '\\' || *c == '/' || *c == ':')
- return c + 1;
-
- // otherwise, return the whole thing
- return filename;
-}
-
/*-------------------------------------------------
internal_error - debug function for raising
internal errors
@@ -2102,9 +2085,13 @@ imgtoolerr_t imgtool_partition_put_file(imgtool_partition *partition, const char
imgtool_stream *f = nullptr;
imgtool_charset charset;
char *alloc_newfname = nullptr;
+ std::string basename;
if (!newfname)
- newfname = (const char *) imgtool_basename((char *) source);
+ {
+ basename = core_filename_extract_base(source);
+ newfname = basename.c_str();
+ }
charset = (imgtool_charset) (int) imgtool_partition_get_info_int(partition, IMGTOOLINFO_INT_CHARSET);
if (charset != IMGTOOL_CHARSET_UTF8)
diff --git a/src/tools/imgtool/imgtool.h b/src/tools/imgtool/imgtool.h
index 65b843ec5b8..6313d5d988a 100644
--- a/src/tools/imgtool/imgtool.h
+++ b/src/tools/imgtool/imgtool.h
@@ -84,7 +84,6 @@ const imgtool_module *imgtool_find_module(const char *modulename);
const imgtool::library::modulelist &imgtool_get_modules();
imgtool_module_features imgtool_get_module_features(const imgtool_module *module);
void imgtool_warn(const char *format, ...) ATTR_PRINTF(1,2);
-char *imgtool_basename(char *filename);
/* ----- image management ----- */
imgtoolerr_t imgtool_identify_file(const char *filename, imgtool_module **modules, size_t count);
diff --git a/src/tools/imgtool/main.cpp b/src/tools/imgtool/main.cpp
index bbc246a86fc..298b444bacb 100644
--- a/src/tools/imgtool/main.cpp
+++ b/src/tools/imgtool/main.cpp
@@ -23,9 +23,10 @@
static void writeusage(FILE *f, int write_word_usage, const struct command *c, char *argv[])
{
+ std::string cmdname = core_filename_extract_base(argv[0]);
fprintf(f, "%s %s %s %s\n",
(write_word_usage ? "Usage:" : " "),
- imgtool_basename(argv[0]),
+ cmdname.c_str(),
c->name,
c->usage ? c->usage : "");
}
@@ -870,6 +871,7 @@ int CLIB_DECL main(int argc, char *argv[])
int result;
const struct command *c;
const char *sample_format = "coco_jvc_rsdos";
+ std::string cmdname = core_filename_extract_base(argv[0]);
#ifdef MAME_DEBUG
if (imgtool_validitychecks())
@@ -929,9 +931,9 @@ int CLIB_DECL main(int argc, char *argv[])
fprintf(stderr, "<imagename> is the image filename; can specify a ZIP file for image name\n");
fprintf(stderr, "\nExample usage:\n");
- fprintf(stderr, "\t%s dir %s myimageinazip.zip\n", imgtool_basename(argv[0]), sample_format);
- fprintf(stderr, "\t%s get %s myimage.dsk myfile.bin mynewfile.txt\n", imgtool_basename(argv[0]), sample_format);
- fprintf(stderr, "\t%s getall %s myimage.dsk\n", imgtool_basename(argv[0]), sample_format);
+ fprintf(stderr, "\t%s dir %s myimageinazip.zip\n", cmdname.c_str(), sample_format);
+ fprintf(stderr, "\t%s get %s myimage.dsk myfile.bin mynewfile.txt\n", cmdname.c_str(), sample_format);
+ fprintf(stderr, "\t%s getall %s myimage.dsk\n", cmdname.c_str(), sample_format);
result = 0;
goto done;