2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.3 1995-12-15 16:57:11 quinn
8 * Added formatted-text.
10 * Revision 1.2 1995/11/01 13:54:49 quinn
13 * Revision 1.1 1995/11/01 11:56:09 quinn
14 * Added Retrieval (data management) functions en masse.
25 #define NTOBUF_INDENT 2
26 #define NTOBUF_MARGIN 75
28 static int wordlen(char *b)
32 while (*b && !isspace(*b))
37 static int nodetobuf(data1_node *n, int select, WRBUF b, int indent, int col)
42 for (c = n->child; c; c = c->next)
46 if (c->which == DATA1N_tag)
48 if (select && !c->u.tag.node_selected)
50 if (c->u.tag.element && c->u.tag.element->tag)
51 tag = c->u.tag.element->tag->names->name; /* first name */
53 tag = c->u.tag.tag; /* local string tag */
54 if (data1_matchstr(tag, "wellknown")) /* skip wellknown */
58 sprintf(line, "%*s%s:", indent * NTOBUF_INDENT, "", tag);
59 wrbuf_write(b, line, strlen(line));
62 if (nodetobuf(c, select, b, indent+1, col) < 0)
65 else if (c->which == DATA1N_data)
67 char *p = c->u.data.data;
68 int l = c->u.data.len;
71 if (c->u.data.what == DATA1I_text && c->u.data.formatted_text)
74 wrbuf_write(b, c->u.data.data, c->u.data.len);
75 sprintf(line, "%*s", indent * NTOBUF_INDENT, "");
76 wrbuf_write(b, line, strlen(line));
77 col = indent * NTOBUF_INDENT;
79 else if (c->u.data.what == DATA1I_text)
85 while (l && isspace(*p))
89 /* break if we'll cross margin and word is not too long */
90 if (col + (wlen = wordlen(p)) > NTOBUF_MARGIN && wlen <
91 NTOBUF_MARGIN - indent * NTOBUF_INDENT)
93 sprintf(line, "\n%*s", indent * NTOBUF_INDENT, "");
94 wrbuf_write(b, line, strlen(line));
95 col = indent * NTOBUF_INDENT;
103 while (l && !isspace(*p))
105 if (col > NTOBUF_MARGIN)
109 sprintf(line, "%*s", indent * NTOBUF_INDENT, "");
110 wrbuf_write(b, line, strlen(line));
111 col = indent * NTOBUF_INDENT;
121 else if (c->u.data.what == DATA1I_num)
124 wrbuf_write(b, c->u.data.data, c->u.data.len);
132 * Return area containing SUTRS-formatted data. Ownership of this data
133 * remains in this module, and the buffer is reused on next call. This may
137 char *data1_nodetobuf(data1_node *n, int select, int *len)
145 if (nodetobuf(n, select, b, 0, 0))