aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Kołodziejski2009-02-20 20:01:31 +0000
committerPaweł Kołodziejski2009-02-20 20:01:31 +0000
commit208016649999ae89a2bba1f382f4f9fdbdd519b2 (patch)
tree32d003f9d78ac5ede21a4b670c8e9d6c1f78015b
parent054f1fb5145b6e29af786e4f31a49d193f152ecc (diff)
downloadscummvm-rg350-208016649999ae89a2bba1f382f4f9fdbdd519b2.tar.gz
scummvm-rg350-208016649999ae89a2bba1f382f4f9fdbdd519b2.tar.bz2
scummvm-rg350-208016649999ae89a2bba1f382f4f9fdbdd519b2.zip
formating
svn-id: r38616
-rw-r--r--engines/sci/engine/said.y387
1 files changed, 128 insertions, 259 deletions
diff --git a/engines/sci/engine/said.y b/engines/sci/engine/said.y
index 33c8401849..97d66a9a88 100644
--- a/engines/sci/engine/said.y
+++ b/engines/sci/engine/said.y
@@ -31,7 +31,7 @@
#define MAX_SAID_TOKENS 128
-/* Maximum number of words to be expected in a parsed sentence */
+// Maximum number of words to be expected in a parsed sentence
#define AUGMENT_MAX_WORDS 64
@@ -43,7 +43,7 @@
#define AUGMENT_SENTENCE_PART_BRACKETS 0x152
-/* Minor numbers */
+// Minor numbers
#define AUGMENT_SENTENCE_MINOR_MATCH_PHRASE 0x14c
#define AUGMENT_SENTENCE_MINOR_MATCH_WORD 0x153
#define AUGMENT_SENTENCE_MINOR_RECURSE 0x144
@@ -51,8 +51,8 @@
#undef YYDEBUG /*1*/
-/*#define SAID_DEBUG*/
-/*#define SCI_DEBUG_PARSE_TREE_AUGMENTATION*/ /* uncomment to debug parse tree augmentation*/
+//#define SAID_DEBUG*/
+//#define SCI_DEBUG_PARSE_TREE_AUGMENTATION // uncomment to debug parse tree augmentation
#ifdef SCI_DEBUG_PARSE_TREE_AUGMENTATION
@@ -67,11 +67,10 @@ static char *said_parse_error;
static int said_token;
static int said_tokens_nr;
static int said_tokens[MAX_SAID_TOKENS];
+static int said_blessed; // increminated by said_top_branch
-static int said_blessed; /* increminated by said_top_branch */
-
-static int said_tree_pos; /* Set to 0 if we're out of space */
-#define SAID_TREE_START 4; /* Reserve space for the 4 top nodes */
+static int said_tree_pos; // Set to 0 if we're out of space
+#define SAID_TREE_START 4; // Reserve space for the 4 top nodes
#define VALUE_IGNORE -424242
@@ -81,34 +80,19 @@ typedef int wgroup_t;
typedef int tree_t;
typedef int said_spec_t;
-static tree_t
-said_aug_branch(int, int, tree_t, tree_t);
-
-static tree_t
-said_attach_branch(tree_t, tree_t);
+static tree_t said_aug_branch(int, int, tree_t, tree_t);
+static tree_t said_attach_branch(tree_t, tree_t);
/*
-static tree_t
-said_wgroup_branch(wgroup_t);
+static tree_t said_wgroup_branch(wgroup_t);
*/
-static said_spec_t
-said_top_branch(tree_t);
-
-static tree_t
-said_paren(tree_t, tree_t);
-
-static tree_t
-said_value(int, tree_t);
-
-static tree_t
-said_terminal(int);
-
+static said_spec_t said_top_branch(tree_t);
+static tree_t said_paren(tree_t, tree_t);
+static tree_t said_value(int, tree_t);
+static tree_t said_terminal(int);
-static int
-yylex(void);
+static int yylex(void);
-static int
-yyerror(char *s)
-{
+static int yyerror(char *s) {
said_parse_error = sci_strdup(s);
return 1; /* Abort */
}
@@ -177,7 +161,6 @@ rightspec : YY_SLASH expr
;
-
word : WGROUP
{ $$ = said_paren(said_value(0x141, said_value(0x153, said_terminal($1))), SAID_BRANCH_NULL); }
;
@@ -203,7 +186,6 @@ wordset : word
;
-
expr : cwordset cwordrefset
{ $$ = said_attach_branch($1, $2); }
| cwordset
@@ -213,7 +195,6 @@ expr : cwordset cwordrefset
;
-
cwordrefset : wordrefset
{ $$ = $1; }
| YY_BRACKETSO_LT wordrefset YY_BRACKETSC
@@ -223,7 +204,6 @@ cwordrefset : wordrefset
;
-
wordrefset : YY_LT word recref
{ $$ = said_aug_branch(0x144, 0x14f, $2, $3); }
| YY_LT_PARENO YY_PARENO expr YY_PARENC
@@ -235,7 +215,6 @@ wordrefset : YY_LT word recref
;
-
recref : YY_LT wordset recref
{ $$ = said_aug_branch(0x141, 0x144, said_aug_branch(0x144, 0x14f, $2, SAID_BRANCH_NULL), $3); }
| YY_LT wordset
@@ -244,18 +223,11 @@ recref : YY_LT wordset recref
{ $$ = said_aug_branch(0x141, 0x14c, $2, SAID_BRANCH_NULL); }
;
-
-
%%
+int parse_yy_token_lookup[] = {YY_COMMA, YY_AMP, YY_SLASH, YY_PARENO, YY_PARENC, YY_BRACKETSO, YY_BRACKETSC, YY_HASH, YY_LT, YY_GT};
-int
-parse_yy_token_lookup[] = {YY_COMMA, YY_AMP, YY_SLASH, YY_PARENO, YY_PARENC, YY_BRACKETSO, YY_BRACKETSC,
- YY_HASH, YY_LT, YY_GT};
-
-static int
-yylex(void)
-{
+static int yylex(void) {
int retval = said_tokens[said_token++];
if (retval < SAID_LONG(SAID_FIRST)) {
@@ -286,11 +258,9 @@ yylex(void)
return retval;
}
-#define SAID_NEXT_NODE ((said_tree_pos == 0) || (said_tree_pos >= VOCAB_TREE_NODES))? said_tree_pos = 0 : said_tree_pos++
+#define SAID_NEXT_NODE ((said_tree_pos == 0) || (said_tree_pos >= VOCAB_TREE_NODES)) ? said_tree_pos = 0 : said_tree_pos++
-static inline int
-said_leaf_node(tree_t pos, int value)
-{
+static inline int said_leaf_node(tree_t pos, int value) {
said_tree[pos].type = PARSE_TREE_NODE_LEAF;
if (value != VALUE_IGNORE)
@@ -299,9 +269,7 @@ said_leaf_node(tree_t pos, int value)
return pos;
}
-static inline int
-said_branch_node(tree_t pos, int left, int right)
-{
+static inline int said_branch_node(tree_t pos, int left, int right) {
said_tree[pos].type = PARSE_TREE_NODE_BRANCH;
if (left != VALUE_IGNORE)
@@ -313,51 +281,27 @@ said_branch_node(tree_t pos, int left, int right)
return pos;
}
-
-static tree_t
-said_paren(tree_t t1, tree_t t2)
-{
+static tree_t said_paren(tree_t t1, tree_t t2) {
if (t1)
- return said_branch_node(SAID_NEXT_NODE,
- t1,
- t2
- );
+ return said_branch_node(SAID_NEXT_NODE, t1, t2);
else
return t2;
}
-static tree_t
-said_value(int val, tree_t t)
-{
- return said_branch_node(SAID_NEXT_NODE,
- said_leaf_node(SAID_NEXT_NODE, val),
- t
- );
+static tree_t said_value(int val, tree_t t) {
+ return said_branch_node(SAID_NEXT_NODE, said_leaf_node(SAID_NEXT_NODE, val), t);
}
-static tree_t
-said_terminal(int val)
-{
+static tree_t said_terminal(int val) {
return said_leaf_node(SAID_NEXT_NODE, val);
}
-
-static tree_t
-said_aug_branch(int n1, int n2, tree_t t1, tree_t t2)
-{
+static tree_t said_aug_branch(int n1, int n2, tree_t t1, tree_t t2) {
int retval;
- retval = said_branch_node(SAID_NEXT_NODE,
- said_branch_node(SAID_NEXT_NODE,
- said_leaf_node(SAID_NEXT_NODE, n1),
- said_branch_node(SAID_NEXT_NODE,
- said_leaf_node(SAID_NEXT_NODE, n2),
- t1
- )
- ),
- t2
- );
+ retval = said_branch_node(SAID_NEXT_NODE, said_branch_node(SAID_NEXT_NODE, said_leaf_node(SAID_NEXT_NODE, n1),
+ said_branch_node(SAID_NEXT_NODE, said_leaf_node(SAID_NEXT_NODE, n2), t1)), t2);
#ifdef SAID_DEBUG
fprintf(stderr,"AUG(0x%x, 0x%x, [%04x], [%04x]) = [%04x]\n", n1, n2, t1, t2, retval);
@@ -366,9 +310,7 @@ said_aug_branch(int n1, int n2, tree_t t1, tree_t t2)
return retval;
}
-static tree_t
-said_attach_branch(tree_t base, tree_t attacheant)
-{
+static tree_t said_attach_branch(tree_t base, tree_t attacheant) {
#ifdef SAID_DEBUG
fprintf(stderr,"ATT2([%04x], [%04x]) = [%04x]\n", base, attacheant, base);
#endif
@@ -379,33 +321,28 @@ said_attach_branch(tree_t base, tree_t attacheant)
return attacheant;
if (!base)
- return 0; /* Happens if we're out of space */
+ return 0; // Happens if we're out of space
said_branch_node(base, VALUE_IGNORE, attacheant);
return base;
}
-static said_spec_t
-said_top_branch(tree_t first)
-{
+static said_spec_t said_top_branch(tree_t first) {
#ifdef SAID_DEBUG
fprintf(stderr, "TOP([%04x])\n", first);
#endif
said_branch_node(0, 1, 2);
- said_leaf_node(1, 0x141); /* Magic number #1 */
+ said_leaf_node(1, 0x141); // Magic number #1
said_branch_node(2, 3, first);
- said_leaf_node(3, 0x13f); /* Magic number #2 */
+ said_leaf_node(3, 0x13f); // Magic number #2
++said_blessed;
return 0;
}
-
-int
-said_parse_spec(state_t *s, byte *spec)
-{
+int said_parse_spec(state_t *s, byte *spec) {
int nextitem;
said_parse_error = NULL;
@@ -454,29 +391,25 @@ said_parse_spec(state_t *s, byte *spec)
/**** Augmentation ****/
/**********************/
-
-/** primitive functions **/
+// primitive functions
#define AUG_READ_BRANCH(a, br, p) \
- if (tree[p].type != PARSE_TREE_NODE_BRANCH) \
- return 0; \
- a = tree[p].content.branches[br];
+ if (tree[p].type != PARSE_TREE_NODE_BRANCH) \
+ return 0; \
+ a = tree[p].content.branches[br];
#define AUG_READ_VALUE(a, p) \
- if (tree[p].type != PARSE_TREE_NODE_LEAF) \
- return 0; \
- a = tree[p].content.value;
+ if (tree[p].type != PARSE_TREE_NODE_LEAF) \
+ return 0; \
+ a = tree[p].content.value;
#define AUG_ASSERT(i) \
- if (!i) return 0;
-
-static int
-aug_get_next_sibling(parse_tree_node_t *tree, int pos, int *first, int *second)
- /* Returns the next sibling relative to the specified position in 'tree',
- ** sets *first and *second to its augment node values, returns the new position
- ** or 0 if there was no next sibling
- */
-{
+ if (!i) return 0;
+
+static int aug_get_next_sibling(parse_tree_node_t *tree, int pos, int *first, int *second) {
+ // Returns the next sibling relative to the specified position in 'tree',
+ // sets *first and *second to its augment node values, returns the new position
+ // or 0 if there was no next sibling
int seek, valpos;
AUG_READ_BRANCH(pos, 1, pos);
@@ -484,12 +417,12 @@ aug_get_next_sibling(parse_tree_node_t *tree, int pos, int *first, int *second)
AUG_READ_BRANCH(seek, 0, pos);
AUG_ASSERT(seek);
- /* Now retreive first value */
+ // Now retreive first value
AUG_READ_BRANCH(valpos, 0, seek);
AUG_ASSERT(valpos);
AUG_READ_VALUE(*first, valpos);
- /* Get second value */
+ // Get second value
AUG_READ_BRANCH(seek, 1, seek);
AUG_ASSERT(seek);
AUG_READ_BRANCH(valpos, 0, seek);
@@ -499,13 +432,9 @@ aug_get_next_sibling(parse_tree_node_t *tree, int pos, int *first, int *second)
return pos;
}
-
-static int
-aug_get_wgroup(parse_tree_node_t *tree, int pos)
- /* Returns 0 if pos in tree is not the root of a 3-element list, otherwise
- ** it returns the last element (which, in practice, is the word group
- */
-{
+static int aug_get_wgroup(parse_tree_node_t *tree, int pos) {
+ // Returns 0 if pos in tree is not the root of a 3-element list, otherwise
+ // it returns the last element (which, in practice, is the word group
int val;
AUG_READ_BRANCH(pos, 0, pos);
@@ -519,26 +448,19 @@ aug_get_wgroup(parse_tree_node_t *tree, int pos)
return val;
}
-
-static int
-aug_get_base_node(parse_tree_node_t *tree)
-{
+static int aug_get_base_node(parse_tree_node_t *tree) {
int startpos = 0;
AUG_READ_BRANCH(startpos, 1, startpos);
+
return startpos;
}
+// semi-primitive functions
-/** semi-primitive functions **/
-
-
-static int
-aug_get_first_child(parse_tree_node_t *tree, int pos, int *first, int *second)
- /* like aug_get_next_sibling, except that it recurses into the tree and
- ** finds the first child (usually *not* Ayanami Rei) of the current branch
- ** rather than its next sibling.
- */
-{
+static int aug_get_first_child(parse_tree_node_t *tree, int pos, int *first, int *second) {
+ // like aug_get_next_sibling, except that it recurses into the tree and
+ // finds the first child (usually *not* Ayanami Rei) of the current branch
+ // rather than its next sibling.
AUG_READ_BRANCH(pos, 0, pos);
AUG_ASSERT(pos);
AUG_READ_BRANCH(pos, 1, pos);
@@ -547,48 +469,43 @@ aug_get_first_child(parse_tree_node_t *tree, int pos, int *first, int *second)
return aug_get_next_sibling(tree, pos, first, second);
}
-static void
-aug_find_words_recursively(parse_tree_node_t *tree, int startpos,
- int *base_words, int *base_words_nr,
- int *ref_words, int *ref_words_nr,
- int maxwords, int refbranch)
- /* Finds and lists all base (141) and reference (144) words */
-{
+static void aug_find_words_recursively(parse_tree_node_t *tree, int startpos, int *base_words, int *base_words_nr,
+ int *ref_words, int *ref_words_nr, int maxwords, int refbranch) {
+ // Finds and lists all base (141) and reference (144) words */
int major, minor;
int word;
int pos = aug_get_first_child(tree, startpos, &major, &minor);
- /* if (major == WORD_TYPE_REF)
- refbranch = 1;*/
+ //if (major == WORD_TYPE_REF)
+ // refbranch = 1;
while (pos) {
- if ((word = aug_get_wgroup(tree, pos))) { /* found a word */
-
+ if ((word = aug_get_wgroup(tree, pos))) { // found a word
if (!refbranch && major == WORD_TYPE_BASE) {
if ((*base_words_nr) == maxwords) {
sciprintf("Out of regular words\n");
- return; /* return gracefully */
+ return; // return gracefully
}
- base_words[*base_words_nr] = word; /* register word */
+ base_words[*base_words_nr] = word; // register word
++(*base_words_nr);
}
if (major == WORD_TYPE_REF || refbranch) {
if ((*ref_words_nr) == maxwords) {
sciprintf("Out of reference words\n");
- return; /* return gracefully */
+ return; // return gracefully
}
- ref_words[*ref_words_nr] = word; /* register word */
+ ref_words[*ref_words_nr] = word; // register word
++(*ref_words_nr);
}
if (major != WORD_TYPE_SYNTACTIC_SUGAR && major != WORD_TYPE_BASE && major != WORD_TYPE_REF)
sciprintf("aug_find_words_recursively(): Unknown word type %03x\n", major);
- } else /* Did NOT find a word group: Attempt to recurse */
- aug_find_words_recursively(tree, pos, base_words, base_words_nr,
+ } else // Did NOT find a word group: Attempt to recurse
+ aug_find_words_recursively(tree, pos, base_words, base_words_nr,
ref_words, ref_words_nr, maxwords, refbranch || major == WORD_TYPE_REF);
pos = aug_get_next_sibling(tree, pos, &major, &minor);
@@ -596,13 +513,9 @@ aug_find_words_recursively(parse_tree_node_t *tree, int startpos,
}
-static void
-aug_find_words(parse_tree_node_t *tree, int startpos,
- int *base_words, int *base_words_nr,
- int *ref_words, int *ref_words_nr,
- int maxwords)
- /* initializing wrapper for aug_find_words_recursively() */
-{
+static void aug_find_words(parse_tree_node_t *tree, int startpos, int *base_words, int *base_words_nr,
+ int *ref_words, int *ref_words_nr, int maxwords)
+ // initializing wrapper for aug_find_words_recursively()
*base_words_nr = 0;
*ref_words_nr = 0;
@@ -610,10 +523,9 @@ aug_find_words(parse_tree_node_t *tree, int startpos,
}
-static inline int
-aug_contains_word(int *list, int length, int word)
-{
+static inline int aug_contains_word(int *list, int length, int word) {
int i;
+
if (word == ANYWORD)
return (length);
@@ -625,20 +537,13 @@ aug_contains_word(int *list, int length, int word)
}
-static int
-augment_sentence_expression(parse_tree_node_t *saidt, int augment_pos,
- parse_tree_node_t *parset, int parse_branch,
- int major, int minor,
- int *base_words, int base_words_nr,
- int *ref_words, int ref_words_nr);
-
-static int
-augment_match_expression_p(parse_tree_node_t *saidt, int augment_pos,
- parse_tree_node_t *parset, int parse_basepos,
- int major, int minor,
- int *base_words, int base_words_nr,
- int *ref_words, int ref_words_nr)
-{
+static int augment_sentence_expression(parse_tree_node_t *saidt, int augment_pos, parse_tree_node_t *parset,
+ int parse_branch, int major, int minor, int *base_words, int base_words_nr,
+ int *ref_words, int ref_words_nr);
+
+static int augment_match_expression_p(parse_tree_node_t *saidt, int augment_pos, parse_tree_node_t *parset,
+ int parse_basepos, int major, int minor,
+ int *base_words, int base_words_nr, int *ref_words, int ref_words_nr) {
int cmajor, cminor, cpos;
cpos = aug_get_first_child(saidt, augment_pos, &cmajor, &cminor);
if (!cpos) {
@@ -649,12 +554,8 @@ augment_match_expression_p(parse_tree_node_t *saidt, int augment_pos,
scidprintf("Attempting to match (%03x %03x (%03x %03x\n", major, minor, cmajor, cminor);
if ((major == WORD_TYPE_BASE) && (minor == AUGMENT_SENTENCE_MINOR_RECURSE))
- return augment_match_expression_p(saidt, cpos,
- parset, parse_basepos,
- cmajor, cminor,
- base_words, base_words_nr,
- ref_words, ref_words_nr);
-
+ return augment_match_expression_p(saidt, cpos, parset, parse_basepos, cmajor, cminor,
+ base_words, base_words_nr, ref_words, ref_words_nr);
switch (major) {
@@ -667,21 +568,16 @@ augment_match_expression_p(parse_tree_node_t *saidt, int augment_pos,
if (aug_contains_word(base_words, base_words_nr, word))
return 1;
} else if (cminor == AUGMENT_SENTENCE_MINOR_MATCH_PHRASE) {
- if (augment_sentence_expression(saidt, cpos,
- parset, parse_basepos,
- cmajor, cminor,
- base_words, base_words_nr,
- ref_words, ref_words_nr))
+ if (augment_sentence_expression(saidt, cpos, parset, parse_basepos, cmajor, cminor,
+ base_words, base_words_nr, ref_words, ref_words_nr))
return 1;
} else if (cminor == AUGMENT_SENTENCE_MINOR_PARENTHESES) {
int gc_major, gc_minor;
int gchild = aug_get_first_child(saidt, cpos, &gc_major, &gc_minor);
while (gchild) {
- if (augment_match_expression_p(saidt, cpos,
- parset, parse_basepos,
- major, minor,
- base_words, base_words_nr,
+ if (augment_match_expression_p(saidt, cpos, parset, parse_basepos, major,
+ minor, base_words, base_words_nr,
ref_words, ref_words_nr))
return 1;
gchild = aug_get_next_sibling(saidt, gchild, &gc_major, &gc_minor);
@@ -703,22 +599,17 @@ augment_match_expression_p(parse_tree_node_t *saidt, int augment_pos,
if (aug_contains_word(ref_words, ref_words_nr, word))
return 1;
} else if (cminor == AUGMENT_SENTENCE_MINOR_MATCH_PHRASE) {
- if (augment_match_expression_p(saidt, cpos,
- parset, parse_basepos,
- cmajor, cminor,
- base_words, base_words_nr,
- ref_words, ref_words_nr))
+ if (augment_match_expression_p(saidt, cpos, parset, parse_basepos, cmajor, cminor,
+ base_words, base_words_nr, ref_words, ref_words_nr))
return 1;
} else if (cminor == AUGMENT_SENTENCE_MINOR_PARENTHESES) {
int gc_major, gc_minor;
int gchild = aug_get_first_child(saidt, cpos, &gc_major, &gc_minor);
while (gchild) {
- if (augment_match_expression_p(saidt, cpos,
- parset, parse_basepos,
- major, minor,
- base_words, base_words_nr,
- ref_words, ref_words_nr))
+ if (augment_match_expression_p(saidt, cpos, parset, parse_basepos, major,
+ minor, base_words, base_words_nr,
+ ref_words, ref_words_nr))
return 1;
gchild = aug_get_next_sibling(saidt, gchild, &gc_major, &gc_minor);
}
@@ -731,11 +622,8 @@ augment_match_expression_p(parse_tree_node_t *saidt, int augment_pos,
break;
case AUGMENT_SENTENCE_PART_BRACKETS:
- if (augment_match_expression_p(saidt, cpos,
- parset, parse_basepos,
- cmajor, cminor,
- base_words, base_words_nr,
- ref_words, ref_words_nr))
+ if (augment_match_expression_p(saidt, cpos, parset, parse_basepos, cmajor, cminor,
+ base_words, base_words_nr, ref_words, ref_words_nr))
return 1;
scidprintf("Didn't match subexpression; checking sub-bracked predicate %03x\n", cmajor);
@@ -763,34 +651,25 @@ augment_match_expression_p(parse_tree_node_t *saidt, int augment_pos,
}
scidprintf("Generic failure\n");
+
return 0;
}
-static int
-augment_sentence_expression(parse_tree_node_t *saidt, int augment_pos,
- parse_tree_node_t *parset, int parse_branch,
- int major, int minor,
- int *base_words, int base_words_nr,
- int *ref_words, int ref_words_nr)
-{
+static int augment_sentence_expression(parse_tree_node_t *saidt, int augment_pos, parse_tree_node_t *parset,
+ int parse_branch, int major, int minor, int *base_words, int base_words_nr,
+ int *ref_words, int ref_words_nr) {
int check_major, check_minor;
int check_pos = aug_get_first_child(saidt, augment_pos, &check_major, &check_minor);
do {
- if (!(augment_match_expression_p(saidt, check_pos, parset, parse_branch,
- check_major, check_minor, base_words, base_words_nr,
- ref_words, ref_words_nr)))
+ if (!(augment_match_expression_p(saidt, check_pos, parset, parse_branch, check_major, check_minor,
+ base_words, base_words_nr, ref_words, ref_words_nr)))
return 0;
} while ((check_pos = aug_get_next_sibling(saidt, check_pos, &check_major, &check_minor)));
+
return 1;
}
-
-
-static int
-augment_sentence_part(parse_tree_node_t *saidt, int augment_pos,
- parse_tree_node_t *parset, int parse_basepos,
- int major, int minor)
-{
+static int augment_sentence_part(parse_tree_node_t *saidt, int augment_pos, parse_tree_node_t *parset, int parse_basepos, int major, int minor) {
int pmajor, pminor;
int parse_branch = parse_basepos;
int optional = 0;
@@ -798,9 +677,8 @@ augment_sentence_part(parse_tree_node_t *saidt, int augment_pos,
scidprintf("Augmenting (%03x %03x\n", major, minor);
- if (major == AUGMENT_SENTENCE_PART_BRACKETS) { /* '[/ foo]' is true if '/foo' or if there
- ** exists no x for which '/x' is true
- */
+ if (major == AUGMENT_SENTENCE_PART_BRACKETS) { // '[/ foo]' is true if '/foo' or if there
+ // exists no x for which '/x' is true
if ((augment_pos = aug_get_first_child(saidt, augment_pos, &major, &minor))) {
scidprintf("Optional part: Now augmenting (%03x %03x\n", major, minor);
optional = 1;
@@ -810,14 +688,13 @@ augment_sentence_part(parse_tree_node_t *saidt, int augment_pos,
}
}
- if ((major < 0x141)
- || (major > 0x143)) {
+ if ((major < 0x141) || (major > 0x143)) {
scidprintf("augment_sentence_part(): Unexpected sentence part major number %03x\n", major);
return 0;
}
- while ((parse_branch = aug_get_next_sibling(parset, parse_branch, &pmajor, &pminor)))
- if (pmajor == major) { /* found matching sentence part */
+ while ((parse_branch = aug_get_next_sibling(parset, parse_branch, &pmajor, &pminor))) {
+ if (pmajor == major) { // found matching sentence part
int success;
int base_words_nr;
int ref_words_nr;
@@ -828,8 +705,7 @@ augment_sentence_part(parse_tree_node_t *saidt, int augment_pos,
#endif
scidprintf("Found match with pminor = %03x\n", pminor);
- aug_find_words(parset, parse_branch, base_words, &base_words_nr,
- ref_words, &ref_words_nr, AUGMENT_MAX_WORDS);
+ aug_find_words(parset, parse_branch, base_words, &base_words_nr, ref_words, &ref_words_nr, AUGMENT_MAX_WORDS);
foundwords |= (ref_words_nr | base_words_nr);
#ifdef SCI_DEBUG_PARSE_TREE_AUGMENTATION
sciprintf("%d base words:", base_words_nr);
@@ -841,28 +717,26 @@ augment_sentence_part(parse_tree_node_t *saidt, int augment_pos,
sciprintf("\n");
#endif
- success = augment_sentence_expression(saidt, augment_pos,
- parset, parse_basepos, major, minor,
- base_words, base_words_nr,
- ref_words, ref_words_nr);
+ success = augment_sentence_expression(saidt, augment_pos, parset, parse_basepos, major, minor,
+ base_words, base_words_nr, ref_words, ref_words_nr);
if (success) {
scidprintf("SUCCESS on augmenting (%03x %03x\n", major, minor);
return 1;
}
}
+ }
if (optional && (foundwords == 0)) {
scidprintf("Found no words and optional branch => SUCCESS on augmenting (%03x %03x\n", major, minor);
return 1;
}
scidprintf("FAILURE on augmenting (%03x %03x\n", major, minor);
+
return 0;
}
-static int
-augment_parse_nodes(parse_tree_node_t *parset, parse_tree_node_t *saidt)
-{
+static int augment_parse_nodes(parse_tree_node_t *parset, parse_tree_node_t *saidt) {
int augment_basepos = 0;
int parse_basepos;
int major, minor;
@@ -879,15 +753,14 @@ augment_parse_nodes(parse_tree_node_t *parset, parse_tree_node_t *saidt)
sciprintf("augment_parse_nodes(): Said tree is corrupt\n");
return 0;
}
- while ((augment_basepos = aug_get_next_sibling(saidt, augment_basepos, &major, &minor))) {
- if ((major == 0x14b)
- && (minor == SAID_LONG(SAID_GT)))
- dontclaim = 1; /* special case */
- else /* normal sentence part */
+ while ((augment_basepos = aug_get_next_sibling(saidt, augment_basepos, &major, &minor))) {
+ if ((major == 0x14b) && (minor == SAID_LONG(SAID_GT)))
+ dontclaim = 1; // special case
+ else // normal sentence part
if (!(augment_sentence_part(saidt, augment_basepos, parset, parse_basepos, major, minor))) {
scidprintf("Returning failure\n");
- return 0; /* fail */
+ return 0; // fail
}
}
@@ -895,7 +768,8 @@ augment_parse_nodes(parse_tree_node_t *parset, parse_tree_node_t *saidt)
if (dontclaim)
return SAID_PARTIAL_MATCH;
- else return 1; /* full match */
+ else
+ return 1; // full match
}
@@ -903,15 +777,12 @@ augment_parse_nodes(parse_tree_node_t *parset, parse_tree_node_t *saidt)
/**** Main code ****/
/*******************/
-int
-said(state_t *s, byte *spec, int verbose)
-{
+int said(state_t *s, byte *spec, int verbose) {
int retval;
parse_tree_node_t *parse_tree_ptr = s->parser_nodes;
if (s->parser_valid) {
-
if (said_parse_spec(s, spec)) {
sciprintf("Offending spec was: ");
vocab_decypher_said_block(s, spec);
@@ -919,25 +790,23 @@ said(state_t *s, byte *spec, int verbose)
}
if (verbose)
- vocab_dump_parse_tree("Said-tree", said_tree); /* Nothing better to do yet */
+ vocab_dump_parse_tree("Said-tree", said_tree); // Nothing better to do yet
retval = augment_parse_nodes(parse_tree_ptr, &(said_tree[0]));
if (!retval)
return SAID_NO_MATCH;
else if (retval != SAID_PARTIAL_MATCH)
return SAID_FULL_MATCH;
- else return SAID_PARTIAL_MATCH;
+ else
+ return SAID_PARTIAL_MATCH;
}
return SAID_NO_MATCH;
}
-
#ifdef SAID_DEBUG_PROGRAM
-int
-main (int argc, char *argv)
-{
+int main (int argc, char *argv) {
byte block[] = {0x01, 0x00, 0xf8, 0xf5, 0x02, 0x01, 0xf6, 0xf2, 0x02, 0x01, 0xf2, 0x01, 0x03, 0xff};
state_t s;
con_passthrough = 1;