aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sci/engine')
-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
6 files changed, 14 insertions, 37 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 */