From: Sebastian Hammer Date: Tue, 4 Jan 2005 16:28:34 +0000 (+0000) Subject: Added support for 'melm' directive X-Git-Tag: snippet.version.1~191 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=bc69879777443f6a65ede7dea9d46374de1c0bcd;p=idzebra-moved-to-github.git Added support for 'melm' directive --- diff --git a/data1/d1_absyn.c b/data1/d1_absyn.c index 45620d5..2165bc5 100644 --- a/data1/d1_absyn.c +++ b/data1/d1_absyn.c @@ -1,4 +1,4 @@ -/* $Id: d1_absyn.c,v 1.16 2004-12-13 20:51:27 adam Exp $ +/* $Id: d1_absyn.c,v 1.17 2005-01-04 16:28:34 quinn Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -596,6 +596,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 = index(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 +870,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);