2 * Copyright (c) 1995-2001, Index Data
3 * See the file LICENSE for details.
5 * $Id: query.c,v 1.1 2003-10-27 12:21:35 adam Exp $
13 #include <yaz/proto.h>
15 static Z_Complex *makecomplex(ODR o, char **buf);
16 static Z_Operand *makesimple(ODR o, char **buf);
17 Z_RPNStructure *makerpn(ODR o, char **buf);
19 void skip_spaces(char**p)
21 while (**p && isspace(**p))
25 static Z_Operand *makesimple(ODR o, char **buf)
28 Z_AttributesPlusTerm *t;
31 r = odr_malloc(o, sizeof(*r));
32 if (**buf == 's' && *((*buf) + 1) == '=')
34 char *b = odr_malloc(o, 100);
36 r->which = Z_Operand_resultSetId;
40 while (**buf && !isspace(**buf))
45 else if (**buf != '"')
48 r->which = Z_Operand_APT;
49 r->u.attributesPlusTerm = t = odr_malloc(o, sizeof(*t));
50 t->attributes = odr_malloc(o, sizeof(*t));
51 t->attributes->num_attributes = 0;
52 t->attributes->attributes = 0;
53 t->term = odr_malloc(o, sizeof(*t->term));
54 t->term->which = Z_Term_general;
55 t->term->u.general = odr_malloc(o, sizeof(Odr_oct));
56 t->term->u.general->buf = odr_malloc(o, 100);
57 t->term->u.general->size = 100;
58 t->term->u.general->len = 0;
59 b = (char*) t->term->u.general->buf;
60 while (**buf && **buf != '"')
63 t->term->u.general->len++;
71 static Z_Complex *makecomplex(ODR o, char **buf)
76 r = odr_malloc(o, sizeof(*r));
77 r->roperator = odr_malloc(o, sizeof(*r->roperator));
80 while (**buf && !isspace(**buf))
83 if (!strcmp(op, "and"))
84 r->roperator->which = Z_Operator_and;
85 else if (!strcmp(op, "or"))
86 r->roperator->which = Z_Operator_or;
87 else if (!strcmp(op, "not"))
88 r->roperator->which = Z_Operator_and_not;
89 r->roperator->u.and = "";
90 while (**buf && !isspace(**buf))
92 if (!(r->s1 = makerpn(o, buf)))
94 if (!(r->s2 = makerpn(o, buf)))
99 Z_RPNStructure *makerpn(ODR o, char **buf)
103 r = odr_malloc(o, sizeof(*r));
105 if (**buf == '"' || **buf == 's')
107 r->which = Z_RPNStructure_simple;
108 if (!(r->u.simple = makesimple(o, buf)))
112 r->which = Z_RPNStructure_complex;
113 if (!(r->u.complex = makecomplex(o, buf)))