94ea25e0df7681a4091abff840479559912a5977
[yaz-moved-to-github.git] / src / cqlstring.c
1 /* $Id: cqlstring.c,v 1.2 2004-10-03 22:34:07 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 for details.
8 */
9
10 /**
11  * \file cqlstring.c
12  * \brief Implements query stream reader that reads from a C string.
13  */
14
15
16 #include <yaz/cql.h>
17
18 struct cql_buf_info {
19     const char *str;
20     int off;
21 };
22
23 int getbuf(void *vp)
24 {
25     struct cql_buf_info *bi = (struct cql_buf_info *) vp;
26     if (bi->str[bi->off] == 0)
27         return 0;
28     return bi->str[bi->off++];
29 }
30
31 void ungetbuf(int b, void *vp)
32 {
33     struct cql_buf_info *bi = (struct cql_buf_info *) vp;
34     if (b)
35         (bi->off--);
36 }
37
38 int cql_parser_string(CQL_parser cp, const char *str)
39 {
40     struct cql_buf_info b;
41
42     b.str = str;
43     b.off = 0;
44     
45     return cql_parser_stream(cp, getbuf, ungetbuf, &b);
46 }
47