2 * Copyright (c) 1995-2002, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Id: d1_prtree.c,v 1.10 2002-09-24 13:58:13 adam Exp $
10 #include <yaz/data1.h>
12 static void pr_string (FILE *out, const char *str, int len)
15 for (i = 0; i<len; i++)
19 fprintf (out, "\\x%02x", c & 255);
25 static void pr_tree (data1_handle dh, data1_node *n, FILE *out, int level)
27 fprintf (out, "%*s", level, "");
31 fprintf (out, "root abstract syntax=%s\n", n->u.root.type);
34 fprintf (out, "tag type=%s sel=%d\n", n->u.tag.tag,
35 n->u.tag.node_selected);
36 if (n->u.tag.attributes)
38 data1_xattr *xattr = n->u.tag.attributes;
39 fprintf (out, "%*s attr", level, "");
40 for (; xattr; xattr = xattr->next)
41 fprintf (out, " %s=%s ", xattr->name, xattr->value);
47 if (n->which == DATA1N_data)
48 fprintf (out, "data type=");
50 fprintf (out, "comment type=");
51 switch (n->u.data.what)
54 fprintf (out, "inctxt\n");
57 fprintf (out, "incbin\n");
60 fprintf (out, "text '");
61 pr_string (out, n->u.data.data, n->u.data.len);
65 fprintf (out, "num '");
66 pr_string (out, n->u.data.data, n->u.data.len);
70 fprintf (out, "oid '");
71 pr_string (out, n->u.data.data, n->u.data.len);
75 fprintf (out, "unknown(%d)\n", n->u.data.what);
79 case DATA1N_preprocess:
80 fprintf (out, "preprocess target=%s\n", n->u.preprocess.target);
81 if (n->u.preprocess.attributes)
83 data1_xattr *xattr = n->u.preprocess.attributes;
84 fprintf (out, "%*s attr", level, "");
85 for (; xattr; xattr = xattr->next)
86 fprintf (out, " %s=%s ", xattr->name, xattr->value);
91 fprintf (out, "variant\n");
93 if (n->u.variant.type->name)
94 fprintf (out, " class=%s type=%d value=%s\n",
95 n->u.variant.type->name, n->u.variant.type->type,
100 fprintf (out, "unknown(%d)\n", n->which);
103 pr_tree (dh, n->child, out, level+4);
105 pr_tree (dh, n->next, out, level);
109 void data1_pr_tree (data1_handle dh, data1_node *n, FILE *out)
111 pr_tree (dh, n, out, 0);