summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/options.cpp
diff options
context:
space:
mode:
author ImJezze <jezze@gmx.net>2016-03-02 21:49:49 +0100
committer ImJezze <jezze@gmx.net>2016-03-02 21:49:49 +0100
commit9fe9f6d93e672bcd926f9e7461774bc9cc22e094 (patch)
tree3911b611dd010a4108b90fb8b8c82116eec21117 /src/lib/util/options.cpp
parentdbdf21ee465acadf3e643d62d6bedfcc297ada85 (diff)
parent1914702e6fae052668df5b068a502bca57c9a3b0 (diff)
Merge remote-tracking branch 'refs/remotes/mamedev/master'
# Resolved Conflicts: # src/osd/modules/render/d3d/d3dhlsl.cpp # src/osd/windows/winmain.cpp
Diffstat (limited to 'src/lib/util/options.cpp')
-rw-r--r--src/lib/util/options.cpp124
1 files changed, 61 insertions, 63 deletions
diff --git a/src/lib/util/options.cpp b/src/lib/util/options.cpp
index 830721127ac..56bad147bcb 100644
--- a/src/lib/util/options.cpp
+++ b/src/lib/util/options.cpp
@@ -355,7 +355,7 @@ bool core_options::parse_command_line(int argc, char **argv, int priority, std::
auto curentry = m_entrymap.find(optionname);
if (curentry == m_entrymap.end())
{
- strcatprintf(error_string, "Error: unknown option: %s\n", curarg);
+ error_string.append(string_format("Error: unknown option: %s\n", curarg));
retval = false;
if (!is_unadorned) arg++;
continue;
@@ -367,7 +367,7 @@ bool core_options::parse_command_line(int argc, char **argv, int priority, std::
// can only have one command
if (!m_command.empty())
{
- strcatprintf(error_string,"Error: multiple commands specified -%s and %s\n", m_command.c_str(), curarg);
+ error_string.append(string_format("Error: multiple commands specified -%s and %s\n", m_command, curarg));
return false;
}
m_command = curentry->second->name();
@@ -384,7 +384,7 @@ bool core_options::parse_command_line(int argc, char **argv, int priority, std::
newdata = argv[++arg];
else
{
- strcatprintf(error_string, "Error: option %s expected a parameter\n", curarg);
+ error_string.append(string_format("Error: option %s expected a parameter\n", curarg));
return false;
}
@@ -425,7 +425,7 @@ bool core_options::parse_ini_file(core_file &inifile, int priority, int ignore_p
// if we hit the end early, print a warning and continue
if (*temp == 0)
{
- strcatprintf(error_string,"Warning: invalid line in INI: %s", buffer);
+ error_string.append(string_format("Warning: invalid line in INI: %s", buffer));
continue;
}
@@ -449,7 +449,7 @@ bool core_options::parse_ini_file(core_file &inifile, int priority, int ignore_p
if (curentry == m_entrymap.end())
{
if (priority >= ignore_priority)
- strcatprintf(error_string, "Warning: unknown option in INI: %s\n", optionname);
+ error_string.append(string_format("Warning: unknown option in INI: %s\n", optionname));
continue;
}
@@ -482,7 +482,7 @@ void core_options::revert(int priority)
std::string core_options::output_ini(const core_options *diff) const
{
// INI files are complete, so always start with a blank buffer
- std::string buffer;
+ std::ostringstream buffer;
int num_valid_headers = 0;
int unadorned_index = 0;
@@ -518,8 +518,8 @@ std::string core_options::output_ini(const core_options *diff) const
if (last_header != nullptr)
{
if (num_valid_headers++)
- strcatprintf(buffer,"\n");
- strcatprintf(buffer, "#\n# %s\n#\n", last_header);
+ buffer << '\n';
+ util::stream_format(buffer, "#\n# %s\n#\n", last_header);
last_header = nullptr;
}
@@ -527,15 +527,15 @@ std::string core_options::output_ini(const core_options *diff) const
if (!is_unadorned)
{
if (strchr(value, ' ') != nullptr)
- strcatprintf(buffer,"%-25s \"%s\"\n", name, value);
+ util::stream_format(buffer, "%-25s \"%s\"\n", name, value);
else
- strcatprintf(buffer,"%-25s %s\n", name, value);
+ util::stream_format(buffer, "%-25s %s\n", name, value);
}
}
}
}
}
- return buffer;
+ return buffer.str();
}
@@ -546,20 +546,20 @@ std::string core_options::output_ini(const core_options *diff) const
std::string core_options::output_help() const
{
// start empty
- std::string buffer;
+ std::ostringstream buffer;
// loop over all items
for (entry *curentry = m_entrylist.first(); curentry != nullptr; curentry = curentry->next())
{
// header: just print
if (curentry->is_header())
- strcatprintf(buffer,"\n#\n# %s\n#\n", curentry->description());
+ util::stream_format(buffer, "\n#\n# %s\n#\n", curentry->description());
// otherwise, output entries for all non-deprecated items
else if (curentry->description() != nullptr)
- strcatprintf(buffer,"-%-20s%s\n", curentry->name(), curentry->description());
+ util::stream_format(buffer, "-%-20s%s\n", curentry->name(), curentry->description());
}
- return buffer;
+ return buffer.str();
}
@@ -635,7 +635,7 @@ bool core_options::set_value(const char *name, const char *value, int priority,
auto curentry = m_entrymap.find(name);
if (curentry == m_entrymap.end())
{
- strcatprintf(error_string, "Attempted to set unknown option %s\n", name);
+ error_string.append(string_format("Attempted to set unknown option %s\n", name));
return false;
}
@@ -645,14 +645,12 @@ bool core_options::set_value(const char *name, const char *value, int priority,
bool core_options::set_value(const char *name, int value, int priority, std::string &error_string)
{
- std::string tempstr = strformat("%d", value);
- return set_value(name, tempstr.c_str(), priority, error_string);
+ return set_value(name, string_format("%d", value).c_str(), priority, error_string);
}
bool core_options::set_value(const char *name, float value, int priority, std::string &error_string)
{
- std::string tempstr = strformat("%f", (double)value);
- return set_value(name, tempstr.c_str(), priority, error_string);
+ return set_value(name, string_format("%f", value).c_str(), priority, error_string);
}
@@ -785,53 +783,53 @@ bool core_options::validate_and_set_data(core_options::entry &curentry, const ch
int ival;
switch (curentry.type())
{
- // booleans must be 0 or 1
- case OPTION_BOOLEAN:
- if (sscanf(data.c_str(), "%d", &ival) != 1 || ival < 0 || ival > 1)
- {
- strcatprintf(error_string, "Illegal boolean value for %s: \"%s\"; reverting to %s\n", curentry.name(), data.c_str(), curentry.value());
- return false;
- }
- break;
+ // booleans must be 0 or 1
+ case OPTION_BOOLEAN:
+ if (sscanf(data.c_str(), "%d", &ival) != 1 || ival < 0 || ival > 1)
+ {
+ error_string.append(string_format("Illegal boolean value for %s: \"%s\"; reverting to %s\n", curentry.name(), data.c_str(), curentry.value()));
+ return false;
+ }
+ break;
- // integers must be integral
- case OPTION_INTEGER:
- if (sscanf(data.c_str(), "%d", &ival) != 1)
- {
- strcatprintf(error_string, "Illegal integer value for %s: \"%s\"; reverting to %s\n", curentry.name(), data.c_str(), curentry.value());
- return false;
- }
- if (curentry.has_range() && (ival < atoi(curentry.minimum()) || ival > atoi(curentry.maximum())))
- {
- strcatprintf(error_string, "Out-of-range integer value for %s: \"%s\" (must be between %s and %s); reverting to %s\n", curentry.name(), data.c_str(), curentry.minimum(), curentry.maximum(), curentry.value());
- return false;
- }
- break;
+ // integers must be integral
+ case OPTION_INTEGER:
+ if (sscanf(data.c_str(), "%d", &ival) != 1)
+ {
+ error_string.append(string_format("Illegal integer value for %s: \"%s\"; reverting to %s\n", curentry.name(), data.c_str(), curentry.value()));
+ return false;
+ }
+ if (curentry.has_range() && (ival < atoi(curentry.minimum()) || ival > atoi(curentry.maximum())))
+ {
+ error_string.append(string_format("Out-of-range integer value for %s: \"%s\" (must be between %s and %s); reverting to %s\n", curentry.name(), data.c_str(), curentry.minimum(), curentry.maximum(), curentry.value()));
+ return false;
+ }
+ break;
- // floating-point values must be numeric
- case OPTION_FLOAT:
- if (sscanf(data.c_str(), "%f", &fval) != 1)
- {
- strcatprintf(error_string, "Illegal float value for %s: \"%s\"; reverting to %s\n", curentry.name(), data.c_str(), curentry.value());
- return false;
- }
- if (curentry.has_range() && ((double) fval < atof(curentry.minimum()) || (double) fval > atof(curentry.maximum())))
- {
- strcatprintf(error_string, "Out-of-range float value for %s: \"%s\" (must be between %s and %s); reverting to %s\n", curentry.name(), data.c_str(), curentry.minimum(), curentry.maximum(), curentry.value());
- return false;
- }
- break;
+ // floating-point values must be numeric
+ case OPTION_FLOAT:
+ if (sscanf(data.c_str(), "%f", &fval) != 1)
+ {
+ error_string.append(string_format("Illegal float value for %s: \"%s\"; reverting to %s\n", curentry.name(), data.c_str(), curentry.value()));
+ return false;
+ }
+ if (curentry.has_range() && ((double) fval < atof(curentry.minimum()) || (double) fval > atof(curentry.maximum())))
+ {
+ error_string.append(string_format("Out-of-range float value for %s: \"%s\" (must be between %s and %s); reverting to %s\n", curentry.name(), data.c_str(), curentry.minimum(), curentry.maximum(), curentry.value()));
+ return false;
+ }
+ break;
- // strings can be anything
- case OPTION_STRING:
- break;
+ // strings can be anything
+ case OPTION_STRING:
+ break;
- // anything else is invalid
- case OPTION_INVALID:
- case OPTION_HEADER:
- default:
- strcatprintf(error_string, "Attempted to set invalid option %s\n", curentry.name());
- return false;
+ // anything else is invalid
+ case OPTION_INVALID:
+ case OPTION_HEADER:
+ default:
+ error_string.append(string_format("Attempted to set invalid option %s\n", curentry.name()));
+ return false;
}
// set the data