YAZ  5.23.1
Data Structures | Functions
cqltransform.c File Reference

Implements CQL transform (CQL to RPN conversion). More...

#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <yaz/rpn2cql.h>
#include <yaz/xmalloc.h>
#include <yaz/diagsrw.h>
#include <yaz/tokenizer.h>
#include <yaz/wrbuf.h>
#include <yaz/z-core.h>
#include <yaz/matchstr.h>
#include <yaz/oid_db.h>
#include <yaz/log.h>
#include <yaz/proxunit.h>

Go to the source code of this file.

Data Structures

struct  cql_prop_entry
 
struct  cql_transform_t_
 

Functions

cql_transform_t cql_transform_create (void)
 creates a CQL transform handle More...
 
static int cql_transform_parse_tok_line (cql_transform_t ct, const char *pattern, yaz_tok_parse_t tp)
 
int cql_transform_define_pattern (cql_transform_t ct, const char *pattern, const char *value)
 defines CQL transform pattern More...
 
cql_transform_t cql_transform_open_FILE (FILE *f)
 creates a CQL transform handle from am opened file handle More...
 
void cql_transform_close (cql_transform_t ct)
 destroys a CQL transform handle More...
 
cql_transform_t cql_transform_open_fname (const char *fname)
 creates a CQL transform handle from a file More...
 
static int compare_attr (Z_AttributeElement *a, Z_AttributeElement *b)
 
const char * cql_lookup_reverse (cql_transform_t ct, const char *category, Z_AttributeList *attributes)
 find a pattern that has a subset of attributes More...
 
static const char * cql_lookup_property (cql_transform_t ct, const char *pat1, const char *pat2, const char *pat3)
 
int cql_pr_attr_uri (cql_transform_t ct, WRBUF addinfo, const char *category, const char *uri, const char *val, const char *default_val, void(*pr)(const char *buf, void *client_data), void *client_data, int errcode)
 
int cql_pr_attr (cql_transform_t ct, WRBUF addinfo, const char *category, const char *val, const char *default_val, void(*pr)(const char *buf, void *client_data), void *client_data, int errcode)
 
static void cql_pr_int (int val, void(*pr)(const char *buf, void *client_data), void *client_data)
 
static int cql_pr_prox (cql_transform_t ct, struct cql_node *mods, WRBUF addinfo, void(*pr)(const char *buf, void *client_data), void *client_data)
 
static int has_modifier (struct cql_node *cn, const char *name)
 
static int emit_term (cql_transform_t ct, struct cql_node *cn, WRBUF addinfo, const char *term, int length, void(*pr)(const char *buf, void *client_data), void *client_data)
 
static int emit_terms (cql_transform_t ct, struct cql_node *cn, WRBUF addinfo, void(*pr)(const char *buf, void *client_data), void *client_data, const char *op)
 
static int emit_wordlist (cql_transform_t ct, struct cql_node *cn, WRBUF addinfo, void(*pr)(const char *buf, void *client_data), void *client_data, const char *op)
 
static int emit_node (cql_transform_t ct, struct cql_node *cn, WRBUF addinfo, void(*pr)(const char *buf, void *client_data), void *client_data)
 
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 (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_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...
 

Detailed Description

Implements CQL transform (CQL to RPN conversion).

Evaluation order of rules:

always relation structure position truncation index relationModifier

Definition in file cqltransform.c.

Function Documentation

static int compare_attr ( Z_AttributeElement a,
Z_AttributeElement b 
)
static
static const char* cql_lookup_property ( cql_transform_t  ct,
const char *  pat1,
const char *  pat2,
const char *  pat3 
)
static
const char* cql_lookup_reverse ( cql_transform_t  ct,
const char *  category,
Z_AttributeList attributes 
)

find a pattern that has a subset of attributes

Parameters
ctCQL transform handle
categorypattern category
attributesRPN attributes
Returns
pattern value or NULL if not found

Definition at line 322 of file cqltransform.c.

References cql_prop_entry::attr_list, Z_AttributeList::attributes, Z_AttributeElement::attributeSet, compare_attr(), cql_transform_t_::entry, cql_prop_entry::next, Z_AttributeList::num_attributes, oid_oidcmp(), cql_prop_entry::pattern, and yaz_oid_attset_bib_1.

Referenced by rpn2cql_attr(), and solr_lookup_reverse().

int cql_pr_attr ( cql_transform_t  ct,
WRBUF  addinfo,
const char *  category,
const char *  val,
const char *  default_val,
void(*)(const char *buf, void *client_data)  pr,
void *  client_data,
int  errcode 
)

Definition at line 475 of file cqltransform.c.

References cql_pr_attr_uri().

Referenced by emit_node(), and emit_term().

int cql_pr_attr_uri ( cql_transform_t  ct,
WRBUF  addinfo,
const char *  category,
const char *  uri,
const char *  val,
const char *  default_val,
void(*)(const char *buf, void *client_data)  pr,
void *  client_data,
int  errcode 
)
static void cql_pr_int ( int  val,
void(*)(const char *buf, void *client_data)  pr,
void *  client_data 
)
static

Definition at line 486 of file cqltransform.c.

Referenced by cql_pr_prox().

static int cql_pr_prox ( cql_transform_t  ct,
struct cql_node mods,
WRBUF  addinfo,
void(*)(const char *buf, void *client_data)  pr,
void *  client_data 
)
static
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)

Parameters
ctCQL transform handle
cnCQL node tree
prprint function
client_datadata to be passed to pr
Return values
0success
!=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)

Parameters
ctCQL transform handle
cnCQL tree
outbuffer for output
maxmaximum bytes for output (size of buffer)
Return values
0success
!=0failure (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)
cql_transform_t cql_transform_create ( void  )

creates a CQL transform handle

Returns
transform handle or NULL for failure

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

Parameters
ctCQL transform handle
patternpattern string
valuepattern value
Returns
0 for succes; -1 for failure

Definition at line 204 of file cqltransform.c.

References cql_transform_parse_tok_line(), cql_transform_t_::tok_cfg, 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

Parameters
ctCQL transform handle
addinfoadditional info (result)
Returns
error code

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)

Parameters
ctCQL transform handle
cnCQL tree
fFILE where output is written
Return values
0success
!=0failure (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

Parameters
ffile 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 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

Parameters
fnamename of where transformation spec is read
Returns
transform handle or NULL for failure

Definition at line 276 of file cqltransform.c.

References cql_transform_open_FILE(), and cql_prop_entry::value.

Referenced by cql2pqf(), solr_transform_open_fname(), and xml_config_read().

static int cql_transform_parse_tok_line ( cql_transform_t  ct,
const char *  pattern,
yaz_tok_parse_t  tp 
)
static
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)

Parameters
ctCQL transform handle
cnCQL node tree
addinfoadditional information (if error)
prprint function
client_datadata to be passed to pr
Return values
0success
!=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

Parameters
ctCQL transform handle
errorerror code
addinfoadditional 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().

static int emit_node ( cql_transform_t  ct,
struct cql_node cn,
WRBUF  addinfo,
void(*)(const char *buf, void *client_data)  pr,
void *  client_data 
)
static
static int emit_term ( cql_transform_t  ct,
struct cql_node cn,
WRBUF  addinfo,
const char *  term,
int  length,
void(*)(const char *buf, void *client_data)  pr,
void *  client_data 
)
static
static int emit_terms ( cql_transform_t  ct,
struct cql_node cn,
WRBUF  addinfo,
void(*)(const char *buf, void *client_data)  pr,
void *  client_data,
const char *  op 
)
static

Definition at line 782 of file cqltransform.c.

References emit_term(), cql_node::st, and cql_node::u.

Referenced by emit_node().

static int emit_wordlist ( cql_transform_t  ct,
struct cql_node cn,
WRBUF  addinfo,
void(*)(const char *buf, void *client_data)  pr,
void *  client_data,
const char *  op 
)
static

Definition at line 812 of file cqltransform.c.

References emit_term(), cql_node::st, and cql_node::u.

Referenced by emit_node().

static int has_modifier ( struct cql_node cn,
const char *  name 
)
static

Definition at line 569 of file cqltransform.c.

References cql_node::st, and cql_node::u.

Referenced by emit_term().