File: cql2pqf.c

package info (click to toggle)
yaz 2.1.18-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 11,988 kB
  • ctags: 11,045
  • sloc: xml: 109,719; ansic: 41,566; sh: 10,625; makefile: 1,115; tcl: 380; yacc: 288
file content (99 lines) | stat: -rw-r--r-- 2,073 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* $Id: cql2pqf.c,v 1.7 2005/06/25 15:46:07 adam Exp $
   Copyright (C) 1995-2005, Index Data ApS
   Index Data Aps

This file is part of the YAZ toolkit.

See the file LICENSE.
*/

#include <stdlib.h>
#include <stdio.h>

#include <yaz/cql.h>
#include <yaz/options.h>

static void usage()
{
    fprintf (stderr, "usage\n cql2pqf [-n <n>] <properties> [<query>]\n");
    exit (1);
}

int main(int argc, char **argv)
{
    cql_transform_t ct;
    int r = 0;
    int i, iterations = 1;
    CQL_parser cp = cql_parser_create();
    char *query = 0;
    char *fname = 0;

    int ret;
    char *arg;

    while ((ret = options("n:", argv, argc, &arg)) != -2)
    {
        switch (ret)
        {
        case 0:
            if (!fname)
                fname = arg;
            else
                query = arg;
            break;
        case 'n':
            iterations = atoi(arg);
            break;
        default:
            usage();
        }
    }
    if (!fname)
        usage();
    ct = cql_transform_open_fname(fname);
    if (!ct)
    {
        fprintf (stderr, "failed to read properties %s\n", fname);
        exit (1);
    }

    if (query)
    {
        for (i = 0; i<iterations; i++)
            r = cql_parser_string(cp, query);
    }
    else
        r = cql_parser_stdio(cp, stdin);

    if (r)
        fprintf (stderr, "Syntax error\n");
    else
    {
        r = cql_transform_FILE(ct, cql_parser_result(cp), stdout);
        printf("\n");
        if (r)
        {
            const char *addinfo;
            cql_transform_error(ct, &addinfo);
            printf ("Transform error %d %s\n", r, addinfo ? addinfo : "");
        }
        else
        {
            FILE *null = fopen("/dev/null", "w");
            for (i = 1; i<iterations; i++)
                cql_transform_FILE(ct, cql_parser_result(cp), null);
            fclose(null);
        }
    }
    cql_transform_close(ct);
    cql_parser_destroy(cp);
    return 0;
}
/*
 * Local variables:
 * c-basic-offset: 4
 * indent-tabs-mode: nil
 * End:
 * vim: shiftwidth=4 tabstop=8 expandtab
 */