2 * Copyright (c) 1996-1997, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.10 1997-09-29 08:58:25 adam
8 * Fixed conversion of trees so that true copy is made.
10 * Revision 1.9 1997/06/23 10:31:25 adam
11 * Added ODR argument to ccl_rpn_query and ccl_scan_query.
13 * Revision 1.8 1996/10/29 13:36:27 adam
25 static Z_RPNStructure *ccl_rpn_structure (ODR o, struct ccl_rpn_node *p);
27 static Z_AttributesPlusTerm *ccl_rpn_term (ODR o, struct ccl_rpn_node *p)
29 struct ccl_rpn_attr *attr;
31 Z_AttributesPlusTerm *zapt;
35 zapt = odr_malloc (o, sizeof(*zapt));
38 term_octet = odr_malloc (o, sizeof(*term_octet));
41 term = odr_malloc (o, sizeof(*term));
44 for (attr = p->u.t.attr_list; attr; attr = attr->next)
46 zapt->num_attributes = num;
50 zapt->attributeList = odr_malloc (o, num*sizeof(*zapt->attributeList));
51 assert (zapt->attributeList);
52 for (attr = p->u.t.attr_list; attr; attr = attr->next, i++)
54 zapt->attributeList[i] =
55 odr_malloc (o, sizeof(**zapt->attributeList));
56 assert (zapt->attributeList[i]);
57 zapt->attributeList[i]->attributeType =
58 odr_malloc(o, sizeof(int));
59 *zapt->attributeList[i]->attributeType = attr->type;
60 zapt->attributeList[i]->attributeSet = 0;
61 zapt->attributeList[i]->which = Z_AttributeValue_numeric;
62 zapt->attributeList[i]->value.numeric =
63 odr_malloc (o, sizeof(int));
64 *zapt->attributeList[i]->value.numeric = attr->value;
68 zapt->attributeList = ODR_NULLVAL;
71 term->which = Z_Term_general;
72 term->u.general = term_octet;
73 term_octet->len = term_octet->size = strlen (p->u.t.term);
74 term_octet->buf = odr_malloc (o, term_octet->len+1);
75 strcpy ((char*) term_octet->buf, p->u.t.term);
79 static Z_Operand *ccl_rpn_simple (ODR o, struct ccl_rpn_node *p)
83 zo = odr_malloc (o, sizeof(*zo));
89 zo->which = Z_Operand_APT;
90 zo->u.attributesPlusTerm = ccl_rpn_term (o, p);
93 zo->which = Z_Operand_resultSetId;
94 zo->u.resultSetId = p->u.setname;
102 static Z_Complex *ccl_rpn_complex (ODR o, struct ccl_rpn_node *p)
107 zc = odr_malloc (o, sizeof(*zc));
109 zo = odr_malloc (o, sizeof(*zo));
116 zo->which = Z_Operator_and;
117 zo->u.and = ODR_NULLVAL;
120 zo->which = Z_Operator_or;
121 zo->u.and = ODR_NULLVAL;
124 zo->which = Z_Operator_and_not;
125 zo->u.and = ODR_NULLVAL;
130 zc->s1 = ccl_rpn_structure (o, p->u.p[0]);
131 zc->s2 = ccl_rpn_structure (o, p->u.p[1]);
135 static Z_RPNStructure *ccl_rpn_structure (ODR o, struct ccl_rpn_node *p)
139 zs = odr_malloc (o, sizeof(*zs));
147 zs->which = Z_RPNStructure_complex;
148 zs->u.complex = ccl_rpn_complex (o, p);
152 zs->which = Z_RPNStructure_simple;
153 zs->u.simple = ccl_rpn_simple (o, p);
161 Z_RPNQuery *ccl_rpn_query (ODR o, struct ccl_rpn_node *p)
165 zq = odr_malloc (o, sizeof(*zq));
167 zq->attributeSetId = NULL;
168 zq->RPNStructure = ccl_rpn_structure (o, p);
172 Z_AttributesPlusTerm *ccl_scan_query (ODR o, struct ccl_rpn_node *p)
174 if (p->kind != CCL_RPN_TERM)
176 return ccl_rpn_term (o, p);