hdf_dump_cb data loss

Nikolai Kondrashov <[email protected]>
Newsgroups gmane.text.clearsilver.general
Message-ID <[email protected]>
Hello, all!

I'm not sure whether it is a bug or just design inconsistency, but
hdf_dump_cb (used, for example, by hdf_write_file) ignores nodes without
both value and children.

So, if you read a file like that:

fruit {
  apple {
    color = green
  }
  orange {
  }
}

then "fruit.orange" node will be created, but will not have neither value
(i.e. it will be NULL) nor children.

But if you will write this dataset into a file using hdf_write_file, you
will end up with this:

fruit {
  apple {
    color = green
  }
}

Note: "fruit.orange" is lost.

Below is a patch, which seems to fix it. It also should fix a case of lost
attributes on a node without value, and also extra space character after
attributes.
---:<---
--- util/neo_hdf.c      (revision 41766)
+++ util/neo_hdf.c      (working copy)
@@ -1146,7 +1146,7 @@
                            void *rock, DUMPF_CB dump_cbf)
 {
   NEOERR *err;
-  char *p, op;
+  char *p;
   char ml[10] = "\nEOM\n";
   int ml_len = strlen(ml);
   char whsp[256] = "";
@@ -1163,10 +1163,8 @@

   while (hdf != NULL)
   {
-    op = '=';
-    if (hdf->value)
+    if (hdf->value || hdf->attr || !hdf->child)
     {
-      if (hdf->link) op = ':';
       if (prefix && (dtype == DUMP_TYPE_DOTTED))
       {
        err = dump_cbf(rock, "%s.%s", prefix, hdf->name);
@@ -1204,11 +1202,22 @@
          }
          attr = attr->next;
        }
-       err = dump_cbf(rock, "] ");
+       err = dump_cbf(rock, "]");
        if (err) return nerr_pass(err);
       }
-      if (strchr (hdf->value, '\n'))
+      if (!hdf->value)
       {
+       if (dtype == DUMP_TYPE_DOTTED)
+         err = dump_cbf(rock, " {}\n");
+       else
+         err = dump_cbf(rock, " {\n%s}\n", whsp);
+      }
+      else if (hdf->link)
+      {
+       err = dump_cbf(rock, " : %s\n", hdf->value);
+      }
+      else if (strchr (hdf->value, '\n'))
+      {
        int vlen = strlen(hdf->value);

        while (strstr(hdf->value, ml) || ((vlen > ml_len) && !strncmp(hdf->value + vlen - ml_len + 1, ml, strlen(ml) - 1)))
@@ -1223,7 +1232,7 @@
       }
       else
       {
-       err = dump_cbf(rock, " %c %s\n", op, hdf->value);
+       err = dump_cbf(rock, " = %s\n", hdf->value);
       }
       if (err) return nerr_pass (err);
     }
--->:---

Thanks for your attention :)

Sincerely,
Nick



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ClearSilver/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/ClearSilver/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[email protected] 
    mailto:[email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.