diff options
author | 2017-06-24 22:48:56 -0400 | |
---|---|---|
committer | 2017-06-25 12:48:56 +1000 | |
commit | b193e05cd7c8456a2648d43854645da84f56ddbd (patch) | |
tree | 406d4dca91e403acdcea26379bcf65e567ca4834 /src/frontend/mame/clifront.cpp | |
parent | 1b28df0b39225c3017e7bc843c14b58f548162ac (diff) |
Overhaul to how MAME handles options, take two (#2341)
Diffstat (limited to 'src/frontend/mame/clifront.cpp')
-rw-r--r-- | src/frontend/mame/clifront.cpp | 96 |
1 files changed, 47 insertions, 49 deletions
diff --git a/src/frontend/mame/clifront.cpp b/src/frontend/mame/clifront.cpp index 6e5d77c40e0..a36b47da683 100644 --- a/src/frontend/mame/clifront.cpp +++ b/src/frontend/mame/clifront.cpp @@ -190,26 +190,30 @@ cli_frontend::cli_frontend(emu_options &options, osd_interface &osd) cli_frontend::~cli_frontend() { - // nuke any device options since they will leak memory - mame_options::remove_device_options(m_options); } -void cli_frontend::start_execution(mame_machine_manager *manager, std::vector<std::string> &args) +void cli_frontend::start_execution(mame_machine_manager *manager, const std::vector<std::string> &args) { - std::string option_errors; + std::ostringstream option_errors; + + // because softlist evaluation relies on hashpath being populated, we are going to go through + // a special step to force it to be evaluated + mame_options::populate_hashpath_from_args_and_inis(m_options, args); // parse the command line, adding any system-specific options - if (!mame_options::parse_command_line(m_options, args, option_errors)) + try + { + m_options.parse_command_line(args, OPTION_PRIORITY_CMDLINE); + } + catch (options_exception &ex) { // if we failed, check for no command and a system name first; in that case error on the name - if (m_options.command().empty() && mame_options::system(m_options) == nullptr && *(m_options.system_name()) != 0) - throw emu_fatalerror(EMU_ERR_NO_SUCH_GAME, "Unknown system '%s'", m_options.system_name()); + if (m_options.command().empty() && mame_options::system(m_options) == nullptr && !m_options.attempted_system_name().empty()) + throw emu_fatalerror(EMU_ERR_NO_SUCH_GAME, "Unknown system '%s'", m_options.attempted_system_name().c_str()); // otherwise, error on the options - throw emu_fatalerror(EMU_ERR_INVALID_CONFIG, "%s", strtrimspace(option_errors).c_str()); + throw emu_fatalerror(EMU_ERR_INVALID_CONFIG, "%s", ex.message().c_str()); } - if (!option_errors.empty()) - osd_printf_error("Error in command line:\n%s\n", strtrimspace(option_errors).c_str()); // determine the base name of the EXE std::string exename = core_filename_extract_base(args[0], true); @@ -232,8 +236,11 @@ void cli_frontend::start_execution(mame_machine_manager *manager, std::vector<st manager->start_luaengine(); - if (!option_errors.empty()) - osd_printf_error("Error in command line:\n%s\n", strtrimspace(option_errors).c_str()); + if (option_errors.tellp() > 0) + { + std::string option_errors_string = option_errors.str(); + osd_printf_error("Error in command line:\n%s\n", strtrimspace(option_errors_string).c_str()); + } // if we can't find it, give an appropriate error const game_driver *system = mame_options::system(m_options); @@ -269,16 +276,19 @@ int cli_frontend::execute(std::vector<std::string> &args) // if a game was specified, wasn't a wildcard, and our error indicates this was the // reason for failure, offer some suggestions - if (m_result == EMU_ERR_NO_SUCH_GAME && *(m_options.system_name()) != 0 && !core_iswildstr(m_options.system_name()) && mame_options::system(m_options) == nullptr) + if (m_result == EMU_ERR_NO_SUCH_GAME + && !m_options.attempted_system_name().empty() + && !core_iswildstr(m_options.attempted_system_name().c_str()) + && mame_options::system(m_options) == nullptr) { // get the top 16 approximate matches driver_enumerator drivlist(m_options); int matches[16]; - drivlist.find_approximate_matches(m_options.system_name(), ARRAY_LENGTH(matches), matches); + drivlist.find_approximate_matches(m_options.attempted_system_name().c_str(), ARRAY_LENGTH(matches), matches); // print them out osd_printf_error("\n\"%s\" approximately matches the following\n" - "supported machines (best match first):\n\n", m_options.system_name()); + "supported machines (best match first):\n\n", m_options.attempted_system_name().c_str()); for (auto & matche : matches) if (matche != -1) osd_printf_error("%-18s%s\n", drivlist.driver(matche).name, drivlist.driver(matche).type.fullname()); @@ -1441,8 +1451,7 @@ void cli_frontend::romident(const std::vector<std::string> &args) // create our own copy of options for the purposes of ROM identification // so we are not "polluted" with driver-specific slot/image options emu_options options; - std::string error_string; - options.set_value(OPTION_MEDIAPATH, m_options.media_path(), OPTION_PRIORITY_DEFAULT, error_string); + options.set_value(OPTION_MEDIAPATH, m_options.media_path(), OPTION_PRIORITY_DEFAULT); media_identifier ident(options); @@ -1470,24 +1479,24 @@ const cli_frontend::info_command_struct *cli_frontend::find_command(const std::s { static const info_command_struct s_info_commands[] = { - { CLICOMMAND_LISTXML, 0, -1, false, &cli_frontend::listxml, "[pattern] ..." }, - { CLICOMMAND_LISTFULL, 0, 1, false, &cli_frontend::listfull, "[system name]" }, - { CLICOMMAND_LISTSOURCE, 0, 1, false, &cli_frontend::listsource, "[system name]" }, - { CLICOMMAND_LISTCLONES, 0, 1, false, &cli_frontend::listclones, "[system name]" }, - { CLICOMMAND_LISTBROTHERS, 0, 1, false, &cli_frontend::listbrothers, "[system name]" }, - { CLICOMMAND_LISTCRC, 0, 1, false, &cli_frontend::listcrc, "[system name]" }, - { CLICOMMAND_LISTDEVICES, 0, 1, true, &cli_frontend::listdevices, "[system name]" }, - { CLICOMMAND_LISTSLOTS, 0, 1, true, &cli_frontend::listslots, "[system name]" }, - { CLICOMMAND_LISTROMS, 0, -1, false, &cli_frontend::listroms, "[pattern] ..." }, - { CLICOMMAND_LISTSAMPLES, 0, 1, false, &cli_frontend::listsamples, "[system name]" }, - { CLICOMMAND_VERIFYROMS, 0, -1, false, &cli_frontend::verifyroms, "[pattern] ..." }, - { CLICOMMAND_VERIFYSAMPLES, 0, 1, false, &cli_frontend::verifysamples, "[system name|*]" }, - { CLICOMMAND_LISTMEDIA, 0, 1, true, &cli_frontend::listmedia, "[system name]" }, - { CLICOMMAND_LISTSOFTWARE, 0, 1, false, &cli_frontend::listsoftware, "[system name]" }, - { CLICOMMAND_VERIFYSOFTWARE, 0, 1, false, &cli_frontend::verifysoftware, "[system name|*]" }, - { CLICOMMAND_ROMIDENT, 1, 1, false, &cli_frontend::romident, "(file or directory path)" }, - { CLICOMMAND_GETSOFTLIST, 0, 1, false, &cli_frontend::getsoftlist, "[system name|*]" }, - { CLICOMMAND_VERIFYSOFTLIST, 0, 1, false, &cli_frontend::verifysoftlist, "[system name|*]" } + { CLICOMMAND_LISTXML, 0, -1, &cli_frontend::listxml, "[pattern] ..." }, + { CLICOMMAND_LISTFULL, 0, 1, &cli_frontend::listfull, "[system name]" }, + { CLICOMMAND_LISTSOURCE, 0, 1, &cli_frontend::listsource, "[system name]" }, + { CLICOMMAND_LISTCLONES, 0, 1, &cli_frontend::listclones, "[system name]" }, + { CLICOMMAND_LISTBROTHERS, 0, 1, &cli_frontend::listbrothers, "[system name]" }, + { CLICOMMAND_LISTCRC, 0, 1, &cli_frontend::listcrc, "[system name]" }, + { CLICOMMAND_LISTDEVICES, 0, 1, &cli_frontend::listdevices, "[system name]" }, + { CLICOMMAND_LISTSLOTS, 0, 1, &cli_frontend::listslots, "[system name]" }, + { CLICOMMAND_LISTROMS, 0, -1, &cli_frontend::listroms, "[pattern] ..." }, + { CLICOMMAND_LISTSAMPLES, 0, 1, &cli_frontend::listsamples, "[system name]" }, + { CLICOMMAND_VERIFYROMS, 0, -1, &cli_frontend::verifyroms, "[pattern] ..." }, + { CLICOMMAND_VERIFYSAMPLES, 0, 1, &cli_frontend::verifysamples, "[system name|*]" }, + { CLICOMMAND_LISTMEDIA, 0, 1, &cli_frontend::listmedia, "[system name]" }, + { CLICOMMAND_LISTSOFTWARE, 0, 1, &cli_frontend::listsoftware, "[system name]" }, + { CLICOMMAND_VERIFYSOFTWARE, 0, 1, &cli_frontend::verifysoftware, "[system name|*]" }, + { CLICOMMAND_ROMIDENT, 1, 1, &cli_frontend::romident, "(file or directory path)" }, + { CLICOMMAND_GETSOFTLIST, 0, 1, &cli_frontend::getsoftlist, "[system name|*]" }, + { CLICOMMAND_VERIFYSOFTLIST, 0, 1, &cli_frontend::verifysoftlist, "[system name|*]" } }; for (const auto &info_command : s_info_commands) @@ -1500,17 +1509,6 @@ const cli_frontend::info_command_struct *cli_frontend::find_command(const std::s //------------------------------------------------- -// parse_slot_options_for_auxverb -//------------------------------------------------- - -bool cli_frontend::parse_slot_options_for_auxverb(const std::string &auxverb) -{ - const info_command_struct *command = find_command(auxverb); - return command && command->specify_system; -} - - -//------------------------------------------------- // execute_commands - execute various frontend // commands //------------------------------------------------- @@ -1545,10 +1543,10 @@ void cli_frontend::execute_commands(const char *exename) } // other commands need the INIs parsed - std::string option_errors; + std::ostringstream option_errors; mame_options::parse_standard_inis(m_options,option_errors); - if (!option_errors.empty()) - osd_printf_error("%s\n", option_errors.c_str()); + if (option_errors.tellp() > 0) + osd_printf_error("%s\n", option_errors.str().c_str()); // createconfig? if (m_options.command() == CLICOMMAND_CREATECONFIG) |