From cfe5f99ac4ab3fda679a35e5d9591495a5879a05 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 27 Jul 2011 15:07:05 +0200 Subject: [PATCH] cql2xcql: option -s deals with CQL sortkeys --- util/cql2xcql.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/util/cql2xcql.c b/util/cql2xcql.c index 5c70d7a..31a9e51 100644 --- a/util/cql2xcql.c +++ b/util/cql2xcql.c @@ -10,11 +10,12 @@ #include #include +#include #include static void usage(const char *prog) { - fprintf(stderr, "%s: [-c] [-n iterations] [infile]\n", prog); + fprintf(stderr, "%s: [-c] [-n iterations] [-s] [infile]\n", prog); exit(1); } @@ -28,8 +29,9 @@ int main(int argc, char **argv) int convert_to_ccl = 0; char *arg; char *prog = argv[0]; + int do_sortkeys = 0; - while ((ret = options("cn:", argv, argc, &arg)) != -2) + while ((ret = options("cn:s", argv, argc, &arg)) != YAZ_OPTIONS_EOF) { switch (ret) { @@ -42,6 +44,9 @@ int main(int argc, char **argv) case 'n': iterations = atoi(arg); break; + case 's': + do_sortkeys = 1; + break; default: usage(prog); } @@ -67,6 +72,17 @@ int main(int argc, char **argv) } else cql_to_xml_stdio(cql_parser_result(cp), stdout); + if (do_sortkeys) + { + WRBUF w = wrbuf_alloc(); + r = cql_sortby_to_sortkeys(cql_parser_result(cp), + wrbuf_vp_puts, w); + if (r == 0) + printf("sortkeys: %s\n", wrbuf_cstr(w)); + else + fprintf(stderr, "failed to generate sortkeys\n"); + wrbuf_destroy(w); + } } cql_parser_destroy(cp); return 0; -- 1.7.10.4