/*
- * Copyright (c) 1996-1998, Index Data.
+ * Copyright (c) 1996-2001, Index Data.
* See the file LICENSE for details.
- * Sebastian Hammer, Adam Dickmeiss
- *
- * $Log: yaz-ccl.c,v $
- * 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>
#include <stdlib.h>
#include <string.h>
-#include <assert.h>
-#include <yaz-ccl.h>
+#include <yaz/yaz-ccl.h>
static Z_RPNStructure *ccl_rpn_structure (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++;
{
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)
+ {
+ elements[i]->attributeSet =
+ yaz_oidval_to_z3950oid(o, CLASS_ATTSET, value);
+ }
+ }
elements[i]->which = Z_AttributeValue_numeric;
elements[i]->value.numeric =
(int *)odr_malloc (o, sizeof(int));
*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;
Z_Operand *zo;
zo = (Z_Operand *)odr_malloc (o, sizeof(*zo));
- assert (zo);
switch (p->kind)
{
break;
case CCL_RPN_SET:
zo->which = Z_Operand_resultSetId;
- zo->u.resultSetId = p->u.setname;
+ zo->u.resultSetId = odr_strdup (o, p->u.setname);
break;
default:
- assert (0);
+ return 0;
}
return zo;
}
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)
{
case CCL_RPN_AND:
zo->which = Z_Operator_and;
- zo->u.and = odr_nullval();
+ zo->u.and_not = odr_nullval();
break;
case CCL_RPN_OR:
zo->which = Z_Operator_or;
- zo->u.and = odr_nullval();
+ zo->u.and_not = odr_nullval();
break;
case CCL_RPN_NOT:
zo->which = Z_Operator_and_not;
- zo->u.and = odr_nullval();
+ zo->u.and_not = odr_nullval();
break;
+ case CCL_RPN_PROX:
+ zo->which = Z_Operator_prox;
+ zo->u.prox = (Z_ProximityOperator *)
+ odr_malloc (o, sizeof(*zo->u.prox));
+ zo->u.prox->exclusion = 0;
+
+ zo->u.prox->distance = (int *)
+ odr_malloc (o, sizeof(*zo->u.prox->distance));
+ *zo->u.prox->distance = 2;
+
+ zo->u.prox->ordered = (bool_t *)
+ odr_malloc (o, sizeof(*zo->u.prox->ordered));
+ *zo->u.prox->ordered = 0;
+
+ zo->u.prox->relationType = (int *)
+ odr_malloc (o, sizeof(*zo->u.prox->relationType));
+ *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;
+ 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]);
Z_RPNStructure *zs;
zs = (Z_RPNStructure *)odr_malloc (o, sizeof(*zs));
- assert (zs);
switch (p->kind)
{
case CCL_RPN_AND:
zs->u.simple = ccl_rpn_simple (o, p);
break;
default:
- assert (0);
+ return 0;
}
return zs;
}
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;
+ 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;
}
return NULL;
return ccl_rpn_term (o, p);
}
+
+static void ccl_pquery_complex (WRBUF w, struct ccl_rpn_node *p)
+{
+ switch (p->kind)
+ {
+ case CCL_RPN_AND:
+ wrbuf_puts (w, "@and ");
+ break;
+ case CCL_RPN_OR:
+ wrbuf_puts(w, "@or ");
+ break;
+ case CCL_RPN_NOT:
+ wrbuf_puts(w, "@not ");
+ break;
+ case CCL_RPN_PROX:
+ wrbuf_puts(w, "@prox 0 2 0 1 known 2 ");
+ break;
+ default:
+ wrbuf_puts(w, "@ bad op (unknown) ");
+ };
+ ccl_pquery(w, p->u.p[0]);
+ ccl_pquery(w, p->u.p[1]);
+}
+
+void ccl_pquery (WRBUF w, struct ccl_rpn_node *p)
+{
+ struct ccl_rpn_attr *att;
+ const char *cp;
+
+ switch (p->kind)
+ {
+ case CCL_RPN_AND:
+ case CCL_RPN_OR:
+ case CCL_RPN_NOT:
+ case CCL_RPN_PROX:
+ ccl_pquery_complex (w, p);
+ break;
+ case CCL_RPN_SET:
+ wrbuf_puts (w, "@set ");
+ wrbuf_puts (w, p->u.setname);
+ wrbuf_puts (w, " ");
+ break;
+ case CCL_RPN_TERM:
+ for (att = p->u.t.attr_list; att; att = att->next)
+ {
+ char tmpattr[128];
+ wrbuf_puts (w, "@attr ");
+ if (att->set)
+ {
+ wrbuf_puts (w, att->set);
+ wrbuf_puts (w, " ");
+ }
+ sprintf(tmpattr, "%d=%d ", att->type, att->value);
+ wrbuf_puts (w, tmpattr);
+ }
+ for (cp = p->u.t.term; *cp; cp++)
+ {
+ if (*cp == ' ' || *cp == '\\')
+ wrbuf_putc (w, '\\');
+ wrbuf_putc (w, *cp);
+ }
+ wrbuf_puts (w, " ");
+ break;
+ }
+}