SCI: Renamed some Vocabulary methods for clarity; also renamed decypherSaidBlock -> decipherSaidBlock; some cleanup in Console::cmdSentenceFragments
svn-id: r41072
This commit is contained in:
parent
4fba6e5d4c
commit
cf68dc1a7b
6 changed files with 48 additions and 46 deletions
|
@ -499,29 +499,30 @@ bool Console::cmdSentenceFragments(int argc, const char **argv) {
|
||||||
for (uint i = 0; i < g_EngineState->_vocabulary->getParserBranchesSize(); i++) {
|
for (uint i = 0; i < g_EngineState->_vocabulary->getParserBranchesSize(); i++) {
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
||||||
DebugPrintf("R%02d: [%x] ->", i, g_EngineState->_vocabulary->getParseTreeBranch(i).id);
|
const parse_tree_branch_t &branch = g_EngineState->_vocabulary->getParseTreeBranch(i);
|
||||||
while ((j < 10) && g_EngineState->_vocabulary->getParseTreeBranch(i).data[j]) {
|
DebugPrintf("R%02d: [%x] ->", i, branch.id);
|
||||||
int dat = g_EngineState->_vocabulary->getParseTreeBranch(i).data[j++];
|
while ((j < 10) && branch.data[j]) {
|
||||||
|
int dat = branch.data[j++];
|
||||||
|
|
||||||
switch (dat) {
|
switch (dat) {
|
||||||
case VOCAB_TREE_NODE_COMPARE_TYPE:
|
case VOCAB_TREE_NODE_COMPARE_TYPE:
|
||||||
dat = g_EngineState->_vocabulary->getParseTreeBranch(i).data[j++];
|
dat = branch.data[j++];
|
||||||
DebugPrintf(" C(%x)", dat);
|
DebugPrintf(" C(%x)", dat);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VOCAB_TREE_NODE_COMPARE_GROUP:
|
case VOCAB_TREE_NODE_COMPARE_GROUP:
|
||||||
dat = g_EngineState->_vocabulary->getParseTreeBranch(i).data[j++];
|
dat = branch.data[j++];
|
||||||
DebugPrintf(" WG(%x)", dat);
|
DebugPrintf(" WG(%x)", dat);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VOCAB_TREE_NODE_FORCE_STORAGE:
|
case VOCAB_TREE_NODE_FORCE_STORAGE:
|
||||||
dat = g_EngineState->_vocabulary->getParseTreeBranch(i).data[j++];
|
dat = branch.data[j++];
|
||||||
DebugPrintf(" FORCE(%x)", dat);
|
DebugPrintf(" FORCE(%x)", dat);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (dat > VOCAB_TREE_NODE_LAST_WORD_STORAGE) {
|
if (dat > VOCAB_TREE_NODE_LAST_WORD_STORAGE) {
|
||||||
int dat2 = g_EngineState->_vocabulary->getParseTreeBranch(i).data[j++];
|
int dat2 = branch.data[j++];
|
||||||
DebugPrintf(" %x[%x]", dat, dat2);
|
DebugPrintf(" %x[%x]", dat, dat2);
|
||||||
} else
|
} else
|
||||||
DebugPrintf(" ?%x?", dat);
|
DebugPrintf(" ?%x?", dat);
|
||||||
|
|
|
@ -906,7 +906,7 @@ static void vocab_get_knames11(ResourceManager *resmgr, Common::StringList &name
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool Vocabulary::getKernelNames() {
|
bool Vocabulary::loadKernelNames() {
|
||||||
_kernelNames.clear();
|
_kernelNames.clear();
|
||||||
|
|
||||||
switch (_resmgr->_sciVersion) {
|
switch (_resmgr->_sciVersion) {
|
||||||
|
|
|
@ -95,7 +95,7 @@ reg_t kSaid(EngineState *s, int funct_nr, int argc, reg_t *argv) {
|
||||||
|
|
||||||
#ifdef DEBUG_PARSER
|
#ifdef DEBUG_PARSER
|
||||||
debugC(2, kDebugLevelParser, "Said block:", 0);
|
debugC(2, kDebugLevelParser, "Said block:", 0);
|
||||||
s->_vocabulary->decypherSaidBlock(said_block);
|
s->_vocabulary->decipherSaidBlock(said_block);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (s->parser_event.isNull() || (GET_SEL32V(s->parser_event, claimed))) {
|
if (s->parser_event.isNull() || (GET_SEL32V(s->parser_event, claimed))) {
|
||||||
|
|
|
@ -2448,7 +2448,7 @@ int said(EngineState *s, byte *spec, int verbose) {
|
||||||
if (s->parser_valid) {
|
if (s->parser_valid) {
|
||||||
if (said_parse_spec(s, spec)) {
|
if (said_parse_spec(s, spec)) {
|
||||||
sciprintf("Offending spec was: ");
|
sciprintf("Offending spec was: ");
|
||||||
s->_vocabulary->decypherSaidBlock(spec);
|
s->_vocabulary->decipherSaidBlock(spec);
|
||||||
return SAID_NO_MATCH;
|
return SAID_NO_MATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,8 +92,8 @@ Vocabulary::Vocabulary(ResourceManager *resmgr, bool isOldSci0) : _resmgr(resmgr
|
||||||
|
|
||||||
debug(2, "Initializing vocabulary");
|
debug(2, "Initializing vocabulary");
|
||||||
|
|
||||||
if (_resmgr->_sciVersion < SCI_VERSION_01_VGA && getParserWords()) {
|
if (_resmgr->_sciVersion < SCI_VERSION_01_VGA && loadParserWords()) {
|
||||||
getSuffixes();
|
loadSuffixes();
|
||||||
if (getBranches())
|
if (getBranches())
|
||||||
// Now build a GNF grammar out of this
|
// Now build a GNF grammar out of this
|
||||||
_parserRules = buildGNF();
|
_parserRules = buildGNF();
|
||||||
|
@ -102,16 +102,16 @@ Vocabulary::Vocabulary(ResourceManager *resmgr, bool isOldSci0) : _resmgr(resmgr
|
||||||
_parserRules = NULL;
|
_parserRules = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
getOpcodes();
|
loadOpcodes();
|
||||||
|
|
||||||
if (!getSelectorNames()) {
|
if (!loadSelectorNames()) {
|
||||||
error("Vocabulary: Could not retrieve selector names");
|
error("Vocabulary: Could not retrieve selector names");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map a few special selectors for later use
|
// Map a few special selectors for later use
|
||||||
mapSelectors();
|
mapSelectors();
|
||||||
|
|
||||||
getKernelNames();
|
loadKernelNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vocabulary::~Vocabulary() {
|
Vocabulary::~Vocabulary() {
|
||||||
|
@ -124,7 +124,7 @@ Vocabulary::~Vocabulary() {
|
||||||
freeSuffixes();
|
freeSuffixes();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vocabulary::getSelectorNames() {
|
bool Vocabulary::loadSelectorNames() {
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
Resource *r = _resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_SNAMES, 0);
|
Resource *r = _resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_SNAMES, 0);
|
||||||
|
@ -150,7 +150,7 @@ bool Vocabulary::getSelectorNames() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vocabulary::getOpcodes() {
|
bool Vocabulary::loadOpcodes() {
|
||||||
int count, i = 0;
|
int count, i = 0;
|
||||||
Resource* r = _resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_OPCODES, 0);
|
Resource* r = _resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_OPCODES, 0);
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ bool Vocabulary::getOpcodes() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vocabulary::getParserWords() {
|
bool Vocabulary::loadParserWords() {
|
||||||
|
|
||||||
char currentword[256] = ""; // They're not going to use words longer than 255 ;-)
|
char currentword[256] = ""; // They're not going to use words longer than 255 ;-)
|
||||||
int currentwordpos = 0;
|
int currentwordpos = 0;
|
||||||
|
@ -260,7 +260,7 @@ const char *Vocabulary::getAnyWordFromGroup(int group) {
|
||||||
return "{invalid}";
|
return "{invalid}";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vocabulary::getSuffixes() {
|
bool Vocabulary::loadSuffixes() {
|
||||||
// Determine if we can find a SCI1 suffix vocabulary first
|
// Determine if we can find a SCI1 suffix vocabulary first
|
||||||
Resource* resource = NULL;
|
Resource* resource = NULL;
|
||||||
|
|
||||||
|
@ -410,7 +410,7 @@ ResultWord Vocabulary::lookupWord(const char *word, int word_len) {
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vocabulary::decypherSaidBlock(byte *addr) {
|
void Vocabulary::decipherSaidBlock(byte *addr) {
|
||||||
int nextitem;
|
int nextitem;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -503,7 +503,7 @@ bool Vocabulary::tokenizeString(ResultWordList &retval, const char *sentence, ch
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vocabulary::printSuffixes() {
|
void Vocabulary::printSuffixes() const {
|
||||||
char word_buf[256], alt_buf[256];
|
char word_buf[256], alt_buf[256];
|
||||||
Sci::Console *con = ((SciEngine *)g_engine)->_console;
|
Sci::Console *con = ((SciEngine *)g_engine)->_console;
|
||||||
|
|
||||||
|
@ -519,7 +519,7 @@ void Vocabulary::printSuffixes() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vocabulary::printParserWords() {
|
void Vocabulary::printParserWords() const {
|
||||||
Sci::Console *con = ((SciEngine *)g_engine)->_console;
|
Sci::Console *con = ((SciEngine *)g_engine)->_console;
|
||||||
|
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
|
@ -195,10 +195,11 @@ public:
|
||||||
const char *getAnyWordFromGroup(int group);
|
const char *getAnyWordFromGroup(int group);
|
||||||
|
|
||||||
|
|
||||||
/* Looks up a single word in the words and suffixes list
|
/**
|
||||||
** Parameters: (char *) word: Pointer to the word to look up
|
* Looks up a single word in the words and suffixes list.
|
||||||
** (int) word_len: Length of the word to look up
|
* @param word pointer to the word to look up
|
||||||
** Returns : (const ResultWordList &) A list containing 1 or 0 words
|
* @param word_len length of the word to look up
|
||||||
|
* @return the matching word (or (-1,-1) if there was no match)
|
||||||
*/
|
*/
|
||||||
ResultWord lookupWord(const char *word, int word_len);
|
ResultWord lookupWord(const char *word, int word_len);
|
||||||
|
|
||||||
|
@ -239,22 +240,22 @@ public:
|
||||||
*/
|
*/
|
||||||
parse_rule_list_t *buildGNF(bool verbose = false);
|
parse_rule_list_t *buildGNF(bool verbose = false);
|
||||||
|
|
||||||
/* Decyphers a said block and dumps its content via sciprintf.
|
/**
|
||||||
** Parameters: (EngineState *) s: The state to use
|
* Deciphers a said block and dumps its content via sciprintf.
|
||||||
** (byte *) pos: Pointer to the data to dump
|
* For debugging only.
|
||||||
** For debugging only.
|
* @param pos pointer to the data to dump
|
||||||
*/
|
*/
|
||||||
void decypherSaidBlock(byte *pos);
|
void decipherSaidBlock(byte *pos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints the parser suffixes to the debug console
|
* Prints the parser suffixes to the debug console.
|
||||||
*/
|
*/
|
||||||
void printSuffixes();
|
void printSuffixes() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints the parser words to the debug console
|
* Prints the parser words to the debug console.
|
||||||
*/
|
*/
|
||||||
void printParserWords();
|
void printParserWords() const;
|
||||||
|
|
||||||
uint getParserBranchesSize() const { return _parserBranches.size(); }
|
uint getParserBranchesSize() const { return _parserBranches.size(); }
|
||||||
const parse_tree_branch_t &getParseTreeBranch(int number) const { return _parserBranches[number]; }
|
const parse_tree_branch_t &getParseTreeBranch(int number) const { return _parserBranches[number]; }
|
||||||
|
@ -293,7 +294,7 @@ private:
|
||||||
* Loads the vocabulary selector names.
|
* Loads the vocabulary selector names.
|
||||||
* Returns true upon success, false otherwise.
|
* Returns true upon success, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool getSelectorNames();
|
bool loadSelectorNames();
|
||||||
|
|
||||||
/* Maps special selectors
|
/* Maps special selectors
|
||||||
** Returns : (void)
|
** Returns : (void)
|
||||||
|
@ -301,33 +302,33 @@ private:
|
||||||
void mapSelectors();
|
void mapSelectors();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills the given Array with opcodes.
|
* Loads the opcode names (only used for debugging).
|
||||||
* @return true on success, false on failure
|
* @return true on success, false on failure
|
||||||
*/
|
*/
|
||||||
bool getOpcodes();
|
bool loadOpcodes();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills the given StringList with kernel function names.
|
* Loads the kernel function names.
|
||||||
*
|
*
|
||||||
* This function reads the kernel function name table from resource_map,
|
* This function reads the kernel function name table from resource_map,
|
||||||
* and fills the given StringList with them.
|
* and fills the _kernelNames array with them.
|
||||||
* The resulting list has the same format regardless of the format of the
|
* The resulting list has the same format regardless of the format of the
|
||||||
* name table of the resource (the format changed between version 0 and 1).
|
* name table of the resource (the format changed between version 0 and 1).
|
||||||
* @return true on success, false on failure
|
* @return true on success, false on failure
|
||||||
*/
|
*/
|
||||||
bool getKernelNames();
|
bool loadKernelNames();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all words from the main vocabulary.
|
* Loads all words from the main vocabulary.
|
||||||
* @return true on success, false on failure
|
* @return true on success, false on failure
|
||||||
*/
|
*/
|
||||||
bool getParserWords();
|
bool loadParserWords();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all suffixes from the suffix vocabulary.
|
* Loads all suffixes from the suffix vocabulary.
|
||||||
* @return true on success, false on failure
|
* @return true on success, false on failure
|
||||||
*/
|
*/
|
||||||
bool getSuffixes();
|
bool loadSuffixes();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frees all suffixes in the given list.
|
* Frees all suffixes in the given list.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue