static int read_any_identity(xmlNode *an, cp_any_identity_t **dst) { cp_domain_t *domain, *last_domain = NULL; cp_except_domain_t *except, *last_except = NULL; xmlNode *n; int res = RES_OK; *dst = (cp_any_identity_t*)cds_malloc(sizeof(cp_any_identity_t)); if (!*dst) return RES_MEMORY_ERR; memset(*dst, 0, sizeof(**dst)); n = an->children; while (n) { if (n->type == XML_ELEMENT_NODE) { if (cmp_node(n, "domain", common_policy_ns) >= 0) { res = read_domain(n, &domain); if (res != 0) break; LINKED_LIST_ADD((*dst)->domains, last_domain, domain); } else if (cmp_node(n, "except-domain", common_policy_ns) >= 0) { res = read_except_domain(n, &except); if (res != 0) break; LINKED_LIST_ADD((*dst)->except_domains, last_except, except); } } n = n->next; } return res; }
int read_service(xmlNode *list_node, service_t **dst) { int res = 0; xmlAttr *a; const char *a_val; xmlNode *n; int first_node; DEBUG_LOG("read_service(): called\n"); /* allocate memory and prepare empty node */ if (!dst) return -1; *dst = (service_t*)cds_malloc(sizeof(service_t)); if (!(*dst)) return -2; memset(*dst, 0, sizeof(service_t)); /* get attributes */ a = find_attr(list_node->properties, "uri"); if (a) { a_val = get_attr_value(a); if (a_val) (*dst)->uri = zt_strdup(a_val); } /* read child nodes */ n = list_node->children; first_node = 1; while (n) { if (n->type == XML_ELEMENT_NODE) { if (first_node) { /* element must be list or resource-list */ if (cmp_node(n, "list", rls_namespace) >= 0) { res = read_list(n, &(*dst)->content.list, 0); if ( (res == 0) && ((*dst)->content.list) ) { (*dst)->content_type = stc_list; } else return -1; } else if (cmp_node(n, "resource-list", rls_namespace) >= 0) { a_val = get_node_value(n); if (a_val) (*dst)->content.resource_list = zt_strdup(a_val); else (*dst)->content.resource_list = NULL; (*dst)->content_type = stc_resource_list; } else return -1; first_node = 0; } else { /* packages node */ if (cmp_node(n, "packages", rls_namespace) >= 0) { res = read_packages(n, &(*dst)->packages); } break; } } n = n->next; } return 0; }
static int read_names(xmlNode *entry_node, display_name_t **dst) { xmlNode *n; display_name_t *name, *last; int res = 0; last = NULL; *dst = NULL; n = entry_node->children; while (n) { if (n->type == XML_ELEMENT_NODE) { if (cmp_node(n, "display-name", rl_namespace) >= 0) { res = read_name(n, &name); if (res == 0) { if (name) { SEQUENCE_ADD((*dst), last, name); name = NULL; } } else break; } } n = n->next; } return res; }
static int read_packages(xmlNode *list_node, packages_t **dst) { int res = 0; xmlNode *n; package_t *p, *last; /* allocate memory and prepare empty node */ if (!dst) return -1; *dst = (packages_t*)cds_malloc(sizeof(packages_t)); if (!(*dst)) return -2; memset(*dst, 0, sizeof(packages_t)); /* read packages */ n = list_node->children; last = NULL; while (n) { if (n->type == XML_ELEMENT_NODE) { if (cmp_node(n, "package", rls_namespace) >= 0) { res = read_package(n, &p); if ((res == 0) && p) { SEQUENCE_ADD((*dst)->package, last, p); } } } n = n->next; } return 0; }
/* 一番確率の低いノードを消去する*/ static void remove_min_node(struct lattice_info *info, struct node_list_head *node_list) { struct lattice_node* node = node_list->head; struct lattice_node* previous_node = NULL; struct lattice_node* min_node = node; struct lattice_node* previous_min_node = NULL; /* 一番確率の低いノードを探す */ while (node) { if (cmp_node(node, min_node) < 0) { previous_min_node = previous_node; min_node = node; } previous_node = node; node = node->next; } /* 一番確率の低いノードを削除する */ if (previous_min_node) { previous_min_node->next = min_node->next; } else { node_list->head = min_node->next; } release_lattice_node(info, min_node); node_list->nr_nodes --; }
void down_heap(node_heap *h, oct_node p) { int n = p->heap_idx, m; while (1) { m = n * 2; if (m >= h->n) break; if (m + 1 < h->n && cmp_node(h->buf[m], h->buf[m + 1]) > 0) m++; if (cmp_node(p, h->buf[m]) <= 0) break; h->buf[n] = h->buf[m]; h->buf[n]->heap_idx = n; n = m; } h->buf[n] = p; p->heap_idx = n; }
static int read_conditions(xmlNode *cn, cp_conditions_t **dst) { xmlNode *n; int res = RES_OK; cp_sphere_t *sphere, * last_sphere = NULL; if ((!cn) || (!dst)) return RES_INTERNAL_ERR; *dst = (cp_conditions_t*)cds_malloc(sizeof(cp_conditions_t)); if (!(*dst)) return RES_MEMORY_ERR; memset(*dst, 0, sizeof(cp_conditions_t)); n = cn->children; while (n) { if (n->type == XML_ELEMENT_NODE) { if (cmp_node(n, "validity", common_policy_ns) >= 0) { /* FIXME: free existing validity */ res = read_validity(n, &(*dst)->validity); if (res != 0) break; } else { if (cmp_node(n, "identity", common_policy_ns) >= 0) { /* FIXME: free existing identity */ res = read_identity(n, &(*dst)->identity); if (res != 0) break; } else { if (cmp_node(n, "sphere", common_policy_ns) >= 0) { res = read_sphere(n, &sphere); if (res != 0) break; LINKED_LIST_ADD((*dst)->spheres, last_sphere, sphere); } /* else process other elements ? */ } } } n = n->next; } return res; }
static int read_common_rules(xmlNode *root, cp_ruleset_t **dst, cp_read_actions_func read_actions, cp_free_actions_func free_actions) { cp_ruleset_t *rs = NULL; cp_rule_t *r, *last = NULL; xmlNode *n; int res = RES_OK; if (!dst) return RES_INTERNAL_ERR; else *dst = NULL; if (!root) return RES_INTERNAL_ERR; if (cmp_node(root, "ruleset", common_policy_ns) < 0) { ERROR_LOG("document is not a ruleset \n"); return RES_INTERNAL_ERR; } rs = (cp_ruleset_t*)cds_malloc(sizeof(cp_ruleset_t)); if (!rs) return RES_MEMORY_ERR; *dst = rs; memset(rs, 0, sizeof(*rs)); /* read rules in ruleset */ n = root->children; while (n) { if (n->type == XML_ELEMENT_NODE) { if (cmp_node(n, "rule", common_policy_ns) >= 0) { res = read_rule(n, &r, read_actions, free_actions); if (res == 0) { if (r) LINKED_LIST_ADD(rs->rules, last, r); } else break; } } n = n->next; } return res; }
static int read_resource_lists(xmlNode *root, resource_lists_t **dst) { resource_lists_t *rl; /* xmlAttr *a; */ xmlNode *n; list_t *l, *last_l; int res = 0; if (!dst) return -1; else *dst = NULL; if (!root) return -1; if (cmp_node(root, "resource-lists", rl_namespace) < 0) { ERROR_LOG("document is not a resource-lists\n"); return -1; } rl = (resource_lists_t*)cds_malloc(sizeof(resource_lists_t)); if (!rl) return -2; *dst = rl; rl->lists = NULL; last_l = NULL; n = root->children; while (n) { if (n->type == XML_ELEMENT_NODE) { if (cmp_node(n, "list", rl_namespace) >= 0) { res = read_list(n, &l, 0); if (res == 0) { if (l) SEQUENCE_ADD(rl->lists, last_l, l); } else break; } } n = n->next; } return res; }
bool node_in_list(t_points *list, t_points *node) { t_points *it; it = list->next; while (it != list) { if (cmp_node(it, node)) return (true); it = it->next; } return (false); }
/* * 構成中のラティスにノードを追加する */ static void push_node(struct lattice_info* info, struct lattice_node* new_node, int position) { struct lattice_node* node; struct lattice_node* previous_node = NULL; if (anthy_splitter_debug_flags() & SPLITTER_DEBUG_LN) { print_lattice_node(info, new_node); } /* 先頭のnodeが無ければ無条件に追加 */ node = info->lattice_node_list[position].head; if (!node) { info->lattice_node_list[position].head = new_node; info->lattice_node_list[position].nr_nodes ++; return; } while (node->next) { /* 余計なノードを追加しないための枝刈り */ if (new_node->seg_class == node->seg_class && new_node->border == node->border) { /* segclassが同じで、始まる位置が同じなら */ switch (cmp_node(new_node, node)) { case 0: case 1: /* 新しい方が確率が大きいか学習によるものなら、古いのと置き換え*/ if (previous_node) { previous_node->next = new_node; } else { info->lattice_node_list[position].head = new_node; } new_node->next = node->next; release_lattice_node(info, node); break; case -1: /* そうでないなら削除 */ release_lattice_node(info, new_node); break; } return; } previous_node = node; node = node->next; } /* 最後のノードの後ろに追加 */ node->next = new_node; info->lattice_node_list[position].nr_nodes ++; }
static int read_rls_services(xmlNode *root, rls_services_t **dst) { /* xmlAttr *a; */ xmlNode *n; service_t *l, *last_l; int res = 0; if (!root) return -1; if (!dst) return -1; if (cmp_node(root, "rls-services", rls_namespace) < 0) { ERROR_LOG("document is not a rls-services\n"); return -1; } *dst = (rls_services_t*)cds_malloc(sizeof(rls_services_t)); if (!(*dst)) return -2; (*dst)->rls_services = NULL; last_l = NULL; n = root->children; while (n) { if (n->type == XML_ELEMENT_NODE) { if (cmp_node(n, "service", rls_namespace) >= 0) { res = read_service(n, &l); if (res == 0) { if (l) SEQUENCE_ADD((*dst)->rls_services, last_l, l); } else break; } } n = n->next; } return res; }
void up_heap(node_heap *h, oct_node p) { int n = p->heap_idx; oct_node prev; while (n > 1) { prev = h->buf[n / 2]; if (cmp_node(p, prev) >= 0) break; h->buf[n] = prev; prev->heap_idx = n; n /= 2; } h->buf[n] = p; p->heap_idx = n; }
/* いわゆるビタビアルゴリズムを使用して経路を選ぶ */ static void choose_path(struct lattice_info* info, int to) { /* 最後まで到達した遷移のなかで一番確率の大きいものを選ぶ */ struct lattice_node* node; struct lattice_node* best_node = NULL; int last = to; while (!info->lattice_node_list[last].head) { /* 最後の文字まで遷移していなかったら後戻り */ --last; } for (node = info->lattice_node_list[last].head; node; node = node->next) { if (cmp_node(node, best_node) > 0) { best_node = node; } } if (!best_node) { return; } /* 遷移を逆にたどりつつ文節の切れ目を記録 */ node = best_node; if (anthy_splitter_debug_flags() & SPLITTER_DEBUG_LN) { printf("choose_path()\n"); } while (node->before_node) { info->sc->word_split_info->best_seg_class[node->border] = node->seg_class; anthy_mark_border_by_metaword(info->sc, node->mw); /**/ if (anthy_splitter_debug_flags() & SPLITTER_DEBUG_LN) { print_lattice_node(info, node); } /**/ node = node->before_node; } }
Node *limit() const { Node *tmp = cmp_node(); return (tmp && tmp->req()==3) ? tmp->in(2) : NULL; }
Node *incr() const { Node *tmp = cmp_node(); return (tmp && tmp->req()==3) ? tmp->in(1) : NULL; }
int read_list(xmlNode *list_node, list_t **dst, int read_content_only) { int res = 0; xmlAttr *a; const char *a_val; xmlNode *n; list_content_t *l, *last_l; /* allocate memory and prepare empty node */ if (!dst) return -1; *dst = (list_t*)cds_malloc(sizeof(list_t)); if (!(*dst)) return -2; memset(*dst, 0, sizeof(list_t)); /* get attributes */ if (!read_content_only) { a = find_attr(list_node->properties, "name"); if (a) { a_val = get_attr_value(a); if (a_val) (*dst)->name = zt_strdup(a_val); } } /* read entries */ last_l = NULL; n = list_node->children; while (n) { if (n->type == XML_ELEMENT_NODE) { l = (list_content_t*) cds_malloc(sizeof(list_content_t)); if (!l) return -1; memset(l, 0, sizeof(*l)); if (cmp_node(n, "list", rl_namespace) >= 0) { res = read_list(n, &l->u.list, 0); if (res == 0) { if (l->u.list) { l->type = lct_list; SEQUENCE_ADD((*dst)->content, last_l, l); l = NULL; } } else break; } if (cmp_node(n, "entry", rl_namespace) >= 0) { res = read_entry(n, &l->u.entry); if (res == 0) { if (l->u.entry) { l->type = lct_entry; SEQUENCE_ADD((*dst)->content, last_l, l); l = NULL; } } else break; } if (cmp_node(n, "entry-ref", rl_namespace) >= 0) { res = read_entry_ref(n, &l->u.entry_ref); if (res == 0) { if (l->u.entry_ref) { l->type = lct_entry_ref; SEQUENCE_ADD((*dst)->content, last_l, l); l = NULL; } } else break; } if (cmp_node(n, "external", rl_namespace) >= 0) { res = read_external(n, &l->u.external); if (res == 0) { if (l->u.external) { l->type = lct_external; SEQUENCE_ADD((*dst)->content, last_l, l); l = NULL; } } else break; } if (l) { cds_free(l); l = NULL; } } n = n->next; } return 0; }