Added skeleton for query charset conversion. Bug #977.
[yaz-moved-to-github.git] / src / grs1disp.c
1 /*
2  * Copyright (C) 1995-2007, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: grs1disp.c,v 1.6 2007-03-12 16:16:49 adam Exp $
6  */
7
8 /**
9  * \file grs1disp.c
10  * \brief Implements display of GRS-1 records
11  */
12
13 #include <stdio.h>
14 #include <string.h>
15 #include <stdlib.h>
16 #include <ctype.h>
17
18 #include <yaz/proto.h>
19
20 static void display_variant(WRBUF w, Z_Variant *v, int level)
21 {
22     int i;
23
24     for (i = 0; i < v->num_triples; i++)
25     {
26         printf("%*sclass=%d,type=%d", level * 4, "", *v->triples[i]->zclass,
27             *v->triples[i]->type);
28         if (v->triples[i]->which == Z_Triple_internationalString)
29             printf(",value=%s\n", v->triples[i]->value.internationalString);
30         else
31             printf("\n");
32     }
33 }
34
35 static void display_grs1(WRBUF w, Z_GenericRecord *r, int level)
36 {
37     int i;
38
39     if (!r)
40     {
41         return;
42     }
43     for (i = 0; i < r->num_elements; i++)
44     {
45         Z_TaggedElement *t;
46
47         wrbuf_printf(w, "%*s", level * 4, "");
48         t = r->elements[i];
49         wrbuf_printf(w, "(");
50         if (t->tagType)
51             wrbuf_printf(w, "%d,", *t->tagType);
52         else
53             wrbuf_printf(w, "?,");
54         if (t->tagValue->which == Z_StringOrNumeric_numeric)
55             wrbuf_printf(w, "%d) ", *t->tagValue->u.numeric);
56         else
57             wrbuf_printf(w, "%s) ", t->tagValue->u.string);
58         if (t->content->which == Z_ElementData_subtree)
59         {
60             if (!t->content->u.subtree)
61                 printf (" (no subtree)\n");
62             else
63             {
64                 wrbuf_printf(w, "\n");
65                 display_grs1(w, t->content->u.subtree, level+1);
66             }
67         }
68         else if (t->content->which == Z_ElementData_string)
69         {
70             wrbuf_puts(w, t->content->u.string);
71             wrbuf_puts(w, "\n");
72         }
73         else if (t->content->which == Z_ElementData_numeric)
74         {
75             wrbuf_printf(w, "%d\n", *t->content->u.numeric);
76         }
77         else if (t->content->which == Z_ElementData_oid)
78         {
79             int *ip = t->content->u.oid;
80             oident *oent;
81             
82             if ((oent = oid_getentbyoid(t->content->u.oid)))
83                 wrbuf_printf(w, "OID: %s\n", oent->desc);
84             else
85             {
86                 wrbuf_printf(w, "{");
87                 while (ip && *ip >= 0)
88                     wrbuf_printf(w, " %d", *(ip++));
89                 wrbuf_printf(w, " }\n");
90             }
91         }
92         else if (t->content->which == Z_ElementData_noDataRequested)
93             wrbuf_printf(w, "[No data requested]\n");
94         else if (t->content->which == Z_ElementData_elementEmpty)
95             wrbuf_printf(w, "[Element empty]\n");
96         else if (t->content->which == Z_ElementData_elementNotThere)
97             wrbuf_printf(w, "[Element not there]\n");
98         else if (t->content->which == Z_ElementData_date)
99             wrbuf_printf(w, "Date: %s\n", t->content->u.date);
100         else if (t->content->which == Z_ElementData_ext)
101         {
102             printf ("External\n");
103             /* we cannot print externals here. Srry */
104         } 
105         else
106             wrbuf_printf(w, "? type = %d\n",t->content->which);
107         if (t->appliedVariant)
108             display_variant(w, t->appliedVariant, level+1);
109         if (t->metaData && t->metaData->supportedVariants)
110         {
111             int c;
112
113             wrbuf_printf(w, "%*s---- variant list\n", (level+1)*4, "");
114             for (c = 0; c < t->metaData->num_supportedVariants; c++)
115             {
116                 wrbuf_printf(w, "%*svariant #%d\n", (level+1)*4, "", c);
117                 display_variant(w, t->metaData->supportedVariants[c], level+2);
118             }
119         }
120     }
121 }
122
123 void yaz_display_grs1(WRBUF wrbuf, Z_GenericRecord *r, int flags)
124 {
125     display_grs1 (wrbuf, r, 0);
126 }
127
128 /*
129  * Local variables:
130  * c-basic-offset: 4
131  * indent-tabs-mode: nil
132  * End:
133  * vim: shiftwidth=4 tabstop=8 expandtab
134  */
135