YAZ  5.23.1
cql.h
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data.
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
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.
15  *
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.
26  */
27 
32 #ifndef CQL_H_INCLUDED
33 #define CQL_H_INCLUDED
34 #include <stdio.h>
35 #include <yaz/nmem.h>
36 #include <yaz/wrbuf.h>
37 
39 
41 typedef struct cql_parser *CQL_parser;
42 
48 YAZ_EXPORT
49 CQL_parser cql_parser_create(void);
50 
56 YAZ_EXPORT
57 void cql_parser_destroy(CQL_parser cp);
58 
65 YAZ_EXPORT
66 int cql_parser_string(CQL_parser cp, const char *str);
67 
82 YAZ_EXPORT
83 int cql_parser_stream(CQL_parser cp,
84  int (*getbyte)(void *client_data),
85  void (*ungetbyte)(int b, void *client_data),
86  void *client_data);
87 
97 YAZ_EXPORT
98 int cql_parser_stdio(CQL_parser cp, FILE *f);
99 
107 YAZ_EXPORT
108 void cql_parser_strict(CQL_parser cp, int mode);
109 
111 #define CQL_NODE_ST 1
112 
113 #define CQL_NODE_BOOL 2
114 
115 #define CQL_NODE_SORT 3
116 
119 struct cql_node {
121  int which;
122  union {
124  struct {
126  char *index;
128  char *index_uri;
130  char *term;
132  char *relation;
139  } st;
141  struct {
143  char *value;
145  struct cql_node *left;
147  struct cql_node *right;
149  struct cql_node *modifiers;
150  } boolean;
152  struct {
153  char *index;
155  struct cql_node *next;
157  struct cql_node *modifiers;
159  struct cql_node *search;
160  } sort;
161  } u;
162 };
163 
166 struct cql_properties;
167 
171  int max;
172  int off;
173  char *buf;
174 };
175 
178 YAZ_EXPORT
179 void cql_buf_write_handler(const char *b, void *client_data);
180 
185 YAZ_EXPORT
186 void cql_node_print(struct cql_node *cn);
187 
189 YAZ_EXPORT
190 struct cql_node *cql_node_mk_sc(NMEM nmem, const char *index,
191  const char *relation, const char *term);
192 
197 YAZ_EXPORT
198 struct cql_node *cql_apply_prefix(NMEM nmem, struct cql_node *cn,
199  const char *prefix, const char *uri);
200 
202 YAZ_EXPORT
203 struct cql_node *cql_node_mk_boolean(NMEM nmem, const char *op);
204 
206 YAZ_EXPORT
207 struct cql_node *cql_node_mk_sort(NMEM nmem, const char *index,
208  struct cql_node *modifiers);
209 
211 YAZ_EXPORT
212 void cql_node_destroy(struct cql_node *cn);
213 
215 YAZ_EXPORT
216 struct cql_node *cql_node_dup (NMEM nmem, struct cql_node *cp);
217 
222 YAZ_EXPORT
223 struct cql_node *cql_parser_result(CQL_parser cp);
224 
229 YAZ_EXPORT
230 struct cql_node *cql_parser_sort_result(CQL_parser cp);
231 
237 YAZ_EXPORT
238 void cql_to_xml(struct cql_node *cn,
239  void (*pr)(const char *buf, void *client_data),
240  void *client_data);
245 YAZ_EXPORT
246 void cql_to_xml_stdio(struct cql_node *cn, FILE *f);
247 
254 YAZ_EXPORT
255 int cql_to_xml_buf(struct cql_node *cn, char *out, int max);
256 
262 YAZ_EXPORT
263 int cql_to_ccl(struct cql_node *cn,
264  void (*pr)(const char *buf, void *client_data),
265  void *client_data);
266 
271 YAZ_EXPORT
272 void cql_to_ccl_stdio(struct cql_node *cn, FILE *f);
273 
282 YAZ_EXPORT
283 int cql_to_ccl_buf(struct cql_node *cn, char *out, int max);
284 
286 YAZ_EXPORT
287 void cql_fputs(const char *buf, void *client_data);
288 
293 
297 YAZ_EXPORT
298 cql_transform_t cql_transform_create(void);
299 
307 YAZ_EXPORT
308 cql_transform_t cql_transform_open_FILE (FILE *f);
309 
314 YAZ_EXPORT
315 cql_transform_t cql_transform_open_fname(const char *fname);
316 
317 
324 YAZ_EXPORT
325 int cql_transform_define_pattern(cql_transform_t ct, const char *pattern,
326  const char *value);
327 
328 
329 
333 YAZ_EXPORT
334 void cql_transform_close(cql_transform_t ct);
335 
346 YAZ_EXPORT
347 int cql_transform(cql_transform_t ct,
348  struct cql_node *cn,
349  void (*pr)(const char *buf, void *client_data),
350  void *client_data);
351 
363 YAZ_EXPORT
364 int cql_transform_r(cql_transform_t ct, struct cql_node *cn,
365  WRBUF addinfo,
366  void (*pr)(const char *buf, void *client_data),
367  void *client_data);
368 
379 YAZ_EXPORT
380 int cql_transform_FILE(cql_transform_t ct,
381  struct cql_node *cn, FILE *f);
382 
391 YAZ_EXPORT
392 int cql_transform_buf(cql_transform_t ct,
393  struct cql_node *cn, char *out, int max);
394 
400 YAZ_EXPORT
401 int cql_transform_error(cql_transform_t ct, const char **addinfo);
402 
408 YAZ_EXPORT
409 void cql_transform_set_error(cql_transform_t ct, int error, const char *addinfo);
410 
415 YAZ_EXPORT
416 const char *cql_strerror(int code);
417 
421 YAZ_EXPORT
422 const char *cql_uri(void);
423 
431 YAZ_EXPORT
432 int cql_strcmp(const char *s1, const char *s2);
433 
442 YAZ_EXPORT
443 int cql_strncmp(const char *s1, const char *s2, size_t n);
444 
471 YAZ_EXPORT
472 int cql_sortby_to_sortkeys(struct cql_node *cn,
473  void (*pr)(const char *buf, void *client_data),
474  void *client_data);
475 
483 YAZ_EXPORT
484 int cql_sortby_to_sortkeys_buf(struct cql_node *cn, char *out, int max);
485 
487 
488 #endif
489 /* CQL_H_INCLUDED */
490 /*
491  * Local variables:
492  * c-basic-offset: 4
493  * c-file-style: "Stroustrup"
494  * indent-tabs-mode: nil
495  * End:
496  * vim: shiftwidth=4 tabstop=8 expandtab
497  */
498 
char * relation_uri
Definition: cql.h:134
int cql_transform_r(cql_transform_t ct, struct cql_node *cn, WRBUF addinfo, void(*pr)(const char *buf, void *client_data), void *client_data)
tranforms PQF given a CQL tree (re-entrant)
Definition: cqltransform.c:966
const char * cql_uri(void)
returns the standard CQL context set URI.
Definition: cqlutil.c:105
void cql_node_print(struct cql_node *cn)
Prints a CQL node and all sub nodes. Hence this function prints the parse tree which is as returned b...
cql_transform_t cql_transform_open_FILE(FILE *f)
creates a CQL transform handle from am opened file handle
Definition: cqltransform.c:215
int cql_to_ccl_buf(struct cql_node *cn, char *out, int max)
converts CQL tree to CCL and writes result to buffer
Definition: cql2ccl.c:261
void cql_to_ccl_stdio(struct cql_node *cn, FILE *f)
converts CQL tree to CCL and writes to file
Definition: cql2ccl.c:256
int cql_transform_buf(cql_transform_t ct, struct cql_node *cn, char *out, int max)
transforms PQF given a CQL tree from buffer (not re-entrant)
void cql_transform_set_error(cql_transform_t ct, int error, const char *addinfo)
sets error and addinfo for transform
struct cql_parser * CQL_parser
CQL parser handle (opaque pointer)
Definition: cql.h:41
Header for WRBUF (growing buffer)
void cql_transform_close(cql_transform_t ct)
destroys a CQL transform handle
Definition: cqltransform.c:256
int cql_to_ccl(struct cql_node *cn, void(*pr)(const char *buf, void *client_data), void *client_data)
converts CQL tree to CCL and writes to user-defined stream
Definition: cql2ccl.c:249
void cql_to_xml(struct cql_node *cn, void(*pr)(const char *buf, void *client_data), void *client_data)
converts CQL tree to XCQL and writes to user-defined stream
Definition: xcqlutil.c:239
CQL_parser cql_parser_create(void)
creates a CQL parser.
Definition: cql.c:1971
void cql_parser_strict(CQL_parser cp, int mode)
configures strict mode
Definition: cql.c:1998
#define YAZ_END_CDECL
Definition: yconfig.h:57
char * index_uri
Definition: cql.h:128
struct cql_node::@13::@14 st
int cql_parser_stream(CQL_parser cp, int(*getbyte)(void *client_data), void(*ungetbyte)(int b, void *client_data), void *client_data)
parses CQL query (query stream)
Definition: cql.c:1955
int cql_transform_FILE(cql_transform_t ct, struct cql_node *cn, FILE *f)
transforms PQF given a CQL tree from FILE (not re-entrant)
Definition: cqltransform.c:998
int cql_sortby_to_sortkeys(struct cql_node *cn, void(*pr)(const char *buf, void *client_data), void *client_data)
converts CQL sortby to sortkeys (ala versions 1.1)
Definition: cql_sortkeys.c:83
struct cql_node * modifiers
Definition: cql.h:136
void cql_to_xml_stdio(struct cql_node *cn, FILE *f)
converts CQL tree to XCQL and writes to file
Definition: xcqlutil.c:246
string buffer
Definition: wrbuf.h:42
char * term
Definition: cql.h:130
int cql_strcmp(const char *s1, const char *s2)
compares two CQL strings (ala strcmp)
Definition: cqlutil.c:194
struct cql_node * cql_node_mk_sort(NMEM nmem, const char *index, struct cql_node *modifiers)
creates a sort single spec node.
Definition: cqlutil.c:91
struct cql_transform_t_ * cql_transform_t
CQL transform handle. The transform describes how to convert from CQL to PQF (Type-1 AKA RPN)...
Definition: cql.h:292
struct cql_node * cql_node_dup(NMEM nmem, struct cql_node *cp)
Definition: cqlutil.c:24
void(* ungetbyte)(int b, void *client_data)
Definition: cql.c:111
union cql_node::@13 u
struct cql_node * next
Definition: cql.h:155
int cql_strncmp(const char *s1, const char *s2, size_t n)
compares two CQL strings (ala strncmp)
Definition: cqlutil.c:210
void cql_parser_destroy(CQL_parser cp)
destroys a CQL parser.
Definition: cql.c:1986
int cql_to_xml_buf(struct cql_node *cn, char *out, int max)
converts CQL tree to XCQL and writes result to buffer
Definition: xcqlutil.c:264
void cql_fputs(const char *buf, void *client_data)
stream handle for file (used by cql_to_xml_stdio)
Definition: cqlutil.c:18
char * value
Definition: cql.h:143
Structure used by cql_buf_write_handler.
Definition: cql.h:170
int cql_parser_string(CQL_parser cp, const char *str)
parses a CQL query (string)
Definition: cqlstring.c:35
struct cql_node * cql_node_mk_boolean(NMEM nmem, const char *op)
creates a boolean node.
Definition: cqlutil.c:78
int cql_parser_stdio(CQL_parser cp, FILE *f)
parses CQL query (from FILE)
Definition: cqlstdio.c:34
struct cql_node * extra_terms
Definition: cql.h:138
struct cql_node * cql_parser_result(CQL_parser cp)
returns the parse tree of the most recently parsed CQL query.
Definition: cql.c:1993
cql_transform_t cql_transform_create(void)
creates a CQL transform handle
Definition: cqltransform.c:53
void cql_buf_write_handler(const char *b, void *client_data)
Handler for cql_buf_write_info.
Definition: xcqlutil.c:251
int which
Definition: cql.h:121
struct cql_node * cql_parser_sort_result(CQL_parser cp)
returns the sortby tree of the most recently parsed CQL query.
int(* getbyte)(void *client_data)
Definition: cql.c:110
void cql_node_destroy(struct cql_node *cn)
destroys a node and its children.
Definition: cqlutil.c:173
int cql_transform(cql_transform_t ct, struct cql_node *cn, void(*pr)(const char *buf, void *client_data), void *client_data)
tranforms PQF given a CQL tree (NOT re-entrant)
Definition: cqltransform.c:987
struct cql_node * left
Definition: cql.h:145
struct cql_node * search
Definition: cql.h:159
char * index
Definition: cql.h:126
char * buf
Definition: cql.h:173
char * relation
Definition: cql.h:132
struct cql_node * cql_node_mk_sc(NMEM nmem, const char *index, const char *relation, const char *term)
creates a search clause node (st).
Definition: cqlutil.c:55
struct cql_node::@13::@16 sort
Header for Nibble Memory functions.
cql_transform_t cql_transform_open_fname(const char *fname)
creates a CQL transform handle from a file
Definition: cqltransform.c:276
struct cql_node * cql_apply_prefix(NMEM nmem, struct cql_node *cn, const char *prefix, const char *uri)
applies a prefix+uri to "unresolved" index and relation URIs. "unresolved" URIs are those nodes where...
Definition: cqlutil.c:110
struct cql_node * right
Definition: cql.h:147
int cql_transform_error(cql_transform_t ct, const char **addinfo)
returns additional information for last transform
const char * cql_strerror(int code)
returns the CQL message corresponding to a given error code.
Definition: cqlstrer.c:20
void * client_data
Definition: cql.c:112
int cql_transform_define_pattern(cql_transform_t ct, const char *pattern, const char *value)
defines CQL transform pattern
Definition: cqltransform.c:204
int cql_sortby_to_sortkeys_buf(struct cql_node *cn, char *out, int max)
converts CQL sortby to sortkeys ..
Definition: cql_sortkeys.c:120
#define YAZ_BEGIN_CDECL
Definition: yconfig.h:56
struct cql_node::@13::@15 boolean
CQL parse tree (node)
Definition: cql.h:119