1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
12 #include <yaz/rpn2cql.h>
13 #include <yaz/rpn2solr.h>
14 #include <yaz/pquery.h>
15 #include <yaz/options.h>
17 static void usage(void)
19 fprintf(stderr, "usage\n cql2pqf [-n <n>] [-r] [-s] [-S] <properties> "
21 fprintf(stderr, " -r reverse conversion (RPN to Solr/CQL)\n");
22 fprintf(stderr, " -s Solr instead of CQL\n");
23 fprintf(stderr, " -S strict CQL 2.0\n");
27 int main(int argc, char **argv)
30 int i, iterations = 1;
41 while ((ret = options("n:rsSv", argv, argc, &arg)) != -2)
52 iterations = atoi(arg);
72 ct = cql_transform_open_fname(fname);
75 fprintf(stderr, "failed to read properties %s\n", fname);
80 ct = cql_transform_create();
88 if (fgets(buf, sizeof buf, stdin))
90 if (*buf && buf[strlen(buf)-1] == '\n')
91 buf[strlen(buf)-1] = '\0';
97 ODR odr = odr_createmem(ODR_ENCODE);
98 YAZ_PQF_Parser pp = yaz_pqf_create();
99 Z_RPNQuery *rpn = yaz_pqf_parse(pp, odr, query);
102 fprintf(stderr, "PQF syntax error\n");
108 ret = solr_transform_rpn2solr_stream(ct, cql_fputs,
111 ret = cql_transform_rpn2cql_stream(ct, cql_fputs,
116 int r = cql_transform_error(ct, &addinfo);
117 printf("Transform error %d %s\n", r, addinfo ? addinfo : "");
128 CQL_parser cp = cql_parser_create();
131 cql_parser_strict(cp, do_strict);
135 printf("Parsing CQL %s\n", query);
136 for (i = 0; i<iterations; i++)
137 r = cql_parser_string(cp, query);
140 r = cql_parser_stdio(cp, stdin);
143 fprintf(stderr, "Syntax error\n");
146 printf("CQL to Solr not supported (supported is reverse -r)\n");
150 r = cql_transform_FILE(ct, cql_parser_result(cp), stdout);
155 r = cql_transform_error(ct, &addinfo);
156 printf("Transform error %d %s\n", r, addinfo ? addinfo : "");
160 FILE *null = fopen("/dev/null", "w");
161 for (i = 1; i<iterations; i++)
162 cql_transform_FILE(ct, cql_parser_result(cp), null);
166 cql_parser_destroy(cp);
168 cql_transform_close(ct);
174 * c-file-style: "Stroustrup"
175 * indent-tabs-mode: nil
177 * vim: shiftwidth=4 tabstop=8 expandtab