Omit YLOG_LOG msg
[yazpp-moved-to-github.git] / src / yaz-cql2rpn.cpp
1 /*
2  * Copyright (c) 1998-2004, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Id: yaz-cql2rpn.cpp,v 1.12 2007-01-12 10:15:06 adam Exp $
6  */
7
8 #include <yaz/log.h>
9 #include <yaz/pquery.h>
10 #include <yazpp/cql2rpn.h>
11
12 using namespace yazpp_1;
13
14 Yaz_cql2rpn::Yaz_cql2rpn()
15 {
16     m_transform = 0;
17 }
18
19 Yaz_cql2rpn::~Yaz_cql2rpn()
20 {
21     if (m_transform)
22         cql_transform_close(m_transform);
23 }
24
25 void Yaz_cql2rpn::set_pqf_file(const char *fname)
26 {
27     if (!m_transform)
28         m_transform = cql_transform_open_fname(fname);
29 }
30
31
32 bool Yaz_cql2rpn::parse_spec_file(const char *fname, int *error)
33 {
34     *error = 0;
35     cql_transform_close(m_transform);
36     m_transform = cql_transform_open_fname(fname);
37     return m_transform ? true : false;
38 }
39
40 int Yaz_cql2rpn::query_transform(const char *cql_query, 
41                                  Z_RPNQuery **rpnquery, ODR o,
42                                  char **addinfop)
43 {
44     const char *addinfo = 0;
45     if (!m_transform)
46         return -3;
47     CQL_parser cp = cql_parser_create();
48
49     int r = cql_parser_string(cp, cql_query);
50     if (r)
51     {
52         r = 10;
53     }
54     else
55     {
56         char rpn_buf[10240];
57         r = cql_transform_buf(m_transform, cql_parser_result(cp), 
58                               rpn_buf, sizeof(rpn_buf)-1);
59         if (!r)
60         {
61             YAZ_PQF_Parser pp = yaz_pqf_create();
62
63             *rpnquery = yaz_pqf_parse(pp, o, rpn_buf);
64             if (!*rpnquery)
65             {
66                 size_t off;
67                 const char *pqf_msg;
68                 int code = yaz_pqf_error(pp, &pqf_msg, &off);
69                 yaz_log(YLOG_WARN, "PQF Parser Error %s (code %d)",
70                         pqf_msg, code);
71                 r = -1;
72             }
73             yaz_pqf_destroy(pp);
74         }
75         else
76         {
77             r = cql_transform_error(m_transform, &addinfo);
78             yaz_log(YLOG_LOG, "CQL Transform Error %d %s", r,
79                     addinfo ? addinfo : "");
80         }
81     }   
82     cql_parser_destroy(cp);
83     if (addinfo)
84         *addinfop = odr_strdup(o, addinfo);
85     else
86         *addinfop = 0;
87     return r;
88 }
89 /*
90  * Local variables:
91  * c-basic-offset: 4
92  * indent-tabs-mode: nil
93  * End:
94  * vim: shiftwidth=4 tabstop=8 expandtab
95  */
96