Made data1_pr_tree make better printing of data1 buffers.
[yaz-moved-to-github.git] / retrieval / d1_prtree.c
1 /*
2  * Copyright (c) 1995-1999, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: d1_prtree.c,v $
7  * Revision 1.5  1999-01-25 13:49:47  adam
8  * Made data1_pr_tree make better printing of data1 buffers.
9  *
10  * Revision 1.4  1998/05/18 13:07:06  adam
11  * Changed the way attribute sets are handled by the retriaval module.
12  * Extended Explain conversion / schema.
13  * Modified server and client to work with ASN.1 compiled protocol handlers.
14  *
15  * Revision 1.3  1998/02/27 14:05:34  adam
16  * Added printing of integer nodes.
17  *
18  * Revision 1.2  1997/11/06 11:36:44  adam
19  * Implemented variant match on simple elements -data1 tree and Espec-1.
20  *
21  * Revision 1.1  1997/10/27 14:04:07  adam
22  * New debug utility, data1_pr_tree, that dumps a data1 tree.
23  *
24  */
25
26 #include <log.h>
27 #include <data1.h>
28
29 static void pr_string (FILE *out, const char *str, int len)
30 {
31     int i;
32     for (i = 0; i<len; i++)
33     {
34         int c = str[i];
35         if (c < 32 || c >126)
36             fprintf (out, "\\x%02x", c);
37         else
38             fputc (c, out);
39     }
40 }
41
42 static void pr_tree (data1_handle dh, data1_node *n, FILE *out, int level)
43 {
44     fprintf (out, "%*s", level, "");
45     switch (n->which)
46     {
47      case DATA1N_root:
48          fprintf (out, "root abstract syntax=%s\n", n->u.root.type);
49          break;
50     case DATA1N_tag:
51         fprintf (out, "tag type=%s\n", n->u.tag.tag);
52         break;
53     case DATA1N_data:
54         fprintf (out, "data type=");
55         switch (n->u.data.what)
56         {
57         case DATA1I_inctxt:
58             fprintf (out, "inctxt\n");
59             break;
60         case DATA1I_incbin:
61             fprintf (out, "incbin\n");
62             break;
63         case DATA1I_text:
64             fprintf (out, "text '");
65             pr_string (out, n->u.data.data, n->u.data.len);
66             fprintf (out, "'\n");
67             break;
68         case DATA1I_num:
69             fprintf (out, "num '");
70             pr_string (out, n->u.data.data, n->u.data.len);
71             fprintf (out, "'\n");
72             break;
73         case DATA1I_oid:
74             fprintf (out, "oid '");
75             pr_string (out, n->u.data.data, n->u.data.len);
76             fprintf (out, "'\n");
77             break;
78         default:
79             fprintf (out, "unknown(%d)\n", n->u.data.what);
80             break;
81         }
82         break;
83     case DATA1N_variant:
84         fprintf (out, "variant\n");
85 #if 0
86         if (n->u.variant.type->name)
87             fprintf (out, " class=%s type=%d value=%s\n",
88                      n->u.variant.type->name, n->u.variant.type->type,
89                      n->u.variant.value);
90 #endif
91         break;
92     default:
93         fprintf (out, "unknown(%d)\n", n->which);
94     }
95     if (n->child)
96         pr_tree (dh, n->child, out, level+4);
97     if (n->next)
98         pr_tree (dh, n->next, out, level);
99 }
100
101
102 void data1_pr_tree (data1_handle dh, data1_node *n, FILE *out)
103 {
104     pr_tree (dh, n, out, 0);
105 }