2 * Copyright (c) 1995-1997, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.5 1999-10-21 12:06:29 adam
8 * Retrieval module no longer uses ctype.h - functions.
10 * Revision 1.4 1997/09/17 12:10:38 adam
13 * Revision 1.3 1995/12/15 16:57:11 quinn
14 * Added formatted-text.
16 * Revision 1.2 1995/11/01 13:54:49 quinn
19 * Revision 1.1 1995/11/01 11:56:09 quinn
20 * Added Retrieval (data management) functions en masse.
27 #define NTOBUF_INDENT 2
28 #define NTOBUF_MARGIN 75
30 static int wordlen(char *b)
34 while (*b && !d1_isspace(*b))
39 static int nodetobuf(data1_node *n, int select, WRBUF b, int indent, int col)
44 for (c = n->child; c; c = c->next)
48 if (c->which == DATA1N_tag)
50 if (select && !c->u.tag.node_selected)
52 if (c->u.tag.element && c->u.tag.element->tag)
53 tag = c->u.tag.element->tag->names->name; /* first name */
55 tag = c->u.tag.tag; /* local string tag */
56 if (data1_matchstr(tag, "wellknown")) /* skip wellknown */
60 sprintf(line, "%*s%s:", indent * NTOBUF_INDENT, "", tag);
61 wrbuf_write(b, line, strlen(line));
64 if (nodetobuf(c, select, b, indent+1, col) < 0)
67 else if (c->which == DATA1N_data)
69 char *p = c->u.data.data;
70 int l = c->u.data.len;
73 if (c->u.data.what == DATA1I_text && c->u.data.formatted_text)
76 wrbuf_write(b, c->u.data.data, c->u.data.len);
77 sprintf(line, "%*s", indent * NTOBUF_INDENT, "");
78 wrbuf_write(b, line, strlen(line));
79 col = indent * NTOBUF_INDENT;
81 else if (c->u.data.what == DATA1I_text)
87 while (l && d1_isspace(*p))
91 /* break if we'll cross margin and word is not too long */
92 if (col + (wlen = wordlen(p)) > NTOBUF_MARGIN && wlen <
93 NTOBUF_MARGIN - indent * NTOBUF_INDENT)
95 sprintf(line, "\n%*s", indent * NTOBUF_INDENT, "");
96 wrbuf_write(b, line, strlen(line));
97 col = indent * NTOBUF_INDENT;
105 while (l && !d1_isspace(*p))
107 if (col > NTOBUF_MARGIN)
111 sprintf(line, "%*s", indent * NTOBUF_INDENT, "");
112 wrbuf_write(b, line, strlen(line));
113 col = indent * NTOBUF_INDENT;
123 else if (c->u.data.what == DATA1I_num)
126 wrbuf_write(b, c->u.data.data, c->u.data.len);
134 * Return area containing SUTRS-formatted data. Ownership of this data
135 * remains in this module, and the buffer is reused on next call. This may
139 char *data1_nodetobuf (data1_handle dh, data1_node *n, int select, int *len)
141 WRBUF b = data1_get_wrbuf (dh);
144 if (nodetobuf(n, select, b, 0, 0))