IDZEBRA 2.2.8
d1_prtree.c
Go to the documentation of this file.
1/* This file is part of the Zebra server.
2 Copyright (C) Index Data
3
4Zebra is free software; you can redistribute it and/or modify it under
5the terms of the GNU General Public License as published by the Free
6Software Foundation; either version 2, or (at your option) any later
7version.
8
9Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10WARRANTY; without even the implied warranty of MERCHANTABILITY or
11FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
18*/
19
20#if HAVE_CONFIG_H
21#include <config.h>
22#endif
23#include <yaz/log.h>
24#include <idzebra/data1.h>
25
26static void pr_string (FILE *out, const char *str, int len)
27{
28 int i;
29 for (i = 0; i<len; i++)
30 {
31 int c = str[i];
32 if (c < 32 || c >126)
33 fprintf (out, "\\x%02x", c & 255);
34 else
35 fputc (c, out);
36 }
37}
38
39static void pr_tree (data1_handle dh, data1_node *n, FILE *out, int level)
40{
41 fprintf (out, "%*s", level, "");
42 switch (n->which)
43 {
44 case DATA1N_root:
45 fprintf (out, "root abstract syntax=%s\n", n->u.root.type);
46 break;
47 case DATA1N_tag:
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)
51 {
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);
56 fprintf (out, "\n");
57 }
58 break;
59 case DATA1N_data:
60 case DATA1N_comment:
61 if (n->which == DATA1N_data)
62 fprintf (out, "data type=");
63 else
64 fprintf (out, "comment type=");
65 switch (n->u.data.what)
66 {
67 case DATA1I_inctxt:
68 fprintf (out, "inctxt\n");
69 break;
70 case DATA1I_incbin:
71 fprintf (out, "incbin\n");
72 break;
73 case DATA1I_text:
74 fprintf (out, "text '");
75 pr_string (out, n->u.data.data, n->u.data.len);
76 fprintf (out, "'\n");
77 break;
78 case DATA1I_num:
79 fprintf (out, "num '");
80 pr_string (out, n->u.data.data, n->u.data.len);
81 fprintf (out, "'\n");
82 break;
83 case DATA1I_oid:
84 fprintf (out, "oid '");
85 pr_string (out, n->u.data.data, n->u.data.len);
86 fprintf (out, "'\n");
87 break;
88 case DATA1I_xmltext:
89 fprintf (out, "xml text '");
90 pr_string (out, n->u.data.data, n->u.data.len);
91 fprintf (out, "'\n");
92 break;
93 default:
94 fprintf (out, "unknown(%d)\n", n->u.data.what);
95 break;
96 }
97 break;
99 fprintf (out, "preprocess target=%s\n", n->u.preprocess.target);
100 if (n->u.preprocess.attributes)
101 {
103 fprintf (out, "%*s attr", level, "");
104 for (; xattr; xattr = xattr->next)
105 fprintf (out, " %s=%s ", xattr->name, xattr->value);
106 fprintf (out, "\n");
107 }
108 break;
109 case DATA1N_variant:
110 fprintf (out, "variant\n");
111#if 0
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,
115 n->u.variant.value);
116#endif
117 break;
118 default:
119 fprintf (out, "unknown(%d)\n", n->which);
120 }
121 if (n->child)
122 pr_tree (dh, n->child, out, level+4);
123 if (n->next)
124 pr_tree (dh, n->next, out, level);
125 else
126 {
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);
130 }
131}
132
133
134void data1_pr_tree (data1_handle dh, data1_node *n, FILE *out)
135{
136 pr_tree (dh, n, out, 0);
137}
138/*
139 * Local variables:
140 * c-basic-offset: 4
141 * c-file-style: "Stroustrup"
142 * indent-tabs-mode: nil
143 * End:
144 * vim: shiftwidth=4 tabstop=8 expandtab
145 */
146
static void pr_string(FILE *out, const char *str, int len)
Definition d1_prtree.c:26
static void pr_tree(data1_handle dh, data1_node *n, FILE *out, int level)
Definition d1_prtree.c:39
void data1_pr_tree(data1_handle dh, data1_node *n, FILE *out)
Definition d1_prtree.c:134
#define DATA1N_variant
Definition data1.h:280
#define DATA1N_comment
Definition data1.h:282
#define DATA1I_inctxt
Definition data1.h:310
#define DATA1I_oid
Definition data1.h:318
#define DATA1N_tag
Definition data1.h:276
#define DATA1N_data
Definition data1.h:278
#define DATA1I_incbin
Definition data1.h:312
#define DATA1N_root
Definition data1.h:274
#define DATA1N_preprocess
Definition data1.h:284
#define DATA1I_num
Definition data1.h:316
#define DATA1I_text
Definition data1.h:314
#define DATA1I_xmltext
Definition data1.h:320
struct data1_node::@2::@7 preprocess
data1_xattr * attributes
Definition data1.h:302
struct data1_node::@2::@3 root
char * type
Definition data1.h:290
struct data1_node * parent
Definition data1.h:343
struct data1_node * child
Definition data1.h:341
char * tag
Definition data1.h:296
char * data
Definition data1.h:307
struct data1_node * next
Definition data1.h:340
char * target
Definition data1.h:333
struct data1_node * last_child
Definition data1.h:342
union data1_node::@2 u
int which
Definition data1.h:285
struct data1_node::@2::@6 variant
char * value
Definition data1.h:328
char * value
Definition data1.h:261
char * name
Definition data1.h:260
struct data1_xattr * next
Definition data1.h:262