1 /* $Id: rset.c,v 1.21 2004-08-03 14:54:41 heikki Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
31 #include <../index/index.h> /* for log_keydump. Debugging only */
33 RSET rset_create(const struct rset_control *sel, void *parms)
38 logf (LOG_DEBUG, "rs_create(%s)", sel->desc);
39 rnew = (RSET) xmalloc(sizeof(*rnew));
43 rnew->rset_terms = NULL;
44 rnew->no_rset_terms = 0;
45 rnew->buf = (*sel->f_create)(rnew, sel, parms);
46 logf (LOG_DEBUG, "no_rset_terms: %d", rnew->no_rset_terms);
47 for (i = 0; i<rnew->no_rset_terms; i++)
48 logf (LOG_DEBUG, " %s", rnew->rset_terms[i]->name);
52 void rset_delete (RSET rs)
57 (*rs->control->f_delete)(rs);
62 RSET rset_dup (RSET rs)
68 void rset_default_pos (RSFD rfd, int *current, int *total)
69 { /* FIXME - This function should not be needed, only while */
70 /* coding the pos functions. */
74 *current=-1; /* signal that pos is not implemented */
76 } /* rset_default_pos */
78 int rset_default_forward(RSET ct, RSFD rfd, void *buf, int *term_index,
79 int (*cmpfunc)(const void *p1, const void *p2),
84 logf (LOG_DEBUG, "rset_default_forward starting '%s' (ct=%p rfd=%p)",
85 ct->control->desc, ct,rfd);
86 key_logdump(LOG_DEBUG, untilbuf);
87 while ( (cmp==2) && (more))
89 logf (LOG_DEBUG, "rset_default_forward looping m=%d c=%d",more,cmp);
90 more=rset_read(ct, rfd, buf, term_index);
92 cmp=(*cmpfunc)(untilbuf,buf);
94 key_logdump(LOG_DEBUG,buf);
96 logf (LOG_DEBUG, "rset_default_forward exiting m=%d c=%d",more,cmp);
101 RSET_TERM *rset_terms(RSET rs, int *no)
103 *no = rs->no_rset_terms;
104 return rs->rset_terms;
107 RSET_TERM rset_term_create (const char *name, int length, const char *flags,
110 RSET_TERM t = (RSET_TERM) xmalloc (sizeof(*t));
113 else if (length == -1)
114 t->name = xstrdup (name);
117 t->name = (char*) xmalloc (length+1);
118 memcpy (t->name, name, length);
119 t->name[length] = '\0';
124 t->flags = xstrdup (flags);
131 void rset_term_destroy (RSET_TERM t)
138 RSET_TERM rset_term_dup (RSET_TERM t)
140 RSET_TERM nt = (RSET_TERM) xmalloc (sizeof(*nt));
142 nt->name = xstrdup (t->name);
146 nt->flags = xstrdup (t->flags);