+static const char *return_record(ZOOM_record rec, int *len,
+ Z_NamePlusRecord *npr,
+ int marctype, const char *charset)
+{
+ Z_External *r = (Z_External *) npr->u.databaseRecord;
+ const Odr_oid *oid = r->direct_reference;
+ WRBUF wrbuf;
+
+#if SHPTR
+ if (!rec->record_wrbuf)
+ {
+ WRBUF w = wrbuf_alloc();
+ YAZ_SHPTR_INIT(rec->record_wrbuf, w);
+ }
+ wrbuf = rec->record_wrbuf->ptr;
+#else
+ if (!rec->wrbuf)
+ rec->wrbuf = wrbuf_alloc();
+ wrbuf = rec->wrbuf;
+#endif
+ wrbuf_rewind(wrbuf);
+ /* render bibliographic record .. */
+ if (r->which == Z_External_OPAC)
+ {
+ return return_opac_record(rec, wrbuf, marctype, len,
+ r->u.opac, charset);
+ }
+ if (r->which == Z_External_sutrs)
+ return return_string_record(rec, wrbuf, len,
+ (char*) r->u.sutrs->buf,
+ r->u.sutrs->len,
+ charset);
+ else if (r->which == Z_External_octet)
+ {
+ if (yaz_oid_is_iso2709(oid))
+ {
+ const char *ret_buf = return_marc_record(
+ rec, wrbuf, marctype, len,
+ (const char *) r->u.octet_aligned->buf,
+ r->u.octet_aligned->len,
+ charset);
+ if (ret_buf)
+ return ret_buf;
+ /* bad ISO2709. Return fail unless raw (ISO2709) is wanted */
+ if (marctype != YAZ_MARC_ISO2709)
+ return 0;
+ }
+ return return_string_record(rec, wrbuf, len,
+ (const char *) r->u.octet_aligned->buf,
+ r->u.octet_aligned->len,
+ charset);
+ }
+ else if (r->which == Z_External_grs1)
+ {
+ yaz_display_grs1(wrbuf, r->u.grs1, 0);
+ return return_string_record(rec, wrbuf, len,
+ wrbuf_buf(wrbuf),
+ wrbuf_len(wrbuf),
+ charset);
+ }
+ return 0;
+}
+