1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2008 Index Data
3 * See the file LICENSE for details.
8 * \brief Implements RPN to CQL conversion
10 * Evaluation order of rules:
24 #include <yaz/rpn2cql.h>
25 #include <yaz/xmalloc.h>
26 #include <yaz/diagbib1.h>
27 #include <yaz/z-core.h>
28 #include <yaz/wrbuf.h>
30 static int rpn2cql_simple(cql_transform_t ct,
31 void (*pr)(const char *buf, void *client_data),
36 if (q->which != Z_Operand_APT)
39 cql_transform_set_error(ct, YAZ_BIB1_RESULT_SET_UNSUPP_AS_A_SEARCH_TERM, 0);
43 Z_AttributesPlusTerm *apt = q->u.attributesPlusTerm;
44 Z_Term *term = apt->term;
45 Z_AttributeList *attributes = apt->attributes;
46 WRBUF w = wrbuf_alloc();
51 wrbuf_write(w, (const char *) term->u.general->buf, term->u.general->len);
54 wrbuf_printf(w, "%d", *term->u.numeric);
56 case Z_Term_characterString:
57 wrbuf_puts(w, term->u.characterString);
61 cql_transform_set_error(ct, YAZ_BIB1_TERM_TYPE_UNSUPP, 0);
64 pr(wrbuf_cstr(w), client_data);
70 static int rpn2cql_structure(cql_transform_t ct,
71 void (*pr)(const char *buf, void *client_data),
73 Z_RPNStructure *q, int nested)
75 if (q->which == Z_RPNStructure_simple)
76 return rpn2cql_simple(ct, pr, client_data, q->u.simple);
79 Z_Operator *op = q->u.complex->roperator;
85 r = rpn2cql_structure(ct, pr, client_data, q->u.complex->s1, 1);
91 pr(" and ", client_data);
94 pr(" or ", client_data);
96 case Z_Operator_and_not:
97 pr(" not ", client_data);
100 cql_transform_set_error(ct, YAZ_BIB1_UNSUPP_SEARCH, 0);
103 r = rpn2cql_structure(ct, pr, client_data, q->u.complex->s2, 1);
105 pr(")", client_data);
110 int cql_transform_rpn2cql(cql_transform_t ct,
111 void (*pr)(const char *buf, void *client_data),
115 cql_transform_set_error(ct, 0, 0);
116 return rpn2cql_structure(ct, pr, client_data, q->RPNStructure, 0);
123 * indent-tabs-mode: nil
125 * vim: shiftwidth=4 tabstop=8 expandtab