blob: a73656ea6185b196ea92f51a76f20ea5f57515e9 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 | #include "wordcompletion.h"
#include "engines/agi/agi.h"
#include "osystem_ds.h"
#ifndef DISABLE_AGI
namespace DS {
void findWordCompletions(char* input) {
	int start = 0;
	for (int r = strlen(input) - 1; r>0; r--) {
		if (input[r] == ' ') {
			start = r + 1;
			break;
		}
	}
	char word[32];
	strcpy(word, &input[start]);
	int fchr = word[0] - 'a';
	int len = strlen(word);
	OSystem_DS* system = (OSystem_DS *) g_system;
	system->clearAutoComplete();
	system->setCharactersEntered(strlen(word));
	if (strlen(word) == 0) {
		return;
	}		
	uint8 *wordList = Agi::AgiEngine::getWordsData();
	uint8 *wordListEnd = Agi::AgiEngine::getWordsData() + Agi::AgiEngine::getWordsDataSize();
	/* Get the offset to the first word beginning with the
	 * right character
	 */
	wordList += READ_BE_UINT16(wordList + 2 * fchr);
	char currentWord[32];
	
	while (wordList < wordListEnd) {
		int pos = *wordList++;		// Number of chars to keep from previous word
		if (wordList == wordListEnd)
			break;
		char c;
		do {
			c = *wordList++;
			currentWord[pos++] =  (~c) & 0x7F;
		} while ((c & 0x80) == 0);		// Top bit indicates end of word
		currentWord[pos++] = '\0';
		if (!strncmp(currentWord, word, strlen(word))) {
			system->addAutoComplete(currentWord);
		}
		wordList += 2;	// Skip the two byte word id.
	}
}
}
#endif
 |