/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2011 Index Data
+ * Copyright (C) 1995-2012 Index Data
* See the file LICENSE for details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <ctype.h>
#include <yaz/marcdisp.h>
#include <yaz/wrbuf.h>
#include <yaz/yaz-util.h>
return 0;
}
+static void sanitise_leader_for_utf8(yaz_marc_t mt)
+{
+ /* the leader MUST be ASCII for UTF-8 output (XML) */
+ struct yaz_marc_node *n;
+ for (n = mt->nodes; n; n = n->next)
+ if (n->which == YAZ_MARC_LEADER)
+ {
+ size_t i;
+ for (i = 0; n->u.leader[i]; i++)
+ if (n->u.leader[i] < ' ' || n->u.leader[i] > 126)
+ {
+ n->u.leader[i] = ' ';
+ yaz_marc_cprintf(mt, "Fixing leader char at offset %d",
+ (int) (i+1));
+ }
+ }
+}
+
static int yaz_marc_write_marcxml_ns(yaz_marc_t mt, WRBUF wr,
const char *ns,
const char *format,
const char *type,
int turbo)
{
+ sanitise_leader_for_utf8(mt);
if (mt->write_using_libxml2)
{
#if YAZ_HAVE_XML2
xmlAddChild(record_ptr, ptr);
break;
case YAZ_MARC_LEADER:
- {
- char *field = "leader";
- field = "l";
- xmlNewTextChild(record_ptr, ns_record, BAD_CAST field,
+ xmlNewTextChild(record_ptr, ns_record, BAD_CAST "l",
BAD_CAST n->u.leader);
- }
- break;
+ break;
}
}
wrbuf_destroy(wr_cdata);
switch(n->which)
{
case YAZ_MARC_DATAFIELD:
- wrbuf_printf(wr, "%.*s", indicator_length,
- n->u.datafield.indicator);
+ wrbuf_write(wr, n->u.datafield.indicator, indicator_length);
for (s = n->u.datafield.subfields; s; s = s->next)
{
wrbuf_putc(wr, ISO2709_IDFS);