2 * Copyright (c) 1995-1997, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.6 1999-11-30 13:47:12 adam
8 * Improved installation. Moved header files to include/yaz.
10 * Revision 1.5 1999/10/21 12:06:29 adam
11 * Retrieval module no longer uses ctype.h - functions.
13 * Revision 1.4 1997/09/17 12:10:38 adam
16 * Revision 1.3 1995/12/15 16:57:11 quinn
17 * Added formatted-text.
19 * Revision 1.2 1995/11/01 13:54:49 quinn
22 * Revision 1.1 1995/11/01 11:56:09 quinn
23 * Added Retrieval (data management) functions en masse.
28 #include <yaz/data1.h>
30 #define NTOBUF_INDENT 2
31 #define NTOBUF_MARGIN 75
33 static int wordlen(char *b)
37 while (*b && !d1_isspace(*b))
42 static int nodetobuf(data1_node *n, int select, WRBUF b, int indent, int col)
47 for (c = n->child; c; c = c->next)
51 if (c->which == DATA1N_tag)
53 if (select && !c->u.tag.node_selected)
55 if (c->u.tag.element && c->u.tag.element->tag)
56 tag = c->u.tag.element->tag->names->name; /* first name */
58 tag = c->u.tag.tag; /* local string tag */
59 if (data1_matchstr(tag, "wellknown")) /* skip wellknown */
63 sprintf(line, "%*s%s:", indent * NTOBUF_INDENT, "", tag);
64 wrbuf_write(b, line, strlen(line));
67 if (nodetobuf(c, select, b, indent+1, col) < 0)
70 else if (c->which == DATA1N_data)
72 char *p = c->u.data.data;
73 int l = c->u.data.len;
76 if (c->u.data.what == DATA1I_text && c->u.data.formatted_text)
79 wrbuf_write(b, c->u.data.data, c->u.data.len);
80 sprintf(line, "%*s", indent * NTOBUF_INDENT, "");
81 wrbuf_write(b, line, strlen(line));
82 col = indent * NTOBUF_INDENT;
84 else if (c->u.data.what == DATA1I_text)
90 while (l && d1_isspace(*p))
94 /* break if we'll cross margin and word is not too long */
95 if (col + (wlen = wordlen(p)) > NTOBUF_MARGIN && wlen <
96 NTOBUF_MARGIN - indent * NTOBUF_INDENT)
98 sprintf(line, "\n%*s", indent * NTOBUF_INDENT, "");
99 wrbuf_write(b, line, strlen(line));
100 col = indent * NTOBUF_INDENT;
108 while (l && !d1_isspace(*p))
110 if (col > NTOBUF_MARGIN)
114 sprintf(line, "%*s", indent * NTOBUF_INDENT, "");
115 wrbuf_write(b, line, strlen(line));
116 col = indent * NTOBUF_INDENT;
126 else if (c->u.data.what == DATA1I_num)
129 wrbuf_write(b, c->u.data.data, c->u.data.len);
137 * Return area containing SUTRS-formatted data. Ownership of this data
138 * remains in this module, and the buffer is reused on next call. This may
142 char *data1_nodetobuf (data1_handle dh, data1_node *n, int select, int *len)
144 WRBUF b = data1_get_wrbuf (dh);
147 if (nodetobuf(n, select, b, 0, 0))