2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.1 1995-12-13 15:38:43 quinn
8 * Added SGML-output filter.
19 #define IDSGML_MARGIN 75
21 static int wordlen(char *b)
25 while (*b && !isspace(*b))
30 static int nodetoidsgml(data1_node *n, int select, WRBUF b, int col)
35 for (c = n->child; c; c = c->next)
39 if (c->which == DATA1N_tag)
41 if (select && c->u.tag.node_selected)
43 if (c->u.tag.element && c->u.tag.element->tag)
44 tag = c->u.tag.element->tag->names->name; /* first name */
46 tag = c->u.tag.tag; /* local string tag */
47 if (data1_matchstr(tag, "wellknown")) /* skip wellknown */
49 sprintf(line, "<%s>\n", tag);
50 wrbuf_write(b, line, strlen(line));
53 if (nodetoidsgml(c, select, b, col) < 0)
55 wrbuf_write(b, "</>\n", 5);
58 else if (c->which == DATA1N_data)
60 char *p = c->u.data.data;
61 int l = c->u.data.len;
64 if (c->u.data.what == DATA1I_text)
70 while (l && isspace(*p))
74 /* break if we'll cross margin and word is not too long */
75 if (col + (wlen = wordlen(p)) > IDSGML_MARGIN && wlen <
80 wrbuf_write(b, line, strlen(line));
88 while (l && !isspace(*p))
91 if (col > NTOBUF_MARGIN)
95 sprintf(line, "%*s", indent * NTOBUF_INDENT, "");
96 wrbuf_write(b, line, strlen(line));
97 col = indent * NTOBUF_INDENT;
107 wrbuf_write(b, "\n", 1);
110 else if (c->u.data.what == DATA1I_num)
113 wrbuf_write(b, c->u.data.data, c->u.data.len);
120 char *data1_nodetoidsgml(data1_node *n, int select, int *len)
130 sprintf(line, "<%s>\n", n->u.root.type);
131 wrbuf_write(b, line, strlen(line));
132 if (nodetoidsgml(n, select, b, 0))
134 sprintf(line, "</%s>\n", n->u.root.type);
135 wrbuf_write(b, line, strlen(line));