+static int yaz_record_conv_record_rule(yaz_record_conv_t p,
+ struct yaz_record_conv_rule *r,
+ const char *input_record_buf,
+ size_t input_record_len,
+ WRBUF output_record);
+
+int yaz_record_conv_opac_record(yaz_record_conv_t p,
+ Z_OPACRecord *input_record,
+ WRBUF output_record)
+{
+ int ret = 0;
+ struct yaz_record_conv_rule *r = p->rules;
+ if (!r || r->which != YAZ_RECORD_CONV_RULE_MARC)
+ ret = -1; /* no marc rule so we can't do OPAC */
+ else
+ {
+ WRBUF res = wrbuf_alloc();
+ yaz_marc_t mt = yaz_marc_create();
+ yaz_iconv_t cd = yaz_iconv_open(r->u.marc.output_charset,
+ r->u.marc.input_charset);
+
+ wrbuf_rewind(p->wr_error);
+ yaz_marc_xml(mt, r->u.marc.output_format);
+
+ yaz_marc_iconv(mt, cd);
+
+ yaz_opac_decode_wrbuf(mt, input_record, res);
+ if (ret != -1)
+ {
+ ret = yaz_record_conv_record_rule(p,
+ r->next,
+ wrbuf_buf(res), wrbuf_len(res),
+ output_record);
+ }
+ yaz_marc_destroy(mt);
+ if (cd)
+ yaz_iconv_close(cd);
+ wrbuf_destroy(res);
+ }
+ return ret;
+}
+