+ /* 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)
+ {
+ if (e->children)
+ fix_element_ref (dh, absyn, e->children);
+ }
+ else
+ {
+ data1_sub_elements *sub_e = absyn->sub_elements;
+ while (sub_e && strcmp (e->sub_name, sub_e->name))
+ sub_e = sub_e->next;
+ if (sub_e)
+ e->children = sub_e->elements;
+ else
+ yaz_log (LOG_WARN, "Unresolved reference to sub-elements %s",
+ e->sub_name);
+ }
+ }
+}
+
+
+static int parse_termlists (data1_handle dh, data1_termlist ***tpp,
+ char *p, const char *file, int lineno,
+ const char *element_name, data1_absyn *res)
+{
+ data1_termlist **tp = *tpp;
+ do
+ {
+ char attname[512], structure[512];
+ char *source;
+ int r;
+
+ if (!(r = sscanf(p, "%511[^:,]:%511[^,]", attname,
+ structure)))
+ {
+ yaz_log(LOG_WARN,
+ "%s:%d: Syntax error in termlistspec '%s'",
+ file, lineno, p);
+ return -1;
+ }
+ if (*attname == '!')
+ strcpy(attname, element_name);
+ *tp = (data1_termlist *)
+ nmem_malloc(data1_nmem_get(dh), sizeof(**tp));
+ (*tp)->next = 0;
+ if (!((*tp)->att = data1_getattbyname(dh, res->attset,
+ attname)))
+ {
+ yaz_log(LOG_WARN,
+ "%s:%d: Couldn't find att '%s' in attset",
+ file, lineno, attname);
+ return -1;
+ }
+ 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_strdup (data1_nmem_get (dh), structure);
+ tp = &(*tp)->next;
+ }
+ while ((p = strchr(p, ',')) && *(++p));
+ *tpp = tp;
+ return 0;
+}
+
+data1_absyn *data1_read_absyn (data1_handle dh, const char *file,
+ int file_must_exist)
+{
+ data1_sub_elements *cur_elements = NULL;