+ {
+ wrbuf_printf(p->wr_error, "Element <marc inputformat='%s'>: "
+ " Unsupported input format"
+ " defined by attribute value",
+ input_format);
+ return -1;
+ }
+
+ if (!output_format)
+ {
+ wrbuf_printf(p->wr_error,
+ "Element <marc>: attribute 'outputformat' required");
+ return -1;
+ }
+ else if (!strcmp(output_format, "line"))
+ {
+ output_format_mode = YAZ_MARC_LINE;
+ }
+ else if (!strcmp(output_format, "marcxml"))
+ {
+ output_format_mode = YAZ_MARC_MARCXML;
+ if (input_charset && !output_charset)
+ output_charset = "utf-8";
+ }
+ else if (!strcmp(output_format, "marc"))
+ {
+ output_format_mode = YAZ_MARC_ISO2709;
+ }
+ else if (!strcmp(output_format, "marcxchange"))
+ {
+ output_format_mode = YAZ_MARC_XCHANGE;
+ if (input_charset && !output_charset)
+ output_charset = "utf-8";
+ }
+ else
+ {
+ wrbuf_printf(p->wr_error, "Element <marc outputformat='%s'>: "
+ " Unsupported output format"
+ " defined by attribute value",
+ output_format);
+ return -1;
+ }
+ if (input_charset && output_charset)
+ {
+ cd = yaz_iconv_open(output_charset, input_charset);
+ if (!cd)
+ {
+ wrbuf_printf(p->wr_error,
+ "Element <marc inputcharset='%s' outputcharset='%s'>:"
+ " Unsupported character set mapping"
+ " defined by attribute values",
+ input_charset, output_charset);
+ return -1;
+ }
+ }
+ else if (input_charset)
+ {
+ wrbuf_printf(p->wr_error, "Element <marc>: "
+ "attribute 'outputcharset' missing");
+ return -1;
+ }
+ else if (output_charset)
+ {
+ wrbuf_printf(p->wr_error, "Element <marc>: "
+ "attribute 'inputcharset' missing");
+ return -1;
+ }
+ r = add_rule(p, YAZ_RECORD_CONV_RULE_MARC);
+ r->u.marc.iconv_t = cd;
+
+ r->u.marc.input_format = input_format_mode;
+ r->u.marc.output_format = output_format_mode;