2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1995-12-13 17:14:27 quinn
8 * *** empty log message ***
10 * Revision 1.1 1995/12/13 15:38:43 quinn
11 * Added SGML-output filter.
22 #define IDSGML_MARGIN 75
24 static int wordlen(char *b)
28 while (*b && !isspace(*b))
33 static int nodetoidsgml(data1_node *n, int select, WRBUF b, int col)
38 for (c = n->child; c; c = c->next)
42 if (c->which == DATA1N_tag)
44 if (select && c->u.tag.node_selected)
46 if (c->u.tag.element && c->u.tag.element->tag)
47 tag = c->u.tag.element->tag->names->name; /* first name */
49 tag = c->u.tag.tag; /* local string tag */
50 if (data1_matchstr(tag, "wellknown")) /* skip wellknown */
52 sprintf(line, "<%s>\n", tag);
53 wrbuf_write(b, line, strlen(line));
56 if (nodetoidsgml(c, select, b, col) < 0)
58 wrbuf_write(b, "</>\n", 4);
61 else if (c->which == DATA1N_data)
63 char *p = c->u.data.data;
64 int l = c->u.data.len;
67 if (c->u.data.what == DATA1I_text)
73 while (l && isspace(*p))
77 /* break if we'll cross margin and word is not too long */
78 if (col + (wlen = wordlen(p)) > IDSGML_MARGIN && wlen <
83 wrbuf_write(b, line, strlen(line));
91 while (l && !isspace(*p))
94 if (col > NTOBUF_MARGIN)
98 sprintf(line, "%*s", indent * NTOBUF_INDENT, "");
99 wrbuf_write(b, line, strlen(line));
100 col = indent * NTOBUF_INDENT;
110 wrbuf_write(b, "\n", 1);
113 else if (c->u.data.what == DATA1I_num)
116 wrbuf_write(b, c->u.data.data, c->u.data.len);
123 char *data1_nodetoidsgml(data1_node *n, int select, int *len)
133 sprintf(line, "<%s>\n", n->u.root.type);
134 wrbuf_write(b, line, strlen(line));
135 if (nodetoidsgml(n, select, b, 0))
137 sprintf(line, "</%s>\n", n->u.root.type);
138 wrbuf_write(b, line, strlen(line));