00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00027 #include <errno.h>
00028 #include <stdlib.h>
00029 #include <string.h>
00030
00031 #include "treeconf_int.h"
00032
00033 RCSTAG("@(#)$Id: tc_find.c,v 1.5 2005/06/07 04:53:50 klmitch Exp $");
00034
00035 unsigned int
00036 tc_find(treeconf_ctx_t *ctx, const char *name, treeconf_node_t **node_p,
00037 treeconf_node_t *parent)
00038 {
00039 treeconf_node_t *node = 0;
00040 struct result res;
00041 unsigned int err = 0;
00042 int i;
00043
00044 initialize_trcf_error_table();
00045
00046
00047 if (!tx_verify(ctx) || !name || !node_p ||
00048 (parent && (!tn_verify(parent) || parent->tn_context != ctx)))
00049 return EINVAL;
00050
00051
00052 if ((err = _tc_lookup_node(ctx, name, parent, &res)))
00053 return err;
00054
00055
00056 if (!res.r_node || res.r_count != res.r_startnew) {
00057
00058 if (_tn_call_nodown(res.r_node, &res.r_comps[res.r_startnew],
00059 res.r_count - res.r_startnew)) {
00060
00061 for (i = res.r_startnew, node = res.r_node; i < res.r_count; i++)
00062
00063 if (!(node = _tc_create_node(ctx, node,
00064 ((i == res.r_count - 1 ?
00065 (TC_NODETYPE_VARIABLE) :
00066 (TC_NODETYPE_NODE)) |
00067 TC_NODETYPE_IMPLICIT),
00068 res.r_comps[i].ts_string,
00069 res.r_comps[i].ts_length, 0,
00070 res.r_node->tn_nodown,
00071 res.r_node->tn_change, 0)))
00072 _tc_doerror(ENOMEM);
00073 } else
00074 _tc_doerror(ENOENT);
00075 } else
00076 node = res.r_node;
00077
00078 *node_p = node;
00079
00080 error:
00081 free(res.r_comps);
00082
00083 return err;
00084 }