Happy new year
[yaz-moved-to-github.git] / src / cqlstring.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 cqlstring.c
8  * \brief Implements query stream reader that reads from a C string.
9  */
10
11 #include <yaz/cql.h>
12
13 struct cql_buf_info {
14     const char *str;
15     int off;
16 };
17
18 static int getbuf(void *vp)
19 {
20     struct cql_buf_info *bi = (struct cql_buf_info *) vp;
21     if (bi->str[bi->off] == 0)
22         return 0;
23     return bi->str[bi->off++];
24 }
25
26 static void ungetbuf(int b, void *vp)
27 {
28     struct cql_buf_info *bi = (struct cql_buf_info *) vp;
29     if (b)
30         (bi->off--);
31 }
32
33 int cql_parser_string(CQL_parser cp, const char *str)
34 {
35     struct cql_buf_info b;
36
37     b.str = str;
38     b.off = 0;
39     
40     return cql_parser_stream(cp, getbuf, ungetbuf, &b);
41 }
42
43 /*
44  * Local variables:
45  * c-basic-offset: 4
46  * indent-tabs-mode: nil
47  * End:
48  * vim: shiftwidth=4 tabstop=8 expandtab
49  */
50