Add Zthes tag-set -- where was it?!
[yaz-moved-to-github.git] / zutil / yaz-ccl.c
index d672503..f8b8050 100644 (file)
@@ -1,63 +1,8 @@
 /*
  * Copyright (c) 1996-2001, Index Data.
  * See the file LICENSE for details.
- * Sebastian Hammer, Adam Dickmeiss
- *
- * $Log: yaz-ccl.c,v $
- * Revision 1.11  2001-02-21 13:46:54  adam
- * C++ fixes.
- *
- * Revision 1.10  2001/02/20 11:23:50  adam
- * Updated ccl_pquery to consider local attribute set too.
- *
- * Revision 1.9  2000/11/27 14:16:55  adam
- * Fixed bug in ccl_rpn_simple regarding resultSetId's.
- *
- * Revision 1.8  2000/11/16 13:03:13  adam
- * Function ccl_rpn_query sets attributeSet to Bib-1.
- *
- * 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
- * Improved installation. Moved header files to include/yaz.
- *
- * Revision 1.2  1999/06/16 12:00:08  adam
- * Added proximity.
- *
- * Revision 1.1  1999/06/08 10:12:43  adam
- * Moved file to be part of zutil (instead of util).
- *
- * Revision 1.13  1998/03/31 15:13:20  adam
- * Development towards compiled ASN.1.
- *
- * Revision 1.12  1998/02/11 11:53:36  adam
- * Changed code so that it compiles as C++.
- *
- * Revision 1.11  1997/11/24 11:33:57  adam
- * Using function odr_nullval() instead of global ODR_NULLVAL when
- * appropriate.
- *
- * Revision 1.10  1997/09/29 08:58:25  adam
- * Fixed conversion of trees so that true copy is made.
- *
- * Revision 1.9  1997/06/23 10:31:25  adam
- * Added ODR argument to ccl_rpn_query and ccl_scan_query.
- *
- * Revision 1.8  1996/10/29 13:36:27  adam
- * Added header.
  *
+ * $Id: yaz-ccl.c,v 1.15 2001-11-13 23:00:43 adam Exp $
  */
 
 #include <stdio.h>
@@ -106,14 +51,8 @@ static Z_AttributesPlusTerm *ccl_rpn_term (ODR o, struct ccl_rpn_node *p)
 
                if (value != VAL_NONE)
                {
-                   int oid[OID_SIZE];
-                   struct oident ident;
-
-                   ident.oclass = CLASS_ATTSET;
-                   ident.proto = PROTO_Z3950;
-                   ident.value = (oid_value) value;
                    elements[i]->attributeSet =
-                       odr_oiddup (o, oid_ent_to_oid (&ident, oid));
+                       yaz_oidval_to_z3950oid(o, CLASS_ATTSET, value);
                }
            }
            elements[i]->which = Z_AttributeValue_numeric;
@@ -122,15 +61,10 @@ static Z_AttributesPlusTerm *ccl_rpn_term (ODR o, struct ccl_rpn_node *p)
            *elements[i]->value.numeric = attr->value;
         }
     }
-#ifdef ASN_COMPILED
     zapt->attributes = (Z_AttributeList *)
        odr_malloc (o, sizeof(*zapt->attributes));
     zapt->attributes->num_attributes = num;
     zapt->attributes->attributes = elements;
-#else
-    zapt->num_attributes = num;
-    zapt->attributeList = elements;
-#endif    
     zapt->term = term;
     term->which = Z_Term_general;
     term->u.general = term_octet;
@@ -175,15 +109,15 @@ static Z_Complex *ccl_rpn_complex (ODR o, struct ccl_rpn_node *p)
     {
     case CCL_RPN_AND:
         zo->which = Z_Operator_and;
-        zo->u.op_and = odr_nullval();
+        zo->u.and_not = odr_nullval();
         break;
     case CCL_RPN_OR:
         zo->which = Z_Operator_or;
-        zo->u.op_or = odr_nullval();
+        zo->u.and_not = odr_nullval();
         break;
     case CCL_RPN_NOT:
         zo->which = Z_Operator_and_not;
-        zo->u.op_and_not = odr_nullval();
+        zo->u.and_not = odr_nullval();
         break;
     case CCL_RPN_PROX:
        zo->which = Z_Operator_prox;
@@ -201,19 +135,11 @@ static Z_Complex *ccl_rpn_complex (ODR o, struct ccl_rpn_node *p)
 
        zo->u.prox->relationType = (int *)
            odr_malloc (o, sizeof(*zo->u.prox->relationType));
-#ifdef ASN_COMPILED
        *zo->u.prox->relationType = Z_ProximityOperator_Prox_lessThan;
        zo->u.prox->which = Z_ProximityOperator_known;
        zo->u.prox->u.known = 
            (Z_ProxUnit *) odr_malloc (o, sizeof(*zo->u.prox->u.known));
        *zo->u.prox->u.known = Z_ProxUnit_word;
-#else
-       *zo->u.prox->relationType = Z_Prox_lessThan;
-       zo->u.prox->which = Z_ProxCode_known;
-       zo->u.prox->proximityUnitCode = (int*)
-           odr_malloc (o, sizeof(*zo->u.prox->proximityUnitCode));
-       *zo->u.prox->proximityUnitCode = Z_ProxUnit_word;
-#endif
        break;
     default:
        return 0;
@@ -250,15 +176,8 @@ static Z_RPNStructure *ccl_rpn_structure (ODR o, struct ccl_rpn_node *p)
 
 Z_RPNQuery *ccl_rpn_query (ODR o, struct ccl_rpn_node *p)
 {
-    Z_RPNQuery *zq;
-    oident bib1;
-    int oid[OID_SIZE];
-    bib1.proto = PROTO_Z3950;
-    bib1.oclass = CLASS_ATTSET;
-    bib1.value = VAL_BIB1;
-
-    zq = (Z_RPNQuery *)odr_malloc (o, sizeof(*zq));
-    zq->attributeSetId = odr_oiddup (o, oid_ent_to_oid (&bib1, oid));
+    Z_RPNQuery *zq = (Z_RPNQuery *)odr_malloc (o, sizeof(*zq));
+    zq->attributeSetId = yaz_oidval_to_z3950oid (o, CLASS_ATTSET, VAL_BIB1);
     zq->RPNStructure = ccl_rpn_structure (o, p);
     return zq;
 }
@@ -296,6 +215,7 @@ static void ccl_pquery_complex (WRBUF w, struct ccl_rpn_node *p)
 void ccl_pquery (WRBUF w, struct ccl_rpn_node *p)
 {
     struct ccl_rpn_attr *att;
+    const char *cp;
 
     switch (p->kind)
     {
@@ -323,9 +243,13 @@ void ccl_pquery (WRBUF w, struct ccl_rpn_node *p)
            sprintf(tmpattr, "%d=%d ", att->type, att->value);
            wrbuf_puts (w, tmpattr);
        }
-       wrbuf_puts (w, "{");
-       wrbuf_puts (w, p->u.t.term);
-       wrbuf_puts (w, "} ");
+       for (cp = p->u.t.term; *cp; cp++)
+       {
+           if (*cp == ' ' || *cp == '\\')
+               wrbuf_putc (w, '\\');
+           wrbuf_putc (w, *cp);
+       }
+       wrbuf_puts (w, " ");
        break;
     }
 }