2 * Copyright (c) 1995-1997, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.4 1997-09-17 12:10:38 adam
10 * Revision 1.3 1995/12/15 16:57:11 quinn
11 * Added formatted-text.
13 * Revision 1.2 1995/11/01 13:54:49 quinn
16 * Revision 1.1 1995/11/01 11:56:09 quinn
17 * Added Retrieval (data management) functions en masse.
26 #define NTOBUF_INDENT 2
27 #define NTOBUF_MARGIN 75
29 static int wordlen(char *b)
33 while (*b && !isspace(*b))
38 static int nodetobuf(data1_node *n, int select, WRBUF b, int indent, int col)
43 for (c = n->child; c; c = c->next)
47 if (c->which == DATA1N_tag)
49 if (select && !c->u.tag.node_selected)
51 if (c->u.tag.element && c->u.tag.element->tag)
52 tag = c->u.tag.element->tag->names->name; /* first name */
54 tag = c->u.tag.tag; /* local string tag */
55 if (data1_matchstr(tag, "wellknown")) /* skip wellknown */
59 sprintf(line, "%*s%s:", indent * NTOBUF_INDENT, "", tag);
60 wrbuf_write(b, line, strlen(line));
63 if (nodetobuf(c, select, b, indent+1, col) < 0)
66 else if (c->which == DATA1N_data)
68 char *p = c->u.data.data;
69 int l = c->u.data.len;
72 if (c->u.data.what == DATA1I_text && c->u.data.formatted_text)
75 wrbuf_write(b, c->u.data.data, c->u.data.len);
76 sprintf(line, "%*s", indent * NTOBUF_INDENT, "");
77 wrbuf_write(b, line, strlen(line));
78 col = indent * NTOBUF_INDENT;
80 else if (c->u.data.what == DATA1I_text)
86 while (l && isspace(*p))
90 /* break if we'll cross margin and word is not too long */
91 if (col + (wlen = wordlen(p)) > NTOBUF_MARGIN && wlen <
92 NTOBUF_MARGIN - indent * NTOBUF_INDENT)
94 sprintf(line, "\n%*s", indent * NTOBUF_INDENT, "");
95 wrbuf_write(b, line, strlen(line));
96 col = indent * NTOBUF_INDENT;
104 while (l && !isspace(*p))
106 if (col > NTOBUF_MARGIN)
110 sprintf(line, "%*s", indent * NTOBUF_INDENT, "");
111 wrbuf_write(b, line, strlen(line));
112 col = indent * NTOBUF_INDENT;
122 else if (c->u.data.what == DATA1I_num)
125 wrbuf_write(b, c->u.data.data, c->u.data.len);
133 * Return area containing SUTRS-formatted data. Ownership of this data
134 * remains in this module, and the buffer is reused on next call. This may
138 char *data1_nodetobuf (data1_handle dh, data1_node *n, int select, int *len)
140 WRBUF b = data1_get_wrbuf (dh);
143 if (nodetobuf(n, select, b, 0, 0))