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