summaryrefslogtreecommitdiffstatshomepage
path: root/src/tools/chdman.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/chdman.cpp')
-rw-r--r--src/tools/chdman.cpp509
1 files changed, 257 insertions, 252 deletions
diff --git a/src/tools/chdman.cpp b/src/tools/chdman.cpp
index 3ea0a31f752..88a629b97dd 100644
--- a/src/tools/chdman.cpp
+++ b/src/tools/chdman.cpp
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <time.h>
#include <ctype.h>
+#include <unordered_map>
#include <new>
@@ -96,7 +97,7 @@ const int MODE_GDI = 2;
// FUNCTION PROTOTYPES
//**************************************************************************
-typedef tagmap_t<std::string *> parameters_t;
+typedef std::unordered_map<std::string,std::string *> parameters_t;
static void report_error(int error, const char *format, ...) ATTR_PRINTF(2,3);
static void do_info(parameters_t &params);
@@ -189,7 +190,7 @@ public:
chd_rawfile_compressor(core_file *file, UINT64 offset = 0, UINT64 maxoffset = ~0)
: m_file(file),
m_offset(offset),
- m_maxoffset(MIN(maxoffset, (file != NULL) ? core_fsize(file) : 0)) { }
+ m_maxoffset(MIN(maxoffset, (file != nullptr) ? core_fsize(file) : 0)) { }
// read interface
virtual UINT32 read_data(void *dest, UINT64 offset, UINT32 length)
@@ -218,7 +219,7 @@ class chd_chdfile_compressor : public chd_file_compressor
public:
// construction/destruction
chd_chdfile_compressor(chd_file &file, UINT64 offset = 0, UINT64 maxoffset = ~0)
- : m_toc(NULL),
+ : m_toc(nullptr),
m_file(file),
m_offset(offset),
m_maxoffset(MIN(maxoffset, file.logical_bytes())) { }
@@ -289,13 +290,13 @@ class chd_cd_compressor : public chd_file_compressor
public:
// construction/destruction
chd_cd_compressor(cdrom_toc &toc, chdcd_track_input_info &info)
- : m_file(NULL),
+ : m_file(nullptr),
m_toc(toc),
m_info(info) { }
~chd_cd_compressor()
{
- if (m_file != NULL)
+ if (m_file != nullptr)
core_fclose(m_file);
}
@@ -320,9 +321,9 @@ public:
if (offset >= startoffs && offset < endoffs)
{
// if we don't already have this file open, open it now
- if (m_file == NULL || m_lastfile.compare(m_info.track[tracknum].fname)!=0)
+ if (m_file == nullptr || m_lastfile.compare(m_info.track[tracknum].fname)!=0)
{
- if (m_file != NULL)
+ if (m_file != nullptr)
core_fclose(m_file);
m_lastfile = m_info.track[tracknum].fname;
file_error filerr = core_fopen(m_lastfile.c_str(), OPEN_FLAG_READ, &m_file);
@@ -764,17 +765,17 @@ static void ATTR_PRINTF(2,3) progress(bool forceit, const char *format, ...)
// print_help - print help for all the commands
//-------------------------------------------------
-static int print_help(const char *argv0, const char *error = NULL)
+static int print_help(const char *argv0, const char *error = nullptr)
{
// print the error message first
- if (error != NULL)
+ if (error != nullptr)
fprintf(stderr, "Error: %s\n\n", error);
// print a summary of each command
printf("Usage:\n");
- for (int cmdnum = 0; cmdnum < ARRAY_LENGTH(s_commands); cmdnum++)
+ for (auto & desc : s_commands)
{
- const command_description &desc = s_commands[cmdnum];
+
printf(" %s %s%s\n", argv0, desc.name, desc.description);
}
printf("\nFor help with any command, run:\n");
@@ -788,10 +789,10 @@ static int print_help(const char *argv0, const char *error = NULL)
// command
//-------------------------------------------------
-static int print_help(const char *argv0, const command_description &desc, const char *error = NULL)
+static int print_help(const char *argv0, const command_description &desc, const char *error = nullptr)
{
// print the error message first
- if (error != NULL)
+ if (error != nullptr)
fprintf(stderr, "Error: %s\n\n", error);
// print usage for this command
@@ -801,19 +802,19 @@ static int print_help(const char *argv0, const command_description &desc, const
{
// determine whether we are required
const char *option = desc.valid_options[valid];
- if (option == NULL)
+ if (option == nullptr)
break;
bool required = (option[0] == REQUIRED[0]);
if (required)
option++;
// find the option
- for (int optnum = 0; optnum < ARRAY_LENGTH(s_options); optnum++)
- if (strcmp(option, s_options[optnum].name) == 0)
+ for (auto & s_option : s_options)
+ if (strcmp(option, s_option.name) == 0)
{
- const option_description &odesc = s_options[optnum];
+ const option_description &odesc = s_option;
printf(" --%s", odesc.name);
- if (odesc.shortname != NULL)
+ if (odesc.shortname != nullptr)
printf(", -%s", odesc.shortname);
printf("%s%s\n", odesc.description, required ? " (required)" : "");
}
@@ -904,7 +905,7 @@ UINT64 parse_number(const char *string)
static void guess_chs(std::string *filename, UINT64 filesize, int sectorsize, UINT32 &cylinders, UINT32 &heads, UINT32 &sectors, UINT32 &bps)
{
// if this is a direct physical drive read, handle it specially
- if (filename != NULL && osd_get_physical_drive_geometry(filename->c_str(), &cylinders, &heads, &sectors, &bps))
+ if (filename != nullptr && osd_get_physical_drive_geometry(filename->c_str(), &cylinders, &heads, &sectors, &bps))
return;
// if we have no length to work with, we can't guess
@@ -940,21 +941,21 @@ static void guess_chs(std::string *filename, UINT64 filesize, int sectorsize, UI
static void parse_input_chd_parameters(const parameters_t &params, chd_file &input_chd, chd_file &input_parent_chd, bool writeable = false)
{
// process input parent file
- std::string *input_chd_parent_str = params.find(OPTION_INPUT_PARENT);
- if (input_chd_parent_str != NULL)
+ auto input_chd_parent_str = params.find(OPTION_INPUT_PARENT);
+ if (input_chd_parent_str != params.end())
{
- chd_error err = input_parent_chd.open(input_chd_parent_str->c_str());
+ chd_error err = input_parent_chd.open(input_chd_parent_str->second->c_str());
if (err != CHDERR_NONE)
- report_error(1, "Error opening parent CHD file (%s): %s", input_chd_parent_str->c_str(), chd_file::error_string(err));
+ report_error(1, "Error opening parent CHD file (%s): %s", input_chd_parent_str->second->c_str(), chd_file::error_string(err));
}
// process input file
- std::string *input_chd_str = params.find(OPTION_INPUT);
- if (input_chd_str != NULL)
+ auto input_chd_str = params.find(OPTION_INPUT);
+ if (input_chd_str != params.end())
{
- chd_error err = input_chd.open(input_chd_str->c_str(), writeable, input_parent_chd.opened() ? &input_parent_chd : NULL);
+ chd_error err = input_chd.open(input_chd_str->second->c_str(), writeable, input_parent_chd.opened() ? &input_parent_chd : nullptr);
if (err != CHDERR_NONE)
- report_error(1, "Error opening CHD file (%s): %s", input_chd_str->c_str(), chd_file::error_string(err));
+ report_error(1, "Error opening CHD file (%s): %s", input_chd_str->second->c_str(), chd_file::error_string(err));
}
}
@@ -971,29 +972,29 @@ static void parse_input_start_end(const parameters_t &params, UINT64 logical_siz
input_end = logical_size;
// process input start
- std::string *input_start_byte_str = params.find(OPTION_INPUT_START_BYTE);
- std::string *input_start_hunk_str = params.find(OPTION_INPUT_START_HUNK);
- std::string *input_start_frame_str = params.find(OPTION_INPUT_START_FRAME);
- if (input_start_byte_str != NULL)
- input_start = parse_number(input_start_byte_str->c_str());
- if (input_start_hunk_str != NULL)
- input_start = parse_number(input_start_hunk_str->c_str()) * hunkbytes;
- if (input_start_frame_str != NULL)
- input_start = parse_number(input_start_frame_str->c_str()) * framebytes;
+ auto input_start_byte_str = params.find(OPTION_INPUT_START_BYTE);
+ auto input_start_hunk_str = params.find(OPTION_INPUT_START_HUNK);
+ auto input_start_frame_str = params.find(OPTION_INPUT_START_FRAME);
+ if (input_start_byte_str != params.end())
+ input_start = parse_number(input_start_byte_str->second->c_str());
+ if (input_start_hunk_str != params.end())
+ input_start = parse_number(input_start_hunk_str->second->c_str()) * hunkbytes;
+ if (input_start_frame_str != params.end())
+ input_start = parse_number(input_start_frame_str->second->c_str()) * framebytes;
if (input_start >= input_end)
report_error(1, "Input start offset greater than input file size");
// process input length
- std::string *input_length_bytes_str = params.find(OPTION_INPUT_LENGTH_BYTES);
- std::string *input_length_hunks_str = params.find(OPTION_INPUT_LENGTH_HUNKS);
- std::string *input_length_frames_str = params.find(OPTION_INPUT_LENGTH_FRAMES);
+ auto input_length_bytes_str = params.find(OPTION_INPUT_LENGTH_BYTES);
+ auto input_length_hunks_str = params.find(OPTION_INPUT_LENGTH_HUNKS);
+ auto input_length_frames_str = params.find(OPTION_INPUT_LENGTH_FRAMES);
UINT64 input_length = input_end;
- if (input_length_bytes_str != NULL)
- input_length = parse_number(input_length_bytes_str->c_str());
- if (input_length_hunks_str != NULL)
- input_length = parse_number(input_length_hunks_str->c_str()) * hunkbytes;
- if (input_length_frames_str != NULL)
- input_length = parse_number(input_length_frames_str->c_str()) * framebytes;
+ if (input_length_bytes_str != params.end())
+ input_length = parse_number(input_length_bytes_str->second->c_str());
+ if (input_length_hunks_str != params.end())
+ input_length = parse_number(input_length_hunks_str->second->c_str()) * hunkbytes;
+ if (input_length_frames_str != params.end())
+ input_length = parse_number(input_length_frames_str->second->c_str()) * framebytes;
if (input_start + input_length < input_end)
input_end = input_start + input_length;
}
@@ -1007,7 +1008,7 @@ static void parse_input_start_end(const parameters_t &params, UINT64 logical_siz
static void check_existing_output_file(const parameters_t &params, const char *filename)
{
- if (params.find(OPTION_OUTPUT_FORCE) == NULL)
+ if (params.find(OPTION_OUTPUT_FORCE) == params.end())
{
core_file *file;
file_error filerr = core_fopen(filename, OPEN_FLAG_READ, &file);
@@ -1028,19 +1029,19 @@ static void check_existing_output_file(const parameters_t &params, const char *f
static std::string *parse_output_chd_parameters(const parameters_t &params, chd_file &output_parent_chd)
{
// process output parent file
- std::string *output_chd_parent_str = params.find(OPTION_OUTPUT_PARENT);
- if (output_chd_parent_str != NULL)
+ auto output_chd_parent_str = params.find(OPTION_OUTPUT_PARENT);
+ if (output_chd_parent_str != params.end())
{
- chd_error err = output_parent_chd.open(output_chd_parent_str->c_str());
+ chd_error err = output_parent_chd.open(output_chd_parent_str->second->c_str());
if (err != CHDERR_NONE)
- report_error(1, "Error opening parent CHD file (%s): %s", output_chd_parent_str->c_str(), chd_file::error_string(err));
+ report_error(1, "Error opening parent CHD file (%s): %s", output_chd_parent_str->second->c_str(), chd_file::error_string(err));
}
// process output file
- std::string *output_chd_str = params.find(OPTION_OUTPUT);
- if (output_chd_str != NULL)
- check_existing_output_file(params, output_chd_str->c_str());
- return output_chd_str;
+ auto output_chd_str = params.find(OPTION_OUTPUT);
+ if (output_chd_str != params.end())
+ check_existing_output_file(params, output_chd_str->second->c_str());
+ return (output_chd_str != params.end()) ? output_chd_str->second : nullptr;
}
@@ -1051,10 +1052,10 @@ static std::string *parse_output_chd_parameters(const parameters_t &params, chd_
static void parse_hunk_size(const parameters_t &params, UINT32 required_granularity, UINT32 &hunk_size)
{
- std::string *hunk_size_str = params.find(OPTION_HUNK_SIZE);
- if (hunk_size_str != NULL)
+ auto hunk_size_str = params.find(OPTION_HUNK_SIZE);
+ if (hunk_size_str != params.end())
{
- hunk_size = parse_number(hunk_size_str->c_str());
+ hunk_size = parse_number(hunk_size_str->second->c_str());
if (hunk_size < 16 || hunk_size > 1024 * 1024)
report_error(1, "Invalid hunk size");
if (hunk_size % required_granularity != 0)
@@ -1071,12 +1072,12 @@ static void parse_hunk_size(const parameters_t &params, UINT32 required_granular
static void parse_compression(const parameters_t &params, chd_codec_type compression[4])
{
// see if anything was specified
- std::string *compression_str = params.find(OPTION_COMPRESSION);
- if (compression_str == NULL)
+ auto compression_str = params.find(OPTION_COMPRESSION);
+ if (compression_str == params.end())
return;
// special case: 'none'
- if (compression_str->compare("none")==0)
+ if (compression_str->second->compare("none")==0)
{
compression[0] = compression[1] = compression[2] = compression[3] = CHD_CODEC_NONE;
return;
@@ -1084,9 +1085,9 @@ static void parse_compression(const parameters_t &params, chd_codec_type compres
// iterate through compressors
int index = 0;
- for (int start = 0, end = compression_str->find_first_of(','); index < 4; start = end + 1, end = compression_str->find_first_of(',', end + 1))
+ for (int start = 0, end = compression_str->second->find_first_of(','); index < 4; start = end + 1, end = compression_str->second->find_first_of(',', end + 1))
{
- std::string name(*compression_str, start, (end == -1) ? -1 : end - start);
+ std::string name(*compression_str->second, start, (end == -1) ? -1 : end - start);
if (name.length() != 4)
report_error(1, "Invalid compressor '%s' specified", name.c_str());
chd_codec_type type = CHD_MAKE_TAG(name[0], name[1], name[2], name[3]);
@@ -1111,11 +1112,11 @@ static void parse_compression(const parameters_t &params, chd_codec_type compres
static void parse_numprocessors(const parameters_t &params)
{
- std::string *numprocessors_str = params.find(OPTION_NUMPROCESSORS);
- if (numprocessors_str == NULL)
+ auto numprocessors_str = params.find(OPTION_NUMPROCESSORS);
+ if (numprocessors_str == params.end())
return;
- int count = atoi(numprocessors_str->c_str());
+ int count = atoi(numprocessors_str->second->c_str());
if (count > 0)
{
extern int osd_num_processors;
@@ -1234,7 +1235,7 @@ void output_track_metadata(int mode, core_file *file, int tracknum, const cdrom_
size = 2352;
break;
}
- bool needquote = strchr(filename, ' ') != NULL;
+ bool needquote = strchr(filename, ' ') != nullptr;
core_fprintf(file, "%d %d %d %d %s%s%s %" I64FMT "d\n", tracknum+1, frameoffs, mode, size, needquote?"\"":"", filename, needquote?"\"":"", discoffs);
}
else if (mode == MODE_CUEBIN)
@@ -1348,7 +1349,7 @@ static void do_info(parameters_t &params)
// print filename and version
std::string tempstr;
- printf("Input file: %s\n", params.find(OPTION_INPUT)->c_str());
+ printf("Input file: %s\n", params.find(OPTION_INPUT)->second->c_str());
printf("File Version: %d\n", input_chd.version());
if (input_chd.version() < 3)
report_error(1, "Unsupported version (%d); use an older chdman to upgrade to version 3 or later", input_chd.version());
@@ -1391,10 +1392,10 @@ static void do_info(parameters_t &params)
// determine our index
UINT32 metaindex = ~0;
- for (unsigned int cur = 0; cur < info.size(); cur++)
- if (info[cur].tag == metatag)
+ for (auto & elem : info)
+ if (elem.tag == metatag)
{
- metaindex = ++info[cur].index;
+ metaindex = ++elem.index;
break;
}
@@ -1421,7 +1422,7 @@ static void do_info(parameters_t &params)
}
// print compression stats if verbose
- if (params.find(OPTION_VERBOSE) != NULL)
+ if (params.find(OPTION_VERBOSE) != params.end())
{
UINT32 compression_types[10] = { 0 };
for (UINT32 hunknum = 0; hunknum < input_chd.hunk_count(); hunknum++)
@@ -1512,7 +1513,7 @@ static void do_verify(parameters_t &params)
UINT32 bytes_to_read = MIN((UINT32)buffer.size(), input_chd.logical_bytes() - offset);
chd_error err = input_chd.read_bytes(offset, &buffer[0], bytes_to_read);
if (err != CHDERR_NONE)
- report_error(1, "Error reading CHD file (%s): %s", params.find(OPTION_INPUT)->c_str(), chd_file::error_string(err));
+ report_error(1, "Error reading CHD file (%s): %s", params.find(OPTION_INPUT)->second->c_str(), chd_file::error_string(err));
// add to the checksum
rawsha1.append(&buffer[0], bytes_to_read);
@@ -1528,7 +1529,7 @@ static void do_verify(parameters_t &params)
fprintf(stderr, " actual SHA1 = %s\n", computed_sha1.as_string(tempstr));
// fix it if requested; this also fixes the overall one so we don't need to do any more
- if (params.find(OPTION_FIX) != NULL)
+ if (params.find(OPTION_FIX) != params.end())
{
input_chd.set_raw_sha1(computed_sha1);
printf("SHA-1 updated to correct value in input CHD\n");
@@ -1551,7 +1552,7 @@ static void do_verify(parameters_t &params)
fprintf(stderr, " actual SHA1 = %s\n", computed_overall_sha1.as_string(tempstr));
// fix it if requested
- if (params.find(OPTION_FIX) != NULL)
+ if (params.find(OPTION_FIX) != params.end())
{
input_chd.set_raw_sha1(computed_sha1);
printf("SHA-1 updated to correct value in input CHD\n");
@@ -1570,13 +1571,13 @@ static void do_verify(parameters_t &params)
static void do_create_raw(parameters_t &params)
{
// process input file
- core_file *input_file = NULL;
- std::string *input_file_str = params.find(OPTION_INPUT);
- if (input_file_str != NULL)
+ core_file *input_file = nullptr;
+ auto input_file_str = params.find(OPTION_INPUT);
+ if (input_file_str != params.end())
{
- file_error filerr = core_fopen(input_file_str->c_str(), OPEN_FLAG_READ, &input_file);
+ file_error filerr = core_fopen(input_file_str->second->c_str(), OPEN_FLAG_READ, &input_file);
if (filerr != FILERR_NONE)
- report_error(1, "Unable to open file (%s)", input_file_str->c_str());
+ report_error(1, "Unable to open file (%s)", input_file_str->second->c_str());
}
// process output CHD
@@ -1589,10 +1590,10 @@ static void do_create_raw(parameters_t &params)
// process unit size
UINT32 unit_size = output_parent.opened() ? output_parent.unit_bytes() : 0;
- std::string *unit_size_str = params.find(OPTION_UNIT_SIZE);
- if (unit_size_str != NULL)
+ auto unit_size_str = params.find(OPTION_UNIT_SIZE);
+ if (unit_size_str != params.end())
{
- unit_size = parse_number(unit_size_str->c_str());
+ unit_size = parse_number(unit_size_str->second->c_str());
if (hunk_size % unit_size != 0)
report_error(1, "Unit size is not an even divisor of the hunk size");
}
@@ -1614,8 +1615,8 @@ static void do_create_raw(parameters_t &params)
std::string tempstr;
printf("Output CHD: %s\n", output_chd_str->c_str());
if (output_parent.opened())
- printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->c_str());
- printf("Input file: %s\n", input_file_str->c_str());
+ printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->second->c_str());
+ printf("Input file: %s\n", input_file_str->second->c_str());
if (input_start != 0 || input_end != core_fsize(input_file))
{
printf("Input start: %s\n", big_int_string(tempstr, input_start));
@@ -1626,7 +1627,7 @@ static void do_create_raw(parameters_t &params)
printf("Logical size: %s\n", big_int_string(tempstr, input_end - input_start));
// catch errors so we can close & delete the output file
- chd_rawfile_compressor *chd = NULL;
+ chd_rawfile_compressor *chd = nullptr;
try
{
// create the new CHD
@@ -1651,9 +1652,9 @@ static void do_create_raw(parameters_t &params)
{
delete chd;
// delete the output file
- std::string *output_chd_str = params.find(OPTION_OUTPUT);
- if (output_chd_str != NULL)
- osd_rmfile(output_chd_str->c_str());
+ auto output_chd_str = params.find(OPTION_OUTPUT);
+ if (output_chd_str != params.end())
+ osd_rmfile(output_chd_str->second->c_str());
throw;
}
}
@@ -1667,13 +1668,13 @@ static void do_create_raw(parameters_t &params)
static void do_create_hd(parameters_t &params)
{
// process input file
- core_file *input_file = NULL;
- std::string *input_file_str = params.find(OPTION_INPUT);
- if (input_file_str != NULL)
+ core_file *input_file = nullptr;
+ auto input_file_str = params.find(OPTION_INPUT);
+ if (input_file_str != params.end())
{
- file_error filerr = core_fopen(input_file_str->c_str(), OPEN_FLAG_READ, &input_file);
+ file_error filerr = core_fopen(input_file_str->second->c_str(), OPEN_FLAG_READ, &input_file);
if (filerr != FILERR_NONE)
- report_error(1, "Unable to open file (%s)", input_file_str->c_str());
+ report_error(1, "Unable to open file (%s)", input_file_str->second->c_str());
}
// process output CHD
@@ -1682,12 +1683,12 @@ static void do_create_hd(parameters_t &params)
// process sectorsize
UINT32 sector_size = output_parent.opened() ? output_parent.unit_bytes() : IDE_SECTOR_SIZE;
- std::string *sectorsize_str = params.find(OPTION_SECTOR_SIZE);
- if (sectorsize_str != NULL)
+ auto sectorsize_str = params.find(OPTION_SECTOR_SIZE);
+ if (sectorsize_str != params.end())
{
if (output_parent.opened())
report_error(1, "Sector size does not apply when creating a diff from the parent");
- sector_size = parse_number(sectorsize_str->c_str());
+ sector_size = parse_number(sectorsize_str->second->c_str());
}
// process hunk size (needs to know sector_size)
@@ -1698,17 +1699,17 @@ static void do_create_hd(parameters_t &params)
UINT64 filesize = 0;
UINT64 input_start = 0;
UINT64 input_end = 0;
- if (input_file != NULL)
+ if (input_file != nullptr)
{
parse_input_start_end(params, core_fsize(input_file), hunk_size, hunk_size, input_start, input_end);
filesize = input_end - input_start;
}
else
{
- std::string *size_str = params.find(OPTION_SIZE);
- if (size_str != NULL)
+ auto size_str = params.find(OPTION_SIZE);
+ if (size_str != params.end())
{
- if (sscanf(size_str->c_str(), "%" I64FMT"d", &filesize) != 1)
+ if (sscanf(size_str->second->c_str(), "%" I64FMT"d", &filesize) != 1)
report_error(1, "Invalid size string");
}
}
@@ -1716,10 +1717,10 @@ static void do_create_hd(parameters_t &params)
// process compression
chd_codec_type compression[4];
memcpy(compression, s_default_hd_compression, sizeof(compression));
- if (input_file == NULL)
+ if (input_file == nullptr)
compression[0] = compression[1] = compression[2] = compression[3] = CHD_CODEC_NONE;
parse_compression(params, compression);
- if (input_file == NULL && compression[0] != CHD_CODEC_NONE)
+ if (input_file == nullptr && compression[0] != CHD_CODEC_NONE)
report_error(1, "Blank hard disks must be uncompressed");
// process numprocessors
@@ -1729,12 +1730,12 @@ static void do_create_hd(parameters_t &params)
UINT32 cylinders = 0;
UINT32 heads = 0;
UINT32 sectors = 0;
- std::string *chs_str = params.find(OPTION_CHS);
- if (chs_str != NULL)
+ auto chs_str = params.find(OPTION_CHS);
+ if (chs_str != params.end())
{
if (output_parent.opened())
report_error(1, "CHS does not apply when creating a diff from the parent");
- if (sscanf(chs_str->c_str(), "%d,%d,%d", &cylinders, &heads, &sectors) != 3)
+ if (sscanf(chs_str->second->c_str(), "%d,%d,%d", &cylinders, &heads, &sectors) != 3)
report_error(1, "Invalid CHS string; must be of the form <cylinders>,<heads>,<sectors>");
}
@@ -1742,17 +1743,17 @@ static void do_create_hd(parameters_t &params)
dynamic_buffer identdata;
if (output_parent.opened())
output_parent.read_metadata(HARD_DISK_IDENT_METADATA_TAG, 0, identdata);
- std::string *ident_str = params.find(OPTION_IDENT);
- if (ident_str != NULL)
+ auto ident_str = params.find(OPTION_IDENT);
+ if (ident_str != params.end())
{
// load the file
- file_error filerr = core_fload(ident_str->c_str(), identdata);
+ file_error filerr = core_fload(ident_str->second->c_str(), identdata);
if (filerr != FILERR_NONE)
- report_error(1, "Error reading ident file (%s)", ident_str->c_str());
+ report_error(1, "Error reading ident file (%s)", ident_str->second->c_str());
// must be at least 14 bytes; extract CHS data from there
if (identdata.size() < 14)
- report_error(1, "Ident file '%s' is invalid (too short)", ident_str->c_str());
+ report_error(1, "Ident file '%s' is invalid (too short)", ident_str->second->c_str());
cylinders = (identdata[3] << 8) | identdata[2];
heads = (identdata[7] << 8) | identdata[6];
sectors = (identdata[13] << 8) | identdata[12];
@@ -1775,9 +1776,9 @@ static void do_create_hd(parameters_t &params)
// if no CHS values, try to guess them
if (cylinders == 0)
{
- if (input_file == NULL && filesize == 0)
+ if (input_file == nullptr && filesize == 0)
report_error(1, "Blank hard drives must specify either a length or a set of CHS values");
- guess_chs(input_file_str, filesize, sector_size, cylinders, heads, sectors, sector_size);
+ guess_chs((input_file_str != params.end()) ? input_file_str->second : nullptr, filesize, sector_size, cylinders, heads, sectors, sector_size);
}
UINT32 totalsectors = cylinders * heads * sectors;
@@ -1785,10 +1786,10 @@ static void do_create_hd(parameters_t &params)
std::string tempstr;
printf("Output CHD: %s\n", output_chd_str->c_str());
if (output_parent.opened())
- printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->c_str());
- if (input_file != NULL)
+ printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->second->c_str());
+ if (input_file != nullptr)
{
- printf("Input file: %s\n", input_file_str->c_str());
+ printf("Input file: %s\n", input_file_str->second->c_str());
if (input_start != 0 || input_end != core_fsize(input_file))
{
printf("Input start: %s\n", big_int_string(tempstr, input_start));
@@ -1804,7 +1805,7 @@ static void do_create_hd(parameters_t &params)
printf("Logical size: %s\n", big_int_string(tempstr, UINT64(totalsectors) * UINT64(sector_size)));
// catch errors so we can close & delete the output file
- chd_rawfile_compressor *chd = NULL;
+ chd_rawfile_compressor *chd = nullptr;
try
{
// create the new hard drive
@@ -1833,7 +1834,7 @@ static void do_create_hd(parameters_t &params)
}
// compress it generically
- if (input_file != NULL)
+ if (input_file != nullptr)
compress_common(*chd);
delete chd;
}
@@ -1841,9 +1842,9 @@ static void do_create_hd(parameters_t &params)
{
delete chd;
// delete the output file
- std::string *output_chd_str = params.find(OPTION_OUTPUT);
- if (output_chd_str != NULL)
- osd_rmfile(output_chd_str->c_str());
+ auto output_chd_str = params.find(OPTION_OUTPUT);
+ if (output_chd_str != params.end())
+ osd_rmfile(output_chd_str->second->c_str());
throw;
}
}
@@ -1859,12 +1860,12 @@ static void do_create_cd(parameters_t &params)
// process input file
chdcd_track_input_info track_info;
cdrom_toc toc = { 0 };
- std::string *input_file_str = params.find(OPTION_INPUT);
- if (input_file_str != NULL)
+ auto input_file_str = params.find(OPTION_INPUT);
+ if (input_file_str != params.end())
{
- chd_error err = chdcd_parse_toc(input_file_str->c_str(), toc, track_info);
+ chd_error err = chdcd_parse_toc(input_file_str->second->c_str(), toc, track_info);
if (err != CHDERR_NONE)
- report_error(1, "Error parsing input file (%s: %s)\n", input_file_str->c_str(), chd_file::error_string(err));
+ report_error(1, "Error parsing input file (%s: %s)\n", input_file_str->second->c_str(), chd_file::error_string(err));
}
// process output CHD
@@ -1899,15 +1900,15 @@ static void do_create_cd(parameters_t &params)
std::string tempstr;
printf("Output CHD: %s\n", output_chd_str->c_str());
if (output_parent.opened())
- printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->c_str());
- printf("Input file: %s\n", input_file_str->c_str());
+ printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->second->c_str());
+ printf("Input file: %s\n", input_file_str->second->c_str());
printf("Input tracks: %d\n", toc.numtrks);
printf("Input length: %s\n", msf_string_from_frames(tempstr, origtotalsectors));
printf("Compression: %s\n", compression_string(tempstr, compression));
printf("Logical size: %s\n", big_int_string(tempstr, UINT64(totalsectors) * CD_FRAME_SIZE));
// catch errors so we can close & delete the output file
- chd_cd_compressor *chd = NULL;
+ chd_cd_compressor *chd = nullptr;
try
{
// create the new CD
@@ -1933,9 +1934,9 @@ static void do_create_cd(parameters_t &params)
{
delete chd;
// delete the output file
- std::string *output_chd_str = params.find(OPTION_OUTPUT);
- if (output_chd_str != NULL)
- osd_rmfile(output_chd_str->c_str());
+ auto output_chd_str = params.find(OPTION_OUTPUT);
+ if (output_chd_str != params.end())
+ osd_rmfile(output_chd_str->second->c_str());
throw;
}
}
@@ -1949,13 +1950,13 @@ static void do_create_cd(parameters_t &params)
static void do_create_ld(parameters_t &params)
{
// process input file
- avi_file *input_file = NULL;
- std::string *input_file_str = params.find(OPTION_INPUT);
- if (input_file_str != NULL)
+ avi_file *input_file = nullptr;
+ auto input_file_str = params.find(OPTION_INPUT);
+ if (input_file_str != params.end())
{
- avi_error avierr = avi_open(input_file_str->c_str(), &input_file);
+ avi_error avierr = avi_open(input_file_str->second->c_str(), &input_file);
if (avierr != AVIERR_NONE)
- report_error(1, "Error opening AVI file (%s): %s\n", input_file_str->c_str(), avi_error_string(avierr));
+ report_error(1, "Error opening AVI file (%s): %s\n", input_file_str->second->c_str(), avi_error_string(avierr));
}
const avi_movie_info *aviinfo = avi_get_movie_info(input_file);
@@ -2009,8 +2010,8 @@ static void do_create_ld(parameters_t &params)
std::string tempstr;
printf("Output CHD: %s\n", output_chd_str->c_str());
if (output_parent.opened())
- printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->c_str());
- printf("Input file: %s\n", input_file_str->c_str());
+ printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->second->c_str());
+ printf("Input file: %s\n", input_file_str->second->c_str());
if (input_start != 0 && input_end != aviinfo->video_numsamples)
printf("Input start: %s\n", big_int_string(tempstr, input_start));
printf("Input length: %s (%02d:%02d:%02d)\n", big_int_string(tempstr, input_end - input_start),
@@ -2025,7 +2026,7 @@ static void do_create_ld(parameters_t &params)
printf("Logical size: %s\n", big_int_string(tempstr, UINT64(input_end - input_start) * hunk_size));
// catch errors so we can close & delete the output file
- chd_avi_compressor *chd = NULL;
+ chd_avi_compressor *chd = nullptr;
try
{
// create the new CHD
@@ -2061,9 +2062,9 @@ static void do_create_ld(parameters_t &params)
{
delete chd;
// delete the output file
- std::string *output_chd_str = params.find(OPTION_OUTPUT);
- if (output_chd_str != NULL)
- osd_rmfile(output_chd_str->c_str());
+ auto output_chd_str = params.find(OPTION_OUTPUT);
+ if (output_chd_str != params.end())
+ osd_rmfile(output_chd_str->second->c_str());
throw;
}
}
@@ -2122,8 +2123,8 @@ static void do_copy(parameters_t &params)
std::string tempstr;
printf("Output CHD: %s\n", output_chd_str->c_str());
if (output_parent.opened())
- printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->c_str());
- printf("Input CHD: %s\n", params.find(OPTION_INPUT)->c_str());
+ printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->second->c_str());
+ printf("Input CHD: %s\n", params.find(OPTION_INPUT)->second->c_str());
if (input_start != 0 || input_end != input_chd.logical_bytes())
{
printf("Input start: %s\n", big_int_string(tempstr, input_start));
@@ -2134,7 +2135,7 @@ static void do_copy(parameters_t &params)
printf("Logical size: %s\n", big_int_string(tempstr, input_end - input_start));
// catch errors so we can close & delete the output file
- chd_chdfile_compressor *chd = NULL;
+ chd_chdfile_compressor *chd = nullptr;
try
{
// create the new CHD
@@ -2179,7 +2180,7 @@ static void do_copy(parameters_t &params)
if (redo_cd)
{
cdrom_file *cdrom = cdrom_open(&input_chd);
- if (cdrom == NULL)
+ if (cdrom == nullptr)
report_error(1, "Error upgrading CD metadata");
const cdrom_toc *toc = cdrom_get_toc(cdrom);
err = cdrom_write_metadata(chd, toc);
@@ -2197,9 +2198,9 @@ static void do_copy(parameters_t &params)
{
delete chd;
// delete the output file
- std::string *output_chd_str = params.find(OPTION_OUTPUT);
- if (output_chd_str != NULL)
- osd_rmfile(output_chd_str->c_str());
+ auto output_chd_str = params.find(OPTION_OUTPUT);
+ if (output_chd_str != params.end())
+ osd_rmfile(output_chd_str->second->c_str());
throw;
}
}
@@ -2223,14 +2224,14 @@ static void do_extract_raw(parameters_t &params)
parse_input_start_end(params, input_chd.logical_bytes(), input_chd.hunk_bytes(), input_chd.hunk_bytes(), input_start, input_end);
// verify output file doesn't exist
- std::string *output_file_str = params.find(OPTION_OUTPUT);
- if (output_file_str != NULL)
- check_existing_output_file(params, output_file_str->c_str());
+ auto output_file_str = params.find(OPTION_OUTPUT);
+ if (output_file_str != params.end())
+ check_existing_output_file(params, output_file_str->second->c_str());
// print some info
std::string tempstr;
- printf("Output File: %s\n", output_file_str->c_str());
- printf("Input CHD: %s\n", params.find(OPTION_INPUT)->c_str());
+ printf("Output File: %s\n", output_file_str->second->c_str());
+ printf("Input CHD: %s\n", params.find(OPTION_INPUT)->second->c_str());
if (input_start != 0 || input_end != input_chd.logical_bytes())
{
printf("Input start: %s\n", big_int_string(tempstr, input_start));
@@ -2238,13 +2239,13 @@ static void do_extract_raw(parameters_t &params)
}
// catch errors so we can close & delete the output file
- core_file *output_file = NULL;
+ core_file *output_file = nullptr;
try
{
// process output file
- file_error filerr = core_fopen(output_file_str->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_file);
+ file_error filerr = core_fopen(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_file);
if (filerr != FILERR_NONE)
- report_error(1, "Unable to open file (%s)", output_file_str->c_str());
+ report_error(1, "Unable to open file (%s)", output_file_str->second->c_str());
// copy all data
dynamic_buffer buffer((TEMP_BUFFER_SIZE / input_chd.hunk_bytes()) * input_chd.hunk_bytes());
@@ -2256,12 +2257,12 @@ static void do_extract_raw(parameters_t &params)
UINT32 bytes_to_read = MIN((UINT32)buffer.size(), input_end - offset);
chd_error err = input_chd.read_bytes(offset, &buffer[0], bytes_to_read);
if (err != CHDERR_NONE)
- report_error(1, "Error reading CHD file (%s): %s", params.find(OPTION_INPUT)->c_str(), chd_file::error_string(err));
+ report_error(1, "Error reading CHD file (%s): %s", params.find(OPTION_INPUT)->second->c_str(), chd_file::error_string(err));
// write to the output
UINT32 count = core_fwrite(output_file, &buffer[0], bytes_to_read);
if (count != bytes_to_read)
- report_error(1, "Error writing to file; check disk space (%s)", output_file_str->c_str());
+ report_error(1, "Error writing to file; check disk space (%s)", output_file_str->second->c_str());
// advance
offset += bytes_to_read;
@@ -2274,10 +2275,10 @@ static void do_extract_raw(parameters_t &params)
catch (...)
{
// delete the output file
- if (output_file != NULL)
+ if (output_file != nullptr)
{
core_fclose(output_file);
- osd_rmfile(output_file_str->c_str());
+ osd_rmfile(output_file_str->second->c_str());
}
throw;
}
@@ -2298,54 +2299,58 @@ static void do_extract_cd(parameters_t &params)
// further process input file
cdrom_file *cdrom = cdrom_open(&input_chd);
- if (cdrom == NULL)
+ if (cdrom == nullptr)
report_error(1, "Unable to recognize CHD file as a CD");
const cdrom_toc *toc = cdrom_get_toc(cdrom);
// verify output file doesn't exist
- std::string *output_file_str = params.find(OPTION_OUTPUT);
- if (output_file_str != NULL)
- check_existing_output_file(params, output_file_str->c_str());
+ auto output_file_str = params.find(OPTION_OUTPUT);
+ if (output_file_str != params.end())
+ check_existing_output_file(params, output_file_str->second->c_str());
// verify output BIN file doesn't exist
- std::string *output_bin_file_str = params.find(OPTION_OUTPUT_BIN);
- std::string default_name(*output_file_str);
+ auto output_bin_file_fnd = params.find(OPTION_OUTPUT_BIN);
+ std::string default_name(*output_file_str->second);
int chop = default_name.find_last_of('.');
if (chop != -1)
default_name.substr(0, chop);
char basename[128];
strncpy(basename, default_name.c_str(), 127);
default_name.append(".bin");
- if (output_bin_file_str == NULL)
+ std::string *output_bin_file_str;
+ if (output_bin_file_fnd == params.end())
output_bin_file_str = &default_name;
+ else
+ output_bin_file_str = output_bin_file_fnd->second;
+
check_existing_output_file(params, output_bin_file_str->c_str());
// print some info
std::string tempstr;
- printf("Output TOC: %s\n", output_file_str->c_str());
+ printf("Output TOC: %s\n", output_file_str->second->c_str());
printf("Output Data: %s\n", output_bin_file_str->c_str());
- printf("Input CHD: %s\n", params.find(OPTION_INPUT)->c_str());
+ printf("Input CHD: %s\n", params.find(OPTION_INPUT)->second->c_str());
// catch errors so we can close & delete the output file
- core_file *output_bin_file = NULL;
- core_file *output_toc_file = NULL;
+ core_file *output_bin_file = nullptr;
+ core_file *output_toc_file = nullptr;
try
{
int mode = MODE_NORMAL;
- if (output_file_str->find(".cue") != -1)
+ if (output_file_str->second->find(".cue") != -1)
{
mode = MODE_CUEBIN;
}
- else if (output_file_str->find(".gdi") != -1)
+ else if (output_file_str->second->find(".gdi") != -1)
{
mode = MODE_GDI;
}
// process output file
- file_error filerr = core_fopen(output_file_str->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_NO_BOM, &output_toc_file);
+ file_error filerr = core_fopen(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_NO_BOM, &output_toc_file);
if (filerr != FILERR_NONE)
- report_error(1, "Unable to open file (%s)", output_file_str->c_str());
+ report_error(1, "Unable to open file (%s)", output_file_str->second->c_str());
// process output BIN file
if (mode != MODE_GDI)
@@ -2387,7 +2392,7 @@ static void do_extract_cd(parameters_t &params)
if (output_bin_file)
{
core_fclose(output_bin_file);
- output_bin_file = NULL;
+ output_bin_file = nullptr;
}
filerr = core_fopen(trackbin_name.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_bin_file);
@@ -2457,7 +2462,7 @@ static void do_extract_cd(parameters_t &params)
core_fseek(output_bin_file, outputoffs, SEEK_SET);
UINT32 byteswritten = core_fwrite(output_bin_file, &buffer[0], bufferoffs);
if (byteswritten != bufferoffs)
- report_error(1, "Error writing frame %d to file (%s): %s\n", frame, output_file_str->c_str(), chd_file::error_string(CHDERR_WRITE_ERROR));
+ report_error(1, "Error writing frame %d to file (%s): %s\n", frame, output_file_str->second->c_str(), chd_file::error_string(CHDERR_WRITE_ERROR));
outputoffs += bufferoffs;
bufferoffs = 0;
}
@@ -2474,12 +2479,12 @@ static void do_extract_cd(parameters_t &params)
catch (...)
{
// delete the output files
- if (output_bin_file != NULL)
+ if (output_bin_file != nullptr)
core_fclose(output_bin_file);
- if (output_toc_file != NULL)
+ if (output_toc_file != nullptr)
core_fclose(output_toc_file);
osd_rmfile(output_bin_file_str->c_str());
- osd_rmfile(output_file_str->c_str());
+ osd_rmfile(output_file_str->second->c_str());
throw;
}
}
@@ -2550,14 +2555,14 @@ static void do_extract_ld(parameters_t &params)
info.audio_samplerate = rate;
// verify output file doesn't exist
- std::string *output_file_str = params.find(OPTION_OUTPUT);
- if (output_file_str != NULL)
- check_existing_output_file(params, output_file_str->c_str());
+ auto output_file_str = params.find(OPTION_OUTPUT);
+ if (output_file_str != params.end())
+ check_existing_output_file(params, output_file_str->second->c_str());
// print some info
std::string tempstr;
- printf("Output File: %s\n", output_file_str->c_str());
- printf("Input CHD: %s\n", params.find(OPTION_INPUT)->c_str());
+ printf("Output File: %s\n", output_file_str->second->c_str());
+ printf("Input CHD: %s\n", params.find(OPTION_INPUT)->second->c_str());
if (input_start != 0 || input_end != input_chd.hunk_count())
{
printf("Input start: %s\n", big_int_string(tempstr, input_start));
@@ -2565,13 +2570,13 @@ static void do_extract_ld(parameters_t &params)
}
// catch errors so we can close & delete the output file
- avi_file *output_file = NULL;
+ avi_file *output_file = nullptr;
try
{
// process output file
- avi_error avierr = avi_create(output_file_str->c_str(), &info, &output_file);
+ avi_error avierr = avi_create(output_file_str->second->c_str(), &info, &output_file);
if (avierr != AVIERR_NONE)
- report_error(1, "Unable to open file (%s)", output_file_str->c_str());
+ report_error(1, "Unable to open file (%s)", output_file_str->second->c_str());
// create the codec configuration
avhuff_decompress_config avconfig;
@@ -2581,7 +2586,7 @@ static void do_extract_ld(parameters_t &params)
avconfig.actsamples = &actsamples;
for (int chnum = 0; chnum < ARRAY_LENGTH(audio_data); chnum++)
{
- audio_data[chnum].resize(max_samples_per_frame);
+ audio_data[chnum].resize(MAX(1,max_samples_per_frame));
avconfig.audio[chnum] = &audio_data[chnum][0];
}
@@ -2596,11 +2601,11 @@ static void do_extract_ld(parameters_t &params)
input_chd.codec_configure(CHD_CODEC_AVHUFF, AVHUFF_CODEC_DECOMPRESS_CONFIG, &avconfig);
// read the hunk into the buffers
- chd_error err = input_chd.read_hunk(framenum, NULL);
+ chd_error err = input_chd.read_hunk(framenum, nullptr);
if (err != CHDERR_NONE)
{
UINT64 filepos = core_ftell(input_chd);
- report_error(1, "Error reading hunk %" I64FMT "d at offset %" I64FMT "d from CHD file (%s): %s\n", framenum, filepos, params.find(OPTION_INPUT)->c_str(), chd_file::error_string(err));
+ report_error(1, "Error reading hunk %" I64FMT "d at offset %" I64FMT "d from CHD file (%s): %s\n", framenum, filepos, params.find(OPTION_INPUT)->second->c_str(), chd_file::error_string(err));
}
// write audio
@@ -2608,7 +2613,7 @@ static void do_extract_ld(parameters_t &params)
{
avi_error avierr = avi_append_sound_samples(output_file, chnum, avconfig.audio[chnum], actsamples, 0);
if (avierr != AVIERR_NONE)
- report_error(1, "Error writing samples for hunk %" I64FMT "d to file (%s): %s\n", framenum, output_file_str->c_str(), avi_error_string(avierr));
+ report_error(1, "Error writing samples for hunk %" I64FMT "d to file (%s): %s\n", framenum, output_file_str->second->c_str(), avi_error_string(avierr));
}
// write video
@@ -2616,7 +2621,7 @@ static void do_extract_ld(parameters_t &params)
{
avi_error avierr = avi_append_video_frame(output_file, fullbitmap);
if (avierr != AVIERR_NONE)
- report_error(1, "Error writing video for hunk %" I64FMT "d to file (%s): %s\n", framenum, output_file_str->c_str(), avi_error_string(avierr));
+ report_error(1, "Error writing video for hunk %" I64FMT "d to file (%s): %s\n", framenum, output_file_str->second->c_str(), avi_error_string(avierr));
}
}
@@ -2627,9 +2632,9 @@ static void do_extract_ld(parameters_t &params)
catch (...)
{
// delete the output file
- if (output_file != NULL)
+ if (output_file != nullptr)
avi_close(output_file);
- osd_rmfile(output_file_str->c_str());
+ osd_rmfile(output_file_str->second->c_str());
throw;
}
}
@@ -2649,63 +2654,63 @@ static void do_add_metadata(parameters_t &params)
// process tag
chd_metadata_tag tag = CHD_MAKE_TAG('?','?','?','?');
- std::string *tag_str = params.find(OPTION_TAG);
- if (tag_str != NULL)
+ auto tag_str = params.find(OPTION_TAG);
+ if (tag_str != params.end())
{
- tag_str->append(" ");
- tag = CHD_MAKE_TAG((*tag_str)[0], (*tag_str)[1], (*tag_str)[2], (*tag_str)[3]);
+ tag_str->second->append(" ");
+ tag = CHD_MAKE_TAG((*tag_str->second)[0], (*tag_str->second)[1], (*tag_str->second)[2], (*tag_str->second)[3]);
}
// process index
UINT32 index = 0;
- std::string *index_str = params.find(OPTION_INDEX);
- if (index_str != NULL)
- index = atoi(index_str->c_str());
+ auto index_str = params.find(OPTION_INDEX);
+ if (index_str != params.end())
+ index = atoi(index_str->second->c_str());
// process text input
- std::string *text_str = params.find(OPTION_VALUE_TEXT);
+ auto text_str = params.find(OPTION_VALUE_TEXT);
std::string text;
- if (text_str != NULL)
+ if (text_str != params.end())
{
- text = *text_str;
+ text = *text_str->second;
if (text[0] == '"' && text[text.length() - 1] == '"')
text.substr(1, text.length() - 2);
}
// process file input
- std::string *file_str = params.find(OPTION_VALUE_FILE);
+ auto file_str = params.find(OPTION_VALUE_FILE);
dynamic_buffer file;
- if (file_str != NULL)
+ if (file_str != params.end())
{
- file_error filerr = core_fload(file_str->c_str(), file);
+ file_error filerr = core_fload(file_str->second->c_str(), file);
if (filerr != FILERR_NONE)
- report_error(1, "Error reading metadata file (%s)", file_str->c_str());
+ report_error(1, "Error reading metadata file (%s)", file_str->second->c_str());
}
// make sure we have one or the other
- if (text_str == NULL && file_str == NULL)
+ if (text_str == params.end() && file_str == params.end())
report_error(1, "Error: missing either --valuetext/-vt or --valuefile/-vf parameters");
- if (text_str != NULL && file_str != NULL)
+ if (text_str != params.end() && file_str != params.end())
report_error(1, "Error: both --valuetext/-vt or --valuefile/-vf parameters specified; only one permitted");
// process no checksum
UINT8 flags = CHD_MDFLAGS_CHECKSUM;
- if (params.find(OPTION_NO_CHECKSUM) != NULL)
+ if (params.find(OPTION_NO_CHECKSUM) != params.end())
flags &= ~CHD_MDFLAGS_CHECKSUM;
// print some info
std::string tempstr;
- printf("Input file: %s\n", params.find(OPTION_INPUT)->c_str());
+ printf("Input file: %s\n", params.find(OPTION_INPUT)->second->c_str());
printf("Tag: %c%c%c%c\n", (tag >> 24) & 0xff, (tag >> 16) & 0xff, (tag >> 8) & 0xff, tag & 0xff);
printf("Index: %d\n", index);
- if (text_str != NULL)
+ if (text_str != params.end())
printf("Text: %s\n", text.c_str());
else
- printf("Data: %s (%d bytes)\n", file_str->c_str(), int(file.size()));
+ printf("Data: %s (%d bytes)\n", file_str->second->c_str(), int(file.size()));
// write the metadata
chd_error err;
- if (text_str != NULL)
+ if (text_str != params.end())
err = input_chd.write_metadata(tag, index, text, flags);
else
err = input_chd.write_metadata(tag, index, &file[0], flags);
@@ -2729,22 +2734,22 @@ static void do_del_metadata(parameters_t &params)
// process tag
chd_metadata_tag tag = CHD_MAKE_TAG('?','?','?','?');
- std::string *tag_str = params.find(OPTION_TAG);
- if (tag_str != NULL)
+ auto tag_str = params.find(OPTION_TAG);
+ if (tag_str != params.end())
{
- tag_str->append(" ");
- tag = CHD_MAKE_TAG((*tag_str)[0], (*tag_str)[1], (*tag_str)[2], (*tag_str)[3]);
+ tag_str->second->append(" ");
+ tag = CHD_MAKE_TAG((*tag_str->second)[0], (*tag_str->second)[1], (*tag_str->second)[2], (*tag_str->second)[3]);
}
// process index
UINT32 index = 0;
- std::string *index_str = params.find(OPTION_INDEX);
- if (index_str != NULL)
- index = atoi(index_str->c_str());
+ auto index_str = params.find(OPTION_INDEX);
+ if (index_str != params.end())
+ index = atoi(index_str->second->c_str());
// print some info
std::string tempstr;
- printf("Input file: %s\n", params.find(OPTION_INPUT)->c_str());
+ printf("Input file: %s\n", params.find(OPTION_INPUT)->second->c_str());
printf("Tag: %c%c%c%c\n", (tag >> 24) & 0xff, (tag >> 16) & 0xff, (tag >> 8) & 0xff, tag & 0xff);
printf("Index: %d\n", index);
@@ -2769,24 +2774,24 @@ static void do_dump_metadata(parameters_t &params)
parse_input_chd_parameters(params, input_chd, input_parent_chd);
// verify output file doesn't exist
- std::string *output_file_str = params.find(OPTION_OUTPUT);
- if (output_file_str != NULL)
- check_existing_output_file(params, output_file_str->c_str());
+ auto output_file_str = params.find(OPTION_OUTPUT);
+ if (output_file_str != params.end())
+ check_existing_output_file(params, output_file_str->second->c_str());
// process tag
chd_metadata_tag tag = CHD_MAKE_TAG('?','?','?','?');
- std::string *tag_str = params.find(OPTION_TAG);
- if (tag_str != NULL)
+ auto tag_str = params.find(OPTION_TAG);
+ if (tag_str != params.end())
{
- tag_str->append(" ");
- tag = CHD_MAKE_TAG((*tag_str)[0], (*tag_str)[1], (*tag_str)[2], (*tag_str)[3]);
+ tag_str->second->append(" ");
+ tag = CHD_MAKE_TAG((*tag_str->second)[0], (*tag_str->second)[1], (*tag_str->second)[2], (*tag_str->second)[3]);
}
// process index
UINT32 index = 0;
- std::string *index_str = params.find(OPTION_INDEX);
- if (index_str != NULL)
- index = atoi(index_str->c_str());
+ auto index_str = params.find(OPTION_INDEX);
+ if (index_str != params.end())
+ index = atoi(index_str->second->c_str());
// write the metadata
dynamic_buffer buffer;
@@ -2795,25 +2800,25 @@ static void do_dump_metadata(parameters_t &params)
report_error(1, "Error reading metadata: %s", chd_file::error_string(err));
// catch errors so we can close & delete the output file
- core_file *output_file = NULL;
+ core_file *output_file = nullptr;
try
{
// create the file
- if (output_file_str != NULL)
+ if (output_file_str != params.end())
{
- file_error filerr = core_fopen(output_file_str->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_file);
+ file_error filerr = core_fopen(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_file);
if (filerr != FILERR_NONE)
- report_error(1, "Unable to open file (%s)", output_file_str->c_str());
+ report_error(1, "Unable to open file (%s)", output_file_str->second->c_str());
// output the metadata
UINT32 count = core_fwrite(output_file, &buffer[0], buffer.size());
if (count != buffer.size())
- report_error(1, "Error writing file (%s)", output_file_str->c_str());
+ report_error(1, "Error writing file (%s)", output_file_str->second->c_str());
core_fclose(output_file);
// provide some feedback
std::string tempstr;
- printf("File (%s) written, %s bytes\n", output_file_str->c_str(), big_int_string(tempstr, buffer.size()));
+ printf("File (%s) written, %s bytes\n", output_file_str->second->c_str(), big_int_string(tempstr, buffer.size()));
}
// flush to stdout
@@ -2826,9 +2831,9 @@ static void do_dump_metadata(parameters_t &params)
catch (...)
{
// delete the output file
- if (output_file != NULL)
+ if (output_file != nullptr)
core_fclose(output_file);
- osd_rmfile(output_file_str->c_str());
+ osd_rmfile(output_file_str->second->c_str());
throw;
}
}
@@ -2858,17 +2863,17 @@ int CLIB_DECL main(int argc, char *argv[])
}
// iterate over commands to find our match
- for (int cmdnum = 0; cmdnum < ARRAY_LENGTH(s_commands); cmdnum++)
- if (strcmp(command, s_commands[cmdnum].name) == 0)
+ for (auto & s_command : s_commands)
+ if (strcmp(command, s_command.name) == 0)
{
- const command_description &desc = s_commands[cmdnum];
+ const command_description &desc = s_command;
// print help if that was requested
if (help)
return print_help(argv[0], desc);
// otherwise, verify the parameters
- tagmap_t<std::string *> parameters;
+ parameters_t parameters;
while (argnum < argc)
{
// should be an option name
@@ -2882,7 +2887,7 @@ int CLIB_DECL main(int argc, char *argv[])
{
// reduce to the option name
const char *validname = desc.valid_options[valid];
- if (validname == NULL)
+ if (validname == nullptr)
break;
if (*validname == REQUIRED[0])
validname++;
@@ -2897,7 +2902,7 @@ int CLIB_DECL main(int argc, char *argv[])
// do we match?
const option_description &odesc = s_options[optnum];
if ((arg[1] == '-' && strcmp(odesc.name, &arg[2]) == 0) ||
- (arg[1] != '-' && odesc.shortname != NULL && strcmp(odesc.shortname, &arg[1]) == 0))
+ (arg[1] != '-' && odesc.shortname != nullptr && strcmp(odesc.shortname, &arg[1]) == 0))
{
// if we need a parameter, consume it
const char *param = "";
@@ -2909,7 +2914,7 @@ int CLIB_DECL main(int argc, char *argv[])
}
// add to the map
- if (parameters.add(odesc.name, new std::string(param)) == TMERR_DUPLICATE)
+ if (!parameters.insert(std::make_pair(odesc.name, new std::string(param))).second)
return print_help(argv[0], desc, "Multiple parameters of the same type specified");
break;
}
@@ -2924,16 +2929,16 @@ int CLIB_DECL main(int argc, char *argv[])
for (int valid = 0; valid < ARRAY_LENGTH(desc.valid_options); valid++)
{
const char *validname = desc.valid_options[valid];
- if (validname == NULL)
+ if (validname == nullptr)
break;
- if (*validname == REQUIRED[0] && parameters.find(++validname) == NULL)
+ if (*validname == REQUIRED[0] && parameters.find(++validname) == parameters.end())
return print_help(argv[0], desc, "Required parameters missing");
}
// all clear, run the command
try
{
- (*s_commands[cmdnum].handler)(parameters);
+ (*s_command.handler)(parameters);
return 0;
}
catch (chd_error &err)