Removed duplicate variable for turbo marcxml (using_turbo_format). Now works in zooms...
[yaz-moved-to-github.git] / src / marcdisp.c
index bd03c00..1f00f41 100644 (file)
@@ -91,7 +91,6 @@ struct yaz_marc_t_ {
     int output_format;
     int debug;
     int write_using_libxml2;
-    int turbo_format;
     enum yaz_collection_state enable_collection;
     yaz_iconv_t iconv_cd;
     char subfield_str[8];
@@ -163,6 +162,16 @@ void yaz_marc_add_controlfield_xml(yaz_marc_t mt, const xmlNode *ptr_tag,
     n->u.controlfield.tag = nmem_text_node_cdata(ptr_tag, mt->nmem);
     n->u.controlfield.data = nmem_text_node_cdata(ptr_data, mt->nmem);
 }
+
+void yaz_marc_add_controlfield_turbo_xml(yaz_marc_t mt, const char *tag,
+                                   const xmlNode *ptr_data)
+{
+    struct yaz_marc_node *n = yaz_marc_add_node(mt);
+    n->which = YAZ_MARC_CONTROLFIELD;
+    n->u.controlfield.tag = tag;
+    n->u.controlfield.data = nmem_text_node_cdata(ptr_data, mt->nmem);
+}
+
 #endif
 
 
@@ -527,6 +536,7 @@ int yaz_marc_write_trailer(yaz_marc_t mt, WRBUF wr)
         switch(mt->output_format)
         {
         case YAZ_MARC_MARCXML:
+        case YAZ_MARC_TMARCXML:
             wrbuf_printf(wr, "</collection>\n");
             break;
         case YAZ_MARC_XCHANGE:
@@ -686,9 +696,9 @@ static int yaz_marc_write_marcxml_ns(yaz_marc_t mt, WRBUF wr,
         int ret;
         xmlNode *root_ptr;
 
-        if (!mt->turbo_format)
+        if (yaz_marc_get_write_format(mt) == YAZ_MARC_MARCXML)
                ret = yaz_marc_write_xml(mt, &root_ptr, ns, format, type);
-        else
+        else // Check for Turbo XML
                ret = yaz_marc_write_turbo_xml(mt, &root_ptr, ns, format, type);
         if (ret == 0)
         {
@@ -741,7 +751,7 @@ void add_marc_datafield_turbo_xml(yaz_marc_t mt, struct yaz_marc_node *n, xmlNod
 {
     xmlNode *ptr;
     struct yaz_marc_subfield *s;
-    int turbo = mt->turbo_format;
+    int turbo = mt->output_format == YAZ_MARC_TMARCXML;
     if (!turbo) {
         ptr = xmlNewChild(record_ptr, ns_record, BAD_CAST "datafield", 0);
         xmlNewProp(ptr, BAD_CAST "tag", BAD_CAST n->u.datafield.tag);
@@ -751,6 +761,7 @@ void add_marc_datafield_turbo_xml(yaz_marc_t mt, struct yaz_marc_node *n, xmlNod
        char field[10];
        field[0] = 'd';
         strncpy(field + 1, n->u.datafield.tag, 3);
+        field[4] = '\0';
         ptr = xmlNewChild(record_ptr, ns_record, BAD_CAST field, 0);
     }
     if (n->u.datafield.indicator)
@@ -832,7 +843,7 @@ int yaz_marc_write_turbo_xml(yaz_marc_t mt, xmlNode **root_ptr,
     xmlNode *record_ptr;
     xmlNsPtr ns_record;
     WRBUF wr_cdata = 0;
-    int turbo = mt->turbo_format;
+    int turbo = mt->output_format == YAZ_MARC_TMARCXML;
     for (n = mt->nodes; n; n = n->next)
         if (n->which == YAZ_MARC_LEADER)
         {
@@ -883,6 +894,7 @@ int yaz_marc_write_turbo_xml(yaz_marc_t mt, xmlNode **root_ptr,
                char field[10];
                                field[0] = 'c';
                 strncpy(field + 1, n->u.controlfield.tag, 3);
+                field[4] = '\0';
                 ptr = xmlNewTextChild(record_ptr, ns_record,
                                                                          BAD_CAST field,
                                                                          BAD_CAST wrbuf_cstr(wr_cdata));
@@ -1194,8 +1206,12 @@ int yaz_marc_get_read_format(yaz_marc_t mt)
 
 void yaz_marc_set_write_format(yaz_marc_t mt, int format)
 {
-    if (mt)
+    if (mt) {
         mt->output_format = format;
+        // Force using libxml2
+        if (mt->output_format == YAZ_MARC_TMARCXML)
+               mt->write_using_libxml2 = 1;
+    }
 }
 
 int yaz_marc_get_write_format(yaz_marc_t mt)
@@ -1211,8 +1227,7 @@ int yaz_marc_get_write_format(yaz_marc_t mt)
  */
 void yaz_marc_xml(yaz_marc_t mt, int xmlmode)
 {
-    if (mt)
-        mt->output_format = xmlmode;
+       yaz_marc_set_write_format(mt, xmlmode);
 }
 
 
@@ -1324,14 +1339,9 @@ void yaz_marc_write_using_libxml2(yaz_marc_t mt, int enable)
     mt->write_using_libxml2 = enable;
 }
 
-void yaz_marc_write_turbo_format(yaz_marc_t mt, int enable)
-{
-    mt->turbo_format = enable;
-}
-
 int yaz_marc_is_turbo_format(yaz_marc_t mt)
 {
-    return mt->turbo_format;
+    return mt->output_format == YAZ_MARC_TMARCXML;
 }