Allow use of string attributes for regular attribute sets
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 26 May 2004 13:52:25 +0000 (13:52 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 26 May 2004 13:52:25 +0000 (13:52 +0000)
NEWS
index/attribute.c
index/index.h
index/zrpn.c

diff --git a/NEWS b/NEWS
index 7cc854c..fa00adc 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,8 @@
 
+Allow use of string use attributes for regular attribute sets. The
+name matches the name given in the attribute set file. All strings
+starting with / are considered X-Path as usual.
+
 Fixed bug in grs.regx. filter . 'end element' could pop off top tag
 element for XML tree. It may only pop off if -record is given.
 
index 11914bd..22bba54 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: attribute.c,v 1.14 2002-08-02 19:26:55 adam Exp $
+/* $Id: attribute.c,v 1.15 2004-05-26 13:52:25 adam Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
    Index Data Aps
 
@@ -29,23 +29,26 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <zebrautl.h>
 #include "index.h"
 
-static data1_att *getatt(data1_attset *p, int att)
+static data1_att *getatt(data1_attset *p, int att, const char *sattr)
 {
     data1_att *a;
     data1_attset_child *c;
 
     /* scan local set */
     for (a = p->atts; a; a = a->next)
-       if (a->value == att)
+       if (sattr && !yaz_matchstr(sattr, a->name))
+           return a;
+       else if (a->value == att)
            return a;
     /* scan included sets */
     for (c = p->children; c; c = c->next)
-       if ((a = getatt(c->child, att)))
+       if ((a = getatt(c->child, att, sattr)))
            return a;
     return 0;
 }
 
-int att_getentbyatt(ZebraHandle zi, attent *res, oid_value set, int att)
+int att_getentbyatt(ZebraHandle zi, attent *res, oid_value set, int att,
+               const char *sattr)
 {
     data1_att *r;
     data1_attset *p;
@@ -57,7 +60,7 @@ int att_getentbyatt(ZebraHandle zi, attent *res, oid_value set, int att)
     }
     if (!p)
        return -2;
-    if (!(r = getatt(p, att)))
+    if (!(r = getatt(p, att, sattr)))
        return -1;
     res->attset_ordinal = r->parent->reference;
     res->local_attributes = r->locals;
index 35abd54..7b7a5d7 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: index.h,v 1.105 2004-03-29 15:48:14 adam Exp $
+/* $Id: index.h,v 1.106 2004-05-26 13:52:25 adam Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
    Index Data Aps
 
@@ -409,7 +409,8 @@ void zebraRankInstall (struct zebra_register *reg, struct rank_control *ctrl);
 ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name);
 void zebraRankDestroy (struct zebra_register *reg);
 
-int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att);
+int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att,
+               const char *sattr);
 
 extern struct rank_control *rank1_class;
 extern struct rank_control *rankzv_class;
index 66777f6..9e23c2f 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zrpn.c,v 1.137 2004-05-10 08:47:54 adam Exp $
+/* $Id: zrpn.c,v 1.138 2004-05-26 13:52:26 adam Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
@@ -941,7 +941,7 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
             zh->errString = basenames[base_no];
             return -1;
         }
-        if (use_value == -2)  /* string attribute (assume IDXPATH/any) */
+        if (xpath_use > 0 && use_value == -2) 
         {
             use_value = xpath_use;
             attp.local_attributes = &id_xpath_attr;
@@ -958,17 +958,23 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
         }
         else
         {
-            if ((r=att_getentbyatt (zh, &attp, curAttributeSet, use_value)))
+            if ((r=att_getentbyatt (zh, &attp, curAttributeSet, use_value,
+                                           use_string)))
             {
                 logf (LOG_DEBUG, "att_getentbyatt fail. set=%d use=%d r=%d",
                       curAttributeSet, use_value, r);
                 if (r == -1)
                 {
                     /* set was found, but value wasn't defined */
-                    char val_str[32];
-                    sprintf (val_str, "%d 1", use_value);
                     errCode = 114;
-                    errString = nmem_strdup (stream, val_str);
+                   if (use_string)
+                       errString = nmem_strdup(stream, use_string);
+                   else
+                    {
+                        char val_str[32];
+                        sprintf (val_str, "%d", use_value);
+                        errString = nmem_strdup (stream, val_str);
+                   }
                 }
                 else
                 {
@@ -1015,7 +1021,7 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
            bases_ok++;
 #else
             char val_str[32];
-            sprintf (val_str, "%d 2", use_value);
+            sprintf (val_str, "%d", use_value);
             errCode = 114;
             errString = nmem_strdup (stream, val_str);
 #endif
@@ -1850,7 +1856,8 @@ static int numeric_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
         }
         else
         {
-            if ((r=att_getentbyatt (zh, &attp, curAttributeSet, use_value)))
+            if ((r=att_getentbyatt (zh, &attp, curAttributeSet, use_value,
+                                           use_string)))
             {
                 logf (LOG_DEBUG, "att_getentbyatt fail. set=%d use=%d r=%d",
                       curAttributeSet, use_value, r);
@@ -2692,6 +2699,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
     char termz[IT_MAX_WORD+20];
     AttrType use;
     int use_value;
+    const char *use_string = 0;
     struct scan_info *scan_info_array;
     ZebraScanEntry *glist;
     int ords[32], ord_no = 0;
@@ -2742,7 +2750,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
              pos, num, attributeset);
         
     attr_init (&use, zapt, 1);
-    use_value = attr_find (&use, &attributeset);
+    use_value = attr_find_ex (&use, &attributeset, &use_string);
 
     if (zebra_maps_attr (zh->reg->zebra_maps, zapt, &reg_id, &search_type,
                         rank_type, &complete_flag, &sort_flag))
@@ -2761,7 +2769,8 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
         attent attp;
         data1_local_attribute *local_attr;
 
-        if ((r=att_getentbyatt (zh, &attp, attributeset, use_value)))
+        if ((r=att_getentbyatt (zh, &attp, attributeset, use_value,
+                               use_string)))
         {
             logf (LOG_DEBUG, "att_getentbyatt fail. set=%d use=%d",
                   attributeset, use_value);