From 3e4a78274a6cb7a99f3e90967ea30c830ffbf8c3 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 19 Mar 2007 21:50:39 +0000 Subject: [PATCH] WRBUF updates. --- data1/d1_handle.c | 4 ++-- data1/d1_read.c | 22 +++++++--------------- index/alvis.c | 6 +++--- index/marcread.c | 16 ++++++++-------- index/orddict.c | 18 +++++++++--------- index/regxread.c | 4 ++-- index/retrieve.c | 14 +++++++------- index/rpnscan.c | 16 ++++++++-------- index/rpnsearch.c | 19 +++++++++---------- index/sgmlread.c | 8 ++++---- index/zebraapi.c | 8 ++++---- index/zebrash.c | 14 +++++++------- isamb/benchindex1.c | 4 ++-- util/zebramap.c | 4 ++-- 14 files changed, 74 insertions(+), 83 deletions(-) diff --git a/data1/d1_handle.c b/data1/d1_handle.c index 68f4e02..9955132 100644 --- a/data1/d1_handle.c +++ b/data1/d1_handle.c @@ -1,4 +1,4 @@ -/* $Id: d1_handle.c,v 1.14 2007-01-15 15:10:14 adam Exp $ +/* $Id: d1_handle.c,v 1.15 2007-03-19 21:50:39 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -89,7 +89,7 @@ void data1_destroy (data1_handle dh) */ data1_absyn_destroy(dh); - wrbuf_free (dh->wrbuf, 1); + wrbuf_destroy(dh->wrbuf); if (dh->tab_path) xfree (dh->tab_path); if (dh->tab_root) diff --git a/data1/d1_read.c b/data1/d1_read.c index 56fdffd..68ee97f 100644 --- a/data1/d1_read.c +++ b/data1/d1_read.c @@ -1,4 +1,4 @@ -/* $Id: d1_read.c,v 1.22 2007-01-15 15:10:14 adam Exp $ +/* $Id: d1_read.c,v 1.23 2007-03-19 21:50:39 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -592,7 +592,6 @@ data1_xattr *data1_read_xattr (data1_handle dh, NMEM m, for (;;) { data1_xattr *p; - int len; while (*amp || (c && d1_isspace(c))) c = ampr (get_byte, fh, amp); if (*amp == 0 && (c == 0 || c == '>' || c == '/')) @@ -609,10 +608,7 @@ data1_xattr *data1_read_xattr (data1_handle dh, NMEM m, wrbuf_putc (wrbuf, c); c = ampr (get_byte, fh, amp); } - wrbuf_putc (wrbuf, '\0'); - len = wrbuf_len(wrbuf); - p->name = (char*) nmem_malloc (m, len); - strcpy (p->name, wrbuf_buf(wrbuf)); + p->name = nmem_strdup (m, wrbuf_cstr(wrbuf)); if (c == '=') { c = ampr (get_byte, fh, amp); @@ -649,10 +645,7 @@ data1_xattr *data1_read_xattr (data1_handle dh, NMEM m, c = ampr (get_byte, fh, amp); } } - wrbuf_putc (wrbuf, '\0'); - len = wrbuf_len(wrbuf); - p->value = (char*) nmem_malloc (m, len); - strcpy (p->value, wrbuf_buf(wrbuf)); + p->value = nmem_strdup(m, wrbuf_cstr(wrbuf)); } } *ch = c; @@ -965,7 +958,7 @@ data1_node *data1_read_node (data1_handle dh, const char **buf, NMEM m) data1_node *node; node = data1_read_nodex(dh, m, getc_mem, (void *) (buf), wrbuf); - wrbuf_free (wrbuf, 1); + wrbuf_destroy(wrbuf); return node; } @@ -1075,8 +1068,7 @@ static void data1_iconv_s (data1_handle dh, NMEM m, data1_node *n, conv_item(m, t, wrbuf, p->value, strlen(p->value)) == 0) { - wrbuf_puts (wrbuf, ""); - p->value = nmem_strdup (m, wrbuf->buf); + p->value = nmem_strdup(m, wrbuf_cstr(wrbuf)); } } } @@ -1124,12 +1116,12 @@ int data1_iconv (data1_handle dh, NMEM m, data1_node *n, yaz_iconv_t t = yaz_iconv_open(tocode, fromcode); if (!t) { - wrbuf_free(wrbuf, 1); + wrbuf_destroy(wrbuf); return -1; } data1_iconv_s(dh, m, n, t, wrbuf, tocode); yaz_iconv_close(t); - wrbuf_free(wrbuf, 1); + wrbuf_destroy(wrbuf); } return 0; } diff --git a/index/alvis.c b/index/alvis.c index c926129..e168da3 100644 --- a/index/alvis.c +++ b/index/alvis.c @@ -1,4 +1,4 @@ -/* $Id: alvis.c,v 1.14 2007-03-07 14:18:35 marc Exp $ +/* $Id: alvis.c,v 1.15 2007-03-19 21:50:39 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -632,10 +632,10 @@ static const char *snippet_doc(struct recRetrieveCtrl *p, int text_mode, else wrbuf_printf(wrbuf, "\n"); - xml_doc_str = odr_strdup(p->odr, wrbuf_buf(wrbuf)); + xml_doc_str = odr_strdup(p->odr, wrbuf_cstr(wrbuf)); zebra_snippets_destroy(res); - wrbuf_free(wrbuf, 1); + wrbuf_destroy(wrbuf); return xml_doc_str; } diff --git a/index/marcread.c b/index/marcread.c index 24f8e46..78c7d82 100644 --- a/index/marcread.c +++ b/index/marcread.c @@ -1,4 +1,4 @@ -/* $Id: marcread.c,v 1.7 2007-03-08 13:18:35 adam Exp $ +/* $Id: marcread.c,v 1.8 2007-03-19 21:50:39 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -772,14 +772,14 @@ static void parse_data1_tree(struct grs_read_info *p, const char *mc_stmnt, field = cat_field(p, pf, buf, field); - pb = wrbuf_buf(buf); + pb = wrbuf_cstr(buf); for (pb = strtok(pb, "\n"); pb; pb = strtok(NULL, "\n")) { - if (!is_empty(pb)) - { - new = data1_mk_tag_n(p->dh, p->mem, mc_stmnt, strlen(mc_stmnt), 0, top); - data1_mk_text_n(p->dh, p->mem, pb, strlen(pb), new); - } + if (!is_empty(pb)) + { + new = data1_mk_tag_n(p->dh, p->mem, mc_stmnt, strlen(mc_stmnt), 0, top); + data1_mk_text_n(p->dh, p->mem, pb, strlen(pb), new); + } } } else @@ -790,7 +790,7 @@ static void parse_data1_tree(struct grs_read_info *p, const char *mc_stmnt, } mc_destroy_field(pf); mc_destroy_context(c); - wrbuf_free(buf, 1); + wrbuf_destroy(buf); } data1_node *grs_read_marcxml(struct grs_read_info *p) diff --git a/index/orddict.c b/index/orddict.c index a711749..853d583 100644 --- a/index/orddict.c +++ b/index/orddict.c @@ -1,4 +1,4 @@ -/* $Id: orddict.c,v 1.5 2007-01-15 15:10:16 adam Exp $ +/* $Id: orddict.c,v 1.6 2007-03-19 21:50:39 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -42,8 +42,8 @@ WRBUF zebra_mk_ord_str(int ord, const char *str) char *dict_lookup_ord(Dict d, int ord, const char *str) { WRBUF w = zebra_mk_ord_str(ord, str); - char *rinfo = dict_lookup(d, wrbuf_buf(w)); - wrbuf_free(w, 1); + char *rinfo = dict_lookup(d, wrbuf_cstr(w)); + wrbuf_destroy(w); return rinfo; } @@ -51,16 +51,16 @@ int dict_insert_ord(Dict d, int ord, const char *p, int userlen, void *userinfo) { WRBUF w = zebra_mk_ord_str(ord, p); - int r = dict_insert(d, wrbuf_buf(w), userlen, userinfo); - wrbuf_free(w, 1); + int r = dict_insert(d, wrbuf_cstr(w), userlen, userinfo); + wrbuf_destroy(w); return r; } int dict_delete_ord(Dict d, int ord, const char *p) { WRBUF w = zebra_mk_ord_str(ord, p); - int r = dict_delete(d, wrbuf_buf(w)); - wrbuf_free(w, 1); + int r = dict_delete(d, wrbuf_cstr(w)); + wrbuf_destroy(w); return r; } @@ -68,8 +68,8 @@ int dict_delete_subtree_ord(Dict d, int ord, void *client, int (*f)(const char *info, void *client)) { WRBUF w = zebra_mk_ord_str(ord, ""); - int r = dict_delete_subtree(d, wrbuf_buf(w), client, f); - wrbuf_free(w, 1); + int r = dict_delete_subtree(d, wrbuf_cstr(w), client, f); + wrbuf_destroy(w); return r; } /* diff --git a/index/regxread.c b/index/regxread.c index 966ce6a..4e75ffa 100644 --- a/index/regxread.c +++ b/index/regxread.c @@ -1,4 +1,4 @@ -/* $Id: regxread.c,v 1.6 2007-01-15 15:10:17 adam Exp $ +/* $Id: regxread.c,v 1.7 2007-03-19 21:50:39 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -646,7 +646,7 @@ int readFileSpec (struct lexSpec *spec) } } fclose (spec_inf); - wrbuf_free(lineBuf, 1); + wrbuf_destroy(lineBuf); for (lc = spec->context; lc; lc = lc->next) { diff --git a/index/retrieve.c b/index/retrieve.c index d2f5398..2627998 100644 --- a/index/retrieve.c +++ b/index/retrieve.c @@ -1,4 +1,4 @@ -/* $Id: retrieve.c,v 1.66 2007-03-06 12:40:18 adam Exp $ +/* $Id: retrieve.c,v 1.67 2007-03-19 21:50:39 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -208,7 +208,7 @@ int zebra_special_sort_fetch(ZebraHandle zh, zint sysno, ODR odr, *rec_lenp = wrbuf_len(wrbuf); *rec_bufp = odr_malloc(odr, *rec_lenp); memcpy(*rec_bufp, wrbuf_buf(wrbuf), *rec_lenp); - wrbuf_free(wrbuf, 1); + wrbuf_destroy(wrbuf); return 0; } } @@ -359,7 +359,7 @@ int zebra_special_index_fetch(ZebraHandle zh, zint sysno, ODR odr, *rec_lenp = wrbuf_len(wrbuf); *rec_bufp = odr_malloc(odr, *rec_lenp); memcpy(*rec_bufp, wrbuf_buf(wrbuf), *rec_lenp); - wrbuf_free(wrbuf, 1); + wrbuf_destroy(wrbuf); } zebra_rec_keys_close(keys); return ret_code; @@ -428,10 +428,10 @@ int zebra_special_fetch(ZebraHandle zh, zint sysno, int score, ODR odr, } *rec_lenp = wrbuf_len(wrbuf); if (*rec_lenp) - *rec_bufp = odr_strdup(odr, wrbuf_buf(wrbuf)); + *rec_bufp = odr_strdup(odr, wrbuf_cstr(wrbuf)); else ret = YAZ_BIB1_NO_SYNTAXES_AVAILABLE_FOR_THIS_REQUEST; - wrbuf_free(wrbuf, 1); + wrbuf_destroy(wrbuf); return ret; } @@ -527,11 +527,11 @@ int zebra_special_fetch(ZebraHandle zh, zint sysno, int score, ODR odr, } *rec_lenp = wrbuf_len(wrbuf); if (*rec_lenp) - *rec_bufp = odr_strdup(odr, wrbuf_buf(wrbuf)); + *rec_bufp = odr_strdup(odr, wrbuf_cstr(wrbuf)); else ret = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS; - wrbuf_free(wrbuf, 1); + wrbuf_destroy(wrbuf); rec_free(&rec); return ret; } diff --git a/index/rpnscan.c b/index/rpnscan.c index 38a9aee..1e54721 100644 --- a/index/rpnscan.c +++ b/index/rpnscan.c @@ -1,4 +1,4 @@ -/* $Id: rpnscan.c,v 1.5 2007-01-15 15:10:17 adam Exp $ +/* $Id: rpnscan.c,v 1.6 2007-03-19 21:50:39 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -150,7 +150,7 @@ static int scan_save_set(ZebraHandle zh, ODR stream, NMEM nmem, RSET rset = 0; for (i = 0; i < ord_no; i++) { - if (ar[i].isam_p && strcmp(wrbuf_buf(ar[i].term), term) == 0) + if (ar[i].isam_p && strcmp(wrbuf_cstr(ar[i].term), term) == 0) { RSET rset_t = rset_trunc( zh, &ar[i].isam_p, 1, @@ -265,7 +265,7 @@ static ZEBRA_RES rpn_scan_ver2(ZebraHandle zh, ODR stream, NMEM nmem, ar[i].pos_to_save = -1; strcpy(termz, ar[i].prefix); - strcat(termz, wrbuf_buf(ar[i].term)); + strcat(termz, wrbuf_cstr(ar[i].term)); dict_scan(zh->reg->dict, termz, &before, &after, ar+i, scan_handle2); } @@ -274,8 +274,8 @@ static ZEBRA_RES rpn_scan_ver2(ZebraHandle zh, ODR stream, NMEM nmem, for (i = 0; i < ord_no; i++) { if (ar[i].isam_p - && (hi == 0 || strcmp(wrbuf_buf(ar[i].term), hi) > 0)) - hi = wrbuf_buf(ar[i].term); + && (hi == 0 || strcmp(wrbuf_cstr(ar[i].term), hi) > 0)) + hi = wrbuf_cstr(ar[i].term); } if (!hi) break; @@ -329,7 +329,7 @@ static ZEBRA_RES rpn_scan_ver2(ZebraHandle zh, ODR stream, NMEM nmem, ar[i].pos_to_save = 1; strcpy(termz, ar[i].prefix); - strcat(termz, wrbuf_buf(ar[i].term)); + strcat(termz, wrbuf_cstr(ar[i].term)); dict_scan(zh->reg->dict, termz, &before, &after, ar+i, scan_handle2); } @@ -338,8 +338,8 @@ static ZEBRA_RES rpn_scan_ver2(ZebraHandle zh, ODR stream, NMEM nmem, for (i = 0; i < ord_no; i++) { if (ar[i].isam_p - && (lo == 0 || strcmp(wrbuf_buf(ar[i].term), lo) < 0)) - lo = wrbuf_buf(ar[i].term); + && (lo == 0 || strcmp(wrbuf_cstr(ar[i].term), lo) < 0)) + lo = wrbuf_cstr(ar[i].term); } if (!lo) break; diff --git a/index/rpnsearch.c b/index/rpnsearch.c index 5ade0ea..aaae58a 100644 --- a/index/rpnsearch.c +++ b/index/rpnsearch.c @@ -1,4 +1,4 @@ -/* $Id: rpnsearch.c,v 1.9 2007-03-06 12:21:04 adam Exp $ +/* $Id: rpnsearch.c,v 1.10 2007-03-19 21:50:39 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -2175,26 +2175,25 @@ ZEBRA_RES rpn_search_xpath(ZebraHandle zh, cp++; } } - wrbuf_puts(wbuf, ""); rset_attr = xpath_trunc( - zh, stream, '0', wrbuf_buf(wbuf), ZEBRA_XPATH_ATTR_NAME, + zh, stream, '0', wrbuf_cstr(wbuf), ZEBRA_XPATH_ATTR_NAME, rset_nmem, kc); - wrbuf_free(wbuf, 1); + wrbuf_destroy(wbuf); } else { if (!first_path) { - wrbuf_free(xpath_rev, 1); + wrbuf_destroy(xpath_rev); continue; } } - yaz_log(log_level_rpn, "xpath_rev (%d) = %.*s", level, - wrbuf_len(xpath_rev), wrbuf_buf(xpath_rev)); + yaz_log(log_level_rpn, "xpath_rev (%d) = %s", level, + wrbuf_cstr(xpath_rev)); if (wrbuf_len(xpath_rev)) { rset_start_tag = xpath_trunc(zh, stream, '0', - wrbuf_buf(xpath_rev), + wrbuf_cstr(xpath_rev), ZEBRA_XPATH_ELM_BEGIN, rset_nmem, kc); if (always_matches) @@ -2202,7 +2201,7 @@ ZEBRA_RES rpn_search_xpath(ZebraHandle zh, else { rset_end_tag = xpath_trunc(zh, stream, '0', - wrbuf_buf(xpath_rev), + wrbuf_cstr(xpath_rev), ZEBRA_XPATH_ELM_END, rset_nmem, kc); @@ -2211,7 +2210,7 @@ ZEBRA_RES rpn_search_xpath(ZebraHandle zh, rset_end_tag, rset_attr); } } - wrbuf_free(xpath_rev, 1); + wrbuf_destroy(xpath_rev); first_path = 0; } } diff --git a/index/sgmlread.c b/index/sgmlread.c index 45680d0..5c18872 100644 --- a/index/sgmlread.c +++ b/index/sgmlread.c @@ -1,4 +1,4 @@ -/* $Id: sgmlread.c,v 1.4 2007-01-15 15:10:17 adam Exp $ +/* $Id: sgmlread.c,v 1.5 2007-03-19 21:50:39 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -99,9 +99,9 @@ static void grs_destroy_sgml(void *clientData) { struct sgml_getc_info *p = (struct sgml_getc_info *) clientData; - wrbuf_free(p->wrbuf, 1); - xfree (p->buf); - xfree (p); + wrbuf_destroy(p->wrbuf); + xfree(p->buf); + xfree(p); } static int grs_extract_sgml(void *clientData, struct recExtractCtrl *ctrl) diff --git a/index/zebraapi.c b/index/zebraapi.c index d3fdab2..a1bb61d 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.251 2007-03-14 11:48:32 adam Exp $ +/* $Id: zebraapi.c,v 1.252 2007-03-19 21:50:39 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -1513,9 +1513,9 @@ ZEBRA_RES zebra_create_database (ZebraHandle zh, const char *db) return zebra_end_trans (zh); } -int zebra_string_norm (ZebraHandle zh, unsigned reg_id, - const char *input_str, int input_len, - char *output_str, int output_len) +int zebra_string_norm(ZebraHandle zh, unsigned reg_id, + const char *input_str, int input_len, + char *output_str, int output_len) { WRBUF wrbuf; ASSERTZH; diff --git a/index/zebrash.c b/index/zebrash.c index 2374646..333b378 100644 --- a/index/zebrash.c +++ b/index/zebrash.c @@ -1,4 +1,4 @@ -/* $Id: zebrash.c,v 1.43 2007-03-14 11:48:32 adam Exp $ +/* $Id: zebrash.c,v 1.44 2007-03-19 21:50:39 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -419,14 +419,14 @@ static int cmd_find( char *args[], WRBUF outbuff) wrbuf_puts(qry,restargs(args,1)); if (!zh) onecommand("quickstart", outbuff, ""); - wrbuf_printf(outbuff, "find %s\n",wrbuf_buf(qry)); - rc = zebra_search_PQF(zh, wrbuf_buf(qry), setname, &hits); + wrbuf_printf(outbuff, "find %s\n",wrbuf_cstr(qry)); + rc = zebra_search_PQF(zh, wrbuf_cstr(qry), setname, &hits); if (0==rc) { wrbuf_printf(outbuff, ZINT_FORMAT " hits found\n", hits); nextrecno = 1; } - wrbuf_free(qry, 1); + wrbuf_destroy(qry); return rc; } @@ -812,7 +812,7 @@ void shell(void) /* get rid of \n in line */ if ((nl_cp = strchr(buf, '\n'))) *nl_cp = '\0'; - strncpy(prevout, wrbuf_buf(outbuff), MAX_OUT_BUFF); + strncpy(prevout, wrbuf_cstr(outbuff), MAX_OUT_BUFF); wrbuf_rewind(outbuff); rc=onecommand(buf, outbuff, prevout); if (rc==0) @@ -825,9 +825,9 @@ void shell(void) wrbuf_printf(outbuff, " command returned %d\n",rc); } Zerrors(outbuff); - printf("%s\n", wrbuf_buf(outbuff)); + printf("%s\n", wrbuf_cstr(outbuff)); } /* while */ - wrbuf_free(outbuff,1); + wrbuf_destroy(outbuff); } /* shell() */ diff --git a/isamb/benchindex1.c b/isamb/benchindex1.c index 9c4f01d..e0de99d 100644 --- a/isamb/benchindex1.c +++ b/isamb/benchindex1.c @@ -1,4 +1,4 @@ -/* $Id: benchindex1.c,v 1.9 2007-01-15 15:10:17 adam Exp $ +/* $Id: benchindex1.c,v 1.10 2007-03-19 21:50:39 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -490,7 +490,7 @@ void index_marc_from_file(ISAMB isb, index_block_check_flush(b, isb, dict, no_docs); } index_block_flush(b, isb, dict, no_docs); - wrbuf_free(wrbuf, 1); + wrbuf_destroy(wrbuf); yaz_marc_destroy(mt); index_block_destroy(&b); } diff --git a/util/zebramap.c b/util/zebramap.c index dfec14c..d227956 100644 --- a/util/zebramap.c +++ b/util/zebramap.c @@ -1,4 +1,4 @@ -/* $Id: zebramap.c,v 1.56 2007-01-22 18:15:04 adam Exp $ +/* $Id: zebramap.c,v 1.57 2007-03-19 21:50:39 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -77,7 +77,7 @@ void zebra_maps_close(ZebraMaps zms) chrmaptab_destroy(zm->maptab); zm = zm->next; } - wrbuf_free(zms->wrbuf_1, 1); + wrbuf_destroy(zms->wrbuf_1); nmem_destroy(zms->nmem); xfree(zms); } -- 1.7.10.4