Added termlist source for data1 system.
[yaz-moved-to-github.git] / retrieval / d1_absyn.c
index 6ff747b..c664825 100644 (file)
@@ -4,7 +4,21 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: d1_absyn.c,v $
- * Revision 1.24  1999-08-27 09:40:32  adam
+ * Revision 1.28  2000-12-05 12:21:45  adam
+ * Added termlist source for data1 system.
+ *
+ * Revision 1.27  1999/12/21 14:16:19  ian
+ * Changed retrieval module to allow data1 trees with no associated absyn.
+ * Also added a simple interface for extracting values from data1 trees using
+ * a string based tagpath.
+ *
+ * Revision 1.26  1999/11/30 13:47:12  adam
+ * Improved installation. Moved header files to include/yaz.
+ *
+ * Revision 1.25  1999/10/21 12:06:29  adam
+ * Retrieval module no longer uses ctype.h - functions.
+ *
+ * Revision 1.24  1999/08/27 09:40:32  adam
  * Renamed logf function to yaz_log. Removed VC++ project files.
  *
  * Revision 1.23  1998/10/15 08:29:16  adam
  *
  */
 
-#include <ctype.h>
 #include <stdio.h>
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include <oid.h>
-#include <log.h>
-#include <data1.h>
+#include <yaz/oid.h>
+#include <yaz/log.h>
+#include <yaz/data1.h>
 
 #define D1_MAX_NESTING  128
 
@@ -256,6 +269,10 @@ data1_element *data1_getelementbytagname (data1_handle dh, data1_absyn *abs,
 {
     data1_element *r;
 
+    /* It's now possible to have a data1 tree with no abstract syntax */
+    if ( !abs )
+        return 0;
+
     if (!parent)
         r = abs->main_elements;
     else
@@ -276,6 +293,11 @@ data1_element *data1_getelementbyname (data1_handle dh, data1_absyn *absyn,
                                       const char *name)
 {
     data1_element *r;
+
+    /* It's now possible to have a data1 tree with no abstract syntax */
+    if ( !absyn )
+        return 0;
+    
     assert (absyn->main_elements);
     for (r = absyn->main_elements; r; r = r->next)
        if (!data1_matchstr(r->name, name))
@@ -286,6 +308,10 @@ data1_element *data1_getelementbyname (data1_handle dh, data1_absyn *absyn,
 
 void fix_element_ref (data1_handle dh, data1_absyn *absyn, data1_element *e)
 {
+    /* It's now possible to have a data1 tree with no abstract syntax */
+    if ( !absyn )
+        return;
+
     for (; e; e = e->next)
     {
        if (!e->sub_name)
@@ -469,6 +495,7 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file)
                do
                {
                    char attname[512], structure[512];
+                   char *source;
                    int r;
                    
                    if (!(r = sscanf(p, "%511[^:,]:%511[^,]", attname,
@@ -494,15 +521,18 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file)
                        fclose(f);
                        return 0;
                    }
+                   if (r == 2 && (source = strchr(structure, ':')))
+                       *source++ = '\0';   /* cut off structure .. */
+                   else
+                       source = "data";    /* ok: default is leaf data */
+                   (*tp)->source = (char *)
+                       nmem_strdup (data1_nmem_get (dh), source);
+
                    if (r < 2) /* is the structure qualified? */
                        (*tp)->structure = "w";
                    else 
-                   {
                        (*tp)->structure = (char *)
-                           nmem_malloc (data1_nmem_get (dh),
-                                        strlen(structure)+1);
-                       strcpy ((*tp)->structure, structure);
-                   }
+                           nmem_strdup (data1_nmem_get (dh), structure);
                    tp = &(*tp)->next;
                }
                while ((p = strchr(p, ',')) && *(++p));