From: Adam Dickmeiss Date: Thu, 28 Feb 2002 13:21:16 +0000 (+0000) Subject: MARC to XML conversion X-Git-Tag: YAZ.1.8.6~41 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=08e514143cd7d16db15c1c3d4d15d687f561c047 MARC to XML conversion --- diff --git a/CHANGELOG b/CHANGELOG index 49aefa5..edc9267 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,9 @@ Possible compatibility problems with earlier versions marked with '*'. --- 1.8.6 2002/MM/DD +Added function yaz_marc_decode that decodes MARC for line mode +display or XML. + Fixed BER decoding of OPTIONAL CHOICE. The bug didn't affect the Z39.50. But ISO/ILL was, however. diff --git a/buildconf.sh b/buildconf.sh index 047b5aa..9816e34 100755 --- a/buildconf.sh +++ b/buildconf.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $Id: buildconf.sh,v 1.7 2001-11-06 17:03:50 adam Exp $ +# $Id: buildconf.sh,v 1.8 2002-02-28 13:21:16 adam Exp $ aclocal libtoolize --automake --force || exit 2 automake -a || exit 3 @@ -7,4 +7,4 @@ autoconf || exit 4 if [ -f config.cache ]; then rm config.cache fi -util/cvs-date.tcl include/yaz/yaz-date.h +#util/cvs-date.tcl include/yaz/yaz-date.h diff --git a/doc/yazhtml.xsl b/doc/yazhtml.xsl index 05cbcbf..521d024 100644 --- a/doc/yazhtml.xsl +++ b/doc/yazhtml.xsl @@ -4,6 +4,8 @@ + + diff --git a/include/yaz/marcdisp.h b/include/yaz/marcdisp.h index 86abc0f..4eb7017 100644 --- a/include/yaz/marcdisp.h +++ b/include/yaz/marcdisp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995-2001, Index Data. + * Copyright (c) 1995-2002, Index Data. * * Permission to use, copy, modify, distribute, and sell this software and * its documentation, in whole or in part, for any purpose, is hereby granted, @@ -23,45 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Log: marcdisp.h,v $ - * Revision 1.4 2001-10-29 09:17:19 adam - * New function marc_display_exl - used by YAZ client. Server returns - * bad record on position 98 (for testing). - * - * Revision 1.3 2001/04/06 12:26:46 adam - * Optional CCL module. Moved atoi_n to marcdisp.h from yaz-util.h. - * - * Revision 1.2 2000/02/28 11:20:06 adam - * Using autoconf. New definitions: YAZ_BEGIN_CDECL/YAZ_END_CDECL. - * - * Revision 1.1 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.8 1997/09/24 13:35:45 adam - * Added two members to data1_marctab to ease reading of weird MARC records. - * - * Revision 1.7 1997/09/04 07:57:51 adam - * Definition of ISO2709 control characters to this file. - * - * Revision 1.6 1997/09/01 08:49:49 adam - * New windows NT/95 port using MSV5.0. To export DLL functions the - * YAZ_EXPORT modifier was added. Defined in yconfig.h. - * - * Revision 1.5 1997/05/14 06:53:40 adam - * C++ support. - * - * Revision 1.4 1995/09/29 17:12:03 quinn - * Smallish - * - * Revision 1.3 1995/09/27 15:02:47 quinn - * Modified function heads & prototypes. - * - * Revision 1.2 1995/05/16 08:50:32 quinn - * License, documentation, and memory fixes - * - * Revision 1.1 1995/04/10 10:28:28 quinn - * Added copy of CCL. - * + * $Id: marcdisp.h,v 1.5 2002-02-28 13:21:16 adam Exp $ */ #ifndef MARCDISP_H diff --git a/include/yaz/wrbuf.h b/include/yaz/wrbuf.h index f3bb57b..3832743 100644 --- a/include/yaz/wrbuf.h +++ b/include/yaz/wrbuf.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995-2000, Index Data. + * Copyright (c) 1995-2002, Index Data. * * Permission to use, copy, modify, distribute, and sell this software and * its documentation, in whole or in part, for any purpose, is hereby granted, @@ -23,32 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Log: wrbuf.h,v $ - * Revision 1.4 2001-10-23 21:00:19 adam - * Old Z39.50 codecs gone. Added ZOOM. WRBUF MARC display util. - * - * Revision 1.3 2001/10/15 19:36:48 adam - * New function marc_display_wrbuf. - * - * Revision 1.2 2000/02/28 11:20:06 adam - * Using autoconf. New definitions: YAZ_BEGIN_CDECL/YAZ_END_CDECL. - * - * Revision 1.1 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.8 1999/11/03 09:05:56 adam - * Implemented wrbuf_puts. - * - * Revision 1.7 1999/08/27 09:40:32 adam - * Renamed logf function to yaz_log. Removed VC++ project files. - * - * Revision 1.6 1997/10/31 12:20:08 adam - * Improved memory debugging for xmalloc/nmem.c. References to NMEM - * instead of ODR in n ESPEC-1 handling in source d1_espec.c. - * Bug fix: missing fclose in data1_read_espec1. - * - * Revision 1.5 1997/09/17 12:10:32 adam - * YAZ version 1.4. + * $Id: wrbuf.h,v 1.5 2002-02-28 13:21:16 adam Exp $ * */ @@ -83,6 +58,9 @@ YAZ_EXPORT int wrbuf_puts(WRBUF b, const char *buf); YAZ_EXPORT int marc_display_wrbuf (const char *buf, WRBUF wr, int debug, int bsize); +YAZ_EXPORT int yaz_marc_decode (const char *buf, WRBUF wr, int debug, + int bsize, int xml); + YAZ_END_CDECL #endif diff --git a/lib/Makefile.am b/lib/Makefile.am index 5fe0a9c..6fb0ce2 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.18 2001-11-19 20:43:39 adam Exp $ +## $Id: Makefile.am,v 1.19 2002-02-28 13:21:16 adam Exp $ if ISTHR extra=libyazthread.la @@ -51,7 +51,6 @@ xmalloc.lo: $(top_srcdir)/util/xmalloc.c xmalloc.o: $(top_srcdir)/util/xmalloc.c $(COMPILE) $(XMALLOC_FLAGS) -c $(top_srcdir)/util/xmalloc.c - libyaz_la_LIBADD=../odr/libodr.la \ ../comstack/libcomstack.la ../server/libserver.la \ ../util/libutil.la ../retrieval/libret.la \ diff --git a/util/marcdisp.c b/util/marcdisp.c index 03bb37c..f728d12 100644 --- a/util/marcdisp.c +++ b/util/marcdisp.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Id: marcdisp.c,v 1.17 2002-02-01 14:50:29 adam Exp $ + * $Id: marcdisp.c,v 1.18 2002-02-28 13:21:16 adam Exp $ */ #if HAVE_CONFIG_H @@ -16,8 +16,7 @@ #include #include -int marc_display_wrbuf (const char *buf, WRBUF wr, int debug, - int bsize) +int yaz_marc_decode (const char *buf, WRBUF wr, int debug, int bsize, int xml) { int entry_p; int record_length; @@ -94,10 +93,19 @@ int marc_display_wrbuf (const char *buf, WRBUF wr, int debug, memcpy (tag, buf+entry_p, 3); entry_p += 3; tag[3] = '\0'; - if (debug) - wrbuf_puts (wr, "Tag: "); - wrbuf_puts (wr, tag); - wrbuf_puts (wr, " "); + if (xml) + { + wrbuf_puts (wr, ""); + if (identifier_flag) + wrbuf_puts (wr, "\n"); + } + else + { + if (debug) + wrbuf_puts (wr, " Fields: "); + } while (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS && i < end_offset) { if (identifier_flag) { i++; - wrbuf_puts (wr, " $"); - for (j = 1; j"); + } + else + { + wrbuf_puts (wr, " $"); + for (j = 1; j\n"); } else { @@ -144,16 +182,25 @@ int marc_display_wrbuf (const char *buf, WRBUF wr, int debug, i++; } } - wrbuf_putc (wr, '\n'); + if (!xml) + wrbuf_putc (wr, '\n'); if (i < end_offset) - wrbuf_puts (wr, "-- separator but not at end of field\n"); + wrbuf_puts (wr, " \n"); if (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS) - wrbuf_puts (wr, "-- no separator at end of field\n"); + wrbuf_puts (wr, " \n"); + if (xml) + wrbuf_puts (wr, "\n"); } wrbuf_puts (wr, ""); return record_length; } +int marc_display_wrbuf (const char *buf, WRBUF wr, int debug, + int bsize) +{ + return yaz_marc_decode (buf, wr, debug, bsize, 0); +} + int marc_display_exl (const char *buf, FILE *outf, int debug, int length) { int record_length; @@ -168,7 +215,6 @@ int marc_display_exl (const char *buf, FILE *outf, int debug, int length) return record_length; } - int marc_display_ex (const char *buf, FILE *outf, int debug) { return marc_display_exl (buf, outf, debug, -1); diff --git a/zoom/zoom-c.c b/zoom/zoom-c.c index 41ec33b..481f904 100644 --- a/zoom/zoom-c.c +++ b/zoom/zoom-c.c @@ -1,5 +1,5 @@ /* - * $Id: zoom-c.c,v 1.23 2002-01-28 09:27:48 adam Exp $ + * $Id: zoom-c.c,v 1.24 2002-02-28 13:21:16 adam Exp $ * * ZOOM layer for C, connections, result sets, queries. */ @@ -902,51 +902,96 @@ const char *ZOOM_record_get (ZOOM_record rec, const char *type, int *len) } return "none"; } - else if (!strcmp (type, "render")) + else if (!strcmp (type, "render") && + npr->which == Z_NamePlusRecord_databaseRecord) { - if (npr->which == Z_NamePlusRecord_databaseRecord) - { - Z_External *r = (Z_External *) npr->u.databaseRecord; - oident *ent = oid_getentbyoid(r->direct_reference); - - if (r->which == Z_External_sutrs) - { - *len = r->u.sutrs->len; - return (const char *) r->u.sutrs->buf; - } - else if (r->which == Z_External_octet) - { - switch (ent->value) - { - case VAL_SOIF: - case VAL_HTML: - case VAL_SUTRS: - break; - case VAL_TEXT_XML: - case VAL_APPLICATION_XML: - break; - default: - if (!rec->wrbuf_marc) - rec->wrbuf_marc = wrbuf_alloc(); - wrbuf_rewind (rec->wrbuf_marc); - if (marc_display_wrbuf ((const char *) - r->u.octet_aligned->buf, - rec->wrbuf_marc, 0, - r->u.octet_aligned->len) > 0) - { - *len = wrbuf_len(rec->wrbuf_marc); - return wrbuf_buf(rec->wrbuf_marc); - } - } - *len = r->u.octet_aligned->len; - return (const char *) r->u.octet_aligned->buf; - } - else if (r->which == Z_External_grs1) - { - *len = 5; - return "GRS-1"; - } - } + Z_External *r = (Z_External *) npr->u.databaseRecord; + oident *ent = oid_getentbyoid(r->direct_reference); + + if (r->which == Z_External_sutrs) + { + *len = r->u.sutrs->len; + return (const char *) r->u.sutrs->buf; + } + else if (r->which == Z_External_octet) + { + switch (ent->value) + { + case VAL_SOIF: + case VAL_HTML: + case VAL_SUTRS: + break; + case VAL_TEXT_XML: + case VAL_APPLICATION_XML: + break; + default: + if (!rec->wrbuf_marc) + rec->wrbuf_marc = wrbuf_alloc(); + wrbuf_rewind (rec->wrbuf_marc); + if (yaz_marc_decode ((const char *) + r->u.octet_aligned->buf, + rec->wrbuf_marc, 0, + r->u.octet_aligned->len, + 0) > 0) + { + *len = wrbuf_len(rec->wrbuf_marc); + return wrbuf_buf(rec->wrbuf_marc); + } + } + *len = r->u.octet_aligned->len; + return (const char *) r->u.octet_aligned->buf; + } + else if (r->which == Z_External_grs1) + { + *len = 5; + return "GRS-1"; + } + return 0; + } + else if (!strcmp (type, "xml") && + npr->which == Z_NamePlusRecord_databaseRecord) + { + Z_External *r = (Z_External *) npr->u.databaseRecord; + oident *ent = oid_getentbyoid(r->direct_reference); + + if (r->which == Z_External_sutrs) + { + *len = r->u.sutrs->len; + return (const char *) r->u.sutrs->buf; + } + else if (r->which == Z_External_octet) + { + switch (ent->value) + { + case VAL_SOIF: + case VAL_HTML: + case VAL_SUTRS: + break; + case VAL_TEXT_XML: + case VAL_APPLICATION_XML: + break; + default: + if (!rec->wrbuf_marc) + rec->wrbuf_marc = wrbuf_alloc(); + wrbuf_rewind (rec->wrbuf_marc); + if (yaz_marc_decode ((const char *) + r->u.octet_aligned->buf, + rec->wrbuf_marc, 0, + r->u.octet_aligned->len, + 1) > 0) + { + *len = wrbuf_len(rec->wrbuf_marc); + return wrbuf_buf(rec->wrbuf_marc); + } + } + *len = r->u.octet_aligned->len; + return (const char *) r->u.octet_aligned->buf; + } + else if (r->which == Z_External_grs1) + { + *len = 5; + return "GRS-1"; + } return 0; } else if (!strcmp (type, "raw")) diff --git a/zoom/zoomtst5.c b/zoom/zoomtst5.c index 0d24287..5061d13 100644 --- a/zoom/zoomtst5.c +++ b/zoom/zoomtst5.c @@ -1,5 +1,5 @@ /* - * $Id: zoomtst5.c,v 1.8 2002-02-20 14:40:42 adam Exp $ + * $Id: zoomtst5.c,v 1.9 2002-02-28 13:21:16 adam Exp $ * * Asynchronous multi-target client doing search, sort and present */ @@ -97,7 +97,7 @@ int main(int argc, char **argv) /* get database for record and record itself at pos */ db = ZOOM_record_get (rec, "database", 0); - str = ZOOM_record_get (rec, "render", &len); + str = ZOOM_record_get (rec, "xml", &len); syntax = ZOOM_record_get (rec, "syntax", &len); /* if rec is non-null, we got a record for display */ if (str)