Put local variables footer in all c, h files.
[idzebra-moved-to-github.git] / data1 / d1_read.c
index 742e170..f5aa467 100644 (file)
@@ -1,6 +1,6 @@
-/* $Id: d1_read.c,v 1.9 2004-08-04 08:35:22 adam Exp $
-   Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
-   Index Data Aps
+/* $Id: d1_read.c,v 1.18 2006-05-10 08:13:18 adam Exp $
+   Copyright (C) 1995-2005
+   Index Data ApS
 
 This file is part of the Zebra server.
 
@@ -29,10 +29,8 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <stdio.h>
 #include <stdlib.h>
 
-#include <yaz/xmalloc.h>
 #include <yaz/yaz-util.h>
-#include <yaz/log.h>
-#include <data1.h>
+#include <d1_absyn.h>
 
 data1_node *data1_get_root_tag (data1_handle dh, data1_node *n)
 {
@@ -118,7 +116,7 @@ static void data1_init_node (data1_handle dh, data1_node *r, int type)
         r->u.preprocess.attributes = 0;
         break;
     default:
-       logf (LOG_WARN, "data_mk_node_type. bad type = %d\n", type);
+       yaz_log (YLOG_WARN, "data_mk_node_type. bad type = %d\n", type);
     }
 }
 
@@ -194,7 +192,7 @@ data1_node *data1_mk_root (data1_handle dh, NMEM nmem, const char *name)
     data1_node *res;
     if (!absyn)
     {
-        yaz_log(LOG_WARN, "Unable to acquire abstract syntax " "for '%s'",
+        yaz_log(YLOG_WARN, "Unable to acquire abstract syntax " "for '%s'",
                 name); 
         /* It's now OK for a record not to have an absyn */
     }
@@ -699,8 +697,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 +708,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 +802,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;
@@ -786,7 +809,7 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m,
            }
            if (amp || c != '>')
            {
-               yaz_log(LOG_WARN, "d1: %d: Malformed tag", line);
+               yaz_log(YLOG_WARN, "d1: %d: Malformed tag", line);
                return 0;
            }
            else
@@ -814,7 +837,7 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m,
                    }
                    if (i != level)
                    {
-                       yaz_log (LOG_WARN, "%d: no begin tag for %s",
+                       yaz_log (YLOG_WARN, "%d: no begin tag for %s",
                                 line, tag);
                        break;
                    }
@@ -831,17 +854,20 @@ 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;
-               }
+               yaz_log(YLOG_LOG, "Variant class=%s type=%s value=%s",
+                       tclass, type, value);
                if (!(tp =
                      data1_getvartypebyct(dh,
                                           parent->root->u.root.absyn->varset,
@@ -871,7 +897,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 
@@ -1110,12 +1136,15 @@ int data1_iconv (data1_handle dh, NMEM m, data1_node *n,
     if (yaz_matchstr (tocode, fromcode))
     {
         WRBUF wrbuf = wrbuf_alloc();
-        yaz_iconv_t t = yaz_iconv_open (tocode, fromcode);
+        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);
+       }
+        data1_iconv_s(dh, m, n, t, wrbuf, tocode);
+        yaz_iconv_close(t);
+        wrbuf_free(wrbuf, 1);
     }
     return 0;
 }
@@ -1149,3 +1178,11 @@ void data1_concat_text(data1_handle dh, NMEM m, data1_node *n)
         data1_concat_text(dh, m, n->child);
     }
 }
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+