Added body-of-text to BIB-1 ANY and the WAIS profile
[yaz-moved-to-github.git] / retrieval / d1_absyn.c
index 1322132..92d5f1c 100644 (file)
@@ -4,7 +4,19 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: d1_absyn.c,v $
- * Revision 1.2  1995-11-01 13:54:44  quinn
+ * Revision 1.6  1996-05-31 13:52:21  quinn
+ * Fixed uninitialized variable for local tags in abstract syntax.
+ *
+ * Revision 1.5  1996/05/09  07:27:43  quinn
+ * Multiple local attributes values supported.
+ *
+ * Revision 1.4  1996/05/01  12:45:28  quinn
+ * Support use of local tag names in abs file.
+ *
+ * Revision 1.3  1995/11/01  16:34:55  quinn
+ * Making data1 look for tables in data1_tabpath
+ *
+ * Revision 1.2  1995/11/01  13:54:44  quinn
  * Minor adjustments
  *
  * Revision 1.1  1995/11/01  11:56:06  quinn
@@ -22,6 +34,7 @@
 #include <xmalloc.h>
 #include <oid.h>
 #include <log.h>
+#include <tpath.h>
 
 #include <data1.h>
 
@@ -109,7 +122,7 @@ data1_absyn *data1_read_absyn(char *file)
     data1_marctab **marcp;
     int level = 0;
 
-    if (!(f = fopen(file, "r")))
+    if (!(f = yaz_path_fopen(data1_tabpath, file, "r")))
     {
        logf(LOG_WARN|LOG_ERRNO, "%s", file);
        return 0;
@@ -151,10 +164,11 @@ data1_absyn *data1_read_absyn(char *file)
        {
            data1_element *new;
            int i;
-           char path[512], name[512], att[512], *p;
+           char path[512], name[512], termlists[512], *p;
            int type, value;
+           data1_termlist **tp;
 
-           if (sscanf(args, "%s %s %s", path, name, att) < 3)
+           if (sscanf(args, "%s %s %s", path, name, termlists) < 3)
            {
                logf(LOG_WARN, "Bad # of args to elm in %s: '%s'", 
                    file, args);
@@ -180,33 +194,54 @@ data1_absyn *data1_read_absyn(char *file)
            level = i;
            if (!(new = *ppl[level] = xmalloc(sizeof(*new))))
                abort;
-           new ->next = new->children = 0;
+           new->next = new->children = 0;
+           new->tag = 0;
+           new->termlists = 0;
+           tp = &new->termlists;
            ppl[level] = &new->next;
            ppl[level+1] = &new->children;
 
-           if (sscanf(p, "(%d,%d)", &type, &value) < 2)
+           /* well-defined tag */
+           if (sscanf(p, "(%d,%d)", &type, &value) == 2)
            {
-               logf(LOG_WARN, "Malformed element '%s' in %s", p, file);
-               fclose(f);
-               return 0;
+               if (!res->tagset)
+               {
+                   logf(LOG_WARN, "No tagset loaded in %s", file);
+                   fclose(f);
+                   return 0;
+               }
+               if (!(new->tag = data1_gettagbynum(res->tagset, type, value)))
+               {
+                   logf(LOG_WARN, "Couldn't find tag %s in tagset in %s",
+                       p, file);
+                   fclose(f);
+                   return 0;
+               }
            }
-           if (!res->tagset)
+           /* private tag */
+           else if (*p)
            {
-               logf(LOG_WARN, "No tagset loaded in %s", file);
-               fclose(f);
-               return 0;
+               data1_tag *nt = new->tag = xmalloc(sizeof(*new->tag));
+               nt->which = DATA1T_string;
+               nt->value.string = xstrdup(p);
+               nt->names = xmalloc(sizeof(*new->tag->names));
+               nt->names->name = nt->value.string;
+               nt->names->next = 0;
+               nt->kind = DATA1K_string;
+               nt->next = 0;
+               nt->tagset = 0;
            }
-           if (!(new->tag = data1_gettagbynum(res->tagset, type, value)))
+           else
            {
-               logf(LOG_WARN, "Couldn't find tag %s in tagset in %s",
-                   p, file);
+               logf(LOG_WARN, "Bad element is %s", file);
                fclose(f);
                return 0;
            }
-           if (*att == '!')
-               strcpy(att, name);
-           if (*att == '-')
-               new->att = 0;
+
+           /* parse termList definitions */
+           p = termlists;
+           if (*p == '-')
+               new->termlists = 0;
            else
            {
                if (!res->attset)
@@ -215,16 +250,44 @@ data1_absyn *data1_read_absyn(char *file)
                    fclose(f);
                    return 0;
                }
-               if (!(new->att = data1_getattbyname(res->attset, att)))
+               do
                {
-                   logf(LOG_WARN, "Couldn't find att '%s' in attset", att);
-                   fclose(f);
-                   return 0;
+                   char attname[512], structure[512];
+                   int r;
+
+                   if (!(r = sscanf(p, "%511[^:,]:%511[^,]", attname,
+                       structure)))
+                   {
+                       logf(LOG_WARN, "Syntax error in termlistspec in %s",
+                           file);
+                       fclose(f);
+                       return 0;
+                   }
+                   if (*attname == '!')
+                       strcpy(attname, name);
+                   *tp = xmalloc(sizeof(**tp));
+                   if (!((*tp)->att = data1_getattbyname(res->attset,
+                       attname)))
+                   {
+                       logf(LOG_WARN, "Couldn't find att '%s' in attset",
+                           attname);
+                       fclose(f);
+                       return 0;
+                   }
+                   if (r < 2) /* is the structure qualified? */
+                       (*tp)->structure = DATA1S_word;
+                   else if (!data1_matchstr(structure, "w"))
+                       (*tp)->structure = DATA1S_word;
+                   else if (!data1_matchstr(structure, "p"))
+                       (*tp)->structure = DATA1S_phrase;
+
+                   (*tp)->next = 0;
+                   tp = &(*tp)->next;
                }
+               while ((p = strchr(p, ',')) && *(++p));
            }
-           if (!(new->name = xmalloc(strlen(name)+1)))
-               abort();
-           strcpy(new->name, name);
+
+           new->name = xstrdup(name);
        }
        else if (!strcmp(cmd, "name"))
        {