projects
/
yaz-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' of ssh://git.indexdata.com:222/home/git/pub/yaz
[yaz-moved-to-github.git]
/
util
/
cql2pqf.c
diff --git
a/util/cql2pqf.c
b/util/cql2pqf.c
index
c2a404d
..
0baa175
100644
(file)
--- a/
util/cql2pqf.c
+++ b/
util/cql2pqf.c
@@
-1,5
+1,5
@@
/* This file is part of the YAZ toolkit.
/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2013 Index Data
+ * Copyright (C) Index Data
* See the file LICENSE for details.
*/
#if HAVE_CONFIG_H
* See the file LICENSE for details.
*/
#if HAVE_CONFIG_H
@@
-10,12
+10,17
@@
#include <stdio.h>
#include <yaz/rpn2cql.h>
#include <stdio.h>
#include <yaz/rpn2cql.h>
+#include <yaz/rpn2solr.h>
#include <yaz/pquery.h>
#include <yaz/options.h>
static void usage(void)
{
#include <yaz/pquery.h>
#include <yaz/options.h>
static void usage(void)
{
- fprintf(stderr, "usage\n cql2pqf [-n <n>] [-r] <properties> [<query>]\n");
+ fprintf(stderr, "usage\n cql2pqf [-n <n>] [-r] [-s] [-S] <properties> "
+ "[<query>]\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);
}
exit(1);
}
@@
-26,12
+31,14
@@
int main(int argc, char **argv)
char *query = 0;
char *fname = 0;
int reverse = 0;
char *query = 0;
char *fname = 0;
int reverse = 0;
- int verbose = 1;
+ int solr = 0;
+ int verbose = 0;
+ int do_strict = 0;
int ret;
char *arg;
int ret;
char *arg;
- while ((ret = options("n:rv", argv, argc, &arg)) != -2)
+ while ((ret = options("n:rsSv", argv, argc, &arg)) != -2)
{
switch (ret)
{
{
switch (ret)
{
@@
-47,6
+54,12
@@
int main(int argc, char **argv)
case 'r':
reverse = 1;
break;
case 'r':
reverse = 1;
break;
+ case 'S':
+ do_strict = 1;
+ break;
+ case 's':
+ solr = 1;
+ break;
case 'v':
verbose = 1;
break;
case 'v':
verbose = 1;
break;
@@
-54,23
+67,32
@@
int main(int argc, char **argv)
usage();
}
}
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)
{
if (reverse)
{
+ char buf[1024];
+
if (!query)
if (!query)
- usage();
- else
+ {
+ if (fgets(buf, sizeof buf, stdin))
+ {
+ if (*buf && buf[strlen(buf)-1] == '\n')
+ buf[strlen(buf)-1] = '\0';
+ query = buf;
+ }
+ }
+ if (query)
{
ODR odr = odr_createmem(ODR_ENCODE);
YAZ_PQF_Parser pp = yaz_pqf_create();
{
ODR odr = odr_createmem(ODR_ENCODE);
YAZ_PQF_Parser pp = yaz_pqf_create();
@@
-81,9
+103,13
@@
int main(int argc, char **argv)
}
else
{
}
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);
stdout, rpn);
-
if (ret)
{
const char *addinfo;
if (ret)
{
const char *addinfo;
@@
-102,6
+128,7
@@
int main(int argc, char **argv)
CQL_parser cp = cql_parser_create();
int r = 0;
CQL_parser cp = cql_parser_create();
int r = 0;
+ cql_parser_strict(cp, do_strict);
if (query)
{
if (verbose)
if (query)
{
if (verbose)
@@
-114,6
+141,10
@@
int main(int argc, char **argv)
if (r)
fprintf(stderr, "Syntax error\n");
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);
else
{
r = cql_transform_FILE(ct, cql_parser_result(cp), stdout);