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

treeconf.h

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: treeconf.h,v 1.10 2005/06/08 13:17:36 klmitch Exp $
00019 */
00020 #ifndef __include_treeconf_h__
00021 #define __include_treeconf_h__
00022 
00056 #undef TC_BEGIN_C_DECLS
00057 #undef TC_END_C_DECLS
00058 #ifdef __cplusplus
00059 # define TC_BEGIN_C_DECLS extern "C" {
00060 # define TC_END_C_DECLS }
00061 #else
00062 # define TC_BEGIN_C_DECLS /* empty */
00063 # define TC_END_C_DECLS   /* empty */
00064 #endif
00065 
00071 TC_BEGIN_C_DECLS
00072 
00073 #ifndef __TREECONF_LIBRARY__
00074 #include <treeconf/treeconf_err.h>
00075 #include <treeconf/treeconf_version.h>
00076 #endif /* __TREECONF_LIBRARY__ */
00077 
00089 typedef struct _treeconf_ctx_s treeconf_ctx_t;
00090 
00102 typedef struct _treeconf_node_s treeconf_node_t;
00103 
00115 typedef struct _treeconf_str_s treeconf_str_t;
00116 
00128 typedef struct _treeconf_subst_s treeconf_subst_t;
00129 
00140 typedef enum {
00141   TC_NODETYPE_VARIABLE =    0,      
00142   TC_NODETYPE_NODE     =    1,      
00143   TC_NODETYPE_IMPLICIT = 0x10,      
00144   TC_NODETYPE_MASK     = 0x0f 
00145 } treeconf_type_t;
00146 
00167 typedef int (*treeconf_nodown_t)(treeconf_ctx_t *ctx, treeconf_node_t *parent,
00168                          treeconf_str_t *name, int elements);
00169 
00180 typedef void (*treeconf_change_t)(treeconf_ctx_t *ctx, treeconf_node_t *node);
00181 
00196 typedef unsigned int (*treeconf_file_t)(const char *file, void *data);
00197 
00203 struct _treeconf_ctx_s {
00204   unsigned int          tx_magic;   
00205   treeconf_node_t      *tx_config;  
00206   unsigned int          tx_count;   
00207 };
00208 
00213 #define TREECONF_CTX_MAGIC 0x838290fd
00214 
00219 #define TREECONF_CTX_INIT     { TREECONF_CTX_MAGIC, 0, 0 }
00220 
00233 #define tx_verify(ctx)        ((ctx) &&                           \
00234                          (ctx)->tx_magic == TREECONF_CTX_MAGIC)
00235 
00246 #define tx_config(ctx)        ((ctx)->tx_config)
00247 
00258 #define tx_count(ctx)         ((ctx)->tx_count)
00259 
00267 #define tc_init(ctx) do {                                         \
00268   treeconf_ctx_t *_ctx = (ctx);                                         \
00269   _ctx->tx_config = 0;                                            \
00270   _ctx->tx_count = 0;                                             \
00271   _ctx->tx_magic = TREECONF_CTX_MAGIC;                                  \
00272 } while (0)
00273 
00279 struct _treeconf_node_s {
00280   unsigned int          tn_magic;   
00281   treeconf_ctx_t       *tn_context; 
00282   treeconf_type_t tn_type;    
00283   treeconf_node_t      *tn_next;    
00284   treeconf_node_t      *tn_down;    
00285   treeconf_node_t      *tn_parent;  
00286   treeconf_nodown_t     tn_nodown;  
00287   treeconf_change_t     tn_change;  
00288   const char             *tn_value; 
00289   const char             *tn_default;     
00290   void                   *tn_assoc; 
00291   char                  tn_name[1]; 
00292 };
00293 
00298 #define TREECONF_NODE_MAGIC 0x80ab298d
00299 
00312 #define tn_verify(node)       ((node) &&                          \
00313                          (node)->tn_magic == TREECONF_NODE_MAGIC)
00314 
00324 #define tn_context(node)      ((node)->tn_context)
00325 
00338 #define tn_type(node)         ((node)->tn_type)
00339 
00350 #define tn_next(node)         ((node)->tn_next)
00351 
00363 #define tn_down(node)         ((node)->tn_down)
00364 
00375 #define tn_parent(node)       ((node)->tn_parent)
00376 
00392 #define tn_nodown(node)       ((node)->tn_nodown)
00393 
00408 #define tn_change(node)       ((node)->tn_change)
00409 
00423 #define tn_value(node)        ((node)->tn_value)
00424 
00438 #define tn_default(node)      ((node)->tn_default)
00439 
00452 #define tn_assoc(node)        ((node)->tn_assoc)
00453 
00471 #define tn_name(node)         ((node)->tn_name)
00472 
00483 #define tn_isdef(node)        ((node)->tn_value == (node)->tn_default)
00484 
00490 struct _treeconf_str_s {
00491   const char             *ts_string;      
00492   int             ts_length;  
00493 };
00494 
00505 #define ts_string(strs, n)    ((strs)[(n)].ts_string)
00506 
00517 #define ts_length(strs, n)    ((strs)[(n)].ts_length)
00518 
00524 struct _treeconf_subst_s {
00525   const char            tu_char;    
00526   const char             *tu_value; 
00527   unsigned int          tu_flags;   
00528 };
00529 
00535 #define TC_SUBST_INSECURE     0x01
00536 
00543 #define TC_SUBST_IGNORE       0x02
00544 
00555 #define TC_SUBST_INIT(chr, str, flags)                                  \
00556                         { (chr), (str), (flags) }
00557 
00570 #define tu_char(sub)          ((sub)->tu_char)
00571 
00582 #define tu_value(sub)         ((sub)->tu_value)
00583 
00594 #define tu_flags(sub)         ((sub)->tu_flags)
00595 
00623 unsigned int tc_break(treeconf_str_t **str_p, int *cnt_p, const char *name,
00624                   const char *delims);
00625 
00681 unsigned int tc_path(const char *path, const char *def,
00682                  treeconf_subst_t substs[], int s_cnt,
00683                  unsigned int flags, treeconf_file_t call,
00684                  void *call_data);
00685 
00692 #define TC_PATH_SECURE        TC_SUBST_INSECURE
00693 
00701 #define TC_PATH_ALL           0x02
00702 
00716 unsigned int tc_destroy(treeconf_ctx_t *ctx);
00717 
00765 unsigned int tc_register(treeconf_ctx_t *ctx, const char *name,
00766                    const char *def, treeconf_node_t *parent,
00767                    treeconf_nodown_t nodown, treeconf_change_t change,
00768                    void *assoc);
00769 
00802 unsigned int tc_set(treeconf_ctx_t *ctx, const char *name, const char *value,
00803                 treeconf_node_t *parent);
00804 
00831 unsigned int tc_get(treeconf_ctx_t *ctx, const char *name, const char **value,
00832                 treeconf_node_t *parent);
00833 
00861 unsigned int tc_find(treeconf_ctx_t *ctx, const char *name,
00862                  treeconf_node_t **node, treeconf_node_t *parent);
00863 
00901 unsigned int tc_load(const char *file, void *ctx);
00902 
00903 TC_END_C_DECLS
00904 
00907 #endif /* __include_treeconf_h__ */

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