diff options
Diffstat (limited to 'src/lib/util/options.cpp')
-rw-r--r-- | src/lib/util/options.cpp | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/src/lib/util/options.cpp b/src/lib/util/options.cpp index 56bad147bcb..f8ef33b0d39 100644 --- a/src/lib/util/options.cpp +++ b/src/lib/util/options.cpp @@ -146,13 +146,13 @@ void core_options::entry::set_flag(UINT32 mask, UINT32 flag) //------------------------------------------------- // revert - revert back to our default if we are -// at or below the given priority +// within the given priority range //------------------------------------------------- -void core_options::entry::revert(int priority) +void core_options::entry::revert(int priority_hi, int priority_lo) { - // if our priority is low enough, revert to the default - if (m_priority <= priority) + // if our priority is within the range, revert to the default + if (m_priority <= priority_hi && m_priority >= priority_lo) { m_data = m_defdata; m_priority = OPTION_PRIORITY_DEFAULT; @@ -226,11 +226,11 @@ core_options &core_options::operator=(const core_options &rhs) bool core_options::operator==(const core_options &rhs) { // iterate over options in the first list - for (entry *curentry = m_entrylist.first(); curentry != nullptr; curentry = curentry->next()) - if (!curentry->is_header()) + for (entry &curentry : m_entrylist) + if (!curentry.is_header()) { // if the values differ, return false - if (strcmp(curentry->value(), rhs.value(curentry->name())) != 0) + if (strcmp(curentry.value(), rhs.value(curentry.name())) != 0) return false; } @@ -400,11 +400,11 @@ bool core_options::parse_command_line(int argc, char **argv, int priority, std:: // an INI file //------------------------------------------------- -bool core_options::parse_ini_file(core_file &inifile, int priority, int ignore_priority, std::string &error_string) +bool core_options::parse_ini_file(util::core_file &inifile, int priority, int ignore_priority, std::string &error_string) { // loop over lines in the file char buffer[4096]; - while (core_fgets(buffer, ARRAY_LENGTH(buffer), &inifile) != nullptr) + while (inifile.gets(buffer, ARRAY_LENGTH(buffer)) != nullptr) { // find the extent of the name char *optionname; @@ -465,11 +465,11 @@ bool core_options::parse_ini_file(core_file &inifile, int priority, int ignore_p // priority back to their defaults //------------------------------------------------- -void core_options::revert(int priority) +void core_options::revert(int priority_hi, int priority_lo) { // iterate over options and revert to defaults if below the given priority - for (entry *curentry = m_entrylist.first(); curentry != nullptr; curentry = curentry->next()) - curentry->revert(priority); + for (entry &curentry : m_entrylist) + curentry.revert(priority_hi, priority_lo); } @@ -489,10 +489,10 @@ std::string core_options::output_ini(const core_options *diff) const const char *last_header = nullptr; // loop over all items - for (entry *curentry = m_entrylist.first(); curentry != nullptr; curentry = curentry->next()) + for (entry &curentry : m_entrylist) { - const char *name = curentry->name(); - const char *value = curentry->value(); + const char *name = curentry.name(); + const char *value = curentry.value(); bool is_unadorned = false; // check if it's unadorned @@ -503,13 +503,13 @@ std::string core_options::output_ini(const core_options *diff) const } // header: record description - if (curentry->is_header()) - last_header = curentry->description(); + if (curentry.is_header()) + last_header = curentry.description(); // otherwise, output entries for all non-command items - else if (!curentry->is_command()) + else if (!curentry.is_command()) { - if ( !curentry->is_internal() ) + if (!curentry.is_internal()) { // look up counterpart in diff, if diff is specified if (diff == nullptr || strcmp(value, diff->value(name)) != 0) @@ -549,15 +549,15 @@ std::string core_options::output_help() const std::ostringstream buffer; // loop over all items - for (entry *curentry = m_entrylist.first(); curentry != nullptr; curentry = curentry->next()) + for (entry &curentry : m_entrylist) { // header: just print - if (curentry->is_header()) - util::stream_format(buffer, "\n#\n# %s\n#\n", curentry->description()); + if (curentry.is_header()) + util::stream_format(buffer, "\n#\n# %s\n#\n", curentry.description()); // otherwise, output entries for all non-deprecated items - else if (curentry->description() != nullptr) - util::stream_format(buffer, "-%-20s%s\n", curentry->name(), curentry->description()); + else if (curentry.description() != nullptr) + util::stream_format(buffer, "-%-20s%s\n", curentry.name(), curentry.description()); } return buffer.str(); } @@ -744,8 +744,8 @@ void core_options::copyfrom(const core_options &src) reset(); // iterate through the src options and make our own - for (entry *curentry = src.m_entrylist.first(); curentry != nullptr; curentry = curentry->next()) - append_entry(*global_alloc(entry(curentry->name(), curentry->description(), curentry->flags(), curentry->default_value()))); + for (entry &curentry : src.m_entrylist) + append_entry(*global_alloc(entry(curentry.name(), curentry.description(), curentry.flags(), curentry.default_value()))); } /** @@ -836,3 +836,9 @@ bool core_options::validate_and_set_data(core_options::entry &curentry, const ch curentry.set_value(data.c_str(), priority); return true; } + +core_options::entry *core_options::get_entry(const char *name) const +{ + auto curentry = m_entrymap.find(name); + return (curentry != m_entrymap.end()) ? curentry->second : nullptr; +}
\ No newline at end of file |