X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmarcdisp.c;h=dbee668dca49b2d84cb438332c96e7bd6bd29e01;hb=4050fa4e2dbbd93fe6297c2cab8e59ed01e9060d;hp=1b02e110102ee69115fa60872122dea250e58bc1;hpb=f5234a7d67df11584a2f29b35d999a603ab9cc80;p=yaz-moved-to-github.git diff --git a/src/marcdisp.c b/src/marcdisp.c index 1b02e11..dbee668 100644 --- a/src/marcdisp.c +++ b/src/marcdisp.c @@ -1,8 +1,8 @@ /* - * Copyright (c) 1995-2004, Index Data + * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: marcdisp.c,v 1.9 2004-11-25 09:43:10 adam Exp $ + * $Id: marcdisp.c,v 1.15 2005-02-02 23:25:08 adam Exp $ */ /** @@ -26,6 +26,8 @@ struct yaz_marc_t_ { int xml; int debug; yaz_iconv_t iconv_cd; + char subfield_str[8]; + char endline_str[8]; }; yaz_marc_t yaz_marc_create(void) @@ -35,9 +37,23 @@ yaz_marc_t yaz_marc_create(void) mt->debug = 0; mt->m_wr = wrbuf_alloc(); mt->iconv_cd = 0; + strcpy(mt->subfield_str, " $"); + strcpy(mt->endline_str, "\n"); return mt; } +void yaz_marc_subfield_str(yaz_marc_t mt, const char *s) +{ + strncpy(mt->subfield_str, s, sizeof(mt->subfield_str)-1); + mt->subfield_str[sizeof(mt->subfield_str)-1] = '\0'; +} + +void yaz_marc_endline_str(yaz_marc_t mt, const char *s) +{ + strncpy(mt->endline_str, s, sizeof(mt->endline_str)-1); + mt->endline_str[sizeof(mt->endline_str)-1] = '\0'; +} + void yaz_marc_destroy(yaz_marc_t mt) { if (!mt) @@ -84,18 +100,28 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) /* ballout if bsize is known and record_length is less than that */ if (bsize != -1 && record_length > bsize) return -1; - if (isdigit(buf[10])) + if (isdigit(((const unsigned char *) buf)[10])) indicator_length = atoi_n (buf+10, 1); else indicator_length = 2; - if (isdigit(buf[11])) + if (isdigit(((const unsigned char *) buf)[11])) identifier_length = atoi_n (buf+11, 1); else identifier_length = 2; base_address = atoi_n (buf+12, 5); length_data_entry = atoi_n (buf+20, 1); + if (buf[20] <= '0' || buf[20] >= '9') + { + wrbuf_printf(wr, "\n"); + length_data_entry = 4; + } length_starting = atoi_n (buf+21, 1); + if (buf[21] <= '0' || buf[21] >= '9') + { + wrbuf_printf(wr, "\n"); + length_starting = 5; + } length_implementation = atoi_n (buf+22, 1); if (mt->xml != YAZ_MARC_LINE) @@ -248,9 +274,11 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) int i, j; char tag[4]; int identifier_flag = 0; + int entry_p0; memcpy (tag, buf+entry_p, 3); entry_p += 3; + entry_p0 = entry_p; tag[3] = '\0'; data_length = atoi_n (buf+entry_p, length_data_entry); entry_p += length_data_entry; @@ -259,16 +287,29 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) i = data_offset + base_address; end_offset = i+data_length-1; - if (indicator_length < 4 && indicator_length > 0) + if (mt->debug) + { + wrbuf_printf(wr, "\n", + entry_p0, data_length, data_offset); + } + + if (memcmp (tag, "00", 2)) + identifier_flag = 1; /* if not 00X assume subfields */ + else if (indicator_length < 4 && indicator_length > 0) { + /* Danmarc 00X have subfields */ if (buf[i + indicator_length] == ISO2709_IDFS) identifier_flag = 1; else if (buf[i + indicator_length + 1] == ISO2709_IDFS) identifier_flag = 2; } - else if (memcmp (tag, "00", 2)) - identifier_flag = 1; - + + if (mt->debug) + { + wrbuf_printf(wr, "\n", + identifier_flag); + } + switch(mt->xml) { case YAZ_MARC_LINE: @@ -358,7 +399,7 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) i += identifier_length; break; case YAZ_MARC_LINE: - wrbuf_puts (wr, " $"); + wrbuf_puts (wr, mt->subfield_str); marc_cdata(mt, buf+i, identifier_length-1, wr); i = i+identifier_length-1; wrbuf_putc (wr, ' '); @@ -407,11 +448,11 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) marc_cdata(mt, buf + i, 1, wr); } if (mt->xml == YAZ_MARC_LINE) - wrbuf_putc (wr, '\n'); + wrbuf_puts (wr, mt->endline_str); if (i < end_offset) - wrbuf_puts (wr, " \n"); + wrbuf_printf(wr, " \n", data_length); if (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS) - wrbuf_puts (wr, " \n"); + wrbuf_printf(wr, " \n", data_length); switch(mt->xml) { case YAZ_MARC_SIMPLEXML: @@ -419,15 +460,15 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) break; case YAZ_MARC_OAIMARC: if (identifier_flag) - wrbuf_puts (wr, " \n"); + wrbuf_puts (wr, "\n"); else - wrbuf_puts (wr, " \n"); + wrbuf_puts (wr, "\n"); break; case YAZ_MARC_MARCXML: if (identifier_flag) wrbuf_puts (wr, " \n"); else - wrbuf_puts (wr, " \n"); + wrbuf_puts (wr, "\n"); break; } }