OSSP CVS Repository

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

Check-in Number: 2222
Date: 2002-Jul-04 14:30:08 (local)
2002-Jul-04 12:30:08 (UTC)
User:rse
Branch:
Comment: add a new cfg_node_goto() function
Tickets:
Inspections:
Files:
ossp-pkg/cfg/cfg.h      1.2 -> 1.3     13 inserted, 2 deleted
ossp-pkg/cfg/cfg_node.c      1.2 -> 1.3     46 inserted, 1 deleted
ossp-pkg/cfg/cfg_node.h      1.2 -> 1.3     6 inserted, 1 deleted

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

--- cfg.h        2002/07/04 06:16:13     1.2
+++ cfg.h        2002/07/04 12:30:08     1.3
@@ -42,7 +42,9 @@
     CFG_ERR_USE,
     CFG_ERR_INT,
     CFG_ERR_SYS,
-    CFG_ERR_SYN
+    CFG_ERR_SYN,
+    CFG_ERR_FMT,
+    CFG_ERR_GOT
 } cfg_rc_t;
 
 /* ============================================================ */
@@ -59,7 +61,6 @@
 
 /* list of node types */
 typedef enum {
-    CFG_NODE_TYPE_NN = 0,     /* node unknown */
     CFG_NODE_TYPE_SEQ,        /* node represents a sequence */
     CFG_NODE_TYPE_DIR,        /* node represents a directive */
     CFG_NODE_TYPE_TOK         /* node represents a token */
@@ -75,6 +76,15 @@
     CFG_NODE_ATTR_DATA        /* pointer to the node annotation data */
 } cfg_node_attr_t;
 
+/* list of node goto */
+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,
@@ -89,6 +99,7 @@
 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);


ossp-pkg/cfg/cfg_node.c 1.2 -> 1.3

--- cfg_node.c   2002/07/04 06:16:13     1.2
+++ cfg_node.c   2002/07/04 12:30:08     1.3
@@ -41,10 +41,10 @@
 
     if ((n = malloc(sizeof(cfg_node_t))) == NULL)
         return CFG_ERR_SYS;
-    n->type     = CFG_NODE_TYPE_NN;
     n->parent   = NULL;
     n->rbroth   = NULL;
     n->child1   = NULL;
+    n->type     = CFG_NODE_TYPE_TOK;
     n->token    = NULL;
     cfg_data_init(&n->data);
     *node = n;
@@ -134,6 +134,51 @@
     return CFG_OK;
 }
 
+cfg_rc_t cfg_node_goto(cfg_node_t *node, cfg_node_goto_t id, cfg_node_t **node2)
+{
+    cfg_node_t *n;
+
+    if (node == NULL || node2 == NULL)
+        return CFG_ERR_ARG;
+    *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;
+        }
+    }
+    if (*node2 == NULL)
+        return CFG_ERR_GOT;
+    return CFG_OK;
+}
+
 cfg_rc_t cfg_node_link(cfg_node_t *node, cfg_node_link_t id, cfg_node_t *node2)
 {
     cfg_node_t *n;


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

--- cfg_node.h   2002/07/04 06:16:13     1.2
+++ cfg_node.h   2002/07/04 12:30:08     1.3
@@ -35,11 +35,16 @@
 #include "cfg_data.h"
 
 struct cfg_node_st {
-    cfg_node_type_t type;    /* type of node */
+    /* node linkage */
     cfg_node_t     *parent;  /* pointer to parent node */
     cfg_node_t     *rbroth;  /* pointer to right brother node */
     cfg_node_t     *child1;  /* pointer to first child node */
+
+    /* node contents */
+    cfg_node_type_t type;    /* type of node */
     char           *token;   /* pointer to corresponding token string */
+
+    /* node annotation */
     cfg_data_t      data;    /* annotation data */ 
 };
 

CVSTrac 2.0.1