2 * Copyright (c) 1995-1998, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.5 1998-06-05 08:57:43 adam
8 * Fixed problem with function wordlen.
10 * Revision 1.4 1998/05/18 13:07:08 adam
11 * Changed the way attribute sets are handled by the retriaval module.
12 * Extended Explain conversion / schema.
13 * Modified server and client to work with ASN.1 compiled protocol handlers.
15 * Revision 1.3 1997/09/17 12:10:39 adam
18 * Revision 1.2 1995/12/13 17:14:27 quinn
19 * *** empty log message ***
21 * Revision 1.1 1995/12/13 15:38:43 quinn
22 * Added SGML-output filter.
33 #define IDSGML_MARGIN 75
35 static int wordlen(char *b, int max)
39 while (l < max && !isspace(*b))
44 static int nodetoidsgml(data1_node *n, int select, WRBUF b, int col)
49 for (c = n->child; c; c = c->next)
53 if (c->which == DATA1N_tag)
55 if (select && c->u.tag.node_selected)
57 if (c->u.tag.element && c->u.tag.element->tag)
58 tag = c->u.tag.element->tag->names->name; /* first name */
60 tag = c->u.tag.tag; /* local string tag */
61 if (data1_matchstr(tag, "wellknown")) /* skip wellknown */
63 sprintf(line, "<%s>\n", tag);
64 wrbuf_write(b, line, strlen(line));
67 if (nodetoidsgml(c, select, b, col) < 0)
69 wrbuf_write(b, "</>\n", 4);
72 else if (c->which == DATA1N_data)
74 char *p = c->u.data.data;
75 int l = c->u.data.len;
78 switch (c->u.data.what)
85 while (l && isspace(*p))
89 /* break if we'll cross margin and word is not too long */
90 if (col + (wlen = wordlen(p, l)) > IDSGML_MARGIN && wlen <
95 wrbuf_write(b, line, strlen(line));
103 while (l && !isspace(*p))
106 if (col > NTOBUF_MARGIN)
110 sprintf(line, "%*s", indent * NTOBUF_INDENT, "");
111 wrbuf_write(b, line, strlen(line));
112 col = indent * NTOBUF_INDENT;
122 wrbuf_write(b, "\n", 1);
127 wrbuf_write(b, c->u.data.data, c->u.data.len);
131 wrbuf_write(b, c->u.data.data, c->u.data.len);
138 char *data1_nodetoidsgml (data1_handle dh, data1_node *n, int select, int *len)
140 WRBUF b = data1_get_wrbuf (dh);
145 sprintf(line, "<%s>\n", n->u.root.type);
146 wrbuf_write(b, line, strlen(line));
147 if (nodetoidsgml(n, select, b, 0))
149 sprintf(line, "</%s>\n", n->u.root.type);
150 wrbuf_write(b, line, strlen(line));