1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2010 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <idzebra/data1.h>
23 static void pr_string (FILE *out, const char *str, int len)
26 for (i = 0; i<len; i++)
30 fprintf (out, "\\x%02x", c & 255);
36 static void pr_tree (data1_handle dh, data1_node *n, FILE *out, int level)
38 fprintf (out, "%*s", level, "");
42 fprintf (out, "root abstract syntax=%s\n", n->u.root.type);
45 fprintf (out, "tag type=%s sel=%d\n", n->u.tag.tag,
46 n->u.tag.node_selected);
47 if (n->u.tag.attributes)
49 data1_xattr *xattr = n->u.tag.attributes;
50 fprintf (out, "%*s attr", level, "");
51 for (; xattr; xattr = xattr->next)
52 fprintf (out, " %s=%s ", xattr->name, xattr->value);
58 if (n->which == DATA1N_data)
59 fprintf (out, "data type=");
61 fprintf (out, "comment type=");
62 switch (n->u.data.what)
65 fprintf (out, "inctxt\n");
68 fprintf (out, "incbin\n");
71 fprintf (out, "text '");
72 pr_string (out, n->u.data.data, n->u.data.len);
76 fprintf (out, "num '");
77 pr_string (out, n->u.data.data, n->u.data.len);
81 fprintf (out, "oid '");
82 pr_string (out, n->u.data.data, n->u.data.len);
86 fprintf (out, "xml text '");
87 pr_string (out, n->u.data.data, n->u.data.len);
91 fprintf (out, "unknown(%d)\n", n->u.data.what);
95 case DATA1N_preprocess:
96 fprintf (out, "preprocess target=%s\n", n->u.preprocess.target);
97 if (n->u.preprocess.attributes)
99 data1_xattr *xattr = n->u.preprocess.attributes;
100 fprintf (out, "%*s attr", level, "");
101 for (; xattr; xattr = xattr->next)
102 fprintf (out, " %s=%s ", xattr->name, xattr->value);
107 fprintf (out, "variant\n");
109 if (n->u.variant.type->name)
110 fprintf (out, " class=%s type=%d value=%s\n",
111 n->u.variant.type->name, n->u.variant.type->type,
116 fprintf (out, "unknown(%d)\n", n->which);
119 pr_tree (dh, n->child, out, level+4);
121 pr_tree (dh, n->next, out, level);
124 if (n->parent && n->parent->last_child != n)
125 fprintf(out, "%*sWARNING: last_child=%p != %p\n", level, "",
126 n->parent->last_child, n);
131 void data1_pr_tree (data1_handle dh, data1_node *n, FILE *out)
133 pr_tree (dh, n, out, 0);
138 * c-file-style: "Stroustrup"
139 * indent-tabs-mode: nil
141 * vim: shiftwidth=4 tabstop=8 expandtab