Implemented local AttributeSet setting for CCL field maps.
[yaz-moved-to-github.git] / zutil / yaz-ccl.c
index 2740396..aede44b 100644 (file)
@@ -1,10 +1,21 @@
 /*
- * Copyright (c) 1996-1999, Index Data.
+ * Copyright (c) 1996-2000, Index Data.
  * See the file LICENSE for details.
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: yaz-ccl.c,v $
- * Revision 1.4  1999-12-20 15:20:13  adam
+ * Revision 1.7  2000-11-16 09:58:02  adam
+ * Implemented local AttributeSet setting for CCL field maps.
+ *
+ * Revision 1.6  2000/02/02 15:13:23  adam
+ * Minor change.
+ *
+ * Revision 1.5  2000/01/31 13:15:22  adam
+ * Removed uses of assert(3). Cleanup of ODR. CCL parser update so
+ * that some characters are not surrounded by spaces in resulting term.
+ * ILL-code updates.
+ *
+ * Revision 1.4  1999/12/20 15:20:13  adam
  * Implemented ccl_pquery to convert from CCL tree to prefix query.
  *
  * Revision 1.3  1999/11/30 13:47:12  adam
@@ -40,7 +51,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <assert.h>
 
 #include <yaz/yaz-ccl.h>
 
@@ -56,13 +66,10 @@ static Z_AttributesPlusTerm *ccl_rpn_term (ODR o, struct ccl_rpn_node *p)
     Z_AttributeElement **elements;
 
     zapt = (Z_AttributesPlusTerm *)odr_malloc (o, sizeof(*zapt));
-    assert (zapt);
 
     term_octet = (Odr_oct *)odr_malloc (o, sizeof(*term_octet));
-    assert (term_octet);
 
     term = (Z_Term *)odr_malloc (o, sizeof(*term));
-    assert(term);
 
     for (attr = p->u.t.attr_list; attr; attr = attr->next)
         num++;
@@ -77,11 +84,26 @@ static Z_AttributesPlusTerm *ccl_rpn_term (ODR o, struct ccl_rpn_node *p)
         {
             elements[i] = (Z_AttributeElement *)
                odr_malloc (o, sizeof(**elements));
-            assert (elements[i]);
             elements[i]->attributeType =
                (int *)odr_malloc(o, sizeof(int));
             *elements[i]->attributeType = attr->type;
            elements[i]->attributeSet = 0;
+           if (attr->set && *attr->set)
+           {
+               int value = oid_getvalbyname (attr->set);
+
+               if (value != VAL_NONE)
+               {
+                   int oid[OID_SIZE];
+                   struct oident ident;
+
+                   ident.oclass = CLASS_ATTSET;
+                   ident.proto = PROTO_Z3950;
+                   ident.value = value;
+                   elements[i]->attributeSet =
+                       odr_oiddup (o, oid_ent_to_oid (&ident, oid));
+               }
+           }
            elements[i]->which = Z_AttributeValue_numeric;
            elements[i]->value.numeric =
                (int *)odr_malloc (o, sizeof(int));
@@ -111,7 +133,6 @@ static Z_Operand *ccl_rpn_simple (ODR o, struct ccl_rpn_node *p)
     Z_Operand *zo;
 
     zo = (Z_Operand *)odr_malloc (o, sizeof(*zo));
-    assert (zo);
 
     switch (p->kind)
     {
@@ -124,7 +145,7 @@ static Z_Operand *ccl_rpn_simple (ODR o, struct ccl_rpn_node *p)
         zo->u.resultSetId = p->u.setname;
         break;
     default:
-        assert (0);
+       return 0;
     }
     return zo;
 }
@@ -135,9 +156,7 @@ static Z_Complex *ccl_rpn_complex (ODR o, struct ccl_rpn_node *p)
     Z_Operator *zo;
 
     zc = (Z_Complex *)odr_malloc (o, sizeof(*zc));
-    assert (zc);
     zo = (Z_Operator *)odr_malloc (o, sizeof(*zo));
-    assert (zo);
 
     zc->roperator = zo;
     switch (p->kind)
@@ -185,7 +204,7 @@ static Z_Complex *ccl_rpn_complex (ODR o, struct ccl_rpn_node *p)
 #endif
        break;
     default:
-        assert (0);
+       return 0;
     }
     zc->s1 = ccl_rpn_structure (o, p->u.p[0]);
     zc->s2 = ccl_rpn_structure (o, p->u.p[1]);
@@ -197,7 +216,6 @@ static Z_RPNStructure *ccl_rpn_structure (ODR o, struct ccl_rpn_node *p)
     Z_RPNStructure *zs;
 
     zs = (Z_RPNStructure *)odr_malloc (o, sizeof(*zs));
-    assert (zs);
     switch (p->kind)
     {
     case CCL_RPN_AND:
@@ -213,7 +231,7 @@ static Z_RPNStructure *ccl_rpn_structure (ODR o, struct ccl_rpn_node *p)
         zs->u.simple = ccl_rpn_simple (o, p);
         break;
     default:
-        assert (0);
+       return 0;
     }
     return zs;
 }
@@ -223,7 +241,6 @@ Z_RPNQuery *ccl_rpn_query (ODR o, struct ccl_rpn_node *p)
     Z_RPNQuery *zq;
 
     zq = (Z_RPNQuery *)odr_malloc (o, sizeof(*zq));
-    assert (zq);
     zq->attributeSetId = NULL;
     zq->RPNStructure = ccl_rpn_structure (o, p);
     return zq;
@@ -253,7 +270,7 @@ static void ccl_pquery_complex (WRBUF w, struct ccl_rpn_node *p)
        wrbuf_puts(w, "@prox 0 2 0 1 known 2 ");
        break;
     default:
-       assert(0);
+       wrbuf_puts(w, "@ bad op (unknown) ");
     };
     ccl_pquery(w, p->u.p[0]);
     ccl_pquery(w, p->u.p[1]);
@@ -287,7 +304,5 @@ void ccl_pquery (WRBUF w, struct ccl_rpn_node *p)
        wrbuf_puts (w, p->u.t.term);
        wrbuf_puts (w, "} ");
        break;
-    default:
-       assert (0);
-    };
+    }
 }