YAZ  5.23.1
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)
 
static struct ccl_rpn_nodeccl_rpn_node_mkbool (struct ccl_rpn_node *l, struct ccl_rpn_node *r, enum ccl_rpn_kind op)
 
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_set_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 has_ccl_masking (const char *src_str, size_t src_len, const char **truncation_aliases, const char **mask_aliases)
 
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, const char **mask_aliases, int is_first, int is_last, int *left_trunc, int *right_trunc)
 
static struct ccl_rpn_nodeccl_term_one_use (CCL_parser cclp, struct ccl_token *lookahead0, struct ccl_rpn_attr *attr_use, ccl_qualifier_t *qa, size_t no, int is_phrase, int auto_group)
 
static struct ccl_rpn_nodeccl_term_multi_use (CCL_parser cclp, struct ccl_token *lookahead0, ccl_qualifier_t *qa, size_t no, int is_phrase, int auto_group)
 
static struct ccl_rpn_nodesplit_recur (CCL_parser cclp, ccl_qualifier_t *qa, struct ccl_token **ar, size_t sz, size_t sub_len)
 
static struct ccl_rpn_nodesearch_term_split_list (CCL_parser cclp, ccl_qualifier_t *qa, int *term_list, int multi)
 
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 More...
 
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 More...
 

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 263 of file cclfind.c.

Referenced by append_term().

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

Definition at line 262 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 
)
static
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,
const char **  mask_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 213 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 ccl_set_attr_numeric(), and ccl_term_one_use().

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 
)

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 1310 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 
)

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 1271 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 
)
void ccl_rpn_delete ( struct ccl_rpn_node rpn)
struct ccl_rpn_node* ccl_rpn_node_create ( enum ccl_rpn_kind  kind)

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

Definition at line 100 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 ccl_rpn_node_mkbool(), ccl_term_one_use(), qualifiers_order(), search_elements(), and search_terms().

static struct ccl_rpn_node* ccl_rpn_node_mkbool ( struct ccl_rpn_node l,
struct ccl_rpn_node r,
enum ccl_rpn_kind  op 
)
static
void ccl_set_attr_numeric ( struct ccl_rpn_node p,
const char *  set,
int  type,
int  value 
)
static struct ccl_rpn_node* ccl_term_multi_use ( CCL_parser  cclp,
struct ccl_token lookahead0,
ccl_qualifier_t qa,
size_t  no,
int  is_phrase,
int  auto_group 
)
static
static struct ccl_rpn_node* ccl_term_one_use ( CCL_parser  cclp,
struct ccl_token lookahead0,
struct ccl_rpn_attr attr_use,
ccl_qualifier_t qa,
size_t  no,
int  is_phrase,
int  auto_group 
)
static
static size_t cmp_operator ( const char **  aliases,
const char *  input 
)
static

Definition at line 247 of file cclfind.c.

Referenced by append_term(), and has_ccl_masking().

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 86 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 
)
static

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 1226 of file cclfind.c.

References ADVANCE, CCL_RPN_AND, ccl_rpn_delete(), ccl_rpn_node_mkbool(), CCL_RPN_NOT, CCL_RPN_OR, CCL_TOK_AND, CCL_TOK_NOT, CCL_TOK_OR, KIND, and search_elements().

Referenced by ccl_parser_find_token(), ccl_rpn_delete(), and search_terms2().

static int has_ccl_masking ( const char *  src_str,
size_t  src_len,
const char **  truncation_aliases,
const char **  mask_aliases 
)
static

Definition at line 265 of file cclfind.c.

References cmp_operator().

Referenced by ccl_term_one_use().

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

Definition at line 181 of file cclfind.c.

References search_terms().

Referenced by search_term_split_list(), 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 ccl_term_one_use(), 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 
)
static

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 958 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_mkbool(), 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(), qualifier_relation(), xfree, and xmalloc.

Referenced by search_elements().

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

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 1156 of file cclfind.c.

References ADVANCE, CCL_ERR_SETNAME_EXPECTED, ccl_qual_search(), ccl_rpn_delete(), ccl_rpn_node_create(), ccl_rpn_node_mkbool(), 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(), 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 
)
static

Definition at line 737 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_split_list ( CCL_parser  cclp,
ccl_qualifier_t qa,
int *  term_list,
int  multi 
)
static
static struct ccl_rpn_node* search_term_x ( CCL_parser  cclp,
ccl_qualifier_t qa,
int *  term_list,
int  multi 
)
static

search_term: Parse CCL search term. cclp: CCL Parser qa: Qualifier attributes already applied. term_list: tokens we accept as terms in context multi: whether we accept "multiple" tokens return: pointer to node(s); NULL on error.

Definition at line 667 of file cclfind.c.

References ADVANCE, CCL_BIB1_STR, CCL_BIB1_STR_AND_LIST, CCL_BIB1_STR_AUTO_GROUP, CCL_BIB1_STR_OR_LIST, CCL_BIB1_STR_SPLIT_LIST, CCL_ERR_TERM_EXPECTED, CCL_RPN_AND, ccl_rpn_node_mkbool(), CCL_RPN_OR, ccl_term_multi_use(), CCL_TOK_COMMA, ccl_parser::error_code, is_term_ok(), ccl_token::kind, ccl_token::len, ccl_parser::look_token, ccl_token::name, ccl_token::next, ccl_rpn_node::p, qual_val_type(), and search_term_split_list().

Referenced by search_term(), and search_terms2().

static struct ccl_rpn_node * search_terms ( CCL_parser  cclp,
ccl_qualifier_t qa 
)
static

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 1094 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 is_term_ok(), qualifier_relation(), qualifiers_order(), and search_elements().

static struct ccl_rpn_node* search_terms2 ( CCL_parser  cclp,
ccl_qualifier_t qa 
)
static
static struct ccl_rpn_node* split_recur ( CCL_parser  cclp,
ccl_qualifier_t qa,
struct ccl_token **  ar,
size_t  sz,
size_t  sub_len 
)
static
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 72 of file cclfind.c.

Referenced by append_term(), and ccl_term_one_use().