summaryrefslogtreecommitdiffstatshomepage
path: root/src/tools/imgtool/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/imgtool/main.cpp')
-rw-r--r--src/tools/imgtool/main.cpp63
1 files changed, 35 insertions, 28 deletions
diff --git a/src/tools/imgtool/main.cpp b/src/tools/imgtool/main.cpp
index d5320beb347..ca38d7905cb 100644
--- a/src/tools/imgtool/main.cpp
+++ b/src/tools/imgtool/main.cpp
@@ -9,15 +9,23 @@
***************************************************************************/
#include "imgtool.h"
+#include "filter.h"
#include "main.h"
#include "modules.h"
+
+#include "corestr.h"
+#include "opresolv.h"
+#include "path.h"
#include "strformat.h"
+#include "unicode.h"
+
+#include "osdcore.h" // osd_get_command_line
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <time.h>
+#include <cstdio>
+#include <cstring>
+#include <cctype>
+#include <cstdlib>
+#include <ctime>
#include <iostream>
#ifdef _WIN32
@@ -29,7 +37,7 @@
static void writeusage(std::wostream &output, bool write_word_usage, const struct command *c, char *argv[])
{
- std::string cmdname = core_filename_extract_base(argv[0]);
+ std::string cmdname(core_filename_extract_base(argv[0]));
util::stream_format(output,
L"%s %s %s %s\n",
@@ -43,7 +51,7 @@ static void writeusage(std::wostream &output, bool write_word_usage, const struc
// ----------------------------------------------------------------------
static int parse_options(int argc, char *argv[], int minunnamed, int maxunnamed,
- util::option_resolution *resolution, filter_getinfoproc *filter, const char **fork)
+ util::option_resolution *resolution, imgtool::filter_getinfoproc *filter, const char **fork)
{
int i;
int lastunnamed = 0;
@@ -97,7 +105,7 @@ static int parse_options(int argc, char *argv[], int minunnamed, int maxunnamed,
if (*fork)
goto optionalreadyspecified;
- snprintf(buf, ARRAY_LENGTH(buf), "%s", value);
+ snprintf(buf, std::size(buf), "%s", value);
*fork = buf;
}
else
@@ -107,6 +115,9 @@ static int parse_options(int argc, char *argv[], int minunnamed, int maxunnamed,
goto error; /* Too few unnamed */
util::option_resolution::entry *entry = resolution->find(name);
+ if (entry == nullptr)
+ goto error; /* Unknown option */
+
if (entry->option_type() == util::option_guide::entry::option_type::ENUM_BEGIN)
{
const util::option_guide::entry *enum_value;
@@ -231,7 +242,6 @@ static int cmd_dir(const struct command *c, int argc, char *argv[])
if (err)
goto done;
- memset(&ent, 0, sizeof(ent));
last_modified[0] = '\0';
total_count = 0;
total_size = 0;
@@ -248,7 +258,7 @@ static int cmd_dir(const struct command *c, int argc, char *argv[])
{
std::string filesize_string = ent.directory
? "<DIR>"
- : string_format("%u", (unsigned int) ent.filesize);
+ : util::string_format("%u", (unsigned int) ent.filesize);
if (!ent.lastmodified_time.empty())
{
@@ -266,16 +276,16 @@ static int cmd_dir(const struct command *c, int argc, char *argv[])
columnwidth_attributes, wstring_from_utf8(ent.attr),
columnwidth_lastmodified, wstring_from_utf8(last_modified));
- if (ent.softlink && ent.softlink[0] != '\0')
+ if (ent.softlink[0] != '\0')
util::stream_format(std::wcout, L"-> %s\n", wstring_from_utf8(ent.softlink));
- if (ent.comment && ent.comment[0] != '\0')
+ if (ent.comment[0] != '\0')
util::stream_format(std::wcout, L": %s\n", wstring_from_utf8(ent.comment));
total_count++;
total_size += ent.filesize;
- memset(&ent, 0, sizeof(ent));
+ ent = imgtool_dirent();
}
freespace_err = partition->get_free_space(freespace);
@@ -306,7 +316,7 @@ static int cmd_get(const struct command *c, int argc, char *argv[])
const char *filename;
char *new_filename;
int unnamedargs = 0;
- filter_getinfoproc filter;
+ imgtool::filter_getinfoproc filter;
const char *fork;
int partition_index = 0;
@@ -343,12 +353,11 @@ done:
static int cmd_put(const struct command *c, int argc, char *argv[])
{
imgtoolerr_t err = IMGTOOLERR_SUCCESS;
- int i;
imgtool::image::ptr image;
imgtool::partition::ptr partition;
const char *filename = nullptr;
int unnamedargs;
- filter_getinfoproc filter;
+ imgtool::filter_getinfoproc filter;
const imgtool_module *module;
std::unique_ptr<util::option_resolution> resolution;
const char *fork;
@@ -406,7 +415,7 @@ static int cmd_put(const struct command *c, int argc, char *argv[])
filename_count = unnamedargs - 3;
/* loop through the filenames, and put them */
- for (i = 0; i < filename_count; i++)
+ for (int i = 0; i < filename_count; i++)
{
filename = filename_list[i];
util::stream_format(std::wcout, L"Putting file '%s'...\n", wstring_from_utf8(filename));
@@ -430,7 +439,7 @@ static int cmd_getall(const struct command *c, int argc, char *argv[])
imgtool::partition::ptr partition;
imgtool::directory::ptr imgenum;
imgtool_dirent ent;
- filter_getinfoproc filter;
+ imgtool::filter_getinfoproc filter;
int unnamedargs;
const char *path = "";
int arg;
@@ -458,8 +467,6 @@ static int cmd_getall(const struct command *c, int argc, char *argv[])
if (err)
goto done;
- memset(&ent, 0, sizeof(ent));
-
while (((err = imgenum->get_next(ent)) == 0) && !ent.eof)
{
util::stream_format(std::wcout, L"Retrieving %s (%u bytes)\n", wstring_from_utf8(ent.filename), (unsigned int)ent.filesize);
@@ -564,7 +571,7 @@ static int cmd_identify(const struct command *c, int argc, char *argv[])
imgtoolerr_t err;
int i;
- err = imgtool::image::identify_file(argv[0], modules, ARRAY_LENGTH(modules));
+ err = imgtool::image::identify_file(argv[0], modules, std::size(modules));
if (err)
{
reporterror(err, c, nullptr, argv[0], nullptr, nullptr, nullptr);
@@ -597,7 +604,7 @@ static int cmd_create(const struct command *c, int argc, char *argv[])
goto error;
}
- if (module->createimage_optguide && module->createimage_optspec)
+ if (module->createimage_optguide && !module->createimage_optspec.empty())
{
try { resolution.reset(new util::option_resolution(*module->createimage_optguide)); }
catch (...)
@@ -605,7 +612,7 @@ static int cmd_create(const struct command *c, int argc, char *argv[])
err = IMGTOOLERR_OUTOFMEMORY;
goto error;
}
- resolution->set_specification(module->createimage_optspec);
+ resolution->set_specification(module->createimage_optspec.c_str());
}
unnamedargs = parse_options(argc, argv, 2, 3, resolution.get(), nullptr, nullptr);
@@ -748,7 +755,7 @@ static void listoptions(const util::option_guide &opt_guide, const char *opt_spe
const util::option_resolution::entry &entry = *iter;
std::stringstream description_buffer;
- std::string opt_name = string_format("--%s", entry.identifier());
+ std::string opt_name = util::string_format("--%s", entry.identifier());
const char *opt_desc = entry.display_name();
// is this option relevant?
@@ -831,7 +838,7 @@ static int cmd_listdriveroptions(const struct command *c, int argc, char *argv[]
if (opt_guide)
{
util::stream_format(std::wcout, L"Image specific creation options (usable on the 'create' command):\n\n");
- listoptions(*opt_guide, mod->createimage_optspec);
+ listoptions(*opt_guide, mod->createimage_optspec.c_str());
util::stream_format(std::wcout, L"\n");
}
else
@@ -873,7 +880,7 @@ int 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]);
+ std::string cmdname(core_filename_extract_base(argv[0]));
#ifdef _WIN32
_setmode(_fileno(stdout), _O_U8TEXT);
@@ -895,7 +902,7 @@ int main(int argc, char *argv[])
if (argc > 1)
{
/* figure out what command they are running, and run it */
- for (i = 0; i < ARRAY_LENGTH(cmds); i++)
+ for (i = 0; i < std::size(cmds); i++)
{
c = &cmds[i];
if (!core_stricmp(c->name, argv[1]))
@@ -934,7 +941,7 @@ int main(int argc, char *argv[])
// Usage
util::stream_format(std::wcerr, L"imgtool - Generic image manipulation tool for use with MAME\n\n");
- for (i = 0; i < ARRAY_LENGTH(cmds); i++)
+ for (i = 0; i < std::size(cmds); i++)
{
writeusage(std::wcerr, (i == 0), &cmds[i], argv);
}