OSSP CVS Repository

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

Check-in Number: 2275
Date: 2002-Jul-10 21:26:32 (local)
2002-Jul-10 19:26:32 (UTC)
User:rse
Branch:
Comment: implement cfg_node_clone
Tickets:
Inspections:
Files:
ossp-pkg/cfg/cfg_data.c      1.2 -> 1.3     14 inserted, 5 deleted
ossp-pkg/cfg/cfg_data.h      1.2 -> 1.3     4 inserted, 1 deleted
ossp-pkg/cfg/cfg_main.c      1.2 -> 1.3     1 inserted, 1 deleted
ossp-pkg/cfg/cfg_node.c      1.6 -> 1.7     25 inserted, 1 deleted

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

--- cfg_data.c   2002/07/10 12:00:23     1.2
+++ cfg_data.c   2002/07/10 19:26:32     1.3
@@ -84,6 +84,19 @@
     return CFG_OK;
 }
 
+cfg_rc_t cfg_data_copy(cfg_data_t *data, cfg_data_t *copy)
+{
+    cfg_rc_t rc;
+
+    if (data == NULL || copy == NULL)
+        return CFG_ERR_ARG;
+    copy->type = data->type;
+    copy->ctrl = data->ctrl;
+    if ((rc = data->ctrl(data, CFG_DATA_CTRL_CLONE, copy)) != CFG_OK)
+        return rc;
+    return CFG_OK;
+}
+
 cfg_rc_t cfg_data_clone(cfg_data_t *data, cfg_data_t **clone)
 {
     cfg_rc_t rc;
@@ -92,12 +105,8 @@
         return CFG_ERR_ARG;
     if ((*clone = (cfg_data_t *)malloc(sizeof(cfg_data_t))) == NULL)
         return CFG_ERR_SYS;
-    (*clone)->type = data->type;
-    (*clone)->ctrl = data->ctrl;
-    if ((rc = data->ctrl(data, CFG_DATA_CTRL_CLONE, *clone)) != CFG_OK) {
-        free(*clone);
+    if ((rc = cfg_data_copy(data, *clone)) != CFG_OK)
         return rc;
-    }
     return CFG_OK;
 }
 


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

--- cfg_data.h   2002/07/10 12:00:23     1.2
+++ cfg_data.h   2002/07/10 19:26:32     1.3
@@ -49,9 +49,12 @@
 
 extern cfg_rc_t  cfg_data_create       (cfg_data_t **data);
 extern cfg_rc_t  cfg_data_init         (cfg_data_t  *data);
-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_kill         (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_copy         (cfg_data_t  *data, cfg_data_t  *copy);
 
 #endif /* __CFG_DATA_H__ */
 


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

--- cfg_main.c   2002/07/10 14:46:28     1.2
+++ cfg_main.c   2002/07/10 19:26:32     1.3
@@ -158,7 +158,7 @@
     else 
         return CFG_ERR_INT; 
 
-    /* FIXME merge: cfg->root[node] := cfg->root[node] + root */
+    /* FIXME: merge: cfg->root[node] := cfg->root[node] + root */
     cfg->root = root;
 
     return CFG_OK;


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

--- cfg_node.c   2002/07/10 14:46:28     1.6
+++ cfg_node.c   2002/07/10 19:26:32     1.7
@@ -45,10 +45,13 @@
     if ((n = malloc(sizeof(cfg_node_t))) == NULL)
         return CFG_ERR_SYS;
     n->parent   = NULL;
+    n->lbroth   = NULL;
     n->rbroth   = NULL;
     n->child1   = NULL;
     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;
@@ -60,15 +63,36 @@
         return CFG_ERR_ARG;
     if (node->token != NULL)
         free(node->token);
+    if (node->name != NULL)
+        free(node->name);
     free(node);
     return CFG_OK;
 }
 
 cfg_rc_t cfg_node_clone(cfg_t *cfg, cfg_node_t *node, cfg_node_t **node2)
 {
+    cfg_node_t *n;
+
     if (node == NULL || node2 == NULL)
         return CFG_ERR_ARG;
-    /* FIXME */
+    if ((n = malloc(sizeof(cfg_node_t))) == NULL)
+        return CFG_ERR_SYS;
+    n->parent   = node->parent;
+    n->lbroth   = node->lbroth;
+    n->rbroth   = node->rbroth;
+    n->child1   = node->child1;
+    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;
+    cfg_data_copy(&node->data, &n->data);
+    *node2 = n;
     return CFG_OK;
 }
 

CVSTrac 2.0.1