+
+static void r_pos_between (RSFD rfd, double *current, double *total)
+{
+ struct rset_between_rfd *p=(struct rset_between_rfd *)rfd->priv;
+ double lcur,ltot;
+ double mcur,mtot;
+ double rcur,rtot;
+ double r;
+ ltot=-1; rtot=-1;
+ rset_pos(p->rfd_l, &lcur, <ot);
+ rset_pos(p->rfd_m, &mcur, &mtot);
+ rset_pos(p->rfd_r, &rcur, &rtot);
+ if ( (ltot<0) && (mtot<0) && (rtot<0) ) { /*no position */
+ *current=mcur; /* return same as you got */
+ *total=mtot; /* probably -1 for not available */
+ }
+ if ( ltot<0) { ltot=0; lcur=0;} /* if only one useful, use it */
+ if ( mtot<0) { mtot=0; mcur=0;}
+ if ( rtot<0) { rtot=0; rcur=0;}
+ if ( ltot+mtot+rtot < 1 ) { /* empty rset */
+ *current=0;
+ *total=0;
+ return;
+ }
+ r=1.0*(lcur+mcur+rcur)/(ltot+mtot+rtot); /* weighed average of l and r */
+ *current=p->hits;
+ *total=*current/r ;
+#if RSBETWEEN_DEBUG
+ {
+ struct rset_between_info *info =(struct rset_between_info *)rfd->rset->priv;
+ yaz_log(LOG_LOG,"betw_pos: (%s/%s) %0.1f/%0.1f= %0.4f ",
+ info->rset_l->control->desc, info->rset_r->control->desc,
+ *current, *total, r);
+ }
+#endif
+}
+
+static void r_get_terms(RSET ct, TERMID *terms, int maxterms, int *curterm)
+{
+ struct rset_between_info *info = (struct rset_between_info *) ct->priv;
+ rset_getterms(info->rset_m, terms, maxterms, curterm);
+}
+
+/* Better algorithm
+ * One of the major problems with rsbetween is the complexity of keeping track
+ * of start tags, stop tags, hits, and attributes, together with record
+ * boundaries etc.
+ *
+ * Things can be divided into finding the right records, and then processing
+ * hits inside the record.
+ *
+ * Finding the record is mostly a matter of forwarding until we have a start
+ * tag and a hit in the same record.
+ *
+ * Handling stuff inside a record, we can simplify things by implementing a
+ * glorified OR operator that returns all the occurrences in proper order,
+ * together with info on what type it was. Then the main logic can just keep
+ * reading, and consider each type separately:
+ * - if a start tag, increment level (some trickery with attributes!)
+ * - if a stop tag, decrement level
+ * - if a hit, and we have a level, return it
+ * - if a hit, but no level, ignore it
+ *
+ * The attributes can be detected when ever reading start tags. The main
+ * routine needs to keep a stack of attribute match bits, so when ever we read
+ * a start tag, we must report back if we have a matching attribute or not.
+ *
+ */
+