static Clause conflicts(Clause a, Clause b) { if (!unit_clause(a) || !unit_clause(b)) return NULL; else if (a->literals->sign == b->literals->sign) return NULL; else { Clause empty = NULL; Term a_atom = a->literals->atom; Term b_atom = b->literals->atom; Context ca = get_context(); Context cb = get_context(); Trail tr = NULL; if (unify(a_atom, ca, b_atom, cb, &tr)) { Ilist j = NULL; undo_subst(tr); empty = get_clause(); j = ilist_append(j, a->id); j = ilist_append(j, 1); j = ilist_append(j, b->id); j = ilist_append(j, 1); empty->justification = resolve_just(j, BINARY_RES_JUST); upward_clause_links(empty); assign_clause_id(empty); } free_context(ca); free_context(cb); return empty; } } /* conflicts */
static int convert_str_to_msg(const char *optarg) { int tmp, retval = 0; if (isdigit(optarg[0])) { errno = 0; tmp = strtoul(optarg, NULL, 10); if (errno) { fprintf(stderr, "Numeric message type conversion error (%s) for %s\n", strerror(errno), optarg); retval = -1; } } else { tmp = audit_name_to_msg_type(optarg); if (tmp < 0) retval = -1; } if (retval == 0) { if (event_type == NULL) { event_type = malloc(sizeof(ilist)); if (event_type == NULL) return -1; ilist_create(event_type); } ilist_append(event_type, tmp, 1, 0); } return retval; }
int v_makeloc(struct command *c) { int n; int sk; int kind; sk = lookup(subkind_s, c->parse[1]); if (sk < 0) { wout(c->who, "Unknown subkind."); return FALSE; } if (sk == sub_galley || sk == sub_roundship) kind = T_ship; else kind = T_loc; n = new_ent(kind, sk); if (n < 0) { wout(c->who, "Out of boxes."); return FALSE; } set_where(n, subloc(c->who)); wout(c->who, "Created %s", box_name(n)); if (sk == sub_temple) ilist_append(&p_subloc(n)->teaches, sk_religion); return TRUE; }
static Clause cd(Clause maj, Clause min) { if (!unit_clause(maj) || !unit_clause(min)) return NULL; else if (!maj->literals->sign || !min->literals->sign) return NULL; else { Term a = ARG(maj->literals->atom,0); Term b = ARG(min->literals->atom,0); if (ARITY(a) != 2) return NULL; else { Clause resolvent = NULL; Term a0 = ARG(a,0); Term a1 = ARG(a,1); Context ca = get_context(); Context cb = get_context(); Trail tr = NULL; if (unify(a0, ca, b, cb, &tr)) { Term r = apply(a1, ca); Term r_atom = build_unary_term(SYMNUM(maj->literals->atom), r); Literal r_literal = get_literal(); Ilist j = NULL; r_literal->sign = TRUE; r_literal->atom = r_atom; resolvent = get_clause(); append_literal(resolvent, r_literal); j = ilist_append(j, maj->id); j = ilist_append(j, 1); j = ilist_append(j, min->id); j = ilist_append(j, 1); resolvent->justification = resolve_just(j, BINARY_RES_JUST); upward_clause_links(resolvent); renumber_variables(resolvent, MAX_VARS); undo_subst(tr); } free_context(ca); free_context(cb); return resolvent; } } } /* cd */
void add_to_here_list(int loc, int who) { assert(!in_here_list(loc, who)); ilist_append(&(p_loc_info(loc)->here_list), who); assert(in_here_list(loc, who)); }
static Clause resolve(Clash first, Just_type rule) { Clause r = get_clause(); Clause nuc = first->nuc_lit->atom->container; Ilist j = ilist_append(NULL, nuc->id); Clash p; int n; /* First, include literals in the nucleus. */ for (p = first; p != NULL; p = p->next, n++) { if (!p->clashed) append_literal(r, apply_lit(p->nuc_lit, p->nuc_subst)); } r->attributes = cat_att(r->attributes, inheritable_att_instances(nuc->attributes, first->nuc_subst)); /* Next, include literals in the satellites. */ n = 1; /* n-th nucleus literal, starting with 1 */ for (p = first; p != NULL; p = p->next, n++) { if (p->clashed) { Literal lit; Clause sat = p->sat_lit->atom->container; j = ilist_append(j, n); j = ilist_append(j, sat->id); j = ilist_append(j, lit_position(sat, p->sat_lit)); for (lit = sat->literals; lit != NULL; lit = lit->next) { if (lit != p->sat_lit) append_literal(r, apply_lit(lit, p->sat_subst)); } r->attributes = cat_att(r->attributes, inheritable_att_instances(sat->attributes, p->sat_subst)); } } r->justification = resolve_just(j, rule); upward_clause_links(r); return r; } /* resolve */
void kill_stack_ocean(int who) { static ilist l = NULL; int i; int where; ilist_clear(&l); loop_stack(who, i) { ilist_append(&l, i); }
Node *pool_append(PoolObject *pool, Data data){ if (pool == NULL) return NULL; if (list_is_empty(&pool->free_list)) if (append_array(pool) < 0) return NULL; Node *node = list_remove_first(&pool->free_list); node->value = data; hash_table_append(&pool->table, node); if (data.counter == 0){ ilist_append(&pool->list_zero, node); } return node; }
int ilist_add_if_uniq(ilist *l, int num) { register int_node* cur; cur = l->head; while (cur) { if (cur->num == num) return 0; else cur = cur->next; } /* No matches, append to the end */ ilist_append(l, num); return 1; }
static void add_here(int who, ilist *l) { int i; struct loc_info *p; assert(valid_box(who)); ilist_append(l, who); p = rp_loc_info(who); assert(p != NULL); for (i = 0; i < ilist_len(p->here_list); i++) add_here(p->here_list[i], l); }
void all_stack(int who, ilist *l) { int i; struct loc_info *p; assert(valid_box(who)); ilist_clear(l); ilist_append(l, who); p = rp_loc_info(who); if (p == NULL) return; for (i = 0; i < ilist_len(p->here_list); i++) if (kind(p->here_list[i]) == T_char) add_char_here(p->here_list[i], l); }