2 * Copyright (c) 1995-1999, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.9 2000-11-29 14:22:47 adam
8 * Implemented XML/SGML attributes for data1 so that d1_read reads them
9 * and d1_write generates proper attributes for XML/SGML records. Added
10 * register locking for threaded version.
12 * Revision 1.8 1999/11/30 13:47:12 adam
13 * Improved installation. Moved header files to include/yaz.
15 * Revision 1.7 1999/10/21 12:06:29 adam
16 * Retrieval module no longer uses ctype.h - functions.
18 * Revision 1.6 1999/07/06 12:16:00 adam
19 * Improved layout generated record in SGML/XML format.
21 * Revision 1.5 1998/06/05 08:57:43 adam
22 * Fixed problem with function wordlen.
24 * Revision 1.4 1998/05/18 13:07:08 adam
25 * Changed the way attribute sets are handled by the retriaval module.
26 * Extended Explain conversion / schema.
27 * Modified server and client to work with ASN.1 compiled protocol handlers.
29 * Revision 1.3 1997/09/17 12:10:39 adam
32 * Revision 1.2 1995/12/13 17:14:27 quinn
33 * *** empty log message ***
35 * Revision 1.1 1995/12/13 15:38:43 quinn
36 * Added SGML-output filter.
43 #include <yaz/data1.h>
44 #include <yaz/wrbuf.h>
46 #define IDSGML_MARGIN 75
48 static int wordlen(char *b, int max)
52 while (l < max && !d1_isspace(*b))
57 static int nodetoidsgml(data1_node *n, int select, WRBUF b, int col)
62 for (c = n->child; c; c = c->next)
66 if (c->which == DATA1N_tag)
68 if (select && c->u.tag.node_selected)
70 if (c->u.tag.element && c->u.tag.element->tag)
71 tag = c->u.tag.element->tag->names->name; /* first name */
73 tag = c->u.tag.tag; /* local string tag */
74 if (!data1_matchstr(tag, "wellknown")) /* skip wellknown */
76 if (nodetoidsgml(c, select, b, col) < 0)
84 sprintf (line, "%*s<", col, "");
88 for (p = c->u.tag.attributes; p; p = p->next)
91 wrbuf_puts (b, p->name);
94 wrbuf_puts (b, p->value);
99 if (nodetoidsgml(c, select, b, (col > 40) ? 40 : col+2) < 0)
101 sprintf (line, "%*s</%s>\n", col, "", tag);
102 wrbuf_write(b, line, strlen(line));
105 else if (c->which == DATA1N_data)
107 char *p = c->u.data.data;
108 int l = c->u.data.len;
112 sprintf(line, "%*s", col, "");
113 wrbuf_write(b, line, strlen(line));
114 switch (c->u.data.what)
121 while (l && d1_isspace(*p))
125 /* break if we'll cross margin and word is not too long */
126 if (lcol + (wlen = wordlen(p, l)) > IDSGML_MARGIN && wlen <
129 sprintf(line, "\n%*s", col, "");
131 wrbuf_write(b, line, strlen(line));
139 while (l && !d1_isspace(*p))
148 wrbuf_write(b, "\n", 1);
151 wrbuf_write(b, c->u.data.data, c->u.data.len);
154 wrbuf_write(b, c->u.data.data, c->u.data.len);
161 char *data1_nodetoidsgml (data1_handle dh, data1_node *n, int select, int *len)
163 WRBUF b = data1_get_wrbuf (dh);
168 sprintf(line, "<%s>\n", n->u.root.type);
169 wrbuf_write(b, line, strlen(line));
170 if (nodetoidsgml(n, select, b, 0))
172 sprintf(line, "</%s>\n", n->u.root.type);
173 wrbuf_write(b, line, strlen(line));