Made approx matches code to be used from one place (no whatsnew)

This commit is contained in:
Miodrag Milanovic 2011-06-15 18:35:13 +00:00
parent 9a2b931d6d
commit d7beedfe70
3 changed files with 56 additions and 85 deletions

View File

@ -229,45 +229,8 @@ int cli_frontend::execute(int argc, char **argv)
}
}
if (!found) {
for (device_t *swlists = config.devicelist().first(SOFTWARE_LIST); swlists != NULL; swlists = swlists->typenext())
{
software_list_config *swlist = (software_list_config *)downcast<const legacy_device_base *>(swlists)->inline_config();
for (int i = 0; i < DEVINFO_STR_SWLIST_MAX - DEVINFO_STR_SWLIST_0; i++)
{
if (swlist->list_name[i] && *swlist->list_name[i])
{
software_list *list = software_list_open(m_options, swlist->list_name[i], FALSE, NULL);
if (list)
{
software_info *matches[10] = { 0 };
int softnum;
software_list_parse(list, list->error_proc, NULL);
// get the top 5 approximate matches for the selected device interface (i.e. only carts for cartslot, etc.)
software_list_find_approx_matches(list, m_options.software_name(), ARRAY_LENGTH(matches), matches, NULL);
if (matches[0] != 0)
{
if (swlist->list_type == SOFTWARE_LIST_ORIGINAL_SYSTEM)
mame_printf_error("* Software list \"%s\" (%s) matches: \n", swlist->list_name[i], software_list_get_description(list));
else
mame_printf_error("* Compatible software list \"%s\" (%s) matches: \n", swlist->list_name[i], software_list_get_description(list));
// print them out
for (softnum = 0; softnum < ARRAY_LENGTH(matches); softnum++)
if (matches[softnum] != NULL)
mame_printf_error("%-18s%s\n", matches[softnum]->shortname, matches[softnum]->longname);
mame_printf_error("\n");
}
software_list_close(list);
}
}
}
}
throw emu_fatalerror(MAMERR_FATALERROR, "Software item '%s' can not be found in any list\n",m_options.software_name());
software_display_matches(config.devicelist(),m_options, NULL,m_options.software_name());
throw emu_fatalerror(MAMERR_FATALERROR, "");
}
}
// otherwise just run the game

View File

@ -1320,6 +1320,58 @@ software_part *software_part_next(software_part *part)
return part;
}
/*-------------------------------------------------
software_display_matches
-------------------------------------------------*/
void software_display_matches(const device_list &devlist,emu_options &options, const char *interface ,const char *name)
{
// check if there is at least a software list
if (devlist.first(SOFTWARE_LIST))
{
mame_printf_error("\n\"%s\" approximately matches the following\n"
"supported software items (best match first):\n\n", name);
}
for (device_t *swlists = devlist.first(SOFTWARE_LIST); swlists != NULL; swlists = swlists->typenext())
{
software_list_config *swlist = (software_list_config *)downcast<const legacy_device_base *>(swlists)->inline_config();
for (int i = 0; i < DEVINFO_STR_SWLIST_MAX - DEVINFO_STR_SWLIST_0; i++)
{
if (swlist->list_name[i] && *swlist->list_name[i])
{
software_list *list = software_list_open(options, swlist->list_name[i], FALSE, NULL);
if (list)
{
software_info *matches[10] = { 0 };
int softnum;
software_list_parse(list, list->error_proc, NULL);
// get the top 5 approximate matches for the selected device interface (i.e. only carts for cartslot, etc.)
software_list_find_approx_matches(list, name, ARRAY_LENGTH(matches), matches, interface);
if (matches[0] != 0)
{
if (swlist->list_type == SOFTWARE_LIST_ORIGINAL_SYSTEM)
mame_printf_error("* Software list \"%s\" (%s) matches: \n", swlist->list_name[i], software_list_get_description(list));
else
mame_printf_error("* Compatible software list \"%s\" (%s) matches: \n", swlist->list_name[i], software_list_get_description(list));
// print them out
for (softnum = 0; softnum < ARRAY_LENGTH(matches); softnum++)
if (matches[softnum] != NULL)
mame_printf_error("%-18s%s\n", matches[softnum]->shortname, matches[softnum]->longname);
mame_printf_error("\n");
}
software_list_close(list);
}
}
}
}
}
/*-------------------------------------------------
load_software_part
@ -1463,51 +1515,7 @@ bool load_software_part(device_image_interface *image, const char *path, softwar
// if no match has been found, we suggest similar shortnames
if (software_info_ptr == NULL)
{
// check if there is at least a software list
if (image->device().machine().devicelist().first(SOFTWARE_LIST))
{
mame_printf_error("\n\"%s\" approximately matches the following\n"
"supported software items (best match first):\n\n", swname_bckp);
}
for (device_t *swlists = image->device().machine().devicelist().first(SOFTWARE_LIST); swlists != NULL; swlists = swlists->typenext())
{
software_list_config *swlist = (software_list_config *)downcast<const legacy_device_base *>(swlists)->inline_config();
for (int i = 0; i < DEVINFO_STR_SWLIST_MAX - DEVINFO_STR_SWLIST_0; i++)
{
if (swlist->list_name[i] && *swlist->list_name[i])
{
software_list *list = software_list_open(image->device().machine().options(), swlist->list_name[i], FALSE, NULL);
if (list)
{
software_info *matches[10] = { 0 };
int softnum;
software_list_parse(list, list->error_proc, NULL);
// get the top 5 approximate matches for the selected device interface (i.e. only carts for cartslot, etc.)
software_list_find_approx_matches(list, swname_bckp, ARRAY_LENGTH(matches), matches, image->image_interface());
if (matches[0] != 0)
{
if (swlist->list_type == SOFTWARE_LIST_ORIGINAL_SYSTEM)
mame_printf_error("* Software list \"%s\" (%s) matches: \n", swlist->list_name[i], software_list_get_description(list));
else
mame_printf_error("* Compatible software list \"%s\" (%s) matches: \n", swlist->list_name[i], software_list_get_description(list));
// print them out
for (softnum = 0; softnum < ARRAY_LENGTH(matches); softnum++)
if (matches[softnum] != NULL)
mame_printf_error("%-18s%s\n", matches[softnum]->shortname, matches[softnum]->longname);
mame_printf_error("\n");
}
software_list_close(list);
}
}
}
}
software_display_matches(image->device().machine().devicelist(),image->device().machine().options(), image->image_interface(), swname_bckp);
}
if ( software_part_ptr )

View File

@ -114,7 +114,7 @@ const char *software_part_get_feature(software_part *part, const char *feature_n
bool load_software_part(device_image_interface *image, const char *path, software_info **sw_info, software_part **sw_part, char **full_sw_name);
void software_list_find_approx_matches(software_list *swlist, const char *name, int matches, software_info **list, const char* interface);
void software_display_matches(const device_list &devlist, emu_options &options,const char *interface,const char *swname_bckp);
/*********************************************************************