X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=rset%2Frsbetween.c;h=9c778be7810fddcb1963dc997627f683916a9dd5;hp=486954bd27daf73ec076bbf092f5de2b7893fefb;hb=4478d785b7769691261005c98063b98a5a5971b3;hpb=98912d364cb21abf4c2f3229d5578e2a3159f616 diff --git a/rset/rsbetween.c b/rset/rsbetween.c index 486954b..9c778be 100644 --- a/rset/rsbetween.c +++ b/rset/rsbetween.c @@ -1,5 +1,5 @@ -/* $Id: rsbetween.c,v 1.35 2005-01-15 20:47:16 adam Exp $ - Copyright (C) 1995-2005 +/* $Id: rsbetween.c,v 1.45 2006-08-14 10:40:21 adam Exp $ + Copyright (C) 1995-2006 Index Data ApS This file is part of the Zebra server. @@ -15,9 +15,9 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with Zebra; see the file LICENSE.zebra. If not, write to the -Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA -02111-1307, USA. +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ @@ -36,13 +36,13 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include -static RSFD r_open (RSET ct, int flag); -static void r_close (RSFD rfd); -static void r_delete (RSET ct); +static RSFD r_open(RSET ct, int flag); +static void r_close(RSFD rfd); +static void r_delete(RSET ct); static int r_forward(RSFD rfd, void *buf, TERMID *term, const void *untilbuf); static int r_read(RSFD rfd, void *buf, TERMID *term ); @@ -63,16 +63,12 @@ static const struct rset_control control = r_write, }; - -const struct rset_control *rset_kind_between = &control; - #define STARTTAG 0 #define HIT 1 #define STOPTAG 2 #define ATTRTAG 3 struct rset_between_info { - RSET andset; /* the multi-and of the above */ TERMID startterm; /* pseudo terms for detecting which one we read from */ TERMID stopterm; TERMID attrterm; @@ -96,22 +92,21 @@ static int log_level_initialized = 0; /* make sure that the rset has a term attached. If not, create one */ /* we need these terms for the tags, to distinguish what we read */ -static void checkterm( RSET rs, char *tag, NMEM nmem) +static void checkterm(RSET rs, char *tag, NMEM nmem) { if (!rs->term) { - rs->term= - rset_term_create(tag,strlen(tag),"",0,nmem); + rs->term = rset_term_create(tag, -1, "", 0, nmem, 0, 0, 0, 0); rs->term->rset = rs; } } -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 rset_create_between(NMEM nmem, struct rset_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, 0, 0); struct rset_between_info *info= (struct rset_between_info *) nmem_malloc(rnew->nmem,sizeof(*info)); RSET rsetarray[4]; @@ -128,14 +123,14 @@ RSET rsbetween_create( NMEM nmem, const struct key_control *kcontrol, rsetarray[ATTRTAG] = rset_attr; /* make sure we have decent terms for all rsets. Create dummies if needed*/ - checkterm( rsetarray[STARTTAG], "(start)",nmem); - checkterm( rsetarray[STOPTAG], "(start)",nmem); + checkterm(rsetarray[STARTTAG], "(start)", nmem); + checkterm(rsetarray[STOPTAG], "(start)", nmem); info->startterm = rsetarray[STARTTAG]->term; info->stopterm = rsetarray[STOPTAG]->term; if (rset_attr) { - checkterm( rsetarray[ATTRTAG], "(start)",nmem); + checkterm(rsetarray[ATTRTAG], "(start)", nmem); info->attrterm = rsetarray[ATTRTAG]->term; n = 4; } @@ -144,30 +139,28 @@ RSET rsbetween_create( NMEM nmem, const struct key_control *kcontrol, info->attrterm = NULL; n = 3; } - info->andset = rsmulti_and_create( nmem, kcontrol, scope, n, rsetarray); + rnew->no_children = 1; + rnew->children = nmem_malloc(rnew->nmem, sizeof(RSET *)); + rnew->children[0] = rset_create_and(nmem, kcontrol, + scope, n, rsetarray); rnew->priv = info; - yaz_log(log_level,"create rset at %p",rnew); + yaz_log(log_level, "create rset at %p", rnew); return rnew; } - -static void r_delete (RSET ct) +static void r_delete(RSET ct) { - struct rset_between_info *info = (struct rset_between_info *) ct->priv; - yaz_log(log_level,"delete rset at %p",ct); - rset_delete(info->andset); } -static RSFD r_open (RSET ct, int flag) +static RSFD r_open(RSET ct, int flag) { - struct rset_between_info *info = (struct rset_between_info *) ct->priv; RSFD rfd; struct rset_between_rfd *p; if (flag & RSETF_WRITE) { - yaz_log (YLOG_FATAL, "between set type is read-only"); + yaz_log(YLOG_FATAL, "between set type is read-only"); return NULL; } rfd = rfd_create_base(ct); @@ -176,30 +169,27 @@ static RSFD r_open (RSET ct, int flag) else { p = (struct rset_between_rfd *) nmem_malloc(ct->nmem, (sizeof(*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->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->andrfd = rset_open(ct->children[0], RSETF_READ); + p->hits = -1; p->depth = 0; p->attrdepth = 0; p->attrbufok = 0; p->startbufok = 0; - yaz_log(log_level,"open rset=%p rfd=%p", ct, rfd); + yaz_log(log_level, "open rset=%p rfd=%p", ct, rfd); return rfd; } -static void r_close (RSFD rfd) +static void r_close(RSFD rfd) { struct rset_between_rfd *p=(struct rset_between_rfd *)rfd->priv; yaz_log(log_level,"close rfd=%p", rfd); - rset_close (p->andrfd); - rfd_delete_base(rfd); + rset_close(p->andrfd); } - - static int r_forward(RSFD rfd, void *buf, TERMID *term, const void *untilbuf) { @@ -210,13 +200,12 @@ static int r_forward(RSFD rfd, void *buf, return rc; } - - 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; + 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 rset_key_control *kctrl = rfd->rset->keycontrol; int cmp; if (p->attrdepth) return; /* already found one */ @@ -236,47 +225,47 @@ static void checkattr(RSFD rfd) } } - -static int r_read (RSFD rfd, void *buf, TERMID *term) +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; + 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 rset_key_control *kctrl = rfd->rset->keycontrol; int cmp; TERMID dummyterm = 0; - yaz_log(log_level,"== read: term=%p",term); + yaz_log(log_level, "== read: term=%p",term); if (!term) - term=&dummyterm; - while ( rset_read(p->andrfd,buf,term) ) + term = &dummyterm; + while (rset_read(p->andrfd, buf, term)) { yaz_log(log_level,"read loop term=%p d=%d ad=%d", - *term,p->depth, p->attrdepth); + *term, p->depth, p->attrdepth); if (p->hits<0) {/* first time? */ - memcpy(p->recbuf,buf,kctrl->key_size); + memcpy(p->recbuf, buf, kctrl->key_size); p->hits = 0; cmp = rfd->rset->scope; /* force newrecord */ } else { - cmp=(kctrl->cmp)(buf,p->recbuf); - yaz_log(log_level, "cmp=%d",cmp); + cmp = (kctrl->cmp)(buf, p->recbuf); + yaz_log(log_level, "cmp=%d", cmp); } if (cmp>=rfd->rset->scope) { - yaz_log(log_level,"new record"); + yaz_log(log_level, "new record"); p->depth = 0; p->attrdepth = 0; - memcpy(p->recbuf,buf,kctrl->key_size); + memcpy(p->recbuf, buf, kctrl->key_size); } if (*term) - yaz_log(log_level," term: '%s'", (*term)->name); + yaz_log(log_level, " term: '%s'", (*term)->name); if (*term==info->startterm) { p->depth++; - yaz_log(log_level,"read start tag. d=%d",p->depth); - memcpy(p->startbuf,buf,kctrl->key_size); + yaz_log(log_level, "read start tag. d=%d", p->depth); + memcpy(p->startbuf, buf, kctrl->key_size); p->startbufok = 1; checkattr(rfd); /* in case we already saw the attr here */ } @@ -285,12 +274,13 @@ static int r_read (RSFD rfd, void *buf, TERMID *term) if (p->depth == p->attrdepth) 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); + yaz_log(log_level,"read end tag. d=%d ad=%d", p->depth, + p->attrdepth); } else if (*term==info->attrterm) { yaz_log(log_level,"read attr"); - memcpy(p->attrbuf,buf,kctrl->key_size); + memcpy(p->attrbuf, buf, kctrl->key_size); p->attrbufok = 1; checkattr(rfd); /* in case the start tag came first */ } @@ -300,11 +290,11 @@ static int r_read (RSFD rfd, void *buf, TERMID *term) { p->hits++; yaz_log(log_level,"got a hit h="ZINT_FORMAT" d=%d ad=%d", - p->hits,p->depth,p->attrdepth); + p->hits, p->depth, p->attrdepth); return 1; /* we have everything in place already! */ } else yaz_log(log_level, "Ignoring hit. h="ZINT_FORMAT" d=%d ad=%d", - p->hits,p->depth,p->attrdepth); + p->hits, p->depth, p->attrdepth); } } /* while read */ @@ -313,24 +303,31 @@ static int r_read (RSFD rfd, void *buf, TERMID *term) } /* r_read */ -static int r_write (RSFD rfd, const void *buf) +static int r_write(RSFD rfd, const void *buf) { - yaz_log (YLOG_FATAL, "between set type is read-only"); + yaz_log(YLOG_FATAL, "between set type is read-only"); return -1; } -static void r_pos (RSFD rfd, double *current, double *total) +static void r_pos(RSFD rfd, double *current, double *total) { struct rset_between_rfd *p=(struct rset_between_rfd *)rfd->priv; - rset_pos(p->andrfd,current, total); - yaz_log(log_level,"pos: %0.1f/%0.1f ", *current, *total); + rset_pos(p->andrfd, current, total); + yaz_log(log_level, "pos: %0.1f/%0.1f ", *current, *total); } 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->andset, terms, maxterms, curterm); + rset_getterms(ct->children[0], terms, maxterms, curterm); } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +