Renamed ZOOM_process_event to ZOOM_event_nonblock to signal that it
[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.5 2007-01-03 08:42:15 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             wrbuf_printf(w, "%s\n", t->content->u.string);
70         else if (t->content->which == Z_ElementData_numeric)
71             wrbuf_printf(w, "%d\n", *t->content->u.numeric);
72         else if (t->content->which == Z_ElementData_oid)
73         {
74             int *ip = t->content->u.oid;
75             oident *oent;
76             
77             if ((oent = oid_getentbyoid(t->content->u.oid)))
78                 wrbuf_printf(w, "OID: %s\n", oent->desc);
79             else
80             {
81                 wrbuf_printf(w, "{");
82                 while (ip && *ip >= 0)
83                     wrbuf_printf(w, " %d", *(ip++));
84                 wrbuf_printf(w, " }\n");
85             }
86         }
87         else if (t->content->which == Z_ElementData_noDataRequested)
88             wrbuf_printf(w, "[No data requested]\n");
89         else if (t->content->which == Z_ElementData_elementEmpty)
90             wrbuf_printf(w, "[Element empty]\n");
91         else if (t->content->which == Z_ElementData_elementNotThere)
92             wrbuf_printf(w, "[Element not there]\n");
93         else if (t->content->which == Z_ElementData_date)
94             wrbuf_printf(w, "Date: %s\n", t->content->u.date);
95         else if (t->content->which == Z_ElementData_ext)
96         {
97             printf ("External\n");
98             /* we cannot print externals here. Srry */
99         } 
100         else
101             wrbuf_printf(w, "? type = %d\n",t->content->which);
102         if (t->appliedVariant)
103             display_variant(w, t->appliedVariant, level+1);
104         if (t->metaData && t->metaData->supportedVariants)
105         {
106             int c;
107
108             wrbuf_printf(w, "%*s---- variant list\n", (level+1)*4, "");
109             for (c = 0; c < t->metaData->num_supportedVariants; c++)
110             {
111                 wrbuf_printf(w, "%*svariant #%d\n", (level+1)*4, "", c);
112                 display_variant(w, t->metaData->supportedVariants[c], level+2);
113             }
114         }
115     }
116 }
117
118 void yaz_display_grs1(WRBUF wrbuf, Z_GenericRecord *r, int flags)
119 {
120     display_grs1 (wrbuf, r, 0);
121 }
122
123 /*
124  * Local variables:
125  * c-basic-offset: 4
126  * indent-tabs-mode: nil
127  * End:
128  * vim: shiftwidth=4 tabstop=8 expandtab
129  */
130