softlist.c: only output best match if a list is present, limit the scan for best match to the devices with the same interface and fixed a corner case with shortname=listname [Miodrag Milanovic]

This commit is contained in:
Fabio Priuli 2011-01-13 15:09:15 +00:00
parent e2925112a4
commit 148ca8dcf9

View File

@ -1009,7 +1009,7 @@ static int softlist_penalty_compare(const char *source, const char *target)
software_list_find_approx_matches software_list_find_approx_matches
-------------------------------------------------*/ -------------------------------------------------*/
void software_list_find_approx_matches(software_list *swlist, const char *name, int matches, software_info **list) void software_list_find_approx_matches(software_list *swlist, const char *name, int matches, software_info **list, const char* interface)
{ {
#undef rand #undef rand
@ -1035,6 +1035,10 @@ void software_list_find_approx_matches(software_list *swlist, const char *name,
int curpenalty, tmp; int curpenalty, tmp;
software_info *candidate = swinfo; software_info *candidate = swinfo;
software_part *part = software_find_part(swinfo, NULL, NULL);
if (!strcmp(interface, part->interface_))
{
/* pick the best match between driver name and description */ /* pick the best match between driver name and description */
curpenalty = softlist_penalty_compare(name, candidate->longname); curpenalty = softlist_penalty_compare(name, candidate->longname);
tmp = softlist_penalty_compare(name, candidate->shortname); tmp = softlist_penalty_compare(name, candidate->shortname);
@ -1057,6 +1061,7 @@ void software_list_find_approx_matches(software_list *swlist, const char *name,
penalty[matchnum] = curpenalty; penalty[matchnum] = curpenalty;
} }
} }
}
/* free our temp memory */ /* free our temp memory */
global_free(penalty); global_free(penalty);
@ -1072,6 +1077,9 @@ software_info *software_list_find(software_list *swlist, const char *look_for, s
if (swlist == NULL) if (swlist == NULL)
return NULL; return NULL;
if (look_for == NULL)
return NULL;
/* If we haven't read in the xml file yet, then do it now */ /* If we haven't read in the xml file yet, then do it now */
if ( ! swlist->software_info_list ) if ( ! swlist->software_info_list )
software_list_parse( swlist, swlist->error_proc, NULL ); software_list_parse( swlist, swlist->error_proc, NULL );
@ -1296,11 +1304,15 @@ 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) if (software_info_ptr == NULL)
{ {
// check if there is at least a software list
if (image->device().machine->m_devicelist.first(SOFTWARE_LIST))
{
mame_printf_error("\n\"%s\" approximately matches the following\n" mame_printf_error("\n\"%s\" approximately matches the following\n"
"supported software items (best match first):\n\n", swname_bckp); "supported software items (best match first):\n\n", swname_bckp);
}
for (device_t *swlists = image->device().machine->m_devicelist.first(SOFTWARE_LIST); swlists != NULL; swlists = swlists->typenext()) for (device_t *swlists = image->device().machine->m_devicelist.first(SOFTWARE_LIST); swlists != NULL; swlists = swlists->typenext())
{ {
@ -1318,22 +1330,25 @@ bool load_software_part(device_image_interface *image, const char *path, softwar
int softnum; int softnum;
software_list_parse(list, list->error_proc, NULL); software_list_parse(list, list->error_proc, NULL);
mame_printf_error("* Software list \"%s\" matches: \n", software_list_get_description(list)); // get the top 5 approximate matches for the selected device interface (i.e. only carts for cartslot, etc.)
/* get the top 5 approximate matches */ software_list_find_approx_matches(list, swname_bckp, ARRAY_LENGTH(matches), matches, image->image_config().image_interface());
software_list_find_approx_matches(list, swname_bckp, ARRAY_LENGTH(matches), matches);
/* print them out */ if (matches[0] != 0)
{
mame_printf_error("* Software list \"%s\" matches: \n", software_list_get_description(list));
// print them out
for (softnum = 0; softnum < ARRAY_LENGTH(matches); softnum++) for (softnum = 0; softnum < ARRAY_LENGTH(matches); softnum++)
if (matches[softnum] != NULL) if (matches[softnum] != NULL)
mame_printf_error("%-18s%s\n", matches[softnum]->shortname, matches[softnum]->longname); mame_printf_error("%-18s%s\n", matches[softnum]->shortname, matches[softnum]->longname);
mame_printf_error("\n"); mame_printf_error("\n");
} }
}
software_list_close(list); software_list_close(list);
} }
} }
} }
} }
if ( software_part_ptr ) if ( software_part_ptr )