From c2325decb75c5dac5532dcc1533f990338e4d86b Mon Sep 17 00:00:00 2001 From: thrust26 Date: Tue, 10 Oct 2017 14:03:52 +0200 Subject: [PATCH] advanced auto complete added; first letter has to match, following letters have to appear in correct order. examples: - 'twf' finds and completes into 'trapwriteif', - 'g0' finds and completes into 'GRP0' - 'em' finds 'ENAM0'&'ENAM1' and completes into 'ENAM' --- src/common/bspf.hxx | 18 ++++++++++++++++++ src/debugger/CartDebug.cxx | 10 +++++----- src/debugger/Debugger.cxx | 4 ++-- src/debugger/DebuggerParser.cxx | 2 +- src/debugger/gui/PromptWidget.cxx | 4 ++-- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/common/bspf.hxx b/src/common/bspf.hxx index 607c4522b..0a44af7f0 100644 --- a/src/common/bspf.hxx +++ b/src/common/bspf.hxx @@ -189,6 +189,24 @@ namespace BSPF { return findIgnoreCase(s1, s2) != string::npos; } + + inline bool matches(const string& command, const string& in) + { + if(BSPF::startsWithIgnoreCase(command, in.substr(0, 1))) + { + size_t pos = 1; + + for(int j = 1; j < in.size(); j++) + { + int found = BSPF::findIgnoreCase(command, in.substr(j, 1), pos); + if(found == string::npos) + return false; + pos += found + 1; + } + return true; + } + return false; + } } // namespace BSPF #endif diff --git a/src/debugger/CartDebug.cxx b/src/debugger/CartDebug.cxx index da2b9eb76..fc173af0c 100644 --- a/src/debugger/CartDebug.cxx +++ b/src/debugger/CartDebug.cxx @@ -1279,23 +1279,23 @@ void CartDebug::getCompletions(const char* in, StringList& completions) const { // First scan system equates for(uInt16 addr = 0x00; addr <= 0x0F; ++addr) - if(ourTIAMnemonicR[addr] && BSPF::startsWithIgnoreCase(ourTIAMnemonicR[addr], in)) + if(ourTIAMnemonicR[addr] && BSPF::matches(ourTIAMnemonicR[addr], in)) completions.push_back(ourTIAMnemonicR[addr]); for(uInt16 addr = 0x00; addr <= 0x3F; ++addr) - if(ourTIAMnemonicW[addr] && BSPF::startsWithIgnoreCase(ourTIAMnemonicW[addr], in)) + if(ourTIAMnemonicW[addr] && BSPF::matches(ourTIAMnemonicW[addr], in)) completions.push_back(ourTIAMnemonicW[addr]); for(uInt16 addr = 0; addr <= 0x297-0x280; ++addr) - if(ourIOMnemonic[addr] && BSPF::startsWithIgnoreCase(ourIOMnemonic[addr], in)) + if(ourIOMnemonic[addr] && BSPF::matches(ourIOMnemonic[addr], in)) completions.push_back(ourIOMnemonic[addr]); for(uInt16 addr = 0; addr <= 0x7F; ++addr) - if(ourZPMnemonic[addr] && BSPF::startsWithIgnoreCase(ourZPMnemonic[addr], in)) + if(ourZPMnemonic[addr] && BSPF::matches(ourZPMnemonic[addr], in)) completions.push_back(ourZPMnemonic[addr]); // Now scan user-defined labels for(const auto& iter: myUserAddresses) { const char* l = iter.first.c_str(); - if(BSPF::startsWithIgnoreCase(l, in)) + if(BSPF::matches(l, in)) completions.push_back(l); } } diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index de570fbba..fdbb5e3f4 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -707,12 +707,12 @@ void Debugger::getCompletions(const char* in, StringList& list) const for(const auto& iter: myFunctions) { const char* l = iter.first.c_str(); - if(BSPF::startsWithIgnoreCase(l, in)) + if(BSPF::matches(l, in)) list.push_back(l); } for(int i = 0; pseudo_registers[i][0] != 0; ++i) - if(BSPF::startsWithIgnoreCase(pseudo_registers[i][0], in)) + if(BSPF::matches(pseudo_registers[i][0], in)) list.push_back(pseudo_registers[i][0]); } diff --git a/src/debugger/DebuggerParser.cxx b/src/debugger/DebuggerParser.cxx index ffe7a5c43..468314892 100644 --- a/src/debugger/DebuggerParser.cxx +++ b/src/debugger/DebuggerParser.cxx @@ -174,7 +174,7 @@ void DebuggerParser::getCompletions(const char* in, StringList& completions) con // cerr << "Attempting to complete \"" << in << "\"" << endl; for(int i = 0; i < kNumCommands; ++i) { - if(BSPF::startsWithIgnoreCase(commands[i].cmdString.c_str(), in)) + if(BSPF::matches(commands[i].cmdString, in)) completions.push_back(commands[i].cmdString); } } diff --git a/src/debugger/gui/PromptWidget.cxx b/src/debugger/gui/PromptWidget.cxx index 33aa0284a..7c9775681 100644 --- a/src/debugger/gui/PromptWidget.cxx +++ b/src/debugger/gui/PromptWidget.cxx @@ -501,7 +501,7 @@ void PromptWidget::loadConfig() print(PROMPT); // Take care of one-time debugger stuff - // fill the history from the saves breaks, traps and watches commands + // fill the history from the saved breaks, traps and watches commands StringList history; print(instance().debugger().autoExec(&history)); for(uInt32 i = 0; i < history.size(); i++) @@ -922,7 +922,7 @@ string PromptWidget::getCompletionPrefix(const StringList& completions, string p { if(s.length() < prefix.length()) return prefix; // current prefix is the best we're going to get - else if(!BSPF::startsWithIgnoreCase(s, prefix)) + else if(!BSPF::matches(s, prefix)) { prefix.erase(prefix.length()-1); return prefix;