YAZ  4.2.57
Macros | Functions
cclfind.c File Reference

Implements parsing of a CCL FIND query. More...

#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "cclp.h"

Go to the source code of this file.

Macros

#define KIND   (cclp->look_token->kind)
#define ADVANCE   cclp->look_token = cclp->look_token->next
#define REGEX_CHARS   "^[]{}()|.*+?!$"
#define CCL_CHARS   "#?\\"

Functions

static int qual_val_type (ccl_qualifier_t *qa, int type, int value, char **attset)
static void strxcat (char *n, const char *src, int len)
static char * copy_token_name (struct ccl_token *tp)
struct ccl_rpn_nodeccl_rpn_node_create (enum ccl_rpn_kind kind)
void ccl_rpn_delete (struct ccl_rpn_node *rpn)
static struct ccl_rpn_nodefind_spec (CCL_parser cclp, ccl_qualifier_t *qa)
static int is_term_ok (int look, int *list)
static struct ccl_rpn_nodesearch_terms (CCL_parser cclp, ccl_qualifier_t *qa)
static struct ccl_rpn_attradd_attr_node (struct ccl_rpn_node *p, const char *set, int type)
void ccl_add_attr_numeric (struct ccl_rpn_node *p, const char *set, int type, int value)
void ccl_add_attr_string (struct ccl_rpn_node *p, const char *set, int type, char *value)
static size_t cmp_operator (const char **aliases, const char *input)
static int append_term (CCL_parser cclp, const char *src_str, size_t src_len, char *dst_term, int *regex_trunc, int *z3958_trunc, const char **truncation_aliases, int is_first, int is_last, int *left_trunc, int *right_trunc)
static struct ccl_rpn_nodesearch_term_x (CCL_parser cclp, ccl_qualifier_t *qa, int *term_list, int multi)
static struct ccl_rpn_nodesearch_term (CCL_parser cclp, ccl_qualifier_t *qa)
static struct ccl_rpn_nodesearch_terms2 (CCL_parser cclp, ccl_qualifier_t *qa)
static struct ccl_rpn_nodequalifiers_order (CCL_parser cclp, ccl_qualifier_t *ap, char *attset)
static struct ccl_rpn_nodequalifier_relation (CCL_parser cclp, ccl_qualifier_t *ap)
static struct ccl_rpn_nodequalifier_list (CCL_parser cclp, struct ccl_token *la, ccl_qualifier_t *qa)
static struct ccl_rpn_nodesearch_elements (CCL_parser cclp, ccl_qualifier_t *qa)
struct ccl_rpn_nodeccl_parser_find_str (CCL_parser cclp, const char *str)
 parse CCL find string with parser and return RPN tree
struct ccl_rpn_nodeccl_parser_find_token (CCL_parser cclp, struct ccl_token *list)
struct ccl_rpn_nodeccl_find_str (CCL_bibset bibset, const char *str, int *error, int *pos)
 parse CCL find string using CCL profile return RPN tree

Detailed Description

Implements parsing of a CCL FIND query.

This source file implements parsing of a CCL Query (ISO8777). The parser uses predictive parsing, but it does several tokens of lookahead in the handling of relational operations.. So it's not really pure.

Definition in file cclfind.c.

Macro Definition Documentation

#define ADVANCE   cclp->look_token = cclp->look_token->next
#define CCL_CHARS   "#?\\"

Definition at line 231 of file cclfind.c.

Referenced by append_term().

#define KIND   (cclp->look_token->kind)
#define REGEX_CHARS   "^[]{}()|.*+?!$"

Definition at line 230 of file cclfind.c.

Referenced by append_term().

Function Documentation

static struct ccl_rpn_attr* add_attr_node ( struct ccl_rpn_node p,
const char *  set,
int  type 
)
staticread
static int append_term ( CCL_parser  cclp,
const char *  src_str,
size_t  src_len,
char *  dst_term,
int *  regex_trunc,
int *  z3958_trunc,
const char **  truncation_aliases,
int  is_first,
int  is_last,
int *  left_trunc,
int *  right_trunc 
)
static
void ccl_add_attr_numeric ( struct ccl_rpn_node p,
const char *  set,
int  type,
int  value 
)

add_attr_numeric: Add attribute (type/value) to RPN term node. p: RPN node of type term. type: Type of attribute value: Value of attribute set: Attribute set name

Definition at line 195 of file cclfind.c.

References add_attr_node(), CCL_RPN_ATTR_NUMERIC, ccl_rpn_attr::kind, ccl_rpn_attr::numeric, and ccl_rpn_attr::value.

Referenced by qualifiers_order(), and search_term_x().

void ccl_add_attr_string ( struct ccl_rpn_node p,
const char *  set,
int  type,
char *  value 
)
struct ccl_rpn_node* ccl_find_str ( CCL_bibset  bibset,
const char *  str,
int *  error,
int *  pos 
)
read

parse CCL find string using CCL profile return RPN tree

ccl_find_str: Parse CCL find - string representation bibset: Bibset to be used for the parsing str: String to be parsed error: Pointer to integer. Holds error no. on completion. pos: Pointer to char position. Holds approximate error position. return: RPN tree on successful completion; NULL otherwise.

Definition at line 1196 of file cclfind.c.

References ccl_parser_create(), ccl_parser_destroy(), ccl_parser_find_token(), ccl_parser_tokenize(), ccl_token_del(), ccl_parser::error_code, ccl_parser::error_pos, and ccl_rpn_node::p.

Referenced by ccl2pqf(), and ZOOM_query_ccl2rpn().

struct ccl_rpn_node* ccl_parser_find_str ( CCL_parser  cclp,
const char *  str 
)
read

parse CCL find string with parser and return RPN tree

Parses a CCL Find command in a simple C string. Returns CCL parse tree node describing RPN if parsing is successful. If parsing is unsuccesful, NULL is returned and error and pos is set accordingly.

Definition at line 1155 of file cclfind.c.

References ccl_parser_find_token(), ccl_parser_tokenize(), ccl_token_del(), and ccl_rpn_node::p.

struct ccl_rpn_node* ccl_parser_find_token ( CCL_parser  cclp,
struct ccl_token list 
)
read
void ccl_rpn_delete ( struct ccl_rpn_node rpn)
struct ccl_rpn_node* ccl_rpn_node_create ( enum ccl_rpn_kind  kind)
read

mk_node: Create RPN node. kind: Type of node. return: pointer to allocated node.

Definition at line 96 of file cclfind.c.

References ccl_assert, CCL_RPN_TERM, ccl_rpn_node::kind, ccl_rpn_node::p, ccl_rpn_node::t, ccl_rpn_node::u, and xmalloc.

Referenced by find_spec(), qualifier_list(), qualifiers_order(), search_elements(), search_term_x(), and search_terms().

static size_t cmp_operator ( const char **  aliases,
const char *  input 
)
static

Definition at line 215 of file cclfind.c.

Referenced by append_term().

static char* copy_token_name ( struct ccl_token tp)
static

copy_token_name: Return copy of CCL token name tp: Pointer to token info. return: malloc(3) allocated copy of token name.

Definition at line 82 of file cclfind.c.

References ccl_assert, ccl_token::len, ccl_token::name, ccl_rpn_attr::str, and xmalloc.

Referenced by search_elements().

static struct ccl_rpn_node * find_spec ( CCL_parser  cclp,
ccl_qualifier_t qa 
)
staticread

find_spec: Parse CCL find specification cclp: CCL Parser qa: Qualifier attributes already applied. return: pointer to node(s); NULL on error.

Definition at line 1098 of file cclfind.c.

References ADVANCE, CCL_RPN_AND, ccl_rpn_delete(), ccl_rpn_node_create(), CCL_RPN_NOT, CCL_RPN_OR, CCL_TOK_AND, CCL_TOK_NOT, CCL_TOK_OR, KIND, ccl_rpn_node::p, search_elements(), and ccl_rpn_node::u.

Referenced by ccl_parser_find_token(), and search_terms2().

static int is_term_ok ( int  look,
int *  list 
)
static

Definition at line 160 of file cclfind.c.

Referenced by search_term_x(), and search_terms().

static int qual_val_type ( ccl_qualifier_t qa,
int  type,
int  value,
char **  attset 
)
static

qual_val_type: test for existance of attribute type/value pair. qa: Attribute array type: Type of attribute to search for value: Value of attribute to seach for return: 1 if found; 0 otherwise.

Definition at line 37 of file cclfind.c.

References ccl_qual_get_attr(), CCL_RPN_ATTR_NUMERIC, ccl_rpn_attr::kind, ccl_rpn_attr::next, ccl_rpn_attr::numeric, ccl_rpn_attr::set, ccl_rpn_attr::type, and ccl_rpn_attr::value.

Referenced by qualifier_relation(), qualifiers_order(), and search_term_x().

static struct ccl_rpn_node* qualifier_list ( CCL_parser  cclp,
struct ccl_token la,
ccl_qualifier_t qa 
)
staticread

qualifier_list: Parse CCL qualifiers and search terms. cclp: CCL Parser la: Token pointer to RELATION token. qa: Qualifier attributes already applied. return: pointer to node(s); NULL on error.

Definition at line 802 of file cclfind.c.

References ccl_parser::bibset, ccl_assert, CCL_ERR_DOUBLE_QUAL, CCL_ERR_UNKNOWN_QUAL, ccl_qual_search(), ccl_qual_search_special(), ccl_rpn_delete(), ccl_rpn_node_create(), CCL_RPN_OR, CCL_TOK_COMMA, ccl_parser::error_code, ccl_token::kind, ccl_token::len, ccl_parser::look_token, ccl_token::name, ccl_token::next, node(), ccl_rpn_node::p, qualifier_relation(), ccl_rpn_node::u, xfree, and xmalloc.

Referenced by search_elements().

static struct ccl_rpn_node* qualifier_relation ( CCL_parser  cclp,
ccl_qualifier_t ap 
)
staticread
static struct ccl_rpn_node* qualifiers_order ( CCL_parser  cclp,
ccl_qualifier_t ap,
char *  attset 
)
staticread
static struct ccl_rpn_node* search_elements ( CCL_parser  cclp,
ccl_qualifier_t qa 
)
staticread

search_elements: Parse CCL search elements cclp: CCL Parser qa: Qualifier attributes already applied. return: pointer to node(s); NULL on error.

Definition at line 1018 of file cclfind.c.

References ADVANCE, CCL_ERR_SETNAME_EXPECTED, ccl_qual_search(), ccl_rpn_delete(), ccl_rpn_node_create(), CCL_RPN_OR, CCL_RPN_SET, CCL_TOK_COMMA, CCL_TOK_EQ, CCL_TOK_LP, CCL_TOK_REL, CCL_TOK_SET, CCL_TOK_TERM, copy_token_name(), ccl_parser::error_code, KIND, ccl_token::kind, ccl_parser::look_token, ccl_token::next, node(), ccl_rpn_node::p, qualifier_list(), search_terms(), ccl_rpn_node::setname, and ccl_rpn_node::u.

Referenced by find_spec().

static struct ccl_rpn_node* search_term ( CCL_parser  cclp,
ccl_qualifier_t qa 
)
staticread

Definition at line 586 of file cclfind.c.

References CCL_TOK_COMMA, CCL_TOK_TERM, and search_term_x().

Referenced by qualifiers_order().

static struct ccl_rpn_node* search_term_x ( CCL_parser  cclp,
ccl_qualifier_t qa,
int *  term_list,
int  multi 
)
staticread
static struct ccl_rpn_node * search_terms ( CCL_parser  cclp,
ccl_qualifier_t qa 
)
staticread

search_terms: Parse CCL search terms - including proximity. cclp: CCL Parser qa: Qualifier attributes already applied. return: pointer to node(s); NULL on error.

Definition at line 956 of file cclfind.c.

References ADVANCE, ccl_rpn_delete(), ccl_rpn_node_create(), CCL_RPN_PROX, CCL_RPN_TERM, CCL_TOK_COMMA, CCL_TOK_EQ, CCL_TOK_PROX, CCL_TOK_REL, CCL_TOK_SET, CCL_TOK_TERM, is_term_ok(), KIND, ccl_token::len, ccl_parser::look_token, ccl_token::name, ccl_rpn_node::p, search_terms2(), ccl_rpn_node::t, ccl_rpn_node::u, and xmalloc.

Referenced by qualifier_relation(), qualifiers_order(), and search_elements().

static struct ccl_rpn_node* search_terms2 ( CCL_parser  cclp,
ccl_qualifier_t qa 
)
staticread
static void strxcat ( char *  n,
const char *  src,
int  len 
)
static

strxcat: concatenate strings. n: Null-terminated Destination string src: Source string to be appended (not null-terminated) len: Length of source string.

Definition at line 68 of file cclfind.c.

Referenced by append_term(), and search_term_x().