cql.h File Reference

Header with public definitions about CQL. More...

#include <stdio.h>
#include <yaz/nmem.h>

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...

Defines

#define CQL_NODE_ST   1
 Node type: search term.
#define CQL_NODE_BOOL   2
 Node type: boolean.

Typedefs

typedef struct cql_parserCQL_parser
 CQL parser handle (opaque pointer).
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).

Functions

CQL_parser cql_parser_create (void)
 creates a CQL parser.
void cql_parser_destroy (CQL_parser cp)
 destroys a CQL parser.
int cql_parser_string (CQL_parser cp, const char *str)
 parses a CQL query (string)
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)
int cql_parser_stdio (CQL_parser cp, FILE *f)
 parses CQL query (from FILE)
void cql_buf_write_handler (const char *b, void *client_data)
 Handler for cql_buf_write_info.
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.
struct cql_nodecql_node_mk_sc (NMEM nmem, const char *index, const char *relation, const char *term)
 creates a search clause node (st).
struct cql_nodecql_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.
struct cql_nodecql_node_mk_boolean (NMEM nmem, const char *op)
 creates a boolean node.
void cql_node_destroy (struct cql_node *cn)
 destroys a node and its children.
struct cql_nodecql_node_dup (NMEM nmem, struct cql_node *cp)
struct cql_nodecql_parser_result (CQL_parser cp)
 returns the parse tree of the most recently parsed CQL query.
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
void cql_to_xml_stdio (struct cql_node *cn, FILE *f)
 converts CQL tree to XCQL and writes to file
int cql_to_xml_buf (struct cql_node *cn, char *out, int max)
 converts CQL tree to XCQL and writes result to buffer
void cql_fputs (const char *buf, void *client_data)
 stream handle for file (used by cql_to_xml_stdio)
cql_transform_t cql_transform_open_FILE (FILE *f)
 creates a CQL transform handle from am opened file handle
cql_transform_t cql_transform_open_fname (const char *fname)
 creates a CQL transform handle from a file
void cql_transform_close (cql_transform_t ct)
 destroys a CQL transform handle
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
int cql_transform_FILE (cql_transform_t ct, struct cql_node *cn, FILE *f)
 transforms PQF given a CQL tree (from FILE)
int cql_transform_buf (cql_transform_t ct, struct cql_node *cn, char *out, int max)
 transforms PQF given a CQL tree (from FILE)
int cql_transform_error (cql_transform_t ct, const char **addinfo)
 returns additional information for last transform
void cql_transform_set_error (cql_transform_t ct, int error, const char *addinfo)
 sets error and addinfo for transform
const char * cql_strerror (int code)
 returns the CQL message corresponding to a given error code.
const char * cql_uri (void)
 returns the standard CQL context set URI.
int cql_strcmp (const char *s1, const char *s2)
 compares two CQL strings (ala strcmp)
int cql_strncmp (const char *s1, const char *s2, size_t n)
 compares two CQL strings (ala strncmp)


Detailed Description

Header with public definitions about CQL.

Definition in file cql.h.


Define Documentation

#define CQL_NODE_BOOL   2

Node type: boolean.

Definition at line 102 of file cql.h.

Referenced by cql_apply_prefix(), cql_node_destroy(), cql_node_dup(), cql_node_mk_boolean(), and cql_transform_r().

#define CQL_NODE_ST   1

Node type: search term.

Definition at line 100 of file cql.h.

Referenced by cql_apply_prefix(), cql_node_destroy(), cql_node_dup(), cql_node_mk_sc(), cql_transform_r(), and emit_term().


Typedef Documentation

typedef struct cql_parser* CQL_parser

CQL parser handle (opaque pointer).

Definition at line 40 of file cql.h.

CQL transform handle. The transform describes how to convert from CQL to PQF (Type-1 AKA RPN).

Definition at line 228 of file cql.h.


Function Documentation

struct cql_node* cql_apply_prefix ( NMEM  nmem,
struct cql_node cn,
const char *  prefix,
const char *  uri 
) [read]

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 89 of file cqlutil.c.

References cql_node::boolean, cql_apply_prefix(), CQL_NODE_BOOL, CQL_NODE_ST, cql_strncmp(), nmem_strdup(), cql_node::st, cql_node::u, and cql_node::which.

Referenced by cql_apply_prefix(), cql_transform(), and yyparse().

void cql_buf_write_handler ( const char *  b,
void *  client_data 
)

void cql_fputs ( const char *  buf,
void *  client_data 
)

stream handle for file (used by cql_to_xml_stdio)

Definition at line 16 of file cqlutil.c.

Referenced by 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 132 of file cqlutil.c.

References cql_node::boolean, CQL_NODE_BOOL, cql_node_destroy(), CQL_NODE_ST, cql_node::st, cql_node::u, and cql_node::which.

Referenced by cql_node_destroy(), cql_parser_destroy(), cql_parser_stream(), and yyparse().

struct cql_node* cql_node_dup ( NMEM  nmem,
struct cql_node cp 
) [read]

duplicates a node (returns a copy of supplied node) .

Definition at line 22 of file cqlutil.c.

References cql_node::boolean, CQL_NODE_BOOL, cql_node_dup(), cql_node_mk_boolean(), cql_node_mk_sc(), CQL_NODE_ST, nmem_strdup(), cql_node::st, cql_node::u, and cql_node::which.

Referenced by cql_node_dup(), and yyparse().

struct cql_node* cql_node_mk_boolean ( NMEM  nmem,
const char *  op 
) [read]

creates a boolean node.

Definition at line 71 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 
) [read]

creates a search clause node (st).

Definition at line 48 of file cqlutil.c.

References CQL_NODE_ST, nmem_malloc(), nmem_strdup(), cql_node::st, 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:
CCL parser
Returns CQL parser or NULL if parser could not be created.

Definition at line 1988 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::top, cql_parser::ungetbyte, and xmalloc.

void cql_parser_destroy ( CQL_parser  cp  ) 

destroys a CQL parser.

Parameters:
cp CQL parser
This function does nothing if NULL if received.

Definition at line 2002 of file cql.c.

References cql_node_destroy(), cql_parser::nmem, nmem_destroy(), cql_parser::top, and xfree.

struct cql_node* cql_parser_result ( CQL_parser  cp  )  [read]

returns the parse tree of the most recently parsed CQL query.

Parameters:
cp CQL parser
Returns:
CQL node or NULL for failure

Definition at line 2009 of file cql.c.

References cql_parser::top.

int cql_parser_stdio ( CQL_parser  cp,
FILE *  f 
)

parses CQL query (from FILE)

Parameters:
cp CQL parser
f file where query is read from
Return values:
0 success
!=0 failure
This function is similar to cql_parser_string but reads from stdio FILE handle instead.

Definition at line 32 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)

Parameters:
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
Return values:
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 1971 of file cql.c.

References cql_parser::client_data, cql_node_destroy(), cql_parser::getbyte, cql_parser::nmem, nmem_reset(), cql_parser::top, and cql_parser::ungetbyte.

Referenced by cql_parser_stdio(), and cql_parser_string().

int cql_parser_string ( CQL_parser  cp,
const char *  str 
)

parses a CQL query (string)

Parameters:
cp CQL parser
str CQL string
Return values:
0 success
!=0 failure

Definition at line 33 of file cqlstring.c.

References cql_parser_stream(), cql_buf_info::off, and cql_buf_info::str.

int cql_strcmp ( const char *  s1,
const char *  s2 
)

compares two CQL strings (ala strcmp)

Parameters:
s1 string 1
s2 string 2
Returns:
comparison value Compares two CQL strings (for relations, operators, etc) (unfortunately defined as case-insensitive unlike XML etc)

Definition at line 148 of file cqlutil.c.

Referenced by cql_transform(), cql_transform_r(), and yylex().

const char* cql_strerror ( int  code  ) 

returns the CQL message corresponding to a given error code.

Parameters:
code error code
Returns:
text message

Definition at line 18 of file cqlstrer.c.

int cql_strncmp ( const char *  s1,
const char *  s2,
size_t  n 
)

compares two CQL strings (ala strncmp)

Parameters:
s1 string 1
s2 string 2
n size
Returns:
comparison value Compares two CQL strings at most n bytes (unfortunately defined as case-insensitive unlike XML etc)

Definition at line 164 of file cqlutil.c.

Referenced by cql_apply_prefix(), and cql_transform().

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

Parameters:
cn CQL node (tree)
pr print function
client_data data to be passed to pr function

Definition at line 205 of file xcqlutil.c.

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

Parameters:
cn CQL node (tree)
out buffer
max size of buffer (max chars to write)
Returns:
length of resulting buffer

Definition at line 230 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

Parameters:
cn CQL node (tree)
f file handle

Definition at line 212 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

Parameters:
ct CQL transform handle
cn CQL node tree
pr print function
client_data data to be passed to pr
Return values:
0 success
!= 0 error
The result is written to a user-defined stream.

Definition at line 679 of file cqltransform.c.

References cql_transform_t_::addinfo, cql_apply_prefix(), cql_strcmp(), cql_strncmp(), cql_transform_r(), cql_transform_t_::entry, cql_transform_t_::error, cql_prop_entry::next, nmem_create(), nmem_destroy(), cql_prop_entry::pattern, cql_prop_entry::value, and xfree.

Referenced by 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 FILE)

Parameters:
ct CQL transform handle
cn CQL tree
out buffer for output
max maximum bytes for output (size of buffer)
Return values:
0 success
!=0 failure (error code)

Definition at line 708 of file cqltransform.c.

References cql_transform_t_::addinfo, cql_buf_write_info::buf, cql_buf_write_handler(), cql_transform(), cql_transform_t_::error, cql_buf_write_info::max, cql_buf_write_info::off, xstrdup, and YAZ_SRW_TOO_MANY_CHARS_IN_QUERY.

void cql_transform_close ( cql_transform_t  ct  ) 

int cql_transform_error ( cql_transform_t  ct,
const char **  addinfo 
)

returns additional information for last transform

Parameters:
ct CQL transform handle
addinfo additional info (result)
Returns:
error code

Definition at line 732 of file cqltransform.c.

References cql_transform_t_::addinfo, and cql_transform_t_::error.

int cql_transform_FILE ( cql_transform_t  ct,
struct cql_node cn,
FILE *  f 
)

transforms PQF given a CQL tree (from FILE)

Parameters:
ct CQL transform handle
cn CQL tree
f FILE where output is written
Return values:
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 703 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

Parameters:
f file where transformation spec is read
Returns:
transform handle or NULL for failure
The transformation spec is read from a FILE handle which is assumed opened for reading.

Definition at line 44 of file cqltransform.c.

References cql_transform_t_::addinfo, cql_transform_close(), cql_transform_t_::entry, cql_transform_t_::error, cql_prop_entry::next, cql_prop_entry::pattern, cql_transform_t_::tok_cfg, cql_transform_t_::w, wrbuf_alloc(), wrbuf_cstr(), wrbuf_puts(), wrbuf_rewind(), xmalloc, xstrdup, yaz_tok_cfg_create(), 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().

cql_transform_t cql_transform_open_fname ( const char *  fname  ) 

creates a CQL transform handle from a file

Parameters:
fname name of where transformation spec is read
Returns:
transform handle or NULL for failure

Definition at line 142 of file cqltransform.c.

References cql_transform_open_FILE().

void cql_transform_set_error ( cql_transform_t  ct,
int  error,
const char *  addinfo 
)

sets error and addinfo for transform

Parameters:
ct CQL transform handle
error error code
addinfo additional info

Definition at line 738 of file cqltransform.c.

References cql_transform_t_::addinfo, cql_transform_t_::error, xfree, and xstrdup.

Referenced by cql_transform_rpn2cql().

const char* cql_uri ( void   ) 

returns the standard CQL context set URI.

Returns:
CQL URI string

Definition at line 84 of file cqlutil.c.

Referenced by cql_transform_r().


Generated on Wed Jun 18 11:17:01 2008 for YAZ by  doxygen 1.5.6