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