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