Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

_tc_node.c

Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 2004, 2005 by Kevin L. Mitchell <klmitch@mit.edu>
00003 **
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 **
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software
00016 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 **
00018 ** @(#)$Id: _tc_node.c,v 1.6 2005/06/07 04:53:50 klmitch Exp $
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)) { /* Walk through all the children... */
00050     node->tn_down = tnode->tn_next; /* shift next node up */
00051 
00052     _tc_release_node(tnode); /* release the node */
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   /* Create the node... */
00090   if (!(node = (treeconf_node_t *)malloc(sizeof(treeconf_node_t) + len)))
00091     return 0;
00092 
00093   /* Then duplicate the default, if given */
00094   if (def && !(def = strdup(def))) {
00095     free(node);
00096     return 0;
00097   }
00098 
00099   /* Initialize the node */
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   /* Make it valid */
00113   node->tn_magic = TREECONF_NODE_MAGIC;
00114 
00115   /* And link it into the parent or context as appropriate */
00116   if (parent)
00117     parent->tn_down = node;
00118   else
00119     ctx->tx_config = node;
00120 
00121   /* Finally, increment the count of configs */
00122   ctx->tx_count++;
00123 
00124   return node; /* return the new node */
00125 }

Generated on Wed Jun 8 09:18:27 2005 for treeconf by  doxygen 1.3.9.1