X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=util%2Fyaz-ccl.c;h=6c856427ed14356115cfcf16f228a862ea6252ff;hp=8aa385428fcbe696146f2d086397b72cf40e8c3a;hb=a807bde38544a7aa45dd2988e504a1acb3fd30c0;hpb=d4c12ec7c451e74a949cc7c8d5fef226c995ddc6 diff --git a/util/yaz-ccl.c b/util/yaz-ccl.c index 8aa3854..6c85642 100644 --- a/util/yaz-ccl.c +++ b/util/yaz-ccl.c @@ -1,3 +1,24 @@ +/* + * Copyright (c) 1996-1997, Index Data. + * See the file LICENSE for details. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: yaz-ccl.c,v $ + * 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. + * + */ + #include #include #include @@ -5,9 +26,9 @@ #include -static Z_RPNStructure *ccl_rpn_structure (struct ccl_rpn_node *p); +static Z_RPNStructure *ccl_rpn_structure (ODR o, struct ccl_rpn_node *p); -static Z_AttributesPlusTerm *ccl_rpn_term (struct ccl_rpn_node *p) +static Z_AttributesPlusTerm *ccl_rpn_term (ODR o, struct ccl_rpn_node *p) { struct ccl_rpn_attr *attr; int num = 0; @@ -15,13 +36,13 @@ static Z_AttributesPlusTerm *ccl_rpn_term (struct ccl_rpn_node *p) Odr_oct *term_octet; Z_Term *term; - zapt = malloc (sizeof(*zapt)); + zapt = odr_malloc (o, sizeof(*zapt)); assert (zapt); - term_octet = malloc (sizeof(*term_octet)); + term_octet = odr_malloc (o, sizeof(*term_octet)); assert (term_octet); - term = malloc(sizeof(*term)); + term = odr_malloc (o, sizeof(*term)); assert(term); for (attr = p->u.t.attr_list; attr; attr = attr->next) @@ -30,41 +51,47 @@ static Z_AttributesPlusTerm *ccl_rpn_term (struct ccl_rpn_node *p) if (num) { int i = 0; - zapt->attributeList = malloc (num*sizeof(*zapt->attributeList)); + zapt->attributeList = odr_malloc (o, num*sizeof(*zapt->attributeList)); assert (zapt->attributeList); for (attr = p->u.t.attr_list; attr; attr = attr->next, i++) { - zapt->attributeList[i] = malloc (sizeof(**zapt->attributeList)); + zapt->attributeList[i] = + odr_malloc (o, sizeof(**zapt->attributeList)); assert (zapt->attributeList[i]); zapt->attributeList[i]->attributeType = - &attr->type; - zapt->attributeList[i]->attributeValue = - &attr->value; + odr_malloc(o, sizeof(int)); + *zapt->attributeList[i]->attributeType = attr->type; + zapt->attributeList[i]->attributeSet = 0; + zapt->attributeList[i]->which = Z_AttributeValue_numeric; + zapt->attributeList[i]->value.numeric = + odr_malloc (o, sizeof(int)); + *zapt->attributeList[i]->value.numeric = attr->value; } } else - zapt->attributeList = NULL; + zapt->attributeList = odr_nullval(); zapt->term = term; term->which = Z_Term_general; term->u.general = term_octet; - term_octet->buf = (unsigned char*) p->u.t.term; term_octet->len = term_octet->size = strlen (p->u.t.term); + term_octet->buf = odr_malloc (o, term_octet->len+1); + strcpy ((char*) term_octet->buf, p->u.t.term); return zapt; } -static Z_Operand *ccl_rpn_simple (struct ccl_rpn_node *p) +static Z_Operand *ccl_rpn_simple (ODR o, struct ccl_rpn_node *p) { Z_Operand *zo; - zo = malloc (sizeof(*zo)); + zo = odr_malloc (o, sizeof(*zo)); assert (zo); switch (p->kind) { case CCL_RPN_TERM: zo->which = Z_Operand_APT; - zo->u.attributesPlusTerm = ccl_rpn_term (p); + zo->u.attributesPlusTerm = ccl_rpn_term (o, p); break; case CCL_RPN_SET: zo->which = Z_Operand_resultSetId; @@ -76,44 +103,44 @@ static Z_Operand *ccl_rpn_simple (struct ccl_rpn_node *p) return zo; } -static Z_Complex *ccl_rpn_complex (struct ccl_rpn_node *p) +static Z_Complex *ccl_rpn_complex (ODR o, struct ccl_rpn_node *p) { Z_Complex *zc; Z_Operator *zo; - zc = malloc (sizeof(*zc)); + zc = odr_malloc (o, sizeof(*zc)); assert (zc); - zo = malloc (sizeof(*zo)); + zo = odr_malloc (o, sizeof(*zo)); assert (zo); - zc->operator = zo; + zc->roperator = zo; switch (p->kind) { case CCL_RPN_AND: zo->which = Z_Operator_and; - zo->u.and = ODR_NULLVAL; + zo->u.and = odr_nullval(); break; case CCL_RPN_OR: zo->which = Z_Operator_or; - zo->u.and = ODR_NULLVAL; + zo->u.and = odr_nullval(); break; case CCL_RPN_NOT: zo->which = Z_Operator_and_not; - zo->u.and = ODR_NULLVAL; + zo->u.and = odr_nullval(); break; default: assert (0); } - zc->s1 = ccl_rpn_structure (p->u.p[0]); - zc->s2 = ccl_rpn_structure (p->u.p[1]); + zc->s1 = ccl_rpn_structure (o, p->u.p[0]); + zc->s2 = ccl_rpn_structure (o, p->u.p[1]); return zc; } -static Z_RPNStructure *ccl_rpn_structure (struct ccl_rpn_node *p) +static Z_RPNStructure *ccl_rpn_structure (ODR o, struct ccl_rpn_node *p) { Z_RPNStructure *zs; - zs = malloc (sizeof(*zs)); + zs = odr_malloc (o, sizeof(*zs)); assert (zs); switch (p->kind) { @@ -122,12 +149,12 @@ static Z_RPNStructure *ccl_rpn_structure (struct ccl_rpn_node *p) case CCL_RPN_NOT: case CCL_RPN_PROX: zs->which = Z_RPNStructure_complex; - zs->u.complex = ccl_rpn_complex (p); + zs->u.complex = ccl_rpn_complex (o, p); break; case CCL_RPN_TERM: case CCL_RPN_SET: zs->which = Z_RPNStructure_simple; - zs->u.simple = ccl_rpn_simple (p); + zs->u.simple = ccl_rpn_simple (o, p); break; default: assert (0); @@ -135,20 +162,20 @@ static Z_RPNStructure *ccl_rpn_structure (struct ccl_rpn_node *p) return zs; } -Z_RPNQuery *ccl_rpn_query (struct ccl_rpn_node *p) +Z_RPNQuery *ccl_rpn_query (ODR o, struct ccl_rpn_node *p) { Z_RPNQuery *zq; - zq = malloc (sizeof(*zq)); + zq = odr_malloc (o, sizeof(*zq)); assert (zq); zq->attributeSetId = NULL; - zq->RPNStructure = ccl_rpn_structure (p); + zq->RPNStructure = ccl_rpn_structure (o, p); return zq; } -Z_AttributesPlusTerm *ccl_scan_query (struct ccl_rpn_node *p) +Z_AttributesPlusTerm *ccl_scan_query (ODR o, struct ccl_rpn_node *p) { if (p->kind != CCL_RPN_TERM) return NULL; - return ccl_rpn_term (p); + return ccl_rpn_term (o, p); }