src/emu/softlist.c
| r10017 | r10018 | |
| 53 | 53 | int rom_entries; |
| 54 | 54 | int current_rom_entry; |
| 55 | 55 | void (*error_proc)(const char *message); |
| 56 | int list_entries; |
| 56 | 57 | }; |
| 57 | 58 | |
| 58 | 59 | |
| r10017 | r10018 | |
| 803 | 804 | |
| 804 | 805 | |
| 805 | 806 | /*------------------------------------------------- |
| 807 | software_list_get_count |
| 808 | -------------------------------------------------*/ |
| 809 | |
| 810 | static int software_list_get_count(software_list *swlist) |
| 811 | { |
| 812 | int count = 0; |
| 813 | |
| 814 | for (software_info *swinfo = software_list_find(swlist, "*", NULL); swinfo != NULL; swinfo = software_list_find(swlist, "*", swinfo)) |
| 815 | count++; |
| 816 | |
| 817 | return count; |
| 818 | } |
| 819 | |
| 820 | |
| 821 | /*------------------------------------------------- |
| 806 | 822 | software_list_parse |
| 807 | 823 | -------------------------------------------------*/ |
| 808 | 824 | |
| r10017 | r10018 | |
| 851 | 867 | XML_ParserFree(swlist->state.parser); |
| 852 | 868 | swlist->state.parser = NULL; |
| 853 | 869 | swlist->current_software_info = swlist->software_info_list; |
| 870 | swlist->list_entries = software_list_get_count(swlist); |
| 854 | 871 | } |
| 855 | 872 | |
| 856 | 873 | |
| r10017 | r10018 | |
| 930 | 947 | |
| 931 | 948 | |
| 932 | 949 | /*------------------------------------------------- |
| 950 | software_list_find_by_number |
| 951 | -------------------------------------------------*/ |
| 952 | |
| 953 | INLINE software_info *software_list_find_by_number(software_list *swlist, int number) |
| 954 | { |
| 955 | int length = swlist->list_entries; |
| 956 | if (number > length) |
| 957 | return NULL; |
| 958 | |
| 959 | software_info *cur_info = software_list_find(swlist, "*", NULL); |
| 960 | |
| 961 | for (int count = 0; count < number; count++) |
| 962 | cur_info = software_list_find(swlist, "*", cur_info); |
| 963 | |
| 964 | return cur_info; |
| 965 | } |
| 966 | |
| 967 | |
| 968 | /*------------------------------------------------- |
| 969 | softlist_penalty_compare (borrowed from driver.c) |
| 970 | -------------------------------------------------*/ |
| 971 | |
| 972 | static int softlist_penalty_compare(const char *source, const char *target) |
| 973 | { |
| 974 | int gaps = 1; |
| 975 | int last = TRUE; |
| 976 | |
| 977 | /* scan the strings */ |
| 978 | for ( ; *source && *target; target++) |
| 979 | { |
| 980 | /* do a case insensitive match */ |
| 981 | int match = (tolower((UINT8)*source) == tolower((UINT8)*target)); |
| 982 | |
| 983 | /* if we matched, advance the source */ |
| 984 | if (match) |
| 985 | source++; |
| 986 | |
| 987 | /* if the match state changed, count gaps */ |
| 988 | if (match != last) |
| 989 | { |
| 990 | last = match; |
| 991 | if (!match) |
| 992 | gaps++; |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | /* penalty if short string does not completely fit in */ |
| 997 | for ( ; *source; source++) |
| 998 | gaps++; |
| 999 | |
| 1000 | /* if we matched perfectly, gaps == 0 */ |
| 1001 | if (gaps == 1 && *source == 0 && *target == 0) |
| 1002 | gaps = 0; |
| 1003 | |
| 1004 | return gaps; |
| 1005 | } |
| 1006 | |
| 1007 | |
| 1008 | /*------------------------------------------------- |
| 1009 | software_list_find_approx_matches |
| 1010 | -------------------------------------------------*/ |
| 1011 | |
| 1012 | void software_list_find_approx_matches(software_list *swlist, const char *name, int matches, software_info **list) |
| 1013 | { |
| 1014 | #undef rand |
| 1015 | |
| 1016 | int matchnum; |
| 1017 | int *penalty; |
| 1018 | |
| 1019 | /* if no name, return */ |
| 1020 | if (name == NULL || name[0] == 0) |
| 1021 | return; |
| 1022 | |
| 1023 | /* allocate some temp memory */ |
| 1024 | penalty = global_alloc_array(int, matches); |
| 1025 | |
| 1026 | /* initialize everyone's states */ |
| 1027 | for (matchnum = 0; matchnum < matches; matchnum++) |
| 1028 | { |
| 1029 | penalty[matchnum] = 9999; |
| 1030 | list[matchnum] = NULL; |
| 1031 | } |
| 1032 | |
| 1033 | for (software_info *swinfo = software_list_find(swlist, "*", NULL); swinfo != NULL; swinfo = software_list_find(swlist, "*", swinfo)) |
| 1034 | { |
| 1035 | int curpenalty, tmp; |
| 1036 | software_info *candidate = swinfo; |
| 1037 | |
| 1038 | /* pick the best match between driver name and description */ |
| 1039 | curpenalty = softlist_penalty_compare(name, candidate->longname); |
| 1040 | tmp = softlist_penalty_compare(name, candidate->shortname); |
| 1041 | curpenalty = MIN(curpenalty, tmp); |
| 1042 | |
| 1043 | /* insert into the sorted table of matches */ |
| 1044 | for (matchnum = matches - 1; matchnum >= 0; matchnum--) |
| 1045 | { |
| 1046 | /* stop if we're worse than the current entry */ |
| 1047 | if (curpenalty >= penalty[matchnum]) |
| 1048 | break; |
| 1049 | |
| 1050 | /* as long as this isn't the last entry, bump this one down */ |
| 1051 | if (matchnum < matches - 1) |
| 1052 | { |
| 1053 | penalty[matchnum + 1] = penalty[matchnum]; |
| 1054 | list[matchnum + 1] = list[matchnum]; |
| 1055 | } |
| 1056 | list[matchnum] = candidate; |
| 1057 | penalty[matchnum] = curpenalty; |
| 1058 | } |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | |
| 1063 | /*------------------------------------------------- |
| 933 | 1064 | software_list_find |
| 934 | 1065 | -------------------------------------------------*/ |
| 935 | 1066 | |
| r10017 | r10018 | |
| 1037 | 1168 | |
| 1038 | 1169 | bool load_software_part(device_image_interface *image, const char *path, software_info **sw_info, software_part **sw_part, char **full_sw_name) |
| 1039 | 1170 | { |
| 1040 | | char *swlist_name, *swname, *swpart; |
| 1171 | char *swlist_name, *swname, *swpart, *swname_bckp; |
| 1041 | 1172 | bool result = false; |
| 1042 | 1173 | software_list *software_list_ptr = NULL; |
| 1043 | 1174 | software_info *software_info_ptr = NULL; |
| r10017 | r10018 | |
| 1048 | 1179 | |
| 1049 | 1180 | /* Split full software name into software list name and short software name */ |
| 1050 | 1181 | software_name_split( image->device().machine, path, &swlist_name, &swname, &swpart ); |
| 1182 | swname_bckp = swname; |
| 1051 | 1183 | |
| 1052 | 1184 | const char *interface = image->image_config().image_interface(); |
| 1053 | 1185 | |
| r10017 | r10018 | |
| 1161 | 1293 | } |
| 1162 | 1294 | } |
| 1163 | 1295 | |
| 1296 | if (software_info_ptr == NULL) |
| 1297 | { |
| 1298 | |
| 1299 | mame_printf_error("\n\"%s\" approximately matches the following\n" |
| 1300 | "supported software items (best match first):\n\n", swname_bckp); |
| 1301 | |
| 1302 | for (device_t *swlists = image->device().machine->m_devicelist.first(SOFTWARE_LIST); swlists != NULL; swlists = swlists->typenext()) |
| 1303 | { |
| 1304 | software_list_config *swlist = (software_list_config *)downcast<const legacy_device_config_base *>(&swlists->baseconfig())->inline_config(); |
| 1305 | |
| 1306 | for (int i = 0; i < DEVINFO_STR_SWLIST_MAX - DEVINFO_STR_SWLIST_0; i++) |
| 1307 | { |
| 1308 | if (swlist->list_name[i] && *swlist->list_name[i] && (swlist->list_type == SOFTWARE_LIST_ORIGINAL_SYSTEM)) |
| 1309 | { |
| 1310 | software_list *list = software_list_open(image->device().machine->options(), swlist->list_name[i], FALSE, NULL); |
| 1311 | |
| 1312 | if (list) |
| 1313 | { |
| 1314 | software_info *matches[5] = { 0 }; |
| 1315 | int softnum; |
| 1316 | |
| 1317 | software_list_parse(list, list->error_proc, NULL); |
| 1318 | mame_printf_error("* Software list \"%s\" matches: \n", software_list_get_description(list)); |
| 1319 | /* get the top 5 approximate matches */ |
| 1320 | software_list_find_approx_matches(list, swname_bckp, ARRAY_LENGTH(matches), matches); |
| 1321 | |
| 1322 | /* print them out */ |
| 1323 | for (softnum = 0; softnum < ARRAY_LENGTH(matches); softnum++) |
| 1324 | if (matches[softnum] != NULL) |
| 1325 | mame_printf_error("%-18s%s\n", matches[softnum]->shortname, matches[softnum]->longname); |
| 1326 | |
| 1327 | mame_printf_error("\n"); |
| 1328 | } |
| 1329 | software_list_close(list); |
| 1330 | } |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | } |
| 1335 | |
| 1164 | 1336 | if ( software_part_ptr ) |
| 1165 | 1337 | { |
| 1166 | 1338 | /* Load the software part */ |