X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=rset%2Frstemp.c;h=e32822b2e66b949c37898060bc69897ce3aaeacd;hp=0ab65fcf62865eb0dc8137a799a2f163b8875c43;hb=896c0427df9d8eff5de6a1735dcd992e067df844;hpb=7e75317bed8eecabcb57e59b16093a32238738e2 diff --git a/rset/rstemp.c b/rset/rstemp.c index 0ab65fc..e32822b 100644 --- a/rset/rstemp.c +++ b/rset/rstemp.c @@ -1,10 +1,26 @@ -/* - * Copyright (C) 1994-2002, Index Data - * All rights reserved. - * Sebastian Hammer, Adam Dickmeiss - * - * $Id: rstemp.c,v 1.27 2002-02-20 17:30:01 adam Exp $ - */ +/* $Id: rstemp.c,v 1.33 2002-08-02 19:26:57 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 + Index Data Aps + +This file is part of the Zebra server. + +Zebra is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +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. +*/ + + #include #include @@ -57,11 +73,14 @@ struct rset_temp_info { int dirty; /* window is dirty */ int hits; /* no of hits */ char *temp_path; + int (*cmp)(const void *p1, const void *p2); }; struct rset_temp_rfd { struct rset_temp_info *info; struct rset_temp_rfd *next; + int *countp; + void *buf; }; static void *r_create(RSET ct, const struct rset_control *sel, void *parms) @@ -80,6 +99,7 @@ static void *r_create(RSET ct, const struct rset_control *sel, void *parms) info->pos_buf = 0; info->dirty = 0; info->hits = -1; + info->cmp = temp_parms->cmp; if (!temp_parms->temp_path) info->temp_path = NULL; else @@ -90,6 +110,7 @@ static void *r_create(RSET ct, const struct rset_control *sel, void *parms) ct->no_rset_terms = 1; ct->rset_terms = (RSET_TERM *) xmalloc (sizeof(*ct->rset_terms)); ct->rset_terms[0] = temp_parms->rset_term; + return info; } @@ -114,6 +135,10 @@ static RSFD r_open (RSET ct, int flag) rfd = (struct rset_temp_rfd *) xmalloc (sizeof(*rfd)); rfd->info = info; r_rewind (rfd); + + rfd->countp = &ct->rset_terms[0]->count; + rfd->buf = xmalloc (info->key_size); + return rfd; } @@ -126,10 +151,13 @@ static void r_flush (RSFD rfd, int mk) if (!info->fname && mk) { -#if 1 +#if HAVE_MKSTEMP char template[1024]; - sprintf (template, "%s/zrsXXXXXX", info->temp_path); + if (info->temp_path) + sprintf (template, "%s/zrsXXXXXX", info->temp_path); + else + sprintf (template, "zrsXXXXXX"); info->fd = mkstemp (template); @@ -190,6 +218,7 @@ static void r_close (RSFD rfd) close (info->fd); info->fd = -1; } + xfree (((struct rset_temp_rfd *)rfd)->buf); xfree (rfd); } @@ -272,7 +301,8 @@ static int r_count (RSET ct) static int r_read (RSFD rfd, void *buf, int *term_index) { - struct rset_temp_info *info = ((struct rset_temp_rfd*)rfd)->info; + struct rset_temp_rfd *mrfd = (struct rset_temp_rfd*) rfd; + struct rset_temp_info *info = mrfd->info; size_t nc = info->pos_cur + info->key_size; @@ -288,6 +318,12 @@ static int r_read (RSFD rfd, void *buf, int *term_index) info->key_size); info->pos_cur = nc; *term_index = 0; + + if (*mrfd->countp == 0 || (*info->cmp)(buf, mrfd->buf) > 1) + { + memcpy (mrfd->buf, buf, mrfd->info->key_size); + (*mrfd->countp)++; + } return 1; }