OSSP CVS Repository

ossp - Difference in ossp-pkg/cfg/cfg_test.c versions 1.1 and 1.2
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

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

--- cfg_test.c   2002/07/03 13:25:34     1.1
+++ cfg_test.c   2002/07/04 14:51:21     1.2
@@ -7,61 +7,7 @@
 #include "cfg_util.h"
 #include "cfg_node.h"
 #include "cfg_syn.h"
-
-typedef struct {
-    int line;
-    int col;
-    FILE *fp;
-} cb_ctx_t;
-
-static void cb_out(cb_ctx_t *ctx, char *str)
-{
-    int i;
-
-    fprintf(stderr, "cb_out <%s>\n", str);
-    fprintf(ctx->fp, "%s", str);
-    for (i = 0; str[i] != '\0'; i++) {
-        if (str[i] == '\n') {
-            ctx->line++;
-            ctx->col = 0;
-        }
-        else {
-            ctx->col++;
-        }
-    }
-}
-
-static void cb_fct(void *_ctx, cfg_node_t *node)
-{
-    cb_ctx_t *ctx = (cb_ctx_t *)_ctx;
-    cfg_node_type_t type;
-    cfg_node_t *node2;
-    cfg_rc_t rc;
-    char *token;
-
-    fprintf(stderr, "cb_fct enter\n");
-    rc = cfg_node_get(node, CFG_NODE_ATTR_TYPE, &type);
-    fprintf(stderr, "rc=%d type=%d\n", rc, type);
-    if (type == CFG_NODE_TYPE_SEQ) {
-        cb_out(ctx, " {\n");
-    }
-    else if (type == CFG_NODE_TYPE_DIR) {
-        cb_out(ctx, ";\n");
-        cfg_node_get(node, CFG_NODE_ATTR_RBROTH, &node2);
-        if (node2 == NULL)
-            cb_out(ctx, "};\n");
-    }
-    else if (type == CFG_NODE_TYPE_TOK) {
-        cfg_node_get(node, CFG_NODE_ATTR_TOKEN, &token);
-        if (token != NULL) {
-            cb_out(ctx, token);
-            cfg_node_get(node, CFG_NODE_ATTR_RBROTH, &node2);
-            if (node2 != NULL)
-                cb_out(ctx, " ");
-        }
-    }
-    fprintf(stderr, "cb_fct leave\n");
-}
+#include "cfg_buf.h"
 
 int main(int argc, char *argv[]) 
 {
@@ -79,18 +25,15 @@
         fprintf(stderr, "ERROR: reading file \"%s\"\n", argv[1]);
         exit(1);
     }
-    if ((rc = cfg_syn(NULL, &node, err_buf, sizeof(err_buf), buf_ptr)) != CFG_OK) {
+    rc = cfg_syn_import(NULL, &node, buf_ptr, err_buf, sizeof(err_buf));
+    free(buf_ptr);
+
+    if (rc != CFG_OK)
         fprintf(stderr, "ERROR: %s\n", err_buf);
-    }
     else {
-        cb_ctx_t ctx;
-
-        ctx.line = 0;
-        ctx.col = 0;
-        ctx.fp = stdout;
-        cfg_node_apply(node, cb_fct, &ctx);
+        cfg_syn_export(NULL, node, &buf_ptr);
+        fprintf(stdout, "%s\n", buf_ptr);
     }
-    free(buf_ptr);
 
     return 0;
 }

CVSTrac 2.0.1