2 * Copyright (c) 1995-1997, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.3 1997-09-17 12:10:39 adam
10 * Revision 1.2 1995/12/13 17:14:27 quinn
11 * *** empty log message ***
13 * Revision 1.1 1995/12/13 15:38:43 quinn
14 * Added SGML-output filter.
25 #define IDSGML_MARGIN 75
27 static int wordlen(char *b)
31 while (*b && !isspace(*b))
36 static int nodetoidsgml(data1_node *n, int select, WRBUF b, int col)
41 for (c = n->child; c; c = c->next)
45 if (c->which == DATA1N_tag)
47 if (select && c->u.tag.node_selected)
49 if (c->u.tag.element && c->u.tag.element->tag)
50 tag = c->u.tag.element->tag->names->name; /* first name */
52 tag = c->u.tag.tag; /* local string tag */
53 if (data1_matchstr(tag, "wellknown")) /* skip wellknown */
55 sprintf(line, "<%s>\n", tag);
56 wrbuf_write(b, line, strlen(line));
59 if (nodetoidsgml(c, select, b, col) < 0)
61 wrbuf_write(b, "</>\n", 4);
64 else if (c->which == DATA1N_data)
66 char *p = c->u.data.data;
67 int l = c->u.data.len;
70 if (c->u.data.what == DATA1I_text)
76 while (l && isspace(*p))
80 /* break if we'll cross margin and word is not too long */
81 if (col + (wlen = wordlen(p)) > IDSGML_MARGIN && wlen <
86 wrbuf_write(b, line, strlen(line));
94 while (l && !isspace(*p))
97 if (col > NTOBUF_MARGIN)
101 sprintf(line, "%*s", indent * NTOBUF_INDENT, "");
102 wrbuf_write(b, line, strlen(line));
103 col = indent * NTOBUF_INDENT;
113 wrbuf_write(b, "\n", 1);
116 else if (c->u.data.what == DATA1I_num)
119 wrbuf_write(b, c->u.data.data, c->u.data.len);
126 char *data1_nodetoidsgml (data1_handle dh, data1_node *n, int select, int *len)
128 WRBUF b = data1_get_wrbuf (dh);
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));