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.20 2008-01-06 16:22:02 adam Exp $ */
30 \brief Header with public definitions about CQL.
33 #ifndef CQL_H_INCLUDED
34 #define CQL_H_INCLUDED
40 /** \brief CQL parser handle (opaque pointer) */
41 typedef struct cql_parser *CQL_parser;
43 /** \brief creates a CQL parser.
46 Returns CQL parser or NULL if parser could not be created.
49 CQL_parser cql_parser_create(void);
51 /** \brief destroys a CQL parser.
54 This function does nothing if NULL if received.
57 void cql_parser_destroy(CQL_parser cp);
59 /** \brief parses a CQL query (string)
66 int cql_parser_string(CQL_parser cp, const char *str);
68 /** \brief parses CQL query (query stream)
70 \param getbyte function which reads one character from stream
71 \param ungetbyte function which unreads one character from stream
72 \param client_data data to be passed to stream functions
76 This function is similar to cql_parser_string but takes a
77 functions to read each query character from a stream.
79 The functions pointers getbytes, ungetbyte are similar to
80 that known from stdios getc, ungetc.
83 int cql_parser_stream(CQL_parser cp,
84 int (*getbyte)(void *client_data),
85 void (*ungetbyte)(int b, void *client_data),
88 /** \brief parses CQL query (from FILE)
90 \param f file where query is read from
94 This function is similar to cql_parser_string but reads from
95 stdio FILE handle instead.
98 int cql_parser_stdio(CQL_parser cp, FILE *f);
100 /** \brief Node type: search term */
101 #define CQL_NODE_ST 1
102 /** \brief Node type: boolean */
103 #define CQL_NODE_BOOL 2
104 /** \brief CQL parse tree (node)
110 /** which == CQL_NODE_ST */
114 /** CQL index URI or NULL if no URI */
120 /** relation URL or NULL if no relation URI) */
122 /** relation modifiers */
123 struct cql_node *modifiers;
125 struct cql_node *extra_terms;
127 /** which == CQL_NODE_BOOL */
129 /** operator name "and", "or", ... */
132 struct cql_node *left;
134 struct cql_node *right;
135 /** modifiers (NULL for no list) */
136 struct cql_node *modifiers;
141 /** \brief Private structure that describes the CQL properties (profile)
143 struct cql_properties;
145 /** \brief Structure used by cql_buf_write_handler
147 struct cql_buf_write_info {
153 /** \brief Handler for cql_buf_write_info
156 void cql_buf_write_handler(const char *b, void *client_data);
158 /** \brief Prints a CQL node and all sub nodes.
159 Hence this function prints the parse tree which is as returned by
163 void cql_node_print(struct cql_node *cn);
165 /** \brief creates a search clause node (st). */
167 struct cql_node *cql_node_mk_sc(NMEM nmem, const char *index,
168 const char *relation, const char *term);
170 /** \brief applies a prefix+uri to "unresolved" index and relation URIs.
171 "unresolved" URIs are those nodes where member index_uri / relation_uri
175 struct cql_node *cql_apply_prefix(NMEM nmem, struct cql_node *cn,
176 const char *prefix, const char *uri);
178 /** \brief creates a boolean node. */
180 struct cql_node *cql_node_mk_boolean(NMEM nmem, const char *op);
182 /** \brief destroys a node and its children. */
184 void cql_node_destroy(struct cql_node *cn);
186 /** duplicates a node (returns a copy of supplied node) . */
188 struct cql_node *cql_node_dup (NMEM nmem, struct cql_node *cp);
190 /** \brief returns the parse tree of the most recently parsed CQL query.
192 \returns CQL node or NULL for failure
195 struct cql_node *cql_parser_result(CQL_parser cp);
197 /** \brief converts CQL tree to XCQL and writes to user-defined stream
198 \param cn CQL node (tree)
199 \param pr print function
200 \param client_data data to be passed to pr function
203 void cql_to_xml(struct cql_node *cn,
204 void (*pr)(const char *buf, void *client_data),
206 /** \brief converts CQL tree to XCQL and writes to file
207 \param cn CQL node (tree)
211 void cql_to_xml_stdio(struct cql_node *cn, FILE *f);
213 /** \brief converts CQL tree to XCQL and writes result to buffer
214 \param cn CQL node (tree)
216 \param max size of buffer (max chars to write)
217 \returns length of resulting buffer
220 int cql_to_xml_buf(struct cql_node *cn, char *out, int max);
222 /** \brief stream handle for file (used by cql_to_xml_stdio) */
224 void cql_fputs(const char *buf, void *client_data);
226 /** \brief CQL transform handle.
227 The transform describes how to convert from CQL to PQF (Type-1 AKA RPN).
229 typedef struct cql_transform_t_ *cql_transform_t;
231 /** \brief creates a CQL transform handle from am opened file handle
232 \param f file where transformation spec is read
233 \returns transform handle or NULL for failure
235 The transformation spec is read from a FILE handle which is assumed
239 cql_transform_t cql_transform_open_FILE (FILE *f);
241 /** \brief creates a CQL transform handle from a file
242 \param fname name of where transformation spec is read
243 \returns transform handle or NULL for failure
246 cql_transform_t cql_transform_open_fname(const char *fname);
248 /** \brief destroys a CQL transform handle
249 \param ct CQL transform handle
252 void cql_transform_close(cql_transform_t ct);
254 /** \brief tranforms PQF given a CQL tree
255 \param ct CQL transform handle
256 \param cn CQL node tree
257 \param pr print function
258 \param client_data data to be passed to pr
262 The result is written to a user-defined stream.
265 int cql_transform(cql_transform_t ct,
267 void (*pr)(const char *buf, void *client_data),
270 /** \brief transforms PQF given a CQL tree (from FILE)
271 \param ct CQL transform handle
273 \param f FILE where output is written
275 \retval !=0 failure (error code)
277 The result is written to a file specified by FILE handle (which must
278 be opened for writing.
281 int cql_transform_FILE(cql_transform_t ct,
282 struct cql_node *cn, FILE *f);
284 /** \brief transforms PQF given a CQL tree (from FILE)
285 \param ct CQL transform handle
287 \param out buffer for output
288 \param max maximum bytes for output (size of buffer)
290 \retval !=0 failure (error code)
293 int cql_transform_buf(cql_transform_t ct,
294 struct cql_node *cn, char *out, int max);
296 /** \brief returns additional information for last transform
297 \param ct CQL transform handle
298 \param addinfo additional info (result)
302 int cql_transform_error(cql_transform_t ct, const char **addinfo);
304 /** \brief returns the CQL message corresponding to a given error code.
305 \param code error code
306 \returns text message
309 const char *cql_strerror(int code);
311 /** \brief returns the standard CQL context set URI.
312 \returns CQL URI string
315 const char *cql_uri(void);
317 /** \brief compares two CQL strings (ala strcmp)
320 \returns comparison value
321 Compares two CQL strings (for relations, operators, etc)
322 (unfortunately defined as case-insensitive unlike XML etc)
325 int cql_strcmp(const char *s1, const char *s2);
327 /** \brief compares two CQL strings (ala strncmp)
331 \returns comparison value
332 Compares two CQL strings at most n bytes
333 (unfortunately defined as case-insensitive unlike XML etc)
336 int cql_strncmp(const char *s1, const char *s2, size_t n);
345 * indent-tabs-mode: nil
347 * vim: shiftwidth=4 tabstop=8 expandtab