]>
Dogcows Code - chaz/openbox/blob - plugins/keyboard/tree.c
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_new(KeyBindingTree
, 1);
35 ret
->next_sibling
= NULL
;
39 /* this is the first built node, the bottom node of the tree */
40 ret
->keylist
= g_list_copy(keylist
); /* shallow copy */
41 for (it
= ret
->keylist
; it
!= NULL
; it
= it
->next
) /* deep copy */
42 it
->data
= g_strdup(it
->data
);
45 if (!translate_key(it
->data
, &ret
->state
, &ret
->key
)) {
53 void tree_assimilate(KeyBindingTree
*node
)
55 KeyBindingTree
*a
, *b
, *tmp
, *last
;
57 if (firstnode
== NULL
) {
58 /* there are no nodes at this level yet */
66 if (!(a
->state
== b
->state
&& a
->key
== b
->key
)) {
75 if (!(last
->state
== b
->state
&& last
->key
== b
->key
))
76 last
->next_sibling
= b
;
78 last
->first_child
= b
->first_child
;
84 KeyBindingTree
*tree_find(KeyBindingTree
*search
, gboolean
*conflict
)
86 KeyBindingTree
*a
, *b
;
93 if (!(a
->state
== b
->state
&& a
->key
== b
->key
)) {
96 if ((a
->first_child
== NULL
) == (b
->first_child
== NULL
)) {
97 if (a
->first_child
== NULL
) {
98 /* found it! (return the actual node, not the search's) */
103 return NULL
; /* the chain status' don't match (conflict!) */
109 return NULL
; /* it just isn't in here */
This page took 0.035997 seconds and 4 git commands to generate.