From 366dc7568281c9774cd309b28c24a077604264a0 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 3 Dec 2002 10:03:27 +0000 Subject: [PATCH] MARC XML --- CHANGELOG | 6 ++ include/yaz/marcdisp.h | 14 +++- include/yaz/wrbuf.h | 8 +-- util/marcdisp.c | 177 ++++++++++++++++++++++++++++-------------------- util/marcdump.c | 15 ++-- zutil/zoom-c.c | 13 ++-- 6 files changed, 143 insertions(+), 90 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2f72252..daadce0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,11 @@ Possible compatibility problems with earlier versions marked with '*'. +ZOOM_record_get supports type "xml" in which case OAI MARC is +returned for MARC. If type is "MarcXML" , MARC XML is returned. + +yaz_marc_decode supports MARC XML as well. The xml parameter +specifies type. See include/marcdisp.h + Fix creation of lib/yaz-config so it works if srcdir != objdir. Patch from Kang-Jin Lee. diff --git a/include/yaz/marcdisp.h b/include/yaz/marcdisp.h index 4eb7017..1668836 100644 --- a/include/yaz/marcdisp.h +++ b/include/yaz/marcdisp.h @@ -23,13 +23,14 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: marcdisp.h,v 1.5 2002-02-28 13:21:16 adam Exp $ + * $Id: marcdisp.h,v 1.6 2002-12-03 10:03:27 adam Exp $ */ #ifndef MARCDISP_H #define MARCDISP_H #include +#include YAZ_BEGIN_CDECL @@ -39,6 +40,17 @@ YAZ_EXPORT int marc_display_exl (const char *buf, FILE *outf, int debug, int length); YAZ_EXPORT int atoi_n (const char *buf, int len); +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); + +#define YAZ_MARC_LINE 0 +#define YAZ_MARC_XML 1 +#define YAZ_MARC_OAIMARC 2 +#define YAZ_MARC_MARCXML 3 + #define ISO2709_RS 035 #define ISO2709_FS 036 #define ISO2709_IDFS 037 diff --git a/include/yaz/wrbuf.h b/include/yaz/wrbuf.h index 383edb2..79c568d 100644 --- a/include/yaz/wrbuf.h +++ b/include/yaz/wrbuf.h @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: wrbuf.h,v 1.6 2002-10-22 10:05:36 adam Exp $ + * $Id: wrbuf.h,v 1.7 2002-12-03 10:03:27 adam Exp $ * */ @@ -56,12 +56,6 @@ YAZ_EXPORT void wrbuf_printf(WRBUF b, const char *fmt, ...); (((b)->pos >= (b)->size ? wrbuf_grow(b, 1) : 0), \ (b)->buf[(b)->pos++] = (c), 0) -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/util/marcdisp.c b/util/marcdisp.c index 235f040..7cadfcd 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.23 2002-10-04 19:11:17 adam Exp $ + * $Id: marcdisp.c,v 1.24 2002-12-03 10:03:27 adam Exp $ */ #if HAVE_CONFIG_H @@ -60,8 +60,22 @@ int yaz_marc_decode (const char *buf, WRBUF wr, int debug, int bsize, int xml) { char str[80]; int i; - if (xml > 1) + switch(xml) { + case YAZ_MARC_XML: + wrbuf_puts (wr, "\n"); + break; + case YAZ_MARC_OAIMARC: wrbuf_puts( wr, "\n", buf[5], buf[6], buf[7]); wrbuf_puts (wr, str); - } - else - { - wrbuf_puts (wr, "\n"); + break; + case YAZ_MARC_MARCXML: + wrbuf_printf( + wr, + "\n" + " \n" + " %.24s\n", buf); + break; } } if (debug) @@ -148,51 +156,51 @@ int yaz_marc_decode (const char *buf, WRBUF wr, int debug, int bsize, int xml) } else if (!memcmp (tag, "00", 2)) identifier_flag = 0; - - - if (xml) - { - if (xml > 1) - { - if (identifier_flag) - wrbuf_puts (wr, " 1) - sprintf (nostr, " i%d=\"%c\"", j+1, buf[i]); - else - sprintf (nostr, " Indicator%d=\"%c\"", j+1, buf[i]); - wrbuf_puts (wr, nostr); - } - else + case YAZ_MARC_LINE: + if (debug) + wrbuf_puts (wr, " Ind: "); wrbuf_putc (wr, buf[i]); + break; + case YAZ_MARC_XML: + wrbuf_printf (wr, " Indicator%d=\"%c\"", j+1, buf[i]); + break; + case YAZ_MARC_OAIMARC: + wrbuf_printf (wr, " i%d=\"%c\"", j+1, buf[i]); + break; + case YAZ_MARC_MARCXML: + wrbuf_printf (wr, " ind%d=\"%c\"", j+1, buf[i]); + } } } if (xml) @@ -211,22 +219,32 @@ int yaz_marc_decode (const char *buf, WRBUF wr, int debug, int bsize, int xml) if (identifier_flag) { i++; - if (xml) + switch(xml) { - if (xml > 1) - wrbuf_puts (wr, " "); - } - else - { - wrbuf_puts (wr, " $"); + break; + case YAZ_MARC_OAIMARC: + wrbuf_puts (wr, " "); + break; + case YAZ_MARC_MARCXML: + wrbuf_puts (wr, " "); + break; } while (buf[i] != ISO2709_RS && buf[i] != ISO2709_IDFS && buf[i] != ISO2709_FS && i < end_offset) @@ -261,27 +279,42 @@ int yaz_marc_decode (const char *buf, WRBUF wr, int debug, int bsize, int xml) wrbuf_puts (wr, " \n"); if (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS) wrbuf_puts (wr, " \n"); - if (xml) + switch(xml) { - if (xml > 1) - { - if (identifier_flag) - wrbuf_puts (wr, "\n"); - else - wrbuf_puts (wr, "\n"); - } + case YAZ_MARC_LINE: + break; + case YAZ_MARC_XML: + wrbuf_puts (wr, "\n"); + break; + case YAZ_MARC_OAIMARC: + if (identifier_flag) + 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"); + break; } } - if (xml) + switch(xml) { - if (xml > 1) - wrbuf_puts (wr, "\n"); - else - wrbuf_puts (wr, "\n"); + case YAZ_MARC_LINE: + wrbuf_puts (wr, ""); + break; + case YAZ_MARC_XML: + wrbuf_puts (wr, "\n"); + break; + case YAZ_MARC_OAIMARC: + wrbuf_puts (wr, "\n"); + break; + case YAZ_MARC_MARCXML: + wrbuf_puts (wr, " \n\n"); + break; } - wrbuf_puts (wr, ""); return record_length; } diff --git a/util/marcdump.c b/util/marcdump.c index b3ff370..076628e 100644 --- a/util/marcdump.c +++ b/util/marcdump.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: marcdump.c,v 1.17 2002-10-04 10:19:58 adam Exp $ + * $Id: marcdump.c,v 1.18 2002-12-03 10:03:27 adam Exp $ */ #if HAVE_CONFIG_H @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -29,7 +28,8 @@ static void usage(const char *prog) { - fprintf (stderr, "Usage: %s [-c cfile] [-x] [-O] [-v] file...\n", prog); + fprintf (stderr, "Usage: %s [-c cfile] [-x] [-O] [-X] [-v] file...\n", + prog); } int main (int argc, char **argv) @@ -44,7 +44,7 @@ int main (int argc, char **argv) int xml = 0; FILE *cfile = 0; - while ((r = options("vc:xO", argv, argc, &arg)) != -2) + while ((r = options("vc:xOX", argv, argc, &arg)) != -2) { int count; no++; @@ -56,10 +56,13 @@ int main (int argc, char **argv) cfile = fopen (arg, "w"); break; case 'x': - xml = 1; + xml = YAZ_MARC_XML; break; case 'O': - xml = 2; + xml = YAZ_MARC_OAIMARC; + break; + case 'X': + xml = YAZ_MARC_MARCXML; break; case 0: inf = fopen (arg, "r"); diff --git a/zutil/zoom-c.c b/zutil/zoom-c.c index c62a08a..9ca55c1 100644 --- a/zutil/zoom-c.c +++ b/zutil/zoom-c.c @@ -1,5 +1,5 @@ /* - * $Id: zoom-c.c,v 1.8 2002-11-30 22:30:51 mike Exp $ + * $Id: zoom-c.c,v 1.9 2002-12-03 10:03:27 adam Exp $ * * ZOOM layer for C, connections, result sets, queries. */ @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -1119,8 +1120,8 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) } return 0; } - else if (!strcmp (type, "xml") && - npr->which == Z_NamePlusRecord_databaseRecord) + else if (npr->which == Z_NamePlusRecord_databaseRecord && + (!strcmp (type, "xml") || !strcmp(type, "MarcXML"))) { Z_External *r = (Z_External *) npr->u.databaseRecord; oident *ent = oid_getentbyoid(r->direct_reference); @@ -1132,6 +1133,10 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) } else if (r->which == Z_External_octet) { + int marc_decode_type = YAZ_MARC_OAIMARC; + + if (!strcmp(type, "MarcXML")) + marc_decode_type = YAZ_MARC_MARCXML; switch (ent->value) { case VAL_SOIF: @@ -1149,7 +1154,7 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) r->u.octet_aligned->buf, rec->wrbuf_marc, 0, r->u.octet_aligned->len, - 2) > 0) + marc_decode_type) > 0) { if (len) *len = wrbuf_len(rec->wrbuf_marc); return wrbuf_buf(rec->wrbuf_marc); -- 1.7.10.4