1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2011 Index Data
3 * See the file LICENSE for details.
12 #include <yaz/rpn2cql.h>
13 #include <yaz/pquery.h>
14 #include <yaz/options.h>
16 static void usage(void)
18 fprintf(stderr, "usage\n cql2pqf [-n <n>] [-r] <properties> [<query>]\n");
22 int main(int argc, char **argv)
25 int i, iterations = 1;
34 while ((ret = options("n:rv", argv, argc, &arg)) != -2)
45 iterations = atoi(arg);
59 if (!strcmp(fname, "-"))
60 ct = cql_transform_create();
62 ct = cql_transform_open_fname(fname);
65 fprintf(stderr, "failed to read properties %s\n", fname);
75 ODR odr = odr_createmem(ODR_ENCODE);
76 YAZ_PQF_Parser pp = yaz_pqf_create();
77 Z_RPNQuery *rpn = yaz_pqf_parse(pp, odr, query);
80 fprintf(stderr, "PQF syntax error\n");
84 int ret = cql_transform_rpn2cql_stream(ct, cql_fputs,
90 int r = cql_transform_error(ct, &addinfo);
91 printf("Transform error %d %s\n", r, addinfo ? addinfo : "");
102 CQL_parser cp = cql_parser_create();
108 printf("Parsing CQL %s\n", query);
109 for (i = 0; i<iterations; i++)
110 r = cql_parser_string(cp, query);
113 r = cql_parser_stdio(cp, stdin);
116 fprintf(stderr, "Syntax error\n");
119 r = cql_transform_FILE(ct, cql_parser_result(cp), stdout);
124 r = cql_transform_error(ct, &addinfo);
125 printf("Transform error %d %s\n", r, addinfo ? addinfo : "");
129 FILE *null = fopen("/dev/null", "w");
130 for (i = 1; i<iterations; i++)
131 cql_transform_FILE(ct, cql_parser_result(cp), null);
135 cql_parser_destroy(cp);
137 cql_transform_close(ct);
143 * c-file-style: "Stroustrup"
144 * indent-tabs-mode: nil
146 * vim: shiftwidth=4 tabstop=8 expandtab