/** * Read table of [link, domain type]. * This tells us what domain type each link belongs to. * This lookup table *must* be defined in the knowledge file. */ static void read_starting_link_table(pp_knowledge *k) { const char *p; const char label[] = "STARTING_LINK_TYPE_TABLE"; int i, n_tokens; if (!pp_lexer_set_label(k->lt, label)) { prt_error("Fatal error: post_process: Couldn't find starting link table %s",label); exit(1); } n_tokens = pp_lexer_count_tokens_of_label(k->lt); if (n_tokens %2) { prt_error("Fatal error: post_process: Link table must have format [<link> <domain name>]+"); exit(1); } k->nStartingLinks = n_tokens/2; k->starting_link_lookup_table = (StartingLinkAndDomain*) xalloc((1+k->nStartingLinks)*sizeof(StartingLinkAndDomain)); for (i=0; i<k->nStartingLinks; i++) { /* read the starting link itself */ k->starting_link_lookup_table[i].starting_link = string_set_add(pp_lexer_get_next_token_of_label(k->lt),k->string_set); /* read the domain type of the link */ p = pp_lexer_get_next_token_of_label(k->lt); check_domain_is_legal(p); k->starting_link_lookup_table[i].domain = (int) p[0]; } /* end sentinel */ k->starting_link_lookup_table[k->nStartingLinks].domain = -1; }
static pp_linkset *read_link_set(pp_knowledge *k, const char *label, String_set *ss) { /* read link set, marked by label in knowledge file, into a set of links whose handle is returned. Return NULL if link set not defined in file, in which case the set is taken to be empty. */ int n_strings,i; pp_linkset *ls; if (!pp_lexer_set_label(k->lt, label)) { if (verbosity_level(+D_PPK)) prt_error("Warning: File %s: Link set %s not defined: assuming empty\n", k->path, label); n_strings = 0; } else { n_strings = pp_lexer_count_tokens_of_label(k->lt); if (-1 == n_strings) return &LINK_SET_ERROR; } ls = pp_linkset_open(n_strings); for (i=0; i<n_strings; i++) pp_linkset_add(ls, string_set_add(pp_lexer_get_next_token_of_label(k->lt),ss)); return ls; }
/** * Read table of [link, domain type]. * This tells us what domain type each link belongs to. * This lookup table *must* be defined in the knowledge file. */ static bool read_starting_link_table(pp_knowledge *k) { const char *p; const char label[] = "STARTING_LINK_TYPE_TABLE"; size_t i, even; int n_tokens; if (!pp_lexer_set_label(k->lt, label)) { prt_error("Error: File %s: Couldn't find starting link table %s\n", k->path, label); return false; } n_tokens = pp_lexer_count_tokens_of_label(k->lt); if (-1 == n_tokens) return false; even = n_tokens % 2; if(0 != even) { prt_error("Error: Link table must have format [<link> <domain name>]+\n"); return false; } k->nStartingLinks = n_tokens/2; k->starting_link_lookup_table = (StartingLinkAndDomain*) malloc((1+k->nStartingLinks)*sizeof(StartingLinkAndDomain)); for (i=0; i<k->nStartingLinks; i++) { /* read the starting link itself */ k->starting_link_lookup_table[i].starting_link = string_set_add(pp_lexer_get_next_token_of_label(k->lt),k->string_set); /* read the domain type of the link */ p = pp_lexer_get_next_token_of_label(k->lt); if (!check_domain_is_legal(k, p)) return false; k->starting_link_lookup_table[i].domain = (int) p[0]; } /* end sentinel */ k->starting_link_lookup_table[k->nStartingLinks].domain = -1; return true; }
static pp_linkset *read_link_set(pp_knowledge *k, const char *label, String_set *ss) { /* read link set, marked by label in knowledge file, into a set of links whose handle is returned. Return NULL if link set not defined in file, in which case the set is taken to be empty. */ int n_strings,i; pp_linkset *ls; if (!pp_lexer_set_label(k->lt, label)) { if (verbosity>0) printf("PP warning: Link set %s not defined: assuming empty.\n",label); n_strings = 0; } else n_strings = pp_lexer_count_tokens_of_label(k->lt); ls = pp_linkset_open(n_strings); for (i=0; i<n_strings; i++) pp_linkset_add(ls, string_set_add(pp_lexer_get_next_token_of_label(k->lt),ss)); return ls; }
static void read_connected_rule(pp_knowledge *k, const char *label) { /* This is a degenerate class of rules: either a single rule asserting connectivity is there, or it isn't. The only information in the rule (besides its presence) is the error message to display if the rule is violated */ k->connected_rules = (pp_rule *) xalloc (sizeof(pp_rule)); if (!pp_lexer_set_label(k->lt, label)) { k->connected_rules[0].msg=0; /* rule not there */ if (verbosity>0) printf("PP warning: Not using 'link is connected' rule\n"); return; } if (pp_lexer_count_tokens_of_label(k->lt)>1) { prt_error("Fatal Error: post_process(): Invalid syntax in %s", label); exit(1); } k->connected_rules[0].msg = string_set_add(pp_lexer_get_next_token_of_label(k->lt), k->string_set); }