X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fmarcdisp.c;h=8a25d609b48a992bdd401d0e22d5754fd7609bae;hp=d3c6c922d5dbf38cb8a9372da616748bb75e65ca;hb=4bed35ab0329789b94620258dc57db5db37bfe02;hpb=af1d725908fed3da0afa5d4a20c6e3359effe643 diff --git a/src/marcdisp.c b/src/marcdisp.c index d3c6c92..8a25d60 100644 --- a/src/marcdisp.c +++ b/src/marcdisp.c @@ -1,8 +1,6 @@ -/* - * Copyright (C) 1995-2007, Index Data ApS +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2009 Index Data * See the file LICENSE for details. - * - * $Id: marcdisp.c,v 1.54 2008-01-30 19:59:02 adam Exp $ */ /** @@ -20,6 +18,7 @@ #include #include +#include #include #include #include @@ -426,7 +425,7 @@ int yaz_marc_write_check(yaz_marc_t mt, WRBUF wr) case YAZ_MARC_COMMENT: wrbuf_iconv_write(wr, mt->iconv_cd, n->u.comment, strlen(n->u.comment)); - wrbuf_puts(wr, ")\n"); + wrbuf_puts(wr, "\n"); break; default: break; @@ -435,6 +434,17 @@ int yaz_marc_write_check(yaz_marc_t mt, WRBUF wr) return 0; } +static size_t get_subfield_len(yaz_marc_t mt, const char *data, + int identifier_length) +{ + /* if identifier length is 2 (most MARCs) or less (probably an error), + the code is a single character .. However we've + seen multibyte codes, so see how big it really is */ + if (identifier_length > 2) + return identifier_length - 1; + else + return cdata_one_character(mt, data); +} int yaz_marc_write_line(yaz_marc_t mt, WRBUF wr) { @@ -464,13 +474,8 @@ int yaz_marc_write_line(yaz_marc_t mt, WRBUF wr) n->u.datafield.indicator); for (s = n->u.datafield.subfields; s; s = s->next) { - /* if identifier length is 2 (most MARCs), - the code is a single character .. However we've - seen multibyte codes, so see how big it really is */ - size_t using_code_len = - (identifier_length != 2) ? identifier_length - 1 - : - cdata_one_character(mt, s->code_data); + size_t using_code_len = get_subfield_len(mt, s->code_data, + identifier_length); wrbuf_puts (wr, mt->subfield_str); wrbuf_iconv_write(wr, mt->iconv_cd, s->code_data, @@ -613,14 +618,8 @@ static int yaz_marc_write_marcxml_ns1(yaz_marc_t mt, WRBUF wr, wrbuf_printf(wr, ">\n"); for (s = n->u.datafield.subfields; s; s = s->next) { - /* if identifier length is 2 (most MARCs), - the code is a single character .. However we've - seen multibyte codes, so see how big it really is */ - size_t using_code_len = - (identifier_length != 2) ? identifier_length - 1 - : - cdata_one_character(mt, s->code_data); - + size_t using_code_len = get_subfield_len(mt, s->code_data, + identifier_length); wrbuf_iconv_puts(wr, mt->iconv_cd, " iconv_cd, s->code_data, using_code_len); @@ -714,17 +713,17 @@ int yaz_marc_write_marcxchange(yaz_marc_t mt, WRBUF wr, const char *type) { return yaz_marc_write_marcxml_ns(mt, wr, - "http://www.bs.dk/standards/MarcXchange", + "info:lc/xmlns/marcxchange-v1", 0, 0); } +#if YAZ_HAVE_XML2 int yaz_marc_write_xml(yaz_marc_t mt, xmlNode **root_ptr, const char *ns, const char *format, const char *type) { -#if YAZ_HAVE_XML2 struct yaz_marc_node *n; int identifier_length; const char *leader = 0; @@ -783,14 +782,8 @@ int yaz_marc_write_xml(yaz_marc_t mt, xmlNode **root_ptr, for (s = n->u.datafield.subfields; s; s = s->next) { xmlNode *ptr_subfield; - /* if identifier length is 2 (most MARCs), - the code is a single character .. However we've - seen multibyte codes, so see how big it really is */ - size_t using_code_len = - (identifier_length != 2) ? identifier_length - 1 - : - cdata_one_character(mt, s->code_data); - + size_t using_code_len = get_subfield_len(mt, s->code_data, + identifier_length); wrbuf_rewind(wr_cdata); wrbuf_iconv_puts(wr_cdata, mt->iconv_cd, s->code_data + using_code_len); @@ -829,10 +822,8 @@ int yaz_marc_write_xml(yaz_marc_t mt, xmlNode **root_ptr, } wrbuf_destroy(wr_cdata); return 0; -#else - return -1; -#endif } +#endif int yaz_marc_write_iso2709(yaz_marc_t mt, WRBUF wr) { @@ -1054,7 +1045,7 @@ static int marc_exec_leader(const char *leader_spec, char *leader, size_t size) no = sscanf(cp, "%d=%20[^,]%n", &pos, val, &no_read); if (no < 2 || no_read < 3) return -1; - if (pos < 0 || pos >= size) + if (pos < 0 || (size_t) pos >= size) return -1; if (*val == '\'') @@ -1107,6 +1098,7 @@ void yaz_marc_write_using_libxml2(yaz_marc_t mt, int enable) /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab