struct ccl_rpn_attr **qa);
static struct ccl_rpn_attr *add_attr_node (struct ccl_rpn_node *p,
struct ccl_rpn_attr **qa);
static struct ccl_rpn_attr *add_attr_node (struct ccl_rpn_node *p,
* set: Attribute set name
*/
static void add_attr_numeric (struct ccl_rpn_node *p, const char *set,
* set: Attribute set name
*/
static void add_attr_numeric (struct ccl_rpn_node *p, const char *set,
if (qual_val_type (qa, CCL_BIB1_STR, CCL_BIB1_STR_AND_LIST, 0))
and_list = 1;
if (qual_val_type (qa, CCL_BIB1_STR, CCL_BIB1_STR_AND_LIST, 0))
and_list = 1;
}
/* go through each TERM token. If no truncation attribute is yet
met, then look for left/right truncation markers (?) and
}
/* go through each TERM token. If no truncation attribute is yet
met, then look for left/right truncation markers (?) and
- switch(attr->kind)
- {
- case CCL_RPN_ATTR_STRING:
- add_attr_string(p, attr->set, attr->type,
- attr->value.str);
- break;
- case CCL_RPN_ATTR_NUMERIC:
- if (attr->value.numeric > 0)
- { /* deal only with REAL attributes (positive) */
- switch (attr->type)
- {
- case CCL_BIB1_REL:
- if (relation_value != -1)
- continue;
- relation_value = attr->value.numeric;
- break;
- case CCL_BIB1_POS:
- if (position_value != -1)
- continue;
- position_value = attr->value.numeric;
- break;
- case CCL_BIB1_STR:
- if (structure_value != -1)
- continue;
- structure_value = attr->value.numeric;
- break;
- case CCL_BIB1_TRU:
- if (truncation_value != -1)
- continue;
- truncation_value = attr->value.numeric;
- left_trunc = right_trunc = mid_trunc = 0;
- break;
- case CCL_BIB1_COM:
- if (completeness_value != -1)
- continue;
- completeness_value = attr->value.numeric;
- break;
- }
- add_attr_numeric(p, attr->set, attr->type,
- attr->value.numeric);
- }
- }
+ switch(attr->kind)
+ {
+ case CCL_RPN_ATTR_STRING:
+ add_attr_string(p, attr->set, attr->type,
+ attr->value.str);
+ break;
+ case CCL_RPN_ATTR_NUMERIC:
+ if (attr->value.numeric > 0)
+ { /* deal only with REAL attributes (positive) */
+ switch (attr->type)
+ {
+ case CCL_BIB1_REL:
+ if (relation_value != -1)
+ continue;
+ relation_value = attr->value.numeric;
+ break;
+ case CCL_BIB1_POS:
+ if (position_value != -1)
+ continue;
+ position_value = attr->value.numeric;
+ break;
+ case CCL_BIB1_STR:
+ if (structure_value != -1)
+ continue;
+ structure_value = attr->value.numeric;
+ break;
+ case CCL_BIB1_TRU:
+ if (truncation_value != -1)
+ continue;
+ truncation_value = attr->value.numeric;
+ left_trunc = right_trunc = mid_trunc = 0;
+ break;
+ case CCL_BIB1_COM:
+ if (completeness_value != -1)
+ continue;
+ completeness_value = attr->value.numeric;
+ break;
+ }
+ add_attr_numeric(p, attr->set, attr->type,
+ attr->value.numeric);
+ }
+ }
- int len = strlen(p->u.t.term);
- if (len &&
- !strchr("-+", *src_str) &&
- !strchr("-+", p->u.t.term[len-1]))
- {
- strcat (p->u.t.term, " ");
- }
+ size_t len = strlen(p->u.t.term);
+ memcpy(p->u.t.term + len, cclp->look_token->ws_prefix_buf,
+ cclp->look_token->ws_prefix_len);
+ p->u.t.term[len + cclp->look_token->ws_prefix_len] = '\0';
- qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_PORDER, 0))
+ qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_PORDER, 0))
- /* allow - inside term and treat it as range _always_ */
- /* relation is =. Extract "embedded" - to separate terms */
- if (KIND == CCL_TOK_TERM)
- {
- size_t i;
- for (i = 0; i<cclp->look_token->len; i++)
- {
- if (cclp->look_token->name[i] == '-')
- break;
- }
-
- if (cclp->look_token->len > 1 && i == 0)
- { /* -xx*/
- struct ccl_token *ntoken = ccl_token_add (cclp->look_token);
-
- ntoken->kind = CCL_TOK_TERM;
- ntoken->name = cclp->look_token->name + 1;
- ntoken->len = cclp->look_token->len - 1;
-
- cclp->look_token->len = 1;
- cclp->look_token->name = "-";
- }
- else if (cclp->look_token->len > 1 && i == cclp->look_token->len-1)
- { /* xx- */
- struct ccl_token *ntoken = ccl_token_add (cclp->look_token);
+ /* allow - inside term and treat it as range _always_ */
+ /* relation is =. Extract "embedded" - to separate terms */
+ if (KIND == CCL_TOK_TERM)
+ {
+ size_t i;
+ for (i = 0; i<cclp->look_token->len; i++)
+ {
+ if (cclp->look_token->name[i] == '-')
+ break;
+ }
+
+ if (cclp->look_token->len > 1 && i == 0)
+ { /* -xx*/
+ struct ccl_token *ntoken = ccl_token_add (cclp->look_token);
- (cclp->look_token->len)--;
- }
- else if (cclp->look_token->len > 2 && i < cclp->look_token->len)
- { /* xx-yy */
- struct ccl_token *ntoken1 = ccl_token_add (cclp->look_token);
- struct ccl_token *ntoken2 = ccl_token_add (ntoken1);
+ cclp->look_token->len = 1;
+ cclp->look_token->name = "-";
+ }
+ else if (cclp->look_token->len > 1 && i == cclp->look_token->len-1)
+ { /* xx- */
+ struct ccl_token *ntoken = ccl_token_add (cclp->look_token);
- ntoken2->kind = CCL_TOK_TERM; /* generate yy */
- ntoken2->name = cclp->look_token->name + (i+1);
- ntoken2->len = cclp->look_token->len - (i+1);
+ (cclp->look_token->len)--;
+ }
+ else if (cclp->look_token->len > 2 && i < cclp->look_token->len)
+ { /* xx-yy */
+ struct ccl_token *ntoken1 = ccl_token_add (cclp->look_token);
+ struct ccl_token *ntoken2 = ccl_token_add (ntoken1);
- cclp->look_token->len = i; /* adjust xx */
- }
- else if (i == cclp->look_token->len &&
- cclp->look_token->next &&
- cclp->look_token->next->kind == CCL_TOK_TERM &&
- cclp->look_token->next->len > 1 &&
- cclp->look_token->next->name[0] == '-')
-
- { /* xx -yy */
- /* we _know_ that xx does not have - in it */
- struct ccl_token *ntoken = ccl_token_add (cclp->look_token);
+ ntoken1->kind = CCL_TOK_TERM; /* generate - */
+ ntoken1->name = "-";
+ ntoken1->len = 1;
- (ntoken->next->name)++; /* adjust yy */
- (ntoken->next->len)--;
- }
- }
+ cclp->look_token->len = i; /* adjust xx */
+ }
+ else if (i == cclp->look_token->len &&
+ cclp->look_token->next &&
+ cclp->look_token->next->kind == CCL_TOK_TERM &&
+ cclp->look_token->next->len > 1 &&
+ cclp->look_token->next->name[0] == '-')
+
+ { /* xx -yy */
+ /* we _know_ that xx does not have - in it */
+ struct ccl_token *ntoken = ccl_token_add (cclp->look_token);
+
+ ntoken->kind = CCL_TOK_TERM; /* generate - */
+ ntoken->name = "-";
+ ntoken->len = 1;
+
+ (ntoken->next->name)++; /* adjust yy */
+ (ntoken->next->len)--;
+ }
+ }
- KIND == CCL_TOK_TERM &&
- cclp->look_token->next && cclp->look_token->next->len == 1 &&
- cclp->look_token->next->name[0] == '-')
+ KIND == CCL_TOK_TERM &&
+ cclp->look_token->next && cclp->look_token->next->len == 1 &&
+ cclp->look_token->next->name[0] == '-')
- struct ccl_rpn_node *p1;
- if (!(p1 = search_term (cclp, ap)))
- return NULL;
- ADVANCE; /* skip '-' */
- if (KIND == CCL_TOK_TERM) /* = term - term ? */
- {
- struct ccl_rpn_node *p2;
-
- if (!(p2 = search_term (cclp, ap)))
- {
- ccl_rpn_delete (p1);
- return NULL;
- }
- p = mk_node (CCL_RPN_AND);
- p->u.p[0] = p1;
- add_attr_numeric (p1, attset, CCL_BIB1_REL, 4);
- p->u.p[1] = p2;
- add_attr_numeric (p2, attset, CCL_BIB1_REL, 2);
- return p;
- }
- else /* = term - */
- {
- add_attr_numeric (p1, attset, CCL_BIB1_REL, 4);
- return p1;
- }
+ struct ccl_rpn_node *p1;
+ if (!(p1 = search_term (cclp, ap)))
+ return NULL;
+ ADVANCE; /* skip '-' */
+ if (KIND == CCL_TOK_TERM) /* = term - term ? */
+ {
+ struct ccl_rpn_node *p2;
+
+ if (!(p2 = search_term (cclp, ap)))
+ {
+ ccl_rpn_delete (p1);
+ return NULL;
+ }
+ p = mk_node (CCL_RPN_AND);
+ p->u.p[0] = p1;
+ add_attr_numeric (p1, attset, CCL_BIB1_REL, 4);
+ p->u.p[1] = p2;
+ add_attr_numeric (p2, attset, CCL_BIB1_REL, 2);
+ return p;
+ }
+ else /* = term - */
+ {
+ add_attr_numeric (p1, attset, CCL_BIB1_REL, 4);
+ return p1;
+ }
- ADVANCE;
- if (!(p = search_term (cclp, ap)))
- return NULL;
- add_attr_numeric (p, attset, CCL_BIB1_REL, 2);
- return p;
+ ADVANCE;
+ if (!(p = search_term (cclp, ap)))
+ return NULL;
+ add_attr_numeric (p, attset, CCL_BIB1_REL, 2);
+ return p;
- ADVANCE;
- if (!(p = find_spec (cclp, ap)))
- return NULL;
- if (KIND != CCL_TOK_RP)
- {
- cclp->error_code = CCL_ERR_RP_EXPECTED;
- ccl_rpn_delete (p);
- return NULL;
- }
- ADVANCE;
- return p;
+ ADVANCE;
+ if (!(p = find_spec (cclp, ap)))
+ return NULL;
+ if (KIND != CCL_TOK_RP)
+ {
+ cclp->error_code = CCL_ERR_RP_EXPECTED;
+ ccl_rpn_delete (p);
+ return NULL;
+ }
+ ADVANCE;
+ return p;
- if (!(p = search_terms (cclp, ap)))
- return NULL;
- add_attr_numeric (p, attset, CCL_BIB1_REL, rel);
- return p;
+ if (!(p = search_terms (cclp, ap)))
+ return NULL;
+ add_attr_numeric (p, attset, CCL_BIB1_REL, rel);
+ return p;
struct ccl_rpn_node *p;
if (qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_ORDER, &attset)
struct ccl_rpn_node *p;
if (qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_ORDER, &attset)
- || qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_PORDER, &attset))
- return qualifiers_order(cclp, ap, attset);
+ || qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_PORDER, &attset))
+ return qualifiers_order(cclp, ap, attset);
- ADVANCE;
- if (!(p = find_spec (cclp, ap)))
- {
- return NULL;
- }
- if (KIND != CCL_TOK_RP)
- {
- cclp->error_code = CCL_ERR_RP_EXPECTED;
- ccl_rpn_delete (p);
- return NULL;
- }
- ADVANCE;
+ ADVANCE;
+ if (!(p = find_spec (cclp, ap)))
+ {
+ return NULL;
+ }
+ if (KIND != CCL_TOK_RP)
+ {
+ cclp->error_code = CCL_ERR_RP_EXPECTED;
+ ccl_rpn_delete (p);
+ return NULL;
+ }
+ ADVANCE;
-struct ccl_rpn_node *ccl_parser_find (CCL_parser cclp, struct ccl_token *list)
+struct ccl_rpn_node *ccl_parser_find_str(CCL_parser cclp, const char *str)
+{
+ struct ccl_rpn_node *p;
+ struct ccl_token *list = ccl_parser_tokenize(cclp, str);
+ p = ccl_parser_find_token(cclp, list);
+ ccl_token_del(list);
+ return p;
+}
+
+struct ccl_rpn_node *ccl_parser_find_token(CCL_parser cclp,
+ struct ccl_token *list)
- * ccl_find: Parse CCL find - token representation
- * bibset: Bibset to be used for the parsing
- * list: List of tokens
- * 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.
- */
-struct ccl_rpn_node *ccl_find (CCL_bibset bibset, struct ccl_token *list,
- int *error, const char **pos)
-{
- struct ccl_rpn_node *p;
- CCL_parser cclp = ccl_parser_create ();
-
- cclp->bibset = bibset;
-
- p = ccl_parser_find (cclp, list);
-
- *error = cclp->error_code;
- *pos = cclp->error_pos;
-
- ccl_parser_destroy (cclp);
-
- return p;
-}
-
-/**
* ccl_find_str: Parse CCL find - string representation
* bibset: Bibset to be used for the parsing
* str: String to be parsed
* ccl_find_str: Parse CCL find - string representation
* bibset: Bibset to be used for the parsing
* str: String to be parsed
* pos: Pointer to char position. Holds approximate error position.
* return: RPN tree on successful completion; NULL otherwise.
*/
* pos: Pointer to char position. Holds approximate error position.
* return: RPN tree on successful completion; NULL otherwise.
*/