aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2012-01-06 11:20:46 +0100
committerWillem Jan Palenstijn2012-01-06 11:22:06 +0100
commit43e2fde7a951d362ab06f20bc043698f0e1e47c3 (patch)
tree737c2d0eb6f9e9156212045c96dcbdb0e94b4a9e
parent41ba2433f57f064f3119b5b5c1247eadb32d5977 (diff)
downloadscummvm-rg350-43e2fde7a951d362ab06f20bc043698f0e1e47c3.tar.gz
scummvm-rg350-43e2fde7a951d362ab06f20bc043698f0e1e47c3.tar.bz2
scummvm-rg350-43e2fde7a951d362ab06f20bc043698f0e1e47c3.zip
AGI: Fix ignoring some exact matches in predictive input
The matcher now always tries an exact match before trying an inexact one. Together with 41ba2433f, this fixes bug #3470080.
-rw-r--r--engines/agi/agi.h2
-rw-r--r--engines/agi/predictive.cpp25
2 files changed, 21 insertions, 6 deletions
diff --git a/engines/agi/agi.h b/engines/agi/agi.h
index e9923aba2e..28403964dd 100644
--- a/engines/agi/agi.h
+++ b/engines/agi/agi.h
@@ -1085,7 +1085,7 @@ private:
void blitTextbox(const char *p, int y, int x, int len);
void eraseTextbox();
void loadDict();
- bool matchWord();
+ bool matchWord(bool onlyExact = false);
// Predictive dialog
// TODO: Move this to a separate class
diff --git a/engines/agi/predictive.cpp b/engines/agi/predictive.cpp
index 56d9190e7f..585a633bb0 100644
--- a/engines/agi/predictive.cpp
+++ b/engines/agi/predictive.cpp
@@ -556,7 +556,7 @@ void AgiEngine::loadDict() {
debug("Time to parse pred.dic: %d, total: %d", time3-time2, time3-time1);
}
-bool AgiEngine::matchWord() {
+bool AgiEngine::matchWord(bool onlyExact) {
// If no text has been entered, then there is no match.
if (_currentCode.empty())
return false;
@@ -565,14 +565,29 @@ bool AgiEngine::matchWord() {
if (_currentCode.size() > MAXWORDLEN)
return false;
- // Perform a binary search on the dictionary to find the first
- // entry that has _currentCode as a prefix.
+ if (!onlyExact) {
+ // First always try an exact match.
+ bool ret = matchWord(true);
+ if (ret)
+ return true;
+ }
+
+ // The entries in the dictionary consist of a code, a space, and then
+ // a space-separated list of words matching this code.
+ // To exactly match a code, we therefore match the code plus the trailing
+ // space in the dictionary.
+ Common::String code = _currentCode;
+ if (onlyExact)
+ code += " ";
+
+ // Perform a binary search on the dictionary to find an entry that has
+ // _currentCode as a prefix.
int hi = _predictiveDictLineCount - 1;
int lo = 0;
int line = 0;
while (lo <= hi) {
line = (lo + hi) / 2;
- int cmpVal = strncmp(_predictiveDictLine[line], _currentCode.c_str(), _currentCode.size());
+ int cmpVal = strncmp(_predictiveDictLine[line], code.c_str(), code.size());
if (cmpVal > 0)
hi = line - 1;
else if (cmpVal < 0)
@@ -585,7 +600,7 @@ bool AgiEngine::matchWord() {
_currentWord.clear();
_wordNumber = 0;
- if (0 == strncmp(_predictiveDictLine[line], _currentCode.c_str(), _currentCode.size())) {
+ if (0 == strncmp(_predictiveDictLine[line], code.c_str(), code.size())) {
_predictiveDictActLine = _predictiveDictLine[line];
char tmp[MAXLINELEN];
strncpy(tmp, _predictiveDictActLine, MAXLINELEN);