YAZ
5.34.0
|
Header with public definitions about CQL. More...
Go to the source code of this file.
Data Structures | |
struct | cql_node |
CQL parse tree (node) More... | |
struct | cql_buf_write_info |
Structure used by cql_buf_write_handler. More... | |
Macros | |
#define | CQL_NODE_ST 1 |
Node type: search term. More... | |
#define | CQL_NODE_BOOL 2 |
Node type: boolean. More... | |
#define | CQL_NODE_SORT 3 |
Node type: sortby single spec. More... | |
Typedefs | |
typedef struct cql_parser * | CQL_parser |
CQL parser handle (opaque pointer) More... | |
typedef struct cql_transform_t_ * | cql_transform_t |
CQL transform handle. The transform describes how to convert from CQL to PQF (Type-1 AKA RPN). More... | |
Functions | |
CQL_parser | cql_parser_create (void) |
creates a CQL parser. More... | |
void | cql_parser_destroy (CQL_parser cp) |
destroys a CQL parser. More... | |
int | cql_parser_string (CQL_parser cp, const char *str) |
parses a CQL query (string) More... | |
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) More... | |
int | cql_parser_stdio (CQL_parser cp, FILE *f) |
parses CQL query (from FILE) More... | |
void | cql_parser_strict (CQL_parser cp, int mode) |
configures strict mode More... | |
void | cql_buf_write_handler (const char *b, void *client_data) |
Handler for cql_buf_write_info. More... | |
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 by cql_parser_result. More... | |
struct cql_node * | cql_node_mk_sc (NMEM nmem, const char *index, const char *relation, const char *term) |
creates a search clause node (st). More... | |
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 member index_uri / relation_uri is NULL. More... | |
struct cql_node * | cql_node_mk_boolean (NMEM nmem, const char *op) |
creates a boolean node. More... | |
struct cql_node * | cql_node_mk_sort (NMEM nmem, const char *index, struct cql_node *modifiers) |
creates a sort single spec node. More... | |
void | cql_node_destroy (struct cql_node *cn) |
destroys a node and its children. More... | |
struct cql_node * | cql_node_dup (NMEM nmem, struct cql_node *cp) |
struct cql_node * | cql_parser_result (CQL_parser cp) |
returns the parse tree of the most recently parsed CQL query. More... | |
struct cql_node * | cql_parser_sort_result (CQL_parser cp) |
returns the sortby tree of the most recently parsed CQL query. More... | |
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 More... | |
void | cql_to_xml_stdio (struct cql_node *cn, FILE *f) |
converts CQL tree to XCQL and writes to file More... | |
int | cql_to_xml_buf (struct cql_node *cn, char *out, int max) |
converts CQL tree to XCQL and writes result to buffer More... | |
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 More... | |
void | cql_to_ccl_stdio (struct cql_node *cn, FILE *f) |
converts CQL tree to CCL and writes to file More... | |
int | cql_to_ccl_buf (struct cql_node *cn, char *out, int max) |
converts CQL tree to CCL and writes result to buffer More... | |
void | cql_fputs (const char *buf, void *client_data) |
stream handle for file (used by cql_to_xml_stdio) More... | |
cql_transform_t | cql_transform_create (void) |
creates a CQL transform handle More... | |
cql_transform_t | cql_transform_open_FILE (FILE *f) |
creates a CQL transform handle from am opened file handle More... | |
cql_transform_t | cql_transform_open_fname (const char *fname) |
creates a CQL transform handle from a file More... | |
int | cql_transform_define_pattern (cql_transform_t ct, const char *pattern, const char *value) |
defines CQL transform pattern More... | |
void | cql_transform_close (cql_transform_t ct) |
destroys a CQL transform handle More... | |
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) More... | |
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) More... | |
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) More... | |
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) More... | |
int | cql_transform_error (cql_transform_t ct, const char **addinfo) |
returns additional information for last transform More... | |
void | cql_transform_set_error (cql_transform_t ct, int error, const char *addinfo) |
sets error and addinfo for transform More... | |
const char * | cql_strerror (int code) |
returns the CQL message corresponding to a given error code. More... | |
const char * | cql_uri (void) |
returns the standard CQL context set URI. More... | |
int | cql_strcmp (const char *s1, const char *s2) |
compares two CQL strings (ala strcmp) More... | |
int | cql_strncmp (const char *s1, const char *s2, size_t n) |
compares two CQL strings (ala strncmp) More... | |
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) More... | |
int | cql_sortby_to_sortkeys_buf (struct cql_node *cn, char *out, int max) |
converts CQL sortby to sortkeys .. More... | |
Header with public definitions about CQL.
Definition in file cql.h.
typedef struct cql_parser* CQL_parser |
typedef struct cql_transform_t_* cql_transform_t |
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 member index_uri / relation_uri is NULL.
Definition at line 110 of file cqlutil.c.
References cql_node::boolean, CQL_NODE_BOOL, CQL_NODE_SORT, CQL_NODE_ST, cql_strncmp(), nmem_strdup(), cql_node::sort, cql_node::st, cql_node::u, and cql_node::which.
Referenced by cql_transform_r(), and yyparse().
void cql_buf_write_handler | ( | const char * | b, |
void * | client_data | ||
) |
Handler for cql_buf_write_info.
Definition at line 251 of file xcqlutil.c.
References cql_buf_write_info::buf, cql_buf_write_info::max, and cql_buf_write_info::off.
Referenced by cql_sortby_to_sortkeys_buf(), cql_to_ccl_buf(), cql_to_xml_buf(), and cql_transform_buf().
void cql_fputs | ( | const char * | buf, |
void * | client_data | ||
) |
stream handle for file (used by cql_to_xml_stdio)
Definition at line 18 of file cqlutil.c.
Referenced by cql_to_ccl_stdio(), cql_to_xml_stdio(), and cql_transform_FILE().
void cql_node_destroy | ( | struct cql_node * | cn | ) |
destroys a node and its children.
Definition at line 173 of file cqlutil.c.
References cql_node::boolean, CQL_NODE_BOOL, CQL_NODE_SORT, CQL_NODE_ST, cql_node::sort, cql_node::st, cql_node::u, and cql_node::which.
Referenced by cql_parser_destroy(), cql_parser_stream(), and yyparse().
duplicates a node (returns a copy of supplied node) .
Definition at line 24 of file cqlutil.c.
References cql_node::boolean, CQL_NODE_BOOL, cql_node_mk_boolean(), cql_node_mk_sc(), cql_node_mk_sort(), CQL_NODE_SORT, CQL_NODE_ST, nmem_strdup(), cql_node::sort, cql_node::st, cql_node::u, and cql_node::which.
Referenced by yyparse().
creates a boolean node.
Definition at line 78 of file cqlutil.c.
References cql_node::boolean, CQL_NODE_BOOL, nmem_malloc(), nmem_strdup(), cql_node::u, and cql_node::which.
Referenced by cql_node_dup(), and yyparse().
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 at line 55 of file cqlutil.c.
References CQL_NODE_ST, cql_node::index, nmem_malloc(), nmem_strdup(), cql_node::relation, cql_node::st, cql_node::term, cql_node::u, and cql_node::which.
Referenced by cql_node_dup(), and yyparse().
creates a sort single spec node.
Definition at line 91 of file cqlutil.c.
References CQL_NODE_SORT, cql_node::index, cql_node::modifiers, nmem_malloc(), nmem_strdup(), cql_node::sort, cql_node::u, and cql_node::which.
Referenced by cql_node_dup(), and yyparse().
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 by cql_parser_result.
CQL_parser cql_parser_create | ( | void | ) |
creates a CQL parser.
Returns CQL parser or NULL if parser could not be created.
Definition at line 1880 of file cql.c.
References cql_parser::client_data, cql_parser::getbyte, cql_parser::last_error, cql_parser::last_pos, cql_parser::nmem, nmem_create(), cql_parser::strict, cql_parser::top, cql_parser::ungetbyte, and xmalloc.
Referenced by cql2pqf().
void cql_parser_destroy | ( | CQL_parser | cp | ) |
destroys a CQL parser.
cp | CQL parser |
This function does nothing if NULL if received.
Definition at line 1895 of file cql.c.
References cql_node_destroy(), cql_parser::nmem, nmem_destroy(), cql_parser::top, and xfree.
Referenced by cql2pqf().
struct cql_node* cql_parser_result | ( | CQL_parser | cp | ) |
returns the parse tree of the most recently parsed CQL query.
cp | CQL parser |
Definition at line 1902 of file cql.c.
References cql_parser::top.
Referenced by cql2pqf().
struct cql_node* cql_parser_sort_result | ( | CQL_parser | cp | ) |
returns the sortby tree of the most recently parsed CQL query.
cp | CQL parser |
int cql_parser_stdio | ( | CQL_parser | cp, |
FILE * | f | ||
) |
parses CQL query (from FILE)
cp | CQL parser |
f | file where query is read from |
0 | success |
!=0 | failure |
This function is similar to cql_parser_string but reads from stdio FILE handle instead.
Definition at line 34 of file cqlstdio.c.
References cql_parser_stream(), getbyte_stream(), and ungetbyte_stream().
int cql_parser_stream | ( | CQL_parser | cp, |
int(*)(void *client_data) | getbyte, | ||
void(*)(int b, void *client_data) | ungetbyte, | ||
void * | client_data | ||
) |
parses CQL query (query stream)
cp | CQL parser |
getbyte | function which reads one character from stream |
ungetbyte | function which unreads one character from stream |
client_data | data to be passed to stream functions |
0 | success |
!=0 | failure |
This function is similar to cql_parser_string but takes a functions to read each query character from a stream.
The functions pointers getbytes, ungetbyte are similar to that known from stdios getc, ungetc.
Definition at line 1864 of file cql.c.
References cql_parser::client_data, cql_node_destroy(), cql_parse(), cql_parser::getbyte, cql_parser::nmem, nmem_reset(), cql_parser::top, and cql_parser::ungetbyte.
Referenced by cql_parser_stdio(), and cql_parser_string().
void cql_parser_strict | ( | CQL_parser | cp, |
int | mode | ||
) |
configures strict mode
cp | CQL parser |
mode | 1=enable strict mode, 0=disable strict mode |
This function is similar to cql_parser_string but reads from stdio FILE handle instead.
Definition at line 1907 of file cql.c.
References cql_parser::strict.
int cql_parser_string | ( | CQL_parser | cp, |
const char * | str | ||
) |
parses a CQL query (string)
cp | CQL parser |
str | CQL string |
0 | success |
!=0 | failure |
Definition at line 35 of file cqlstring.c.
References cql_parser_stream(), getbuf(), cql_buf_info::off, cql_buf_info::str, and ungetbuf().
Referenced by cql2pqf().
int cql_sortby_to_sortkeys | ( | struct cql_node * | cn, |
void(*)(const char *buf, void *client_data) | pr, | ||
void * | client_data | ||
) |
converts CQL sortby to sortkeys (ala versions 1.1)
cn | CQL tree |
pr | print function |
client_data | data to be passed to pr function |
This will take CQL_NODE_SORT entries and conver them to
path,schema,ascending,caseSensitive,missingValue items..
One for each sort keys. Where
path is string index for sorting
schema is schema for sort index
ascending is a boolean (0=false, 1=true). Default is true.
caseSensitive is a boolean. Default is false.
missingValue is a string and one of 'abort', 'highValue', 'lowValue', or 'omit'. Default is 'highValue'.
See also http://www.loc.gov/standards/sru/sru-1-1.html#sort
Definition at line 83 of file cql_sortkeys.c.
References CQL_NODE_SORT, cql_sort_modifiers(), pr_n(), cql_node::sort, cql_node::u, and cql_node::which.
Referenced by cql_sortby_to_sortkeys_buf().
int cql_sortby_to_sortkeys_buf | ( | struct cql_node * | cn, |
char * | out, | ||
int | max | ||
) |
converts CQL sortby to sortkeys ..
cn | CQL tree |
out | result buffer |
max | size of buffer (allocated) |
0 | OK |
-1 | ERROR |
Definition at line 120 of file cql_sortkeys.c.
References cql_buf_write_info::buf, cql_buf_write_handler(), cql_sortby_to_sortkeys(), cql_buf_write_info::max, and cql_buf_write_info::off.
Referenced by cql2pqf().
int cql_strcmp | ( | const char * | s1, |
const char * | s2 | ||
) |
compares two CQL strings (ala strcmp)
s1 | string 1 |
s2 | string 2 |
Definition at line 194 of file cqlutil.c.
Referenced by bool(), cql_lookup_property(), cql_transform_r(), emit_node(), node(), and yylex().
const char* cql_strerror | ( | int | code | ) |
returns the CQL message corresponding to a given error code.
code | error code |
Definition at line 16 of file cqlstrer.c.
References yaz_diag_srw_str().
Referenced by cql2pqf().
int cql_strncmp | ( | const char * | s1, |
const char * | s2, | ||
size_t | n | ||
) |
compares two CQL strings (ala strncmp)
s1 | string 1 |
s2 | string 2 |
n | size |
Definition at line 210 of file cqlutil.c.
Referenced by cql_apply_prefix(), and cql_transform_r().
int cql_to_ccl | ( | struct cql_node * | cn, |
void(*)(const char *buf, void *client_data) | pr, | ||
void * | client_data | ||
) |
converts CQL tree to CCL and writes to user-defined stream
cn | CQL node (tree) |
pr | print function |
client_data | data to be passed to pr function |
Definition at line 249 of file cql2ccl.c.
References cql_to_ccl_r().
Referenced by cql_to_ccl_buf(), and cql_to_ccl_stdio().
int cql_to_ccl_buf | ( | struct cql_node * | cn, |
char * | out, | ||
int | max | ||
) |
converts CQL tree to CCL and writes result to buffer
cn | CQL node (tree) |
out | buffer |
max | size of buffer (max chars to write) |
0 | OK |
-1 | conversion error |
-2 | buffer too small (truncated) |
Definition at line 261 of file cql2ccl.c.
References cql_buf_write_info::buf, cql_buf_write_handler(), cql_to_ccl(), cql_buf_write_info::max, and cql_buf_write_info::off.
void cql_to_ccl_stdio | ( | struct cql_node * | cn, |
FILE * | f | ||
) |
converts CQL tree to CCL and writes to file
cn | CQL node (tree) |
f | file handle |
Definition at line 256 of file cql2ccl.c.
References cql_fputs(), and cql_to_ccl().
void cql_to_xml | ( | struct cql_node * | cn, |
void(*)(const char *buf, void *client_data) | pr, | ||
void * | client_data | ||
) |
converts CQL tree to XCQL and writes to user-defined stream
cn | CQL node (tree) |
pr | print function |
client_data | data to be passed to pr function |
Definition at line 239 of file xcqlutil.c.
References cql_to_xml_r().
Referenced by cql_to_xml_buf(), and cql_to_xml_stdio().
int cql_to_xml_buf | ( | struct cql_node * | cn, |
char * | out, | ||
int | max | ||
) |
converts CQL tree to XCQL and writes result to buffer
cn | CQL node (tree) |
out | buffer |
max | size of buffer (max chars to write) |
Definition at line 264 of file xcqlutil.c.
References cql_buf_write_info::buf, cql_buf_write_handler(), cql_to_xml(), cql_buf_write_info::max, and cql_buf_write_info::off.
void cql_to_xml_stdio | ( | struct cql_node * | cn, |
FILE * | f | ||
) |
converts CQL tree to XCQL and writes to file
cn | CQL node (tree) |
f | file handle |
Definition at line 246 of file xcqlutil.c.
References cql_fputs(), and cql_to_xml().
int cql_transform | ( | cql_transform_t | ct, |
struct cql_node * | cn, | ||
void(*)(const char *buf, void *client_data) | pr, | ||
void * | client_data | ||
) |
tranforms PQF given a CQL tree (NOT re-entrant)
ct | CQL transform handle |
cn | CQL node tree |
pr | print function |
client_data | data to be passed to pr |
0 | success |
!= | 0 error |
The result is written to a user-defined stream.
Definition at line 987 of file cqltransform.c.
References cql_transform_r(), cql_transform_set_error(), wrbuf_alloc(), wrbuf_cstr(), and wrbuf_destroy().
Referenced by cql2pqf(), cql_transform_buf(), and cql_transform_FILE().
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)
ct | CQL transform handle |
cn | CQL tree |
out | buffer for output |
max | maximum bytes for output (size of buffer) |
0 | success |
!=0 | failure (error code) |
Definition at line 1003 of file cqltransform.c.
References cql_buf_write_info::buf, cql_buf_write_handler(), cql_transform(), cql_transform_set_error(), cql_buf_write_info::max, cql_buf_write_info::off, and YAZ_SRW_TOO_MANY_CHARS_IN_QUERY.
void cql_transform_close | ( | cql_transform_t | ct | ) |
destroys a CQL transform handle
ct | CQL transform handle |
Definition at line 256 of file cqltransform.c.
References cql_transform_t_::addinfo, cql_transform_t_::entry, cql_prop_entry::next, cql_transform_t_::nmem, nmem_destroy(), cql_prop_entry::pattern, cql_transform_t_::tok_cfg, cql_prop_entry::value, wrbuf_destroy(), xfree, and yaz_tok_cfg_destroy().
Referenced by cql2pqf(), cql_transform_open_FILE(), and solr_transform_close().
cql_transform_t cql_transform_create | ( | void | ) |
creates a CQL transform handle
Definition at line 53 of file cqltransform.c.
References cql_transform_t_::addinfo, cql_transform_t_::entry, cql_transform_t_::error, cql_transform_t_::nmem, nmem_create(), cql_transform_t_::tok_cfg, wrbuf_alloc(), xmalloc, and yaz_tok_cfg_create().
Referenced by cql_transform_open_FILE(), and solr_transform_create().
int cql_transform_define_pattern | ( | cql_transform_t | ct, |
const char * | pattern, | ||
const char * | value | ||
) |
defines CQL transform pattern
ct | CQL transform handle |
pattern | pattern string |
value | pattern value |
Definition at line 204 of file cqltransform.c.
References cql_transform_parse_tok_line(), cql_prop_entry::pattern, cql_transform_t_::tok_cfg, cql_prop_entry::value, yaz_tok_cfg_single_tokens(), yaz_tok_parse_buf(), and yaz_tok_parse_destroy().
Referenced by solr_transform_define_pattern().
int cql_transform_error | ( | cql_transform_t | ct, |
const char ** | addinfo | ||
) |
returns additional information for last transform
ct | CQL transform handle |
addinfo | additional info (result) |
Definition at line 1027 of file cqltransform.c.
References cql_transform_t_::addinfo, cql_transform_t_::error, wrbuf_cstr(), and wrbuf_len.
Referenced by cql2pqf(), and solr_transform_error().
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)
ct | CQL transform handle |
cn | CQL tree |
f | FILE where output is written |
0 | success |
!=0 | failure (error code) |
The result is written to a file specified by FILE handle (which must be opened for writing.
Definition at line 998 of file cqltransform.c.
References cql_fputs(), and cql_transform().
cql_transform_t cql_transform_open_FILE | ( | FILE * | f | ) |
creates a CQL transform handle from am opened file handle
f | file where transformation spec is read |
The transformation spec is read from a FILE handle which is assumed opened for reading.
Definition at line 215 of file cqltransform.c.
References cql_transform_close(), cql_transform_create(), cql_transform_parse_tok_line(), cql_prop_entry::pattern, cql_transform_t_::tok_cfg, xfree, xstrdup, yaz_tok_cfg_single_tokens(), YAZ_TOK_EOF, yaz_tok_move(), yaz_tok_parse_buf(), yaz_tok_parse_destroy(), yaz_tok_parse_string(), and YAZ_TOK_STRING.
Referenced by cql_transform_open_fname(), and solr_transform_open_FILE().
cql_transform_t cql_transform_open_fname | ( | const char * | fname | ) |
creates a CQL transform handle from a file
fname | name of where transformation spec is read |
Definition at line 276 of file cqltransform.c.
References cql_transform_open_FILE().
Referenced by cql2pqf(), solr_transform_open_fname(), and xml_config_read().
int cql_transform_r | ( | cql_transform_t | ct, |
struct cql_node * | cn, | ||
WRBUF | addinfo, | ||
void(*)(const char *buf, void *client_data) | pr, | ||
void * | client_data | ||
) |
tranforms PQF given a CQL tree (re-entrant)
ct | CQL transform handle |
cn | CQL node tree |
addinfo | additional information (if error) |
pr | print function |
client_data | data to be passed to pr |
0 | success |
!= | 0 error code |
The result is written to a user-defined stream.
Definition at line 966 of file cqltransform.c.
References cql_apply_prefix(), cql_strcmp(), cql_strncmp(), emit_node(), cql_transform_t_::entry, cql_prop_entry::next, nmem_create(), nmem_destroy(), cql_prop_entry::pattern, and cql_prop_entry::value.
Referenced by cql_transform().
void cql_transform_set_error | ( | cql_transform_t | ct, |
int | error, | ||
const char * | addinfo | ||
) |
sets error and addinfo for transform
ct | CQL transform handle |
error | error code |
addinfo | additional info |
Definition at line 1033 of file cqltransform.c.
References cql_transform_t_::addinfo, cql_transform_t_::error, wrbuf_puts(), and wrbuf_rewind().
Referenced by cql_transform(), cql_transform_buf(), cql_transform_rpn2cql_stream(), and solr_transform_set_error().
const char* cql_uri | ( | void | ) |
returns the standard CQL context set URI.
Definition at line 105 of file cqlutil.c.
Referenced by emit_node().