2 * Copyright (c) 1995-1999, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.6 1999-07-06 12:16:00 adam
8 * Improved layout generated record in SGML/XML format.
10 * Revision 1.5 1998/06/05 08:57:43 adam
11 * Fixed problem with function wordlen.
13 * Revision 1.4 1998/05/18 13:07:08 adam
14 * Changed the way attribute sets are handled by the retriaval module.
15 * Extended Explain conversion / schema.
16 * Modified server and client to work with ASN.1 compiled protocol handlers.
18 * Revision 1.3 1997/09/17 12:10:39 adam
21 * Revision 1.2 1995/12/13 17:14:27 quinn
22 * *** empty log message ***
24 * Revision 1.1 1995/12/13 15:38:43 quinn
25 * Added SGML-output filter.
36 #define IDSGML_MARGIN 75
38 static int wordlen(char *b, int max)
42 while (l < max && !isspace(*b))
47 static int nodetoidsgml(data1_node *n, int select, WRBUF b, int col)
52 for (c = n->child; c; c = c->next)
56 if (c->which == DATA1N_tag)
58 if (select && c->u.tag.node_selected)
60 if (c->u.tag.element && c->u.tag.element->tag)
61 tag = c->u.tag.element->tag->names->name; /* first name */
63 tag = c->u.tag.tag; /* local string tag */
64 if (!data1_matchstr(tag, "wellknown")) /* skip wellknown */
66 if (nodetoidsgml(c, select, b, col) < 0)
71 sprintf(line, "%*s<%s>\n", col, "", tag);
72 wrbuf_write(b, line, strlen(line));
73 if (nodetoidsgml(c, select, b, (col > 40) ? 40 : col+2) < 0)
75 sprintf (line, "%*s</%s>\n", col, "", tag);
76 wrbuf_write(b, line, strlen(line));
79 else if (c->which == DATA1N_data)
81 char *p = c->u.data.data;
82 int l = c->u.data.len;
86 sprintf(line, "%*s", col, "");
87 wrbuf_write(b, line, strlen(line));
88 switch (c->u.data.what)
95 while (l && isspace(*p))
99 /* break if we'll cross margin and word is not too long */
100 if (lcol + (wlen = wordlen(p, l)) > IDSGML_MARGIN && wlen <
103 sprintf(line, "\n%*s", col, "");
105 wrbuf_write(b, line, strlen(line));
113 while (l && !isspace(*p))
122 wrbuf_write(b, "\n", 1);
125 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));