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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sun Mar 8 09:17:43 CET 2009


Revision: 39214
          http://scummvm.svn.sourceforge.net/scummvm/?rev=39214&view=rev
Author:   fingolfin
Date:     2009-03-08 08:17:43 +0000 (Sun, 08 Mar 2009)

Log Message:
-----------
SCI: Changed suffix list to be stored as a Common::List; also fixed spelling: suffices -> suffixes

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/game.cpp
    scummvm/trunk/engines/sci/engine/kstring.cpp
    scummvm/trunk/engines/sci/engine/savegame.cfsml
    scummvm/trunk/engines/sci/engine/savegame.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-08 08:17:18 UTC (rev 39213)
+++ scummvm/trunk/engines/sci/engine/game.cpp	2009-03-08 08:17:43 UTC (rev 39214)
@@ -49,7 +49,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)))) {
-		s->parser_suffices = vocab_get_suffices(s->resmgr, &(s->parser_suffices_nr));
+		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
 			s->parser_rules = vocab_build_gnf(s->parser_branches, s->parser_branches_nr);
@@ -78,7 +78,7 @@
 
 	if (s->parser_words) {
 		vocab_free_words(s->parser_words, s->parser_words_nr);
-		vocab_free_suffices(s->resmgr, s->parser_suffices, s->parser_suffices_nr);
+		vocab_free_suffixes(s->resmgr, s->_parserSuffixes);
 		vocab_free_branches(s->parser_branches);
 		vocab_free_rule_list(s->parser_rules);
 	}

Modified: scummvm/trunk/engines/sci/engine/kstring.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kstring.cpp	2009-03-08 08:17:18 UTC (rev 39213)
+++ scummvm/trunk/engines/sci/engine/kstring.cpp	2009-03-08 08:17:43 UTC (rev 39214)
@@ -270,7 +270,7 @@
 
 	words = vocab_tokenize_string(string, &words_nr,
 	                              s->parser_words, s->parser_words_nr,
-	                              s->parser_suffices, s->parser_suffices_nr,
+	                              s->_parserSuffixes,
 	                              &error);
 	s->parser_valid = 0; /* not valid */
 

Modified: scummvm/trunk/engines/sci/engine/savegame.cfsml
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cfsml	2009-03-08 08:17:18 UTC (rev 39213)
+++ scummvm/trunk/engines/sci/engine/savegame.cfsml	2009-03-08 08:17:43 UTC (rev 39214)
@@ -1146,8 +1146,7 @@
 	retval->parser_rules = s->parser_rules;
 	retval->parser_words_nr = s->parser_words_nr;
 	retval->parser_words = s->parser_words;
-	retval->parser_suffices_nr = s->parser_suffices_nr;
-	retval->parser_suffices = s->parser_suffices;
+	retval->_parserSuffixes = s->_parserSuffixes;
 	retval->parser_branches_nr = s->parser_branches_nr;
 	retval->parser_branches = s->parser_branches;
 

Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp	2009-03-08 08:17:18 UTC (rev 39213)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2009-03-08 08:17:43 UTC (rev 39214)
@@ -5306,8 +5306,7 @@
 	retval->parser_rules = s->parser_rules;
 	retval->parser_words_nr = s->parser_words_nr;
 	retval->parser_words = s->parser_words;
-	retval->parser_suffices_nr = s->parser_suffices_nr;
-	retval->parser_suffices = s->parser_suffices;
+	retval->_parserSuffixes = s->_parserSuffixes;
 	retval->parser_branches_nr = s->parser_branches_nr;
 	retval->parser_branches = s->parser_branches;
 
@@ -5383,7 +5382,7 @@
 		}
 	}
 // End of auto-generated CFSML data reader code
-#line 1195 "engines/sci/engine/savegame.cfsml"
+#line 1194 "engines/sci/engine/savegame.cfsml"
 
 	if (read_eof)
 		return false;

Modified: scummvm/trunk/engines/sci/engine/scriptconsole.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/scriptconsole.cpp	2009-03-08 08:17:18 UTC (rev 39213)
+++ scummvm/trunk/engines/sci/engine/scriptconsole.cpp	2009-03-08 08:17:43 UTC (rev 39214)
@@ -707,31 +707,27 @@
 	return 0;
 }
 
-int c_list_suffices(EngineState *s) {
-	suffix_t **suffices;
-	int suffices_nr;
-	int i;
+int c_list_suffixes(EngineState *s) {
+	SuffixList suffixes;
 	char word_buf[256], alt_buf[256];
 
-	suffices = vocab_get_suffices(s->resmgr, &suffices_nr);
-
-	if (!suffices) {
+	if (!vocab_get_suffixes(s->resmgr, suffixes)) {
 		sciprintf("No suffix vocabulary.\n");
 		return 1;
 	}
 
-	for (i = 0; i < suffices_nr; i++) {
-		suffix_t *suf = suffices[i];
-
+	int i = 0;
+	for (SuffixList::const_iterator suf = suffixes.begin(); suf != suffixes.end(); ++suf) {
 		strncpy(word_buf, suf->word_suffix, suf->word_suffix_length);
 		word_buf[suf->word_suffix_length] = 0;
 		strncpy(alt_buf, suf->alt_suffix, suf->alt_suffix_length);
 		alt_buf[suf->alt_suffix_length] = 0;
 
 		sciprintf("%4d: (%03x) -%12s  =>  -%12s (%03x)\n", i, suf->class_mask, word_buf, alt_buf, suf->result_class);
+		++i;
 	}
 
-	vocab_free_suffices(s->resmgr, suffices, suffices_nr);
+	vocab_free_suffixes(s->resmgr, suffixes);
 
 	return 0;
 }
@@ -829,7 +825,7 @@
 				return c_kernelnames(s);
 			else if (!strcmp("suffixes", cmd_params[0].str) || !strcmp("suffices", cmd_params[0].str) || !strcmp("sufficos", cmd_params[0].str))
 				// sufficos: Accusative Plural of 'suffix'
-				return c_list_suffices(s);
+				return c_list_suffixes(s);
 			else if (!strcmp("words", cmd_params[0].str))
 				return c_list_words(s);
 			else if (strcmp("restypes", cmd_params[0].str) == 0) {

Modified: scummvm/trunk/engines/sci/engine/scriptdebug.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-03-08 08:17:18 UTC (rev 39213)
+++ scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-03-08 08:17:43 UTC (rev 39214)
@@ -791,7 +791,7 @@
 			if (openb)
 				*openb = 0; // remove them and the rest
 
-			result = vocab_lookup_word(token, strlen(token), s->parser_words, s->parser_words_nr, s->parser_suffices, s->parser_suffices_nr);
+			result = vocab_lookup_word(token, strlen(token), s->parser_words, s->parser_words_nr, s->_parserSuffixes);
 
 			if (result) {
 				s->parser_nodes[i].type = 0;
@@ -1026,7 +1026,7 @@
 	string = cmd_params[0].str;
 	sciprintf("Parsing '%s'\n", string);
 	words = vocab_tokenize_string(string, &words_nr, s->parser_words, s->parser_words_nr,
-	                              s->parser_suffices, s->parser_suffices_nr, &error);
+	                              s->_parserSuffixes, &error);
 	if (words) {
 		int i, syntax_fail = 0;
 

Modified: scummvm/trunk/engines/sci/engine/state.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/state.cpp	2009-03-08 08:17:18 UTC (rev 39213)
+++ scummvm/trunk/engines/sci/engine/state.cpp	2009-03-08 08:17:43 UTC (rev 39214)
@@ -145,8 +145,6 @@
 	sys_strings = 0;
 	parser_words = 0;
 	parser_words_nr = 0;
-	parser_suffices = 0;
-	parser_suffices_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-08 08:17:18 UTC (rev 39213)
+++ scummvm/trunk/engines/sci/engine/state.h	2009-03-08 08:17:43 UTC (rev 39214)
@@ -254,8 +254,7 @@
 	/* Parser data: */
 	word_t **parser_words;
 	int parser_words_nr;
-	suffix_t **parser_suffices;
-	int parser_suffices_nr;
+	SuffixList _parserSuffixes;
 	parse_tree_branch_t *parser_branches;
 	parse_rule_list_t *parser_rules; /* GNF rules used in the parser algorithm */
 	int parser_branches_nr;

Modified: scummvm/trunk/engines/sci/scicore/vocabulary.cpp
===================================================================
--- scummvm/trunk/engines/sci/scicore/vocabulary.cpp	2009-03-08 08:17:18 UTC (rev 39213)
+++ scummvm/trunk/engines/sci/scicore/vocabulary.cpp	2009-03-08 08:17:43 UTC (rev 39214)
@@ -154,63 +154,46 @@
 	return "{invalid}";
 }
 
-suffix_t **vocab_get_suffices(ResourceManager *resmgr, int *suffices_nr) {
-	int counter = 0;
-	suffix_t **suffices;
+bool vocab_get_suffixes(ResourceManager *resmgr, SuffixList &suffixes) {
 	Resource *resource = resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_SUFFIX_VOCAB, 1);
 	unsigned int seeker = 1;
 
 	if (!resource) {
-		fprintf(stderr, "Could not find suffix vocabulary!\n");
-		return NULL; // Not critical
+		warning("Could not find suffix vocabulary");
+		return false; // Not critical
 	}
 
-	suffices = (suffix_t**)sci_malloc(sizeof(suffix_t *));
-
 	while ((seeker < resource->size - 1) && (resource->data[seeker + 1] != 0xff)) {
-		char *alt_suffix = (char *) resource->data + seeker;
-		int alt_len = strlen(alt_suffix);
-		char *word_suffix;
-		int word_len;
+		suffix_t suffix;
 
-		suffices = (suffix_t**)sci_realloc(suffices, sizeof(suffix_t *) * (counter + 1));
+		suffix.alt_suffix = (char *)resource->data + seeker;
+		suffix.alt_suffix_length = strlen(suffix.alt_suffix);
+		seeker += suffix.alt_suffix_length + 1; // Hit end of string
 
-		seeker += alt_len + 1; // Hit end of string
-		word_suffix = (char *)resource->data + seeker + 3; // Beginning of next string +1 (ignore '*')
-		word_len = strlen(word_suffix);
+		suffix.class_mask = (int16)READ_BE_UINT16(resource->data + seeker);
+		seeker += 2;
 
-		suffices[counter] = (suffix_t *)sci_malloc(sizeof(suffix_t));
-		// allocate enough memory to store the strings
+		// Beginning of next string - skip leading '*'
+		seeker++;
 
-		suffices[counter]->word_suffix = word_suffix;
-		suffices[counter]->alt_suffix = alt_suffix;
+		suffix.word_suffix = (char *)resource->data + seeker;
+		suffix.word_suffix_length = strlen(suffix.word_suffix);
+		seeker += suffix.word_suffix_length + 1;
 
-		suffices[counter]->alt_suffix_length = alt_len;
-		suffices[counter]->word_suffix_length = word_len;
-		suffices[counter]->class_mask = (int16)READ_BE_UINT16(resource->data + seeker);
-
-		seeker += word_len + 4;
-		suffices[counter]->result_class = (int16)READ_BE_UINT16(resource->data + seeker);
+		suffix.result_class = (int16)READ_BE_UINT16(resource->data + seeker);
 		seeker += 3; // Next entry
 
-		++counter;
+		suffixes.push_back(suffix);
 	}
 
-	*suffices_nr = counter;
-
-	return suffices;
+	return true;
 }
 
-void vocab_free_suffices(ResourceManager *resmgr, suffix_t **suffices, int suffices_nr) {
-	int i;
-
+void vocab_free_suffixes(ResourceManager *resmgr, SuffixList &suffixes) {
 	resmgr->unlockResource(resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_SUFFIX_VOCAB, 0),
 	                     VOCAB_RESOURCE_SUFFIX_VOCAB, kResourceTypeVocab);
 
-	for (i = 0; i < suffices_nr; i++)
-		free(suffices[i]);
-
-	free(suffices);
+	suffixes.clear();
 }
 
 void vocab_free_branches(parse_tree_branch_t *parser_branches) {
@@ -258,13 +241,13 @@
 
 
 result_word_t *vocab_lookup_word(char *word, int word_len, word_t **words, int words_nr,
-	suffix_t **suffices, int suffices_nr) {
+	const SuffixList &suffixes) {
 	word_t *tempword = (word_t*)sci_malloc(sizeof(word_t) + word_len + 256);
-	// 256: For suffices. Should suffice.
+	// 256: For suffixes. Should suffice.
 	word_t **dict_word;
 	result_word_t *retval;
 	char *tester;
-	int i, word_len_tmp;
+	int word_len_tmp;
 
 	strncpy(&(tempword->word[0]), word, word_len);
 	tempword->word[word_len] = 0;
@@ -286,24 +269,24 @@
 		return retval;
 	}
 
-	// Now try all suffices
-	for (i = 0; i < suffices_nr; i++)
-		if (suffices[i]->alt_suffix_length <= word_len) {
+	// Now try all suffixes
+	for (SuffixList::const_iterator suffix = suffixes.begin(); suffix != suffixes.end(); ++suffix)
+		if (suffix->alt_suffix_length <= word_len) {
 
-			int suff_index = word_len - suffices[i]->alt_suffix_length;
+			int suff_index = word_len - suffix->alt_suffix_length;
 			// Offset of the start of the suffix
 
-			if (scumm_strnicmp(suffices[i]->alt_suffix, word + suff_index, suffices[i]->alt_suffix_length) == 0) { // Suffix matched!
+			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]), suffices[i]->word_suffix, suffices[i]->word_suffix_length); // ...and append "correct" suffix
+				strncat(&(tempword->word[0]), suffix->word_suffix, suffix->word_suffix_length); // ...and append "correct" suffix
 
 				dict_word = (word_t**)bsearch(&tempword, words, words_nr, sizeof(word_t *), _vocab_cmp_words);
 
-				if ((dict_word) && ((*dict_word)->w_class & suffices[i]->class_mask)) { // Found it?
+				if ((dict_word) && ((*dict_word)->w_class & suffix->class_mask)) { // Found it?
 					free(tempword);
 
-					retval->w_class = suffices[i]->result_class; // Use suffix class
+					retval->w_class = suffix->result_class; // Use suffix class
 					retval->group = (*dict_word)->group;
 
 					return retval;
@@ -482,7 +465,7 @@
 #endif
 
 result_word_t *vocab_tokenize_string(char *sentence, int *result_nr, word_t **words, int words_nr,
-	suffix_t **suffices, int suffices_nr, char **error) {
+	const SuffixList &suffixes, char **error) {
 	char *lastword = sentence;
 	int pos_in_sentence = 0;
 	char c;
@@ -508,7 +491,7 @@
 			if (wordlen) { // Finished a word?
 
 				lookup_result =
-				    vocab_lookup_word(lastword, wordlen, words, words_nr, suffices, suffices_nr);
+				    vocab_lookup_word(lastword, wordlen, words, words_nr, suffixes);
 				// Look it up
 
 				if (!lookup_result) { // Not found?

Modified: scummvm/trunk/engines/sci/scicore/vocabulary.h
===================================================================
--- scummvm/trunk/engines/sci/scicore/vocabulary.h	2009-03-08 08:17:18 UTC (rev 39213)
+++ scummvm/trunk/engines/sci/scicore/vocabulary.h	2009-03-08 08:17:43 UTC (rev 39214)
@@ -27,6 +27,7 @@
 #define SCI_SCICORE_VOCABULARY_H
 
 #include "common/str.h"
+#include "common/list.h"
 
 #include "sci/scicore/versions.h"
 
@@ -149,7 +150,9 @@
 
 };
 
+typedef Common::List<suffix_t> SuffixList;
 
+
 struct result_word_t {
 
 	int w_class; /* Word class */
@@ -239,8 +242,7 @@
 */
 
 
-void
-vocab_free_words(word_t **words, int words_nr);
+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
@@ -248,19 +250,17 @@
 */
 
 
-suffix_t **vocab_get_suffices(ResourceManager *resmgr, int *suffices_nr);
-/* Gets all suffixes from the suffix vocabulary
+bool vocab_get_suffixes(ResourceManager *resmgr, SuffixList &suffixes);
+/* Loads all suffixes from the suffix vocabulary.
 ** Parameters: (ResourceManager*) resmgr: Resource manager the resources are
 **                               read from
-**             (int *) suffices_nr: The variable to store the number of suffices in
-** Returns   : (suffix_t **): A list of suffixes
+** Returns   : true on success, false on failure
 */
 
-void vocab_free_suffices(ResourceManager *resmgr, suffix_t **suffices, int suffices_nr);
-/* Frees suffices_nr suffices
+void vocab_free_suffixes(ResourceManager *resmgr, SuffixList &suffixes);
+/* Frees all suffixes in the given list.
 ** Parameters: (ResourceManager *) resmgr: The resource manager to free from
-**             (suffix_t **) suffices: The suffixes to free
-**             (int) suffices_nr: Number of entrie sin suffices
+**             (SuffixList) suffixes: The suffixes to free
 ** Returns   : (void)
 */
 
@@ -280,28 +280,26 @@
 */
 
 result_word_t *vocab_lookup_word(char *word, int word_len,
-	word_t **words, int words_nr, suffix_t **suffices, int suffices_nr);
+	word_t **words, int words_nr, 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'
-**             (suffix_t **) suffices: List of suffices
-**             (int) suffices_nr: Number of entries in 'suffices'
+**             (SuffixList) suffixes: List of suffixes
 ** Returns   : (result_word_t *) A malloc'd result_word_t, or NULL if the word
 ** could not be found.
 */
 
 
 result_word_t *vocab_tokenize_string(char *sentence, int *result_nr,
-	word_t **words, int words_nr, suffix_t **suffices, int suffices_nr, char **error);
+	word_t **words, int words_nr, const SuffixList &suffixes, char **error);
 /* Tokenizes a string and compiles it into word_ts.
 ** Parameters: (char *) sentence: The sentence to examine
 **             (int *) result_nr: The variable to store the resulting number of words in
 **             (word_t **) words: The words to scan for
 **             (int) words_nr: Number of words to scan for
-**             (suffix_t **) suffices: suffixes to scan for
-**             (int) suffices_nr: Number of suffices 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
 ** Returns   : (word_t *): A list of word_ts containing the result, or NULL.
 ** On error, NULL is returned. If *error is NULL, the sentence did not contain any useful words;


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