Mercurial > repos > blastem
diff 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 |
line wrap: on
line diff
--- a/tern.c Wed Nov 29 08:53:47 2017 -0800 +++ b/tern.c Fri Dec 01 09:22:43 2017 -0800 @@ -45,6 +45,12 @@ (*cur)->left = NULL; (*cur)->right = NULL; (*cur)->el = 0; + (*cur)->valtype = TVAL_NONE; + } + if ((*cur)->valtype == TVAL_PTR) { + //not freeing tern nodes can also cause leaks, but handling freeing those here is problematic + //since updating a sub-tree may involve creating a new root node + free((*cur)->straight.value.ptrval); } (*cur)->straight.value = value; (*cur)->valtype = valtype; @@ -175,6 +181,18 @@ return tern_insert(head, key, val, TVAL_NODE); } +tern_node *tern_insert_path(tern_node *head, char const *key, tern_val val, uint8_t valtype) +{ + const char *next_key = key + strlen(key) + 1; + if (*next_key) { + tern_node *child = tern_find_node(head, key); + child = tern_insert_path(child, next_key, val, valtype); + return tern_insert_node(head, key, child); + } else { + return tern_insert(head, key, val, valtype); + } +} + uint32_t tern_count(tern_node *head) { uint32_t count = 0;