1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2008 Index Data
3 * See the file LICENSE for details.
8 * \brief Implements display of GRS-1 records
16 #include <yaz/proto.h>
17 #include <yaz/oid_db.h>
19 static void display_variant(WRBUF w, Z_Variant *v, int level)
23 for (i = 0; i < v->num_triples; i++)
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);
34 static void display_grs1(WRBUF w, Z_GenericRecord *r, int level)
42 for (i = 0; i < r->num_elements; i++)
46 wrbuf_printf(w, "%*s", level * 4, "");
50 wrbuf_printf(w, "%d,", *t->tagType);
52 wrbuf_printf(w, "?,");
53 if (t->tagValue->which == Z_StringOrNumeric_numeric)
54 wrbuf_printf(w, "%d) ", *t->tagValue->u.numeric);
56 wrbuf_printf(w, "%s) ", t->tagValue->u.string);
57 if (t->content->which == Z_ElementData_subtree)
59 if (!t->content->u.subtree)
60 printf (" (no subtree)\n");
63 wrbuf_printf(w, "\n");
64 display_grs1(w, t->content->u.subtree, level+1);
67 else if (t->content->which == Z_ElementData_string)
69 wrbuf_puts(w, t->content->u.string);
72 else if (t->content->which == Z_ElementData_numeric)
74 wrbuf_printf(w, "%d\n", *t->content->u.numeric);
76 else if (t->content->which == Z_ElementData_oid)
78 Odr_oid *ip = t->content->u.oid;
82 char oid_name_str[OID_STR_MAX];
85 = yaz_oid_to_string_buf(ip, &oclass, oid_name_str);
88 wrbuf_printf(w, "OID: %s\n", oid_name);
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)
101 printf ("External\n");
102 /* we cannot print externals here. Srry */
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)
112 wrbuf_printf(w, "%*s---- variant list\n", (level+1)*4, "");
113 for (c = 0; c < t->metaData->num_supportedVariants; c++)
115 wrbuf_printf(w, "%*svariant #%d\n", (level+1)*4, "", c);
116 display_variant(w, t->metaData->supportedVariants[c], level+2);
122 void yaz_display_grs1(WRBUF wrbuf, Z_GenericRecord *r, int flags)
124 display_grs1 (wrbuf, r, 0);
130 * indent-tabs-mode: nil
132 * vim: shiftwidth=4 tabstop=8 expandtab