2 * Copyright (c) 1995-1999, Index Data
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.3 1999-12-16 23:36:19 adam
8 * Implemented ILL protocol. Minor updates ASN.1 compiler.
10 * Revision 1.2 1999/06/09 14:01:33 adam
11 * Fixed for compiled ASN.1.
13 * Revision 1.1 1999/06/08 10:10:16 adam
14 * New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree.
16 * Revision 1.3 1996/01/02 11:46:56 quinn
17 * Changed 'operator' to 'roperator' to avoid C++ conflict.
19 * Revision 1.2 1995/05/16 08:51:14 quinn
20 * License, documentation, and memory fixes
22 * Revision 1.1 1995/04/10 10:28:47 quinn
23 * Added copy of CCL and MARC display
33 #include <yaz/proto.h>
35 static Z_Complex *makecomplex(ODR o, char **buf);
36 static Z_Operand *makesimple(ODR o, char **buf);
37 Z_RPNStructure *makerpn(ODR o, char **buf);
39 void skip_spaces(char**p)
41 while (**p && isspace(**p))
45 static Z_Operand *makesimple(ODR o, char **buf)
48 Z_AttributesPlusTerm *t;
51 r = odr_malloc(o, sizeof(*r));
52 if (**buf == 's' && *((*buf) + 1) == '=')
54 char *b = odr_malloc(o, 100);
56 r->which = Z_Operand_resultSetId;
60 while (**buf && !isspace(**buf))
65 else if (**buf != '"')
68 r->which = Z_Operand_APT;
69 r->u.attributesPlusTerm = t = odr_malloc(o, sizeof(*t));
71 t->attributes = odr_malloc(o, sizeof(*t));
72 t->attributes->num_attributes = 0;
73 t->attributes->attributes = 0;
75 t->num_attributes = 0;
78 t->term = odr_malloc(o, sizeof(*t->term));
79 t->term->which = Z_Term_general;
80 t->term->u.general = odr_malloc(o, sizeof(Odr_oct));
81 t->term->u.general->buf = odr_malloc(o, 100);
82 t->term->u.general->size = 100;
83 t->term->u.general->len = 0;
84 b = (char*) t->term->u.general->buf;
85 while (**buf && **buf != '"')
88 t->term->u.general->len++;
96 static Z_Complex *makecomplex(ODR o, char **buf)
101 r = odr_malloc(o, sizeof(*r));
102 r->roperator = odr_malloc(o, sizeof(*r->roperator));
105 while (**buf && !isspace(**buf))
106 *(b++) = *((*buf)++);
108 if (!strcmp(op, "and"))
109 r->roperator->which = Z_Operator_and;
110 else if (!strcmp(op, "or"))
111 r->roperator->which = Z_Operator_or;
112 else if (!strcmp(op, "not"))
113 r->roperator->which = Z_Operator_and_not;
114 r->roperator->u.and = "";
115 while (**buf && !isspace(**buf))
117 if (!(r->s1 = makerpn(o, buf)))
119 if (!(r->s2 = makerpn(o, buf)))
124 Z_RPNStructure *makerpn(ODR o, char **buf)
128 r = odr_malloc(o, sizeof(*r));
130 if (**buf == '"' || **buf == 's')
132 r->which = Z_RPNStructure_simple;
133 if (!(r->u.simple = makesimple(o, buf)))
137 r->which = Z_RPNStructure_complex;
138 if (!(r->u.complex = makecomplex(o, buf)))