2 * Copyright (c) 1996-2003, Index Data.
3 * See the file LICENSE for details.
5 * $Id: yaz-ccl.c,v 1.18 2003-01-06 08:20:29 adam Exp $
12 #include <yaz/yaz-ccl.h>
13 #include <yaz/pquery.h>
15 Z_RPNQuery *ccl_rpn_query (ODR o, struct ccl_rpn_node *p)
17 YAZ_PQF_Parser parser = yaz_pqf_create();
18 WRBUF wr = wrbuf_alloc();
23 q = yaz_pqf_parse(parser, o, wrbuf_buf(wr));
26 yaz_pqf_destroy(parser);
30 Z_AttributesPlusTerm *ccl_scan_query (ODR o, struct ccl_rpn_node *p)
32 YAZ_PQF_Parser parser = yaz_pqf_create();
33 WRBUF wr = wrbuf_alloc();
34 Z_AttributesPlusTerm *q;
39 q = yaz_pqf_scan(parser, o, &setp, wrbuf_buf(wr));
42 yaz_pqf_destroy(parser);
46 static void ccl_pquery_complex (WRBUF w, struct ccl_rpn_node *p)
51 wrbuf_puts(w, "@and ");
54 wrbuf_puts(w, "@or ");
57 wrbuf_puts(w, "@not ");
60 if (p->u.p[2] && p->u.p[2]->kind == CCL_RPN_TERM)
62 const char *cp = p->u.p[2]->u.t.term;
63 /* exlusion distance ordered relation which-code unit-code */
66 /* word order specified */
68 wrbuf_printf(w, "@prox 0 %s 1 2 k 2 ", cp+1);
70 wrbuf_printf(w, "@prox 0 1 1 2 k 2 ");
74 /* word order not specified */
76 wrbuf_printf(w, "@prox 0 %s 0 2 k 2 ", cp+1);
78 wrbuf_printf(w, "@prox 0 1 0 2 k 2 ");
82 wrbuf_puts(w, "@prox 0 2 0 1 k 2 ");
85 wrbuf_puts(w, "@ bad op (unknown) ");
87 ccl_pquery(w, p->u.p[0]);
88 ccl_pquery(w, p->u.p[1]);
91 void ccl_pquery (WRBUF w, struct ccl_rpn_node *p)
93 struct ccl_rpn_attr *att;
102 ccl_pquery_complex (w, p);
105 wrbuf_puts (w, "@set ");
106 wrbuf_puts (w, p->u.setname);
110 for (att = p->u.t.attr_list; att; att = att->next)
113 wrbuf_puts (w, "@attr ");
116 wrbuf_puts (w, att->set);
119 sprintf(tmpattr, "%d=%d ", att->type, att->value);
120 wrbuf_puts (w, tmpattr);
122 for (cp = p->u.t.term; *cp; cp++)
124 if (*cp == ' ' || *cp == '\\')
125 wrbuf_putc (w, '\\');