diff options
author | Max Horn | 2009-04-24 10:42:53 +0000 |
---|---|---|
committer | Max Horn | 2009-04-24 10:42:53 +0000 |
commit | 486f10edaf813e19ce55812f7ab75e0b6d349fb6 (patch) | |
tree | 43b38cd1e89fa9a97cf0a963e5bfb0fec5781da0 /engines/sci/scicore | |
parent | 7b11ef429edde1d0b5b85063019bf7b0dfcc8bd4 (diff) | |
download | scummvm-rg350-486f10edaf813e19ce55812f7ab75e0b6d349fb6.tar.gz scummvm-rg350-486f10edaf813e19ce55812f7ab75e0b6d349fb6.tar.bz2 scummvm-rg350-486f10edaf813e19ce55812f7ab75e0b6d349fb6.zip |
SCI: Store parse_tree_branch_t in a Common::Arraay
svn-id: r40100
Diffstat (limited to 'engines/sci/scicore')
-rw-r--r-- | engines/sci/scicore/vocabulary.cpp | 38 | ||||
-rw-r--r-- | engines/sci/scicore/vocabulary.h | 30 |
2 files changed, 27 insertions, 41 deletions
diff --git a/engines/sci/scicore/vocabulary.cpp b/engines/sci/scicore/vocabulary.cpp index 76fbf292fc..d708e95563 100644 --- a/engines/sci/scicore/vocabulary.cpp +++ b/engines/sci/scicore/vocabulary.cpp @@ -193,46 +193,40 @@ void vocab_free_suffixes(ResourceManager *resmgr, SuffixList &suffixes) { suffixes.clear(); } -void vocab_free_branches(parse_tree_branch_t *parser_branches) { - free(parser_branches); -} - -parse_tree_branch_t *vocab_get_branches(ResourceManager * resmgr, int *branches_nr) { +bool vocab_get_branches(ResourceManager * resmgr, Common::Array<parse_tree_branch_t> &branches) { Resource *resource = resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_PARSE_TREE_BRANCHES, 0); - parse_tree_branch_t *retval; - int i; + + branches.clear(); if (!resource) { fprintf(stderr, "No parser tree data found!\n"); - return NULL; + return false; } - *branches_nr = resource->size / 20; + int branches_nr = resource->size / 20; - if (*branches_nr == 0) { + if (branches_nr == 0) { fprintf(stderr, "Parser tree data is empty!\n"); - return NULL; + return false; } - retval = (parse_tree_branch_t *)sci_malloc(sizeof(parse_tree_branch_t) * *branches_nr); - - for (i = 0; i < *branches_nr; i++) { - int k; + branches.resize(branches_nr); + for (int i = 0; i < branches_nr; i++) { byte *base = resource->data + i * 20; - retval[i].id = (int16)READ_LE_UINT16(base); + branches[i].id = (int16)READ_LE_UINT16(base); - for (k = 0; k < 9; k++) - retval[i].data[k] = READ_LE_UINT16(base + 2 + 2 * k); + for (int k = 0; k < 9; k++) + branches[i].data[k] = READ_LE_UINT16(base + 2 + 2 * k); - retval[i].data[9] = 0; // Always terminate + branches[i].data[9] = 0; // Always terminate } - if (!retval[*branches_nr - 1].id) /* branch lists may be terminated by empty rules */ - --(*branches_nr); + if (!branches[branches_nr - 1].id) // branch lists may be terminated by empty rules + branches.remove_at(branches_nr - 1); - return retval; + return true; } diff --git a/engines/sci/scicore/vocabulary.h b/engines/sci/scicore/vocabulary.h index 9a073d2e79..a8d58c04e1 100644 --- a/engines/sci/scicore/vocabulary.h +++ b/engines/sci/scicore/vocabulary.h @@ -243,20 +243,13 @@ void vocab_free_suffixes(ResourceManager *resmgr, SuffixList &suffixes); ** (SuffixList) suffixes: The suffixes to free */ -parse_tree_branch_t *vocab_get_branches(ResourceManager *resmgr, int *branches_nr); -/* Retrieves all grammar rules from the resource data -** Parameters: (ResourceManager*) resmgr: Resource manager the rules are -** read from -** (int *) branches_nr: Pointer to the variable which the number of entries is to be -** stored in -** Returns : (parse_tree_branch_t *): The rules, or NULL on error -*/ - -void vocab_free_branches(parse_tree_branch_t *parser_branches); -/* Frees all branches -** Parameters: (parse_tree_branch_t *) parser_branches: The branches to free -** Returns : (null) -*/ +/** + * Retrieves all grammar rules from the resource data. + * @param resmgr Resource manager the rules are read from + * @param branches The rules are stored into this Array + * @return true on success, false on error + */ +bool vocab_get_branches(ResourceManager *resmgr, Common::Array<parse_tree_branch_t> &branches); ResultWord vocab_lookup_word(char *word, int word_len, const WordMap &words, const SuffixList &suffixes); @@ -284,10 +277,9 @@ bool vocab_tokenize_string(ResultWordList &retval, char *sentence, */ -parse_rule_list_t *vocab_build_gnf(parse_tree_branch_t *branches, int branches_nr); +parse_rule_list_t *vocab_build_gnf(const Common::Array<parse_tree_branch_t> &branches); /* Constructs the Greibach Normal Form of the grammar supplied in 'branches' ** Parameters: (parse_tree_branch_t *) branches: The parser's branches -** (int) branches_nr: Number of parser branches ** Returns : (parse_rule_list_t *): Pointer to a list of singly linked ** GNF rules describing the same language ** that was described by 'branches' @@ -304,7 +296,7 @@ void vocab_free_rule_list(parse_rule_list_t *rule_list); int vocab_build_parse_tree(parse_tree_node_t *nodes, const ResultWordList &words, - parse_tree_branch_t *branch0, parse_rule_list_t *rules); + const parse_tree_branch_t &branch0, parse_rule_list_t *rules); /* Builds a parse tree from a list of words ** Parameters: (parse_tree_node_t *) nodes: A node list to store the tree in (must have ** at least VOCAB_TREE_NODES entries) @@ -357,9 +349,9 @@ void vocab_synonymize_tokens(ResultWordList &words, const SynonymList &synonyms) */ int vocab_gnf_parse(parse_tree_node_t *nodes, const ResultWordList &words, - parse_tree_branch_t *branch0, parse_rule_list_t *tlist, int verbose); + const parse_tree_branch_t &branch0, parse_rule_list_t *tlist, int verbose); -void vocab_gnf_dump(parse_tree_branch_t *branches, int branches_nr); +void vocab_gnf_dump(const Common::Array<parse_tree_branch_t> &branches); } // End of namespace Sci |