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