2 * Copyright (c) 1996-1997, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.12 1998-02-11 11:53:36 adam
8 * Changed code so that it compiles as C++.
10 * Revision 1.11 1997/11/24 11:33:57 adam
11 * Using function odr_nullval() instead of global ODR_NULLVAL when
14 * Revision 1.10 1997/09/29 08:58:25 adam
15 * Fixed conversion of trees so that true copy is made.
17 * Revision 1.9 1997/06/23 10:31:25 adam
18 * Added ODR argument to ccl_rpn_query and ccl_scan_query.
20 * Revision 1.8 1996/10/29 13:36:27 adam
32 static Z_RPNStructure *ccl_rpn_structure (ODR o, struct ccl_rpn_node *p);
34 static Z_AttributesPlusTerm *ccl_rpn_term (ODR o, struct ccl_rpn_node *p)
36 struct ccl_rpn_attr *attr;
38 Z_AttributesPlusTerm *zapt;
42 zapt = (Z_AttributesPlusTerm *)odr_malloc (o, sizeof(*zapt));
45 term_octet = (Odr_oct *)odr_malloc (o, sizeof(*term_octet));
48 term = (Z_Term *)odr_malloc (o, sizeof(*term));
51 for (attr = p->u.t.attr_list; attr; attr = attr->next)
53 zapt->num_attributes = num;
57 zapt->attributeList = (Z_AttributeElement **)odr_malloc (o, num*sizeof(*zapt->attributeList));
58 assert (zapt->attributeList);
59 for (attr = p->u.t.attr_list; attr; attr = attr->next, i++)
61 zapt->attributeList[i] =
62 (Z_AttributeElement *)odr_malloc (o, sizeof(**zapt->attributeList));
63 assert (zapt->attributeList[i]);
64 zapt->attributeList[i]->attributeType =
65 (int *)odr_malloc(o, sizeof(int));
66 *zapt->attributeList[i]->attributeType = attr->type;
67 zapt->attributeList[i]->attributeSet = 0;
68 zapt->attributeList[i]->which = Z_AttributeValue_numeric;
69 zapt->attributeList[i]->value.numeric =
70 (int *)odr_malloc (o, sizeof(int));
71 *zapt->attributeList[i]->value.numeric = attr->value;
75 zapt->attributeList = (Z_AttributeElement**)odr_nullval();
78 term->which = Z_Term_general;
79 term->u.general = term_octet;
80 term_octet->len = term_octet->size = strlen (p->u.t.term);
81 term_octet->buf = (unsigned char *)odr_malloc (o, term_octet->len+1);
82 strcpy ((char*) term_octet->buf, p->u.t.term);
86 static Z_Operand *ccl_rpn_simple (ODR o, struct ccl_rpn_node *p)
90 zo = (Z_Operand *)odr_malloc (o, sizeof(*zo));
96 zo->which = Z_Operand_APT;
97 zo->u.attributesPlusTerm = ccl_rpn_term (o, p);
100 zo->which = Z_Operand_resultSetId;
101 zo->u.resultSetId = p->u.setname;
109 static Z_Complex *ccl_rpn_complex (ODR o, struct ccl_rpn_node *p)
114 zc = (Z_Complex *)odr_malloc (o, sizeof(*zc));
116 zo = (Z_Operator *)odr_malloc (o, sizeof(*zo));
123 zo->which = Z_Operator_and;
124 zo->u.and = odr_nullval();
127 zo->which = Z_Operator_or;
128 zo->u.and = odr_nullval();
131 zo->which = Z_Operator_and_not;
132 zo->u.and = odr_nullval();
137 zc->s1 = ccl_rpn_structure (o, p->u.p[0]);
138 zc->s2 = ccl_rpn_structure (o, p->u.p[1]);
142 static Z_RPNStructure *ccl_rpn_structure (ODR o, struct ccl_rpn_node *p)
146 zs = (Z_RPNStructure *)odr_malloc (o, sizeof(*zs));
154 zs->which = Z_RPNStructure_complex;
155 zs->u.complex = ccl_rpn_complex (o, p);
159 zs->which = Z_RPNStructure_simple;
160 zs->u.simple = ccl_rpn_simple (o, p);
168 Z_RPNQuery *ccl_rpn_query (ODR o, struct ccl_rpn_node *p)
172 zq = (Z_RPNQuery *)odr_malloc (o, sizeof(*zq));
174 zq->attributeSetId = NULL;
175 zq->RPNStructure = ccl_rpn_structure (o, p);
179 Z_AttributesPlusTerm *ccl_scan_query (ODR o, struct ccl_rpn_node *p)
181 if (p->kind != CCL_RPN_TERM)
183 return ccl_rpn_term (o, p);