X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=zutil%2Fyaz-ccl.c;h=17194badba28a94f66376ea227d0886603faa22c;hb=b0ea0712dd81e2d3dd25ec14c0bb9a6ce0a51056;hp=c5ba47acc5f1dfe444efc83391455a06375442de;hpb=d9ee01635f03f9095a66f71b73580560d48798e8;p=yaz-moved-to-github.git diff --git a/zutil/yaz-ccl.c b/zutil/yaz-ccl.c index c5ba47a..17194ba 100644 --- a/zutil/yaz-ccl.c +++ b/zutil/yaz-ccl.c @@ -1,10 +1,33 @@ /* - * 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.3 1999-11-30 13:47:12 adam + * 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 @@ -37,7 +60,6 @@ #include #include #include -#include #include @@ -53,13 +75,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++; @@ -74,11 +93,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)); @@ -108,7 +142,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) { @@ -118,10 +151,10 @@ static Z_Operand *ccl_rpn_simple (ODR o, struct ccl_rpn_node *p) 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; } @@ -132,9 +165,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) @@ -182,7 +213,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]); @@ -194,7 +225,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: @@ -210,7 +240,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; } @@ -218,10 +248,14 @@ 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)); - assert (zq); - zq->attributeSetId = NULL; + zq->attributeSetId = odr_oiddup (o, oid_ent_to_oid (&bib1, oid)); zq->RPNStructure = ccl_rpn_structure (o, p); return zq; } @@ -232,3 +266,63 @@ Z_AttributesPlusTerm *ccl_scan_query (ODR o, struct ccl_rpn_node *p) 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; + + 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); + } + wrbuf_puts (w, "{"); + wrbuf_puts (w, p->u.t.term); + wrbuf_puts (w, "} "); + break; + } +}