2 * Copyright (c) 2002, Index Data.
3 * See the file LICENSE for details.
5 * $Id: grs1disp.c,v 1.1 2002-10-22 10:29:58 adam Exp $
13 #include <yaz/proto.h>
15 static void display_variant(WRBUF w, Z_Variant *v, int level)
19 for (i = 0; i < v->num_triples; i++)
21 printf("%*sclass=%d,type=%d", level * 4, "", *v->triples[i]->zclass,
22 *v->triples[i]->type);
23 if (v->triples[i]->which == Z_Triple_internationalString)
24 printf(",value=%s\n", v->triples[i]->value.internationalString);
30 static void display_grs1(WRBUF w, Z_GenericRecord *r, int level)
38 for (i = 0; i < r->num_elements; i++)
42 wrbuf_printf(w, "%*s", level * 4, "");
46 wrbuf_printf(w, "%d,", *t->tagType);
48 wrbuf_printf(w, "?,");
49 if (t->tagValue->which == Z_StringOrNumeric_numeric)
50 wrbuf_printf(w, "%d) ", *t->tagValue->u.numeric);
52 wrbuf_printf(w, "%s) ", t->tagValue->u.string);
53 if (t->content->which == Z_ElementData_subtree)
55 if (!t->content->u.subtree)
56 printf (" (no subtree)\n");
59 wrbuf_printf(w, "\n");
60 display_grs1(w, t->content->u.subtree, level+1);
63 else if (t->content->which == Z_ElementData_string)
64 wrbuf_printf(w, "%s\n", t->content->u.string);
65 else if (t->content->which == Z_ElementData_numeric)
66 wrbuf_printf(w, "%d\n", *t->content->u.numeric);
67 else if (t->content->which == Z_ElementData_oid)
69 int *ip = t->content->u.oid;
72 if ((oent = oid_getentbyoid(t->content->u.oid)))
73 wrbuf_printf(w, "OID: %s\n", oent->desc);
77 while (ip && *ip >= 0)
78 wrbuf_printf(w, " %d", *(ip++));
79 wrbuf_printf(w, " }\n");
82 else if (t->content->which == Z_ElementData_noDataRequested)
83 wrbuf_printf(w, "[No data requested]\n");
84 else if (t->content->which == Z_ElementData_elementEmpty)
85 wrbuf_printf(w, "[Element empty]\n");
86 else if (t->content->which == Z_ElementData_elementNotThere)
87 wrbuf_printf(w, "[Element not there]\n");
88 else if (t->content->which == Z_ElementData_date)
89 wrbuf_printf(w, "Date: %s\n", t->content->u.date);
90 else if (t->content->which == Z_ElementData_ext)
92 printf ("External\n");
93 /* we cannot print externals here. Srry */
96 wrbuf_printf(w, "? type = %d\n",t->content->which);
97 if (t->appliedVariant)
98 display_variant(w, t->appliedVariant, level+1);
99 if (t->metaData && t->metaData->supportedVariants)
103 wrbuf_printf(w, "%*s---- variant list\n", (level+1)*4, "");
104 for (c = 0; c < t->metaData->num_supportedVariants; c++)
106 wrbuf_printf(w, "%*svariant #%d\n", (level+1)*4, "", c);
107 display_variant(w, t->metaData->supportedVariants[c], level+2);
113 void yaz_display_grs1(WRBUF wrbuf, Z_GenericRecord *r, int flags)
115 display_grs1 (wrbuf, r, 0);