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

tc_get.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_get.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_get.c,v 1.4 2005/06/07 04:53:50 klmitch Exp $");
00034 
00035 unsigned int
00036 tc_get(treeconf_ctx_t *ctx, const char *name, const char **value,
00037        treeconf_node_t *parent)
00038 {
00039   struct result res;
00040   unsigned int err = 0;
00041 
00042   initialize_trcf_error_table();
00043 
00044   /* Verify the arguments */
00045   if (!tx_verify(ctx) || !name ||
00046       (parent && (!tn_verify(parent) || parent->tn_context != ctx)))
00047     return EINVAL;
00048 
00049   /* OK, look up the node... */
00050   if ((err = _tc_lookup_node(ctx, name, parent, &res)))
00051     return err;
00052 
00053   /* Couldn't find the requested node? */
00054   if (!res.r_node || res.r_count != res.r_startnew)
00055     err = ENOENT;
00056   else if ((res.r_node->tn_type & TC_NODETYPE_MASK) != TC_NODETYPE_VARIABLE)
00057     err = TC_ERR_MISMATCH; /* a tree node, not a variable node */
00058   else if (value)
00059     *value = res.r_node->tn_value; /* return the value */
00060 
00061   free(res.r_comps); /* Release temporarily allocated memory */
00062 
00063   return err;
00064 }

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