Mercurial > repos > blastem
comparison tern.c @ 1491:e890971f3757 nuklear_ui
Somewhat fleshed out video settings view
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 01 Dec 2017 09:22:43 -0800 |
parents | 071e761bcdcf |
children | 63659fb92db4 |
comparison
equal
deleted
inserted
replaced
1490:919c0c33885e | 1491:e890971f3757 |
---|---|
43 if (!*cur) { | 43 if (!*cur) { |
44 *cur = malloc(sizeof(tern_node)); | 44 *cur = malloc(sizeof(tern_node)); |
45 (*cur)->left = NULL; | 45 (*cur)->left = NULL; |
46 (*cur)->right = NULL; | 46 (*cur)->right = NULL; |
47 (*cur)->el = 0; | 47 (*cur)->el = 0; |
48 (*cur)->valtype = TVAL_NONE; | |
49 } | |
50 if ((*cur)->valtype == TVAL_PTR) { | |
51 //not freeing tern nodes can also cause leaks, but handling freeing those here is problematic | |
52 //since updating a sub-tree may involve creating a new root node | |
53 free((*cur)->straight.value.ptrval); | |
48 } | 54 } |
49 (*cur)->straight.value = value; | 55 (*cur)->straight.value = value; |
50 (*cur)->valtype = valtype; | 56 (*cur)->valtype = valtype; |
51 return head; | 57 return head; |
52 } | 58 } |
173 tern_val val; | 179 tern_val val; |
174 val.ptrval = value; | 180 val.ptrval = value; |
175 return tern_insert(head, key, val, TVAL_NODE); | 181 return tern_insert(head, key, val, TVAL_NODE); |
176 } | 182 } |
177 | 183 |
184 tern_node *tern_insert_path(tern_node *head, char const *key, tern_val val, uint8_t valtype) | |
185 { | |
186 const char *next_key = key + strlen(key) + 1; | |
187 if (*next_key) { | |
188 tern_node *child = tern_find_node(head, key); | |
189 child = tern_insert_path(child, next_key, val, valtype); | |
190 return tern_insert_node(head, key, child); | |
191 } else { | |
192 return tern_insert(head, key, val, valtype); | |
193 } | |
194 } | |
195 | |
178 uint32_t tern_count(tern_node *head) | 196 uint32_t tern_count(tern_node *head) |
179 { | 197 { |
180 uint32_t count = 0; | 198 uint32_t count = 0; |
181 if (head->left) { | 199 if (head->left) { |
182 count += tern_count(head->left); | 200 count += tern_count(head->left); |