2 * Copyright (c) 1995-1997, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.4 1998-05-18 13:07:08 adam
8 * Changed the way attribute sets are handled by the retriaval module.
9 * Extended Explain conversion / schema.
10 * Modified server and client to work with ASN.1 compiled protocol handlers.
12 * Revision 1.3 1997/09/17 12:10:39 adam
15 * Revision 1.2 1995/12/13 17:14:27 quinn
16 * *** empty log message ***
18 * Revision 1.1 1995/12/13 15:38:43 quinn
19 * Added SGML-output filter.
30 #define IDSGML_MARGIN 75
32 static int wordlen(char *b)
36 while (*b && !isspace(*b))
41 static int nodetoidsgml(data1_node *n, int select, WRBUF b, int col)
46 for (c = n->child; c; c = c->next)
50 if (c->which == DATA1N_tag)
52 if (select && c->u.tag.node_selected)
54 if (c->u.tag.element && c->u.tag.element->tag)
55 tag = c->u.tag.element->tag->names->name; /* first name */
57 tag = c->u.tag.tag; /* local string tag */
58 if (data1_matchstr(tag, "wellknown")) /* skip wellknown */
60 sprintf(line, "<%s>\n", tag);
61 wrbuf_write(b, line, strlen(line));
64 if (nodetoidsgml(c, select, b, col) < 0)
66 wrbuf_write(b, "</>\n", 4);
69 else if (c->which == DATA1N_data)
71 char *p = c->u.data.data;
72 int l = c->u.data.len;
75 switch (c->u.data.what)
82 while (l && isspace(*p))
86 /* break if we'll cross margin and word is not too long */
87 if (col + (wlen = wordlen(p)) > IDSGML_MARGIN && wlen <
92 wrbuf_write(b, line, strlen(line));
100 while (l && !isspace(*p))
103 if (col > NTOBUF_MARGIN)
107 sprintf(line, "%*s", indent * NTOBUF_INDENT, "");
108 wrbuf_write(b, line, strlen(line));
109 col = indent * NTOBUF_INDENT;
119 wrbuf_write(b, "\n", 1);
124 wrbuf_write(b, c->u.data.data, c->u.data.len);
128 wrbuf_write(b, c->u.data.data, c->u.data.len);
135 char *data1_nodetoidsgml (data1_handle dh, data1_node *n, int select, int *len)
137 WRBUF b = data1_get_wrbuf (dh);
142 sprintf(line, "<%s>\n", n->u.root.type);
143 wrbuf_write(b, line, strlen(line));
144 if (nodetoidsgml(n, select, b, 0))
146 sprintf(line, "</%s>\n", n->u.root.type);
147 wrbuf_write(b, line, strlen(line));