1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2013 Index Data
3 * See the file LICENSE for details.
7 * \brief Implements display of GRS-1 records
17 #include <yaz/proto.h>
18 #include <yaz/oid_db.h>
20 static void display_variant(WRBUF w, Z_Variant *v, int level)
24 for (i = 0; i < v->num_triples; i++)
26 wrbuf_printf(w, "%*sclass=" ODR_INT_PRINTF ",type=" ODR_INT_PRINTF,
27 level * 4, "", *v->triples[i]->zclass,
28 *v->triples[i]->type);
29 if (v->triples[i]->which == Z_Triple_internationalString)
30 wrbuf_printf(w, ",value=%s\n",
31 v->triples[i]->value.internationalString);
33 wrbuf_printf(w, "\n");
37 static void display_grs1(WRBUF w, Z_GenericRecord *r, int level)
45 for (i = 0; i < r->num_elements; i++)
49 wrbuf_printf(w, "%*s", level * 4, "");
53 wrbuf_printf(w, ODR_INT_PRINTF ",", *t->tagType);
55 wrbuf_printf(w, "?,");
56 if (t->tagValue->which == Z_StringOrNumeric_numeric)
57 wrbuf_printf(w, ODR_INT_PRINTF ") ", *t->tagValue->u.numeric);
59 wrbuf_printf(w, "%s) ", t->tagValue->u.string);
60 if (t->content->which == Z_ElementData_subtree)
62 if (!t->content->u.subtree)
63 printf (" (no subtree)\n");
66 wrbuf_printf(w, "\n");
67 display_grs1(w, t->content->u.subtree, level+1);
70 else if (t->content->which == Z_ElementData_string)
72 wrbuf_puts(w, t->content->u.string);
75 else if (t->content->which == Z_ElementData_numeric)
77 wrbuf_printf(w, ODR_INT_PRINTF "\n", *t->content->u.numeric);
79 else if (t->content->which == Z_ElementData_oid)
81 Odr_oid *ip = t->content->u.oid;
85 char oid_name_str[OID_STR_MAX];
88 = yaz_oid_to_string_buf(ip, &oclass, oid_name_str);
91 wrbuf_printf(w, "OID: %s\n", oid_name);
94 else if (t->content->which == Z_ElementData_noDataRequested)
95 wrbuf_printf(w, "[No data requested]\n");
96 else if (t->content->which == Z_ElementData_elementEmpty)
97 wrbuf_printf(w, "[Element empty]\n");
98 else if (t->content->which == Z_ElementData_elementNotThere)
99 wrbuf_printf(w, "[Element not there]\n");
100 else if (t->content->which == Z_ElementData_date)
101 wrbuf_printf(w, "Date: %s\n", t->content->u.date);
102 else if (t->content->which == Z_ElementData_ext)
104 printf ("External\n");
105 /* we cannot print externals here. Srry */
108 wrbuf_printf(w, "? type = %d\n",t->content->which);
109 if (t->appliedVariant)
110 display_variant(w, t->appliedVariant, level+1);
111 if (t->metaData && t->metaData->supportedVariants)
115 wrbuf_printf(w, "%*s---- variant list\n", (level+1)*4, "");
116 for (c = 0; c < t->metaData->num_supportedVariants; c++)
118 wrbuf_printf(w, "%*svariant #%d\n", (level+1)*4, "", c);
119 display_variant(w, t->metaData->supportedVariants[c], level+2);
125 void yaz_display_grs1(WRBUF wrbuf, Z_GenericRecord *r, int flags)
127 display_grs1(wrbuf, r, 0);
133 * c-file-style: "Stroustrup"
134 * indent-tabs-mode: nil
136 * vim: shiftwidth=4 tabstop=8 expandtab