OSSP CVS Repository

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

Check-in Number: 2280
Date: 2002-Jul-12 21:59:33 (local)
2002-Jul-12 19:59:33 (UTC)
User:rse
Branch:
Comment: just flush work of this evening
Tickets:
Inspections:
Files:
ossp-pkg/cfg/cfg.h      1.7 -> 1.8     4 inserted, 5 deleted
ossp-pkg/cfg/cfg.pod      1.2 -> 1.3     10 inserted, 0 deleted
ossp-pkg/cfg/cfg_node.c      1.7 -> 1.8     173 inserted, 73 deleted
ossp-pkg/cfg/cfg_node.h      1.4 -> 1.5     2 inserted, 2 deleted

ossp-pkg/cfg/cfg.h 1.7 -> 1.8

--- cfg.h        2002/07/10 14:46:28     1.7
+++ cfg.h        2002/07/12 19:59:33     1.8
@@ -72,11 +72,11 @@
     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 */
-    CFG_NODE_ATTR_SRCNAME,    /* RW: pointer to the source name */
-    CFG_NODE_ATTR_SRCPOS      /* RW: position offset into source */
+    CFG_NODE_ATTR_DATA        /* RW: pointer to the node annotation data */
 } cfg_node_attr_t;
 
 /* list of data types */
@@ -135,8 +135,7 @@
 
 /* node traversing/locating */
 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, cfg_node_t **node2);
-cfg_rc_t   cfg_node_select (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, cfg_node_t **node2, 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);


ossp-pkg/cfg/cfg.pod 1.2 -> 1.3

--- cfg.pod      2002/07/06 12:23:43     1.2
+++ cfg.pod      2002/07/12 19:59:33     1.3
@@ -165,6 +165,16 @@
 
 =head1 APPLICATION PROGRAMMING INTERFACE (API)
 
+spec:
+
+ parent  ..
+ lbroth  ->
+ rbroth  <-
+ child[1] 
+ child[L]
+
+ virtualhost[2].directory
+
 =head1 HISTORY
 
 B<OSSP cfg> was implemented in lots of small steps over a very


ossp-pkg/cfg/cfg_node.c 1.7 -> 1.8

--- cfg_node.c   2002/07/10 19:26:32     1.7
+++ cfg_node.c   2002/07/12 19:59:33     1.8
@@ -48,10 +48,10 @@
     n->lbroth   = NULL;
     n->rbroth   = NULL;
     n->child1   = NULL;
+    n->srcname  = NULL;
+    n->srcpos   = 0;
     n->type     = CFG_NODE_TYPE_ARG;
     n->token    = NULL;
-    n->name     = NULL;
-    n->offset   = 0;
     cfg_data_init(&n->data);
     *node = n;
     return CFG_OK;
@@ -63,8 +63,8 @@
         return CFG_ERR_ARG;
     if (node->token != NULL)
         free(node->token);
-    if (node->name != NULL)
-        free(node->name);
+    if (node->srcname != NULL)
+        free(node->srcname);
     free(node);
     return CFG_OK;
 }
@@ -81,16 +81,10 @@
     n->lbroth   = node->lbroth;
     n->rbroth   = node->rbroth;
     n->child1   = node->child1;
+    n->srcname  = (node->srcname != NULL ? strdup(node->srcname) : NULL);
+    n->srcpos   = node->srcpos;
     n->type     = node->type;
-    if (node->token != NULL)
-        n->token = strdup(node->token);
-    else
-        n->token = NULL;
-    if (node->name != NULL)
-        n->name = strdup(node->name);
-    else
-        n->name = NULL;
-    n->offset   = node->offset;
+    n->token    = (node->token != NULL ? strdup(node->token) : NULL);
     cfg_data_copy(&node->data, &n->data);
     *node2 = n;
     return CFG_OK;
@@ -104,14 +98,13 @@
         return CFG_ERR_ARG;
     va_start(ap, attr);
     switch (attr) {
-        case CFG_NODE_ATTR_TYPE: {
-            node->type = (cfg_node_type_t)va_arg(ap, cfg_node_type_t);
-            break;
-        }
         case CFG_NODE_ATTR_PARENT: {
             node->parent = (cfg_node_t *)va_arg(ap, cfg_node_t *);
             break;
         }
+        case CFG_NODE_ATTR_LBROTH: {
+            return CFG_ERR_USE;
+        }
         case CFG_NODE_ATTR_RBROTH: {
             node->rbroth = (cfg_node_t *)va_arg(ap, cfg_node_t *);
             break;
@@ -120,8 +113,40 @@
             node->child1 = (cfg_node_t *)va_arg(ap, cfg_node_t *);
             break;
         }
+        case CFG_NODE_ATTR_CHILDL: {
+            return CFG_ERR_USE;
+        }
+        case CFG_NODE_ATTR_CHILDS: {
+            return CFG_ERR_USE;
+        }
+        case CFG_NODE_ATTR_NODES: {
+            return CFG_ERR_USE;
+        }
+        case CFG_NODE_ATTR_DEPTH: {
+            return CFG_ERR_USE;
+        }
+        case CFG_NODE_ATTR_SRCNAME: {
+            if (node->srcname != NULL)
+                free(node->srcname);
+            node->srcname = (char *)va_arg(ap, char *);
+            if (node->srcname != NULL)
+                node->srcname = strdup(node->srcname);
+            break;
+        }
+        case CFG_NODE_ATTR_SRCPOS: {
+            node->srcpos = (int)va_arg(ap, int);
+            break;
+        }
+        case CFG_NODE_ATTR_TYPE: {
+            node->type = (cfg_node_type_t)va_arg(ap, cfg_node_type_t);
+            break;
+        }
         case CFG_NODE_ATTR_TOKEN: {
+            if (node->token != NULL)
+                free(node->token);
             node->token = (char *)va_arg(ap, char *);
+            if (node->token != NULL)
+                node->token = strdup(node->token);
             break;
         }
         case CFG_NODE_ATTR_DATA: {
@@ -134,6 +159,22 @@
     return CFG_OK;
 }
 
+static int cfg_node_get_nodes(cfg_node_t *node)
+{
+    int n;
+
+    n = 0;
+    if (node != NULL) {
+        n++;
+        if ((node = node->child1) != NULL) {
+            n += cfg_node_get_nodes(node);
+            if ((node = node->rbroth) != NULL)
+                n += cfg_node_get_nodes(node);
+        }
+    }
+    return n;
+}
+
 cfg_rc_t cfg_node_get(cfg_t *cfg, cfg_node_t *node, cfg_node_attr_t attr, ...)
 {
     va_list ap;
@@ -142,33 +183,117 @@
         return CFG_ERR_ARG;
     va_start(ap, attr);
     switch (attr) {
-        case CFG_NODE_ATTR_TYPE: {
-            cfg_node_type_t *type = (cfg_node_type_t *)va_arg(ap, void *);
-            *type = node->type;
-            break;
-        }
         case CFG_NODE_ATTR_PARENT: {
             cfg_node_t **n = (cfg_node_t **)va_arg(ap, void *);
+            if (n == NULL)
+                return CFG_ERR_ARG;
             *n = node->parent;
             break;
         }
+        case CFG_NODE_ATTR_LBROTH: {
+            cfg_node_t **np = (cfg_node_t **)va_arg(ap, void *);
+            cfg_node_t *n;
+            if (np == NULL)
+                return CFG_ERR_ARG;
+            *np = NULL;
+            if ((n = node->parent) != NULL) {
+                if ((n = n->child1) != NULL) {
+                    while (n->rbroth != node && n->rbroth != NULL)
+                        n = n->rbroth;
+                    if (n->rbroth == node)
+                        *np = n;
+                }
+            }
+            break;
+        }
         case CFG_NODE_ATTR_RBROTH: {
             cfg_node_t **n = (cfg_node_t **)va_arg(ap, void *);
+            if (n == NULL)
+                return CFG_ERR_ARG;
             *n = node->rbroth;
             break;
         }
         case CFG_NODE_ATTR_CHILD1: {
             cfg_node_t **n = (cfg_node_t **)va_arg(ap, void *);
+            if (n == NULL)
+                return CFG_ERR_ARG;
             *n = node->child1;
             break;
         }
+        case CFG_NODE_ATTR_CHILDL: {
+            cfg_node_t **n = (cfg_node_t **)va_arg(ap, void *);
+            if (n == NULL)
+                return CFG_ERR_ARG;
+            if ((*n = node->child1) != NULL)
+                while ((*n)->rbroth != NULL)
+                    *n = (*n)->rbroth;
+            break;
+        }
+        case CFG_NODE_ATTR_CHILDS: {
+            int *c = (int *)va_arg(ap, int *);
+            cfg_node_t *n;
+            if (c == NULL)
+                return CFG_ERR_ARG;
+            *c = 0;
+            if ((n = node->child1) != NULL) {
+                (*c)++;
+                while (n->rbroth != NULL) {
+                    n = n->rbroth;
+                    (*c)++;
+                }
+            }
+            break;
+        }
+        case CFG_NODE_ATTR_NODES: {
+            int *k = (int *)va_arg(ap, int *);
+            if (k == NULL)
+                return CFG_ERR_ARG;
+            *k = cfg_node_get_nodes(node);
+            break;
+        }
+        case CFG_NODE_ATTR_DEPTH: {
+            int *k = (int *)va_arg(ap, int *);
+            cfg_node_t *n;
+            if (k == NULL)
+                return CFG_ERR_ARG;
+            *k = 0; 
+            n = node;
+            while ((n = n->parent) != NULL)
+                (*k)++;
+            break;
+        }
+        case CFG_NODE_ATTR_SRCNAME: {
+            char **name = (char **)va_arg(ap, char **);
+            if (name == NULL)
+                return CFG_ERR_ARG;
+            *name = node->srcname;
+            break;
+        }
+        case CFG_NODE_ATTR_SRCPOS: {
+            int *pos = (int *)va_arg(ap, int *);
+            if (pos == NULL)
+                return CFG_ERR_ARG;
+            *pos = node->srcpos;
+            break;
+        }
+        case CFG_NODE_ATTR_TYPE: {
+            cfg_node_type_t *type = (cfg_node_type_t *)va_arg(ap, void *);
+            if (type == NULL)
+                return CFG_ERR_ARG;
+            *type = node->type;
+            break;
+        }
         case CFG_NODE_ATTR_TOKEN: {
             char **token = (char **)va_arg(ap, char **);
+            if (token == NULL)
+                return CFG_ERR_ARG;
             *token = node->token;
             break;
         }
         case CFG_NODE_ATTR_DATA: {
             cfg_data_t **data = (cfg_data_t **)va_arg(ap, void *);
+            if (data == NULL)
+                return CFG_ERR_ARG;
             *data = &(node->data);
             break;
         }
@@ -187,65 +312,40 @@
     return CFG_OK;
 }
 
-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, cfg_node_t **node2, const char *fmt, ...)
 {
-
-    if (cfg == NULL || node == NULL || spec == NULL || node2 == NULL)
-        return CFG_ERR_ARG;
-    /* FIXME */
 #if 0
     cfg_node_t *n;
-    *node2 = NULL;
-    switch (id) {
-        case CFG_NODE_GOTO_PARENT: {
-            *node2 = node->parent;
-            break;
-        }
-        case CFG_NODE_GOTO_LBROTH: {
-            if ((n = node->parent) != NULL) {
-                if ((n = n->child1) != NULL) {
-                    while (n->rbroth != node && n->rbroth != NULL)
-                        n = n->rbroth;
-                    if (n->rbroth == node)
-                        *node2 = n;
-                }
-            }
-            break;
-        }
-        case CFG_NODE_GOTO_RBROTH: {
-            *node2 = node->rbroth; 
-            break;
-        }
-        case CFG_NODE_GOTO_CHILD1: { 
-            *node2 = node->child1; 
-            break;
-        }
-        case CFG_NODE_GOTO_CHILDL: {
-            if ((n = node->child1) != NULL) {
-                while (n->rbroth != NULL)
-                    n = n->rbroth;
-                *node2 = n;
-            }
-            break;
-        }
+    va_list ap;
+    char *cpB;
+    char *cpE;
+    char *spec;
+
+    if (cfg == NULL || node == NULL || node2 == NULL || spec == NULL)
+        return CFG_ERR_ARG;
+
+    /* on-the-fly create or just take over specification string */
+    va_start(ap, fmt);
+    spec = l2_util_vasprintf(fmt, ap);
+    va_end(ap);
+
+    /* enter the parsing loop */
+    cpE = spec;
+    while (*cpE != '\0') {
+        /* determine begin of parameter name */
+        cpB = cpE;
+        if ((n = strspn(cpB, " \t\r\n")) > 0)
+            cpB += n;
+
+        /* determine end of parameter name */
+        cpE = cpB;
+        if ((n = strspn(cpB, " \t\r\n")) > 0)
+            cpB += n;
     }
-    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, 


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

--- cfg_node.h   2002/07/10 12:00:23     1.4
+++ cfg_node.h   2002/07/12 19:59:33     1.5
@@ -49,8 +49,8 @@
     cfg_data_t      data;    /* annotation data */ 
 
     /* node source location */
-    char           *name;    /* name of original source configuration */
-    int             offset;  /* offset into original source configuration */
+    char           *srcname; /* name of original source configuration */
+    int             srcpos;  /* offset into original source configuration */
 };
 
 #endif /* __CFG_NODE_H__ */

CVSTrac 2.0.1