Get rid of a few warnings
[yaz-moved-to-github.git] / util / cql2pqf.c
1 /* $Id: cql2pqf.c,v 1.4 2004-03-16 13:22:16 adam Exp $
2    Copyright (C) 2002-2004
3    Index Data Aps
4
5 This file is part of the YAZ toolkit.
6
7 See the file LICENSE.
8 */
9
10 #include <stdlib.h>
11 #include <stdio.h>
12
13 #include <yaz/cql.h>
14 #include <yaz/options.h>
15
16 static void usage()
17 {
18     fprintf (stderr, "usage\n cql2pqf [-n <n>] <properties> [<query>]\n");
19     exit (1);
20 }
21
22 int main(int argc, char **argv)
23 {
24     cql_transform_t ct;
25     int r;
26     int i, iterations = 1;
27     CQL_parser cp = cql_parser_create();
28     char *query = 0;
29     char *fname = 0;
30
31     int ret;
32     char *arg;
33
34     while ((ret = options("n:", argv, argc, &arg)) != -2)
35     {
36         switch (ret)
37         {
38         case 0:
39             if (!fname)
40                 fname = arg;
41             else
42                 query = arg;
43             break;
44         case 'n':
45             iterations = atoi(arg);
46             break;
47         default:
48             usage();
49         }
50     }
51     if (!fname)
52         usage();
53     ct = cql_transform_open_fname(fname);
54     if (!ct)
55     {
56         fprintf (stderr, "failed to read properties %s\n", fname);
57         exit (1);
58     }
59
60     if (query)
61     {
62         for (i = 0; i<iterations; i++)
63             r = cql_parser_string(cp, query);
64     }
65     else
66         r = cql_parser_stdio(cp, stdin);
67
68     if (r)
69         fprintf (stderr, "Syntax error\n");
70     else
71     {
72         r = cql_transform_FILE(ct, cql_parser_result(cp), stdout);
73         printf("\n");
74         if (r)
75         {
76             const char *addinfo;
77             cql_transform_error(ct, &addinfo);
78             printf ("Transform error %d %s\n", r, addinfo ? addinfo : "");
79         }
80         else
81         {
82             FILE *null = fopen("/dev/null", "w");
83             for (i = 1; i<iterations; i++)
84                 cql_transform_FILE(ct, cql_parser_result(cp), null);
85             fclose(null);
86         }
87     }
88     cql_transform_close(ct);
89     cql_parser_destroy(cp);
90     return 0;
91 }