X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fcclqual.c;h=1c2dc1ee3a6545a8a29f927f3ec9878164755c5a;hb=f6ae71f4b4a45b3989700f5e1a73c40ccd53040a;hp=24ea31ca4cb0c058b01ddd41c2bbd83900097bb0;hpb=fb6d99a0c7e07d9cc4a315c447deaf6564a85505;p=yaz-moved-to-github.git diff --git a/src/cclqual.c b/src/cclqual.c index 24ea31c..1c2dc1e 100644 --- a/src/cclqual.c +++ b/src/cclqual.c @@ -48,7 +48,7 @@ /* CCL qualifiers * Europagate, 1995 * - * $Id: cclqual.c,v 1.3 2005-06-25 15:46:03 adam Exp $ + * $Id: cclqual.c,v 1.8 2007-04-30 11:33:49 adam Exp $ * * Old Europagate Log: * @@ -86,7 +86,17 @@ #include #include -#include +#include "cclp.h" + +/** CCL Qualifier */ +struct ccl_qualifier { + char *name; + int no_sub; + struct ccl_qualifier **sub; + struct ccl_rpn_attr *attr_list; + struct ccl_qualifier *next; +}; + /** Definition of CCL_bibset pointer */ struct ccl_qualifiers { @@ -103,18 +113,22 @@ struct ccl_qualifier_special { }; -static struct ccl_qualifier *ccl_qual_lookup (CCL_bibset b, - const char *n, size_t len) +static struct ccl_qualifier *ccl_qual_lookup(CCL_bibset b, + const char *n, size_t len) { struct ccl_qualifier *q; for (q = b->list; q; q = q->next) - if (len == strlen(q->name) && !memcmp (q->name, n, len)) + if (len == strlen(q->name) && !memcmp(q->name, n, len)) break; return q; } - -void ccl_qual_add_special (CCL_bibset bibset, const char *n, const char *v) +/** \brief specifies special qualifier + \param bibset Bibset + \param n name of special (without leading @) + \param v value of special +*/ +void ccl_qual_add_special(CCL_bibset bibset, const char *n, const char *v) { struct ccl_qualifier_special *p; const char *pe; @@ -122,11 +136,11 @@ void ccl_qual_add_special (CCL_bibset bibset, const char *n, const char *v) for (p = bibset->special; p && strcmp(p->name, n); p = p->next) ; if (p) - xfree (p->value); + xfree(p->value); else { - p = (struct ccl_qualifier_special *) xmalloc (sizeof(*p)); - p->name = ccl_strdup (n); + p = (struct ccl_qualifier_special *) xmalloc(sizeof(*p)); + p->name = xstrdup(n); p->value = 0; p->next = bibset->special; bibset->special = p; @@ -136,9 +150,9 @@ void ccl_qual_add_special (CCL_bibset bibset, const char *n, const char *v) for (pe = v + strlen(v); pe != v; --pe) if (!strchr(" \n\r\t", pe[-1])) break; - p->value = (char*) xmalloc (pe - v + 1); + p->value = (char*) xmalloc(pe - v + 1); if (pe - v) - memcpy (p->value, v, pe - v); + memcpy(p->value, v, pe - v); p->value[pe - v] = '\0'; } @@ -160,7 +174,13 @@ static int next_token(const char **cpp, const char **dst) return len; } -void ccl_qual_add_combi (CCL_bibset b, const char *n, const char *names) +/** \brief adds specifies qualifier aliases + + \param b bibset + \param n qualifier name + \param names list of qualifier aliases +*/ +void ccl_qual_add_combi(CCL_bibset b, const char *n, const char *names) { const char *cp, *cp1; int i, len; @@ -169,8 +189,8 @@ void ccl_qual_add_combi (CCL_bibset b, const char *n, const char *names) ; if (q) return ; - q = (struct ccl_qualifier *) xmalloc (sizeof(*q)); - q->name = ccl_strdup (n); + q = (struct ccl_qualifier *) xmalloc(sizeof(*q)); + q->name = xstrdup(n); q->attr_list = 0; q->next = b->list; b->list = q; @@ -179,65 +199,60 @@ void ccl_qual_add_combi (CCL_bibset b, const char *n, const char *names) for (i = 0; next_token(&cp, 0); i++) ; q->no_sub = i; - q->sub = (struct ccl_qualifier **) xmalloc (sizeof(*q->sub) * - (1+q->no_sub)); + q->sub = (struct ccl_qualifier **) xmalloc(sizeof(*q->sub) * + (1+q->no_sub)); cp = names; for (i = 0; (len = next_token(&cp, &cp1)); i++) { - q->sub[i] = ccl_qual_lookup (b, cp1, len); + q->sub[i] = ccl_qual_lookup(b, cp1, len); } } -/** - * ccl_qual_add: Add qualifier to Bibset. If qualifier already - * exists, then attributes are appendend to old - * definition. - * name: name of qualifier - * no: No of attribute type/value pairs. - * pairs: Attributes. pairs[0] first type, pair[1] first value, - * ... pair[2*no-2] last type, pair[2*no-1] last value. - */ +/** \brief adds specifies attributes for qualifier + + \param b bibset + \param name qualifier name + \param no number of attribute type+value pairs + \param type_ar attributes type of size no + \param value_ar attribute value of size no + \param svalue_ar attribute string values ([i] only used if != NULL) + \param attsets attribute sets of size no +*/ -void ccl_qual_add_set (CCL_bibset b, const char *name, int no, +void ccl_qual_add_set(CCL_bibset b, const char *name, int no, int *type_ar, int *value_ar, char **svalue_ar, char **attsets) { struct ccl_qualifier *q; struct ccl_rpn_attr **attrp; - ccl_assert (b); + ccl_assert(b); for (q = b->list; q; q = q->next) - if (!strcmp (name, q->name)) + if (!strcmp(name, q->name)) break; if (!q) { - struct ccl_qualifier *new_qual = - (struct ccl_qualifier *)xmalloc (sizeof(*new_qual)); - ccl_assert (new_qual); + q = (struct ccl_qualifier *)xmalloc(sizeof(*q)); + ccl_assert(q); - new_qual->next = b->list; - b->list = new_qual; + q->next = b->list; + b->list = q; - new_qual->name = ccl_strdup (name); - attrp = &new_qual->attr_list; + q->name = xstrdup(name); + q->attr_list = 0; - new_qual->no_sub = 0; - new_qual->sub = 0; - } - else - { - if (q->sub) /* suspect.. */ - xfree (q->sub); - attrp = &q->attr_list; - while (*attrp) - attrp = &(*attrp)->next; + q->no_sub = 0; + q->sub = 0; } + attrp = &q->attr_list; + while (*attrp) + attrp = &(*attrp)->next; while (--no >= 0) { struct ccl_rpn_attr *attr; - attr = (struct ccl_rpn_attr *)xmalloc (sizeof(*attr)); - ccl_assert (attr); + attr = (struct ccl_rpn_attr *)xmalloc(sizeof(*attr)); + ccl_assert(attr); attr->set = *attsets++; attr->type = *type_ar++; if (*svalue_ar) @@ -258,24 +273,24 @@ void ccl_qual_add_set (CCL_bibset b, const char *name, int no, *attrp = NULL; } -/** - * ccl_qual_mk: Make new (empty) bibset. - * return: empty bibset. +/** \brief creates Bibset + \returns bibset */ -CCL_bibset ccl_qual_mk (void) +CCL_bibset ccl_qual_mk(void) { - CCL_bibset b = (CCL_bibset)xmalloc (sizeof(*b)); - ccl_assert (b); + CCL_bibset b = (CCL_bibset)xmalloc(sizeof(*b)); + ccl_assert(b); b->list = NULL; b->special = NULL; return b; } -/** - * ccl_qual_rm: Delete bibset. - * b: pointer to bibset +/** \brief destroys Bibset + \param b pointer to Bibset + + *b will be set to NULL. */ -void ccl_qual_rm (CCL_bibset *b) +void ccl_qual_rm(CCL_bibset *b) { struct ccl_qualifier *q, *q1; struct ccl_qualifier_special *sp, *sp1; @@ -293,76 +308,80 @@ void ccl_qual_rm (CCL_bibset *b) xfree(attr->set); if (attr->kind == CCL_RPN_ATTR_STRING) xfree(attr->value.str); - xfree (attr); + xfree(attr); } q1 = q->next; - xfree (q->name); + xfree(q->name); if (q->sub) - xfree (q->sub); - xfree (q); + xfree(q->sub); + xfree(q); } for (sp = (*b)->special; sp; sp = sp1) { sp1 = sp->next; - xfree (sp->name); - xfree (sp->value); - xfree (sp); + xfree(sp->name); + xfree(sp->value); + xfree(sp); } - xfree (*b); + xfree(*b); *b = NULL; } -/** - * ccl_qual_search: Search for qualifier in bibset. - * b: Bibset - * name: Name of qualifier to search for (need no null-termination) - * len: Length of name. - * return: Attribute info. NULL if not found. - */ -struct ccl_rpn_attr *ccl_qual_search (CCL_parser cclp, - const char *name, size_t len, - int seq) +ccl_qualifier_t ccl_qual_search(CCL_parser cclp, const char *name, + size_t name_len, int seq) { - struct ccl_qualifier *q; + struct ccl_qualifier *q = 0; const char *aliases; int case_sensitive = cclp->ccl_case_sensitive; - ccl_assert (cclp); + ccl_assert(cclp); if (!cclp->bibset) - return NULL; + return 0; aliases = ccl_qual_search_special(cclp->bibset, "case"); if (aliases) case_sensitive = atoi(aliases); for (q = cclp->bibset->list; q; q = q->next) - if (strlen(q->name) == len) + if (strlen(q->name) == name_len) { if (case_sensitive) { - if (!memcmp (name, q->name, len)) + if (!memcmp(name, q->name, name_len)) break; } else { - if (!ccl_memicmp (name, q->name, len)) + if (!ccl_memicmp(name, q->name, name_len)) break; } } if (q) { - if (q->attr_list && seq == 0) - return q->attr_list; - if (seq < q->no_sub && q->sub[seq]) + if (q->no_sub) { - return q->sub[seq]->attr_list; + if (seq < q->no_sub) + q = q->sub[seq]; + else + q = 0; } + else if (seq) + q = 0; } - return 0; + return q; +} + +struct ccl_rpn_attr *ccl_qual_get_attr(ccl_qualifier_t q) +{ + return q->attr_list; +} + +const char *ccl_qual_get_name(ccl_qualifier_t q) +{ + return q->name; } -const char *ccl_qual_search_special (CCL_bibset b, - const char *name) +const char *ccl_qual_search_special(CCL_bibset b, const char *name) { struct ccl_qualifier_special *q; if (!b)