summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2011-01-23 16:55:11 +0000
committer Miodrag Milanovic <mmicko@gmail.com>2011-01-23 16:55:11 +0000
commit9699603819c7514657fe4713892f84ef35d02e4c (patch)
tree74712c2de04e8f5c498e3e294d7718d5d0274e6d /src
parent01158b20fe52b66826ba93de224d3bc3c9a93d1e (diff)
- Display suggestions in case commands that require game name are called and there were no matching games [Miodrag Milanovic]
- Display suggestions for driver even if there are additional parameters that do not match (used on MESS where we have driver dependent parameters)
Diffstat (limited to 'src')
-rw-r--r--src/emu/clifront.c47
-rw-r--r--src/lib/util/options.c24
-rw-r--r--src/lib/util/options.h2
3 files changed, 55 insertions, 18 deletions
diff --git a/src/emu/clifront.c b/src/emu/clifront.c
index b865cb6731a..58bc7eb3d4e 100644
--- a/src/emu/clifront.c
+++ b/src/emu/clifront.c
@@ -62,6 +62,7 @@ static void romident(core_options *options, const char *filename, romident_statu
static void identify_file(core_options *options, const char *name, romident_status *status);
static void identify_data(core_options *options, const char *name, const UINT8 *data, int length, romident_status *status);
static void match_roms(core_options *options, const char *hash, int length, int *found);
+static void display_suggestions(const char *gamename);
@@ -108,6 +109,21 @@ static const options_entry cli_options[] =
CORE IMPLEMENTATION
***************************************************************************/
+static void display_suggestions(const char *gamename)
+{
+ const game_driver *matches[10];
+ int drvnum;
+
+ /* get the top 10 approximate matches */
+ driver_list_get_approx_matches(drivers, gamename, ARRAY_LENGTH(matches), matches);
+
+ /* print them out */
+ fprintf(stderr, "\n\"%s\" approximately matches the following\n"
+ "supported " GAMESNOUN " (best match first):\n\n", gamename);
+ for (drvnum = 0; drvnum < ARRAY_LENGTH(matches); drvnum++)
+ if (matches[drvnum] != NULL)
+ fprintf(stderr, "%-18s%s\n", matches[drvnum]->name, matches[drvnum]->description);
+}
/*-------------------------------------------------
cli_execute - execute a game via the standard
command line interface
@@ -129,7 +145,7 @@ int cli_execute(int argc, char **argv, osd_interface &osd, const options_entry *
options_add_entries(options, cli_options);
/* parse the command line first; if we fail here, we're screwed */
- if (options_parse_command_line(options, argc, argv, OPTION_PRIORITY_CMDLINE))
+ if (options_parse_command_line(options, argc, argv, OPTION_PRIORITY_CMDLINE, FALSE))
{
result = MAMERR_INVALID_CONFIG;
goto error;
@@ -154,23 +170,18 @@ int cli_execute(int argc, char **argv, osd_interface &osd, const options_entry *
/* if we don't have a valid driver selected, offer some suggestions */
if (strlen(gamename_option) > 0 && driver == NULL)
{
- const game_driver *matches[10];
- int drvnum;
-
- /* get the top 10 approximate matches */
- driver_list_get_approx_matches(drivers, gamename_option, ARRAY_LENGTH(matches), matches);
-
- /* print them out */
- fprintf(stderr, "\n\"%s\" approximately matches the following\n"
- "supported " GAMESNOUN " (best match first):\n\n", gamename_option);
- for (drvnum = 0; drvnum < ARRAY_LENGTH(matches); drvnum++)
- if (matches[drvnum] != NULL)
- fprintf(stderr, "%-18s%s\n", matches[drvnum]->name, matches[drvnum]->description);
-
+ display_suggestions(gamename_option);
/* exit with an error */
result = MAMERR_NO_SUCH_GAME;
goto error;
}
+ /* parse the command line first; if we fail here, we're screwed */
+ if (options_parse_command_line(options, argc, argv, OPTION_PRIORITY_CMDLINE, TRUE))
+ {
+ result = MAMERR_INVALID_CONFIG;
+ goto error;
+ }
+
/* run the game */
result = mame_execute(osd, options);
@@ -318,10 +329,14 @@ static int execute_commands(core_options *options, const char *exename, const ga
if (options_get_bool(options, info_commands[i].option))
{
const char *gamename = options_get_string(options, OPTION_GAMENAME);
-
/* parse any relevant INI files before proceeding */
mame_parse_ini_files(options, driver);
- return (*info_commands[i].function)(options, (gamename[0] == 0) ? "*" : gamename);
+ int retVal = (*info_commands[i].function)(options, (gamename[0] == 0) ? "*" : gamename);
+ if ( retVal == MAMERR_NO_SUCH_GAME) {
+ display_suggestions(gamename);
+ return MAMERR_NO_SUCH_GAME;
+ }
+ return retVal;
}
return -1;
diff --git a/src/lib/util/options.c b/src/lib/util/options.c
index 29a8a026a4d..b618b36e04c 100644
--- a/src/lib/util/options.c
+++ b/src/lib/util/options.c
@@ -456,11 +456,32 @@ int options_set_option_callback(core_options *opts, const char *name, void (*cal
of command line arguments
-------------------------------------------------*/
-int options_parse_command_line(core_options *opts, int argc, char **argv, int priority)
+int options_parse_command_line(core_options *opts, int argc, char **argv, int priority, int show_error)
{
int unadorned_index = 0;
int arg;
+ for (arg = 1; arg < argc; arg++)
+ {
+ const char *optionname;
+ options_data *data;
+ int is_unadorned;
+ /* determine the entry name to search for */
+ is_unadorned = (argv[arg][0] != '-');
+ if (!is_unadorned)
+ optionname = &argv[arg][1];
+ else
+ optionname = OPTION_UNADORNED(unadorned_index);
+
+ /* find our entry */
+ data = find_entry_data(opts, optionname, TRUE);
+ if (data == NULL) continue;
+ if ((data->flags & OPTION_COMMAND) != 0) {
+ // in case of any command force show error to TRUE
+ show_error = TRUE;
+ break;
+ }
+ }
/* loop over commands, looking for options */
for (arg = 1; arg < argc; arg++)
{
@@ -479,6 +500,7 @@ int options_parse_command_line(core_options *opts, int argc, char **argv, int pr
data = find_entry_data(opts, optionname, TRUE);
if (data == NULL)
{
+ if (!show_error) continue;
message(opts, OPTMSG_ERROR, "Error: unknown option: %s\n", argv[arg]);
return 1;
}
diff --git a/src/lib/util/options.h b/src/lib/util/options.h
index f54853506e8..0350b16bdb6 100644
--- a/src/lib/util/options.h
+++ b/src/lib/util/options.h
@@ -169,7 +169,7 @@ int options_set_option_callback(core_options *opts, const char *name, void (*cal
/* ----- option data extraction ----- */
/* parse option data from a command line */
-int options_parse_command_line(core_options *opts, int argc, char **argv, int priority);
+int options_parse_command_line(core_options *opts, int argc, char **argv, int priority, int show_error);
/* set option value and execute callback call */
int options_force_option_callback(core_options *opts, const char *optionname, const char *newval, int priority);