From: Adam Dickmeiss Date: Sat, 15 Jan 2005 20:47:15 +0000 (+0000) Subject: Fixed bug #165: Use multi-and and multi-or always. WS cleanups. X-Git-Tag: snippet.version.1~159 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=98912d364cb21abf4c2f3229d5578e2a3159f616;p=idzebra-moved-to-github.git Fixed bug #165: Use multi-and and multi-or always. WS cleanups. --- diff --git a/include/rset.h b/include/rset.h index 06fd485..ec09bad 100644 --- a/include/rset.h +++ b/include/rset.h @@ -1,4 +1,4 @@ -/* $Id: rset.h,v 1.44 2005-01-15 19:38:24 adam Exp $ +/* $Id: rset.h,v 1.45 2005-01-15 20:47:15 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -20,12 +20,10 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - #ifndef RSET_H #define RSET_H -#include +#include /* unfortunately we need the isam includes here, for the arguments for */ /* rsisamX_create */ @@ -33,9 +31,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#ifdef __cplusplus -extern "C" { -#endif +YAZ_BEGIN_CDECL typedef struct rsfd *RSFD; /* Rset "file descriptor" */ typedef struct rset *RSET; /* Result set */ @@ -199,7 +195,7 @@ RSET rset_dup (RSET rs); /* int rset_pos(RSFD fd, double *current, double *total); */ #define rset_pos(rfd,cur,tot) \ - (*(rfd)->rset->control->f_pos)( (rfd),(cur),(tot)) + (*(rfd)->rset->control->f_pos)((rfd),(cur),(tot)) /* int rset_read(RSFD rfd, void *buf, TERMID term); */ #define rset_read(rfd, buf, term) \ @@ -214,62 +210,45 @@ RSET rset_dup (RSET rs); /** rset_count counts or estimates the keys in it*/ zint rset_count(RSET rs); -RSET rstemp_create( NMEM nmem, const struct key_control *kcontrol, +RSET rstemp_create(NMEM nmem, const struct key_control *kcontrol, int scope, const char *temp_path, TERMID term); RSET rsnull_create(NMEM nmem, const struct key_control *kcontrol); -RSET rsbool_create_and( NMEM nmem, const struct key_control *kcontrol, - int scope, - RSET rset_l, RSET rset_r); +RSET rsbool_create_and(NMEM nmem, const struct key_control *kcontrol, + int scope, RSET rset_l, RSET rset_r); -RSET rsbool_create_or ( NMEM nmem, const struct key_control *kcontrol, - int scope, - RSET rset_l, RSET rset_r); +RSET rsbool_create_or (NMEM nmem, const struct key_control *kcontrol, + int scope, RSET rset_l, RSET rset_r); -RSET rsbool_create_not( NMEM nmem, const struct key_control *kcontrol, - int scope, - RSET rset_l, RSET rset_r); +RSET rsbool_create_not(NMEM nmem, const struct key_control *kcontrol, + int scope, RSET rset_l, RSET rset_r); -RSET rsbetween_create( NMEM nmem, const struct key_control *kcontrol, - int scope, - RSET rset_l, RSET rset_m, RSET rset_r, - RSET rset_attr); +RSET rsbetween_create(NMEM nmem, const struct key_control *kcontrol, + int scope, RSET rset_l, RSET rset_m, RSET rset_r, + RSET rset_attr); -RSET rsmultior_create( NMEM nmem, const struct key_control *kcontrol, - int scope, - int no_rsets, RSET* rsets); +RSET rsmulti_or_create(NMEM nmem, const struct key_control *kcontrol, + int scope, int no_rsets, RSET* rsets); -RSET rsmultiand_create( NMEM nmem, const struct key_control *kcontrol, - int scope, - int no_rsets, RSET* rsets); +RSET rsmulti_and_create(NMEM nmem, const struct key_control *kcontrol, + int scope, int no_rsets, RSET* rsets); -RSET rsprox_create( NMEM nmem, const struct key_control *kcontrol, - int scope, - int rset_no, RSET *rset, - int ordered, int exclusion, - int relation, int distance); +RSET rsprox_create(NMEM nmem, const struct key_control *kcontrol, + int scope, int rset_no, RSET *rset, + int ordered, int exclusion, int relation, int distance); -RSET rsisamb_create( NMEM nmem, const struct key_control *kcontrol, - int scope, - ISAMB is, ISAMB_P pos, - TERMID term); +RSET rsisamb_create(NMEM nmem, const struct key_control *kcontrol, + int scope, ISAMB is, ISAMB_P pos, TERMID term); -RSET rsisamc_create( NMEM nmem, const struct key_control *kcontrol, - int scope, - ISAMC is, ISAMC_P pos, - TERMID term); +RSET rsisamc_create(NMEM nmem, const struct key_control *kcontrol, + int scope, ISAMC is, ISAMC_P pos, TERMID term); -RSET rsisams_create( NMEM nmem, const struct key_control *kcontrol, - int scope, - ISAMS is, ISAMS_P pos, - TERMID term); +RSET rsisams_create(NMEM nmem, const struct key_control *kcontrol, + int scope, ISAMS is, ISAMS_P pos, TERMID term); - -#ifdef __cplusplus -} -#endif +YAZ_END_CDECL #endif diff --git a/index/trunc.c b/index/trunc.c index 909999a..f64f12b 100644 --- a/index/trunc.c +++ b/index/trunc.c @@ -1,4 +1,4 @@ -/* $Id: trunc.c,v 1.50 2005-01-15 19:38:28 adam Exp $ +/* $Id: trunc.c,v 1.51 2005-01-15 20:47:15 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -91,19 +91,19 @@ static struct trunc_info *heap_init (int size, int key_size, int (*cmp)(const void *p1, const void *p2)) { - struct trunc_info *ti = (struct trunc_info *) xmalloc (sizeof(*ti)); + struct trunc_info *ti = (struct trunc_info *) xmalloc(sizeof(*ti)); int i; ++size; ti->heapnum = 0; ti->keysize = key_size; ti->cmp = cmp; - ti->indx = (int *) xmalloc (size * sizeof(*ti->indx)); - ti->heap = (char **) xmalloc (size * sizeof(*ti->heap)); - ti->ptr = (int *) xmalloc (size * sizeof(*ti->ptr)); - ti->swapbuf = (char *) xmalloc (ti->keysize); - ti->tmpbuf = (char *) xmalloc (ti->keysize); - ti->buf = (char *) xmalloc (size * ti->keysize); + ti->indx = (int *) xmalloc(size * sizeof(*ti->indx)); + ti->heap = (char **) xmalloc(size * sizeof(*ti->heap)); + ti->ptr = (int *) xmalloc(size * sizeof(*ti->ptr)); + ti->swapbuf = (char *) xmalloc(ti->keysize); + ti->tmpbuf = (char *) xmalloc(ti->keysize); + ti->buf = (char *) xmalloc(size * ti->keysize); for (i = size; --i >= 0; ) { ti->ptr[i] = i; @@ -114,13 +114,13 @@ static struct trunc_info *heap_init (int size, int key_size, static void heap_close (struct trunc_info *ti) { - xfree (ti->ptr); - xfree (ti->indx); - xfree (ti->heap); - xfree (ti->swapbuf); - xfree (ti->tmpbuf); - xfree (ti->buf); - xfree (ti); + xfree(ti->ptr); + xfree(ti->indx); + xfree(ti->heap); + xfree(ti->swapbuf); + xfree(ti->tmpbuf); + xfree(ti->buf); + xfree(ti); } static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, @@ -141,7 +141,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, parms.temp_path = res_get (zi->res, "setTmpDir"); result = rset_create (rset_kind_temp, &parms); */ - result=rstemp_create( rset_nmem,kctrl, scope, + result = rstemp_create( rset_nmem,kctrl, scope, res_get (zi->res, "setTmpDir"), termid); result_rsfd = rset_open (result, RSETF_WRITE); @@ -154,8 +154,8 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, int rscur = 0; int rsmax = (to-from)/i_add + 1; - rset = (RSET *) xmalloc (sizeof(*rset) * rsmax); - rsfd = (RSFD *) xmalloc (sizeof(*rsfd) * rsmax); + rset = (RSET *) xmalloc(sizeof(*rset) * rsmax); + rsfd = (RSFD *) xmalloc(sizeof(*rsfd) * rsmax); for (i = from; i < to; i += i_add) { @@ -209,8 +209,8 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, } } } - xfree (rset); - xfree (rsfd); + xfree(rset); + xfree(rsfd); heap_close (ti); } else if (zi->reg->isamc) @@ -219,7 +219,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, int i; struct trunc_info *ti; - ispt = (ISAMC_PP *) xmalloc (sizeof(*ispt) * (to-from)); + ispt = (ISAMC_PP *) xmalloc(sizeof(*ispt) * (to-from)); ti = heap_init (to-from, sizeof(struct it_key), key_compare_it); @@ -265,7 +265,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, } } heap_close (ti); - xfree (ispt); + xfree(ispt); } else if (zi->reg->isams) { @@ -274,7 +274,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, struct trunc_info *ti; int nn = 0; - ispt = (ISAMS_PP *) xmalloc (sizeof(*ispt) * (to-from)); + ispt = (ISAMS_PP *) xmalloc(sizeof(*ispt) * (to-from)); ti = heap_init (to-from, sizeof(struct it_key), key_compare_it); @@ -309,7 +309,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, } } heap_close (ti); - xfree (ispt); + xfree(ispt); } else if (zi->reg->isamb) { @@ -317,7 +317,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, int i; struct trunc_info *ti; - ispt = (ISAMB_PP *) xmalloc (sizeof(*ispt) * (to-from)); + ispt = (ISAMB_PP *) xmalloc(sizeof(*ispt) * (to-from)); ti = heap_init (to-from, sizeof(struct it_key), key_compare_it); @@ -366,7 +366,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, } } heap_close (ti); - xfree (ispt); + xfree(ispt); } else yaz_log (YLOG_WARN, "Unknown isam set in rset_trunc_r"); @@ -412,7 +412,7 @@ RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no, yaz_log (YLOG_DEBUG, "rset_trunc no=%d", no); if (no < 1) return rsnull_create (rset_nmem,kctrl); - termid=rset_term_create(term, length, flags, term_type,rset_nmem); + termid = rset_term_create(term, length, flags, term_type,rset_nmem); if (zi->reg->isams) { if (no == 1) @@ -435,12 +435,12 @@ RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no, else if (no <10000 ) /* FIXME - hardcoded number */ { RSET r; - RSET *rsets=xmalloc(no*sizeof(RSET)); /* use nmem! */ + RSET *rsets = xmalloc(no*sizeof(RSET)); /* use nmem! */ int i; - for (i=0;ireg->isamb, isam_p[i], termid); - r=rsmultior_create( rset_nmem, kctrl, scope, no, rsets); + r = rsmulti_or_create( rset_nmem, kctrl, scope, no, rsets); xfree(rsets); return r; } diff --git a/index/zrpn.c b/index/zrpn.c index a5a7709..0a49a0f 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -1,4 +1,4 @@ -/* $Id: zrpn.c,v 1.167 2005-01-15 19:38:29 adam Exp $ +/* $Id: zrpn.c,v 1.168 2005-01-15 20:47:15 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -66,8 +66,8 @@ typedef struct } AttrType; -static int log_level_set=0; -static int log_level_rpn=0; +static int log_level_set = 0; +static int log_level_rpn = 0; static const char **rpn_char_map_handler(void *vp, const char **from, int len) { @@ -195,7 +195,7 @@ static void term_untrans(ZebraHandle zh, int reg_type, while (*src) { const char *cp = zebra_maps_output(zh->reg->zebra_maps, - reg_type, &src); + reg_type, &src); if (!cp && len < IT_MAX_WORD-1) dst[len++] = *src++; else @@ -211,7 +211,7 @@ static void add_isam_p(const char *name, const char *info, if (!log_level_set) { log_level_rpn = yaz_log_module_level("rpn"); - log_level_set=1; + log_level_set = 1; } if (p->isam_p_indx == p->isam_p_size) { @@ -231,8 +231,7 @@ static void add_isam_p(const char *name, const char *info, p->isam_p_buf = new_isam_p_buf; #ifdef TERM_COUNT - new_term_no = (int *) xmalloc(sizeof(*new_term_no) * - p->isam_p_size); + new_term_no = (int *) xmalloc(sizeof(*new_term_no) * p->isam_p_size); if (p->term_no) { memcpy(new_term_no, p->isam_p_buf, @@ -298,7 +297,7 @@ static int term_pre(ZebraMaps zebra_maps, int reg_type, const char **src, #define REGEX_CHARS " []()|.*+?!" -/* term_100: handle term, where trunc=none(no operators at all) */ +/* term_100: handle term, where trunc = none(no operators at all) */ static int term_100(ZebraMaps zebra_maps, int reg_type, const char **src, char *dst, int space_split, char *dst_term) @@ -359,7 +358,7 @@ static int term_100(ZebraMaps zebra_maps, int reg_type, return i; } -/* term_101: handle term, where trunc=Process # */ +/* term_101: handle term, where trunc = Process # */ static int term_101(ZebraMaps zebra_maps, int reg_type, const char **src, char *dst, int space_split, char *dst_term) @@ -401,7 +400,7 @@ static int term_101(ZebraMaps zebra_maps, int reg_type, return i; } -/* term_103: handle term, where trunc=re-2 (regular expressions) */ +/* term_103: handle term, where trunc = re-2 (regular expressions) */ static int term_103(ZebraMaps zebra_maps, int reg_type, const char **src, char *dst, int *errors, int space_split, char *dst_term) @@ -450,7 +449,7 @@ static int term_103(ZebraMaps zebra_maps, int reg_type, const char **src, return i; } -/* term_103: handle term, where trunc=re-1 (regular expressions) */ +/* term_103: handle term, where trunc = re-1 (regular expressions) */ static int term_102 (ZebraMaps zebra_maps, int reg_type, const char **src, char *dst, int space_split, char *dst_term) { @@ -459,7 +458,7 @@ static int term_102 (ZebraMaps zebra_maps, int reg_type, const char **src, } -/* term_104: handle term, where trunc=Process # and ! */ +/* term_104: handle term, where trunc = Process # and ! */ static int term_104(ZebraMaps zebra_maps, int reg_type, const char **src, char *dst, int space_split, char *dst_term) @@ -530,7 +529,7 @@ static int term_104(ZebraMaps zebra_maps, int reg_type, return i; } -/* term_105/106: handle term, where trunc=Process * and ! and right trunc */ +/* term_105/106: handle term, where trunc = Process * and ! and right trunc */ static int term_105 (ZebraMaps zebra_maps, int reg_type, const char **src, char *dst, int space_split, char *dst_term, int right_truncate) @@ -682,7 +681,7 @@ static void gen_regular_rel(char *dst, int val, int islt) { /* match everything less than 10^(pos-1) */ strcat(dst, "0*"); - for (i=1; iscope, - rset_no, rset); + return rsmulti_or_create(rset_nmem, key_it_ctrl,key_it_ctrl->scope, + rset_no, rset); } static RSET rpn_search_APT_and_list (ZebraHandle zh, @@ -1474,10 +1473,10 @@ static RSET rpn_search_APT_and_list (ZebraHandle zh, } grep_info_delete (&grep_info); if (rset_no == 0) - return rsnull_create (rset_nmem,key_it_ctrl); - - return rsmultiand_create( rset_nmem, key_it_ctrl, key_it_ctrl->scope, - rset_no, rset); + return rsnull_create(rset_nmem,key_it_ctrl); + + return rsmulti_and_create(rset_nmem, key_it_ctrl, key_it_ctrl->scope, + rset_no, rset); } static int numeric_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt, @@ -1531,7 +1530,7 @@ static int numeric_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt, r = dict_lookup_grep(zh->reg->dict, term_dict, 0, grep_info, max_pos, 0, grep_handle); if (r) - yaz_log(YLOG_WARN, "dict_lookup_grep fail, rel=gt: %d", r); + yaz_log(YLOG_WARN, "dict_lookup_grep fail, rel = gt: %d", r); yaz_log(log_level_rpn, "%d positions", grep_info->isam_p_indx); return 1; } @@ -1588,7 +1587,7 @@ static int numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, } else { - if ((r=att_getentbyatt (zh, &attp, curAttributeSet, use_value, + if ((r = att_getentbyatt (zh, &attp, curAttributeSet, use_value, use_string))) { yaz_log(YLOG_DEBUG, "att_getentbyatt fail. set=%d use=%d r=%d", @@ -1702,11 +1701,11 @@ static RSET rpn_search_APT_numeric (ZebraHandle zh, } grep_info_delete (&grep_info); if (rset_no == 0) - return rsnull_create (rset_nmem,key_it_ctrl); + return rsnull_create(rset_nmem,key_it_ctrl); if (rset_no == 1) return rset[0]; - return rsmultiand_create(rset_nmem,key_it_ctrl,key_it_ctrl->scope, - rset_no, rset); + return rsmulti_and_create(rset_nmem,key_it_ctrl,key_it_ctrl->scope, + rset_no, rset); } static RSET rpn_search_APT_local (ZebraHandle zh, Z_AttributesPlusTerm *zapt, @@ -1928,14 +1927,14 @@ static RSET rpn_search_xpath (ZebraHandle zh, / -> none - a[@attr=value]/b[@other=othervalue] + a[@attr = value]/b[@other = othervalue] /e/@a val range(e/,range(@a,freetext(w,1015,val),@a),e/) /a/b val range(b/a/,freetext(w,1016,val),b/a/) /a/b/@c val range(b/a/,range(@c,freetext(w,1016,val),@c),b/a/) - /a/b[@c=y] val range(b/a/,freetext(w,1016,val),b/a/,@c=y) - /a[@c=y]/b val range(a/,range(b/a/,freetext(w,1016,val),b/a/),a/,@c=y) - /a[@c=x]/b[@c=y] range(a/,range(b/a/,freetext(w,1016,val),b/a/,@c=y),a/,@c=x) + /a/b[@c = y] val range(b/a/,freetext(w,1016,val),b/a/,@c = y) + /a[@c = y]/b val range(a/,range(b/a/,freetext(w,1016,val),b/a/),a/,@c = y) + /a[@c = x]/b[@c = y] range(a/,range(b/a/,freetext(w,1016,val),b/a/,@c = y),a/,@c = x) */ @@ -2029,18 +2028,10 @@ static RSET rpn_search_xpath (ZebraHandle zh, rset_end_tag = xpath_trunc(zh, stream, '0', xpath_rev, 2, curAttributeSet, rset_nmem); - /* - parms.key_size = sizeof(struct it_key); - parms.cmp = key_compare_it; - parms.rset_l = rset_start_tag; - parms.rset_m = rset; - parms.rset_r = rset_end_tag; - parms.rset_attr = rset_attr; - parms.printer = key_print_it; - rset = rset_create (rset_kind_between, &parms); - */ - rset=rsbetween_create( rset_nmem,key_it_ctrl,key_it_ctrl->scope, - rset_start_tag, rset, rset_end_tag, rset_attr); + rset = rsbetween_create(rset_nmem, key_it_ctrl, + key_it_ctrl->scope, + rset_start_tag, rset, + rset_end_tag, rset_attr); } first_path = 0; } @@ -2071,7 +2062,7 @@ static RSET rpn_search_APT (ZebraHandle zh, Z_AttributesPlusTerm *zapt, if (!log_level_set) { log_level_rpn = yaz_log_module_level("rpn"); - log_level_set=1; + log_level_set = 1; } zebra_maps_attr (zh->reg->zebra_maps, zapt, ®_id, &search_type, rank_type, &complete_flag, &sort_flag); @@ -2170,12 +2161,12 @@ static RSET rpn_search_structure (ZebraHandle zh, Z_RPNStructure *zs, switch (zop->which) { case Z_Operator_and: - r=rsmultiand_create(rset_nmem, key_it_ctrl, key_it_ctrl->scope, - 2, rsets); + r = rsmulti_and_create(rset_nmem, key_it_ctrl, key_it_ctrl->scope, + 2, rsets); break; case Z_Operator_or: - r=rsmultior_create(rset_nmem, key_it_ctrl, key_it_ctrl->scope, - 2, rsets); + r = rsmulti_or_create(rset_nmem, key_it_ctrl, key_it_ctrl->scope, + 2, rsets); break; case Z_Operator_and_not: r = rsbool_create_not(rset_nmem,key_it_ctrl, key_it_ctrl->scope, @@ -2198,7 +2189,7 @@ static RSET rpn_search_structure (ZebraHandle zh, Z_RPNStructure *zs, else { /* new / old prox */ - r=rsprox_create(rset_nmem,key_it_ctrl,key_it_ctrl->scope, + r = rsprox_create(rset_nmem,key_it_ctrl,key_it_ctrl->scope, 2, rsets, *zop->u.prox->ordered, (!zop->u.prox->exclusion ? @@ -2421,7 +2412,7 @@ void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, char rank_type[128]; int complete_flag; int sort_flag; - NMEM rset_nmem=NULL; + NMEM rset_nmem = NULL; *list = 0; @@ -2477,7 +2468,7 @@ void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, attent attp; data1_local_attribute *local_attr; - if ((r=att_getentbyatt (zh, &attp, attributeset, use_value, + if ((r = att_getentbyatt (zh, &attp, attributeset, use_value, use_string))) { yaz_log(YLOG_DEBUG, "att_getentbyatt fail. set=%d use=%d", @@ -2553,7 +2544,7 @@ void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, if (trans_scan_term(zh, zapt, termz+prefix_len, reg_id)) return ; - + dict_scan(zh->reg->dict, termz, &before_tmp, &after_tmp, scan_info, scan_handle); } @@ -2577,7 +2568,7 @@ void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, for (j = 0; j < ord_no; j++) { if (ptr[j] < before+after && - (tst=scan_info_array[j].list[ptr[j]].term) && + (tst = scan_info_array[j].list[ptr[j]].term) && (!mterm || strcmp (tst, mterm) < 0)) { j0 = j; @@ -2589,104 +2580,116 @@ void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, scan_term_untrans (zh, stream->mem, reg_id, &glist[i+before].term, mterm); rset = rset_trunc(zh, &scan_info_array[j0].list[ptr[j0]].isam_p, 1, - glist[i+before].term, strlen(glist[i+before].term), - NULL, 0, zapt->term->which, rset_nmem, - key_it_ctrl,key_it_ctrl->scope); + glist[i+before].term, strlen(glist[i+before].term), + NULL, 0, zapt->term->which, rset_nmem, + key_it_ctrl,key_it_ctrl->scope); ptr[j0]++; for (j = j0+1; jterm->which,rset_nmem, - key_it_ctrl, key_it_ctrl->scope); - rset = rsbool_create_or(rset_nmem,key_it_ctrl, - key_it_ctrl->scope, rset, rset2); - /* FIXME - Use a proper multi-or */ - + RSET rsets[2]; + + rsets[0] = rset; + rsets[1] = + rset_trunc(zh, &scan_info_array[j].list[ptr[j]].isam_p, 1, + glist[i+before].term, + strlen(glist[i+before].term), NULL, 0, + zapt->term->which,rset_nmem, + key_it_ctrl, key_it_ctrl->scope); + rset = rsmulti_or_create(rset_nmem, key_it_ctrl, + 2, key_it_ctrl->scope, rsets); ptr[j]++; } } if (limit_set) - rset = rsbool_create_and(rset_nmem,key_it_ctrl,key_it_ctrl->scope, - rset, rset_dup(limit_set)); - count_set (rset, &glist[i+before].occurrences); - rset_delete (rset); + { + RSET rsets[2]; + rsets[0] = rset; + rsets[1] = rset_dup(limit_set); + + rset = rsmulti_and_create(rset_nmem, key_it_ctrl, + key_it_ctrl->scope, 2, rsets); + } + count_set(rset, &glist[i+before].occurrences); + rset_delete(rset); } if (i < after) { - *num_entries -= (after-i); - *is_partial = 1; + *num_entries -= (after-i); + *is_partial = 1; } - + /* consider terms before main term */ for (i = 0; i 0)) - { - j0 = j; - mterm = tst; - } - } - if (j0 == -1) - break; - - scan_term_untrans (zh, stream->mem, reg_id, - &glist[before-1-i].term, mterm); - - rset = rset_trunc - (zh, &scan_info_array[j0].list[before-1-ptr[j0]].isam_p, 1, - glist[before-1-i].term, strlen(glist[before-1-i].term), - NULL, 0, zapt->term->which,rset_nmem, - key_it_ctrl,key_it_ctrl->scope); - - ptr[j0]++; - - for (j = j0+1; j 0)) + { + j0 = j; + mterm = tst; + } + } + if (j0 == -1) + break; + + scan_term_untrans (zh, stream->mem, reg_id, + &glist[before-1-i].term, mterm); + + rset = rset_trunc + (zh, &scan_info_array[j0].list[before-1-ptr[j0]].isam_p, 1, + glist[before-1-i].term, strlen(glist[before-1-i].term), + NULL, 0, zapt->term->which,rset_nmem, + key_it_ctrl,key_it_ctrl->scope); + + ptr[j0]++; + + for (j = j0+1; jterm->which, rset_nmem, key_it_ctrl, key_it_ctrl->scope); - rset = rsbool_create_and(rset_nmem,key_it_ctrl, - key_it_ctrl->scope, rset, rset2); - /* FIXME - multi-and ?? */ - ptr[j]++; - } - } + rset = rsmulti_or_create(rset_nmem, key_it_ctrl, + 2, key_it_ctrl->scope, rsets); + + ptr[j]++; + } + } if (limit_set) - rset = rsbool_create_and(rset_nmem,key_it_ctrl,key_it_ctrl->scope, - rset, rset_dup(limit_set)); - count_set (rset, &glist[before-1-i].occurrences); - rset_delete (rset); + { + RSET rsets[2]; + rsets[0] = rset; + rsets[1] = rset_dup(limit_set); + + rset = rsmulti_and_create(rset_nmem, key_it_ctrl, + key_it_ctrl->scope, 2, rsets); + } + count_set (rset, &glist[before-1-i].occurrences); + rset_delete (rset); } i = before-i; if (i) @@ -2695,13 +2698,13 @@ void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, *position -= i; *num_entries -= i; } - + nmem_destroy(rset_nmem); *list = glist + i; /* list is set to first 'real' entry */ yaz_log(YLOG_DEBUG, "position = %d, num_entries = %d", - *position, *num_entries); + *position, *num_entries); if (zh->errCode) yaz_log(YLOG_DEBUG, "scan error: %d", zh->errCode); } - + diff --git a/rset/rsbetween.c b/rset/rsbetween.c index 1d404c6..486954b 100644 --- a/rset/rsbetween.c +++ b/rset/rsbetween.c @@ -1,4 +1,4 @@ -/* $Id: rsbetween.c,v 1.34 2005-01-15 19:38:33 adam Exp $ +/* $Id: rsbetween.c,v 1.35 2005-01-15 20:47:16 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -26,7 +26,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA * example "Shakespeare" in between "" and . The thing is * complicated by the inclusion of attributes (from their own rset). If attrs * specified, they must match the "left" rset (start tag). "Hamlet" between - * "" and "". (This assumes that the attributes are + * "" and "". (This assumes that the attributes are * indexed to the same seqno as the tags). * */ @@ -90,8 +90,8 @@ struct rset_between_rfd { zint hits; }; -static int log_level=0; -static int log_level_initialized=0; +static int log_level = 0; +static int log_level_initialized = 0; /* make sure that the rset has a term attached. If not, create one */ @@ -102,7 +102,7 @@ static void checkterm( RSET rs, char *tag, NMEM nmem) { rs->term= rset_term_create(tag,strlen(tag),"",0,nmem); - rs->term->rset=rs; + rs->term->rset = rs; } } @@ -111,16 +111,16 @@ RSET rsbetween_create( NMEM nmem, const struct key_control *kcontrol, int scope, RSET rset_l, RSET rset_m, RSET rset_r, RSET rset_attr) { - RSET rnew=rset_create_base(&control, nmem, kcontrol, scope,0); + RSET rnew = rset_create_base(&control, nmem, kcontrol, scope,0); struct rset_between_info *info= (struct rset_between_info *) nmem_malloc(rnew->nmem,sizeof(*info)); RSET rsetarray[4]; - int n=4; + int n = 4; if (!log_level_initialized) { - log_level=yaz_log_module_level("rsbetween"); - log_level_initialized=1; + log_level = yaz_log_module_level("rsbetween"); + log_level_initialized = 1; } rsetarray[STARTTAG] = rset_l; rsetarray[HIT] = rset_m; @@ -130,22 +130,22 @@ RSET rsbetween_create( NMEM nmem, const struct key_control *kcontrol, /* make sure we have decent terms for all rsets. Create dummies if needed*/ checkterm( rsetarray[STARTTAG], "(start)",nmem); checkterm( rsetarray[STOPTAG], "(start)",nmem); - info->startterm=rsetarray[STARTTAG]->term; - info->stopterm=rsetarray[STOPTAG]->term; + info->startterm = rsetarray[STARTTAG]->term; + info->stopterm = rsetarray[STOPTAG]->term; if (rset_attr) { checkterm( rsetarray[ATTRTAG], "(start)",nmem); - info->attrterm=rsetarray[ATTRTAG]->term; - n=4; + info->attrterm = rsetarray[ATTRTAG]->term; + n = 4; } else { - info->attrterm=NULL; - n=3; + info->attrterm = NULL; + n = 3; } - info->andset=rsmultiand_create( nmem, kcontrol, scope, n, rsetarray); - rnew->priv=info; + info->andset = rsmulti_and_create( nmem, kcontrol, scope, n, rsetarray); + rnew->priv = info; yaz_log(log_level,"create rset at %p",rnew); return rnew; } @@ -170,22 +170,22 @@ static RSFD r_open (RSET ct, int flag) yaz_log (YLOG_FATAL, "between set type is read-only"); return NULL; } - rfd=rfd_create_base(ct); + rfd = rfd_create_base(ct); if (rfd->priv) p=(struct rset_between_rfd *)rfd->priv; else { p = (struct rset_between_rfd *) nmem_malloc(ct->nmem, (sizeof(*p))); - rfd->priv=p; + rfd->priv = p; p->recbuf = nmem_malloc(ct->nmem, (ct->keycontrol->key_size)); p->startbuf = nmem_malloc(ct->nmem, (ct->keycontrol->key_size)); p->attrbuf = nmem_malloc(ct->nmem, (ct->keycontrol->key_size)); } p->andrfd = rset_open (info->andset, RSETF_READ); p->hits=-1; - p->depth=0; - p->attrdepth=0; - p->attrbufok=0; - p->startbufok=0; + p->depth = 0; + p->attrdepth = 0; + p->attrbufok = 0; + p->startbufok = 0; yaz_log(log_level,"open rset=%p rfd=%p", ct, rfd); return rfd; } @@ -206,7 +206,7 @@ static int r_forward(RSFD rfd, void *buf, struct rset_between_rfd *p=(struct rset_between_rfd *)rfd->priv; int rc; yaz_log(log_level, "forwarding "); - rc=rset_forward(p->andrfd,buf,term,untilbuf); + rc = rset_forward(p->andrfd,buf,term,untilbuf); return rc; } @@ -216,7 +216,7 @@ static void checkattr(RSFD rfd) { struct rset_between_info *info =(struct rset_between_info *)rfd->rset->priv; struct rset_between_rfd *p=(struct rset_between_rfd *)rfd->priv; - const struct key_control *kctrl=rfd->rset->keycontrol; + const struct key_control *kctrl = rfd->rset->keycontrol; int cmp; if (p->attrdepth) return; /* already found one */ @@ -230,7 +230,7 @@ static void checkattr(RSFD rfd) cmp=(kctrl->cmp)(p->startbuf,p->attrbuf); if (0==cmp) /* and the keys match */ { - p->attrdepth=p->depth; + p->attrdepth = p->depth; yaz_log(log_level, "found attribute match at depth %d",p->attrdepth); } } @@ -241,9 +241,9 @@ static int r_read (RSFD rfd, void *buf, TERMID *term) { struct rset_between_info *info =(struct rset_between_info *)rfd->rset->priv; struct rset_between_rfd *p=(struct rset_between_rfd *)rfd->priv; - const struct key_control *kctrl=rfd->rset->keycontrol; + const struct key_control *kctrl = rfd->rset->keycontrol; int cmp; - TERMID dummyterm=0; + TERMID dummyterm = 0; yaz_log(log_level,"== read: term=%p",term); if (!term) term=&dummyterm; @@ -254,8 +254,8 @@ static int r_read (RSFD rfd, void *buf, TERMID *term) if (p->hits<0) {/* first time? */ memcpy(p->recbuf,buf,kctrl->key_size); - p->hits=0; - cmp=rfd->rset->scope; /* force newrecord */ + p->hits = 0; + cmp = rfd->rset->scope; /* force newrecord */ } else { cmp=(kctrl->cmp)(buf,p->recbuf); @@ -265,8 +265,8 @@ static int r_read (RSFD rfd, void *buf, TERMID *term) if (cmp>=rfd->rset->scope) { yaz_log(log_level,"new record"); - p->depth=0; - p->attrdepth=0; + p->depth = 0; + p->attrdepth = 0; memcpy(p->recbuf,buf,kctrl->key_size); } @@ -277,13 +277,13 @@ static int r_read (RSFD rfd, void *buf, TERMID *term) p->depth++; yaz_log(log_level,"read start tag. d=%d",p->depth); memcpy(p->startbuf,buf,kctrl->key_size); - p->startbufok=1; + p->startbufok = 1; checkattr(rfd); /* in case we already saw the attr here */ } else if (*term==info->stopterm) { if (p->depth == p->attrdepth) - p->attrdepth=0; /* ending the tag with attr match */ + p->attrdepth = 0; /* ending the tag with attr match */ p->depth--; yaz_log(log_level,"read end tag. d=%d ad=%d",p->depth, p->attrdepth); } @@ -291,7 +291,7 @@ static int r_read (RSFD rfd, void *buf, TERMID *term) { yaz_log(log_level,"read attr"); memcpy(p->attrbuf,buf,kctrl->key_size); - p->attrbufok=1; + p->attrbufok = 1; checkattr(rfd); /* in case the start tag came first */ } else diff --git a/rset/rsmultiandor.c b/rset/rsmultiandor.c index 2e5207a..b5c1bd2 100644 --- a/rset/rsmultiandor.c +++ b/rset/rsmultiandor.c @@ -1,4 +1,4 @@ -/* $Id: rsmultiandor.c,v 1.12 2005-01-15 19:38:35 adam Exp $ +/* $Id: rsmultiandor.c,v 1.13 2005-01-15 20:47:16 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -22,7 +22,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA /* - * This module implements the rsmultior and rsmultiand result sets + * This module implements the rsmulti_or and rsmulti_and result sets * * rsmultior is based on a heap, from which we find the next hit. * @@ -125,14 +125,15 @@ struct rset_multiandor_rfd { char *tailbits; }; -static int log_level=0; -static int log_level_initialized=0; +static int log_level = 0; +static int log_level_initialized = 0; /* Heap functions ***********************/ #if 0 -static void heap_dump_item( HEAP h, int i, int level) { +static void heap_dump_item( HEAP h, int i, int level) +{ double cur,tot; if (i>h->heapnum) return; @@ -152,8 +153,8 @@ static void heap_swap (HEAP h, int x, int y) { struct heap_item *swap; swap = h->heap[x]; - h->heap[x]=h->heap[y]; - h->heap[y]=swap; + h->heap[x] = h->heap[y]; + h->heap[y] = swap; } static int heap_cmp(HEAP h, int x, int y) @@ -169,7 +170,7 @@ static int heap_empty(HEAP h) static void heap_delete (HEAP h) { /* deletes the first item in the heap, and balances the rest */ int cur = 1, child = 2; - h->heap[1]=0; /* been deleted */ + h->heap[1] = 0; /* been deleted */ heap_swap (h, 1, h->heapnum--); while (child <= h->heapnum) { if (child < h->heapnum && heap_cmp(h,child,1+child)>0 ) @@ -210,7 +211,7 @@ static void heap_insert (HEAP h, struct heap_item *hi) cur = ++(h->heapnum); assert(cur <= h->heapmax); - h->heap[cur]=hi; + h->heap[cur] = hi; parent = cur/2; while (parent && (heap_cmp(h,parent,cur) > 0)) { @@ -230,7 +231,7 @@ HEAP heap_create (NMEM nmem, int size, const struct key_control *kctrl) ++size; /* heap array starts at 1 */ h->heapnum = 0; h->heapmax = size; - h->kctrl=kctrl; + h->kctrl = kctrl; h->heap = (struct heap_item**) nmem_malloc(nmem,size*sizeof(*h->heap)); h->heap[0]=0; /* not used */ return h; @@ -239,7 +240,7 @@ HEAP heap_create (NMEM nmem, int size, const struct key_control *kctrl) static void heap_clear( HEAP h) { assert(h); - h->heapnum=0; + h->heapnum = 0; } static void heap_destroy (HEAP h) @@ -250,13 +251,15 @@ static void heap_destroy (HEAP h) int compare_ands(const void *x, const void *y) { /* used in qsort to get the multi-and args in optimal order */ /* that is, those with fewest occurrences first */ - const struct heap_item *hx=x; - const struct heap_item *hy=y; + const struct heap_item *hx = x; + const struct heap_item *hy = y; double cur, totx, toty; rset_pos(hx->fd, &cur, &totx); rset_pos(hy->fd, &cur, &toty); - if ( totx > toty +0.5 ) return 1; - if ( totx < toty -0.5 ) return -1; + if ( totx > toty +0.5 ) + return 1; + if ( totx < toty -0.5 ) + return -1; return 0; /* return totx - toty, except for overflows and rounding */ } @@ -266,30 +269,30 @@ static RSET rsmulti_andor_create( NMEM nmem, const struct key_control *kcontrol, int scope, int no_rsets, RSET* rsets, const struct rset_control *ctrl) { - RSET rnew=rset_create_base(ctrl, nmem,kcontrol, scope,0); + RSET rnew = rset_create_base(ctrl, nmem,kcontrol, scope,0); struct rset_multiandor_info *info; if (!log_level_initialized) { - log_level=yaz_log_module_level("rsmultiandor"); - log_level_initialized=1; + log_level = yaz_log_module_level("rsmultiandor"); + log_level_initialized = 1; } info = (struct rset_multiandor_info *) nmem_malloc(rnew->nmem,sizeof(*info)); - info->no_rsets=no_rsets; - info->rsets=(RSET*)nmem_malloc(rnew->nmem, no_rsets*sizeof(*rsets)); + info->no_rsets = no_rsets; + info->rsets = (RSET*)nmem_malloc(rnew->nmem, no_rsets*sizeof(*rsets)); memcpy(info->rsets,rsets,no_rsets*sizeof(*rsets)); - rnew->priv=info; + rnew->priv = info; return rnew; } -RSET rsmultior_create( NMEM nmem, const struct key_control *kcontrol, int scope, - int no_rsets, RSET* rsets) +RSET rsmulti_or_create(NMEM nmem, const struct key_control *kcontrol, + int scope, int no_rsets, RSET* rsets) { return rsmulti_andor_create(nmem, kcontrol, scope, no_rsets, rsets, &control_or); } -RSET rsmultiand_create( NMEM nmem, const struct key_control *kcontrol, int scope, - int no_rsets, RSET* rsets) +RSET rsmulti_and_create(NMEM nmem, const struct key_control *kcontrol, + int scope, int no_rsets, RSET* rsets) { return rsmulti_andor_create(nmem, kcontrol, scope, no_rsets, rsets, &control_and); @@ -299,7 +302,7 @@ static void r_delete (RSET ct) { struct rset_multiandor_info *info = (struct rset_multiandor_info *) ct->priv; int i; - for(i=0;ino_rsets;i++) + for(i = 0; ino_rsets; i++) rset_delete(info->rsets[i]); } @@ -319,9 +322,9 @@ static RSFD r_open_andor (RSET ct, int flag, int is_and) yaz_log (YLOG_FATAL, "multiandor set type is read-only"); return NULL; } - rfd=rfd_create_base(ct); + rfd = rfd_create_base(ct); if (rfd->priv) { - p=(struct rset_multiandor_rfd *)rfd->priv; + p = (struct rset_multiandor_rfd *)rfd->priv; if (!is_and) heap_clear(p->h); assert(p->items); @@ -329,37 +332,37 @@ static RSFD r_open_andor (RSET ct, int flag, int is_and) } else { p = (struct rset_multiandor_rfd *) nmem_malloc (ct->nmem,sizeof(*p)); - rfd->priv=p; - p->h=0; - p->tailbits=0; + rfd->priv = p; + p->h = 0; + p->tailbits = 0; if (is_and) - p->tailbits=nmem_malloc(ct->nmem, info->no_rsets*sizeof(char) ); + p->tailbits = nmem_malloc(ct->nmem, info->no_rsets*sizeof(char) ); else p->h = heap_create( ct->nmem, info->no_rsets, kctrl); p->items=(struct heap_item *) nmem_malloc(ct->nmem, info->no_rsets*sizeof(*p->items)); - for (i=0; ino_rsets; i++){ - p->items[i].rset=info->rsets[i]; - p->items[i].buf=nmem_malloc(ct->nmem,kctrl->key_size); + for (i = 0; ino_rsets; i++){ + p->items[i].rset = info->rsets[i]; + p->items[i].buf = nmem_malloc(ct->nmem,kctrl->key_size); } } p->flag = flag; - p->hits=0; - p->eof=0; - p->tailcount=0; + p->hits = 0; + p->eof = 0; + p->tailcount = 0; if (is_and) { /* read the array and sort it */ - for (i=0; ino_rsets; i++){ - p->items[i].fd=rset_open(info->rsets[i],RSETF_READ); + for (i = 0; ino_rsets; i++){ + p->items[i].fd = rset_open(info->rsets[i],RSETF_READ); if (!rset_read(p->items[i].fd, p->items[i].buf, &p->items[i].term)) - p->eof=1; - p->tailbits[i]=0; + p->eof = 1; + p->tailbits[i] = 0; } qsort(p->items, info->no_rsets, sizeof(p->items[0]), compare_ands); } else { /* fill the heap for ORing */ - for (i=0; ino_rsets; i++){ - p->items[i].fd=rset_open(info->rsets[i],RSETF_READ); + for (i = 0; ino_rsets; i++){ + p->items[i].fd = rset_open(info->rsets[i],RSETF_READ); if ( rset_read(p->items[i].fd, p->items[i].buf, &p->items[i].term)) heap_insert(p->h, &(p->items[i])); } @@ -398,8 +401,8 @@ static void r_close (RSFD rfd) static int r_forward_or(RSFD rfd, void *buf, TERMID *term,const void *untilbuf) { /* while heap head behind untilbuf, forward it and rebalance heap */ - struct rset_multiandor_rfd *p=rfd->priv; - const struct key_control *kctrl=rfd->rset->keycontrol; + struct rset_multiandor_rfd *p = rfd->priv; + const struct key_control *kctrl = rfd->rset->keycontrol; if (heap_empty(p->h)) return 0; while ( (*kctrl->cmp)(p->h->heap[1]->buf,untilbuf) < -rfd->rset->scope ) @@ -421,8 +424,8 @@ static int r_forward_or(RSFD rfd, void *buf, static int r_read_or (RSFD rfd, void *buf, TERMID *term) { - struct rset_multiandor_rfd *mrfd=rfd->priv; - const struct key_control *kctrl=rfd->rset->keycontrol; + struct rset_multiandor_rfd *mrfd = rfd->priv; + const struct key_control *kctrl = rfd->rset->keycontrol; struct heap_item *it; int rdres; if (heap_empty(mrfd->h)) @@ -430,9 +433,9 @@ static int r_read_or (RSFD rfd, void *buf, TERMID *term) it = mrfd->h->heap[1]; memcpy(buf,it->buf, kctrl->key_size); if (term) - *term=it->term; + *term = it->term; (mrfd->hits)++; - rdres=rset_read(it->fd, it->buf, &it->term); + rdres = rset_read(it->fd, it->buf, &it->term); if ( rdres ) heap_balance(mrfd->h); else @@ -450,35 +453,35 @@ static int r_read_and (RSFD rfd, void *buf, TERMID *term) /* Once a hit has been found, scan all items for the smallest */ /* value. Mark all as being in the tail. Read next from that */ /* item, and if not in the same record, clear its tail bit */ - struct rset_multiandor_rfd *p=rfd->priv; - const struct key_control *kctrl=rfd->rset->keycontrol; - struct rset_multiandor_info *info=rfd->rset->priv; + struct rset_multiandor_rfd *p = rfd->priv; + const struct key_control *kctrl = rfd->rset->keycontrol; + struct rset_multiandor_info *info = rfd->rset->priv; int i, mintail; int cmp; while (1) { if (p->tailcount) { /* we are tailing, find lowest tail and return it */ - mintail=0; + mintail = 0; while ((mintailno_rsets) && !p->tailbits[mintail]) mintail++; /* first tail */ - for (i=mintail+1;ino_rsets;i++) + for (i = mintail+1; ino_rsets; i++) { if (p->tailbits[i]) { cmp=(*kctrl->cmp)(p->items[i].buf,p->items[mintail].buf); if (cmp<0) - mintail=i; + mintail = i; } } /* return the lowest tail */ memcpy(buf, p->items[mintail].buf, kctrl->key_size); if (term) - *term=p->items[mintail].term; + *term = p->items[mintail].term; if (!rset_read(p->items[mintail].fd, p->items[mintail].buf, &p->items[mintail].term)) { - p->eof=1; /* game over, once tails have been returned */ + p->eof = 1; /* game over, once tails have been returned */ p->tailbits[mintail]=0; (p->tailcount)--; return 1; @@ -495,23 +498,23 @@ static int r_read_and (RSFD rfd, void *buf, TERMID *term) /* as tails. the earlier 'if' will then return the hits */ if (p->eof) return 0; /* nothing more to see */ - i=1; /* assume items[0] is highest up */ + i = 1; /* assume items[0] is highest up */ while (ino_rsets) { cmp=(*kctrl->cmp)(p->items[0].buf,p->items[i].buf); if (cmp<=-rfd->rset->scope) { /* [0] was behind, forward it */ if (!rset_forward(p->items[0].fd, p->items[0].buf, &p->items[0].term, p->items[i].buf)) { - p->eof=1; /* game over */ + p->eof = 1; /* game over */ return 0; } - i=0; /* start frowarding from scratch */ + i = 0; /* start frowarding from scratch */ } else if (cmp>=rfd->rset->scope) { /* [0] was ahead, forward i */ if (!rset_forward(p->items[i].fd, p->items[i].buf, &p->items[i].term, p->items[0].buf)) { - p->eof=1; /* game over */ + p->eof = 1; /* game over */ return 0; } } else @@ -520,9 +523,9 @@ static int r_read_and (RSFD rfd, void *buf, TERMID *term) /* if we get this far, all rsets are now within +- scope of [0] */ /* ergo, we have a hit. Mark them all as tailing, and let the */ /* upper 'if' return the hits in right order */ - for (i=0; ino_rsets;i++) - p->tailbits[i]=1; - p->tailcount=info->no_rsets; + for (i = 0; ino_rsets; i++) + p->tailbits[i] = 1; + p->tailcount = info->no_rsets; } /* while 1 */ } @@ -530,64 +533,65 @@ static int r_read_and (RSFD rfd, void *buf, TERMID *term) static int r_forward_and(RSFD rfd, void *buf, TERMID *term, const void *untilbuf) { - struct rset_multiandor_rfd *p=rfd->priv; - const struct key_control *kctrl=rfd->rset->keycontrol; - struct rset_multiandor_info *info=rfd->rset->priv; + struct rset_multiandor_rfd *p = rfd->priv; + const struct key_control *kctrl = rfd->rset->keycontrol; + struct rset_multiandor_info *info = rfd->rset->priv; int i; int cmp; - int killtail=0; + int killtail = 0; - for (i=0; ino_rsets;i++) + for (i = 0; ino_rsets; i++) { - cmp=(*kctrl->cmp)(p->items[i].buf,untilbuf); - if ( cmp <= -rfd->rset->scope ) + cmp = (*kctrl->cmp)(p->items[i].buf,untilbuf); + if (cmp <= -rfd->rset->scope) { - killtail=1; /* we are moving to a different hit */ + killtail = 1; /* we are moving to a different hit */ if (!rset_forward(p->items[i].fd, p->items[i].buf, &p->items[i].term, untilbuf)) { - p->eof=1; /* game over */ - p->tailcount=0; + p->eof = 1; /* game over */ + p->tailcount = 0; return 0; } } } if (killtail) { - for (i=0; ino_rsets;i++) - p->tailbits[i]=0; - p->tailcount=0; + for (i = 0; ino_rsets; i++) + p->tailbits[i] = 0; + p->tailcount = 0; } return r_read_and(rfd,buf,term); } static void r_pos (RSFD rfd, double *current, double *total) { - struct rset_multiandor_info *info= - (struct rset_multiandor_info *)(rfd->rset->priv); - struct rset_multiandor_rfd *mrfd=(struct rset_multiandor_rfd *)(rfd->priv); + struct rset_multiandor_info *info = + (struct rset_multiandor_info *)(rfd->rset->priv); + struct rset_multiandor_rfd *mrfd = + (struct rset_multiandor_rfd *)(rfd->priv); double cur, tot; - double scur=0.0, stot=0.0; + double scur = 0.0, stot = 0.0; int i; - for (i=0; ino_rsets; i++){ + for (i = 0; ino_rsets; i++){ rset_pos(mrfd->items[i].fd, &cur, &tot); yaz_log(log_level, "r_pos: %d %0.1f %0.1f", i, cur,tot); scur += cur; stot += tot; } - if (stot <1.0) { /* nothing there */ - *current=0; - *total=0; + if (stot < 1.0) { /* nothing there */ + *current = 0; + *total = 0; yaz_log(log_level, "r_pos: NULL %0.1f %0.1f", *current, *total); - return; } - *current=mrfd->hits; - *total=*current*stot/scur; - yaz_log(log_level, "r_pos: = %0.1f %0.1f", *current, *total); + else + { + *current = mrfd->hits; + *total = *current*stot/scur; + yaz_log(log_level, "r_pos: = %0.1f %0.1f", *current, *total); + } } - - static int r_write (RSFD rfd, const void *buf) { yaz_log (YLOG_FATAL, "multior set type is read-only"); @@ -603,12 +607,13 @@ static void r_get_terms(RSET ct, TERMID *terms, int maxterms, int *curterm) (struct rset_multiandor_info *) ct->priv; int firstterm= *curterm; int i; - for (i=0;ino_rsets;i++) + for (i = 0; ino_rsets; i++) { rset_getterms(info->rsets[i], terms, maxterms, curterm); - if ( ( (*curterm) > firstterm+1 ) && - ( (*curterm) <= maxterms ) && - ( terms[(*curterm)-1] == terms[firstterm] ) ) + if ( ( *curterm > firstterm+1 ) && + ( *curterm <= maxterms ) && + ( terms[(*curterm)-1] == terms[firstterm] ) + ) (*curterm)--; /* forget the term, seen that before */ } }