diff options
Diffstat (limited to 'engines/sci/engine')
-rw-r--r-- | engines/sci/engine/game.cpp | 12 | ||||
-rw-r--r-- | engines/sci/engine/grammar.cpp | 6 | ||||
-rw-r--r-- | engines/sci/engine/kstring.cpp | 9 | ||||
-rw-r--r-- | engines/sci/engine/savegame.cpp | 3 | ||||
-rw-r--r-- | engines/sci/engine/script.cpp | 8 | ||||
-rw-r--r-- | engines/sci/engine/scriptconsole.cpp | 16 | ||||
-rw-r--r-- | engines/sci/engine/scriptdebug.cpp | 26 | ||||
-rw-r--r-- | engines/sci/engine/state.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/state.h | 3 |
9 files changed, 35 insertions, 50 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index 97843041ed..304752235b 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -48,7 +48,7 @@ static int _init_vocabulary(EngineState *s) { // initialize vocabulary and relat 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 @@ extern int _allocd_rules; 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); diff --git a/engines/sci/engine/grammar.cpp b/engines/sci/engine/grammar.cpp index e44a02ef30..1d4e800765 100644 --- a/engines/sci/engine/grammar.cpp +++ b/engines/sci/engine/grammar.cpp @@ -203,15 +203,15 @@ static parse_rule_t *_vsatisfy_rule(parse_rule_t *rule, const ResultWord &input) 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 diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index e15315397e..61c7ee6d47 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -253,13 +253,10 @@ reg_t kParse(EngineState *s, int funct_nr, int argc, reg_t *argv) { 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 @@ reg_t kParse(EngineState *s, int funct_nr, int argc, reg_t *argv) { 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, diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index c90b8cf6c8..70024c2437 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -894,8 +894,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { // 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; diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index aabb89122d..70b25d63cb 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -330,15 +330,14 @@ void script_dissect(ResourceManager *resmgr, int res_no, const Common::StringLis 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 @@ void script_dissect(ResourceManager *resmgr, int res_no, const Common::StringLis 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 @@ void script_dissect(ResourceManager *resmgr, int res_no, const Common::StringLis } } 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"); diff --git a/engines/sci/engine/scriptconsole.cpp b/engines/sci/engine/scriptconsole.cpp index e2a1e94826..38acb8458f 100644 --- a/engines/sci/engine/scriptconsole.cpp +++ b/engines/sci/engine/scriptconsole.cpp @@ -689,21 +689,21 @@ static ResourceType parseResourceType(char *resid) { } 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; } diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index 1117d2aca2..e7ef55e4af 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -802,11 +802,11 @@ int c_sim_parse(EngineState *s) { 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 @@ int c_parse(EngineState *s) { 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 @@ int c_parse(EngineState *s) { 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,23 +2389,20 @@ int c_gfx_debuglog(EngineState *s) { } 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; } diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp index c8f44fa7be..5fbfd44899 100644 --- a/engines/sci/engine/state.cpp +++ b/engines/sci/engine/state.cpp @@ -142,8 +142,6 @@ EngineState::EngineState() : _dirseeker(this) { 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; diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h index ef2ddb7912..2a3a6a150c 100644 --- a/engines/sci/engine/state.h +++ b/engines/sci/engine/state.h @@ -249,8 +249,7 @@ public: 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 */ |