2 * Copyright (c) 1996, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.9 1997-06-23 10:31:25 adam
8 * Added ODR argument to ccl_rpn_query and ccl_scan_query.
10 * Revision 1.8 1996/10/29 13:36:27 adam
22 static Z_RPNStructure *ccl_rpn_structure (ODR o, struct ccl_rpn_node *p);
24 static Z_AttributesPlusTerm *ccl_rpn_term (ODR o, struct ccl_rpn_node *p)
26 struct ccl_rpn_attr *attr;
28 Z_AttributesPlusTerm *zapt;
32 zapt = odr_malloc (o, sizeof(*zapt));
35 term_octet = odr_malloc (o, sizeof(*term_octet));
38 term = odr_malloc (o, sizeof(*term));
41 for (attr = p->u.t.attr_list; attr; attr = attr->next)
43 zapt->num_attributes = num;
47 zapt->attributeList = odr_malloc (o, num*sizeof(*zapt->attributeList));
48 assert (zapt->attributeList);
49 for (attr = p->u.t.attr_list; attr; attr = attr->next, i++)
51 zapt->attributeList[i] =
52 odr_malloc (o, sizeof(**zapt->attributeList));
53 assert (zapt->attributeList[i]);
54 zapt->attributeList[i]->attributeType =
57 zapt->attributeList[i]->attributeSet = 0;
58 zapt->attributeList[i]->which = Z_AttributeValue_numeric;
59 zapt->attributeList[i]->value.numeric = &attr->value;
61 zapt->attributeList[i]->attributeValue =
67 zapt->attributeList = ODR_NULLVAL;
70 term->which = Z_Term_general;
71 term->u.general = term_octet;
72 term_octet->buf = (unsigned char*) p->u.t.term;
73 term_octet->len = term_octet->size = strlen (p->u.t.term);
77 static Z_Operand *ccl_rpn_simple (ODR o, struct ccl_rpn_node *p)
81 zo = odr_malloc (o, sizeof(*zo));
87 zo->which = Z_Operand_APT;
88 zo->u.attributesPlusTerm = ccl_rpn_term (o, p);
91 zo->which = Z_Operand_resultSetId;
92 zo->u.resultSetId = p->u.setname;
100 static Z_Complex *ccl_rpn_complex (ODR o, struct ccl_rpn_node *p)
105 zc = odr_malloc (o, sizeof(*zc));
107 zo = odr_malloc (o, sizeof(*zo));
114 zo->which = Z_Operator_and;
115 zo->u.and = ODR_NULLVAL;
118 zo->which = Z_Operator_or;
119 zo->u.and = ODR_NULLVAL;
122 zo->which = Z_Operator_and_not;
123 zo->u.and = ODR_NULLVAL;
128 zc->s1 = ccl_rpn_structure (o, p->u.p[0]);
129 zc->s2 = ccl_rpn_structure (o, p->u.p[1]);
133 static Z_RPNStructure *ccl_rpn_structure (ODR o, struct ccl_rpn_node *p)
137 zs = odr_malloc (o, sizeof(*zs));
145 zs->which = Z_RPNStructure_complex;
146 zs->u.complex = ccl_rpn_complex (o, p);
150 zs->which = Z_RPNStructure_simple;
151 zs->u.simple = ccl_rpn_simple (o, p);
159 Z_RPNQuery *ccl_rpn_query (ODR o, struct ccl_rpn_node *p)
163 zq = odr_malloc (o, sizeof(*zq));
165 zq->attributeSetId = NULL;
166 zq->RPNStructure = ccl_rpn_structure (o, p);
170 Z_AttributesPlusTerm *ccl_scan_query (ODR o, struct ccl_rpn_node *p)
172 if (p->kind != CCL_RPN_TERM)
174 return ccl_rpn_term (o, p);