1 /* $Id: d1_prtree.c,v 1.7 2005-01-15 19:38:18 adam Exp $
2 Copyright (C) 1995-2005
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include <idzebra/data1.h>
26 static void pr_string (FILE *out, const char *str, int len)
29 for (i = 0; i<len; i++)
33 fprintf (out, "\\x%02x", c & 255);
39 static void pr_tree (data1_handle dh, data1_node *n, FILE *out, int level)
41 fprintf (out, "%*s", level, "");
45 fprintf (out, "root abstract syntax=%s\n", n->u.root.type);
48 fprintf (out, "tag type=%s sel=%d\n", n->u.tag.tag,
49 n->u.tag.node_selected);
50 if (n->u.tag.attributes)
52 data1_xattr *xattr = n->u.tag.attributes;
53 fprintf (out, "%*s attr", level, "");
54 for (; xattr; xattr = xattr->next)
55 fprintf (out, " %s=%s ", xattr->name, xattr->value);
61 if (n->which == DATA1N_data)
62 fprintf (out, "data type=");
64 fprintf (out, "comment type=");
65 switch (n->u.data.what)
68 fprintf (out, "inctxt\n");
71 fprintf (out, "incbin\n");
74 fprintf (out, "text '");
75 pr_string (out, n->u.data.data, n->u.data.len);
79 fprintf (out, "num '");
80 pr_string (out, n->u.data.data, n->u.data.len);
84 fprintf (out, "oid '");
85 pr_string (out, n->u.data.data, n->u.data.len);
89 fprintf (out, "xml text '");
90 pr_string (out, n->u.data.data, n->u.data.len);
94 fprintf (out, "unknown(%d)\n", n->u.data.what);
98 case DATA1N_preprocess:
99 fprintf (out, "preprocess target=%s\n", n->u.preprocess.target);
100 if (n->u.preprocess.attributes)
102 data1_xattr *xattr = n->u.preprocess.attributes;
103 fprintf (out, "%*s attr", level, "");
104 for (; xattr; xattr = xattr->next)
105 fprintf (out, " %s=%s ", xattr->name, xattr->value);
110 fprintf (out, "variant\n");
112 if (n->u.variant.type->name)
113 fprintf (out, " class=%s type=%d value=%s\n",
114 n->u.variant.type->name, n->u.variant.type->type,
119 fprintf (out, "unknown(%d)\n", n->which);
122 pr_tree (dh, n->child, out, level+4);
124 pr_tree (dh, n->next, out, level);
127 if (n->parent && n->parent->last_child != n)
128 fprintf(out, "%*sWARNING: last_child=%p != %p\n", level, "",
129 n->parent->last_child, n);
134 void data1_pr_tree (data1_handle dh, data1_node *n, FILE *out)
136 pr_tree (dh, n, out, 0);