* Sebastian Hammer, Adam Dickmeiss
*
* $Log: d1_absyn.c,v $
- * Revision 1.26 1999-11-30 13:47:12 adam
+ * 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
+ * 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
{
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
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))
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)
}
}
+
+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;
+/*
+ fclose(f);
+ return 0;
+*/
+ }
+ 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;
+/*
+ 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_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)
{
data1_sub_elements *cur_elements = NULL;
}
/* parse termList definitions */
p = termlists;
- if (*p == '-')
- new_element->termlists = 0;
- else
+ if (*p != '-')
{
assert (res->attset);
- do
+
+ if (parse_termlists (dh, &tp, p, file, lineno, name, res))
{
- char attname[512], structure[512];
- int r;
-
- if (!(r = sscanf(p, "%511[^:,]:%511[^,]", attname,
- structure)))
- {
- yaz_log(LOG_WARN,
- "%s:%d: Syntax error in termlistspec '%s'",
- file, lineno, p);
- fclose(f);
- return 0;
- }
- if (*attname == '!')
- strcpy(attname, 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);
- fclose(f);
- return 0;
- }
- 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);
- }
- tp = &(*tp)->next;
+ fclose (f);
+ return 0;
}
- while ((p = strchr(p, ',')) && *(++p));
*tp = all; /* append any ALL entries to the list */
}
new_element->name = nmem_strdup(data1_nmem_get (dh), name);
}
else if (!strcmp(cmd, "all"))
{
- char *p;
data1_termlist **tp = &all;
-
if (all)
{
yaz_log(LOG_WARN, "%s:%d: Too many 'all' directives - ignored",
file, lineno);
continue;
}
-
if (argc != 2)
{
yaz_log(LOG_WARN, "%s:%d: Bad # of args to 'all' directive",
file, lineno);
continue;
}
- p = argv[1];
- assert (res->attset);
- do
+ if (parse_termlists (dh, &tp, argv[1], file, lineno, 0, res))
{
- char attname[512], structure[512];
- int r;
-
- if (!(r = sscanf(p, "%511[^:,]:%511[^,]", attname,
- structure)))
- {
- yaz_log(LOG_WARN, "%s:%d: Syntax error in termlistspec",
- file, lineno);
- fclose(f);
- return 0;
- }
- *tp = (data1_termlist *)
- nmem_malloc(data1_nmem_get(dh), sizeof(**tp));
- 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);
- fclose(f);
- return 0;
- }
- 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);
- }
- (*tp)->next = 0;
- tp = &(*tp)->next;
+ fclose (f);
+ return 0;
}
- while ((p = strchr(p, ',')) && *(++p));
}
else if (!strcmp(cmd, "name"))
{