2 * Copyright (c) 1996-1997, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.11 1997-11-24 11:33:57 adam
8 * Using function odr_nullval() instead of global ODR_NULLVAL when
11 * Revision 1.10 1997/09/29 08:58:25 adam
12 * Fixed conversion of trees so that true copy is made.
14 * Revision 1.9 1997/06/23 10:31:25 adam
15 * Added ODR argument to ccl_rpn_query and ccl_scan_query.
17 * Revision 1.8 1996/10/29 13:36:27 adam
29 static Z_RPNStructure *ccl_rpn_structure (ODR o, struct ccl_rpn_node *p);
31 static Z_AttributesPlusTerm *ccl_rpn_term (ODR o, struct ccl_rpn_node *p)
33 struct ccl_rpn_attr *attr;
35 Z_AttributesPlusTerm *zapt;
39 zapt = odr_malloc (o, sizeof(*zapt));
42 term_octet = odr_malloc (o, sizeof(*term_octet));
45 term = odr_malloc (o, sizeof(*term));
48 for (attr = p->u.t.attr_list; attr; attr = attr->next)
50 zapt->num_attributes = num;
54 zapt->attributeList = odr_malloc (o, num*sizeof(*zapt->attributeList));
55 assert (zapt->attributeList);
56 for (attr = p->u.t.attr_list; attr; attr = attr->next, i++)
58 zapt->attributeList[i] =
59 odr_malloc (o, sizeof(**zapt->attributeList));
60 assert (zapt->attributeList[i]);
61 zapt->attributeList[i]->attributeType =
62 odr_malloc(o, sizeof(int));
63 *zapt->attributeList[i]->attributeType = attr->type;
64 zapt->attributeList[i]->attributeSet = 0;
65 zapt->attributeList[i]->which = Z_AttributeValue_numeric;
66 zapt->attributeList[i]->value.numeric =
67 odr_malloc (o, sizeof(int));
68 *zapt->attributeList[i]->value.numeric = attr->value;
72 zapt->attributeList = odr_nullval();
75 term->which = Z_Term_general;
76 term->u.general = term_octet;
77 term_octet->len = term_octet->size = strlen (p->u.t.term);
78 term_octet->buf = odr_malloc (o, term_octet->len+1);
79 strcpy ((char*) term_octet->buf, p->u.t.term);
83 static Z_Operand *ccl_rpn_simple (ODR o, struct ccl_rpn_node *p)
87 zo = odr_malloc (o, sizeof(*zo));
93 zo->which = Z_Operand_APT;
94 zo->u.attributesPlusTerm = ccl_rpn_term (o, p);
97 zo->which = Z_Operand_resultSetId;
98 zo->u.resultSetId = p->u.setname;
106 static Z_Complex *ccl_rpn_complex (ODR o, struct ccl_rpn_node *p)
111 zc = odr_malloc (o, sizeof(*zc));
113 zo = odr_malloc (o, sizeof(*zo));
120 zo->which = Z_Operator_and;
121 zo->u.and = odr_nullval();
124 zo->which = Z_Operator_or;
125 zo->u.and = odr_nullval();
128 zo->which = Z_Operator_and_not;
129 zo->u.and = odr_nullval();
134 zc->s1 = ccl_rpn_structure (o, p->u.p[0]);
135 zc->s2 = ccl_rpn_structure (o, p->u.p[1]);
139 static Z_RPNStructure *ccl_rpn_structure (ODR o, struct ccl_rpn_node *p)
143 zs = odr_malloc (o, sizeof(*zs));
151 zs->which = Z_RPNStructure_complex;
152 zs->u.complex = ccl_rpn_complex (o, p);
156 zs->which = Z_RPNStructure_simple;
157 zs->u.simple = ccl_rpn_simple (o, p);
165 Z_RPNQuery *ccl_rpn_query (ODR o, struct ccl_rpn_node *p)
169 zq = odr_malloc (o, sizeof(*zq));
171 zq->attributeSetId = NULL;
172 zq->RPNStructure = ccl_rpn_structure (o, p);
176 Z_AttributesPlusTerm *ccl_scan_query (ODR o, struct ccl_rpn_node *p)
178 if (p->kind != CCL_RPN_TERM)
180 return ccl_rpn_term (o, p);