Fix xpath indexing for non-existent attribute value
[idzebra-moved-to-github.git] / recctrl / recgrs.c
index 8d9e3d5..12ad348 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: recgrs.c,v 1.61 2002-08-23 14:29:58 adam Exp $
+/* $Id: recgrs.c,v 1.64 2002-08-29 15:10:47 adam Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
    Index Data Aps
 
@@ -20,8 +20,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 02111-1307, USA.
 */
 
-
-
 #include <stdio.h>
 #include <assert.h>
 #include <sys/types.h>
@@ -101,7 +99,7 @@ static void *grs_init(RecType recType)
     grs_add_handler (h, recTypeGrs_tcl);
 #endif
     grs_add_handler (h, recTypeGrs_marc);
-#if YAZ_HAVE_EXPAT
+#if HAVE_EXPAT_H
     grs_add_handler (h, recTypeGrs_xml);
 #endif
     return h;
@@ -227,9 +225,10 @@ static void index_xpath (data1_node *n, struct recExtractCtrl *p,
                 for (xp = n->u.tag.attributes; xp; xp = xp->next)
                 {
                     char attr_tag_path_full[1024];
+                    int int_len = flen;
                     
                     sprintf (attr_tag_path_full, "@%s/%.*s",
-                             xp->name, flen, tag_path_full);
+                             xp->name, int_len, tag_path_full);
 
                     wrd->reg_type = '0';
                     wrd->attrUse = 1;
@@ -237,12 +236,14 @@ static void index_xpath (data1_node *n, struct recExtractCtrl *p,
                     wrd->length = strlen(attr_tag_path_full);
                     (*p->tokenAdd)(wrd);
                     
-                    wrd->attrUse = 1015;
-                    wrd->reg_type = 'w';
-                    wrd->string = xp->value;
-                    wrd->length = strlen(xp->value);
-                    
-                    (*p->tokenAdd)(wrd);
+                   if (xp->value)
+                   {
+                        wrd->attrUse = 1015;
+                        wrd->reg_type = 'w';
+                        wrd->string = xp->value;
+                        wrd->length = strlen(xp->value);
+                        (*p->tokenAdd)(wrd);
+                    }
                     
                     wrd->reg_type = '0';
                     wrd->attrUse = 2;
@@ -472,7 +473,7 @@ static int grs_extract_sub(struct grs_handlers *h, struct recExtractCtrl *p,
     gri.dh = p->dh;
 
     if (read_grs_type (h, &gri, p->subType, &n))
-       return RECCTRL_EXTRACT_ERROR;
+       return RECCTRL_EXTRACT_ERROR_NO_SUCH_FILTER;
     if (!n)
         return RECCTRL_EXTRACT_EOF;
     oe.proto = PROTO_Z3950;
@@ -499,7 +500,7 @@ static int grs_extract_sub(struct grs_handlers *h, struct recExtractCtrl *p,
     if (dumpkeys(n, p, 0, &wrd) < 0)
     {
        data1_free_tree(p->dh, n);
-       return RECCTRL_EXTRACT_ERROR;
+       return RECCTRL_EXTRACT_ERROR_GENERIC;
     }
     data1_free_tree(p->dh, n);
     return RECCTRL_EXTRACT_OK;
@@ -655,7 +656,7 @@ static int grs_retrieve(void *clientData, struct recRetrieveCtrl *p)
     /* ensure our data1 tree is UTF-8 */
     data1_iconv (p->dh, mem, node, "UTF-8", data1_get_encoding(p->dh, node));
 
-#if 0
+#if 1
     data1_pr_tree (p->dh, node, stdout);
 #endif
     top = data1_get_root_tag (p->dh, node);