2 * Copyright (c) 1995-1999, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.7 1999-10-21 12:06:29 adam
8 * Retrieval module no longer uses ctype.h - functions.
10 * Revision 1.6 1999/07/06 12:16:00 adam
11 * Improved layout generated record in SGML/XML format.
13 * Revision 1.5 1998/06/05 08:57:43 adam
14 * Fixed problem with function wordlen.
16 * Revision 1.4 1998/05/18 13:07:08 adam
17 * Changed the way attribute sets are handled by the retriaval module.
18 * Extended Explain conversion / schema.
19 * Modified server and client to work with ASN.1 compiled protocol handlers.
21 * Revision 1.3 1997/09/17 12:10:39 adam
24 * Revision 1.2 1995/12/13 17:14:27 quinn
25 * *** empty log message ***
27 * Revision 1.1 1995/12/13 15:38:43 quinn
28 * Added SGML-output filter.
38 #define IDSGML_MARGIN 75
40 static int wordlen(char *b, int max)
44 while (l < max && !d1_isspace(*b))
49 static int nodetoidsgml(data1_node *n, int select, WRBUF b, int col)
54 for (c = n->child; c; c = c->next)
58 if (c->which == DATA1N_tag)
60 if (select && c->u.tag.node_selected)
62 if (c->u.tag.element && c->u.tag.element->tag)
63 tag = c->u.tag.element->tag->names->name; /* first name */
65 tag = c->u.tag.tag; /* local string tag */
66 if (!data1_matchstr(tag, "wellknown")) /* skip wellknown */
68 if (nodetoidsgml(c, select, b, col) < 0)
73 sprintf(line, "%*s<%s>\n", col, "", tag);
74 wrbuf_write(b, line, strlen(line));
75 if (nodetoidsgml(c, select, b, (col > 40) ? 40 : col+2) < 0)
77 sprintf (line, "%*s</%s>\n", col, "", tag);
78 wrbuf_write(b, line, strlen(line));
81 else if (c->which == DATA1N_data)
83 char *p = c->u.data.data;
84 int l = c->u.data.len;
88 sprintf(line, "%*s", col, "");
89 wrbuf_write(b, line, strlen(line));
90 switch (c->u.data.what)
97 while (l && d1_isspace(*p))
101 /* break if we'll cross margin and word is not too long */
102 if (lcol + (wlen = wordlen(p, l)) > IDSGML_MARGIN && wlen <
105 sprintf(line, "\n%*s", col, "");
107 wrbuf_write(b, line, strlen(line));
115 while (l && !d1_isspace(*p))
124 wrbuf_write(b, "\n", 1);
127 wrbuf_write(b, c->u.data.data, c->u.data.len);
130 wrbuf_write(b, c->u.data.data, c->u.data.len);
137 char *data1_nodetoidsgml (data1_handle dh, data1_node *n, int select, int *len)
139 WRBUF b = data1_get_wrbuf (dh);
144 sprintf(line, "<%s>\n", n->u.root.type);
145 wrbuf_write(b, line, strlen(line));
146 if (nodetoidsgml(n, select, b, 0))
148 sprintf(line, "</%s>\n", n->u.root.type);
149 wrbuf_write(b, line, strlen(line));