head 1.18; access; symbols FSL_1_7_0:1.18 CFG_0_9_11:1.18 FSL_1_6_1:1.17 CFG_0_9_10:1.17 FSL_1_6_0:1.17 FSL_1_6b2:1.17 CFG_0_9_9:1.17 FSL_1_6b1:1.17 CFG_0_9_8:1.17 CFG_0_9_7:1.16 CFG_0_9_6:1.16 CFG_0_9_5:1.15 CFG_0_9_4:1.14 FSL_1_5_0:1.13 FSL_1_5a3:1.13 CFG_0_9_3:1.13 FSL_1_5a2:1.13 FSL_1_5a1:1.13 FSL_1_4_0:1.13 FSL_1_4b1:1.13 CFG_0_9_2:1.13 CFG_0_9_1:1.13 FSL_1_4a1:1.13 FSL_1_3_0:1.13 FSL_1_3b1:1.13 FSL_1_2_1:1.13 FSL_1_2_0:1.13 FSL_1_1_0:1.13 FSL_1_1b1:1.13 FSL_1_0_8:1.13 FSL_1_0_7:1.13 FSL_1_0_6:1.12 FSL_1_0_5:1.12 FSL_1_0_4:1.12 FSL_1_0_3:1.12 FSL_1_0_2:1.12 FSL_1_0_1:1.11 FSL_1_0_0:1.11 FSL_0_9_0:1.11 CFG_0_9_0:1.11 FSL_0_1_12:1.11 FSL_0_1_11:1.11 FSL_0_1_10:1.11 FSL_0_1_9:1.11 FSL_0_1_8:1.11 FSL_0_1_7:1.11 FSL_0_1_6:1.11 FSL_0_1_5:1.11 FSL_0_1_1:1.11; locks; strict; comment @ * @; 1.18 date 2006.08.10.19.35.56; author rse; state Exp; branches; next 1.17; commitid Isy241gp4yykKkIr; 1.17 date 2004.12.31.19.16.25; author rse; state Exp; branches; next 1.16; 1.16 date 2004.12.04.12.48.40; author rse; state Exp; branches; next 1.15; 1.15 date 2004.11.20.14.52.56; author rse; state Exp; branches; next 1.14; 1.14 date 2004.07.17.07.37.55; author rse; state Exp; branches; next 1.13; 1.13 date 2003.01.06.11.17.43; author rse; state Exp; branches; next 1.12; 1.12 date 2002.08.02.19.07.12; author rse; state Exp; branches; next 1.11; 1.11 date 2002.07.18.15.34.55; author rse; state Exp; branches; next 1.10; 1.10 date 2002.07.17.15.04.08; author rse; state Exp; branches; next 1.9; 1.9 date 2002.07.16.13.48.25; author thl; state Exp; branches; next 1.8; 1.8 date 2002.07.12.19.59.33; author rse; state Exp; branches; next 1.7; 1.7 date 2002.07.10.14.46.28; author rse; state Exp; branches; next 1.6; 1.6 date 2002.07.10.14.14.05; author thl; state Exp; branches; next 1.5; 1.5 date 2002.07.10.12.00.23; author rse; state Exp; branches; next 1.4; 1.4 date 2002.07.05.15.32.42; author rse; state Exp; branches; next 1.3; 1.3 date 2002.07.04.12.30.08; author rse; state Exp; branches; next 1.2; 1.2 date 2002.07.04.06.16.13; author rse; state Exp; branches; next 1.1; 1.1 date 2002.07.03.13.25.34; author rse; state Exp; branches; next ; desc @@ 1.18 log @cleanup source tree for status as of 2006 @ text @/* ** OSSP cfg - Configuration Parsing ** Copyright (c) 2002-2006 Ralf S. Engelschall ** Copyright (c) 2002-2006 The OSSP Project (http://www.ossp.org/) ** ** This file is part of OSSP cfg, a configuration parsing ** library which can be found at http://www.ossp.org/pkg/lib/cfg/. ** ** Permission to use, copy, modify, and distribute this software for ** any purpose with or without fee is hereby granted, provided that ** the above copyright notice and this permission notice appear in all ** copies. ** ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. ** ** cfg.h: master API */ #ifndef __CFG_H__ #define __CFG_H__ #include #include #include /* general return codes */ typedef enum { CFG_OK = 0, /* everything ok */ CFG_ERR_ARG, /* invalid argument */ CFG_ERR_USE, /* invalid use */ CFG_ERR_MEM, /* no more memory available */ CFG_ERR_SYS, /* operating system error */ CFG_ERR_FMT, /* formatting error */ CFG_ERR_INT, /* internal error */ CFG_ERR_SYN, /* syntax error */ CFG_ERR_NDE /* node reference error */ } cfg_rc_t; /* configuration format */ typedef enum { CFG_FMT_CFG, CFG_FMT_XML } cfg_fmt_t; /* list of node types */ typedef enum { CFG_NODE_TYPE_SEQ, /* node represents a sequence */ CFG_NODE_TYPE_DIR, /* node represents a directive */ CFG_NODE_TYPE_OPT, /* node represents a option */ CFG_NODE_TYPE_ARG /* node represents a argument */ } cfg_node_type_t; /* list of node attributes */ typedef int cfg_node_attr_t; enum { /* attribute selection */ CFG_NODE_ATTR_PARENT = (1 << 0), /* RW: (cfg_node_t *) pointer to parent node */ CFG_NODE_ATTR_LBROTH = (1 << 1), /* RW: (cfg_node_t *) pointer to left brother node */ CFG_NODE_ATTR_RBROTH = (1 << 2), /* RW: (cfg_node_t *) pointer to right brother node */ CFG_NODE_ATTR_CHILD1 = (1 << 3), /* RW: (cfg_node_t *) pointer to first child node */ CFG_NODE_ATTR_CHILDL = (1 << 4), /* RO: (cfg_node_t *) pointer to last child */ CFG_NODE_ATTR_CHILDS = (1 << 5), /* RO: (int) number of child nodes */ CFG_NODE_ATTR_NODES = (1 << 6), /* RO: (int) number of total nodes (recursive) */ CFG_NODE_ATTR_DEPTH = (1 << 7), /* RO: (int) number of nodes back to root node */ CFG_NODE_ATTR_SRCNAME = (1 << 8), /* RW: (char *) pointer to the source name */ CFG_NODE_ATTR_SRCPOS = (1 << 9), /* RW: (int) position offset into source */ CFG_NODE_ATTR_TYPE = (1 << 10), /* RW: (cfg_node_type_t) type of node */ CFG_NODE_ATTR_TOKEN = (1 << 11), /* RW: (char *) pointer to the node token string */ CFG_NODE_ATTR_DATA = (1 << 12), /* RW: (cfg_data_t *) pointer to the node annotation data */ /* attribute passing semantics */ CFG_ATTR_LOAN = (1 << 13), /* loan attribute on set/get: source still owns orginal data */ CFG_ATTR_GIFT = (1 << 14), /* gift attribute on set/get: target then owns orginal data */ CFG_ATTR_COPY = (1 << 15) /* copy attribute on set/get: target then owns copied data */ }; /* list of data types */ typedef enum { CFG_DATA_TYPE_PTR, /* "void *" */ CFG_DATA_TYPE_STR, /* "char *" */ CFG_DATA_TYPE_INT, /* "int" */ CFG_DATA_TYPE_FLT /* "double" */ } cfg_data_type_t; /* list of data control operations */ typedef enum { CFG_DATA_CTRL_CLONE, /* clone data */ CFG_DATA_CTRL_DESTROY /* destroy data */ } cfg_data_ctrl_t; /* list of data attributes */ typedef enum { CFG_DATA_ATTR_TYPE, /* RW: type of data value */ CFG_DATA_ATTR_VALUE, /* RW: pointer to data value */ CFG_DATA_ATTR_CTRL /* RW: pointer to data control callback */ } cfg_data_attr_t; /* configuration handle type (opaque) */ struct cfg_st; typedef struct cfg_st cfg_t; /* configuration node type (opaque) */ struct cfg_node_st; typedef struct cfg_node_st cfg_node_t; /* configuration data type */ struct cfg_data_st; typedef struct cfg_data_st cfg_data_t; /* configuration data control callback type */ typedef cfg_rc_t (*cfg_data_cb_t)(cfg_data_t *, cfg_data_ctrl_t, ...); /* configuration handling */ cfg_rc_t cfg_create (cfg_t **cfg); cfg_rc_t cfg_destroy (cfg_t *cfg); cfg_rc_t cfg_error (cfg_t *cfg, cfg_rc_t rc, char **error); long cfg_version (void); /* configuration import/export */ cfg_rc_t cfg_import (cfg_t *cfg, cfg_node_t *node, cfg_fmt_t fmt, const char *in_ptr, size_t in_len); cfg_rc_t cfg_export (cfg_t *cfg, cfg_node_t *node, cfg_fmt_t fmt, char **ex_ptr, size_t ex_len); /* node handling */ cfg_rc_t cfg_node_create (cfg_t *cfg, cfg_node_t **node); cfg_rc_t cfg_node_destroy(cfg_t *cfg, cfg_node_t *node); cfg_rc_t cfg_node_clone (cfg_t *cfg, cfg_node_t *node, cfg_node_t **node2); /* node attribution */ cfg_rc_t cfg_node_set (cfg_t *cfg, cfg_node_t *node, cfg_node_attr_t attr, ...); cfg_rc_t cfg_node_get (cfg_t *cfg, cfg_node_t *node, cfg_node_attr_t attr, ...); /* node traversing/locating */ cfg_rc_t cfg_node_root (cfg_t *cfg, cfg_node_t *node, cfg_node_t **node_old); cfg_rc_t cfg_node_select (cfg_t *cfg, cfg_node_t *node, cfg_node_t ***result, const char *spec, ...); cfg_rc_t cfg_node_find (cfg_t *cfg, cfg_node_t *node, cfg_rc_t (*cb_fct_cmp)(cfg_t *, cfg_node_t *, void *), void *cb_ctx_cmp, cfg_node_t **cont); cfg_rc_t cfg_node_apply (cfg_t *cfg, cfg_node_t *node, cfg_rc_t (*cb_fct_cmp)(cfg_t *, cfg_node_t *, void *), void *cb_ctx_cmp, cfg_rc_t (*cb_fct_cb)(cfg_t *, cfg_node_t *, void *), void *cb_ctx_cb); cfg_rc_t cfg_node_cmp (cfg_t *cfg, cfg_node_t *node, void *token); /* node linking */ cfg_rc_t cfg_node_link (cfg_t *cfg, cfg_node_t *node, cfg_node_attr_t id, cfg_node_t *node2); cfg_rc_t cfg_node_unlink (cfg_t *cfg, cfg_node_t *node); /* data attribution */ cfg_rc_t cfg_data_set (cfg_data_t *data, cfg_data_attr_t attr, ...); cfg_rc_t cfg_data_get (cfg_data_t *data, cfg_data_attr_t attr, ...); cfg_rc_t cfg_data_ctrl (cfg_data_t *data, cfg_data_ctrl_t ctrl, ...); #endif /* __CFG_H__ */ @ 1.17 log @Adjust copyright messages for new year 2005. @ text @d3 2 a4 3 ** Copyright (c) 2002-2005 Ralf S. Engelschall ** Copyright (c) 2002-2005 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2002-2005 Cable & Wireless (http://www.cw.com/) @ 1.16 log @Plug remaining memory leaks by introducing the usual LOAN/GIFT/COPY argument passing semantics to cfg_node_{set,get} and using this to directly pass the allocated tokens from the scanner through the parser into the node tree. @ text @d3 3 a5 3 ** Copyright (c) 2002-2004 Ralf S. Engelschall ** Copyright (c) 2002-2004 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2002-2004 Cable & Wireless (http://www.cw.com/) @ 1.15 log @Change cfg_node_root() API function to be able to both set and/or get the root node. @ text @d66 21 a86 15 typedef enum { CFG_NODE_ATTR_PARENT, /* RW: (cfg_node_t *) pointer to parent node */ CFG_NODE_ATTR_LBROTH, /* RW: (cfg_node_t *) pointer to left brother node */ CFG_NODE_ATTR_RBROTH, /* RW: (cfg_node_t *) pointer to right brother node */ CFG_NODE_ATTR_CHILD1, /* RW: (cfg_node_t *) pointer to first child node */ CFG_NODE_ATTR_CHILDL, /* RO: (cfg_node_t *) pointer to last child */ CFG_NODE_ATTR_CHILDS, /* RO: (int) number of child nodes */ CFG_NODE_ATTR_NODES, /* RO: (int) number of total nodes (recursive) */ CFG_NODE_ATTR_DEPTH, /* RO: (int) number of nodes back to root node */ CFG_NODE_ATTR_SRCNAME, /* RW: (char *) pointer to the source name */ CFG_NODE_ATTR_SRCPOS, /* RW: (int) position offset into source */ CFG_NODE_ATTR_TYPE, /* RW: (cfg_node_type_t) type of node */ CFG_NODE_ATTR_TOKEN, /* RW: (char *) pointer to the node token string */ CFG_NODE_ATTR_DATA /* RW: (cfg_data_t *) pointer to the node annotation data */ } cfg_node_attr_t; @ 1.14 log @Adjust copyright messages for new year 2004. @ text @d138 1 a138 1 cfg_rc_t cfg_node_root (cfg_t *cfg, cfg_node_t **node); @ 1.13 log @update copyright messages for new year @ text @d3 3 a5 3 ** Copyright (c) 2002-2003 Ralf S. Engelschall ** Copyright (c) 2002-2003 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2002-2003 Cable & Wireless Deutschland (http://www.cw.com/de/) @ 1.12 log @full source tree overhauling @ text @d3 3 a5 3 ** Copyright (c) 1999-2002 Ralf S. Engelschall ** Copyright (c) 1999-2002 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2001-2002 Cable & Wireless Deutschland (http://www.cw.com/de/) @ 1.11 log @flush work of today: first cut for real cfg_node_select() @ text @d122 1 @ 1.10 log @Ops, fix a typo I cannot imagine where it comes from... @ text @d138 1 a138 1 cfg_rc_t cfg_node_select (cfg_t *cfg, cfg_node_t *node, cfg_node_t **node2, const char *spec, ...); @ 1.9 log @document return types @ text @d23 1 a23 1 ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRCFG, STRICT LIABILITY, @ 1.8 log @just flush work of this evening @ text @d67 13 a79 13 CFG_NODE_ATTR_PARENT, /* RW: pointer to parent node */ CFG_NODE_ATTR_LBROTH, /* RW: pointer to left brother node */ CFG_NODE_ATTR_RBROTH, /* RW: pointer to right brother node */ CFG_NODE_ATTR_CHILD1, /* RW: pointer to first child node */ CFG_NODE_ATTR_CHILDL, /* RO: pointer to last child */ CFG_NODE_ATTR_CHILDS, /* RO: number of child nodes */ CFG_NODE_ATTR_NODES, /* RO: number of total nodes (recursive) */ CFG_NODE_ATTR_DEPTH, /* RO: number of nodes back to root node */ CFG_NODE_ATTR_SRCNAME, /* RW: pointer to the source name */ CFG_NODE_ATTR_SRCPOS, /* RW: position offset into source */ CFG_NODE_ATTR_TYPE, /* RW: type of node */ CFG_NODE_ATTR_TOKEN, /* RW: pointer to the node token string */ CFG_NODE_ATTR_DATA /* RW: pointer to the node annotation data */ @ 1.7 log @Step 2 in API overhauling and implementation filling. @ text @d75 2 d79 1 a79 3 CFG_NODE_ATTR_DATA, /* RW: pointer to the node annotation data */ CFG_NODE_ATTR_SRCNAME, /* RW: pointer to the source name */ CFG_NODE_ATTR_SRCPOS /* RW: position offset into source */ d138 1 a138 2 cfg_rc_t cfg_node_goto (cfg_t *cfg, cfg_node_t *node, const char *spec, cfg_node_t **node2); cfg_rc_t cfg_node_select (cfg_t *cfg, cfg_node_t *node, const char *spec, cfg_node_t **node2); @ 1.6 log @copy'n'paste typo @ text @d43 2 a44 2 CFG_ERR_SYS, /* operating system error (see errno) */ CFG_ERR_SYN, /* syntax parsing error */ d46 3 a48 2 CFG_ERR_GOT, /* goto error */ CFG_ERR_INT /* internal error */ d121 1 a121 1 cfg_rc_t cfg_error (cfg_t *cfg, cfg_rc_t rc, char *err_ptr, size_t err_len); d125 1 a125 1 cfg_rc_t cfg_export (cfg_t *cfg, cfg_node_t *node, cfg_fmt_t fmt, char *ex_ptr, size_t ex_len); d136 1 a136 1 /* node traversing */ d138 2 a139 4 cfg_rc_t cfg_node_goto (cfg_t *cfg, cfg_node_t **node, const char *spec); /* node locating */ cfg_rc_t cfg_node_select (cfg_t *cfg, cfg_node_t *node, const char *dotpath, cfg_node_t **node2); @ 1.5 log @Mega-change: full API overhauling. @ text @d67 1 a67 1 CFG_NODE_ATTR_LBROTH, /* RW: pointer to right brother node */ @ 1.4 log @thanks to Dmalloc we can fix the memory holes @ text @d34 1 a34 3 #ifdef DMALLOC #include #endif d36 1 a36 2 /* ============================================================ */ d40 8 a47 8 CFG_OK = 0, CFG_ERR_ARG, CFG_ERR_USE, CFG_ERR_INT, CFG_ERR_SYS, CFG_ERR_SYN, CFG_ERR_FMT, CFG_ERR_GOT d50 5 a54 11 /* ============================================================ */ /* configuration handle */ struct cfg_st; typedef struct cfg_st cfg_t; /* configuration API */ cfg_rc_t cfg_create (cfg_t **cfg); cfg_rc_t cfg_destroy (cfg_t *cfg); /* ============================================================ */ d60 2 a61 1 CFG_NODE_TYPE_TOK /* node represents a token */ d66 13 a78 6 CFG_NODE_ATTR_TYPE, /* type of node */ CFG_NODE_ATTR_PARENT, /* pointer to parent node */ CFG_NODE_ATTR_RBROTH, /* pointer to right brother node */ CFG_NODE_ATTR_CHILD1, /* pointer to first child node */ CFG_NODE_ATTR_TOKEN, /* pointer to the node token string */ CFG_NODE_ATTR_DATA /* pointer to the node annotation data */ d81 15 a95 1 /* list of node goto */ d97 8 a104 13 CFG_NODE_GOTO_PARENT, CFG_NODE_GOTO_LBROTH, CFG_NODE_GOTO_RBROTH, CFG_NODE_GOTO_CHILD1, CFG_NODE_GOTO_CHILDL } cfg_node_goto_t; /* list of node linking variants */ typedef enum { CFG_NODE_LINK_PARENT, CFG_NODE_LINK_RBROTH, CFG_NODE_LINK_CHILD1 } cfg_node_link_t; d106 1 a106 1 /* configuration node type */ d110 11 a120 8 cfg_rc_t cfg_node_create (cfg_node_t **node); cfg_rc_t cfg_node_set (cfg_node_t *node, cfg_node_attr_t attr, ...); cfg_rc_t cfg_node_get (cfg_node_t *node, cfg_node_attr_t attr, ...); cfg_rc_t cfg_node_goto (cfg_node_t *node, cfg_node_goto_t id, cfg_node_t **node2); cfg_rc_t cfg_node_link (cfg_node_t *node, cfg_node_link_t id, cfg_node_t *node2); cfg_rc_t cfg_node_unlink (cfg_node_t *node); cfg_rc_t cfg_node_apply (cfg_node_t *node, void (*cb_fct)(void *, cfg_node_t *), void *cb_ctx); cfg_rc_t cfg_node_destroy (cfg_node_t *node); d122 31 a152 1 /* ============================================================ */ @ 1.3 log @add a new cfg_node_goto() function @ text @d34 3 @ 1.2 log @split out cfg_data_t stuff into seperate object to get better abstraction for this @ text @d45 3 a47 1 CFG_ERR_SYN a63 1 CFG_NODE_TYPE_NN = 0, /* node unknown */ d79 9 d102 1 @ 1.1 log @Add this first cut for the forthcoming OSSP cfg library to CVS. This is work in progress and still not ready for use anywhere. @ text @d42 1 @