1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2010 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 wrbuf_printf(w, "%*sclass=" ODR_INT_PRINTF ",type=" ODR_INT_PRINTF,
26 level * 4, "", *v->triples[i]->zclass,
27 *v->triples[i]->type);
28 if (v->triples[i]->which == Z_Triple_internationalString)
29 wrbuf_printf(w, ",value=%s\n",
30 v->triples[i]->value.internationalString);
32 wrbuf_printf(w, "\n");
36 static void display_grs1(WRBUF w, Z_GenericRecord *r, int level)
44 for (i = 0; i < r->num_elements; i++)
48 wrbuf_printf(w, "%*s", level * 4, "");
52 wrbuf_printf(w, ODR_INT_PRINTF, *t->tagType);
54 wrbuf_printf(w, "?,");
55 if (t->tagValue->which == Z_StringOrNumeric_numeric)
56 wrbuf_printf(w, ODR_INT_PRINTF ") ", *t->tagValue->u.numeric);
58 wrbuf_printf(w, "%s) ", t->tagValue->u.string);
59 if (t->content->which == Z_ElementData_subtree)
61 if (!t->content->u.subtree)
62 printf (" (no subtree)\n");
65 wrbuf_printf(w, "\n");
66 display_grs1(w, t->content->u.subtree, level+1);
69 else if (t->content->which == Z_ElementData_string)
71 wrbuf_puts(w, t->content->u.string);
74 else if (t->content->which == Z_ElementData_numeric)
76 wrbuf_printf(w, ODR_INT_PRINTF "\n", *t->content->u.numeric);
78 else if (t->content->which == Z_ElementData_oid)
80 Odr_oid *ip = t->content->u.oid;
84 char oid_name_str[OID_STR_MAX];
87 = yaz_oid_to_string_buf(ip, &oclass, oid_name_str);
90 wrbuf_printf(w, "OID: %s\n", oid_name);
93 else if (t->content->which == Z_ElementData_noDataRequested)
94 wrbuf_printf(w, "[No data requested]\n");
95 else if (t->content->which == Z_ElementData_elementEmpty)
96 wrbuf_printf(w, "[Element empty]\n");
97 else if (t->content->which == Z_ElementData_elementNotThere)
98 wrbuf_printf(w, "[Element not there]\n");
99 else if (t->content->which == Z_ElementData_date)
100 wrbuf_printf(w, "Date: %s\n", t->content->u.date);
101 else if (t->content->which == Z_ElementData_ext)
103 printf ("External\n");
104 /* we cannot print externals here. Srry */
107 wrbuf_printf(w, "? type = %d\n",t->content->which);
108 if (t->appliedVariant)
109 display_variant(w, t->appliedVariant, level+1);
110 if (t->metaData && t->metaData->supportedVariants)
114 wrbuf_printf(w, "%*s---- variant list\n", (level+1)*4, "");
115 for (c = 0; c < t->metaData->num_supportedVariants; c++)
117 wrbuf_printf(w, "%*svariant #%d\n", (level+1)*4, "", c);
118 display_variant(w, t->metaData->supportedVariants[c], level+2);
124 void yaz_display_grs1(WRBUF wrbuf, Z_GenericRecord *r, int flags)
126 display_grs1(wrbuf, r, 0);
132 * c-file-style: "Stroustrup"
133 * indent-tabs-mode: nil
135 * vim: shiftwidth=4 tabstop=8 expandtab