5abdb57524b26b1baf5b8cf1382892b6c8704ae0
[yaz-moved-to-github.git] / util / cql2xcql.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2009 Index Data
3  * See the file LICENSE for details.
4  */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8
9 #include <yaz/cql.h>
10 #include <yaz/options.h>
11
12 int main(int argc, char **argv)
13 {
14     CQL_parser cp;
15     int r = 0;
16     const char *fname = 0;
17     int iterations = 1;
18     int ret;
19     char *arg;
20
21     while ((ret = options("n:", argv, argc, &arg)) != -2)
22     {
23         switch (ret)
24         {
25         case 0:
26             fname = arg;
27             break;
28         case 'n':
29             iterations = atoi(arg);
30             break;
31         }
32     }
33
34     cp = cql_parser_create();
35     if (fname)
36     {
37         int i;
38         for (i = 0; i<iterations; i++)
39             r = cql_parser_string(cp, fname);
40     }
41     else
42         r = cql_parser_stdio(cp, stdin);
43     if (r)
44         fprintf (stderr, "Syntax error\n");
45     else
46         cql_to_xml_stdio(cql_parser_result(cp), stdout);
47     cql_parser_destroy(cp);
48     return 0;
49 }
50 /*
51  * Local variables:
52  * c-basic-offset: 4
53  * c-file-style: "Stroustrup"
54  * indent-tabs-mode: nil
55  * End:
56  * vim: shiftwidth=4 tabstop=8 expandtab
57  */
58