From 401da56d4a26f687cd42024bdef6f29a29bb7663 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 19 Mar 2007 14:40:06 +0000 Subject: [PATCH] API changes to WRBUF. wrbuf_free removed; replaced by wrbuf_destroy. And wrbuf_puts no longer appends '\0'. Use wrbuf_cstr to get C-string out. Deprecated functions for yaz_marc-removed. Changed prototype of yaz_marc_decode_buf: const char for result and size_t for rsize. --- NEWS | 8 +++++++ client/client.c | 14 +++++------ include/yaz/marcdisp.h | 18 ++------------ include/yaz/wrbuf.h | 9 +++---- src/cclptree.c | 3 ++- src/marcdisp.c | 61 ++++++------------------------------------------ src/querytowrbuf.c | 4 +++- src/record_conv.c | 6 ++--- src/retrieval.c | 6 ++--- src/seshigh.c | 42 ++++++++++++++++----------------- src/wrbuf.c | 27 +++++++-------------- src/yaz-ccl.c | 10 ++++---- src/zoom-c.c | 25 ++++++++++---------- test/tst_record_conv.c | 22 +++++++---------- test/tst_retrieval.c | 8 +++---- test/tstccl.c | 4 ++-- test/tsticonv.c | 4 ++-- test/tstpquery.c | 6 ++--- test/tstwrbuf.c | 6 ++--- test/tstxmlquery.c | 6 ++--- util/marcdump.c | 16 ++++++------- util/yaz-xmlquery.c | 4 ++-- ztest/read-marc.c | 12 ++++++---- 23 files changed, 128 insertions(+), 193 deletions(-) diff --git a/NEWS b/NEWS index 419df61..47db860 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,11 @@ +API changes to WRBUF. wrbuf_free removed; replaced by wrbuf_destroy. And +wrbuf_puts no longer appends '\0'. Use wrbuf_cstr to get C-string out. + +Deprecated functions for yaz_marc-removed. + +Changed prototype of yaz_marc_decode_buf: const char for result and size_t +for rsize. + Branch split: YAZ_2_1_55_branch --- 2.1.54 2007/03/16 diff --git a/client/client.c b/client/client.c index 665773b..5369d52 100644 --- a/client/client.c +++ b/client/client.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: client.c,v 1.328 2007-03-14 11:46:37 adam Exp $ + * $Id: client.c,v 1.329 2007-03-19 14:40:06 adam Exp $ */ /** \file client.c * \brief yaz-client program @@ -938,8 +938,8 @@ static void display_record(Z_External *r) #endif ) { - char *result; - int rlen; + const char *result; + size_t rlen; yaz_iconv_t cd = 0; yaz_marc_t mt = yaz_marc_create(); const char *from = 0; @@ -972,7 +972,7 @@ static void display_record(Z_External *r) } } - if (yaz_marc_decode_buf(mt, octet_buf,r->u.octet_aligned->len, + if (yaz_marc_decode_buf(mt, octet_buf, r->u.octet_aligned->len, &result, &rlen)> 0) { fwrite (result, rlen, 1, stdout); @@ -1018,7 +1018,7 @@ static void display_record(Z_External *r) w = wrbuf_alloc(); yaz_display_grs1(w, r->u.grs1, 0); puts (wrbuf_buf(w)); - wrbuf_free(w, 1); + wrbuf_destroy(w); } else if (ent && ent->value == VAL_OPAC) { @@ -1302,7 +1302,7 @@ static char *encode_SRW_term(ODR o, const char *q) cd = yaz_iconv_open("UTF-8", in_charset); if (!cd) { - wrbuf_free(w, 1); + wrbuf_destroy(w); return odr_strdup(o, q); } wrbuf_iconv_write(w, cd, q, strlen(q)); @@ -1314,7 +1314,7 @@ static char *encode_SRW_term(ODR o, const char *q) else res = odr_strdup(o, q); yaz_iconv_close(cd); - wrbuf_free(w, 1); + wrbuf_destroy(w); return res; } diff --git a/include/yaz/marcdisp.h b/include/yaz/marcdisp.h index 4cabfab..834e37f 100644 --- a/include/yaz/marcdisp.h +++ b/include/yaz/marcdisp.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: marcdisp.h,v 1.27 2007-01-24 15:13:20 adam Exp $ */ +/* $Id: marcdisp.h,v 1.28 2007-03-19 14:40:06 adam Exp $ */ /** * \file marcdisp.h @@ -91,7 +91,7 @@ YAZ_EXPORT void yaz_marc_debug(yaz_marc_t mt, int level); Returns -1 on error, or size of input record (>0) if OK */ YAZ_EXPORT int yaz_marc_decode_buf(yaz_marc_t mt, const char *buf, int bsize, - char **result, int *rsize); + const char **result, size_t *rsize); /** \brief decodes ISO2709/MARC buffer and stores result in WRBUF \param mt handle @@ -106,20 +106,6 @@ YAZ_EXPORT int yaz_marc_decode_buf(yaz_marc_t mt, const char *buf, int bsize, YAZ_EXPORT int yaz_marc_decode_wrbuf(yaz_marc_t mt, const char *buf, int bsize, WRBUF wrbuf); -/** \brief depricated */ -YAZ_EXPORT int marc_display(const char *buf, FILE *outf); -/** \brief depricated */ -YAZ_EXPORT int marc_display_ex(const char *buf, FILE *outf, int debug); -/** \brief depricated */ -YAZ_EXPORT int marc_display_exl(const char *buf, FILE *outf, int debug, - int length); -/** \brief depricated */ -YAZ_EXPORT int marc_display_wrbuf(const char *buf, WRBUF wr, int debug, - int bsize); -/** \brief depricated */ -YAZ_EXPORT int yaz_marc_decode(const char *buf, WRBUF wr, - int debug, int bsize, int xml); - YAZ_EXPORT void yaz_marc_subfield_str(yaz_marc_t mt, const char *s); YAZ_EXPORT void yaz_marc_endline_str(yaz_marc_t mt, const char *s); diff --git a/include/yaz/wrbuf.h b/include/yaz/wrbuf.h index 2007567..e3c5de3 100644 --- a/include/yaz/wrbuf.h +++ b/include/yaz/wrbuf.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: wrbuf.h,v 1.24 2007-03-18 12:59:56 adam Exp $ */ +/* $Id: wrbuf.h,v 1.25 2007-03-19 14:40:06 adam Exp $ */ /** * \file wrbuf.h @@ -43,16 +43,13 @@ YAZ_BEGIN_CDECL typedef struct wrbuf { char *buf; - int pos; - int size; + size_t pos; + size_t size; } wrbuf, *WRBUF; /** \brief allocate / construct WRBUF */ YAZ_EXPORT WRBUF wrbuf_alloc(void); -/** \brief free WRBUF and possibly its buffer */ -YAZ_EXPORT void wrbuf_free(WRBUF b, int free_buf); - /** \brief destroy WRBUF and its buffer */ YAZ_EXPORT void wrbuf_destroy(WRBUF b); diff --git a/src/cclptree.c b/src/cclptree.c index bb8196f..bcdfe71 100644 --- a/src/cclptree.c +++ b/src/cclptree.c @@ -53,7 +53,7 @@ /* CCL print rpn tree - infix notation * Europagate, 1995 * - * $Id: cclptree.c,v 1.6 2005-06-25 15:46:03 adam Exp $ + * $Id: cclptree.c,v 1.7 2007-03-19 14:40:07 adam Exp $ * * Old Europagate Log: * @@ -271,6 +271,7 @@ void ccl_pquery (WRBUF w, struct ccl_rpn_node *p) wrbuf_puts (w, " "); break; } + wrbuf_cstr(w); } /* * Local variables: diff --git a/src/marcdisp.c b/src/marcdisp.c index 6eeccb3..6544559 100644 --- a/src/marcdisp.c +++ b/src/marcdisp.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: marcdisp.c,v 1.47 2007-02-23 10:15:01 adam Exp $ + * $Id: marcdisp.c,v 1.48 2007-03-19 14:40:07 adam Exp $ */ /** @@ -116,7 +116,7 @@ void yaz_marc_destroy(yaz_marc_t mt) if (!mt) return ; nmem_destroy(mt->nmem); - wrbuf_free(mt->m_wr, 1); + wrbuf_destroy(mt->m_wr); xfree(mt->leader_spec); xfree(mt); } @@ -890,9 +890,9 @@ int yaz_marc_write_iso2709(yaz_marc_t mt, WRBUF wr) wrbuf_write(wr, wrbuf_buf(wr_head), 24); wrbuf_write(wr, wrbuf_buf(wr_dir), wrbuf_len(wr_dir)); - wrbuf_free(wr_head, 1); - wrbuf_free(wr_dir, 1); - wrbuf_free(wr_data_tmp, 1); + wrbuf_destroy(wr_head); + wrbuf_destroy(wr_dir); + wrbuf_destroy(wr_data_tmp); for (n = mt->nodes; n; n = n->next) { @@ -939,14 +939,14 @@ int yaz_marc_decode_wrbuf(yaz_marc_t mt, const char *buf, int bsize, WRBUF wr) } int yaz_marc_decode_buf (yaz_marc_t mt, const char *buf, int bsize, - char **result, int *rsize) + const char **result, size_t *rsize) { int r; wrbuf_rewind(mt->m_wr); r = yaz_marc_decode_wrbuf(mt, buf, bsize, mt->m_wr); if (result) - *result = wrbuf_buf(mt->m_wr); + *result = wrbuf_cstr(mt->m_wr); if (rsize) *rsize = wrbuf_len(mt->m_wr); return r; @@ -982,53 +982,6 @@ void yaz_marc_modify_leader(yaz_marc_t mt, size_t off, const char *str) } } -/* deprecated */ -int yaz_marc_decode(const char *buf, WRBUF wr, int debug, int bsize, int xml) -{ - yaz_marc_t mt = yaz_marc_create(); - int r; - - mt->debug = debug; - mt->xml = xml; - r = yaz_marc_decode_wrbuf(mt, buf, bsize, wr); - yaz_marc_destroy(mt); - return r; -} - -/* deprecated */ -int marc_display_wrbuf (const char *buf, WRBUF wr, int debug, int bsize) -{ - return yaz_marc_decode(buf, wr, debug, bsize, 0); -} - -/* deprecated */ -int marc_display_exl (const char *buf, FILE *outf, int debug, int bsize) -{ - yaz_marc_t mt = yaz_marc_create(); - int r; - - mt->debug = debug; - r = yaz_marc_decode_wrbuf (mt, buf, bsize, mt->m_wr); - if (!outf) - outf = stdout; - if (r > 0) - fwrite (wrbuf_buf(mt->m_wr), 1, wrbuf_len(mt->m_wr), outf); - yaz_marc_destroy(mt); - return r; -} - -/* deprecated */ -int marc_display_ex (const char *buf, FILE *outf, int debug) -{ - return marc_display_exl (buf, outf, debug, -1); -} - -/* deprecated */ -int marc_display (const char *buf, FILE *outf) -{ - return marc_display_ex (buf, outf, 0); -} - int yaz_marc_leader_spec(yaz_marc_t mt, const char *leader_spec) { xfree(mt->leader_spec); diff --git a/src/querytowrbuf.c b/src/querytowrbuf.c index 2381010..42192b1 100644 --- a/src/querytowrbuf.c +++ b/src/querytowrbuf.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * All rights reserved. * - * $Id: querytowrbuf.c,v 1.6 2007-01-03 08:42:15 adam Exp $ + * $Id: querytowrbuf.c,v 1.7 2007-03-19 14:40:07 adam Exp $ */ /** \file querytowrbuf.c @@ -232,12 +232,14 @@ void yaz_scan_to_wrbuf(WRBUF b, const Z_AttributesPlusTerm *zapt, void wrbuf_scan_term(WRBUF b, const Z_AttributesPlusTerm *zapt, oid_value ast) { yaz_apt_to_wrbuf(b, zapt); + wrbuf_cstr(b); } /* obsolete */ void wrbuf_put_zquery(WRBUF b, const Z_Query *q) { yaz_query_to_wrbuf(b, q); + wrbuf_cstr(b); } diff --git a/src/record_conv.c b/src/record_conv.c index 860a317..27381fa 100644 --- a/src/record_conv.c +++ b/src/record_conv.c @@ -2,7 +2,7 @@ * Copyright (C) 2005-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: record_conv.c,v 1.14 2007-01-03 08:42:15 adam Exp $ + * $Id: record_conv.c,v 1.15 2007-03-19 14:40:07 adam Exp $ */ /** * \file record_conv.c @@ -126,7 +126,7 @@ void yaz_record_conv_destroy(yaz_record_conv_t p) { yaz_record_conv_reset(p); nmem_destroy(p->nmem); - wrbuf_free(p->wr_error, 1); + wrbuf_destroy(p->wr_error); xfree(p->path); xfree(p); } @@ -484,7 +484,7 @@ int yaz_record_conv_record(yaz_record_conv_t p, const char *yaz_record_conv_get_error(yaz_record_conv_t p) { - return wrbuf_buf(p->wr_error); + return wrbuf_cstr(p->wr_error); } void yaz_record_conv_set_path(yaz_record_conv_t p, const char *path) diff --git a/src/retrieval.c b/src/retrieval.c index 6b64b92..e041a2f 100644 --- a/src/retrieval.c +++ b/src/retrieval.c @@ -2,7 +2,7 @@ * Copyright (C) 2005-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: retrieval.c,v 1.16 2007-02-04 02:24:56 quinn Exp $ + * $Id: retrieval.c,v 1.17 2007-03-19 14:40:07 adam Exp $ */ /** * \file retrieval.c @@ -88,7 +88,7 @@ void yaz_retrieval_destroy(yaz_retrieval_t p) { yaz_retrieval_reset(p); odr_destroy(p->odr); - wrbuf_free(p->wr_error, 1); + wrbuf_destroy(p->wr_error); xfree(p->path); xfree(p); } @@ -351,7 +351,7 @@ int yaz_retrieval_request(yaz_retrieval_t p, const char *yaz_retrieval_get_error(yaz_retrieval_t p) { - return wrbuf_buf(p->wr_error); + return wrbuf_cstr(p->wr_error); } void yaz_retrieval_set_path(yaz_retrieval_t p, const char *path) diff --git a/src/seshigh.c b/src/seshigh.c index 0e3186b..68ff2fa 100644 --- a/src/seshigh.c +++ b/src/seshigh.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: seshigh.c,v 1.111 2007-03-13 09:12:09 adam Exp $ + * $Id: seshigh.c,v 1.112 2007-03-19 14:40:07 adam Exp $ */ /** * \file seshigh.c @@ -663,7 +663,7 @@ static int retrieve_fetch(association *assoc, bend_fetch_rr *rr) rr->record = odr_malloc(rr->stream, rr->len); memcpy(rr->record, wrbuf_buf(output_record), rr->len); } - wrbuf_free(output_record, 1); + wrbuf_destroy(output_record); } if (match_syntax) { @@ -1156,8 +1156,8 @@ static void srw_bend_search(association *assoc, request *req, srw_res->resultSetId : "-"), (srw_req->startRecord ? *srw_req->startRecord : 1), srw_res->num_records); - yaz_log(log_request, "%s %s: %s", wrbuf_buf(wr), querytype, querystr); - wrbuf_free(wr, 1); + yaz_log(log_request, "%s %s: %s", wrbuf_cstr(wr), querytype, querystr); + wrbuf_destroy(wr); } } @@ -1434,8 +1434,8 @@ static void srw_bend_scan(association *assoc, request *req, *srw_req->maximumTerms : 1)); /* there is no step size in SRU/W ??? */ wrbuf_printf(wr, "%s: %s ", querytype, querystr); - yaz_log(log_request, "%s ", wrbuf_buf(wr) ); - wrbuf_free(wr, 1); + yaz_log(log_request, "%s ", wrbuf_cstr(wr) ); + wrbuf_destroy(wr); } } @@ -2364,7 +2364,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) assoc->init->implementation_name, odr_prepend(assoc->encode, "GFS", resp->implementationName)); - version = odr_strdup(assoc->encode, "$Revision: 1.111 $"); + version = odr_strdup(assoc->encode, "$Revision: 1.112 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; resp->implementationVersion = odr_prepend(assoc->encode, @@ -2427,8 +2427,8 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) (req->implementationVersion ? req->implementationVersion : "-") ); - yaz_log(log_request, "%s", wrbuf_buf(wr)); - wrbuf_free(wr, 1); + yaz_log(log_request, "%s", wrbuf_cstr(wr)); + wrbuf_destroy(wr); } return apdu; } @@ -2864,8 +2864,8 @@ static Z_APDU *response_searchRequest(association *assoc, request *reqb, req->resultSetName, returnedrecs); yaz_query_to_wrbuf(wr, req->query); - yaz_log(log_request, "Search %s", wrbuf_buf(wr)); - wrbuf_free(wr, 1); + yaz_log(log_request, "Search %s", wrbuf_cstr(wr)); + wrbuf_destroy(wr); } return apdu; } @@ -2969,8 +2969,8 @@ static Z_APDU *process_presentRequest(association *assoc, request *reqb, wrbuf_printf(wr, " %s %d+%d ", req->resultSetId, *req->resultSetStartPoint, *req->numberOfRecordsRequested); - yaz_log(log_request, "%s", wrbuf_buf(wr) ); - wrbuf_free(wr, 1); + yaz_log(log_request, "%s", wrbuf_cstr(wr) ); + wrbuf_destroy(wr); } if (!resp->records) return 0; @@ -3187,8 +3187,8 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd) yaz_scan_to_wrbuf(wr, req->termListAndStartPoint, bsrr->attributeset); - yaz_log(log_request, "%s", wrbuf_buf(wr) ); - wrbuf_free(wr, 1); + yaz_log(log_request, "%s", wrbuf_cstr(wr) ); + wrbuf_destroy(wr); } return apdu; } @@ -3264,8 +3264,8 @@ static Z_APDU *process_sortRequest(association *assoc, request *reqb, } wrbuf_printf(wr, ")->%s ",req->sortedResultSetName); - yaz_log(log_request, "%s", wrbuf_buf(wr) ); - wrbuf_free(wr, 1); + yaz_log(log_request, "%s", wrbuf_cstr(wr) ); + wrbuf_destroy(wr); } return apdu; } @@ -3348,8 +3348,8 @@ static Z_APDU *process_deleteRequest(association *assoc, request *reqb, wrbuf_printf(wr, "OK -"); for (i = 0; inum_resultSetList; i++) wrbuf_printf(wr, " %s ", req->resultSetList[i]); - yaz_log(log_request, "%s", wrbuf_buf(wr) ); - wrbuf_free(wr, 1); + yaz_log(log_request, "%s", wrbuf_cstr(wr) ); + wrbuf_destroy(wr); } return apdu; } @@ -3535,8 +3535,8 @@ static Z_APDU *process_ESRequest(association *assoc, request *reqb, int *fd) { WRBUF wr = wrbuf_alloc(); wrbuf_diags(wr, resp->num_diagnostics, resp->diagnostics); - yaz_log(log_request, "EsRequest %s", wrbuf_buf(wr) ); - wrbuf_free(wr, 1); + yaz_log(log_request, "EsRequest %s", wrbuf_cstr(wr) ); + wrbuf_destroy(wr); } } diff --git a/src/wrbuf.c b/src/wrbuf.c index 973f080..ef2be4c 100644 --- a/src/wrbuf.c +++ b/src/wrbuf.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: wrbuf.c,v 1.17 2007-03-18 12:59:56 adam Exp $ + * $Id: wrbuf.c,v 1.18 2007-03-19 14:40:07 adam Exp $ */ /** @@ -35,16 +35,10 @@ WRBUF wrbuf_alloc(void) return n; } -void wrbuf_free(WRBUF b, int free_buf) -{ - if (free_buf && b->buf) - xfree(b->buf); - xfree(b); -} - void wrbuf_destroy(WRBUF b) { - wrbuf_free(b, 1); + xfree(b->buf); + xfree(b); } void wrbuf_rewind(WRBUF b) @@ -82,23 +76,21 @@ int wrbuf_write(WRBUF b, const char *buf, int size) int wrbuf_puts(WRBUF b, const char *buf) { - wrbuf_write(b, buf, strlen(buf)+1); /* '\0'-terminate as well */ - (b->pos)--; /* don't include '\0' in count */ + wrbuf_write(b, buf, strlen(buf)); return 0; } int wrbuf_puts_replace_char(WRBUF b, const char *buf, const char from, const char to) { - while(*buf){ + while(*buf) + { if (*buf == from) wrbuf_putc(b, to); else wrbuf_putc(b, *buf); buf++; } - wrbuf_putc(b, 0); - (b->pos)--; /* don't include '\0' in count */ return 0; } @@ -107,7 +99,6 @@ void wrbuf_chop_right(WRBUF b) while (b->pos && b->buf[b->pos-1] == ' ') { (b->pos)--; - b->buf[b->pos] = '\0'; } } @@ -149,8 +140,6 @@ int wrbuf_xmlputs_n(WRBUF b, const char *cp, int size) } cp++; } - wrbuf_putc(b, 0); - (b->pos)--; return 0; } @@ -226,8 +215,8 @@ int wrbuf_iconv_write_cdata(WRBUF b, yaz_iconv_t cd, const char *buf, int size) const char *wrbuf_cstr(WRBUF b) { - wrbuf_write(b, "", 1); /* '\0'-terminate as well */ - (b->pos)--; /* don't include '\0' in count */ + wrbuf_putc(b, '\0'); /* add '\0' */ + (b->pos)--; /* don't include '\0' in count */ return b->buf; } diff --git a/src/yaz-ccl.c b/src/yaz-ccl.c index 3ab49dc..8fe39c8 100644 --- a/src/yaz-ccl.c +++ b/src/yaz-ccl.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: yaz-ccl.c,v 1.5 2007-01-03 08:42:15 adam Exp $ + * $Id: yaz-ccl.c,v 1.6 2007-03-19 14:40:07 adam Exp $ */ /** * \file yaz-ccl.c @@ -25,9 +25,9 @@ Z_RPNQuery *ccl_rpn_query (ODR o, struct ccl_rpn_node *p) ccl_pquery(wr, p); - q = yaz_pqf_parse(parser, o, wrbuf_buf(wr)); + q = yaz_pqf_parse(parser, o, wrbuf_cstr(wr)); - wrbuf_free(wr, 1); + wrbuf_destroy(wr); yaz_pqf_destroy(parser); return q; } @@ -41,9 +41,9 @@ Z_AttributesPlusTerm *ccl_scan_query (ODR o, struct ccl_rpn_node *p) ccl_pquery(wr, p); - q = yaz_pqf_scan(parser, o, &setp, wrbuf_buf(wr)); + q = yaz_pqf_scan(parser, o, &setp, wrbuf_cstr(wr)); - wrbuf_free(wr, 1); + wrbuf_destroy(wr); yaz_pqf_destroy(parser); return q; } diff --git a/src/zoom-c.c b/src/zoom-c.c index 1f0cd79..9496de6 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: zoom-c.c,v 1.116 2007-03-12 08:27:44 adam Exp $ + * $Id: zoom-c.c,v 1.117 2007-03-19 14:40:07 adam Exp $ */ /** * \file zoom-c.c @@ -678,8 +678,8 @@ ZOOM_API(int) WRBUF wr = wrbuf_alloc(); ccl_pquery(wr, rpn); ccl_rpn_delete(rpn); - ret = ZOOM_query_prefix(s, wrbuf_buf(wr)); - wrbuf_free(wr, 1); + ret = ZOOM_query_prefix(s, wrbuf_cstr(wr)); + wrbuf_destroy(wr); } ccl_qual_rm(&bibset); return ret; @@ -927,11 +927,11 @@ ZOOM_API(void) for (rc = r->record_hash[i]; rc; rc = rc->next) { if (rc->rec.wrbuf_marc) - wrbuf_free(rc->rec.wrbuf_marc, 1); + wrbuf_destroy(rc->rec.wrbuf_marc); if (rc->rec.wrbuf_iconv) - wrbuf_free(rc->rec.wrbuf_iconv, 1); + wrbuf_destroy(rc->rec.wrbuf_iconv); if (rc->rec.wrbuf_opac) - wrbuf_free(rc->rec.wrbuf_opac, 1); + wrbuf_destroy(rc->rec.wrbuf_opac); } r->record_hash[i] = 0; } @@ -1300,7 +1300,7 @@ static zoom_ret ZOOM_connection_send_init(ZOOM_connection c) odr_prepend(c->odr_out, "ZOOM-C", ireq->implementationName)); - version = odr_strdup(c->odr_out, "$Revision: 1.116 $"); + version = odr_strdup(c->odr_out, "$Revision: 1.117 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; ireq->implementationVersion = @@ -1730,11 +1730,11 @@ ZOOM_API(void) if (!rec) return; if (rec->wrbuf_marc) - wrbuf_free(rec->wrbuf_marc, 1); + wrbuf_destroy(rec->wrbuf_marc); if (rec->wrbuf_iconv) - wrbuf_free(rec->wrbuf_iconv, 1); + wrbuf_destroy(rec->wrbuf_iconv); if (rec->wrbuf_opac) - wrbuf_free(rec->wrbuf_opac, 1); + wrbuf_destroy(rec->wrbuf_opac); odr_destroy(rec->odr); xfree(rec); } @@ -1787,7 +1787,7 @@ static const char *marc_iconv_return(ZOOM_record rec, int marc_type, yaz_iconv_close(cd); if (len) *len = wrbuf_len(rec->wrbuf_marc); - return wrbuf_buf(rec->wrbuf_marc); + return wrbuf_cstr(rec->wrbuf_marc); } yaz_marc_destroy(mt); if (cd) @@ -1850,8 +1850,7 @@ static const char *record_iconv_return(ZOOM_record rec, int *len, } wrbuf_write(rec->wrbuf_iconv, outbuf, outp - outbuf); } - wrbuf_puts(rec->wrbuf_iconv, ""); - buf = wrbuf_buf(rec->wrbuf_iconv); + buf = wrbuf_cstr(rec->wrbuf_iconv); sz = wrbuf_len(rec->wrbuf_iconv); yaz_iconv_close(cd); } diff --git a/test/tst_record_conv.c b/test/tst_record_conv.c index c08b937..6683b84 100644 --- a/test/tst_record_conv.c +++ b/test/tst_record_conv.c @@ -2,7 +2,7 @@ * Copyright (C) 2005-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: tst_record_conv.c,v 1.13 2007-01-03 08:42:16 adam Exp $ + * $Id: tst_record_conv.c,v 1.14 2007-03-19 14:40:07 adam Exp $ * */ #include @@ -78,12 +78,12 @@ int conv_configure_test(const char *xmlstring, const char *expect_error, if (!p) { - if (expect_error && !strcmp(wrbuf_buf(w), expect_error)) + if (expect_error && !strcmp(wrbuf_cstr(w), expect_error)) ret = 1; else { ret = 0; - printf("%.*s\n", wrbuf_len(w), wrbuf_buf(w)); + printf("%s\n", wrbuf_cstr(w)); } } else @@ -100,7 +100,7 @@ int conv_configure_test(const char *xmlstring, const char *expect_error, if (p) yaz_record_conv_destroy(p); - wrbuf_free(w, 1); + wrbuf_destroy(w); return ret; } @@ -188,26 +188,22 @@ static int conv_convert_test(yaz_record_conv_t p, ret = 0; printf("output_record expect-len=%d got-len=%d\n", expect_len, wrbuf_len(output_record)); - printf("got-output_record = %.*s\n", - wrbuf_len(output_record), wrbuf_buf(output_record)); - printf("output_expect_record = %s\n", - output_expect_record); + printf("got-output_record = %s\n", wrbuf_cstr(output_record)); + printf("output_expect_record = %s\n", output_expect_record); } else if (memcmp(output_expect_record, wrbuf_buf(output_record), strlen(output_expect_record))) { ret = 0; - printf("got-output_record = %.*s\n", - wrbuf_len(output_record), wrbuf_buf(output_record)); - printf("output_expect_record = %s\n", - output_expect_record); + printf("got-output_record = %s\n", wrbuf_cstr(output_record)); + printf("output_expect_record = %s\n", output_expect_record); } else { ret = 1; } } - wrbuf_free(output_record, 1); + wrbuf_destroy(output_record); } return ret; } diff --git a/test/tst_retrieval.c b/test/tst_retrieval.c index f49c2c2..8ed48ea 100644 --- a/test/tst_retrieval.c +++ b/test/tst_retrieval.c @@ -2,7 +2,7 @@ * Copyright (C) 2005-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: tst_retrieval.c,v 1.9 2007-01-03 08:42:16 adam Exp $ + * $Id: tst_retrieval.c,v 1.10 2007-03-19 14:40:07 adam Exp $ * */ #include @@ -76,12 +76,12 @@ int conv_configure_test(const char *xmlstring, const char *expect_error, if (!p) { - if (expect_error && !strcmp(wrbuf_buf(w), expect_error)) + if (expect_error && !strcmp(wrbuf_cstr(w), expect_error)) ret = 1; else { ret = 0; - printf("%.*s\n", wrbuf_len(w), wrbuf_buf(w)); + printf("%s\n", wrbuf_cstr(w)); } } else @@ -100,7 +100,7 @@ int conv_configure_test(const char *xmlstring, const char *expect_error, ret = 1; } } - wrbuf_free(w, 1); + wrbuf_destroy(w); return ret; } diff --git a/test/tstccl.c b/test/tstccl.c index 2a95345..6cb694f 100644 --- a/test/tstccl.c +++ b/test/tstccl.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: tstccl.c,v 1.13 2007-01-08 10:48:07 adam Exp $ + * $Id: tstccl.c,v 1.14 2007-03-19 14:40:07 adam Exp $ */ /* CCL test */ @@ -41,7 +41,7 @@ static int tst_ccl_query(CCL_bibset bibset, else ret = 0; ccl_rpn_delete(rpn); - wrbuf_free(wrbuf, 1); + wrbuf_destroy(wrbuf); } else { diff --git a/test/tsticonv.c b/test/tsticonv.c index 7fac3c5..37d3bbf 100644 --- a/test/tsticonv.c +++ b/test/tsticonv.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: tsticonv.c,v 1.27 2007-03-17 00:10:41 adam Exp $ + * $Id: tsticonv.c,v 1.28 2007-03-19 14:40:07 adam Exp $ */ #if HAVE_CONFIG_H @@ -110,7 +110,7 @@ static int tst_convert(yaz_iconv_t cd, const char *buf, const char *cmpbuf) ret = 1; else yaz_log(YLOG_LOG, "GOT (%.*s)", wrbuf_len(b), wrbuf_buf(b)); - wrbuf_free(b, 1); + wrbuf_destroy(b); return ret; } diff --git a/test/tstpquery.c b/test/tstpquery.c index f099862..82fbd30 100644 --- a/test/tstpquery.c +++ b/test/tstpquery.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: tstpquery.c,v 1.4 2007-01-03 08:42:16 adam Exp $ + * $Id: tstpquery.c,v 1.5 2007-03-19 14:40:07 adam Exp $ */ #include @@ -45,9 +45,9 @@ int expect_pqf(const char *pqf, const char *expect_pqf, int expect_error) { yaz_rpnquery_to_wrbuf(wrbuf, rpn); - if (!strcmp(wrbuf_buf(wrbuf), expect_pqf)) + if (!strcmp(wrbuf_cstr(wrbuf), expect_pqf)) res = 1; - wrbuf_free(wrbuf, 1); + wrbuf_destroy(wrbuf); } } yaz_pqf_destroy(parser); diff --git a/test/tstwrbuf.c b/test/tstwrbuf.c index e1ed5f6..52e2fbf 100644 --- a/test/tstwrbuf.c +++ b/test/tstwrbuf.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: tstwrbuf.c,v 1.6 2007-01-03 08:42:16 adam Exp $ + * $Id: tstwrbuf.c,v 1.7 2007-03-19 14:40:07 adam Exp $ */ #include @@ -18,7 +18,7 @@ static void tstwrbuf(void) YAZ_CHECK(wr); - wrbuf_free(wr, 1); + wrbuf_destroy(wr); wr = wrbuf_alloc(); @@ -50,7 +50,7 @@ static void tstwrbuf(void) } wrbuf_rewind(wr); } - wrbuf_free(wr, 1); + wrbuf_destroy(wr); } int main (int argc, char **argv) diff --git a/test/tstxmlquery.c b/test/tstxmlquery.c index bb3e334..e0c7999 100644 --- a/test/tstxmlquery.c +++ b/test/tstxmlquery.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: tstxmlquery.c,v 1.14 2007-01-03 08:42:16 adam Exp $ + * $Id: tstxmlquery.c,v 1.15 2007-03-19 14:40:07 adam Exp $ */ #include @@ -78,14 +78,14 @@ enum pqf2xml_status pqf2xml_text(const char *pqf, const char *expect_xml, { WRBUF w = wrbuf_alloc(); yaz_query_to_wrbuf(w, query2); - if (!expect_pqf || strcmp(expect_pqf, wrbuf_buf(w)) == 0) + if (!expect_pqf || strcmp(expect_pqf, wrbuf_cstr(w)) == 0) status = XML_MATCH; else { status = XML_NO_MATCH; printf("Result: %s\n", wrbuf_buf(w)); } - wrbuf_free(w, 1); + wrbuf_destroy(w); } odr_destroy(odr2); } diff --git a/util/marcdump.c b/util/marcdump.c index 4ecdc86..967fdd7 100644 --- a/util/marcdump.c +++ b/util/marcdump.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: marcdump.c,v 1.50 2007-03-17 09:14:00 adam Exp $ + * $Id: marcdump.c,v 1.51 2007-03-19 14:40:08 adam Exp $ */ #define _FILE_OFFSET_BITS 64 @@ -90,8 +90,8 @@ static void marcdump_read_line(yaz_marc_t mt, const char *fname) { WRBUF wrbuf = wrbuf_alloc(); yaz_marc_write_mode(mt, wrbuf); - fputs(wrbuf_buf(wrbuf), stdout); - wrbuf_free(wrbuf, 1); + fputs(wrbuf_cstr(wrbuf), stdout); + wrbuf_destroy(wrbuf); } fclose(inf); } @@ -116,9 +116,9 @@ static void marcdump_read_xml(yaz_marc_t mt, const char *fname) { yaz_marc_write_mode(mt, wrbuf); - fputs(wrbuf_buf(wrbuf), stdout); + fputs(wrbuf_cstr(wrbuf), stdout); } - wrbuf_free(wrbuf, 1); + wrbuf_destroy(wrbuf); } xmlFreeDoc(doc); } @@ -181,10 +181,10 @@ static void dump(const char *fname, const char *from, const char *to, fprintf (cfile, "char *marc_records[] = {\n"); for(;; marc_no++) { - char *result = 0; + const char *result = 0; size_t len; size_t rlen; - int len_result; + size_t len_result; size_t r; char buf[100001]; @@ -274,7 +274,7 @@ static void dump(const char *fname, const char *from, const char *to, fclose(sf); } } - len_result = (int) rlen; + len_result = rlen; r = yaz_marc_decode_buf(mt, buf, -1, &result, &len_result); if (r > 0 && result) { diff --git a/util/yaz-xmlquery.c b/util/yaz-xmlquery.c index 39000fc..9fcab5a 100644 --- a/util/yaz-xmlquery.c +++ b/util/yaz-xmlquery.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: yaz-xmlquery.c,v 1.6 2007-01-03 08:42:16 adam Exp $ + * $Id: yaz-xmlquery.c,v 1.7 2007-03-19 14:40:08 adam Exp $ */ #include @@ -118,7 +118,7 @@ void xmlquerytopqf(const char *xmlstr) WRBUF w = wrbuf_alloc(); yaz_query_to_wrbuf(w, query); printf("%s\n", wrbuf_buf(w)); - wrbuf_free(w, 1); + wrbuf_destroy(w); } odr_destroy(odr); xmlFreeDoc(doc); diff --git a/ztest/read-marc.c b/ztest/read-marc.c index 102e8ff..82abe54 100644 --- a/ztest/read-marc.c +++ b/ztest/read-marc.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: read-marc.c,v 1.8 2007-01-03 08:42:18 adam Exp $ + * $Id: read-marc.c,v 1.9 2007-03-19 14:40:08 adam Exp $ */ /* @@ -1602,8 +1602,8 @@ char *dummy_marc_record (int num, ODR odr) char *dummy_xml_record (int num, ODR odr) { yaz_marc_t mt = yaz_marc_create(); - char *result; - int rlen; + const char *result; + size_t rlen; char *rec = dummy_marc_record (num, odr); int len; @@ -1613,7 +1613,11 @@ char *dummy_xml_record (int num, ODR odr) yaz_marc_xml(mt, YAZ_MARC_MARCXML); len = yaz_marc_decode_buf (mt, rec, -1, &result, &rlen); if (len > 1) - rec = (char *) odr_strdup(odr, result); + { + rec = odr_malloc(odr, rlen+1); + memcpy(rec, result, rlen); + rec[rlen] = '\0'; + } yaz_marc_destroy(mt); return rec; } -- 1.7.10.4