Re: hdf_dump_cb data loss

Brandon Long <[email protected]>
Newsgroups gmane.text.clearsilver.general
Organization Fiction L Networks
Message-ID <20070824002400.GC6853@bl1>
Thanks.  Probably just didn't think about nodes without values or
sub-nodes as that important, but seems no reason not to include them.

I'll put this in the next release.

Brandon

On 08/22/07 Nikolai Kondrashov uttered the following other thing:
> 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
> 
> 
> 

-- 
 "We [the Net] get portrayed in a crappy light...  This time it's a cult.  
  Usually, it's that we're all child pornographers."  
                    -- Internet Defender, _Washington Post_, 3-29-97
                                           http://www.fiction.net/blong/
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.