Comment node. Extra root level for XML parsed data1
[yaz-moved-to-github.git] / retrieval / d1_write.c
index 51f2ff3..b93a1e7 100644 (file)
@@ -3,7 +3,7 @@
  * See the file LICENSE for details.
  * Sebastian Hammer, Adam Dickmeiss
  *
- * $Id: d1_write.c,v 1.10 2002-04-15 09:06:30 adam Exp $
+ * $Id: d1_write.c,v 1.12 2002-05-21 07:43:16 adam Exp $
  */
 
 #include <string.h>
@@ -43,13 +43,11 @@ static int nodetoidsgml(data1_node *n, int select, WRBUF b, int col)
            }
            else
            {
-#if DATA1_USING_XATTR
                data1_xattr *p;
-#endif
+
                sprintf (line, "%*s<", col, "");
                wrbuf_puts (b, line);
                wrbuf_puts (b, tag);
-#if DATA1_USING_XATTR
                for (p = c->u.tag.attributes; p; p = p->next)
                {
                    wrbuf_putc (b, ' ');
@@ -59,7 +57,6 @@ static int nodetoidsgml(data1_node *n, int select, WRBUF b, int col)
                    wrbuf_puts (b, p->value);
                    wrbuf_putc (b, '"');
                }
-#endif
                wrbuf_puts(b, ">\n");
                if (nodetoidsgml(c, select, b, (col > 40) ? 40 : col+2) < 0)
                    return -1;
@@ -67,50 +64,64 @@ static int nodetoidsgml(data1_node *n, int select, WRBUF b, int col)
                wrbuf_write(b, line, strlen(line));
            }
        }
-       else if (c->which == DATA1N_data)
+       else if (c->which == DATA1N_data || c->which == DATA1N_comment)
        {
            char *p = c->u.data.data;
            int l = c->u.data.len;
            int first = 1;
            int lcol = col;
 
-           sprintf(line, "%*s", col, "");
-           wrbuf_write(b, line, strlen(line));
+            if (!c->u.data.formatted_text)
+            {
+                sprintf(line, "%*s", col, "");
+                wrbuf_write(b, line, strlen(line));
+            }
+            if (c->which == DATA1N_comment)
+            {
+                wrbuf_write (b, "<!--", 4);
+            }
            switch (c->u.data.what)
            {
            case DATA1I_text:
-               while (l)
-               {
-                   int wlen;
-                   
-                   while (l && d1_isspace(*p))
-                       p++, l--;
-                   if (!l)
-                       break;
-                   /* break if we'll cross margin and word is not too long */
-                   if (lcol + (wlen = wordlen(p, l)) > IDSGML_MARGIN && wlen <
-                       IDSGML_MARGIN)
-                   {
-                       sprintf(line, "\n%*s", col, "");
-                       lcol = col;
-                       wrbuf_write(b, line, strlen(line));
-                       first = 1;
-                   }
-                   if (!first)
-                   {
-                       wrbuf_putc(b, ' ');
-                       lcol++;
-                   }
-                   while (l && !d1_isspace(*p))
-                   {
-                       wrbuf_putc(b, *p);
-                       p++;
-                       l--;
-                       lcol++;
-                   }
-                   first = 0;
-               }
-               wrbuf_write(b, "\n", 1);
+                if (c->u.data.formatted_text)
+                {
+                    wrbuf_write (b, p, l);
+                }
+                else
+                {
+                    while (l)
+                    {
+                        int wlen;
+                        
+                        while (l && d1_isspace(*p))
+                            p++, l--;
+                        if (!l)
+                            break;
+                        /* break if we cross margin and word is not too long */
+                        if (lcol + (wlen = wordlen(p, l)) > IDSGML_MARGIN &&
+                            wlen < IDSGML_MARGIN)
+                        {
+                            sprintf(line, "\n%*s", col, "");
+                            lcol = col;
+                            wrbuf_write(b, line, strlen(line));
+                            first = 1;
+                        }
+                        if (!first)
+                        {
+                            wrbuf_putc(b, ' ');
+                            lcol++;
+                        }
+                        while (l && !d1_isspace(*p))
+                        {
+                            wrbuf_putc(b, *p);
+                            p++;
+                            l--;
+                            lcol++;
+                        }
+                        first = 0;
+                    }
+                    wrbuf_write(b, "\n", 1);
+                }
                break;
            case DATA1I_num:
                wrbuf_write(b, c->u.data.data, c->u.data.len);
@@ -118,6 +129,10 @@ static int nodetoidsgml(data1_node *n, int select, WRBUF b, int col)
            case DATA1I_oid:
                wrbuf_write(b, c->u.data.data, c->u.data.len);
            }
+            if (c->which == DATA1N_comment)
+            {
+                wrbuf_write (b, "-->", 3);
+            }
        }
     }
     return 0;