2 * Copyright (c) 1996-1998, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.13 1998-03-31 15:13:20 adam
8 * Development towards compiled ASN.1.
10 * Revision 1.12 1998/02/11 11:53:36 adam
11 * Changed code so that it compiles as C++.
13 * Revision 1.11 1997/11/24 11:33:57 adam
14 * Using function odr_nullval() instead of global ODR_NULLVAL when
17 * Revision 1.10 1997/09/29 08:58:25 adam
18 * Fixed conversion of trees so that true copy is made.
20 * Revision 1.9 1997/06/23 10:31:25 adam
21 * Added ODR argument to ccl_rpn_query and ccl_scan_query.
23 * Revision 1.8 1996/10/29 13:36:27 adam
35 static Z_RPNStructure *ccl_rpn_structure (ODR o, struct ccl_rpn_node *p);
37 static Z_AttributesPlusTerm *ccl_rpn_term (ODR o, struct ccl_rpn_node *p)
39 struct ccl_rpn_attr *attr;
41 Z_AttributesPlusTerm *zapt;
44 Z_AttributeElement **elements;
46 zapt = (Z_AttributesPlusTerm *)odr_malloc (o, sizeof(*zapt));
49 term_octet = (Odr_oct *)odr_malloc (o, sizeof(*term_octet));
52 term = (Z_Term *)odr_malloc (o, sizeof(*term));
55 for (attr = p->u.t.attr_list; attr; attr = attr->next)
58 elements = (Z_AttributeElement**)odr_nullval();
62 elements = (Z_AttributeElement **)
63 odr_malloc (o, num*sizeof(*elements));
64 for (attr = p->u.t.attr_list; attr; attr = attr->next, i++)
66 elements[i] = (Z_AttributeElement *)
67 odr_malloc (o, sizeof(**elements));
69 elements[i]->attributeType =
70 (int *)odr_malloc(o, sizeof(int));
71 *elements[i]->attributeType = attr->type;
72 elements[i]->attributeSet = 0;
73 elements[i]->which = Z_AttributeValue_numeric;
74 elements[i]->value.numeric =
75 (int *)odr_malloc (o, sizeof(int));
76 *elements[i]->value.numeric = attr->value;
80 zapt->attributes = (Z_AttributeList *)
81 odr_malloc (o, sizeof(*zapt->attributes));
82 zapt->attributes->num_attributes = num;
83 zapt->attributes->attributes = elements;
85 zapt->num_attributes = num;
86 zapt->attributeList = elements;
89 term->which = Z_Term_general;
90 term->u.general = term_octet;
91 term_octet->len = term_octet->size = strlen (p->u.t.term);
92 term_octet->buf = (unsigned char *)odr_malloc (o, term_octet->len+1);
93 strcpy ((char*) term_octet->buf, p->u.t.term);
97 static Z_Operand *ccl_rpn_simple (ODR o, struct ccl_rpn_node *p)
101 zo = (Z_Operand *)odr_malloc (o, sizeof(*zo));
107 zo->which = Z_Operand_APT;
108 zo->u.attributesPlusTerm = ccl_rpn_term (o, p);
111 zo->which = Z_Operand_resultSetId;
112 zo->u.resultSetId = p->u.setname;
120 static Z_Complex *ccl_rpn_complex (ODR o, struct ccl_rpn_node *p)
125 zc = (Z_Complex *)odr_malloc (o, sizeof(*zc));
127 zo = (Z_Operator *)odr_malloc (o, sizeof(*zo));
134 zo->which = Z_Operator_and;
135 zo->u.and = odr_nullval();
138 zo->which = Z_Operator_or;
139 zo->u.and = odr_nullval();
142 zo->which = Z_Operator_and_not;
143 zo->u.and = odr_nullval();
148 zc->s1 = ccl_rpn_structure (o, p->u.p[0]);
149 zc->s2 = ccl_rpn_structure (o, p->u.p[1]);
153 static Z_RPNStructure *ccl_rpn_structure (ODR o, struct ccl_rpn_node *p)
157 zs = (Z_RPNStructure *)odr_malloc (o, sizeof(*zs));
165 zs->which = Z_RPNStructure_complex;
166 zs->u.complex = ccl_rpn_complex (o, p);
170 zs->which = Z_RPNStructure_simple;
171 zs->u.simple = ccl_rpn_simple (o, p);
179 Z_RPNQuery *ccl_rpn_query (ODR o, struct ccl_rpn_node *p)
183 zq = (Z_RPNQuery *)odr_malloc (o, sizeof(*zq));
185 zq->attributeSetId = NULL;
186 zq->RPNStructure = ccl_rpn_structure (o, p);
190 Z_AttributesPlusTerm *ccl_scan_query (ODR o, struct ccl_rpn_node *p)
192 if (p->kind != CCL_RPN_TERM)
194 return ccl_rpn_term (o, p);