SCI: added said spec dump ability to logkernel

svn-id: r51242
This commit is contained in:
Martin Kiewitz 2010-07-24 11:51:09 +00:00
parent 9672c757d6
commit d49d1d60fe
5 changed files with 63 additions and 51 deletions

View file

@ -1302,7 +1302,8 @@ bool Console::cmdSaid(int argc, const char **argv) {
spec[len++] = 0xFF; spec[len++] = 0xFF;
printf("Matching '%s' against:", string); printf("Matching '%s' against:", string);
_engine->getVocabulary()->decipherSaidBlock(spec); _engine->getVocabulary()->debugDecipherSaidBlock(spec);
printf("\n");
bool res = _engine->getVocabulary()->tokenizeString(words, string, &error); bool res = _engine->getVocabulary()->tokenizeString(words, string, &error);
if (res && !words.empty()) { if (res && !words.empty()) {

View file

@ -664,8 +664,18 @@ static void logKernelCall(const KernelFunction *kernelCall, EngineState *s, int
printf(" (%s)", s->_segMan->getObjectName(argv[parmNr])); printf(" (%s)", s->_segMan->getObjectName(argv[parmNr]));
break; break;
case SIG_TYPE_REFERENCE: case SIG_TYPE_REFERENCE:
printf(" ('%s')", s->_segMan->getString(argv[parmNr]).c_str()); if (kernelCall->function == kSaid) {
break; SegmentRef saidSpec = s->_segMan->dereference(argv[parmNr]);
if (saidSpec.isRaw) {
printf(" ('");
g_sci->getVocabulary()->debugDecipherSaidBlock(saidSpec.raw);
printf("')");
} else {
printf(" (non-raw said-spec)");
}
} else {
printf(" ('%s')", s->_segMan->getString(argv[parmNr]).c_str());
}
default: default:
break; break;
} }

View file

@ -1003,11 +1003,8 @@ int said(EngineState *s, byte *spec, bool verbose) {
ParseTreeNode *parse_tree_ptr = voc->_parserNodes; ParseTreeNode *parse_tree_ptr = voc->_parserNodes;
if (voc->parserIsValid) { if (voc->parserIsValid) {
if (said_parse_spec(spec)) { if (said_parse_spec(spec))
scidprintf("Offending spec was: ");
voc->decipherSaidBlock(spec);
return SAID_NO_MATCH; return SAID_NO_MATCH;
}
if (verbose) if (verbose)
vocab_dump_parse_tree("Said-tree", said_tree); vocab_dump_parse_tree("Said-tree", said_tree);

View file

@ -321,54 +321,58 @@ ResultWord Vocabulary::lookupWord(const char *word, int word_len) {
return retval; return retval;
} }
void Vocabulary::decipherSaidBlock(byte *addr) { void Vocabulary::debugDecipherSaidBlock(const byte *addr) {
uint16 nextitem; bool first = true;
uint16 nextItem;
do { do {
nextitem = *addr++; nextItem = *addr++;
if (nextItem != 0xff) {
if ((!first) && (nextItem != 0xf0))
printf(" ");
first = false;
if (nextitem < 0xf0) { if (nextItem < 0xf0) {
nextitem = nextitem << 8 | *addr++; nextItem = nextItem << 8 | *addr++;
printf(" %s[%03x]", getAnyWordFromGroup(nextitem), nextitem); printf("%s{%03x}", getAnyWordFromGroup(nextItem), nextItem);
nextitem = 42; // Make sure that group 0xff doesn't abort nextItem = 0; // Make sure that group 0xff doesn't abort
} else switch (nextitem) { } else switch (nextItem) {
case 0xf0: case 0xf0:
printf(" ,"); printf(",");
break; break;
case 0xf1: case 0xf1:
printf(" &"); printf("&");
break; break;
case 0xf2: case 0xf2:
printf(" /"); printf("/");
break; break;
case 0xf3: case 0xf3:
printf(" ("); printf("(");
break; break;
case 0xf4: case 0xf4:
printf(" )"); printf(")");
break; break;
case 0xf5: case 0xf5:
printf(" ["); printf("[");
break; break;
case 0xf6: case 0xf6:
printf(" ]"); printf("]");
break; break;
case 0xf7: case 0xf7:
printf(" #"); printf("#");
break; break;
case 0xf8: case 0xf8:
printf(" <"); printf("<");
break; break;
case 0xf9: case 0xf9:
printf(" >"); printf(">");
break; break;
case 0xff: case 0xff:
break; break;
} }
} while (nextitem != 0xff); }
} while (nextItem != 0xff);
printf("\n");
} }
static const byte lowerCaseMap[256] = { static const byte lowerCaseMap[256] = {

View file

@ -235,7 +235,7 @@ public:
* For debugging only. * For debugging only.
* @param pos pointer to the data to dump * @param pos pointer to the data to dump
*/ */
void decipherSaidBlock(byte *pos); void debugDecipherSaidBlock(const byte *pos);
/** /**
* Prints the parser suffixes to the debug console. * Prints the parser suffixes to the debug console.