1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2009 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=" 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 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, ODR_INT_PRINTF, *t->tagType);
53 wrbuf_printf(w, "?,");
54 if (t->tagValue->which == Z_StringOrNumeric_numeric)
55 wrbuf_printf(w, ODR_INT_PRINTF ") ", *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)
70 wrbuf_puts(w, t->content->u.string);
73 else if (t->content->which == Z_ElementData_numeric)
75 wrbuf_printf(w, ODR_INT_PRINTF "\n", *t->content->u.numeric);
77 else if (t->content->which == Z_ElementData_oid)
79 Odr_oid *ip = t->content->u.oid;
83 char oid_name_str[OID_STR_MAX];
86 = yaz_oid_to_string_buf(ip, &oclass, oid_name_str);
89 wrbuf_printf(w, "OID: %s\n", oid_name);
92 else if (t->content->which == Z_ElementData_noDataRequested)
93 wrbuf_printf(w, "[No data requested]\n");
94 else if (t->content->which == Z_ElementData_elementEmpty)
95 wrbuf_printf(w, "[Element empty]\n");
96 else if (t->content->which == Z_ElementData_elementNotThere)
97 wrbuf_printf(w, "[Element not there]\n");
98 else if (t->content->which == Z_ElementData_date)
99 wrbuf_printf(w, "Date: %s\n", t->content->u.date);
100 else if (t->content->which == Z_ElementData_ext)
102 printf ("External\n");
103 /* we cannot print externals here. Srry */
106 wrbuf_printf(w, "? type = %d\n",t->content->which);
107 if (t->appliedVariant)
108 display_variant(w, t->appliedVariant, level+1);
109 if (t->metaData && t->metaData->supportedVariants)
113 wrbuf_printf(w, "%*s---- variant list\n", (level+1)*4, "");
114 for (c = 0; c < t->metaData->num_supportedVariants; c++)
116 wrbuf_printf(w, "%*svariant #%d\n", (level+1)*4, "", c);
117 display_variant(w, t->metaData->supportedVariants[c], level+2);
123 void yaz_display_grs1(WRBUF wrbuf, Z_GenericRecord *r, int flags)
125 display_grs1 (wrbuf, r, 0);
131 * c-file-style: "Stroustrup"
132 * indent-tabs-mode: nil
134 * vim: shiftwidth=4 tabstop=8 expandtab