diff options
author | 2017-05-11 19:18:20 -0400 | |
---|---|---|
committer | 2017-05-12 09:18:20 +1000 | |
commit | 78bf804192f38d69fc9299dc7da724fb6a537f94 (patch) | |
tree | f6e88d4dbfda3fd902b9d59eeb242da8a8e87b80 /src/lib/util/options.cpp | |
parent | 16cbbd91031df43437ee393cfd18ebc6373409eb (diff) |
Bug fix to -romident and aux verb cleanup (#2288)
* Bug fix to -romident and aux verb cleanup
Made the following changes:
1. Fixed a bug where resolved slot/image options would choke -romident (reproducible in MAME 0.185 with 'mame64 -romident coco.zip')
2. 'mame64 -romident' no longer crashes (though it doesn't do anything useful)
3. Changed the aux verb functions to take 'const std::string &'
* Further cleanups to auxillary verb code, as per Vas
Specifically:
1. The commands themselves now take 'const std::vector<std::string> &' for their argument lists
2. util::core_options now collects command arguments into a separate vector rather than treating them as unadorned arguments
* Vas Crabb feedback
* Now only using trim_spaces_and_quotes() when parsing INIs
Vas pointed out that it is inappropriate to trim spaces and quotes when parsing command line options
Diffstat (limited to 'src/lib/util/options.cpp')
-rw-r--r-- | src/lib/util/options.cpp | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/src/lib/util/options.cpp b/src/lib/util/options.cpp index af172d7a94b..d48268839c2 100644 --- a/src/lib/util/options.cpp +++ b/src/lib/util/options.cpp @@ -44,6 +44,26 @@ const char *const core_options::s_option_unadorned[MAX_UNADORNED_OPTIONS] = }; +//************************************************************************** +// UTILITY +//************************************************************************** + +namespace +{ + void trim_spaces_and_quotes(std::string &data) + { + // trim any whitespace + strtrimspace(data); + + // trim quotes + if (data.find_first_of('"') == 0 && data.find_last_of('"') == data.length() - 1) + { + data.erase(0, 1); + data.erase(data.length() - 1, 1); + } + } +}; + //************************************************************************** // CORE OPTIONS ENTRY @@ -353,6 +373,14 @@ bool core_options::parse_command_line(std::vector<std::string> &args, int priori bool is_unadorned = (curarg[0] != '-'); const char *optionname = is_unadorned ? core_options::unadorned(unadorned_index++) : &curarg[1]; + // special case - collect unadorned arguments after commands into a special place + if (is_unadorned && !m_command.empty()) + { + m_command_arguments.push_back(std::move(args[arg])); + args[arg].clear(); + continue; + } + // find our entry; if not found, continue auto curentry = m_entrymap.find(optionname); if (curentry == m_entrymap.end()) @@ -478,7 +506,9 @@ bool core_options::parse_ini_file(util::core_file &inifile, int priority, bool i } // set the new data - validate_and_set_data(*curentry->second, optiondata, priority, error_string); + std::string data = optiondata; + trim_spaces_and_quotes(data); + validate_and_set_data(*curentry->second, std::move(data), priority, error_string); } return true; } @@ -832,16 +862,6 @@ void core_options::copyfrom(const core_options &src) bool core_options::validate_and_set_data(core_options::entry &curentry, std::string &&data, int priority, std::string &error_string) { - // trim any whitespace - strtrimspace(data); - - // trim quotes - if (data.find_first_of('"') == 0 && data.find_last_of('"') == data.length() - 1) - { - data.erase(0, 1); - data.erase(data.length() - 1, 1); - } - // let derived classes override how we set this data if (override_set_value(curentry.name(), data)) return true; |