2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1995-11-01 13:54:49 quinn
10 * Revision 1.1 1995/11/01 11:56:09 quinn
11 * Added Retrieval (data management) functions en masse.
22 #define NTOBUF_INDENT 2
23 #define NTOBUF_MARGIN 75
25 static int wordlen(char *b)
29 while (*b && !isspace(*b))
34 static int nodetobuf(data1_node *n, int select, WRBUF b, int indent, int col)
39 for (c = n->child; c; c = c->next)
43 if (c->which == DATA1N_tag)
45 if (select && !c->u.tag.node_selected)
47 if (c->u.tag.element && c->u.tag.element->tag)
48 tag = c->u.tag.element->tag->names->name; /* first name */
50 tag = c->u.tag.tag; /* local string tag */
51 if (data1_matchstr(tag, "wellknown")) /* skip wellknown */
55 sprintf(line, "%*s%s:", indent * NTOBUF_INDENT, "", tag);
56 wrbuf_write(b, line, strlen(line));
59 if (nodetobuf(c, select, b, indent+1, col) < 0)
62 else if (c->which == DATA1N_data)
64 char *p = c->u.data.data;
65 int l = c->u.data.len;
68 if (c->u.data.what == DATA1I_text)
74 while (l && isspace(*p))
78 /* break if we'll cross margin and word is not too long */
79 if (col + (wlen = wordlen(p)) > NTOBUF_MARGIN && wlen <
80 NTOBUF_MARGIN - indent * NTOBUF_INDENT)
82 sprintf(line, "\n%*s", indent * NTOBUF_INDENT, "");
83 wrbuf_write(b, line, strlen(line));
84 col = indent * NTOBUF_INDENT;
92 while (l && !isspace(*p))
94 if (col > NTOBUF_MARGIN)
98 sprintf(line, "%*s", indent * NTOBUF_INDENT, "");
99 wrbuf_write(b, line, strlen(line));
100 col = indent * NTOBUF_INDENT;
110 else if (c->u.data.what == DATA1I_num)
113 wrbuf_write(b, c->u.data.data, c->u.data.len);
121 * Return area containing SUTRS-formatted data. Ownership of this data
122 * remains in this module, and the buffer is reused on next call. This may
126 char *data1_nodetobuf(data1_node *n, int select, int *len)
134 if (nodetobuf(n, select, b, 0, 0))