X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmarcdisp.c;h=ef0642545dbd8802d655f3aab7bcdaeed72b7527;hb=8aa7ee02ee4abdda2f19b42236600f2954ce6c05;hp=1266d250baace991d7c9eb38e3fd7d535d146d18;hpb=a19316337aa3e23b74dac29e5dcad06493ecf083;p=yaz-moved-to-github.git diff --git a/src/marcdisp.c b/src/marcdisp.c index 1266d25..ef06425 100644 --- a/src/marcdisp.c +++ b/src/marcdisp.c @@ -1,8 +1,13 @@ /* - * Copyright (c) 1995-2003, Index Data + * Copyright (c) 1995-2004, Index Data * See the file LICENSE for details. * - * $Id: marcdisp.c,v 1.3 2003-12-17 12:28:07 adam Exp $ + * $Id: marcdisp.c,v 1.11 2004-12-30 00:12:13 adam Exp $ + */ + +/** + * \file marcdisp.c + * \brief Implements MARC display - and conversion utilities */ #if HAVE_CONFIG_H @@ -43,56 +48,12 @@ void yaz_marc_destroy(yaz_marc_t mt) static void marc_cdata (yaz_marc_t mt, const char *buf, size_t len, WRBUF wr) { - size_t i; if (mt->xml == YAZ_MARC_ISO2709) - { wrbuf_iconv_write(wr, mt->iconv_cd, buf, len); - } else if (mt->xml == YAZ_MARC_LINE) - { wrbuf_iconv_write(wr, mt->iconv_cd, buf, len); - } else - { - int j = 0; - for (i = 0; i j) - wrbuf_iconv_write(wr, mt->iconv_cd, buf+j, i-j); - wrbuf_puts(wr, "<"); - j=i+1; - break; - case '>': - if (i > j) - wrbuf_iconv_write(wr, mt->iconv_cd, buf+j, i-j); - wrbuf_puts(wr, ">"); - j=i+1; - break; - case '&': - if (i > j) - wrbuf_iconv_write(wr, mt->iconv_cd, buf+j, i-j); - wrbuf_puts(wr, "&"); - j=i+1; - break; - case '"': - if (i > j) - wrbuf_iconv_write(wr, mt->iconv_cd, buf+j, i-j); - wrbuf_puts(wr, """); - j=i+1; - break; - case '\'': - if (i > j) - wrbuf_iconv_write(wr, mt->iconv_cd, buf+j, i-j); - wrbuf_puts(wr, "'"); - j=i+1; - break; - } - } - if (i > j) - wrbuf_iconv_write(wr, mt->iconv_cd, buf+j, i-j); - } + wrbuf_iconv_write_cdata(wr, mt->iconv_cd, buf, len); } int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) @@ -123,18 +84,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) @@ -177,7 +148,15 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) wrbuf_printf( wr, "\n" - " %.24s\n", buf); + " "); +#if 1 + marc_cdata(mt, buf, 9, wr); + marc_cdata(mt, "a", 1, wr); /* set leader to signal unicode */ + marc_cdata(mt, buf+10, 14, wr); +#else + marc_cdata(mt, buf, 24, wr); /* leave header as is .. */ +#endif + wrbuf_printf(wr, "\n"); break; } } @@ -278,10 +257,12 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) int end_offset; int i, j; char tag[4]; - int identifier_flag = 1; + 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; @@ -290,13 +271,21 @@ 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 (mt->debug) + { + wrbuf_printf(wr, "\n", + entry_p0, data_length, data_offset); + } + if (indicator_length < 4 && indicator_length > 0) { - if (buf[i + indicator_length] != ISO2709_IDFS) - identifier_flag = 0; + 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 = 0; + else if (memcmp (tag, "00", 2)) + identifier_flag = 1; switch(mt->xml) { @@ -307,23 +296,30 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) wrbuf_puts (wr, " "); break; case YAZ_MARC_SIMPLEXML: - wrbuf_printf (wr, "xml) @@ -337,13 +333,19 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) wrbuf_putc(wr, buf[i]); break; case YAZ_MARC_SIMPLEXML: - wrbuf_printf(wr, " Indicator%d=\"%c\"", j+1, buf[i]); + wrbuf_printf(wr, " Indicator%d=\"", j+1); + marc_cdata(mt, buf+i, 1, wr); + wrbuf_printf(wr, "\""); break; case YAZ_MARC_OAIMARC: - wrbuf_printf(wr, " i%d=\"%c\"", j+1, buf[i]); + wrbuf_printf(wr, " i%d=\"", j+1); + marc_cdata(mt, buf+i, 1, wr); + wrbuf_printf(wr, "\""); break; case YAZ_MARC_MARCXML: - wrbuf_printf(wr, " ind%d=\"%c\"", j+1, buf[i]); + wrbuf_printf(wr, " ind%d=\"", j+1); + marc_cdata(mt, buf+i, 1, wr); + wrbuf_printf(wr, "\""); } } } @@ -375,26 +377,26 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) break; case YAZ_MARC_LINE: wrbuf_puts (wr, " $"); - for (j = 1; j"); break; case YAZ_MARC_OAIMARC: wrbuf_puts (wr, " "); break; case YAZ_MARC_MARCXML: wrbuf_puts (wr, " "); break; } @@ -425,9 +427,9 @@ int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) if (mt->xml == YAZ_MARC_LINE) wrbuf_putc (wr, '\n'); 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: