X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fmarc_read_iso2709.c;h=dcae48c6b0872b25aadaedeef382fd99caae3a0c;hp=249ba424ccb89290a9ae43dc9bda2702d1a82c1c;hb=9f11f349958f122419856006d9295eb0ce41274d;hpb=4a23f09ebdcc59ef94e50d385cc5b17f42d8845d diff --git a/src/marc_read_iso2709.c b/src/marc_read_iso2709.c index 249ba42..dcae48c 100644 --- a/src/marc_read_iso2709.c +++ b/src/marc_read_iso2709.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2009 Index Data + * Copyright (C) 1995-2010 Index Data * See the file LICENSE for details. */ @@ -74,18 +74,34 @@ int yaz_marc_read_iso2709(yaz_marc_t mt, const char *buf, int bsize) } if (yaz_marc_get_debug(mt)) { - yaz_marc_cprintf(mt, "Directory offset %d: Tag %.3s", - entry_p, buf+entry_p); + WRBUF hex = wrbuf_alloc(); + + wrbuf_puts(hex, "Tag "); + wrbuf_write_escaped(hex, buf + entry_p, 3); + wrbuf_puts(hex, ", length "); + wrbuf_write_escaped(hex, buf + entry_p + 3, + length_data_entry); + wrbuf_puts(hex, ", starting "); + wrbuf_write_escaped(hex, buf + entry_p + 3 + length_data_entry, + length_starting); + yaz_marc_cprintf(mt, "Directory offset %d: %s", + entry_p, wrbuf_cstr(hex)); + wrbuf_destroy(hex); } - /* Check for digits in length info */ + /* Check for digits in length+starting info */ while (--l >= 3) if (!isdigit(*(const unsigned char *) (buf + entry_p+l))) break; if (l >= 3) { + WRBUF hex = wrbuf_alloc(); /* Not all digits, so stop directory scan */ + wrbuf_write_escaped(hex, buf + entry_p, + length_data_entry + length_starting + 3); yaz_marc_cprintf(mt, "Directory offset %d: Bad value for data" - " length and/or length starting", entry_p); + " length and/or length starting (%s)", entry_p, + wrbuf_cstr(hex)); + wrbuf_destroy(hex); break; } entry_p += 3 + length_data_entry + length_starting; @@ -177,7 +193,8 @@ int yaz_marc_read_iso2709(yaz_marc_t mt, const char *buf, int bsize) buf[i] != ISO2709_RS && buf[i] != ISO2709_IDFS && buf[i] != ISO2709_FS) i++; - yaz_marc_add_subfield(mt, buf+code_offset, i - code_offset); + if (i > code_offset) + yaz_marc_add_subfield(mt, buf+code_offset, i - code_offset); } } else @@ -206,6 +223,7 @@ int yaz_marc_read_iso2709(yaz_marc_t mt, const char *buf, int bsize) /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab