Fix grs.sgml to use off_t rather than int for file offsets
[idzebra-moved-to-github.git] / data1 / d1_read.c
index 742e170..3f87878 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: d1_read.c,v 1.9 2004-08-04 08:35:22 adam Exp $
+/* $Id: d1_read.c,v 1.8.2.2 2005-04-23 16:31:54 adam Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
@@ -470,8 +470,8 @@ data1_node *data1_add_taggeddata (data1_handle dh, data1_node *root,
     return data1_add_insert_taggeddata (dh, at, tagname, m, 1, 0);
 }
 
-data1_node *data1_mk_tag_data_zint (data1_handle dh, data1_node *at,
-                                   const char *tag, zint num,
+data1_node *data1_mk_tag_data_int (data1_handle dh, data1_node *at,
+                                   const char *tag, int num,
                                    NMEM nmem)
 {
     data1_node *node_data;
@@ -481,18 +481,11 @@ data1_node *data1_mk_tag_data_zint (data1_handle dh, data1_node *at,
        return 0;
     node_data->u.data.what = DATA1I_num;
     node_data->u.data.data = node_data->lbuf;
-    sprintf (node_data->u.data.data, ZINT_FORMAT, num);
+    sprintf (node_data->u.data.data, "%d", num);
     node_data->u.data.len = strlen (node_data->u.data.data);
     return node_data;
 }
 
-data1_node *data1_mk_tag_data_int (data1_handle dh, data1_node *at,
-                                   const char *tag, int num,
-                                   NMEM nmem)
-{
-    return data1_mk_tag_data_zint(dh, at, tag, num, nmem);
-}
-
 data1_node *data1_mk_tag_data_oid (data1_handle dh, data1_node *at,
                                    const char *tag, Odr_oid *oid,
                                    NMEM nmem)
@@ -699,8 +692,7 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m,
        {
            data1_xattr *xattr;
 
-           char tag[64];
-           char args[256];
+           char tag[256];
            int null_tag = 0;
            int end_tag = 0;
            size_t i = 0;
@@ -711,6 +703,33 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m,
                end_tag = 1;
                c = ampr (get_byte, fh, &amp);
            }
+           else if (amp == 0 && c == '?')
+           {
+               int quote_mode = 0;
+               while ((c = ampr(get_byte, fh, &amp)))
+               {
+                   if (amp)
+                       continue;
+                   if (quote_mode == 0)
+                   {
+                       if (c == '"')
+                           quote_mode = c;
+                       else if (c == '\'')
+                           quote_mode = c;
+                       else if (c == '>')
+                       {
+                           c = ampr(get_byte, fh, &amp);
+                           break;
+                       }
+                   }
+                   else 
+                   {
+                       if (amp == 0 && c == quote_mode)
+                           quote_mode = 0;
+                   }
+               }
+               continue;
+           }
            else if (amp == 0 && c == '!')
            {
                 int c0, amp0;
@@ -778,7 +797,6 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m,
            }
            tag[i] = '\0';
            xattr = data1_read_xattr (dh, m, get_byte, fh, wrbuf, &c, &amp);
-           args[0] = '\0';
            if (amp == 0 && c == '/')
            {    /* <tag attrs/> or <tag/> */
                null_tag = 1;
@@ -831,17 +849,18 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m,
                 }
                continue;
            }   
-           else if (!strcmp(tag, "var"))
+           else if (!strcmp(tag, "var") 
+                    && xattr && xattr->next && xattr->next->next
+                    && xattr->value == 0 
+                    && xattr->next->value == 0
+                    && xattr->next->next->value == 0)
            {
-               char tclass[DATA1_MAX_SYMBOL], type[DATA1_MAX_SYMBOL];
+               /* <var class type value> */
+               const char *tclass = xattr->name;
+               const char *type = xattr->next->name;
+               const char *value = xattr->next->name;
                data1_vartype *tp;
-               int val_offset;
-               
-               if (sscanf(args, "%s %s %n", tclass, type, &val_offset) != 2)
-               {
-                   yaz_log(LOG_WARN, "Malformed variant triple at '%s'", tag);
-                   continue;
-               }
+
                if (!(tp =
                      data1_getvartypebyct(dh,
                                           parent->root->u.root.absyn->varset,
@@ -871,7 +890,7 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m,
                    res = data1_mk_node2 (dh, m, DATA1N_variant, parent);
                    res->u.variant.type = tp;
                    res->u.variant.value =
-                       data1_insert_string (dh, res, m, args + val_offset);
+                       data1_insert_string (dh, res, m, value);
                }
            }
            else 
@@ -1112,7 +1131,10 @@ int data1_iconv (data1_handle dh, NMEM m, data1_node *n,
         WRBUF wrbuf = wrbuf_alloc();
         yaz_iconv_t t = yaz_iconv_open (tocode, fromcode);
         if (!t)
+       {
+            wrbuf_free(wrbuf, 1);
             return -1;
+       }
         data1_iconv_s (dh, m, n, t, wrbuf, tocode);
         yaz_iconv_close (t);
         wrbuf_free (wrbuf, 1);