Pass /manifest option always YAZ-804
[yaz-moved-to-github.git] / ztest / read-marc.c
index b11b697..0b9dc1d 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2013 Index Data
+ * Copyright (C) Index Data
  * See the file LICENSE for details.
  */
 /** \file
 #include <yaz/wrbuf.h>
 #include <yaz/marcdisp.h>
 #include <yaz/odr.h>
+#include <yaz/log.h>
 
 #include "ztest.h"
 
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#if HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef WIN32
+#include <sys/stat.h>
+#endif
+
+#include <stdlib.h>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
 #define NO_MARC_RECORDS 24
 
 char *marc_records[NO_MARC_RECORDS] = {
@@ -1680,6 +1696,49 @@ char *dummy_xml_record(int num, ODR odr, const char *esn)
             return rec;
         }
     }
+    else
+    {
+        char *buf = 0;
+        const char *e = getenv("YAZ_ZTEST_XML_FETCH");
+        if (e)
+        {
+            WRBUF w = wrbuf_alloc();
+            struct stat sbuf;
+            FILE *file = 0;
+
+            wrbuf_printf(w, "%s%s.%d.xml", e, esn, num);
+            if (stat(wrbuf_cstr(w), &sbuf) == 0 &&
+                (file = fopen(wrbuf_cstr(w), "rb")))
+            {
+                buf = odr_malloc(odr, 1 + sbuf.st_size);
+                fread(buf, 1, sbuf.st_size, file);
+                buf[sbuf.st_size] = '\0';
+            }
+            if (file)
+                fclose(file);
+        }
+        return buf;
+    }
+    return 0;
+}
+
+char *dummy_json_record(int num, ODR odr, const char *esn)
+{
+    if (!esn || !strcmp(esn, "marcinjson"))
+    {
+        char *rec = dummy_marc_record(num, odr);
+        if (rec)
+        {
+            WRBUF w = wrbuf_alloc();
+            yaz_marc_t mt = yaz_marc_create();
+            yaz_marc_xml(mt, YAZ_MARC_JSON);
+            yaz_marc_decode_wrbuf(mt, rec, -1, w);
+            rec = odr_strdup(odr, wrbuf_cstr(w));
+            yaz_marc_destroy(mt);
+            wrbuf_destroy(w);
+            return rec;
+        }
+    }
     return 0;
 }