00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00028 #include <stdlib.h>
00029 #include <string.h>
00030
00031 #include "treeconf_int.h"
00032
00033 RCSTAG("@(#)$Id: _tc_node.c,v 1.6 2005/06/07 04:53:50 klmitch Exp $");
00034
00044 void
00045 _tc_release_children(treeconf_node_t *node)
00046 {
00047 treeconf_node_t *tnode;
00048
00049 while ((tnode = node->tn_down)) {
00050 node->tn_down = tnode->tn_next;
00051
00052 _tc_release_node(tnode);
00053 }
00054 }
00055
00081 treeconf_node_t *
00082 _tc_create_node(treeconf_ctx_t *ctx, treeconf_node_t *parent,
00083 treeconf_type_t type, const char *name, int len,
00084 const char *def, treeconf_nodown_t nodown,
00085 treeconf_change_t change, void *assoc)
00086 {
00087 treeconf_node_t *node;
00088
00089
00090 if (!(node = (treeconf_node_t *)malloc(sizeof(treeconf_node_t) + len)))
00091 return 0;
00092
00093
00094 if (def && !(def = strdup(def))) {
00095 free(node);
00096 return 0;
00097 }
00098
00099
00100 node->tn_context = ctx;
00101 node->tn_type = type;
00102 node->tn_next = parent ? parent->tn_down : ctx->tx_config;
00103 node->tn_down = 0;
00104 node->tn_parent = parent;
00105 node->tn_nodown = nodown;
00106 node->tn_change = change;
00107 node->tn_value = node->tn_default = def;
00108 node->tn_assoc = assoc;
00109 strncpy(node->tn_name, name, len);
00110 node->tn_name[len] = '\0';
00111
00112
00113 node->tn_magic = TREECONF_NODE_MAGIC;
00114
00115
00116 if (parent)
00117 parent->tn_down = node;
00118 else
00119 ctx->tx_config = node;
00120
00121
00122 ctx->tx_count++;
00123
00124 return node;
00125 }