b3cc23c33fee2a70c1e5a0aee0628d0e3890a185
[yaz-moved-to-github.git] / src / cqlstdio.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 /**
7  * \file cqlstdio.c
8  * \brief Implements query stream reading using FILE handle.
9  */
10
11 #include <yaz/cql.h>
12
13 int getbyte_stream(void *client_data)
14 {
15     FILE *f = (FILE*) client_data;
16
17     int c = fgetc(f);
18     if (c == EOF)
19         return 0;
20     return c;
21 }
22
23 void ungetbyte_stream (int c, void *client_data)
24 {
25     FILE *f = (FILE*) client_data;
26
27     if (c == 0)
28         c = EOF;
29     ungetc(c, f);
30 }
31
32 int cql_parser_stdio(CQL_parser cp, FILE *f)
33 {
34     return cql_parser_stream(cp, getbyte_stream, ungetbyte_stream, f);
35 }
36
37
38 /*
39  * Local variables:
40  * c-basic-offset: 4
41  * indent-tabs-mode: nil
42  * End:
43  * vim: shiftwidth=4 tabstop=8 expandtab
44  */
45