OSSP CVS Repository

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

Check-in Number: 2292
Date: 2002-Jul-16 16:59:53 (local)
2002-Jul-16 14:59:53 (UTC)
User:thl
Branch:
Comment: now read and check syntax, no recursion required
Tickets:
Inspections:
Files:
ossp-pkg/fsl/fsl.c      1.5 -> 1.6     91 inserted, 7 deleted

ossp-pkg/fsl/fsl.c 1.5 -> 1.6

--- fsl.c        2002/07/16 13:49:29     1.5
+++ fsl.c        2002/07/16 14:59:53     1.6
@@ -176,12 +176,19 @@
     int rc;
     buf_t buf;
     fsl_rc_t rv;
-    cfg_t      *cfg     = NULL;
-    cfg_rc_t    cfgrv   = CFG_OK;
-    cfg_node_t *cfgroot;
+    cfg_t           *cfg     = NULL;
+    cfg_rc_t         cfgrv   = CFG_OK;
+    cfg_node_t      *cfgseq;
+    cfg_node_t      *cfgdir;
+    cfg_node_t      *cfgarg;
+    cfg_node_type_t  cfgtype;
+    int              cfgnumc;
+    char *argident;
+    char *argmatch;
+    char *argl2spec;
     char *cp;
 
-fprintf(stderr, "DEBUG: main(ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx)\n", ident, (unsigned long)logopt, (unsigned long)facility);
+fprintf(stderr, "DEBUG: BEGIN ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx\n", ident, (unsigned long)logopt, (unsigned long)facility);
     buf.base = NULL;
     buf.used = 0;
     buf.size = 0;
@@ -195,15 +202,92 @@
     if ((cfgrv = cfg_import(cfg, NULL, CFG_FMT_CFG, buf.base, buf.size)) != CFG_OK) {
         (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_import() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
 
-    if ((cfgrv = cfg_node_root(cfg, &cfgroot)) != CFG_OK) {
+    /*  find root and check if it is a sequence and has one or more directives below it */
+    if ((cfgrv = cfg_node_root(cfg, &cfgseq)) != CFG_OK) {
         (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_root() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
-    traverse(cfg, cfgroot);
+    //FIXME traverse(cfg, cfgseq); /* DEBUG */
+    if ((cfgrv = cfg_node_get(cfg, cfgseq, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) {
+        (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+    if (cfgtype != CFG_NODE_TYPE_SEQ) {
+        fprintf(stderr, "ERROR: expected sequence\n"); CU(1); }
+    if ((cfgrv = cfg_node_get(cfg, cfgseq, CFG_NODE_ATTR_CHILDS, &cfgnumc)) != CFG_OK) {
+        (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+    if (cfgnumc < 1) {
+        fprintf(stderr, "ERROR: sequence is missing directives, expected 1, got %d\n", cfgnumc); CU(1); }
+
+    /*  get first directive below sequence */
+    if ((cfgrv = cfg_node_get(cfg, cfgseq, CFG_NODE_ATTR_CHILD1, &cfgdir)) != CFG_OK) {
+        (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+    while (cfgdir != NULL) {
+        //FIXME fprintf(stderr, "DEBUG: cfgdir=0x%.8lx\n", (unsigned long)cfgdir);
+
+        /*  check if operating on a directive which has exactly three arguments */
+        if ((cfgrv = cfg_node_get(cfg, cfgdir, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) {
+            (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+        if (cfgtype != CFG_NODE_TYPE_DIR) {
+            fprintf(stderr, "ERROR: expected directive\n"); CU(1); }
+        if ((cfgrv = cfg_node_get(cfg, cfgdir, CFG_NODE_ATTR_CHILDS, &cfgnumc)) != CFG_OK) {
+            (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+        if (cfgnumc != 3) {
+            fprintf(stderr, "ERROR: directive missing arguments, expected 3, got %d\n", cfgnumc); CU(1); }
+
+        /*  process first child of directive, check if it is an argument and has a valid token attached */
+        if ((cfgrv = cfg_node_get(cfg, cfgdir, CFG_NODE_ATTR_CHILD1, &cfgarg)) != CFG_OK) {
+            (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+        if (cfgarg == NULL) {
+            fprintf(stderr, "ERROR: argument \"argident\" is NULL\n"); CU(1); }
+        if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) {
+            (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+        if (cfgtype != CFG_NODE_TYPE_ARG) {
+            fprintf(stderr, "ERROR: expected argument\n"); CU(1); }
+        if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TOKEN, &argident)) != CFG_OK) {
+            (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+        if (argident == NULL) {
+            fprintf(stderr, "ERROR: argument \"argident\" has NULL data\n"); CU(1); }
+
+        /*  process right brother of argument, check if it is an argument and has a valid token attached */
+        if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_RBROTH, &cfgarg)) != CFG_OK) {
+            (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+        if (cfgarg == NULL) {
+            fprintf(stderr, "ERROR: argument \"argmatch\" is NULL\n"); CU(1); }
+        if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) {
+            (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+        if (cfgtype != CFG_NODE_TYPE_ARG) {
+            fprintf(stderr, "ERROR: expected argument\n"); CU(1); }
+        if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TOKEN, &argmatch)) != CFG_OK) {
+            (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+        if (argmatch == NULL) {
+            fprintf(stderr, "ERROR: argument \"argmatch\" has NULL data\n"); CU(1); }
+
+        /*  process right brother of argument, check if it is an argument and has a valid token attached */
+        if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_RBROTH, &cfgarg)) != CFG_OK) {
+            (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+        if (cfgarg == NULL) {
+            fprintf(stderr, "ERROR: argument \"argl2spec\" is NULL\n"); CU(1); }
+        if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) {
+            (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+        if (cfgtype != CFG_NODE_TYPE_ARG) {
+            fprintf(stderr, "ERROR: expected argument\n"); CU(1); }
+        if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TOKEN, &argl2spec)) != CFG_OK) {
+            (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+        if (argl2spec == NULL) {
+            fprintf(stderr, "ERROR: argument \"argl2spec\" has NULL data\n"); CU(1); }
+
+        /*  process the directive using the three arguments found */
+        fprintf(stderr, "DEBUG: argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec);
+
+        /*  get right brother of current directive */
+        if ((cfgrv = cfg_node_get(cfg, cfgdir, CFG_NODE_ATTR_RBROTH, &cfgdir)) != CFG_OK) {
+            (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+    }
+
+
 #if 0
     if ((cfgrv = cfg_destroy(cfg)) != CFG_OK) {
         (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_destroy() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
 #endif
 
-fprintf(stderr, "DEBUG: main() OK, buf.base=0x%.8lx, buf.used=%d, buf.size=%d\n", (unsigned long)buf.base, (int)buf.used, (int)buf.size);
+fprintf(stderr, "DEBUG: *END*, buf.base=0x%.8lx, buf.used=%d, buf.size=%d\n", (unsigned long)buf.base, (int)buf.used, (int)buf.size);
     CU(0);
 CUS:
     FIXMEopenlog(ident, logopt, facility);

CVSTrac 2.0.1