From: Adam Dickmeiss Date: Thu, 10 Apr 2014 09:49:33 +0000 (+0200) Subject: cql2pqf allows RPN to Solr conversion X-Git-Tag: v5.1.0~10^2~2 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=d93ce9819697b5724be8c9a02e41d0eaf818f13b;p=yaz-moved-to-github.git cql2pqf allows RPN to Solr conversion --- diff --git a/util/cql2pqf.c b/util/cql2pqf.c index eec4767..0baa175 100644 --- a/util/cql2pqf.c +++ b/util/cql2pqf.c @@ -10,13 +10,17 @@ #include #include +#include #include #include static void usage(void) { - fprintf(stderr, "usage\n cql2pqf [-n ] [-r] [-S] " + fprintf(stderr, "usage\n cql2pqf [-n ] [-r] [-s] [-S] " "[]\n"); + fprintf(stderr, " -r reverse conversion (RPN to Solr/CQL)\n"); + fprintf(stderr, " -s Solr instead of CQL\n"); + fprintf(stderr, " -S strict CQL 2.0\n"); exit(1); } @@ -27,13 +31,14 @@ int main(int argc, char **argv) char *query = 0; char *fname = 0; int reverse = 0; + int solr = 0; int verbose = 0; int do_strict = 0; int ret; char *arg; - while ((ret = options("n:rSv", argv, argc, &arg)) != -2) + while ((ret = options("n:rsSv", argv, argc, &arg)) != -2) { switch (ret) { @@ -52,6 +57,9 @@ int main(int argc, char **argv) case 'S': do_strict = 1; break; + case 's': + solr = 1; + break; case 'v': verbose = 1; break; @@ -59,17 +67,17 @@ int main(int argc, char **argv) usage(); } } - if (!fname) - usage(); - if (!strcmp(fname, "-")) - ct = cql_transform_create(); - else - ct = cql_transform_open_fname(fname); - if (!ct) + if (fname) { - fprintf(stderr, "failed to read properties %s\n", fname); - exit(1); + ct = cql_transform_open_fname(fname); + if (!ct) + { + fprintf(stderr, "failed to read properties %s\n", fname); + exit(1); + } } + else + ct = cql_transform_create(); if (reverse) { @@ -78,7 +86,11 @@ int main(int argc, char **argv) if (!query) { if (fgets(buf, sizeof buf, stdin)) + { + if (*buf && buf[strlen(buf)-1] == '\n') + buf[strlen(buf)-1] = '\0'; query = buf; + } } if (query) { @@ -91,9 +103,13 @@ int main(int argc, char **argv) } else { - int ret = cql_transform_rpn2cql_stream(ct, cql_fputs, + int ret = 0; + if (solr) + ret = solr_transform_rpn2solr_stream(ct, cql_fputs, + stdout, rpn); + else + ret = cql_transform_rpn2cql_stream(ct, cql_fputs, stdout, rpn); - if (ret) { const char *addinfo; @@ -125,6 +141,10 @@ int main(int argc, char **argv) if (r) fprintf(stderr, "Syntax error\n"); + else if (solr) + { + printf("CQL to Solr not supported (supported is reverse -r)\n"); + } else { r = cql_transform_FILE(ct, cql_parser_result(cp), stdout);