For OIDs use Odr_oid type everywhere, i.e. do not assume Odr_oid=int.
[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.8 2007-05-08 08:22:36 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 #include <yaz/oid_db.h>
20
21 static void display_variant(WRBUF w, Z_Variant *v, int level)
22 {
23     int i;
24
25     for (i = 0; i < v->num_triples; i++)
26     {
27         printf("%*sclass=%d,type=%d", level * 4, "", *v->triples[i]->zclass,
28             *v->triples[i]->type);
29         if (v->triples[i]->which == Z_Triple_internationalString)
30             printf(",value=%s\n", v->triples[i]->value.internationalString);
31         else
32             printf("\n");
33     }
34 }
35
36 static void display_grs1(WRBUF w, Z_GenericRecord *r, int level)
37 {
38     int i;
39
40     if (!r)
41     {
42         return;
43     }
44     for (i = 0; i < r->num_elements; i++)
45     {
46         Z_TaggedElement *t;
47
48         wrbuf_printf(w, "%*s", level * 4, "");
49         t = r->elements[i];
50         wrbuf_printf(w, "(");
51         if (t->tagType)
52             wrbuf_printf(w, "%d,", *t->tagType);
53         else
54             wrbuf_printf(w, "?,");
55         if (t->tagValue->which == Z_StringOrNumeric_numeric)
56             wrbuf_printf(w, "%d) ", *t->tagValue->u.numeric);
57         else
58             wrbuf_printf(w, "%s) ", t->tagValue->u.string);
59         if (t->content->which == Z_ElementData_subtree)
60         {
61             if (!t->content->u.subtree)
62                 printf (" (no subtree)\n");
63             else
64             {
65                 wrbuf_printf(w, "\n");
66                 display_grs1(w, t->content->u.subtree, level+1);
67             }
68         }
69         else if (t->content->which == Z_ElementData_string)
70         {
71             wrbuf_puts(w, t->content->u.string);
72             wrbuf_puts(w, "\n");
73         }
74         else if (t->content->which == Z_ElementData_numeric)
75         {
76             wrbuf_printf(w, "%d\n", *t->content->u.numeric);
77         }
78         else if (t->content->which == Z_ElementData_oid)
79         {
80             Odr_oid *ip = t->content->u.oid;
81
82             if (ip)
83             {
84                 char oid_name_str[OID_STR_MAX];
85                 oid_class oclass;
86                 const char *oid_name 
87                     = yaz_oid_to_string_buf(ip, &oclass, oid_name_str);
88             
89                 if (oid_name)
90                     wrbuf_printf(w, "OID: %s\n", oid_name);
91             }
92         }
93         else if (t->content->which == Z_ElementData_noDataRequested)
94             wrbuf_printf(w, "[No data requested]\n");
95         else if (t->content->which == Z_ElementData_elementEmpty)
96             wrbuf_printf(w, "[Element empty]\n");
97         else if (t->content->which == Z_ElementData_elementNotThere)
98             wrbuf_printf(w, "[Element not there]\n");
99         else if (t->content->which == Z_ElementData_date)
100             wrbuf_printf(w, "Date: %s\n", t->content->u.date);
101         else if (t->content->which == Z_ElementData_ext)
102         {
103             printf ("External\n");
104             /* we cannot print externals here. Srry */
105         } 
106         else
107             wrbuf_printf(w, "? type = %d\n",t->content->which);
108         if (t->appliedVariant)
109             display_variant(w, t->appliedVariant, level+1);
110         if (t->metaData && t->metaData->supportedVariants)
111         {
112             int c;
113
114             wrbuf_printf(w, "%*s---- variant list\n", (level+1)*4, "");
115             for (c = 0; c < t->metaData->num_supportedVariants; c++)
116             {
117                 wrbuf_printf(w, "%*svariant #%d\n", (level+1)*4, "", c);
118                 display_variant(w, t->metaData->supportedVariants[c], level+2);
119             }
120         }
121     }
122 }
123
124 void yaz_display_grs1(WRBUF wrbuf, Z_GenericRecord *r, int flags)
125 {
126     display_grs1 (wrbuf, r, 0);
127 }
128
129 /*
130  * Local variables:
131  * c-basic-offset: 4
132  * indent-tabs-mode: nil
133  * End:
134  * vim: shiftwidth=4 tabstop=8 expandtab
135  */
136