1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2011 Index Data
3 * See the file LICENSE for details.
7 * \brief Implements display of GRS-1 records
18 #include <yaz/proto.h>
19 #include <yaz/oid_db.h>
21 static void display_variant(WRBUF w, Z_Variant *v, int level)
25 for (i = 0; i < v->num_triples; i++)
27 wrbuf_printf(w, "%*sclass=" ODR_INT_PRINTF ",type=" ODR_INT_PRINTF,
28 level * 4, "", *v->triples[i]->zclass,
29 *v->triples[i]->type);
30 if (v->triples[i]->which == Z_Triple_internationalString)
31 wrbuf_printf(w, ",value=%s\n",
32 v->triples[i]->value.internationalString);
34 wrbuf_printf(w, "\n");
38 static void display_grs1(WRBUF w, Z_GenericRecord *r, int level)
46 for (i = 0; i < r->num_elements; i++)
50 wrbuf_printf(w, "%*s", level * 4, "");
54 wrbuf_printf(w, ODR_INT_PRINTF ",", *t->tagType);
56 wrbuf_printf(w, "?,");
57 if (t->tagValue->which == Z_StringOrNumeric_numeric)
58 wrbuf_printf(w, ODR_INT_PRINTF ") ", *t->tagValue->u.numeric);
60 wrbuf_printf(w, "%s) ", t->tagValue->u.string);
61 if (t->content->which == Z_ElementData_subtree)
63 if (!t->content->u.subtree)
64 printf (" (no subtree)\n");
67 wrbuf_printf(w, "\n");
68 display_grs1(w, t->content->u.subtree, level+1);
71 else if (t->content->which == Z_ElementData_string)
73 wrbuf_puts(w, t->content->u.string);
76 else if (t->content->which == Z_ElementData_numeric)
78 wrbuf_printf(w, ODR_INT_PRINTF "\n", *t->content->u.numeric);
80 else if (t->content->which == Z_ElementData_oid)
82 Odr_oid *ip = t->content->u.oid;
86 char oid_name_str[OID_STR_MAX];
89 = yaz_oid_to_string_buf(ip, &oclass, oid_name_str);
92 wrbuf_printf(w, "OID: %s\n", oid_name);
95 else if (t->content->which == Z_ElementData_noDataRequested)
96 wrbuf_printf(w, "[No data requested]\n");
97 else if (t->content->which == Z_ElementData_elementEmpty)
98 wrbuf_printf(w, "[Element empty]\n");
99 else if (t->content->which == Z_ElementData_elementNotThere)
100 wrbuf_printf(w, "[Element not there]\n");
101 else if (t->content->which == Z_ElementData_date)
102 wrbuf_printf(w, "Date: %s\n", t->content->u.date);
103 else if (t->content->which == Z_ElementData_ext)
105 printf ("External\n");
106 /* we cannot print externals here. Srry */
109 wrbuf_printf(w, "? type = %d\n",t->content->which);
110 if (t->appliedVariant)
111 display_variant(w, t->appliedVariant, level+1);
112 if (t->metaData && t->metaData->supportedVariants)
116 wrbuf_printf(w, "%*s---- variant list\n", (level+1)*4, "");
117 for (c = 0; c < t->metaData->num_supportedVariants; c++)
119 wrbuf_printf(w, "%*svariant #%d\n", (level+1)*4, "", c);
120 display_variant(w, t->metaData->supportedVariants[c], level+2);
126 void yaz_display_grs1(WRBUF wrbuf, Z_GenericRecord *r, int flags)
128 display_grs1(wrbuf, r, 0);
134 * c-file-style: "Stroustrup"
135 * indent-tabs-mode: nil
137 * vim: shiftwidth=4 tabstop=8 expandtab