X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fmarcread.c;h=52b59e8c628a65dd9490c1435d92e826da4a2efb;hb=d2bd84bb41320884222ce44b72aa760807b3e659;hp=1cc7de2dad61916735cd5416c48b8510081286e3;hpb=89d3a004b7c651fd5673abfc192e1472dc4d4197;p=idzebra-moved-to-github.git diff --git a/index/marcread.c b/index/marcread.c index 1cc7de2..52b59e8 100644 --- a/index/marcread.c +++ b/index/marcread.c @@ -1,8 +1,5 @@ -/* $Id: marcread.c,v 1.6 2007-01-15 15:10:16 adam Exp $ - Copyright (C) 1995-2007 - Index Data ApS - -This file is part of the Zebra server. +/* This file is part of the Zebra server. + Copyright (C) 1995-2008 Index Data Zebra is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -78,24 +75,35 @@ static data1_node *grs_read_iso2709 (struct grs_read_info *p, int marc_xml) yaz_log (YLOG_WARN, "MARC record length < 25, is %d", record_length); return NULL; } - /* read remaining part - attempt to read one byte furhter... */ - read_bytes = p->stream->readf(p->stream, buf+5, record_length-4); + + read_bytes = p->stream->readf(p->stream, buf+5, record_length-5); if (read_bytes < record_length-5) { yaz_log (YLOG_WARN, "Couldn't read whole MARC record"); return NULL; } - if (read_bytes == record_length - 4) + /* skip until we meet a record separator */ + while (buf[record_length-1] != ISO2709_RS) + { + if (record_length > sizeof(buf)-2) + break; + read_bytes = p->stream->readf(p->stream, buf+record_length, 1); + if (read_bytes != 1) + break; + record_length++; + } + /* read one byte ahead to see if there is more ... */ + read_bytes = p->stream->readf(p->stream, buf+record_length, 1); + if (read_bytes == 1) { off_t cur_offset = p->stream->tellf(p->stream); - if (cur_offset <= 27) - return NULL; if (p->stream->endf) { off_t end_offset = cur_offset - 1; p->stream->endf(p->stream, &end_offset); } } + absynName = mi->type; res_root = data1_mk_root (p->dh, p->mem, absynName); if (!res_root) @@ -761,14 +769,15 @@ static void parse_data1_tree(struct grs_read_info *p, const char *mc_stmnt, field = cat_field(p, pf, buf, field); - pb = wrbuf_buf(buf); + wrbuf_cstr(buf); + pb = wrbuf_buf(buf); for (pb = strtok(pb, "\n"); pb; pb = strtok(NULL, "\n")) { - if (!is_empty(pb)) - { - new = data1_mk_tag_n(p->dh, p->mem, mc_stmnt, strlen(mc_stmnt), 0, top); - data1_mk_text_n(p->dh, p->mem, pb, strlen(pb), new); - } + if (!is_empty(pb)) + { + new = data1_mk_tag_n(p->dh, p->mem, mc_stmnt, strlen(mc_stmnt), 0, top); + data1_mk_text_n(p->dh, p->mem, pb, strlen(pb), new); + } } } else @@ -779,7 +788,7 @@ static void parse_data1_tree(struct grs_read_info *p, const char *mc_stmnt, } mc_destroy_field(pf); mc_destroy_context(c); - wrbuf_free(buf, 1); + wrbuf_destroy(buf); } data1_node *grs_read_marcxml(struct grs_read_info *p)