X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=ztest%2Fread-marc.c;h=b11b6973ae8076e8119c1c5a4e70c3e2999a93ac;hb=1ecf21b0324959e62628807d5df217d7a761730b;hp=4767f782fbfe5fb1a22baa8880f25863fea7c532;hpb=4f3bcae93d51a26709c12b51261c3d95af610cb2;p=yaz-moved-to-github.git
diff --git a/ztest/read-marc.c b/ztest/read-marc.c
index 4767f78..b11b697 100644
--- a/ztest/read-marc.c
+++ b/ztest/read-marc.c
@@ -1,5 +1,5 @@
/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2011 Index Data
+ * Copyright (C) 1995-2013 Index Data
* See the file LICENSE for details.
*/
/** \file
@@ -1536,37 +1536,153 @@ char *marc_records[NO_MARC_RECORDS] = {
"\x44\x42\x46\x38\x38\x34\x32\x1E\x1D"
};
+static char *marc_record0 =
+ "00366nam 220016"
+ "98a 450000100130"
+ "0000003000400013"
+ "0050017000170080"
+ "0410003401000170"
+ "0179040001300075"
+ "0500012000881000"
+ "0170010024500300"
+ "0117260001200147"
+ "2630009001593000"
+ "01100168" "\x1E" " 1122"
+ "4466 " "\x1E" "DLC" "\x1E" "000000"
+ "00000000.0" "\x1E" "91071"
+ "0c19910701nju "
+ " 00010 en"
+ "g " "\x1E" " " "\x1F" "aDLC" "\x1F" "cDLC"
+ "" "\x1E" "00" "\x1F" "a123-xyz" "\x1E" "10" "\x1F" ""
+ "aJack Collins" "\x1E" "10"
+ "" "\x1F" "aHow to program"
+ " a computer" "\x1E" "1 " "\x1F" "a"
+ "Penguin" "\x1E" " " "\x1F" "a8710"
+ "" "\x1E" " " "\x1F" "ap. cm." "\x1E" " " "\x1F" "a"
+ " 11224466 " "\x1E" "" "\x1D" ""
+;
+
/* read MARC record from offset 'num' */
char *dummy_marc_record(int num, ODR odr)
{
if (num < 1)
return 0;
- return marc_records[(num-1) % NO_MARC_RECORDS];
+ if (num >= NO_MARC_RECORDS)
+ {
+ char *p = odr_strdup(odr, marc_record0);
+ sprintf(p + 279, "%-5d", num);
+ p[284] = ' ';
+ return p;
+ }
+ else
+ {
+ return marc_records[(num-1) % NO_MARC_RECORDS];
+ }
}
-/* read MARC record and convert to XML */
-char *dummy_xml_record(int num, ODR odr)
+#define PZ_CBEGIN "\n"
+#define PZ_CEND "\n"
+#define PZ_BEGIN "\n"
+#define PZ_END "\n"
+#define PZ_METADATA(x, y) " " y "\n"
+
+static char *dummy_pz2_record(int num, ODR odr)
{
- char *rec = dummy_marc_record(num, odr);
+ const char *rec[] = {
+ PZ_CBEGIN
+ PZ_BEGIN
+ PZ_METADATA(author,"Jack Collins")
+ PZ_METADATA(medium, "book")
+ PZ_METADATA(date, "1995")
+ PZ_METADATA(title, "How to program a computer vol1")
+ PZ_END
+ PZ_BEGIN
+ PZ_METADATA(author,"Jack Collins")
+ PZ_METADATA(medium, "book")
+ PZ_METADATA(date, "1995")
+ PZ_METADATA(title, "How to program a computer vol2")
+ PZ_END
+ PZ_CEND
+ ,
+ PZ_CBEGIN
+ PZ_BEGIN
+ PZ_METADATA(author,"Jack Collins")
+ PZ_METADATA(medium, "book")
+ PZ_METADATA(date, "1995")
+ PZ_METADATA(title, "How to program a computer vol3")
+ PZ_END
+ PZ_BEGIN
+ PZ_METADATA(author,"Jack Collins")
+ PZ_METADATA(medium, "book")
+ PZ_METADATA(date, "1995")
+ PZ_METADATA(title, "How to program a computer vol2")
+ PZ_END
+ PZ_CEND
+ ,
+ PZ_BEGIN
+ PZ_METADATA(author,"Jack Collins")
+ PZ_METADATA(medium, "book")
+ PZ_METADATA(date, "1995")
+ PZ_METADATA(title, "How to program a computer vol1")
+ PZ_END
+ ,
+ /* identical to first */
+ PZ_CBEGIN
+ PZ_BEGIN
+ PZ_METADATA(author,"Jack Collins")
+ PZ_METADATA(medium, "book")
+ PZ_METADATA(date, "1995")
+ PZ_METADATA(title, "How to program a computer vol1")
+ PZ_END
+ PZ_BEGIN
+ PZ_METADATA(author,"Jack Collins")
+ PZ_METADATA(medium, "book")
+ PZ_METADATA(date, "1995")
+ PZ_METADATA(title, "How to program a computer vol4")
+ PZ_END
+ PZ_CEND
+ };
+ if (num > 0 && num <= sizeof(rec)/sizeof(*rec))
+ return odr_strdup(odr, rec[num - 1]);
+ return 0;
+}
- if (rec)
+/* read MARC record and convert to XML */
+char *dummy_xml_record(int num, ODR odr, const char *esn)
+{
+ if (esn && !strcmp(esn, "pz2"))
{
- const char *result;
- size_t rlen;
- int len;
- yaz_marc_t mt = yaz_marc_create();
- yaz_marc_xml(mt, YAZ_MARC_MARCXML);
- len = yaz_marc_decode_buf(mt, rec, -1, &result, &rlen);
- if (len > 1)
+ return dummy_pz2_record(num, odr);
+ }
+ else if (!esn || !strcmp(esn, "marcxml") || !strcmp(esn, "OP"))
+ {
+ /* MARCXML and OPACXML */
+ char *rec = dummy_marc_record(num, odr);
+ if (rec)
{
- rec = (char *) odr_malloc(odr, rlen+1);
- memcpy(rec, result, rlen);
- rec[rlen] = '\0';
+ WRBUF w = wrbuf_alloc();
+ yaz_marc_t mt = yaz_marc_create();
+ yaz_marc_xml(mt, YAZ_MARC_MARCXML);
+ if (esn && !strcmp(esn, "OP"))
+ {
+ /* generate OPACXML (OPAC in XML) */
+ Z_OPACRecord *opac = dummy_opac(num, odr, rec);
+ yaz_opac_decode_wrbuf(mt, opac, w);
+ }
+ else
+ {
+ /* generate MARCXML */
+ yaz_marc_decode_wrbuf(mt, rec, -1, w);
+ }
+ rec = odr_strdup(odr, wrbuf_cstr(w));
+ yaz_marc_destroy(mt);
+ wrbuf_destroy(w);
+ return rec;
}
- yaz_marc_destroy(mt);
}
- return rec;
+ return 0;
}
+
/*
* Local variables:
* c-basic-offset: 4