2 * Copyright (c) 1995-2007, Index Data
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Index Data nor the names of its contributors
13 * may be used to endorse or promote products derived from this
14 * software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 /* $Id: cql.h,v 1.17 2007-01-03 08:42:14 adam Exp $ */
30 \brief Header with public definitions about CQL.
33 #ifndef CQL_H_INCLUDED
34 #define CQL_H_INCLUDED
40 /** CQL parser handle */
41 typedef struct cql_parser *CQL_parser;
44 * Creates a CQL parser.
45 * Returns CQL parser handle or NULL if parser could not be created.
48 CQL_parser cql_parser_create(void);
51 * Destroys a CQL parser.
53 * This function does nothing if NULL if received.
56 void cql_parser_destroy(CQL_parser cp);
59 * Parses a CQL string query.
61 * Returns 0 if on success; non-zero (error code) on failure.
64 int cql_parser_string(CQL_parser cp, const char *str);
67 * Parses a CQL query - streamed query.
69 * This function is similar to cql_parser_string but takes a
70 * functions to read each query character from a stream.
72 * The functions pointers getbytes, ungetbyte are similar to
73 * that known from stdios getc, ungetc.
75 * Returns 0 if on success; non-zero (error code) on failure.
78 int cql_parser_stream(CQL_parser cp,
79 int (*getbyte)(void *client_data),
80 void (*ungetbyte)(int b, void *client_data),
84 * Parses a CQL query from a FILE handle.
86 * This function is similar to cql_parser_string but reads from
87 * stdio FILE handle instead.
89 * Returns 0 if on success; non-zero (error code) on failure.
92 int cql_parser_stdio(CQL_parser cp, FILE *f);
95 * The node in a CQL parse tree.
98 #define CQL_NODE_BOOL 2
103 /** which == CQL_NODE_ST */
107 /** CQL index URI or NULL if no URI */
113 /** relation URL or NULL if no relation URI) */
115 /** relation modifiers */
116 struct cql_node *modifiers;
118 /** which == CQL_NODE_BOOL */
120 /** operator name "and", "or", ... */
123 struct cql_node *left;
125 struct cql_node *right;
126 /** modifiers (NULL for no list) */
127 struct cql_node *modifiers;
133 * Private structure that describes the CQL properties (profile)
135 struct cql_properties;
138 * Structure used by cql_buf_write_handlre
140 struct cql_buf_write_info {
147 * Handler for cql_buf_write_info *
150 void cql_buf_write_handler (const char *b, void *client_data);
153 * Prints a CQL node and all sub nodes. Hence this function
154 * prints the parse tree which is as returned by cql_parser_result.
157 void cql_node_print(struct cql_node *cn);
160 * This function creates a search clause node (st).
163 struct cql_node *cql_node_mk_sc(NMEM nmem, const char *index,
164 const char *relation, const char *term);
167 * This function applies a prefix+uri to "unresolved" index and relation
170 * "unresolved" URIs are those nodes where member index_uri / relation_uri
174 struct cql_node *cql_apply_prefix(NMEM nmem, struct cql_node *cn,
175 const char *prefix, const char *uri);
178 * This function creates a boolean node.
181 struct cql_node *cql_node_mk_boolean(NMEM nmem, const char *op);
184 * Destroys a node and its children.
187 void cql_node_destroy(struct cql_node *cn);
190 * Duplicate a node (returns a copy of supplied node) .
193 struct cql_node *cql_node_dup (NMEM nmem, struct cql_node *cp);
196 * This function returns the parse tree of the most recently parsed
199 * The function returns NULL if most recently parse failed.
202 struct cql_node *cql_parser_result(CQL_parser cp);
205 * This function converts a CQL node tree to XCQL and writes the
206 * resulting XCQL to a user-defined output stream.
209 void cql_to_xml(struct cql_node *cn,
210 void (*pr)(const char *buf, void *client_data),
213 * This function converts a CQL node tree to XCQL and writes the
214 * resulting XCQL to a FILE handle (stdio)
217 void cql_to_xml_stdio(struct cql_node *cn, FILE *f);
220 * This function converts a CQL node tree to XCQL and writes
221 * the resulting XCQL to a buffer
224 int cql_to_xml_buf(struct cql_node *cn, char *out, int max);
227 * Utility function that prints to a FILE.
230 void cql_fputs(const char *buf, void *client_data);
233 * The CQL transform handle. The transform describes how to
234 * convert from CQL to PQF (Type-1 AKA RPN).
236 typedef struct cql_transform_t_ *cql_transform_t;
239 * Creates a CQL transform handle. The transformation spec is read from
240 * a FILE handle (which is assumed opened in read mode).
243 cql_transform_t cql_transform_open_FILE (FILE *f);
246 * Creates a CQL transform handle. The transformation spec is read from
247 * a file with the filename given.
250 cql_transform_t cql_transform_open_fname(const char *fname);
253 * Destroys a CQL transform handle.
256 void cql_transform_close(cql_transform_t ct);
259 * Performs a CQL transform to PQF given a CQL node tree and a CQL
260 * transformation handle. The result is written to a user-defined stream.
263 void cql_transform_pr(cql_transform_t ct,
265 void (*pr)(const char *buf, void *client_data),
269 * Performs a CQL transform to PQF given a CQL node tree and a CQL
270 * transformation handle. The result is written to a file specified by
271 * FILE handle (which must be opened for writing).
274 int cql_transform_FILE(cql_transform_t ct,
275 struct cql_node *cn, FILE *f);
278 * Performs a CQL transform to PQF given a CQL node tree and a CQL
279 * transformation handle. The result is written to a buffer.
282 int cql_transform_buf(cql_transform_t ct,
283 struct cql_node *cn, char *out, int max);
285 * Returns error code and additional information from last transformation.
286 * Performs a CQL transform given a CQL node tree and a CQL transformation.
289 int cql_transform_error(cql_transform_t ct, const char **addinfo);
292 * Returns the CQL message corresponding to a given error code.
295 const char *cql_strerror(int code);
298 * Returns the standard CQL context set URI.
301 const char *cql_uri(void);
304 * Compares two CQL strings (for relations, operators, etc)
305 * (unfortunately defined as case-insensitive unlike XML etc)
308 int cql_strcmp(const char *s1, const char *s2);
311 * Compares two CQL strings at most n bytes
312 * (unfortunately defined as case-insensitive unlike XML etc)
315 int cql_strncmp(const char *s1, const char *s2, size_t n);
324 * indent-tabs-mode: nil
326 * vim: shiftwidth=4 tabstop=8 expandtab