X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=data1%2Fd1_absyn.c;h=45724a9688537de0934b70217c3ac089830c5dbd;hb=9eebf93dc2525854867cbc43920ea8ba4a199ab5;hp=45620d5791ecdb03d61ef00d3f9043ed518b23ef;hpb=4eb3b54bb2ca9af74f39f000d3d40dba99ded887;p=idzebra-moved-to-github.git diff --git a/data1/d1_absyn.c b/data1/d1_absyn.c index 45620d5..45724a9 100644 --- a/data1/d1_absyn.c +++ b/data1/d1_absyn.c @@ -1,6 +1,6 @@ -/* $Id: d1_absyn.c,v 1.16 2004-12-13 20:51:27 adam 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. @@ -561,12 +561,17 @@ static int parse_termlists (data1_handle dh, data1_termlist ***tpp, 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", @@ -576,7 +581,7 @@ static int parse_termlists (data1_handle dh, data1_termlist ***tpp, (*tp)->att = 0; } } - +#endif if (r == 2 && (source = strchr(structure, ':'))) *source++ = '\0'; /* cut off structure .. */ else @@ -596,6 +601,33 @@ static int parse_termlists (data1_handle dh, data1_termlist ***tpp, 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) { @@ -843,20 +875,28 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file, 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); @@ -1002,6 +1042,9 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file, } else if (!strcmp(cmd, "attset")) { +#if NATTR + yaz_log(YLOG_WARN, "%s:%d: attset obsolete", file, lineno); +#else char *name; data1_attset *attset; @@ -1023,6 +1066,7 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file, (*attset_childp)->child = attset; (*attset_childp)->next = 0; attset_childp = &(*attset_childp)->next; +#endif } else if (!strcmp(cmd, "tagset")) {