6 void tree_destroy(KeyBindingTree *tree)
11 tree_destroy(tree->next_sibling);
12 c = tree->first_child;
15 for (it = tree->keylist; it != NULL; it = it->next)
17 g_list_free(tree->keylist);
18 keyaction_free(&tree->action);
25 KeyBindingTree *tree_build(GList *keylist)
28 KeyBindingTree *ret = NULL, *p;
30 if (g_list_length(keylist) <= 0)
31 return NULL; /* nothing in the list.. */
33 for (it = g_list_last(keylist); it != NULL; it = it->prev) {
35 ret = g_new(KeyBindingTree, 1);
36 ret->next_sibling = NULL;
40 /* this is the first built node, the bottom node of the tree */
41 ret->keylist = g_list_copy(keylist); /* shallow copy */
42 for (it = ret->keylist; it != NULL; it = it->next) /* deep copy */
43 it->data = g_strdup(it->data);
46 if (!translate_key(it->data, &ret->state, &ret->key)) {
54 void tree_assimilate(KeyBindingTree *node)
56 KeyBindingTree *a, *b, *tmp, *last;
58 if (firstnode == NULL) {
59 /* there are no nodes at this level yet */
67 if (!(a->state == b->state && a->key == b->key)) {
76 if (!(last->state == b->state && last->key == b->key))
77 last->next_sibling = b;
79 last->first_child = b->first_child;
85 KeyBindingTree *tree_find(KeyBindingTree *search, gboolean *conflict)
87 KeyBindingTree *a, *b;
94 if (!(a->state == b->state && a->key == b->key)) {
97 if ((a->first_child == NULL) == (b->first_child == NULL)) {
98 if (a->first_child == NULL) {
99 /* found it! (return the actual node, not the search's) */
104 return NULL; /* the chain status' don't match (conflict!) */
110 return NULL; /* it just isn't in here */