CQL w/bison on WIN32
[yaz-moved-to-github.git] / include / yaz / cql.h
1 /* $Id: cql.h,v 1.3 2003-02-18 21:27:53 adam Exp $
2    Copyright (C) 2002-2003
3    Index Data Aps
4
5 This file is part of the YAZ toolkit.
6
7 See the file LICENSE.
8 */
9
10 #ifndef CQL_H_INCLUDED
11 #define CQL_H_INCLUDED
12 #include <stdio.h>
13 #include <yaz/yconfig.h>
14
15 typedef struct cql_parser *CQL_parser;
16
17 /**
18  * cql_parser_create:
19  *
20  * creates a CQL parser.
21  *
22  * Returns CQL parser or NULL if parser could not be created.
23  */
24 YAZ_EXPORT 
25 CQL_parser cql_parser_create(void);
26
27 /**
28  * cql_parser_destroy:
29  * @cp:  A CQL parser
30  *
31  * Destroy CQL parser. This function does nothing if
32  * NULL pointer is received.
33  */
34 YAZ_EXPORT 
35 void cql_parser_destroy(CQL_parser cp);
36
37 /**
38  * cql_parser_string:
39  * @cp:  A CQL parser.
40  * @str:  A query string to be parsed.
41  *
42  * Parses a CQL query string.
43  *
44  * Returns 0 if parsing was succesful; non-zero (error code) if
45  * unsuccesful.
46  */
47 YAZ_EXPORT 
48 int cql_parser_string(CQL_parser cp, const char *str);
49
50 /**
51  * cql_parser_stream:
52  * @cp:  A CQL parser.
53  * @getbyte:  Handler to read one character (for parsing).
54  * @ungetbyte: Handler to unread one byte (for parsing).
55  * @client_data:  User data associated with getbyte/ungetbyte handlers.
56  *
57  * Parses a CQL query from a user defined stream.
58  *
59  * Returns 0 if parsing was succesful; non-zero (error code) if
60  * unsuccesful.
61  */
62 YAZ_EXPORT 
63 int cql_parser_stream(CQL_parser cp,
64                       int (*getbyte)(void *client_data),
65                       void (*ungetbyte)(int b, void *client_data),
66                       void *client_data);
67
68 /**
69  * cql_parser_stdio:
70  * @cp:  A CQL parser.
71  * @f: FILE handler in read mode.
72  *
73  * Parses a CQL query from a file.
74  *
75  * Returns 0 if parsing was succesful; non-zero (error code) if
76  * unsuccesful.
77  */
78 YAZ_EXPORT
79 int cql_parser_stdio(CQL_parser cp, FILE *f);
80
81 #define CQL_NODE_ST 1
82 #define CQL_NODE_BOOL 2
83 #define CQL_NODE_MOD 3
84 struct cql_node {
85     int which;
86     union {
87         struct {
88             char *index;
89             char *term;
90             char *relation;
91             struct cql_node *modifiers;
92             struct cql_node *prefixes;
93         } st;
94         struct {
95             char *value;
96             struct cql_node *left;
97             struct cql_node *right;
98             struct cql_node *modifiers;
99             struct cql_node *prefixes;
100         } boolean;
101         struct {
102             char *name;
103             char *value;
104             struct cql_node *next;
105         } mod;
106     } u;
107 };
108
109 struct cql_properties;
110
111 struct cql_buf_write_info {
112     int max;
113     int off;
114     char *buf;
115 };
116
117 YAZ_EXPORT
118 void cql_buf_write_handler (const char *b, void *client_data);
119
120 YAZ_EXPORT
121 void cql_node_print(struct cql_node *cn);
122 YAZ_EXPORT
123 struct cql_node *cql_node_mk_sc(const char *index,
124                                 const char *relation,
125                                 const char *term);
126 YAZ_EXPORT
127 struct cql_node *cql_node_mk_boolean(const char *op);
128 YAZ_EXPORT
129 void cql_node_destroy(struct cql_node *cn);
130 YAZ_EXPORT
131 struct cql_node *cql_node_prefix(struct cql_node *n, 
132                                  const char *prefix,
133                                  const char *uri);
134 YAZ_EXPORT
135 struct cql_node *cql_node_mk_mod(const char *name,
136                                  const char *value);
137
138 YAZ_EXPORT
139 struct cql_node *cql_node_dup (struct cql_node *cp);
140 YAZ_EXPORT
141 struct cql_node *cql_parser_result(CQL_parser cp);
142
143 YAZ_EXPORT
144 void cql_to_xml(struct cql_node *cn, 
145                 void (*pr)(const char *buf, void *client_data),
146                 void *client_data);
147 YAZ_EXPORT
148 void cql_to_xml_stdio(struct cql_node *cn, FILE *f);
149 YAZ_EXPORT
150 int cql_to_xml_buf(struct cql_node *cn, char *out, int max);
151
152 YAZ_EXPORT
153 struct cql_node *cql_node_mk_proxargs(const char *relation,
154                                       const char *distance,
155                                       const char *unit,
156                                       const char *ordering);
157
158
159 YAZ_EXPORT
160 void cql_fputs(const char *buf, void *client_data);
161
162 typedef struct cql_transform_t_ *cql_transform_t;
163
164 YAZ_EXPORT
165 cql_transform_t cql_transform_open_FILE (FILE *f);
166 YAZ_EXPORT
167 cql_transform_t cql_transform_open_fname(const char *fname);
168 YAZ_EXPORT
169 void cql_transform_close(cql_transform_t ct);
170
171 YAZ_EXPORT
172 void cql_transform_pr(cql_transform_t ct,
173                       struct cql_node *cn,
174                       void (*pr)(const char *buf, void *client_data),
175                       void *client_data);
176
177 YAZ_EXPORT
178 int cql_transform_FILE(cql_transform_t ct,
179                        struct cql_node *cn, FILE *f);
180
181 YAZ_EXPORT
182 int cql_transform_buf(cql_transform_t ct,
183                       struct cql_node *cn, char *out, int max);
184 YAZ_EXPORT
185 int cql_transform_error(cql_transform_t ct, const char **addinfo);
186
187 /*
188 10 Illegal query
189 11 Unsupported query type (XCQL vs CQL)
190 12 Too many characters in query
191 13 Unbalanced or illegal use of parentheses
192 14 Unbalanced or illegal use of quotes
193 15 Illegal or unsupported index set
194 16 Illegal or unsupported index
195 17 Illegal or unsupported combination of index and index set
196 18 Illegal or unsupported combination of indexes
197 19 Illegal or unsupported relation
198 20 Illegal or unsupported relation modifier
199 21 Illegal or unsupported combination of relation modifers
200 22 Illegal or unsupported combination of relation and index
201 23 Too many characters in term
202 24 Illegal combination of relation and term
203 25 Special characters not quoted in term
204 26 Non special character escaped in term
205 27 Empty term unsupported
206 28 Masking character not supported
207 29 Masked words too short
208 30 Too many masking characters in term
209 31 Anchoring character not supported
210 32 Anchoring character in illegal or unsupported position
211 33 Combination of proximity/adjacency and masking characters not supported
212 34 Combination of proximity/adjacency and anchoring characters not supported
213 35 Terms only exclusion (stop) words
214 36 Term in invalid format for index or relation
215 37 Illegal or unsupported boolean operator
216 38 Too many boolean operators in query
217 39 Proximity not supported
218 40 Illegal or unsupported proximity relation
219 41 Illegal or unsupported proximity distance
220 42 Illegal or unsupported proximity unit
221 43 Illegal or unsupported proximity ordering
222 44 Illegal or unsupported combination of proximity modifiers
223 45 Index set name (prefix) assigned to multiple identifiers
224 */
225
226 #endif
227 /* CQL_H_INCLUDED */