-/* $Id: d1_absyn.c,v 1.15 2004-11-19 10:26:53 heikki Exp $
- Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
- Index Data Aps
+/* $Id: d1_absyn.c,v 1.20 2005-06-23 06:45:46 adam Exp $
+ Copyright (C) 1995-2005
+ Index Data ApS
This file is part of the Zebra server.
#include <stdlib.h>
#include <string.h>
+#include <yaz/log.h>
#include <yaz/oid.h>
-#include <yaz/ylog.h>
#include <idzebra/data1.h>
#include <zebra_xpath.h>
#include <d1_absyn.h>
nmem_malloc(data1_nmem_get(dh), sizeof(**tp));
(*tp)->next = 0;
+#if NATTR
+ (*tp)->index_name = nmem_strdup(data1_nmem_get(dh), element_name);
+ if (*attname == '!' && xpelement)
+ (*tp)->index_name = 0;
+#else
if (!xpelement) {
if (*attname == '!')
strcpy(attname, element_name);
}
- if (!((*tp)->att = data1_getattbyname(dh, res->attset,
- attname))) {
+ if (!((*tp)->att = data1_getattbyname(dh, res->attset, attname)))
+ {
if ((!xpelement) || (*attname != '!')) {
yaz_log(YLOG_WARN,
"%s:%d: Couldn't find att '%s' in attset",
(*tp)->att = 0;
}
}
-
+#endif
if (r == 2 && (source = strchr(structure, ':')))
*source++ = '\0'; /* cut off structure .. */
else
return 0;
}
+/* quinn
+ * Converts a 'melm' field[$subfield] pattern to a simple xpath
+ */
+static int melm2xpath(char *melm, char *buf)
+{
+ char *dollar;
+ char *field = melm;
+ char *subfield;
+ char *fieldtype;
+ if ((dollar = strchr(melm, '$'))) {
+ *dollar = '\0';
+ subfield = ++dollar;
+ } else
+ subfield = "";
+ if (field[0] == '0' && field[1] == '0')
+ fieldtype = "controlfield";
+ else
+ fieldtype = "datafield";
+ sprintf(buf, "/*/%s[@tag=\"%s\"]", fieldtype, field);
+ if (*subfield)
+ sprintf(buf + strlen(buf), "/subfield[@code=\"%s\"]", subfield);
+ else if (field[0] != '0' || field[1] != '0')
+ strcat(buf, "/subfield");
+ yaz_log(YLOG_DEBUG, "Created xpath: '%s'", buf);
+ return 0;
+}
+
const char *data1_systag_lookup(data1_absyn *absyn, const char *tag,
const char *default_value)
{
pop, 2003-01-17
*/
- else if (!strcmp(cmd, "xelm")) {
+ else if (!strcmp(cmd, "xelm") || !strcmp(cmd, "melm")) {
int i;
char *p, *xpath_expr, *termlists;
const char *regexp;
struct DFA *dfa = dfa = dfa_init();
data1_termlist **tp;
+ char melm_xpath[128];
if (argc < 3)
{
yaz_log(YLOG_WARN, "%s:%d: Bad # of args to xelm", file, lineno);
continue;
}
- xpath_expr = argv[1];
+
+ if (!strcmp(cmd, "melm")) {
+ if (melm2xpath(argv[1], melm_xpath) < 0)
+ continue;
+ xpath_expr = melm_xpath;
+ } else {
+ xpath_expr = argv[1];
+ }
termlists = argv[2];
regexp = mk_xpath_regexp(dh, xpath_expr);
i = dfa_parse (dfa, ®exp);
}
else if (!strcmp(cmd, "attset"))
{
+#if NATTR
+ yaz_log(YLOG_WARN, "%s:%d: attset obsolete", file, lineno);
+#else
char *name;
data1_attset *attset;
(*attset_childp)->child = attset;
(*attset_childp)->next = 0;
attset_childp = &(*attset_childp)->next;
+#endif
}
else if (!strcmp(cmd, "tagset"))
{