From: Adam Dickmeiss Date: Mon, 16 May 2011 13:53:10 +0000 (+0200) Subject: Add z_Term_create for creating Z_Term things X-Git-Tag: v4.2.0~10 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=66dd1c1a5916fa62a186ba7d95804aa5a3fe6ca2;p=yaz-moved-to-github.git Add z_Term_create for creating Z_Term things --- diff --git a/include/yaz/pquery.h b/include/yaz/pquery.h index 965b1ef..026baa9 100644 --- a/include/yaz/pquery.h +++ b/include/yaz/pquery.h @@ -60,6 +60,9 @@ YAZ_EXPORT void yaz_pqf_destroy(YAZ_PQF_Parser p); YAZ_EXPORT int yaz_pqf_error(YAZ_PQF_Parser p, const char **msg, size_t *off); +YAZ_EXPORT +Z_Term *z_Term_create(ODR o, int term_type, const char *buf, size_t len); + /* no error */ #define YAZ_PQF_ERROR_NONE 0 diff --git a/src/pquery.c b/src/pquery.c index dceed33..bd0671a 100644 --- a/src/pquery.c +++ b/src/pquery.c @@ -304,23 +304,16 @@ Z_AttributeList *get_attributeList(ODR o, return attributes; } -static Z_AttributesPlusTerm *rpn_term_attributes(struct yaz_pqf_parser *li, ODR o, Z_AttributeList *attributes) { - Z_AttributesPlusTerm *zapt; - Odr_oct *term_octet; - Z_Term *term; - - zapt = (Z_AttributesPlusTerm *)odr_malloc(o, sizeof(*zapt)); - term = (Z_Term *)odr_malloc(o, sizeof(*term)); - zapt->term = term; - zapt->attributes = attributes; - - term_octet = (Odr_oct *)odr_malloc(o, sizeof(*term_octet)); - term_octet->buf = (unsigned char *)odr_malloc(o, 1 + li->lex_len); - term_octet->size = term_octet->len = - escape_string((char *) (term_octet->buf), li->lex_buf, li->lex_len); +Z_Term *z_Term_create(ODR o, int term_type, const char *buf, size_t len) +{ + Z_Term *term = (Z_Term *)odr_malloc(o, sizeof(*term)); + Odr_oct *term_octet = (Odr_oct *)odr_malloc(o, sizeof(*term_octet)); + term_octet->buf = (unsigned char *)odr_malloc(o, 1 + len); + memcpy(term_octet->buf, buf, len); + term_octet->size = term_octet->len = len; term_octet->buf[term_octet->size] = 0; /* null terminate */ - switch (li->term_type) + switch (term_type) { case Z_Term_general: term->which = Z_Term_general; @@ -348,8 +341,21 @@ static Z_AttributesPlusTerm *rpn_term_attributes(struct yaz_pqf_parser *li, ODR term->u.null = odr_nullval(); break; } - return zapt; + return term; +} + +static Z_AttributesPlusTerm *rpn_term_attributes( + struct yaz_pqf_parser *li, ODR o, Z_AttributeList *attributes) +{ + char *es_str = odr_malloc(o, li->lex_len+1); + int es_len = escape_string(es_str, li->lex_buf, li->lex_len); + Z_Term *term = z_Term_create(o, li->term_type, es_str, es_len); + Z_AttributesPlusTerm *zapt = (Z_AttributesPlusTerm *) + odr_malloc(o, sizeof(*zapt)); + zapt->term = term; + zapt->attributes = attributes; + return zapt; } static Z_AttributesPlusTerm *rpn_term(struct yaz_pqf_parser *li, ODR o,