2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.3 1997-09-17 12:10:37 adam
10 * Revision 1.2 1997/04/30 08:52:11 quinn
13 * Revision 1.1 1996/10/08 10:43:20 quinn
24 * This module generates SOIF (Simple Object Interchange Format) records
25 * from d1-nodes. nested elements are flattened out, depth first, by
26 * concatenating the tag names at each level.
29 static int nodetoelement(data1_node *n, int select, char *prefix, WRBUF b)
34 for (c = n->child; c; c = c->next)
38 if (c->which == DATA1N_tag)
40 if (select && !c->u.tag.node_selected)
42 if (c->u.tag.element && c->u.tag.element->tag)
43 tag = c->u.tag.element->tag->names->name; /* first name */
45 tag = c->u.tag.tag; /* local string tag */
48 sprintf(tmp, "%s-%s", prefix, tag);
52 if (nodetoelement(c, select, tmp, b) < 0)
55 else if (c->which == DATA1N_data)
57 char *p = c->u.data.data;
58 int l = c->u.data.len;
60 wrbuf_write(b, prefix, strlen(prefix));
62 sprintf(tmp, "{%d}:\t", l);
63 wrbuf_write(b, tmp, strlen(tmp));
71 char *data1_nodetosoif (data1_handle dh, data1_node *n, int select, int *len)
73 WRBUF b = data1_get_wrbuf (dh);
78 if (n->which != DATA1N_root)
80 sprintf(buf, "@%s{\n", n->u.root.type);
81 wrbuf_write(b, buf, strlen(buf));
82 if (nodetoelement(n, select, "", b))
84 wrbuf_write(b, "}\n", 2);