| 1828 | } |
| 1829 | |
| 1830 | void MainWindow::equatesAddFile(const QString &fileName) { |
| 1831 | QFile file(fileName); |
| 1832 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
| 1833 | m_equateFiles.removeAll(fileName); |
| 1834 | console(QStringLiteral("[CEmu] Debugger couldn't open this equate file (removed): ") + fileName + "\n", EmuThread::ConsoleErr); |
| 1835 | return; |
| 1836 | } |
| 1837 | |
| 1838 | QTextStream in(&file); |
| 1839 | QString line; |
| 1840 | if (in.readLineInto(&line) && (line.startsWith(QStringLiteral("Segment")) || line.startsWith(QStringLiteral("Section")))) { |
| 1841 | while ((in.readLineInto(&line) && !line.startsWith(QStringLiteral("Label")))); |
| 1842 | if (!in.readLineInto(&line)) { |
| 1843 | return; |
| 1844 | } |
| 1845 | while (in.readLineInto(&line) && !line.isEmpty()) { |
| 1846 | QStringList split = line.split('=', |
| 1847 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) |
| 1848 | Qt::SkipEmptyParts |
| 1849 | #else |
| 1850 | QString::SkipEmptyParts |
| 1851 | #endif |
| 1852 | ); |
| 1853 | equatesAddEquate(split.at(0).simplified(), hex2int(split.at(1).simplified())); |
| 1854 | } |
| 1855 | } else { |
| 1856 | QRegularExpression equatesRegexp(QStringLiteral("^\\h*\\??\\h*([.A-Z_a-z][.\\w]*)\\h*(?::?=|\\h\\.?equ(?!\\d))\\h*([%@$]\\S+|\\d\\S*[boh]?)\\h*(?:;.*)?$"), |
| 1857 | QRegularExpression::CaseInsensitiveOption); |
| 1858 | QRegularExpression typedEquatesRegexp(QStringLiteral("^(.*)_([0-9A-F]{6})\t(.*)$")); |
| 1859 | do { |
| 1860 | QRegularExpressionMatch matches = equatesRegexp.match(line); |
| 1861 | if (matches.hasMatch()) { |
| 1862 | QString addrStr = matches.captured(2); |
| 1863 | int base = 10; |
| 1864 | if (addrStr.startsWith('%')) { |
| 1865 | addrStr.remove(0, 1); |
| 1866 | base = 2; |
| 1867 | } else if (addrStr.startsWith('@')) { |
| 1868 | addrStr.remove(0, 1); |
| 1869 | base = 8; |
| 1870 | } else if (addrStr.startsWith('$')) { |
| 1871 | addrStr.remove(0, 1); |
| 1872 | base = 16; |
| 1873 | } else if (addrStr.endsWith('b', Qt::CaseInsensitive)) { |
| 1874 | addrStr.chop(1); |
| 1875 | base = 2; |
| 1876 | } else if (addrStr.endsWith('o', Qt::CaseInsensitive)) { |
| 1877 | addrStr.chop(1); |
| 1878 | base = 8; |
| 1879 | } else if (addrStr.endsWith('h', Qt::CaseInsensitive)) { |
| 1880 | addrStr.chop(1); |
| 1881 | base = 16; |
| 1882 | } |
| 1883 | equatesAddEquate(matches.captured(1), addrStr.toUInt(Q_NULLPTR, base)); |
| 1884 | continue; |
| 1885 | } |
| 1886 | matches = typedEquatesRegexp.match(line); |
| 1887 | if (matches.hasMatch()) { |