Version 3.0.49. Update news.
[yaz-moved-to-github.git] / src / grs1disp.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2009 Index Data
3  * See the file LICENSE for details.
4  */
5
6 /**
7  * \file grs1disp.c
8  * \brief Implements display of GRS-1 records
9  */
10
11 #include <stdio.h>
12 #include <string.h>
13 #include <stdlib.h>
14 #include <ctype.h>
15
16 #include <yaz/proto.h>
17 #include <yaz/oid_db.h>
18
19 static void display_variant(WRBUF w, Z_Variant *v, int level)
20 {
21     int i;
22
23     for (i = 0; i < v->num_triples; i++)
24     {
25         printf("%*sclass=" ODR_INT_PRINTF ",type=" ODR_INT_PRINTF,
26                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, ODR_INT_PRINTF, *t->tagType);
52         else
53             wrbuf_printf(w, "?,");
54         if (t->tagValue->which == Z_StringOrNumeric_numeric)
55             wrbuf_printf(w, ODR_INT_PRINTF ") ", *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, ODR_INT_PRINTF "\n", *t->content->u.numeric);
76         }
77         else if (t->content->which == Z_ElementData_oid)
78         {
79             Odr_oid *ip = t->content->u.oid;
80
81             if (ip)
82             {
83                 char oid_name_str[OID_STR_MAX];
84                 oid_class oclass;
85                 const char *oid_name 
86                     = yaz_oid_to_string_buf(ip, &oclass, oid_name_str);
87             
88                 if (oid_name)
89                     wrbuf_printf(w, "OID: %s\n", oid_name);
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  * c-file-style: "Stroustrup"
132  * indent-tabs-mode: nil
133  * End:
134  * vim: shiftwidth=4 tabstop=8 expandtab
135  */
136