aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/sci/engine/game.cpp7
-rw-r--r--engines/sci/engine/kstring.cpp34
-rw-r--r--engines/sci/engine/said.y2
-rw-r--r--engines/sci/engine/scriptdebug.cpp2
-rw-r--r--engines/sci/engine/state.cpp3
-rw-r--r--engines/sci/engine/state.h3
-rw-r--r--engines/sci/scicore/vocabulary.cpp12
-rw-r--r--engines/sci/scicore/vocabulary.h14
8 files changed, 22 insertions, 55 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp
index 3a0d02b4cf..97843041ed 100644
--- a/engines/sci/engine/game.cpp
+++ b/engines/sci/engine/game.cpp
@@ -589,8 +589,7 @@ int game_init(EngineState *s) {
s->parser_valid = 0; // Invalidate parser
s->parser_event = NULL_REG; // Invalidate parser event
- s->synonyms = NULL;
- s->synonyms_nr = 0; // No synonyms
+ s->_synonyms.clear(); // No synonyms
// Initialize send_calls buffer
@@ -664,9 +663,7 @@ int game_exit(EngineState *s) {
delete s->seg_manager;
- free(s->synonyms);
- s->synonyms = NULL;
- s->synonyms_nr = 0;
+ s->_synonyms.clear();
sciprintf("Freeing miscellaneous data...\n");
diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp
index d2dfa843e5..bf03e79360 100644
--- a/engines/sci/engine/kstring.cpp
+++ b/engines/sci/engine/kstring.cpp
@@ -185,12 +185,8 @@ reg_t kSetSynonyms(EngineState *s, int funct_nr, int argc, reg_t *argv) {
List *list;
Node *node;
int script;
- int synpos = 0;
- if (s->synonyms_nr)
- free(s->synonyms);
-
- s->synonyms_nr = 0;
+ s->_synonyms.clear();
list = LOOKUP_LIST(GET_SEL32(object, elements));
node = LOOKUP_NODE(list->first);
@@ -203,22 +199,14 @@ reg_t kSetSynonyms(EngineState *s, int funct_nr, int argc, reg_t *argv) {
script = GET_SEL32V(objpos, number);
seg = s->seg_manager->segGet(script);
- if (seg >= 0) synonyms_nr = s->seg_manager->getSynonymsNr(seg, SEG_ID);
+ if (seg >= 0)
+ synonyms_nr = s->seg_manager->getSynonymsNr(seg, SEG_ID);
if (synonyms_nr) {
byte *synonyms;
synonyms = s->seg_manager->getSynonyms(seg, SEG_ID);
if (synonyms) {
- int i;
- if (s->synonyms_nr)
- s->synonyms = (synonym_t*)sci_realloc(s->synonyms,
- sizeof(synonym_t) * (s->synonyms_nr + synonyms_nr));
- else
- s->synonyms = (synonym_t*)sci_malloc(sizeof(synonym_t) * synonyms_nr);
-
- s->synonyms_nr += synonyms_nr;
-
SCIkdebug(SCIkPARSER, "Setting %d synonyms for script.%d\n",
synonyms_nr, script);
@@ -228,11 +216,11 @@ reg_t kSetSynonyms(EngineState *s, int funct_nr, int argc, reg_t *argv) {
/* We used to reset the corrupted value here. I really don't think it's appropriate.
* Lars */
} else
- for (i = 0; i < synonyms_nr; i++) {
- s->synonyms[synpos].replaceant = (int16)READ_LE_UINT16(synonyms + i * 4);
- s->synonyms[synpos].replacement = (int16)READ_LE_UINT16(synonyms + i * 4 + 2);
-
- synpos++;
+ for (int i = 0; i < synonyms_nr; i++) {
+ synonym_t tmp;
+ tmp.replaceant = (int16)READ_LE_UINT16(synonyms + i * 4);
+ tmp.replacement = (int16)READ_LE_UINT16(synonyms + i * 4 + 2);
+ s->_synonyms.push_back(tmp);
}
} else
warning("Synonyms of script.%03d were requested, but script is not available", script);
@@ -242,10 +230,8 @@ reg_t kSetSynonyms(EngineState *s, int funct_nr, int argc, reg_t *argv) {
node = LOOKUP_NODE(node->succ);
}
- SCIkdebug(SCIkPARSER, "A total of %d synonyms are active now.\n", s->synonyms_nr);
+ SCIkdebug(SCIkPARSER, "A total of %d synonyms are active now.\n", s->_synonyms.size());
- if (!s->synonyms_nr)
- s->synonyms = NULL;
return s->r_acc;
}
@@ -277,7 +263,7 @@ reg_t kParse(EngineState *s, int funct_nr, int argc, reg_t *argv) {
int syntax_fail = 0;
- vocab_synonymize_tokens(words, s->synonyms, s->synonyms_nr);
+ vocab_synonymize_tokens(words, s->_synonyms);
s->r_acc = make_reg(0, 1);
diff --git a/engines/sci/engine/said.y b/engines/sci/engine/said.y
index d2144e76da..82f51f4f2a 100644
--- a/engines/sci/engine/said.y
+++ b/engines/sci/engine/said.y
@@ -305,8 +305,6 @@ static tree_t said_terminal(int val) {
static tree_t said_aug_branch(int n1, int n2, tree_t t1, tree_t t2) {
int retval;
- // FIXME: The following code is ambiguous and *not* safely portable,
- // due to the way the SAID_NEXT_NODE macro is implemented
retval = said_branch_node(SAID_NEXT_NODE,
said_branch_node(SAID_NEXT_NODE,
said_leaf_node(SAID_NEXT_NODE, n1),
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index a7d0abcd2a..35fc41fb31 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -1037,7 +1037,7 @@ int c_parse(EngineState *s) {
if (!words.empty()) {
int syntax_fail = 0;
- vocab_synonymize_tokens(words, s->synonyms, s->synonyms_nr);
+ vocab_synonymize_tokens(words, s->_synonyms);
sciprintf("Parsed to the following blocks:\n");
diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp
index 521cd46de6..c8f44fa7be 100644
--- a/engines/sci/engine/state.cpp
+++ b/engines/sci/engine/state.cpp
@@ -151,9 +151,6 @@ EngineState::EngineState() : _dirseeker(this) {
parser_valid = 0;
- synonyms = 0;
- synonyms_nr = 0;
-
game_obj = NULL_REG;
classtable_size = 0;
diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h
index 069e798ba8..ef2ddb7912 100644
--- a/engines/sci/engine/state.h
+++ b/engines/sci/engine/state.h
@@ -259,8 +259,7 @@ public:
int parser_valid; /* If something has been correctly parsed */
- synonym_t *synonyms; /* The list of synonyms */
- int synonyms_nr;
+ SynonymList _synonyms; /* The list of synonyms */
reg_t game_obj; /* Pointer to the game object */
diff --git a/engines/sci/scicore/vocabulary.cpp b/engines/sci/scicore/vocabulary.cpp
index fac3af1c20..283029b226 100644
--- a/engines/sci/scicore/vocabulary.cpp
+++ b/engines/sci/scicore/vocabulary.cpp
@@ -599,16 +599,14 @@ void vocab_dump_parse_tree(const char *tree_name, parse_tree_node_t *nodes) {
sciprintf("))\n");
}
-void vocab_synonymize_tokens(ResultWordList &words, synonym_t *synonyms, int synonyms_nr) {
- int sync;
-
- if (!synonyms || !synonyms_nr)
+void vocab_synonymize_tokens(ResultWordList &words, const SynonymList &synonyms) {
+ if (synonyms.empty())
return; // No synonyms: Nothing to check
for (ResultWordList::iterator i = words.begin(); i != words.end(); ++i)
- for (sync = 0; sync < synonyms_nr; sync++)
- if (i->group == synonyms[sync].replaceant)
- i->group = synonyms[sync].replacement;
+ for (SynonymList::const_iterator sync = synonyms.begin(); sync != synonyms.end(); ++sync)
+ if (i->group == sync->replaceant)
+ i->group = sync->replacement;
}
} // End of namespace Sci
diff --git a/engines/sci/scicore/vocabulary.h b/engines/sci/scicore/vocabulary.h
index 6ad583a6c4..41562e092d 100644
--- a/engines/sci/scicore/vocabulary.h
+++ b/engines/sci/scicore/vocabulary.h
@@ -165,13 +165,11 @@ struct synonym_t {
int replacement; /* The replacement word group for this one */
};
+typedef Common::List<synonym_t> SynonymList;
struct parse_tree_branch_t {
-
int id;
-
int data[10];
-
};
#define PARSE_TREE_NODE_LEAF 0
@@ -179,16 +177,11 @@ struct parse_tree_branch_t {
struct parse_tree_node_t {
-
short type; /* leaf or branch */
-
union {
-
int value; /* For leaves */
short branches[2]; /* For branches */
-
} content;
-
};
@@ -374,11 +367,10 @@ void vocab_decypher_said_block(EngineState *s, byte *pos);
*/
-void vocab_synonymize_tokens(ResultWordList &words, synonym_t *synonyms, int synonyms_nr);
+void vocab_synonymize_tokens(ResultWordList &words, const SynonymList &synonyms);
/* Synonymizes a token list
** Parameters: (ResultWordList &) words: The word list to synonymize
-** (synonym_t *) synonyms: Synonym list
-** (int) synonyms_nr: Number of synonyms in the list
+** (const SynonymList &) synonyms: Synonym list
*/
int vocab_gnf_parse(parse_tree_node_t *nodes, const ResultWordList &words,