2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: grs1disp.c,v 1.5 2007-01-03 08:42:15 adam Exp $
10 * \brief Implements display of GRS-1 records
18 #include <yaz/proto.h>
20 static void display_variant(WRBUF w, Z_Variant *v, int level)
24 for (i = 0; i < v->num_triples; i++)
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);
35 static void display_grs1(WRBUF w, Z_GenericRecord *r, int level)
43 for (i = 0; i < r->num_elements; i++)
47 wrbuf_printf(w, "%*s", level * 4, "");
51 wrbuf_printf(w, "%d,", *t->tagType);
53 wrbuf_printf(w, "?,");
54 if (t->tagValue->which == Z_StringOrNumeric_numeric)
55 wrbuf_printf(w, "%d) ", *t->tagValue->u.numeric);
57 wrbuf_printf(w, "%s) ", t->tagValue->u.string);
58 if (t->content->which == Z_ElementData_subtree)
60 if (!t->content->u.subtree)
61 printf (" (no subtree)\n");
64 wrbuf_printf(w, "\n");
65 display_grs1(w, t->content->u.subtree, level+1);
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)
74 int *ip = t->content->u.oid;
77 if ((oent = oid_getentbyoid(t->content->u.oid)))
78 wrbuf_printf(w, "OID: %s\n", oent->desc);
82 while (ip && *ip >= 0)
83 wrbuf_printf(w, " %d", *(ip++));
84 wrbuf_printf(w, " }\n");
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)
97 printf ("External\n");
98 /* we cannot print externals here. Srry */
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)
108 wrbuf_printf(w, "%*s---- variant list\n", (level+1)*4, "");
109 for (c = 0; c < t->metaData->num_supportedVariants; c++)
111 wrbuf_printf(w, "%*svariant #%d\n", (level+1)*4, "", c);
112 display_variant(w, t->metaData->supportedVariants[c], level+2);
118 void yaz_display_grs1(WRBUF wrbuf, Z_GenericRecord *r, int flags)
120 display_grs1 (wrbuf, r, 0);
126 * indent-tabs-mode: nil
128 * vim: shiftwidth=4 tabstop=8 expandtab