Implemented data1_set_tabpath and data1_get_tabpath.
[yaz-moved-to-github.git] / retrieval / d1_read.c
index ba2c6e4..a430565 100644 (file)
@@ -4,7 +4,23 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: d1_read.c,v $
- * Revision 1.8  1995-12-15 16:20:41  quinn
+ * Revision 1.13  1996-10-29 13:35:38  adam
+ * Implemented data1_set_tabpath and data1_get_tabpath.
+ *
+ * Revision 1.12  1996/10/11 10:35:38  adam
+ * Fixed a bug that caused data1_read_node to core dump when no abstract
+ * syntax was defined in a "sgml"-record.
+ *
+ * Revision 1.11  1996/07/06 19:58:35  quinn
+ * System headerfiles gathered in yconfig
+ *
+ * Revision 1.10  1996/01/19  15:41:47  quinn
+ * Fixed uninitialized boolean.
+ *
+ * Revision 1.9  1996/01/17  14:52:47  adam
+ * Changed prototype for reader function parsed to data1_read_record.
+ *
+ * Revision 1.8  1995/12/15  16:20:41  quinn
  * Added formatted text.
  *
  * Revision 1.7  1995/12/13  13:44:32  quinn
 
 char *data1_tabpath = 0; /* global path for tables */
 
-void data1_set_tabpath(char *p)
-{ data1_tabpath = p; }
+void data1_set_tabpath(const char *p)
+{
+    if (data1_tabpath)
+    {
+        xfree (data1_tabpath);
+        data1_tabpath = NULL;
+    }
+    if (p)
+    {
+        data1_tabpath = xmalloc (strlen(p)+1);
+        strcpy (data1_tabpath, p);
+    }
+}
+
+const char *data1_get_tabpath (void)
+{
+    return data1_tabpath;
+}
 
 #if 0
 static data1_node *freelist = 0;
@@ -164,6 +196,7 @@ data1_node *data1_insert_taggeddata(data1_node *root, data1_node *at,
     tagn->u.tag.node_selected = 0;
     tagn->u.tag.make_variantlist = 0;
     tagn->u.tag.no_data_requested = 0;
+    tagn->u.tag.get_bytes = -1;
     if (!(tagn->u.tag.element = data1_getelementbytagname(root->u.root.absyn,
        0, tagname)))
        return 0;
@@ -172,6 +205,7 @@ data1_node *data1_insert_taggeddata(data1_node *root, data1_node *at,
     datn->parent = tagn;
     datn->root = root;
     datn->which = DATA1N_data;
+    datn->u.data.formatted_text = 0;
     tagn->next = at->child;
     tagn->parent = at;
     at->child = tagn;
@@ -353,6 +387,7 @@ data1_node *data1_read_node(char **buf, data1_node *parent, int *line,
            res->u.tag.node_selected = 0;
            res->u.tag.make_variantlist = 0;
            res->u.tag.no_data_requested = 0;
+           res->u.tag.get_bytes = -1;
            res->root = parent->root;
            *buf = t + 1;
        }
@@ -379,6 +414,8 @@ data1_node *data1_read_node(char **buf, data1_node *parent, int *line,
        data1_node *partag = get_parent_tag(parent);
 #endif
 
+        if (!parent)      /* abort if abstract syntax is undefined */
+            return 0;
        /* Determine length and remove newlines/extra blanks */
        while (**buf && **buf != '<')
        {
@@ -412,7 +449,8 @@ data1_node *data1_read_node(char **buf, data1_node *parent, int *line,
 /*
  * Read a record in the native syntax.
  */
-data1_node *data1_read_record(int (*rf)(int, char *, size_t), int fd, NMEM m)
+data1_node *data1_read_record(int (*rf)(void *, char *, size_t), void *fh,
+                              NMEM m)
 {
     static char *buf = 0;
     char *bp;
@@ -427,7 +465,7 @@ data1_node *data1_read_record(int (*rf)(int, char *, size_t), int fd, NMEM m)
     {
        if (rd + 4096 > size && !(buf =xrealloc(buf, size *= 2)))
            abort();
-       if ((res = (*rf)(fd, buf + rd, 4096)) <= 0)
+       if ((res = (*rf)(fh, buf + rd, 4096)) <= 0)
        {
            if (!res)
            {