src/emu/softlist.c
| r13403 | r13404 | |
| 1666 | 1666 | { |
| 1667 | 1667 | } |
| 1668 | 1668 | |
| 1669 | | static DEVICE_VALIDITY_CHECK( software_list ) |
| 1669 | void validate_softlists(emu_options &options) |
| 1670 | 1670 | { |
| 1671 | | software_list_config *swlist = (software_list_config *)downcast<const legacy_device_base *>(device)->inline_config(); |
| 1672 | | int error = FALSE; |
| 1673 | | softlist_map names; |
| 1674 | | softlist_map descriptions; |
| 1671 | driver_enumerator drivlist(options); |
| 1672 | // first determine the maximum number of lists we might encounter |
| 1673 | int list_count = 0; |
| 1674 | while (drivlist.next()) |
| 1675 | for (const device_t *dev = drivlist.config().devicelist().first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext()) |
| 1676 | { |
| 1677 | software_list_config *swlist = (software_list_config *)downcast<const legacy_device_base *>(dev)->inline_config(); |
| 1675 | 1678 | |
| 1676 | | enum { NAME_LEN_PARENT = 8, NAME_LEN_CLONE = 16 }; |
| 1679 | for (int listnum = 0; listnum < DEVINFO_STR_SWLIST_MAX - DEVINFO_STR_SWLIST_0; listnum++) |
| 1680 | if (swlist->list_name[listnum] && *swlist->list_name[listnum] && swlist->list_type == SOFTWARE_LIST_ORIGINAL_SYSTEM) |
| 1681 | list_count++; |
| 1682 | } |
| 1677 | 1683 | |
| 1678 | | for (int i = 0; i < DEVINFO_STR_SWLIST_MAX - DEVINFO_STR_SWLIST_0; i++) |
| 1684 | // allocate a list |
| 1685 | astring *lists = global_alloc_array(astring, list_count); |
| 1686 | bool error = FALSE; |
| 1687 | if (list_count) |
| 1679 | 1688 | { |
| 1680 | | if (swlist->list_name[i]) |
| 1689 | drivlist.reset(); |
| 1690 | list_count = 0; |
| 1691 | while (drivlist.next()) |
| 1692 | for (const device_t *dev = drivlist.config().devicelist().first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext()) |
| 1681 | 1693 | { |
| 1682 | | software_list *list = software_list_open(options, swlist->list_name[i], FALSE, NULL); |
| 1694 | software_list_config *swlist = (software_list_config *)downcast<const legacy_device_base *>(dev)->inline_config(); |
| 1695 | softlist_map names; |
| 1696 | softlist_map descriptions; |
| 1683 | 1697 | |
| 1684 | | /* if no .xml list is found, then return (this happens e.g. if you moved/renamed the xml list) */ |
| 1685 | | if (list == NULL) |
| 1686 | | return FALSE; |
| 1698 | enum { NAME_LEN_PARENT = 8, NAME_LEN_CLONE = 16 }; |
| 1687 | 1699 | |
| 1688 | | for (software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo)) |
| 1700 | for (int i = 0; i < DEVINFO_STR_SWLIST_MAX - DEVINFO_STR_SWLIST_0; i++) |
| 1689 | 1701 | { |
| 1690 | | const char *s; |
| 1691 | | int is_clone = 0; |
| 1702 | if (swlist->list_name[i]) |
| 1703 | { |
| 1704 | software_list *list = software_list_open(options, swlist->list_name[i], FALSE, NULL); |
| 1705 | if ( list ) |
| 1706 | { |
| 1707 | /* Verify if we have encountered this list before */ |
| 1708 | bool seen_before = false; |
| 1709 | for (int seen_index = 0; seen_index < list_count && !seen_before; seen_index++) |
| 1710 | if (lists[seen_index] == swlist->list_name[i]) |
| 1711 | seen_before = true; |
| 1692 | 1712 | |
| 1693 | | /* First, check if the xml got corrupted: */ |
| 1713 | if (!seen_before) |
| 1714 | { |
| 1715 | lists[list_count++] = swlist->list_name[i]; |
| 1716 | mame_printf_error("Validating : %s\n",swlist->list_name[i]); |
| 1717 | for (software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo)) |
| 1718 | { |
| 1719 | const char *s; |
| 1720 | int is_clone = 0; |
| 1694 | 1721 | |
| 1695 | | /* Did we lost any description? */ |
| 1696 | | if (swinfo->longname == NULL) |
| 1697 | | { |
| 1698 | | mame_printf_error("%s: %s has no description\n", swlist->list_name[i], swinfo->shortname); |
| 1699 | | return TRUE; |
| 1700 | | } |
| 1722 | /* First, check if the xml got corrupted: */ |
| 1701 | 1723 | |
| 1702 | | /* Did we lost any year? */ |
| 1703 | | if (swinfo->year == NULL) |
| 1704 | | { |
| 1705 | | mame_printf_error("%s: %s has no year\n", swlist->list_name[i], swinfo->shortname); |
| 1706 | | return TRUE; |
| 1707 | | } |
| 1724 | /* Did we lost any description? */ |
| 1725 | if (swinfo->longname == NULL) |
| 1726 | { |
| 1727 | mame_printf_error("%s: %s has no description\n", swlist->list_name[i], swinfo->shortname); |
| 1728 | error = TRUE; break; |
| 1729 | } |
| 1708 | 1730 | |
| 1709 | | /* Did we lost any publisher? */ |
| 1710 | | if (swinfo->publisher == NULL) |
| 1711 | | { |
| 1712 | | mame_printf_error("%s: %s has no publisher\n", swlist->list_name[i], swinfo->shortname); |
| 1713 | | return TRUE; |
| 1714 | | } |
| 1731 | /* Did we lost any year? */ |
| 1732 | if (swinfo->year == NULL) |
| 1733 | { |
| 1734 | mame_printf_error("%s: %s has no year\n", swlist->list_name[i], swinfo->shortname); |
| 1735 | error = TRUE; break; |
| 1736 | } |
| 1715 | 1737 | |
| 1716 | | /* Second, since the xml is fine, run additional checks: */ |
| 1738 | /* Did we lost any publisher? */ |
| 1739 | if (swinfo->publisher == NULL) |
| 1740 | { |
| 1741 | mame_printf_error("%s: %s has no publisher\n", swlist->list_name[i], swinfo->shortname); |
| 1742 | error = TRUE; break; |
| 1743 | } |
| 1717 | 1744 | |
| 1718 | | /* check for duplicate names */ |
| 1719 | | if (names.add(swinfo->shortname, swinfo, FALSE) == TMERR_DUPLICATE) |
| 1720 | | { |
| 1721 | | software_info *match = names.find(swinfo->shortname); |
| 1722 | | mame_printf_error("%s: %s is a duplicate name (%s)\n", swlist->list_name[i], swinfo->shortname, match->shortname); |
| 1723 | | error = TRUE; |
| 1724 | | } |
| 1745 | /* Second, since the xml is fine, run additional checks: */ |
| 1725 | 1746 | |
| 1726 | | /* check for duplicate descriptions */ |
| 1727 | | if (descriptions.add(swinfo->longname, swinfo, FALSE) == TMERR_DUPLICATE) |
| 1728 | | { |
| 1729 | | software_info *match = names.find(swinfo->shortname); |
| 1730 | | mame_printf_error("%s: %s is a duplicate description (%s)\n", swlist->list_name[i], swinfo->longname, match->longname); |
| 1731 | | error = TRUE; |
| 1732 | | } |
| 1747 | /* check for duplicate names */ |
| 1748 | if (names.add(swinfo->shortname, swinfo, FALSE) == TMERR_DUPLICATE) |
| 1749 | { |
| 1750 | software_info *match = names.find(swinfo->shortname); |
| 1751 | mame_printf_error("%s: %s is a duplicate name (%s)\n", swlist->list_name[i], swinfo->shortname, match->shortname); |
| 1752 | error = TRUE; |
| 1753 | } |
| 1733 | 1754 | |
| 1734 | | if (swinfo->parentname != NULL) |
| 1735 | | { |
| 1736 | | is_clone = 1; |
| 1755 | /* check for duplicate descriptions */ |
| 1756 | if (descriptions.add(swinfo->longname, swinfo, FALSE) == TMERR_DUPLICATE) |
| 1757 | { |
| 1758 | software_info *match = names.find(swinfo->shortname); |
| 1759 | mame_printf_error("%s: %s is a duplicate description (%s)\n", swlist->list_name[i], swinfo->longname, match->longname); |
| 1760 | error = TRUE; |
| 1761 | } |
| 1737 | 1762 | |
| 1738 | | if (strcmp(swinfo->parentname, swinfo->shortname) == 0) |
| 1739 | | { |
| 1740 | | mame_printf_error("%s: %s is set as a clone of itself\n", swlist->list_name[i], swinfo->shortname); |
| 1741 | | error = TRUE; |
| 1742 | | break; |
| 1743 | | } |
| 1763 | if (swinfo->parentname != NULL) |
| 1764 | { |
| 1765 | is_clone = 1; |
| 1744 | 1766 | |
| 1745 | | /* make sure the parent exists */ |
| 1746 | | software_info *swinfo2 = software_list_find(list, swinfo->parentname, NULL ); |
| 1767 | if (strcmp(swinfo->parentname, swinfo->shortname) == 0) |
| 1768 | { |
| 1769 | mame_printf_error("%s: %s is set as a clone of itself\n", swlist->list_name[i], swinfo->shortname); |
| 1770 | error = TRUE; |
| 1771 | break; |
| 1772 | } |
| 1747 | 1773 | |
| 1748 | | if (!swinfo2) |
| 1749 | | { |
| 1750 | | mame_printf_error("%s: parent '%s' software for '%s' not found\n", swlist->list_name[i], swinfo->parentname, swinfo->shortname); |
| 1751 | | error = TRUE; |
| 1752 | | } |
| 1753 | | else |
| 1754 | | { |
| 1755 | | if (swinfo2->parentname != NULL) |
| 1756 | | { |
| 1757 | | mame_printf_error("%s: %s is a clone of a clone\n", swlist->list_name[i], swinfo->shortname); |
| 1758 | | error = TRUE; |
| 1759 | | } |
| 1760 | | } |
| 1761 | | } |
| 1774 | /* make sure the parent exists */ |
| 1775 | software_info *swinfo2 = software_list_find(list, swinfo->parentname, NULL ); |
| 1762 | 1776 | |
| 1763 | | /* make sure the driver name is 8 chars or less */ |
| 1764 | | if ((is_clone && strlen(swinfo->shortname) > NAME_LEN_CLONE) || ((!is_clone) && strlen(swinfo->shortname) > NAME_LEN_PARENT)) |
| 1765 | | { |
| 1766 | | mame_printf_error("%s: %s %s driver name must be %d characters or less\n", swlist->list_name[i], swinfo->shortname, |
| 1767 | | is_clone ? "clone" : "parent", is_clone ? NAME_LEN_CLONE : NAME_LEN_PARENT); |
| 1768 | | error = TRUE; |
| 1769 | | } |
| 1777 | if (!swinfo2) |
| 1778 | { |
| 1779 | mame_printf_error("%s: parent '%s' software for '%s' not found\n", swlist->list_name[i], swinfo->parentname, swinfo->shortname); |
| 1780 | error = TRUE; |
| 1781 | } |
| 1782 | else |
| 1783 | { |
| 1784 | if (swinfo2->parentname != NULL) |
| 1785 | { |
| 1786 | mame_printf_error("%s: %s is a clone of a clone\n", swlist->list_name[i], swinfo->shortname); |
| 1787 | error = TRUE; |
| 1788 | } |
| 1789 | } |
| 1790 | } |
| 1770 | 1791 | |
| 1771 | | /* make sure the year is only digits, '?' or '+' */ |
| 1772 | | for (s = swinfo->year; *s; s++) |
| 1773 | | if (!isdigit((UINT8)*s) && *s != '?' && *s != '+') |
| 1774 | | { |
| 1775 | | mame_printf_error("%s: %s has an invalid year '%s'\n", swlist->list_name[i], swinfo->shortname, swinfo->year); |
| 1776 | | error = TRUE; |
| 1777 | | break; |
| 1778 | | } |
| 1792 | /* make sure the driver name is 8 chars or less */ |
| 1793 | if ((is_clone && strlen(swinfo->shortname) > NAME_LEN_CLONE) || ((!is_clone) && strlen(swinfo->shortname) > NAME_LEN_PARENT)) |
| 1794 | { |
| 1795 | mame_printf_error("%s: %s %s driver name must be %d characters or less\n", swlist->list_name[i], swinfo->shortname, |
| 1796 | is_clone ? "clone" : "parent", is_clone ? NAME_LEN_CLONE : NAME_LEN_PARENT); |
| 1797 | error = TRUE; |
| 1798 | } |
| 1779 | 1799 | |
| 1780 | | for (software_part *swpart = software_find_part(swinfo, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart)) |
| 1781 | | { |
| 1782 | | if (swpart->interface_ == NULL) |
| 1783 | | { |
| 1784 | | mame_printf_error("%s: %s has a part (%s) without interface\n", swlist->list_name[i], swinfo->shortname, swpart->name); |
| 1785 | | error = TRUE; |
| 1786 | | } |
| 1800 | /* make sure the year is only digits, '?' or '+' */ |
| 1801 | for (s = swinfo->year; *s; s++) |
| 1802 | if (!isdigit((UINT8)*s) && *s != '?' && *s != '+') |
| 1803 | { |
| 1804 | mame_printf_error("%s: %s has an invalid year '%s'\n", swlist->list_name[i], swinfo->shortname, swinfo->year); |
| 1805 | error = TRUE; |
| 1806 | break; |
| 1807 | } |
| 1787 | 1808 | |
| 1788 | | if (software_find_romdata(swpart, NULL) == NULL) |
| 1789 | | { |
| 1790 | | mame_printf_error("%s: %s has a part (%s) with no data\n", swlist->list_name[i], swinfo->shortname, swpart->name); |
| 1791 | | error = TRUE; |
| 1792 | | } |
| 1809 | for (software_part *swpart = software_find_part(swinfo, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart)) |
| 1810 | { |
| 1811 | if (swpart->interface_ == NULL) |
| 1812 | { |
| 1813 | mame_printf_error("%s: %s has a part (%s) without interface\n", swlist->list_name[i], swinfo->shortname, swpart->name); |
| 1814 | error = TRUE; |
| 1815 | } |
| 1793 | 1816 | |
| 1794 | | for (struct rom_entry *swdata = software_find_romdata(swpart, NULL); swdata != NULL; swdata = software_romdata_next(swdata)) |
| 1795 | | { |
| 1796 | | struct rom_entry *data = swdata; |
| 1817 | if (software_find_romdata(swpart, NULL) == NULL) |
| 1818 | { |
| 1819 | mame_printf_error("%s: %s has a part (%s) with no data\n", swlist->list_name[i], swinfo->shortname, swpart->name); |
| 1820 | error = TRUE; |
| 1821 | } |
| 1797 | 1822 | |
| 1798 | | if (data->_name && data->_hashdata) |
| 1799 | | { |
| 1800 | | const char *str; |
| 1823 | for (struct rom_entry *swdata = software_find_romdata(swpart, NULL); swdata != NULL; swdata = software_romdata_next(swdata)) |
| 1824 | { |
| 1825 | struct rom_entry *data = swdata; |
| 1801 | 1826 | |
| 1802 | | /* make sure it's all lowercase */ |
| 1803 | | for (str = data->_name; *str; str++) |
| 1804 | | if (tolower((UINT8)*str) != *str) |
| 1805 | | { |
| 1806 | | mame_printf_error("%s: %s has upper case ROM name %s\n", swlist->list_name[i], swinfo->shortname, data->_name); |
| 1807 | | error = TRUE; |
| 1808 | | break; |
| 1827 | if (data->_name && data->_hashdata) |
| 1828 | { |
| 1829 | const char *str; |
| 1830 | |
| 1831 | /* make sure it's all lowercase */ |
| 1832 | for (str = data->_name; *str; str++) |
| 1833 | if (tolower((UINT8)*str) != *str) |
| 1834 | { |
| 1835 | mame_printf_error("%s: %s has upper case ROM name %s\n", swlist->list_name[i], swinfo->shortname, data->_name); |
| 1836 | error = TRUE; |
| 1837 | break; |
| 1838 | } |
| 1839 | |
| 1840 | /* make sure the hash is valid */ |
| 1841 | hash_collection hashes; |
| 1842 | if (!hashes.from_internal_string(data->_hashdata)) |
| 1843 | { |
| 1844 | mame_printf_error("%s: %s has rom '%s' with an invalid hash string '%s'\n", swlist->list_name[i], swinfo->shortname, data->_name, data->_hashdata); |
| 1845 | error = TRUE; |
| 1846 | } |
| 1847 | } |
| 1848 | } |
| 1809 | 1849 | } |
| 1810 | | |
| 1811 | | /* make sure the hash is valid */ |
| 1812 | | hash_collection hashes; |
| 1813 | | if (!hashes.from_internal_string(data->_hashdata)) |
| 1814 | | { |
| 1815 | | mame_printf_error("%s: %s has rom '%s' with an invalid hash string '%s'\n", swlist->list_name[i], swinfo->shortname, data->_name, data->_hashdata); |
| 1816 | | error = TRUE; |
| 1817 | 1850 | } |
| 1818 | 1851 | } |
| 1819 | | } |
| 1852 | software_list_close(list); |
| 1853 | } |
| 1820 | 1854 | } |
| 1821 | 1855 | } |
| 1822 | | |
| 1823 | | software_list_close(list); |
| 1824 | 1856 | } |
| 1825 | 1857 | } |
| 1826 | | return error; |
| 1858 | if (error) |
| 1859 | throw emu_fatalerror(MAMERR_FAILED_VALIDITY, "Validity checks failed"); |
| 1827 | 1860 | } |
| 1828 | 1861 | |
| 1829 | 1862 | DEVICE_GET_INFO( software_list ) |
| r13403 | r13404 | |
| 1837 | 1870 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1838 | 1871 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( software_list ); break; |
| 1839 | 1872 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 1840 | | case DEVINFO_FCT_VALIDITY_CHECK: info->p = (void*)DEVICE_VALIDITY_CHECK_NAME( software_list ); break; |
| 1841 | 1873 | |
| 1842 | 1874 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1843 | 1875 | case DEVINFO_STR_NAME: strcpy(info->s, "Software lists"); break; |