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

_tc_lookup_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_lookup_node.c,v 1.4 2005/06/07 04:53:50 klmitch Exp $
00019 */
00027 #include <errno.h>
00028 #include <stdlib.h>
00029 #include <string.h>
00030 
00031 #include "treeconf_int.h"
00032 
00033 RCSTAG("@(#)$Id: _tc_lookup_node.c,v 1.4 2005/06/07 04:53:50 klmitch Exp $");
00034 
00054 unsigned int
00055 _tc_lookup_node(treeconf_ctx_t *ctx, const char *name, treeconf_node_t *node,
00056             struct result *res)
00057 {
00058   unsigned int err;
00059   int i;
00060 
00061   /* break up the name into its components */
00062   if ((err = tc_break(&res->r_comps, &res->r_count, name, "./")))
00063     return err;
00064 
00065   /* Initialize result */
00066   res->r_startnew = 0;
00067   res->r_node = node;
00068 
00069   /* Now go through each component... */
00070   for (i = 0; i < res->r_count && (!i || node); i++) {
00071     if (node && (tn_type(node) & TC_NODETYPE_MASK) != TC_NODETYPE_NODE)
00072       return ENOENT; /* don't descend through a variable node */
00073 
00074     /* Walk through all the current node's children... */
00075     for (node = node ? node->tn_down : tx_config(ctx); node;
00076        node = node->tn_next) {
00077       if (strlen(tn_name(node)) != res->r_comps[i].ts_length ||
00078         strncmp(tn_name(node), res->r_comps[i].ts_string,
00079               res->r_comps[i].ts_length))
00080       continue; /* well, it's not that one... */
00081 
00082       res->r_startnew = i + 1; /* new nodes start at the next index */
00083       res->r_node = node; /* and this is the current node */
00084       break; /* break out of the inner loop */
00085     }
00086   }
00087 
00088   return 0;
00089 }

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