Character set negotiation updates
[yaz-moved-to-github.git] / retrieval / d1_absyn.c
index 916adc4..9e4d41b 100644 (file)
@@ -1,10 +1,19 @@
 /*
- * Copyright (c) 1995-1999, Index Data.
+ * Copyright (c) 1995-2000, Index Data.
  * See the file LICENSE for details.
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: d1_absyn.c,v $
- * Revision 1.29  2000-12-05 14:34:49  adam
+ * Revision 1.32  2002-07-25 12:52:53  adam
+ * Character set negotiation updates
+ *
+ * Revision 1.31  2002/04/04 20:49:46  adam
+ * New functions yaz_is_abspath, yaz_path_fopen_base
+ *
+ * Revision 1.30  2000/12/05 19:07:24  adam
+ * Fixed problem with element level in reading of abstract syntax.
+ *
+ * Revision 1.29  2000/12/05 14:34:49  adam
  * Fixed bug with termlists (introduced by previous commit).
  *
  * Revision 1.28  2000/12/05 12:21:45  adam
@@ -413,7 +422,7 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file)
     int argc;
     char *argv[50], line[512];
 
-    if (!(f = yaz_path_fopen(data1_get_tabpath (dh), file, "r")))
+    if (!(f = data1_path_fopen(dh, file, "r")))
     {
        yaz_log(LOG_WARN|LOG_ERRNO, "Couldn't open %s", file);
        return 0;
@@ -423,6 +432,7 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file)
     res->name = 0;
     res->reference = VAL_NONE;
     res->tagset = 0;
+    res->encoding = 0;
     tagset_childp = &res->tagset;
 
     res->attset = data1_empty_attset (dh);
@@ -472,7 +482,7 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file)
                ppl[level] = &cur_elements->elements;
             }
            p = path;
-           for (i = 0;; i++)
+           for (i = 1;; i++)
            {
                char *e;
 
@@ -481,14 +491,14 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file)
                else
                    break;
            }
-           if (i > level + 1)
+           if (i > level+1)
            {
                yaz_log(LOG_WARN, "%s:%d: Bad level increase", file, lineno);
                fclose(f);
                return 0;
            }
            level = i;
-           new_element = *ppl[level] = (data1_element *)
+           new_element = *ppl[level-1] = (data1_element *)
                nmem_malloc(data1_nmem_get(dh), sizeof(*new_element));
            new_element->next = new_element->children = 0;
            new_element->tag = 0;
@@ -496,8 +506,8 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file)
            new_element->sub_name = 0;
            
            tp = &new_element->termlists;
-           ppl[level] = &new_element->next;
-           ppl[level+1] = &new_element->children;
+           ppl[level-1] = &new_element->next;
+           ppl[level] = &new_element->children;
            
            /* consider subtree (if any) ... */
            if ((sub_p = strchr (p, ':')) && sub_p[1])
@@ -763,6 +773,16 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file)
            }
            marcp = &(*marcp)->next;
        }
+       else if (!strcmp(cmd, "encoding"))
+       {
+           if (argc != 2)
+           {
+               yaz_log(LOG_WARN, "%s:%d: Bad # or args for encoding",
+                    file, lineno);
+               continue;
+           }
+            res->encoding = nmem_strdup (data1_nmem_get(dh), argv[1]);
+       }
        else
        {
            yaz_log(LOG_WARN, "%s:%d: Unknown directive '%s'", file, lineno, cmd);