[Scummvm-cvs-logs] SF.net SVN: scummvm:[39671] scummvm/trunk/engines/sci

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Mar 24 18:42:12 CET 2009


Revision: 39671
          http://scummvm.svn.sourceforge.net/scummvm/?rev=39671&view=rev
Author:   fingolfin
Date:     2009-03-24 17:42:12 +0000 (Tue, 24 Mar 2009)

Log Message:
-----------
SCI: Rewrote vocabulary code to use a Common::HashMap<String,ResultWord>

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/game.cpp
    scummvm/trunk/engines/sci/engine/grammar.cpp
    scummvm/trunk/engines/sci/engine/kstring.cpp
    scummvm/trunk/engines/sci/engine/savegame.cpp
    scummvm/trunk/engines/sci/engine/script.cpp
    scummvm/trunk/engines/sci/engine/scriptconsole.cpp
    scummvm/trunk/engines/sci/engine/scriptdebug.cpp
    scummvm/trunk/engines/sci/engine/state.cpp
    scummvm/trunk/engines/sci/engine/state.h
    scummvm/trunk/engines/sci/scicore/vocabulary.cpp
    scummvm/trunk/engines/sci/scicore/vocabulary.h

Modified: scummvm/trunk/engines/sci/engine/game.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/game.cpp	2009-03-24 17:41:46 UTC (rev 39670)
+++ scummvm/trunk/engines/sci/engine/game.cpp	2009-03-24 17:42:12 UTC (rev 39671)
@@ -48,7 +48,7 @@
 
 	sciprintf("Initializing vocabulary\n");
 
-	if ((s->resmgr->_sciVersion < SCI_VERSION_01_VGA) && (s->parser_words = vocab_get_words(s->resmgr, &(s->parser_words_nr)))) {
+	if ((s->resmgr->_sciVersion < SCI_VERSION_01_VGA) && vocab_get_words(s->resmgr, s->_parserWords)) {
 		vocab_get_suffixes(s->resmgr, s->_parserSuffixes);
 		if ((s->parser_branches = vocab_get_branches(s->resmgr, &(s->parser_branches_nr))))
 			// Now build a GNF grammar out of this
@@ -76,12 +76,10 @@
 static void _free_vocabulary(EngineState *s) {
 	sciprintf("Freeing vocabulary\n");
 
-	if (s->parser_words) {
-		vocab_free_words(s->parser_words, s->parser_words_nr);
-		vocab_free_suffixes(s->resmgr, s->_parserSuffixes);
-		vocab_free_branches(s->parser_branches);
-		vocab_free_rule_list(s->parser_rules);
-	}
+	s->_parserWords.clear();
+	vocab_free_suffixes(s->resmgr, s->_parserSuffixes);
+	vocab_free_branches(s->parser_branches);
+	vocab_free_rule_list(s->parser_rules);
 
 	s->_selectorNames.clear();
 	vocabulary_free_knames(s->kernel_names);

Modified: scummvm/trunk/engines/sci/engine/grammar.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/grammar.cpp	2009-03-24 17:41:46 UTC (rev 39670)
+++ scummvm/trunk/engines/sci/engine/grammar.cpp	2009-03-24 17:42:12 UTC (rev 39671)
@@ -203,15 +203,15 @@
 
 	dep = rule->data[rule->first_special];
 
-	if (((dep & TOKEN_TERMINAL_CLASS) && ((dep & 0xffff) & input.w_class)) ||
-			((dep & TOKEN_TERMINAL_GROUP) && ((dep & 0xffff) & input.group))) {
+	if (((dep & TOKEN_TERMINAL_CLASS) && ((dep & 0xffff) & input._class)) ||
+			((dep & TOKEN_TERMINAL_GROUP) && ((dep & 0xffff) & input._group))) {
 		parse_rule_t *retval = (parse_rule_t*)sci_malloc(sizeof(int) * (4 + rule->length));
 		++_allocd_rules;
 		retval->id = rule->id;
 		retval->specials_nr = rule->specials_nr - 1;
 		retval->length = rule->length;
 		memcpy(retval->data, rule->data, sizeof(int) * retval->length);
-		retval->data[rule->first_special] = TOKEN_STUFFING_WORD | input.group;
+		retval->data[rule->first_special] = TOKEN_STUFFING_WORD | input._group;
 		retval->first_special = 0;
 
 		if (retval->specials_nr) { // find first special, if it exists

Modified: scummvm/trunk/engines/sci/engine/kstring.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kstring.cpp	2009-03-24 17:41:46 UTC (rev 39670)
+++ scummvm/trunk/engines/sci/engine/kstring.cpp	2009-03-24 17:42:12 UTC (rev 39671)
@@ -253,13 +253,10 @@
 		return s->r_acc;
 	}
 
-	int res = vocab_tokenize_string(words, string,
-	                                s->parser_words, s->parser_words_nr,
-	                                s->_parserSuffixes,
-	                                &error);
+	bool res = vocab_tokenize_string(words, string, s->_parserWords, s->_parserSuffixes, &error);
 	s->parser_valid = 0; /* not valid */
 
-	if (res == 0 && !words.empty()) {
+	if (res && !words.empty()) {
 
 		int syntax_fail = 0;
 
@@ -271,7 +268,7 @@
 			SCIkdebug(SCIkPARSER, "Parsed to the following blocks:\n", 0);
 
 			for (ResultWordList::const_iterator i = words.begin(); i != words.end(); ++i)
-				SCIkdebug(SCIkPARSER, "   Type[%04x] Group[%04x]\n", i->w_class, i->group);
+				SCIkdebug(SCIkPARSER, "   Type[%04x] Group[%04x]\n", i->_class, i->_group);
 		}
 
 		if (vocab_build_parse_tree(&(s->parser_nodes[0]), words, s->parser_branches,

Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp	2009-03-24 17:41:46 UTC (rev 39670)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2009-03-24 17:42:12 UTC (rev 39671)
@@ -894,8 +894,7 @@
 
 	// static parser information:
 	retval->parser_rules = s->parser_rules;
-	retval->parser_words_nr = s->parser_words_nr;
-	retval->parser_words = s->parser_words;
+	retval->_parserWords = s->_parserWords;
 	retval->_parserSuffixes = s->_parserSuffixes;
 	retval->parser_branches_nr = s->parser_branches_nr;
 	retval->parser_branches = s->parser_branches;

Modified: scummvm/trunk/engines/sci/engine/script.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/script.cpp	2009-03-24 17:41:46 UTC (rev 39670)
+++ scummvm/trunk/engines/sci/engine/script.cpp	2009-03-24 17:42:12 UTC (rev 39671)
@@ -330,15 +330,14 @@
 	int objectctr[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 	unsigned int _seeker = 0;
 	Resource *script = resmgr->findResource(kResourceTypeScript, res_no, 0);
-	word_t **words;
-	int word_count;
+	WordMap words;
 
 	if (!script) {
 		sciprintf("Script not found!\n");
 		return;
 	}
 
-	words = vocab_get_words(resmgr, &word_count);
+	vocab_get_words(resmgr, words);
 
 	while (_seeker < script->size) {
 		int objtype = (int16)READ_LE_UINT16(script->data + _seeker);
@@ -349,7 +348,6 @@
 			sciprintf("End of script object (#0) encountered.\n");
 			sciprintf("Classes: %i, Objects: %i, Export: %i,\n Var: %i (all base 10)",
 			          objectctr[6], objectctr[1], objectctr[7], objectctr[10]);
-			vocab_free_words(words, word_count);
 			return;
 		}
 
@@ -424,7 +422,7 @@
 					}
 				} else {
 					nextitem = nextitem << 8 | script->data [seeker++];
-					sciprintf("%s[%03x] ", vocab_get_any_group_word(nextitem, words, word_count), nextitem);
+					sciprintf("%s[%03x] ", vocab_get_any_group_word(nextitem, words), nextitem);
 				}
 			}
 			sciprintf("\n");

Modified: scummvm/trunk/engines/sci/engine/scriptconsole.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/scriptconsole.cpp	2009-03-24 17:41:46 UTC (rev 39670)
+++ scummvm/trunk/engines/sci/engine/scriptconsole.cpp	2009-03-24 17:42:12 UTC (rev 39671)
@@ -689,21 +689,21 @@
 }
 
 static int c_list_words(EngineState *s) {
-	word_t **words;
-	int words_nr;
-	int i;
+	WordMap words;
 
-	words = vocab_get_words(s->resmgr, &words_nr);
+	vocab_get_words(s->resmgr, words);
 
-	if (!words) {
+	if (words.empty()) {
 		sciprintf("No vocabulary.\n");
 		return 1;
 	}
 
-	for (i = 0; i < words_nr; i++)
-		sciprintf("%4d: %03x [%03x] %s\n", i, words[i]->w_class, words[i]->group, words[i]->word);
+	int j = 0;
+	for (WordMap::iterator i = words.begin(); i != words.end(); ++i) {
+		sciprintf("%4d: %03x [%03x] %s\n", j, i->_value._class, i->_value._group, i->_key.c_str());
+		j++;
+	}
 
-	vocab_free_words(words, words_nr);
 	return 0;
 }
 

Modified: scummvm/trunk/engines/sci/engine/scriptdebug.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-03-24 17:41:46 UTC (rev 39670)
+++ scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-03-24 17:42:12 UTC (rev 39671)
@@ -802,11 +802,11 @@
 			if (openb)
 				*openb = 0; // remove them and the rest
 
-			result = vocab_lookup_word(token, strlen(token), s->parser_words, s->parser_words_nr, s->_parserSuffixes);
+			result = vocab_lookup_word(token, strlen(token), s->_parserWords, s->_parserSuffixes);
 
-			if (result.w_class != -1) {
+			if (result._class != -1) {
 				s->parser_nodes[i].type = 0;
-				s->parser_nodes[i].content.value = result.group;
+				s->parser_nodes[i].content.value = result._group;
 			} else { // group name was specified directly?
 				int val = strtol(token, NULL, 0);
 				if (val) {
@@ -1032,9 +1032,8 @@
 
 	string = cmd_params[0].str;
 	sciprintf("Parsing '%s'\n", string);
-	int res = vocab_tokenize_string(words, string, s->parser_words, s->parser_words_nr,
-	                                s->_parserSuffixes, &error);
-	if (res == 0&& !words.empty()) {
+	bool res = vocab_tokenize_string(words, string, s->_parserWords, s->_parserSuffixes, &error);
+	if (res && !words.empty()) {
 		int syntax_fail = 0;
 
 		vocab_synonymize_tokens(words, s->_synonyms);
@@ -1042,7 +1041,7 @@
 		sciprintf("Parsed to the following blocks:\n");
 
 		for (ResultWordList::const_iterator i = words.begin(); i != words.end(); ++i)
-			sciprintf("   Type[%04x] Group[%04x]\n", i->w_class, i->group);
+			sciprintf("   Type[%04x] Group[%04x]\n", i->_class, i->_group);
 
 		if (vocab_gnf_parse(&(s->parser_nodes[0]), words, s->parser_branches, s->parser_rules, 1))
 			syntax_fail = 1; // Building a tree failed
@@ -2390,24 +2389,21 @@
 }
 
 int c_dump_words(EngineState *s) {
-	int i;
-
 	if (!s) {
 		sciprintf("Not in debug state\n");
 		return 1;
 	}
 
-	if (!s->parser_words) {
+	if (s->_parserWords.empty()) {
 		sciprintf("No words.\n");
 		return 0;
 	}
 
-	for (i = 0; i < s->parser_words_nr; i++) {
-		word_t *word = s->parser_words[i];
-		sciprintf("%s: C %03x G %03x\n", word->word, word->w_class, word->group);
-	}
-	sciprintf("%d words\n", s->parser_words_nr);
+	for (WordMap::iterator i = s->_parserWords.begin(); i != s->_parserWords.end(); ++i)
+		sciprintf("%s: C %03x G %03x\n", i->_key.c_str(), i->_value._class, i->_value._group);
 
+	sciprintf("%d words\n", s->_parserWords.size());
+
 	return 0;
 }
 

Modified: scummvm/trunk/engines/sci/engine/state.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/state.cpp	2009-03-24 17:41:46 UTC (rev 39670)
+++ scummvm/trunk/engines/sci/engine/state.cpp	2009-03-24 17:42:12 UTC (rev 39671)
@@ -142,8 +142,6 @@
 	debug_mode = 0;
 	sys_strings_segment = 0;
 	sys_strings = 0;
-	parser_words = 0;
-	parser_words_nr = 0;
 	parser_branches = 0;
 	parser_rules = 0;
 	parser_branches_nr = 0;

Modified: scummvm/trunk/engines/sci/engine/state.h
===================================================================
--- scummvm/trunk/engines/sci/engine/state.h	2009-03-24 17:41:46 UTC (rev 39670)
+++ scummvm/trunk/engines/sci/engine/state.h	2009-03-24 17:42:12 UTC (rev 39671)
@@ -249,8 +249,7 @@
 	SegmentId string_frag_segment;
 
 	/* Parser data: */
-	word_t **parser_words;
-	int parser_words_nr;
+	WordMap _parserWords;
 	SuffixList _parserSuffixes;
 	parse_tree_branch_t *parser_branches;
 	parse_rule_list_t *parser_rules; /* GNF rules used in the parser algorithm */

Modified: scummvm/trunk/engines/sci/scicore/vocabulary.cpp
===================================================================
--- scummvm/trunk/engines/sci/scicore/vocabulary.cpp	2009-03-24 17:41:46 UTC (rev 39670)
+++ scummvm/trunk/engines/sci/scicore/vocabulary.cpp	2009-03-24 17:42:12 UTC (rev 39671)
@@ -63,11 +63,8 @@
                              ""
                             };
 */
-int _vocab_cmp_words(const void *word1, const void *word2) {
-	return scumm_stricmp((*((word_t **) word1))->word, (*((word_t **)word2))->word);
-}
 
-word_t **vocab_get_words(ResourceManager *resmgr, int *word_counter) {
+bool vocab_get_words(ResourceManager *resmgr, WordMap &words) {
 
 	char currentword[256] = ""; // They're not going to use words longer than 255 ;-)
 	int currentwordpos = 0;
@@ -86,7 +83,7 @@
 
 	if (!resource) {
 		warning("SCI1: Could not find a main vocabulary");
-		return NULL; // NOT critical: SCI1 games and some demos don't have one!
+		return false; // NOT critical: SCI1 games and some demos don't have one!
 	}
 
 	unsigned int seeker;
@@ -97,19 +94,15 @@
 
 	if (resource->size < seeker) {
 		fprintf(stderr, "Invalid main vocabulary encountered: Too small\n");
-		return NULL;
+		return false;
 		// Now this ought to be critical, but it'll just cause parse() and said() not to work
 	}
 
-	int counter = 0;
-	word_t **words;
-	words = (word_t **)sci_malloc(sizeof(word_t *));
+	words.clear();
 
 	while (seeker < resource->size) {
 		byte c;
 
-		words = (word_t**)sci_realloc(words, (counter + 1) * sizeof(word_t *));
-
 		currentwordpos = resource->data[seeker++]; // Parts of previous words may be re-used
 
 		if (vocab_version == 1) {
@@ -120,8 +113,8 @@
 			}
 			if (seeker == resource->size) {
 				warning("SCI1: Vocabulary not usable, disabling");
-				vocab_free_words(words, counter);
-				return NULL;
+				words.clear();
+				return false;
 			}
 		} else {
 			do {
@@ -132,45 +125,33 @@
 
 		currentword[currentwordpos] = 0;
 
-		words[counter] = (word_t*)sci_malloc(sizeof(word_t) + currentwordpos);
-		// Allocate more memory, so that the word fits into the structure
-
-		strcpy(&(words[counter]->word[0]), &(currentword[0])); // Copy the word
-
 		// Now decode class and group:
 		c = resource->data[seeker + 1];
-		words[counter]->w_class = ((resource->data[seeker]) << 4) | ((c & 0xf0) >> 4);
-		words[counter]->group = (resource->data[seeker + 2]) | ((c & 0x0f) << 8);
+		ResultWord newWord;
+		newWord._class = ((resource->data[seeker]) << 4) | ((c & 0xf0) >> 4);
+		newWord._group = (resource->data[seeker + 2]) | ((c & 0x0f) << 8);
 
+		// Add the word to the list
+		words[currentword] = newWord;
+
 		seeker += 3;
-		++counter;
 	}
 
-	*word_counter = counter;
 
-	qsort(words, counter, sizeof(word_t *), _vocab_cmp_words); // Sort entries
+// FIXME: Sort the list.
+// Or even switch it to a hashmap?
+//	qsort(words, counter, sizeof(word_t *), _vocab_cmp_words); // Sort entries
 
-	return words;
+	return true;
 }
 
-void vocab_free_words(word_t **words, int words_nr) {
-	int i;
-
-	for (i = 0; i < words_nr; i++)
-		free(words[i]);
-
-	free(words);
-}
-
-const char *vocab_get_any_group_word(int group, word_t **words, int words_nr) {
-	int i;
-
+const char *vocab_get_any_group_word(int group, const WordMap &words) {
 	if (group == VOCAB_MAGIC_NUMBER_GROUP)
 		return "{number}";
 
-	for (i = 0; i < words_nr; i++)
-		if (words[i]->group == group)
-			return words[i]->word;
+	for (WordMap::const_iterator i = words.begin(); i != words.end(); ++i)
+		if (i->_value._group == group)
+			return i->_key.c_str();
 
 	return "{invalid}";
 }
@@ -261,29 +242,23 @@
 }
 
 
-ResultWord vocab_lookup_word(char *word, int word_len, word_t **words, int words_nr,
-	const SuffixList &suffixes) {
-	word_t *tempword = (word_t*)sci_malloc(sizeof(word_t) + word_len + 256);
-	// 256: For suffixes. Should suffice.
-	word_t **dict_word;
-	char *tester;
-	int word_len_tmp;
+ResultWord vocab_lookup_word(char *word, int word_len, const WordMap &words, const SuffixList &suffixes) {
+	Common::String tempword(word, word_len);
 
-	strncpy(&(tempword->word[0]), word, word_len);
-	tempword->word[word_len] = 0;
+	// Remove all dashes from tempword
+	for (uint i = 0; i < tempword.size(); ) {
+		if (tempword[i] == '-')
+			tempword.deleteChar(i);
+		else
+			++i;
+	}
 
-	word_len_tmp = word_len;
-	while ((tester = strchr(tempword->word, '-')))
-		memmove(tester, tester + 1, (tempword->word + word_len_tmp--) - tester);
+	// Look it up:
+	WordMap::iterator dict_word = words.find(tempword);
 
-	dict_word = (word_t **)bsearch(&tempword, words, words_nr, sizeof(word_t *), _vocab_cmp_words);
-
-	if (dict_word) {
-		free(tempword);
-
-		ResultWord tmp = { (*dict_word)->w_class, (*dict_word)->group };
-
-		return tmp;
+	// Match found? Return it!
+	if (dict_word != words.end()) {
+		return dict_word->_value;
 	}
 
 	// Now try all suffixes
@@ -294,18 +269,18 @@
 			// Offset of the start of the suffix
 
 			if (scumm_strnicmp(suffix->alt_suffix, word + suff_index, suffix->alt_suffix_length) == 0) { // Suffix matched!
-				strncpy(&(tempword->word[0]), word, word_len);
-				tempword->word[suff_index] = 0; // Terminate word at suffix start position...
-				strncat(&(tempword->word[0]), suffix->word_suffix, suffix->word_suffix_length); // ...and append "correct" suffix
+				// Terminate word at suffix start position...:
+				Common::String tempword2(word, MIN(word_len, suff_index));
 
-				dict_word = (word_t**)bsearch(&tempword, words, words_nr, sizeof(word_t *), _vocab_cmp_words);
+				// ...and append "correct" suffix
+				tempword2 += Common::String(suffix->word_suffix, suffix->word_suffix_length);
 
-				if ((dict_word) && ((*dict_word)->w_class & suffix->class_mask)) { // Found it?
-					free(tempword);
+				dict_word = words.find(tempword2);
 
+				if ((dict_word != words.end()) && (dict_word->_value._class & suffix->class_mask)) { // Found it?
 					// Use suffix class
-					ResultWord tmp = { suffix->result_class, (*dict_word)->group };
-
+					ResultWord tmp = dict_word->_value;
+					tmp._class = suffix->result_class;
 					return tmp;
 				}
 			}
@@ -313,21 +288,13 @@
 
 	// No match so far? Check if it's a number.
 
-	strncpy(&(tempword->word[0]), word, word_len);
-	tempword->word[word_len] = 0;
-
-	word_len_tmp = word_len;
-	while ((tester = strchr(tempword->word, '-')))
-		memmove(tester, tester + 1, (tempword->word + word_len--) - tester);
-
 	ResultWord retval = { -1, -1 };
-	if ((strtol(&(tempword->word[0]), &tester, 10) >= 0) && (*tester == '\0')) { // Do we have a complete number here?
+	char *tester;
+	if ((strtol(tempword.c_str(), &tester, 10) >= 0) && (*tester == '\0')) { // Do we have a complete number here?
 		ResultWord tmp = { VOCAB_CLASS_NUMBER, VOCAB_MAGIC_NUMBER_GROUP };
 		retval = tmp;
 	}
 
-	free(tempword);
-
 	return retval;
 }
 
@@ -339,7 +306,7 @@
 
 		if (nextitem < 0xf0) {
 			nextitem = nextitem << 8 | *addr++;
-			sciprintf(" %s[%03x]", vocab_get_any_group_word(nextitem, s->parser_words, s->parser_words_nr), nextitem);
+			sciprintf(" %s[%03x]", vocab_get_any_group_word(nextitem, s->_parserWords), nextitem);
 
 			nextitem = 42; // Make sure that group 0xff doesn't abort
 		} else switch (nextitem) {
@@ -396,13 +363,13 @@
 	{0x000, 0x180} // number
 };
 
-int vocab_build_simple_parse_tree(parse_tree_node_t *nodes, result_word_t *words, int words_nr) {
+int vocab_build_simple_parse_tree(parse_tree_node_t *nodes, WordMap &words) {
 	int i, length, pos = 0;
 
-	for (i = 0; i < words_nr; ++i) {
-		if (words[i].w_class != VOCAB_CLASS_ANYWORD) {
-			nodes[pos].type = words[i].w_class;
-			nodes[pos].content.value = words[i].group;
+	for (i = 0; i < words.size(); ++i) {
+		if (words[i]._class != VOCAB_CLASS_ANYWORD) {
+			nodes[pos].type = words[i]._class;
+			nodes[pos].content.value = words[i]._group;
 			pos += 2; // Link information is filled in below
 		}
 	}
@@ -477,7 +444,7 @@
 }
 #endif
 
-int vocab_tokenize_string(ResultWordList &retval, char *sentence, word_t **words, int words_nr,
+bool vocab_tokenize_string(ResultWordList &retval, char *sentence, const WordMap &words,
 	const SuffixList &suffixes, char **error) {
 	char *lastword = sentence;
 	int pos_in_sentence = 0;
@@ -499,14 +466,14 @@
 			if (wordlen) { // Finished a word?
 
 				ResultWord lookup_result =
-				    vocab_lookup_word(lastword, wordlen, words, words_nr, suffixes);
+				    vocab_lookup_word(lastword, wordlen, words, suffixes);
 				// Look it up
 
-				if (lookup_result.w_class == -1) { // Not found?
+				if (lookup_result._class == -1) { // Not found?
 					*error = (char *)sci_calloc(wordlen + 1, 1);
 					strncpy(*error, lastword, wordlen); // Set the offending word
 					retval.clear();
-					return 1; // And return with error
+					return false; // And return with error
 				}
 
 				// Copy into list
@@ -519,7 +486,7 @@
 
 	} while (c); // Until terminator is hit
 
-	return 0;
+	return true;
 }
 
 void _vocab_recursive_ptree_dump_treelike(parse_tree_node_t *nodes, int nr, int prevnr) {
@@ -604,8 +571,8 @@
 
 	for (ResultWordList::iterator i = words.begin(); i != words.end(); ++i)
 		for (SynonymList::const_iterator sync = synonyms.begin(); sync != synonyms.end(); ++sync)
-			if (i->group == sync->replaceant)
-				i->group = sync->replacement;
+			if (i->_group == sync->replaceant)
+				i->_group = sync->replacement;
 }
 
 } // End of namespace Sci

Modified: scummvm/trunk/engines/sci/scicore/vocabulary.h
===================================================================
--- scummvm/trunk/engines/sci/scicore/vocabulary.h	2009-03-24 17:41:46 UTC (rev 39670)
+++ scummvm/trunk/engines/sci/scicore/vocabulary.h	2009-03-24 17:42:12 UTC (rev 39671)
@@ -27,6 +27,8 @@
 #define SCI_SCICORE_VOCABULARY_H
 
 #include "common/str.h"
+#include "common/hashmap.h"
+#include "common/hash-str.h"
 #include "common/list.h"
 
 #include "sci/scicore/versions.h"
@@ -115,17 +117,13 @@
 #define SAID_LONG(x) ((x) << 8)
 
 struct ResultWord {
-	int w_class; /* Word class */
-	int group; /* Word group */
+	int _class; /* Word class */
+	int _group; /* Word group */
 };
 
 typedef Common::List<ResultWord> ResultWordList;
 
-struct word_t {
-	int w_class; /* Word class */
-	int group; /* Word group */
-	char word[1]; /* The actual word */
-};
+typedef Common::HashMap<Common::String, ResultWord, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> WordMap;
 
 
 struct parse_rule_t {
@@ -210,7 +208,6 @@
 void vocabulary_free_opcodes(opcode *opcodes);
 /* Frees a previously allocated list of opcodes
 ** Parameters: (opcode *) opcodes: Opcodes to free
-** Returns   : (void)
 */
 
 /**
@@ -225,23 +222,15 @@
 void vocabulary_free_knames(char** names);
 
 
+/**
+ * Gets all words from the main vocabulary.
+ * @param resmr		The resource manager to read from
+ * @param words		A list of all words
+ * @return true on success, false on failure
+ */
+bool vocab_get_words(ResourceManager *resmgr, WordMap &words);
 
-word_t **vocab_get_words(ResourceManager *resmgr, int *word_counter);
-/* Gets all words from the main vocabulary
-** Parameters: (ResourceManager *) resmr: The resource manager to read from
-**             (int *) word_counter: The int which the number of words is stored in
-** Returns   : (word_t **): A list of all words, dynamically allocated
-*/
 
-
-void vocab_free_words(word_t **words, int words_nr);
-/* Frees memory allocated by vocab_get_words
-** Parameters: (word_t **) words: The words to free
-**             (int) words_nr: Number of words in the structure
-** Returns   : (void)
-*/
-
-
 bool vocab_get_suffixes(ResourceManager *resmgr, SuffixList &suffixes);
 /* Loads all suffixes from the suffix vocabulary.
 ** Parameters: (ResourceManager*) resmgr: Resource manager the resources are
@@ -253,7 +242,6 @@
 /* Frees all suffixes in the given list.
 ** Parameters: (ResourceManager *) resmgr: The resource manager to free from
 **             (SuffixList) suffixes: The suffixes to free
-** Returns   : (void)
 */
 
 parse_tree_branch_t *vocab_get_branches(ResourceManager *resmgr, int *branches_nr);
@@ -272,27 +260,25 @@
 */
 
 ResultWord vocab_lookup_word(char *word, int word_len,
-	word_t **words, int words_nr, const SuffixList &suffixes);
+	const WordMap &words, const SuffixList &suffixes);
 /* Looks up a single word in the words and suffixes list
 ** Parameters: (char *) word: Pointer to the word to look up
 **             (int) word_len: Length of the word to look up
-**             (word_t **) words: List of words
-**             (int) words_nr: Number of elements in 'words'
+**             (const WordMap &) words: List of words
 **             (SuffixList) suffixes: List of suffixes
 ** Returns   : (const ResultWordList &) A list containing 1 or 0 words
 */
 
 
-int vocab_tokenize_string(ResultWordList &retval, char *sentence,
-	word_t **words, int words_nr, const SuffixList &suffixes, char **error);
+bool vocab_tokenize_string(ResultWordList &retval, char *sentence,
+	const WordMap &words, const SuffixList &suffixes, char **error);
 /* Tokenizes a string and compiles it into word_ts.
 ** Parameters: (char *) sentence: The sentence to examine
-**             (word_t **) words: The words to scan for
-**             (int) words_nr: Number of words to scan for
+**             (const WordMap &) words: The words to scan for
 **             (SuffixList) suffixes: suffixes to scan for
 **             (char **) error: Points to a malloc'd copy of the offending text or to NULL on error
 **             (ResultWordList) retval: A list of word_ts containing the result, or NULL.
-** Returns   : 0 on success, 1 if an error occurred
+** Returns   : true on success, false on failure
 ** On error, NULL is returned. If *error is NULL, the sentence did not contain any useful words;
 ** if not, *error points to a malloc'd copy of the offending word.
 ** The returned list may contain anywords.
@@ -315,7 +301,6 @@
 void vocab_free_rule_list(parse_rule_list_t *rule_list);
 /* Frees a parser rule list as returned by vocab_build_gnf()
 ** Parameters: (parse_rule_list_t *) rule_list: The rule list to free
-** Returns   : (void)
 */
 
 
@@ -337,7 +322,6 @@
 /* Prints a parse tree
 ** Parameters: (const char *) tree_name: Name of the tree to dump (free-form)
 **             (parse_tree_node_t *) nodes: The nodes containing the parse tree
-** Returns   : (void)
 */
 
 
@@ -351,13 +335,12 @@
 ** Returns   : (int) 1 on a match, 0 otherwise
 */
 
-const char *vocab_get_any_group_word(int group, word_t **words, int words_nr);
-/* Gets any word from the specified group.
-** Parameters: (int) group: Group number.
-**             (word_t **) words: List of words
-**             (int) words_nr: Count of words in the list.
-** For debugging only.
-*/
+/**
+ * Gets any word from the specified group. For debugging only.
+ * @param group		Group number
+ * @param words		List of words
+ */
+const char *vocab_get_any_group_word(int group, const WordMap &words);
 
 
 void vocab_decypher_said_block(EngineState *s, byte *pos);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list