Bump year. Change Aps->ApS
[idzebra-moved-to-github.git] / data1 / d1_absyn.c
index 45620d5..e380610 100644 (file)
@@ -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.19 2005-01-15 19:38:18 adam Exp $
+   Copyright (C) 1995-2005
+   Index Data ApS
 
 This file is part of the Zebra server.
 
@@ -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 = 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 +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, &regexp);