OSSP CVS Repository

ossp - Check-in [2267]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2267
Date: 2002-Jul-10 14:00:23 (local)
2002-Jul-10 12:00:23 (UTC)
User:rse
Branch:
Comment: Mega-change: full API overhauling.
Tickets:
Inspections:
Files:
ossp-pkg/cfg/00TODO      1.6 -> 1.7     120 inserted, 0 deleted
ossp-pkg/cfg/Makefile.in      1.1 -> 1.2     1 inserted, 1 deleted
ossp-pkg/cfg/cfg.h      1.4 -> 1.5     96 inserted, 55 deleted
ossp-pkg/cfg/cfg_data.c      1.1 -> 1.2     12 inserted, 12 deleted
ossp-pkg/cfg/cfg_data.h      1.1 -> 1.2     2 inserted, 27 deleted
ossp-pkg/cfg/cfg_main.c      added-> 1.1
ossp-pkg/cfg/cfg_main.h      added-> 1.1
ossp-pkg/cfg/cfg_node.c      1.4 -> 1.5     105 inserted, 39 deleted
ossp-pkg/cfg/cfg_node.h      1.3 -> 1.4     5 inserted, 0 deleted
ossp-pkg/cfg/cfg_syn.c      1.10 -> 1.11     17 inserted, 15 deleted
ossp-pkg/cfg/cfg_syn_parse.y      1.2 -> 1.3     11 inserted, 11 deleted
ossp-pkg/cfg/cfg_syn_scan.l      1.7 -> 1.8     3 inserted, 3 deleted

ossp-pkg/cfg/00TODO 1.6 -> 1.7

--- 00TODO       2002/07/09 08:29:31     1.6
+++ 00TODO       2002/07/10 12:00:23     1.7
@@ -84,3 +84,123 @@
     option "bar" --occur=1
 };
 
+---------------------------------------------------------------------------
+
+foo on;
+bar /bla {
+    foo off;
+    baz --fuck {
+        b1; b2 --nase=baer; b3; b4; b5;
+    } --fuck2;
+};
+quux a1 a2 a3 a4;
+quux;
+
+---------------------------------------------------------------------------
+
+sequence ROOT {
+    directive foo; 
+    directive bar;
+    directive quux --count=1:oo;
+};
+sequence bar-seq {
+    directive foo --count=0:1; 
+    directive baz --count=1:oo;
+};
+directive foo { 
+    token - on|off|yes|no;
+};
+directive bar {
+    token path /.*; 
+    sequence bar-seq;
+};
+directive baz { 
+    option fuck; 
+    option fuck2; 
+    sequence {
+        directive foo { 
+            option nase (baer|hugo);
+            option foo [0-9]; 
+            token ip-address;
+        };
+    };
+};
+directive quux {
+    token --count=0:oo a.*;
+};
+token ip-address b1|b2|b3|b4|b5;
+
+-------------------------------------------------------------------------------
+
+<config>     ::= "sequence" <count>? <name>;
+               | "sequence" <count>? <name>? "{" <directive>* "}";
+<directive>  ::= "directive" <token-count>? <name>;
+               | "directive" <token-count>? <name>? "{" <option>* <token>+ };
+<option>     ::= "option" <name> <regex>?;
+<token>      ::= "token" <name>? <regex>;
+<count>      ::= /^(\+|\*|\?|[0-9]+,[0-9]*|[0-9]*,[0-9]+|[0-9]+)$/
+<name>       ::= /^[a-zA-Z][a-zA-Z0-9_.-]*$/
+<regex>      ::= ...
+
+-------------------------------------------------------------------------------
+
+sequence ROOT {
+    directive * "directive" {
+
+    directive * token-1 {
+        token token "token";
+        token name  /^[a-zA-Z][a-zA-Z0-9_.-]*$/;
+        token regex /^.+$/;
+    }
+};
+
+-------------------------------------------------------------------------------
+
+directive token {
+    opt1      { /.../ opt2=/.../ } { 
+    directive { /^token$/ }; 
+    name      { m/.../; m/^[a-zA-Z][a-zA-Z0-9_.-]*$/ } ?;
+    name      { m/(...|[a-zA-Z][a-zA-Z0-9_.-]*$)/ } ?;
+    regex     { m/^.+$/ };
+};
+directive acl   { directive=/^acl$/ addr=/^...|...$/+ };
+
+-------------------------------------------------------------------------------
+
+a?b((c|d)+e)?f
+
+A m/a/ ?
+B m/b/ 
+{
+    {
+        C m/c/ ;
+        D m/d/ 
+    } +
+    E m/e/
+} ? 
+F f
+
+<directive-match> ::= <token-match>+
+<token-match> ::= <name>? <regex> <quant>?
+
+-------------------------------------------------------------------------------
+
+<config>     ::= "sequence" <count>? <name>;
+               | "sequence" <count>? <name>? "{" <directive>* "}";
+<directive>  ::= "directive" <name>;
+               | "directive" <name>? "{" <options> "}" "{" <tokens> "}";
+
+<options>     ::= <tok-match>+
+<tokens>      ::= <dir-match>+
+
+<dir-match>   ::= <tok-match>+
+<tok-match>   ::= <name>? <node-match> <quant>?
+<node-match>  ::= "{" <dir-match> "}" | <regex>
+
+<option>     ::= "option" <name> <regex>?;
+<token>      ::= "token" <name>? <regex>;
+
+<count>      ::= /^(\+|\*|\?|[0-9]+,[0-9]*|[0-9]*,[0-9]+|[0-9]+)$/
+<name>       ::= /^[a-zA-Z][a-zA-Z0-9_.-]*$/
+<regex>      ::= ...
+


ossp-pkg/cfg/Makefile.in 1.1 -> 1.2

--- Makefile.in  2002/07/09 08:29:19     1.1
+++ Makefile.in  2002/07/10 12:00:23     1.2
@@ -53,7 +53,7 @@
 BISON       = @BISON@
 
 LIB_NAME    = libcfg.la
-LIB_OBJS    = cfg_buf.lo cfg_grid.lo cfg_data.lo cfg_node.lo cfg_fmt.lo \
+LIB_OBJS    = cfg_main.lo cfg_buf.lo cfg_grid.lo cfg_data.lo cfg_node.lo cfg_fmt.lo \
               cfg_syn.lo cfg_syn_parse.lo cfg_syn_scan.lo cfg_util.lo
 
 TST_NAME    = cfg_test


ossp-pkg/cfg/cfg.h 1.4 -> 1.5

--- cfg.h        2002/07/05 15:32:42     1.4
+++ cfg.h        2002/07/10 12:00:23     1.5
@@ -31,84 +31,125 @@
 #ifndef __CFG_H__
 #define __CFG_H__
 
-#ifdef DMALLOC
-#include <dmalloc.h>
-#endif
+#include <stdlib.h>
 #include <stdarg.h>
-
-/* ============================================================ */
+#include <string.h>
 
 /* general return codes */
 typedef enum {
-    CFG_OK = 0,
-    CFG_ERR_ARG,
-    CFG_ERR_USE,
-    CFG_ERR_INT,
-    CFG_ERR_SYS,
-    CFG_ERR_SYN,
-    CFG_ERR_FMT,
-    CFG_ERR_GOT
+    CFG_OK = 0,               /* everything ok */
+    CFG_ERR_ARG,              /* invalid argument */
+    CFG_ERR_USE,              /* invalid use */
+    CFG_ERR_SYS,              /* operating system error (see errno) */
+    CFG_ERR_SYN,              /* syntax parsing error */
+    CFG_ERR_FMT,              /* formatting error */
+    CFG_ERR_GOT,              /* goto error */
+    CFG_ERR_INT               /* internal error */
 } cfg_rc_t;
 
-/* ============================================================ */
-
-/* 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);
-
-/* ============================================================ */
+/* 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_TOK         /* node represents a token */
+    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 enum {
-    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 */
+    CFG_NODE_ATTR_PARENT,     /* RW: pointer to parent node */
+    CFG_NODE_ATTR_LBROTH,     /* RW: pointer to right 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_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 */
+    CFG_NODE_ATTR_SRCNAME,    /* RW: pointer to the source name */
+    CFG_NODE_ATTR_SRCPOS      /* RW: position offset into source */
 } cfg_node_attr_t;
 
-/* list of node goto */
+/* 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_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;
+    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 */
+/* configuration node type (opaque) */
 struct cfg_node_st;
 typedef struct cfg_node_st cfg_node_t;
 
-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);
+/* 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 *err_ptr, size_t err_len);
 
-/* ============================================================ */
+/* 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 */
+cfg_rc_t   cfg_node_root   (cfg_t  *cfg, cfg_node_t **node);
+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);
+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__ */
 


ossp-pkg/cfg/cfg_data.c 1.1 -> 1.2

--- cfg_data.c   2002/07/04 06:16:13     1.1
+++ cfg_data.c   2002/07/10 12:00:23     1.2
@@ -56,7 +56,7 @@
         return CFG_ERR_ARG;
     data->type    = CFG_DATA_TYPE_INT;
     data->value.i = 0;
-    data->ctrl    = cfg_data_ctrl_default;
+    data->ctrl    = cfg_data_ctrl;
     return CFG_OK;
 }
 
@@ -101,7 +101,7 @@
     return CFG_OK;
 }
 
-cfg_rc_t cfg_data_ctrl_default(cfg_data_t *data, cfg_data_ctrl_t ctrl, ...)
+cfg_rc_t cfg_data_ctrl(cfg_data_t *data, cfg_data_ctrl_t ctrl, ...)
 {
     cfg_data_t *data2;
     va_list ap;
@@ -132,7 +132,7 @@
     return CFG_OK;
 }
 
-cfg_rc_t cfg_data_set(cfg_data_t *data, cfg_data_id_t id, ...)
+cfg_rc_t cfg_data_set(cfg_data_t *data, cfg_data_attr_t id, ...)
 {
     va_list ap;
 
@@ -140,7 +140,7 @@
         return CFG_ERR_ARG;
     va_start(ap, id);
     switch (id) {
-        case CFG_DATA_TYPE: {
+        case CFG_DATA_ATTR_TYPE: {
             cfg_data_type_t t = (cfg_data_type_t)va_arg(ap, int);
             if (!(   t == CFG_DATA_TYPE_PTR
                   || t == CFG_DATA_TYPE_STR
@@ -150,7 +150,7 @@
             data->type = t;
             break;
         }
-        case CFG_DATA_VALUE: {
+        case CFG_DATA_ATTR_VALUE: {
             switch (data->type) {
                 case CFG_DATA_TYPE_PTR: {
                     data->value.p = (void *)va_arg(ap, void *); 
@@ -176,8 +176,8 @@
             }
             break;
         }
-        case CFG_DATA_CTRL: {
-            cfg_data_ctrl_cb_t ctrl = (cfg_data_ctrl_cb_t)va_arg(ap, void (*)(void));
+        case CFG_DATA_ATTR_CTRL: {
+            cfg_data_cb_t ctrl = (cfg_data_cb_t)va_arg(ap, void (*)(void));
             data->ctrl = ctrl;
             break;
         }
@@ -186,7 +186,7 @@
     return CFG_OK;
 }
 
-cfg_rc_t cfg_data_get(cfg_data_t *data, cfg_data_id_t id, ...)
+cfg_rc_t cfg_data_get(cfg_data_t *data, cfg_data_attr_t id, ...)
 {
     va_list ap;
 
@@ -194,14 +194,14 @@
         return CFG_ERR_ARG;
     va_start(ap, id);
     switch (id) {
-        case CFG_DATA_TYPE: {
+        case CFG_DATA_ATTR_TYPE: {
             cfg_data_type_t *pt = (cfg_data_type_t *)va_arg(ap, int *);
             if (pt == NULL)
                 return CFG_ERR_ARG;
             *pt = data->type;
             break;
         }
-        case CFG_DATA_VALUE: {
+        case CFG_DATA_ATTR_VALUE: {
             switch (data->type) {
                 case CFG_DATA_TYPE_PTR: {
                     void **p = (void **)va_arg(ap, void *);
@@ -234,8 +234,8 @@
             }
             break;
         }
-        case CFG_DATA_CTRL: {
-            cfg_data_ctrl_cb_t *pcb = (cfg_data_ctrl_cb_t *)va_arg(ap, void *);
+        case CFG_DATA_ATTR_CTRL: {
+            cfg_data_cb_t *pcb = (cfg_data_cb_t *)va_arg(ap, void *);
             if (pcb == NULL)
                 return CFG_ERR_ARG;
             *pcb = data->ctrl;


ossp-pkg/cfg/cfg_data.h 1.1 -> 1.2

--- cfg_data.h   2002/07/04 06:16:13     1.1
+++ cfg_data.h   2002/07/10 12:00:23     1.2
@@ -33,13 +33,7 @@
 
 #include "cfg.h"
 
-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;
-
+/* configuration data value type */
 typedef union {
     void  *p;
     char  *s;
@@ -47,26 +41,10 @@
     double f;
 } cfg_data_value_t;
 
-typedef enum {
-    CFG_DATA_CTRL_CLONE,
-    CFG_DATA_CTRL_DESTROY
-} cfg_data_ctrl_t;
-
-typedef enum {
-    CFG_DATA_TYPE,
-    CFG_DATA_VALUE,
-    CFG_DATA_CTRL
-} cfg_data_id_t;
-
-struct cfg_data_st;
-typedef struct cfg_data_st cfg_data_t;
-
-typedef cfg_rc_t (*cfg_data_ctrl_cb_t)(cfg_data_t *, cfg_data_ctrl_t, ...);
-
 struct cfg_data_st {
     cfg_data_type_t    type;   /* data type    */
     cfg_data_value_t   value;  /* data value   */
-    cfg_data_ctrl_cb_t ctrl;   /* data control */
+    cfg_data_cb_t      ctrl;   /* data control */
 };
 
 extern cfg_rc_t  cfg_data_create       (cfg_data_t **data);
@@ -74,9 +52,6 @@
 extern cfg_rc_t  cfg_data_kill         (cfg_data_t  *data);
 extern cfg_rc_t  cfg_data_destroy      (cfg_data_t  *data);
 extern cfg_rc_t  cfg_data_clone        (cfg_data_t  *data, cfg_data_t **clone);
-extern cfg_rc_t  cfg_data_set          (cfg_data_t  *data, cfg_data_id_t id, ...);
-extern cfg_rc_t  cfg_data_get          (cfg_data_t  *data, cfg_data_id_t id, ...);
-extern cfg_rc_t  cfg_data_ctrl_default (cfg_data_t  *data, cfg_data_ctrl_t ctrl, ...);
 
 #endif /* __CFG_DATA_H__ */
 


ossp-pkg/cfg/cfg_main.c -> 1.1

*** /dev/null    Mon Apr 29 13:55:00 2024
--- -    Mon Apr 29 13:55:30 2024
***************
*** 0 ****
--- 1,62 ----
+ /*
+ **  OSSP cfg - Configuration Parsing
+ **  Copyright (c) 1999-2002 Ralf S. Engelschall <rse@engelschall.com>
+ **  Copyright (c) 1999-2002 The OSSP Project (http://www.ossp.org/)
+ **  Copyright (c) 2001-2002 Cable & Wireless Deutschland (http://www.cw.com/de/)
+ **
+ **  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 CONTRCFG, 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_main.c: main API
+ */
+ 
+ #include <stdlib.h>
+ #include <stdarg.h>
+ #include <string.h>
+ 
+ #include "cfg.h"
+ #include "cfg_data.h"
+ 
+ cfg_rc_t cfg_create(cfg_t **cfg)
+ {
+     return CFG_OK;
+ }
+ 
+ cfg_rc_t cfg_destroy(cfg_t *cfg)
+ {
+     return CFG_OK;
+ }
+ 
+ cfg_rc_t cfg_error(cfg_t *cfg, cfg_rc_t rc, char *err_ptr, size_t err_len)
+ {
+     return CFG_OK;
+ }
+ 
+ cfg_rc_t cfg_import(cfg_t *cfg, cfg_node_t *node, cfg_fmt_t fmt, const char *in_ptr, size_t in_len)
+ {
+     return CFG_OK;
+ }
+ 
+ cfg_rc_t cfg_export(cfg_t *cfg, cfg_node_t *node, cfg_fmt_t fmt, char *ex_ptr, size_t ex_len)
+ {
+     return CFG_OK;
+ }
+ 


ossp-pkg/cfg/cfg_main.h -> 1.1

*** /dev/null    Mon Apr 29 13:55:00 2024
--- -    Mon Apr 29 13:55:30 2024
***************
*** 0 ****
--- 1,41 ----
+ /*
+ **  OSSP cfg - Configuration Parsing
+ **  Copyright (c) 1999-2002 Ralf S. Engelschall <rse@engelschall.com>
+ **  Copyright (c) 1999-2002 The OSSP Project (http://www.ossp.org/)
+ **  Copyright (c) 2001-2002 Cable & Wireless Deutschland (http://www.cw.com/de/)
+ **
+ **  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 CONTRCFG, 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_main.h: main API
+ */
+ 
+ #ifndef __CFG_MAIN_H__
+ #define __CFG_MAIN_H__
+ 
+ #include "cfg.h"
+ 
+ struct cfg_st {
+     cfg_node_t *root;
+ };
+ 
+ #endif /* __CFG_MAIN_H__ */
+ 


ossp-pkg/cfg/cfg_node.c 1.4 -> 1.5

--- cfg_node.c   2002/07/05 15:32:42     1.4
+++ cfg_node.c   2002/07/10 12:00:23     1.5
@@ -33,9 +33,10 @@
 #include <stdarg.h>
 #include <unistd.h>
 
+#include "cfg_main.h"
 #include "cfg_node.h"
 
-cfg_rc_t cfg_node_create(cfg_node_t **node)
+cfg_rc_t cfg_node_create(cfg_t *cfg, cfg_node_t **node)
 {
     cfg_node_t *n;
 
@@ -44,14 +45,32 @@
     n->parent   = NULL;
     n->rbroth   = NULL;
     n->child1   = NULL;
-    n->type     = CFG_NODE_TYPE_TOK;
+    n->type     = CFG_NODE_TYPE_ARG;
     n->token    = NULL;
     cfg_data_init(&n->data);
     *node = n;
     return CFG_OK;
 }
 
-cfg_rc_t cfg_node_set(cfg_node_t *node, cfg_node_attr_t attr, ...)
+cfg_rc_t cfg_node_destroy(cfg_t *cfg, cfg_node_t *node)
+{
+    if (node == NULL)
+        return CFG_ERR_ARG;
+    if (node->token != NULL)
+        free(node->token);
+    free(node);
+    return CFG_OK;
+}
+
+cfg_rc_t cfg_node_clone(cfg_t *cfg, cfg_node_t *node, cfg_node_t **node2)
+{
+    if (node == NULL || node2 == NULL)
+        return CFG_ERR_ARG;
+    /* FIXME */
+    return CFG_OK;
+}
+
+cfg_rc_t cfg_node_set(cfg_t *cfg, cfg_node_t *node, cfg_node_attr_t attr, ...)
 {
     va_list ap;
 
@@ -89,7 +108,7 @@
     return CFG_OK;
 }
 
-cfg_rc_t cfg_node_get(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, ...)
 {
     va_list ap;
 
@@ -134,12 +153,22 @@
     return CFG_OK;
 }
 
-cfg_rc_t cfg_node_goto(cfg_node_t *node, cfg_node_goto_t id, cfg_node_t **node2)
+cfg_rc_t cfg_node_root(cfg_t *cfg, cfg_node_t **node)
 {
-    cfg_node_t *n;
+    if (cfg == NULL || node == NULL)
+        return CFG_ERR_ARG;
+    *node = cfg->root;
+    return CFG_OK;
+}
 
-    if (node == NULL || node2 == NULL)
+cfg_rc_t cfg_node_goto(cfg_t *cfg, cfg_node_t **node, const char *spec)
+{
+
+    if (cfg == NULL || node == NULL || spec == NULL)
         return CFG_ERR_ARG;
+    /* FIXME */
+#if 0
+    cfg_node_t *n;
     *node2 = NULL;
     switch (id) {
         case CFG_NODE_GOTO_PARENT: {
@@ -176,16 +205,78 @@
     }
     if (*node2 == NULL)
         return CFG_ERR_GOT;
+#endif
+    return CFG_OK;
+}
+
+cfg_rc_t 
+cfg_node_select(
+    cfg_t *cfg, 
+    cfg_node_t *node, 
+    const char *dotpath, 
+    cfg_node_t **node2)
+{
+    /* FIXME */
+    return CFG_OK;
+}
+
+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)
+{
+    /* FIXME */
     return CFG_OK;
 }
 
-cfg_rc_t cfg_node_link(cfg_node_t *node, cfg_node_link_t id, cfg_node_t *node2)
+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)
+{
+    /* FIXME */
+#if 0
+    cfg_rc_t rc;
+
+    if (cb_fct == NULL)
+        return CFG_ERR_ARG;
+    if (node != NULL) {
+        cb_fct(cb_ctx, node);
+        if (node->child1 != NULL)
+            if ((rc = cfg_node_apply(node->child1, cb_fct, cb_ctx)) != CFG_OK)
+                return rc;
+        if (node->rbroth != NULL)
+            if ((rc = cfg_node_apply(node->rbroth, cb_fct, cb_ctx)) != CFG_OK)
+                return rc;
+    }
+#endif
+    return CFG_OK;
+}
+
+cfg_rc_t
+cfg_node_cmp(
+    cfg_t *cfg, 
+    cfg_node_t *node, 
+    void *token)
+{
+    /* FIXME */
+    return CFG_OK;
+}
+
+cfg_rc_t cfg_node_link(cfg_t *cfg, cfg_node_t *node, cfg_node_attr_t attr, cfg_node_t *node2)
 {
     cfg_node_t *n;
 
     if (node == NULL || node2 == NULL)
         return CFG_ERR_ARG;
-    if (id == CFG_NODE_LINK_RBROTH) {
+    if (attr == CFG_NODE_ATTR_RBROTH) {
         /* make node a rbroth */
         n = node2;
         n->parent = node->parent;
@@ -196,7 +287,7 @@
         n->rbroth = node->rbroth; 
         node->rbroth = node2;
     }
-    else if (id == CFG_NODE_LINK_CHILD1) {
+    else if (attr == CFG_NODE_ATTR_CHILD1) {
         /* make node a child1 */
         n = node2;
         n->parent = node;
@@ -207,10 +298,13 @@
         n->rbroth = node->child1;
         node->child1 = node2;
     }
+    /* FIXME more linkage possibilities */
+    else 
+        return CFG_ERR_ARG;
     return CFG_OK;
 }
 
-cfg_rc_t cfg_node_unlink(cfg_node_t *node)
+cfg_rc_t cfg_node_unlink(cfg_t *cfg, cfg_node_t *node)
 {
     cfg_node_t *n;
 
@@ -232,31 +326,3 @@
     return CFG_OK;
 }
 
-cfg_rc_t cfg_node_apply(cfg_node_t *node, void (*cb_fct)(void *, cfg_node_t *), void *cb_ctx)
-{
-    cfg_rc_t rc;
-
-    if (cb_fct == NULL)
-        return CFG_ERR_ARG;
-    if (node != NULL) {
-        cb_fct(cb_ctx, node);
-        if (node->child1 != NULL)
-            if ((rc = cfg_node_apply(node->child1, cb_fct, cb_ctx)) != CFG_OK)
-                return rc;
-        if (node->rbroth != NULL)
-            if ((rc = cfg_node_apply(node->rbroth, cb_fct, cb_ctx)) != CFG_OK)
-                return rc;
-    }
-    return CFG_OK;
-}
-
-cfg_rc_t cfg_node_destroy(cfg_node_t *node)
-{
-    if (node == NULL)
-        return CFG_ERR_ARG;
-    if (node->token != NULL)
-        free(node->token);
-    free(node);
-    return CFG_OK;
-}
-


ossp-pkg/cfg/cfg_node.h 1.3 -> 1.4

--- cfg_node.h   2002/07/04 12:30:08     1.3
+++ cfg_node.h   2002/07/10 12:00:23     1.4
@@ -37,6 +37,7 @@
 struct cfg_node_st {
     /* node linkage */
     cfg_node_t     *parent;  /* pointer to parent node */
+    cfg_node_t     *lbroth;  /* pointer to left  brother node */
     cfg_node_t     *rbroth;  /* pointer to right brother node */
     cfg_node_t     *child1;  /* pointer to first child node */
 
@@ -46,6 +47,10 @@
 
     /* node annotation */
     cfg_data_t      data;    /* annotation data */ 
+
+    /* node source location */
+    char           *name;    /* name of original source configuration */
+    int             offset;  /* offset into original source configuration */
 };
 
 #endif /* __CFG_NODE_H__ */


ossp-pkg/cfg/cfg_syn.c 1.10 -> 1.11

--- cfg_syn.c    2002/07/08 13:45:13     1.10
+++ cfg_syn.c    2002/07/10 12:00:23     1.11
@@ -168,6 +168,7 @@
 }
 
 typedef struct {
+    cfg_t *cfg;
     cfg_buf_t *buf;
     int indent;
 } export_t;
@@ -267,33 +268,33 @@
     cfg_rc_t rc;
     char *token;
 
-    rc = cfg_node_get(node, CFG_NODE_ATTR_TYPE, &type);
+    rc = cfg_node_get(ctx->cfg, node, CFG_NODE_ATTR_TYPE, &type);
     if (type == CFG_NODE_TYPE_SEQ) {
         export_format(ctx, "{\n");
         export_indent(ctx, 1);
-        cfg_node_goto(node, CFG_NODE_GOTO_CHILD1, &node2);
+        cfg_node_get(ctx->cfg, node, CFG_NODE_ATTR_CHILD1, &node2);
         while (node2 != NULL) {
             export_node(ctx, node2);
-            cfg_node_goto(node2, CFG_NODE_GOTO_RBROTH, &node2);
+            cfg_node_get(ctx->cfg, node2, CFG_NODE_ATTR_RBROTH, &node2);
         }
         export_indent(ctx, -1);
         export_format(ctx, "}");
     }
     else if (type == CFG_NODE_TYPE_DIR) {
-        cfg_node_goto(node, CFG_NODE_GOTO_CHILD1, &node2);
+        cfg_node_get(ctx->cfg, node, CFG_NODE_ATTR_CHILD1, &node2);
         while (node2 != NULL) {
             export_node(ctx, node2);
-            cfg_node_goto(node2, CFG_NODE_GOTO_RBROTH, &node2);
+            cfg_node_get(ctx->cfg, node2, CFG_NODE_ATTR_RBROTH, &node2);
             if (node2 != NULL)
                 export_format(ctx, " ");
         }
-        cfg_node_goto(node, CFG_NODE_GOTO_RBROTH, &node2);
+        cfg_node_get(ctx->cfg, node, CFG_NODE_ATTR_RBROTH, &node2);
         if (node2 != NULL)
             export_format(ctx, ";");
         export_format(ctx, "\n");
     }
-    else if (type == CFG_NODE_TYPE_TOK) {
-        cfg_node_get(node, CFG_NODE_ATTR_TOKEN, &token);
+    else if (type == CFG_NODE_TYPE_ARG) {
+        cfg_node_get(ctx->cfg, node, CFG_NODE_ATTR_TOKEN, &token);
         if (token != NULL)
             export_token(ctx, token);
         else
@@ -316,15 +317,16 @@
     if ((rc = cfg_buf_create(&buf)) != CFG_OK)
         return rc;
 
+    ctx.cfg    = cfg;
     ctx.buf    = buf;
     ctx.indent = 0;
 
     /* first SEQ node is special, so expand it manually instead
        of just calling once export_node(&ctx, node); */
-    cfg_node_goto(node, CFG_NODE_GOTO_CHILD1, &node);
+    cfg_node_get(cfg, node, CFG_NODE_ATTR_CHILD1, &node);
     while (node != NULL) {
         export_node(&ctx, node);
-        cfg_node_goto(node, CFG_NODE_GOTO_RBROTH, &node);
+        cfg_node_get(cfg, node, CFG_NODE_ATTR_RBROTH, &node);
     }
 
     cfg_buf_content(buf, output, NULL, NULL);
@@ -333,15 +335,15 @@
     return CFG_OK;
 }
 
-static cfg_rc_t cfg_syn_destroy_node(cfg_node_t *node)
+static cfg_rc_t cfg_syn_destroy_node(cfg_t *cfg, cfg_node_t *node)
 {
     if (node == NULL)
         return CFG_ERR_ARG;
     if (node->child1 != NULL)
-        cfg_syn_destroy_node(node->child1);
+        cfg_syn_destroy_node(cfg, node->child1);
     if (node->rbroth != NULL)
-        cfg_syn_destroy_node(node->rbroth);
-    cfg_node_destroy(node);
+        cfg_syn_destroy_node(cfg, node->rbroth);
+    cfg_node_destroy(cfg, node);
     return CFG_OK;
 }
 
@@ -349,7 +351,7 @@
 {
     if (node == NULL)
         return CFG_ERR_ARG;
-    cfg_syn_destroy_node(node);
+    cfg_syn_destroy_node(cfg, node);
     return CFG_OK;
 }
 


ossp-pkg/cfg/cfg_syn_parse.y 1.2 -> 1.3

--- cfg_syn_parse.y      2002/07/04 14:51:21     1.2
+++ cfg_syn_parse.y      2002/07/10 12:00:23     1.3
@@ -105,9 +105,9 @@
 sequence
     : directives {
         cfg_node_t *n;
-        cfg_node_create(&n);
-        cfg_node_set(n, CFG_NODE_ATTR_TYPE, CFG_NODE_TYPE_SEQ);
-        cfg_node_set(n, CFG_NODE_ATTR_CHILD1, $1);
+        cfg_node_create(CTX->cfg, &n);
+        cfg_node_set(CTX->cfg, n, CFG_NODE_ATTR_TYPE, CFG_NODE_TYPE_SEQ);
+        cfg_node_set(CTX->cfg, n, CFG_NODE_ATTR_CHILD1, $1);
         $$ = n;
       }
     ;
@@ -120,7 +120,7 @@
         $$ = $1; 
       }
     | directive T_SEP directives { 
-        cfg_node_set($1, CFG_NODE_ATTR_RBROTH, $3);
+        cfg_node_set(CTX->cfg, $1, CFG_NODE_ATTR_RBROTH, $3);
         $$ = $1;
       }
     ;
@@ -128,9 +128,9 @@
 directive
     : tokens {
         cfg_node_t *n;
-        cfg_node_create(&n);
-        cfg_node_set(n, CFG_NODE_ATTR_TYPE, CFG_NODE_TYPE_DIR);
-        cfg_node_set(n, CFG_NODE_ATTR_CHILD1, $1);
+        cfg_node_create(CTX->cfg, &n);
+        cfg_node_set(CTX->cfg, n, CFG_NODE_ATTR_TYPE, CFG_NODE_TYPE_DIR);
+        cfg_node_set(CTX->cfg, n, CFG_NODE_ATTR_CHILD1, $1);
         $$ = n;
       }
     ;
@@ -140,7 +140,7 @@
         $$ = $1; 
       }
     | token tokens { 
-        cfg_node_set($1, CFG_NODE_ATTR_RBROTH, $2);
+        cfg_node_set(CTX->cfg, $1, CFG_NODE_ATTR_RBROTH, $2);
         $$ = $1;
       }
     ;
@@ -157,9 +157,9 @@
 string
     : T_STRING {
         cfg_node_t *n;
-        cfg_node_create(&n);
-        cfg_node_set(n, CFG_NODE_ATTR_TYPE, CFG_NODE_TYPE_TOK);
-        cfg_node_set(n, CFG_NODE_ATTR_TOKEN, $1);
+        cfg_node_create(CTX->cfg, &n);
+        cfg_node_set(CTX->cfg, n, CFG_NODE_ATTR_TYPE, CFG_NODE_TYPE_ARG);
+        cfg_node_set(CTX->cfg, n, CFG_NODE_ATTR_TOKEN, $1);
         $$ = n; 
       }
     ;


ossp-pkg/cfg/cfg_syn_scan.l 1.7 -> 1.8

--- cfg_syn_scan.l       2002/07/08 13:45:13     1.7
+++ cfg_syn_scan.l       2002/07/10 12:00:23     1.8
@@ -82,9 +82,9 @@
     /* local variables */
     char  caStr[1024];
     char *cpStr = NULL;
-    int   nQuoteOpen;
-    char  cQuoteOpen;
-    char  cQuoteClose;
+    int   nQuoteOpen = 0;
+    char  cQuoteOpen = '\0';
+    char  cQuoteClose = '\0';
 
     /* whitespaces */
 [ \t\n]+ {

CVSTrac 2.0.1