summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/options.cpp
diff options
context:
space:
mode:
author npwoods <npwoods@alumni.carnegiemellon.edu>2017-02-22 07:16:23 -0500
committer Vas Crabb <cuavas@users.noreply.github.com>2017-02-22 23:16:23 +1100
commit709c330a1f2f2deb095967f865d2c638b63cc497 (patch)
treef502f6b638d1c538f16bac60026205810048ac2c /src/lib/util/options.cpp
parentc2070315db52e43f66b91b385546f2b5885f4eea (diff)
Softlist cleanup (#2075)
* Eliminates the need for emu_options::update_cached_options() by providing a hook for when option values change * This is a preliminary fix to the issue identified in PR#2065 * More softlist related refactoring: - We now only parse the command line (with core_options::parse_command_line()) once - Options that are set up during slot and image setup go through a 'value_specifier' function - Eliminated the command line postprocessing
Diffstat (limited to 'src/lib/util/options.cpp')
-rw-r--r--src/lib/util/options.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/lib/util/options.cpp b/src/lib/util/options.cpp
index 7e40ab736de..b0b5439c129 100644
--- a/src/lib/util/options.cpp
+++ b/src/lib/util/options.cpp
@@ -277,6 +277,9 @@ void core_options::add_entry(const char *name, const char *description, uint32_t
return;
}
}
+
+ // need to call value_changed() with initial value
+ value_changed(newentry->name(), newentry->value());
}
// add us to the list and maps
@@ -462,6 +465,42 @@ bool core_options::parse_ini_file(util::core_file &inifile, int priority, int ig
//-------------------------------------------------
+// find_within_command_line - finds a specific
+// value from within a command line
+//-------------------------------------------------
+
+const char *core_options::find_within_command_line(int argc, char **argv, const char *optionname)
+{
+ // find this entry within the options (it is illegal to call this with a non-existant option
+ // so we assert if not present)
+ auto curentry = m_entrymap.find(optionname);
+ assert(curentry != m_entrymap.end());
+
+ // build a vector with potential targets
+ std::vector<std::string> targets;
+ const char *potential_target;
+ int index = 0;
+ while ((potential_target = curentry->second->name(index++)) != nullptr)
+ {
+ // not supporting unadorned options for now
+ targets.push_back(std::string("-") + potential_target);
+ }
+
+ // find each of the targets in the argv array
+ for (int i = 1; i < argc - 1; i++)
+ {
+ auto const iter = std::find_if(
+ targets.begin(),
+ targets.end(),
+ [argv, i](const std::string &targ) { return targ == argv[i]; });
+ if (iter != targets.end())
+ return argv[i + 1];
+ }
+ return nullptr;
+}
+
+
+//-------------------------------------------------
// revert - revert options at or below a certain
// priority back to their defaults
//-------------------------------------------------
@@ -835,6 +874,7 @@ bool core_options::validate_and_set_data(core_options::entry &curentry, const ch
// set the data
curentry.set_value(data.c_str(), priority);
+ value_changed(curentry.name(), data);
return true;
}