From 98128a8684aa2474140872c25e8c2f5a231710b1 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 20 Apr 2006 19:47:01 +0000 Subject: [PATCH] Added utility yaz_marc_modify_leader which modifies a one or more characters in a MARC leader. Function yaz_write_marcxml and output mode YAZ_MARC_MARCXML sets leader byte at pos = 'a'. Actually this is not new (YAZ 2.1.16 did that too, but it was done differently). --- include/yaz/marcdisp.h | 6 +++++- src/marcdisp.c | 16 +++++++++++++++- test/marc1.xml | 2 +- test/marc1.xml.marc | 2 +- test/marc2.xml | 2 +- test/marc2.xml.marc | 2 +- test/marc3.xml | 2 +- test/marc3.xml.marc | 2 +- test/marc4.xml | 2 +- test/marc4.xml.marc | 2 +- test/marc6.xml | 2 +- test/marc6.xml.marc | 2 +- test/tstmarciso.sh | 12 ++++++------ test/tstmarcxml.sh | 6 +++--- 14 files changed, 39 insertions(+), 21 deletions(-) diff --git a/include/yaz/marcdisp.h b/include/yaz/marcdisp.h index f6a35dc..420f53b 100644 --- a/include/yaz/marcdisp.h +++ b/include/yaz/marcdisp.h @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: marcdisp.h,v 1.15 2006-04-19 10:05:02 adam Exp $ + * $Id: marcdisp.h,v 1.16 2006-04-20 19:47:01 adam Exp $ */ /** @@ -109,6 +109,10 @@ YAZ_EXPORT int yaz_marc_decode(const char *buf, WRBUF wr, YAZ_EXPORT void yaz_marc_subfield_str(yaz_marc_t mt, const char *s); YAZ_EXPORT void yaz_marc_endline_str(yaz_marc_t mt, const char *s); +/** \brief modifies part of the MARC leader */ +YAZ_EXPORT void yaz_marc_modify_leader(yaz_marc_t mt, size_t off, + const char *str); + /** \brief like atoi except that it reads exactly len characters */ YAZ_EXPORT int atoi_n(const char *buf, int len); diff --git a/src/marcdisp.c b/src/marcdisp.c index ea4b2bc..846c38f 100644 --- a/src/marcdisp.c +++ b/src/marcdisp.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: marcdisp.c,v 1.26 2006-04-19 10:05:03 adam Exp $ + * $Id: marcdisp.c,v 1.27 2006-04-20 19:47:01 adam Exp $ */ /** @@ -579,6 +579,7 @@ static int yaz_marc_write_marcxml_ns(yaz_marc_t mt, WRBUF wr, int yaz_marc_write_marcxml(yaz_marc_t mt, WRBUF wr) { + yaz_marc_modify_leader(mt, 9, "a"); return yaz_marc_write_marcxml_ns(mt, wr, "http://www.loc.gov/MARC21/slim"); } @@ -1126,6 +1127,19 @@ void yaz_marc_iconv(yaz_marc_t mt, yaz_iconv_t cd) mt->iconv_cd = cd; } +void yaz_marc_modify_leader(yaz_marc_t mt, size_t off, const char *str) +{ + struct yaz_marc_node *n; + char *leader = 0; + for (n = mt->nodes; n; n = n->next) + if (n->which == YAZ_MARC_LEADER) + { + leader = n->u.leader; + memcpy(leader+off, str, strlen(str)); + break; + } +} + /* deprecated */ int yaz_marc_decode(const char *buf, WRBUF wr, int debug, int bsize, int xml) { diff --git a/test/marc1.xml b/test/marc1.xml index 75b3a95..fe6b692 100644 --- a/test/marc1.xml +++ b/test/marc1.xml @@ -1,6 +1,6 @@ - 00988nam0 32003011 450 + 00988nam0a32003011 450 9 181 423 4 710100 diff --git a/test/marc1.xml.marc b/test/marc1.xml.marc index e899276..efc7bdf 100644 --- a/test/marc1.xml.marc +++ b/test/marc1.xml.marc @@ -1 +1 @@ -00989nam0 32003011 450 001002800000004001000028008002800038009001100066021002700077032001500104100002100119245005400140250004100194260004000235300002700275504012300302512006100425520005000486652002400536652001600560666001600576666001900592666001500611666001800626666001900644666000900663666001500672000a9 181 423 4b710100fa000rnae000tmuua2002buslengv0000aagxx000a1-4000-4596-7d$14,00000&DBC2004390000aSlomanhLarry000aOn the road with Bob DylaneLarry "Ratso" Sloman000aRevised editionbThree Rivers Press000aNew YorkbThree Rivers Pressc2002000axv, 464 sider, tavler000aLarry "Ratso" Slomans meget personlige beretning om Bob Dylans koncertturne i USA i 1975: "The Rolling Thunder revue"000aPå omslaget: With a new introduction by Kinky Friedman000aTidligere: 1. udgave. New York, Bantam, 19780000m99.4aDylanhBob000p78.9064v5000ffolkemusik000ffolkemusikere000frockmusik000frockmusikere000frockkoncerter000eUSA000i1970-1979 \ No newline at end of file +00989nam0a32003011 450 001002800000004001000028008002800038009001100066021002700077032001500104100002100119245005400140250004100194260004000235300002700275504012300302512006100425520005000486652002400536652001600560666001600576666001900592666001500611666001800626666001900644666000900663666001500672000a9 181 423 4b710100fa000rnae000tmuua2002buslengv0000aagxx000a1-4000-4596-7d$14,00000&DBC2004390000aSlomanhLarry000aOn the road with Bob DylaneLarry "Ratso" Sloman000aRevised editionbThree Rivers Press000aNew YorkbThree Rivers Pressc2002000axv, 464 sider, tavler000aLarry "Ratso" Slomans meget personlige beretning om Bob Dylans koncertturne i USA i 1975: "The Rolling Thunder revue"000aPå omslaget: With a new introduction by Kinky Friedman000aTidligere: 1. udgave. New York, Bantam, 19780000m99.4aDylanhBob000p78.9064v5000ffolkemusik000ffolkemusikere000frockmusik000frockmusikere000frockkoncerter000eUSA000i1970-1979 \ No newline at end of file diff --git a/test/marc2.xml b/test/marc2.xml index 6faad3e..dd0bc13 100644 --- a/test/marc2.xml +++ b/test/marc2.xml @@ -1,6 +1,6 @@ - 01116nam0 32002171 450 + 01116nam0a32002171 450 9 182 502 3 710100 diff --git a/test/marc2.xml.marc b/test/marc2.xml.marc index 5580029..106fce3 100644 --- a/test/marc2.xml.marc +++ b/test/marc2.xml.marc @@ -1 +1 @@ -01121nam0 32002171 450 001002800000004001000028008002800038009001100066039000900077100001900086245005900105260003300164300001000197512007300207531001400280538001900294652001500313666004900328795050600377795002000883000a9 182 502 3b710100fa000rcae000tsufa1995bgblengv0000asgxc000abef000aMimmshGarnet000aCry babyaWarm and soulfuleGarnet Mimms ... [et al.]000aBury St. EdmundsbBGOc1995000n1 cd000aIndspilninger publiceret 1963 (Cry baby) og 1965 (Warm and soulful)000aIndhold:000fBGOgBGOCD268000m78.794v4000msoulmrhythm & bluesnvokalp1960-1969lUSA000å11aCry babyaNobody but youaUntil you were goneaAnytime you want meaSo closeaFor your precious loveaBaby don't you weepaA ¤quiet placeaCry to meaDon't change your heartaWanting youaThe ¤truth hurtsaI'll take good care of youaLooking for youaIt won't hurt (half as much)aIt was easier to hurt heraThinkin'aProve it to meaMore than a miracleaAs long as I have youaOne girlaThere goes my babyaIt's just a matter of timeaA ¤little bit of soapaLook awayaI'll make it up to you000å40y0a1 girl \ No newline at end of file +01121nam0a32002171 450 001002800000004001000028008002800038009001100066039000900077100001900086245005900105260003300164300001000197512007300207531001400280538001900294652001500313666004900328795050600377795002000883000a9 182 502 3b710100fa000rcae000tsufa1995bgblengv0000asgxc000abef000aMimmshGarnet000aCry babyaWarm and soulfuleGarnet Mimms ... [et al.]000aBury St. EdmundsbBGOc1995000n1 cd000aIndspilninger publiceret 1963 (Cry baby) og 1965 (Warm and soulful)000aIndhold:000fBGOgBGOCD268000m78.794v4000msoulmrhythm & bluesnvokalp1960-1969lUSA000å11aCry babyaNobody but youaUntil you were goneaAnytime you want meaSo closeaFor your precious loveaBaby don't you weepaA ¤quiet placeaCry to meaDon't change your heartaWanting youaThe ¤truth hurtsaI'll take good care of youaLooking for youaIt won't hurt (half as much)aIt was easier to hurt heraThinkin'aProve it to meaMore than a miracleaAs long as I have youaOne girlaThere goes my babyaIt's just a matter of timeaA ¤little bit of soapaLook awayaI'll make it up to you000å40y0a1 girl \ No newline at end of file diff --git a/test/marc3.xml b/test/marc3.xml index 53f62b8..baab879 100644 --- a/test/marc3.xml +++ b/test/marc3.xml @@ -1,6 +1,6 @@ - 00914naa 2200337 450 + 00914naa a2200337 450 a00001508 a diff --git a/test/marc3.xml.marc b/test/marc3.xml.marc index 9d5c4b7..64f2cef 100644 --- a/test/marc3.xml.marc +++ b/test/marc3.xml.marc @@ -1 +1 @@ -00914naa 2200337 450 001001700000004000900017008002400026009001000050041000800060041000800068097000700076245003300083300002600116557003300142630001600175630001300191633001000204633000900214648006100223648001600284648005400300J01000600354BAS000500360LKR004200365CAT003000407CAT003000437CAT003000467CAT003900497CAT002600536UID001400562 aa00001508fa airn a1991bxxlnortav9 aagxx anor deng00a06 aByfornyelse ved Ibsen-Ringen bfarvefotobplanbsnit aByggekunstj1991v1/2k41-45 fbyfornyelse fsanering fNorge fOslo aTelje Torp Aasen ArkitektkontorcKristian Augustsgate 7B aEng, Dagfin ranlund, TomcKristian AugustsgatecPilestredet 19 aa 0 aITMlARK50b0000145y1991i1/2k41-45 abc20020111lARK01h2002 abc20020111lARK01h2116 abc20021002lARK01h1000 aICLLOADb00c20021122lARK01h1948 c20030618lARK01h1330 aa00001508 \ No newline at end of file +00914naa a2200337 450 001001700000004000900017008002400026009001000050041000800060041000800068097000700076245003300083300002600116557003300142630001600175630001300191633001000204633000900214648006100223648001600284648005400300J01000600354BAS000500360LKR004200365CAT003000407CAT003000437CAT003000467CAT003900497CAT002600536UID001400562 aa00001508fa airn a1991bxxlnortav9 aagxx anor deng00a06 aByfornyelse ved Ibsen-Ringen bfarvefotobplanbsnit aByggekunstj1991v1/2k41-45 fbyfornyelse fsanering fNorge fOslo aTelje Torp Aasen ArkitektkontorcKristian Augustsgate 7B aEng, Dagfin ranlund, TomcKristian AugustsgatecPilestredet 19 aa 0 aITMlARK50b0000145y1991i1/2k41-45 abc20020111lARK01h2002 abc20020111lARK01h2116 abc20021002lARK01h1000 aICLLOADb00c20021122lARK01h1948 c20030618lARK01h1330 aa00001508 \ No newline at end of file diff --git a/test/marc4.xml b/test/marc4.xml index c2f2702..6587da9 100644 --- a/test/marc4.xml +++ b/test/marc4.xml @@ -3,7 +3,7 @@ - 009140091422a 22003370 + 009140091a22a 22003370 diff --git a/test/marc4.xml.marc b/test/marc4.xml.marc index a8f9ac9..9b3d907 100644 --- a/test/marc4.xml.marc +++ b/test/marc4.xml.marc @@ -1 +1 @@ -00026009142200025003370  \ No newline at end of file +000260091a2200025003370  \ No newline at end of file diff --git a/test/marc6.xml b/test/marc6.xml index 2b8578d..a78dca2 100644 --- a/test/marc6.xml +++ b/test/marc6.xml @@ -1,5 +1,5 @@ - 00366nam 22001698a 4500 + 00366nam a22001698a 4500 11224466 DLC 00000000000000.0 diff --git a/test/marc6.xml.marc b/test/marc6.xml.marc index 6f62ae2..400a01a 100644 --- a/test/marc6.xml.marc +++ b/test/marc6.xml.marc @@ -1 +1 @@ -00366nam 22001698a 4500001001300000003000400013005001700017008004100034010001700075040001300092050001200105100001700117245003000134260001200164263000900176300001100185 11224466 DLC00000000000000.0910710c19910701nju 00010 eng  a 11224466  aDLCcDLC00a123-xyz10aJack Collins10aHow to program a computer1 aPenguin a8710 ap. cm. \ No newline at end of file +00366nam a22001698a 4500001001300000003000400013005001700017008004100034010001700075040001300092050001200105100001700117245003000134260001200164263000900176300001100185 11224466 DLC00000000000000.0910710c19910701nju 00010 eng  a 11224466  aDLCcDLC00a123-xyz10aJack Collins10aHow to program a computer1 aPenguin a8710 ap. cm. \ No newline at end of file diff --git a/test/tstmarciso.sh b/test/tstmarciso.sh index 9bf324d..a51a48a 100755 --- a/test/tstmarciso.sh +++ b/test/tstmarciso.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $Id: tstmarciso.sh,v 1.1 2006-04-19 10:05:04 adam Exp $ +# $Id: tstmarciso.sh,v 1.2 2006-04-20 19:47:02 adam Exp $ # Tests reading of ISO2709 and checks that we get identical MARCXML srcdir=${srcdir:-.} ecode=0 @@ -9,24 +9,24 @@ for f in ${srcdir}/marc?; do DIFF=`basename ${f}`.diff ../util/yaz-marcdump -f `cat ${f}.chr` -t utf-8 -X $f > $NEW if test $? != "0"; then - echo "Failed decode of $f" + echo "$f: yaz-marcdump returned error" ecode=1 elif test -f $OLD; then if diff $OLD $NEW >$DIFF; then rm $DIFF rm $NEW else - echo "Differ in $f" + echo "$f: $NEW and $OLD differ" ecode=1 fi else - echo "Making test $f for the first time" + echo "$f: Making test result $OLD for the first time" if test -x /usr/bin/xmllint; then if xmllint --noout $NEW >out 2>stderr; then - echo "XML for $f is OK" + echo "$f: $NEW is well-formed" mv $NEW $OLD else - echo "XML for $f is invalid" + echo "$f: $NEW not well-formed" ecode=1 fi else diff --git a/test/tstmarcxml.sh b/test/tstmarcxml.sh index 7a970fb..0f5cd0b 100755 --- a/test/tstmarcxml.sh +++ b/test/tstmarcxml.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $Id: tstmarcxml.sh,v 1.1 2006-04-19 10:05:04 adam Exp $ +# $Id: tstmarcxml.sh,v 1.2 2006-04-20 19:47:02 adam Exp $ # Tests reading of MARCXML and checks that we get identical ISO2709 output. srcdir=${srcdir:-.} ecode=0 @@ -21,11 +21,11 @@ for f in ${srcdir}/marc?.xml; do rm $DIFF rm $NEW else - echo "Differ in $f" + echo "$f: $NEW and $OLD Differ" ecode=1 fi else - echo "Making test $f for the first time" + echo "$f: Making test result $OLD for the first time" mv $NEW $OLD fi done -- 1.7.10.4