From d7beedfe7063f023a7405b433089e6fa27d929f4 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 15 Jun 2011 18:35:13 +0000 Subject: [PATCH] Made approx matches code to be used from one place (no whatsnew) --- src/emu/clifront.c | 41 +------------------ src/emu/softlist.c | 98 +++++++++++++++++++++++++--------------------- src/emu/softlist.h | 2 +- 3 files changed, 56 insertions(+), 85 deletions(-) diff --git a/src/emu/clifront.c b/src/emu/clifront.c index 46d83f526d5..bc182c36f40 100644 --- a/src/emu/clifront.c +++ b/src/emu/clifront.c @@ -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(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 diff --git a/src/emu/softlist.c b/src/emu/softlist.c index e7c286341da..d1f0f5b1d30 100644 --- a/src/emu/softlist.c +++ b/src/emu/softlist.c @@ -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(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(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 ) diff --git a/src/emu/softlist.h b/src/emu/softlist.h index 92ebc2f2b0f..a120fb1b30a 100644 --- a/src/emu/softlist.h +++ b/src/emu/softlist.h @@ -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); /*********************************************************************