5 void tree_destroy(KeyBindingTree *tree)
10 tree_destroy(tree->next_sibling);
11 c = tree->first_child;
14 for (it = tree->keylist; it != NULL; it = it->next)
16 g_list_free(tree->keylist);
17 action_free(tree->action);
24 KeyBindingTree *tree_build(GList *keylist)
27 KeyBindingTree *ret = NULL, *p;
29 if (g_list_length(keylist) <= 0)
30 return NULL; /* nothing in the list.. */
32 for (it = g_list_last(keylist); it != NULL; it = it->prev) {
34 ret = g_new0(KeyBindingTree, 1);
38 /* this is the first built node, the bottom node of the tree */
39 ret->keylist = g_list_copy(keylist); /* shallow copy */
40 for (it = ret->keylist; it != NULL; it = it->next) /* deep copy */
41 it->data = g_strdup(it->data);
44 if (!translate_key(it->data, &ret->state, &ret->key)) {
52 void tree_assimilate(KeyBindingTree *node)
54 KeyBindingTree *a, *b, *tmp, *last;
56 if (firstnode == NULL) {
57 /* there are no nodes at this level yet */
65 if (!(a->state == b->state && a->key == b->key)) {
74 if (!(last->state == b->state && last->key == b->key))
75 last->next_sibling = b;
77 last->first_child = b->first_child;
83 KeyBindingTree *tree_find(KeyBindingTree *search, gboolean *conflict)
85 KeyBindingTree *a, *b;
92 if (!(a->state == b->state && a->key == b->key)) {
95 if ((a->first_child == NULL) == (b->first_child == NULL)) {
96 if (a->first_child == NULL) {
97 /* found it! (return the actual node, not the search's) */
102 return NULL; /* the chain status' don't match (conflict!) */
108 return NULL; /* it just isn't in here */