[Scummvm-cvs-logs] scummvm master -> 43e2fde7a951d362ab06f20bc043698f0e1e47c3

wjp wjp at usecode.org
Fri Jan 6 11:23:38 CET 2012


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
43e2fde7a9 AGI: Fix ignoring some exact matches in predictive input


Commit: 43e2fde7a951d362ab06f20bc043698f0e1e47c3
    https://github.com/scummvm/scummvm/commit/43e2fde7a951d362ab06f20bc043698f0e1e47c3
Author: Willem Jan Palenstijn (wjp at usecode.org)
Date: 2012-01-06T02:22:06-08:00

Commit Message:
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.

Changed paths:
    engines/agi/agi.h
    engines/agi/predictive.cpp



diff --git a/engines/agi/agi.h b/engines/agi/agi.h
index e9923ab..2840396 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 56d9190..585a633 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);






More information about the Scummvm-git-logs mailing list