2 * Copyright (C) 1994-2002, Index Data
5 * $Id: rsisamc.c,v 1.11 2002-04-05 08:46:26 adam Exp $
14 static void *r_create(RSET ct, const struct rset_control *sel, void *parms);
15 static RSFD r_open (RSET ct, int flag);
16 static void r_close (RSFD rfd);
17 static void r_delete (RSET ct);
18 static void r_rewind (RSFD rfd);
19 static int r_count (RSET ct);
20 static int r_read (RSFD rfd, void *buf, int *term_index);
21 static int r_write (RSFD rfd, const void *buf);
23 static const struct rset_control control =
36 const struct rset_control *rset_kind_isamc = &control;
40 struct rset_pp_info *next;
41 struct rset_isamc_info *info;
46 struct rset_isamc_info {
50 int (*cmp)(const void *p1, const void *p2);
51 struct rset_pp_info *ispt_list;
54 static void *r_create(RSET ct, const struct rset_control *sel, void *parms)
56 rset_isamc_parms *pt = (rset_isamc_parms *) parms;
57 struct rset_isamc_info *info;
59 ct->flags |= RSET_FLAG_VOLATILE;
60 info = (struct rset_isamc_info *) xmalloc (sizeof(*info));
63 info->key_size = pt->key_size;
65 info->ispt_list = NULL;
66 ct->no_rset_terms = 1;
67 ct->rset_terms = (RSET_TERM *) xmalloc (sizeof(*ct->rset_terms));
68 ct->rset_terms[0] = pt->rset_term;
72 RSFD r_open (RSET ct, int flag)
74 struct rset_isamc_info *info = (struct rset_isamc_info *) ct->buf;
75 struct rset_pp_info *ptinfo;
77 logf (LOG_DEBUG, "risamc_open");
78 if (flag & RSETF_WRITE)
80 logf (LOG_FATAL, "ISAMC set type is read-only");
83 ptinfo = (struct rset_pp_info *) xmalloc (sizeof(*ptinfo));
84 ptinfo->next = info->ispt_list;
85 info->ispt_list = ptinfo;
86 ptinfo->pt = isc_pp_open (info->is, info->pos);
88 if (ct->rset_terms[0]->nn < 0)
89 ct->rset_terms[0]->nn = isc_pp_num (ptinfo->pt);
90 ct->rset_terms[0]->count = 0;
91 ptinfo->countp = &ct->rset_terms[0]->count;
92 ptinfo->buf = xmalloc (info->key_size);
96 static void r_close (RSFD rfd)
98 struct rset_isamc_info *info = ((struct rset_pp_info*) rfd)->info;
99 struct rset_pp_info **ptinfop;
101 for (ptinfop = &info->ispt_list; *ptinfop; ptinfop = &(*ptinfop)->next)
104 xfree ((*ptinfop)->buf);
105 isc_pp_close ((*ptinfop)->pt);
106 *ptinfop = (*ptinfop)->next;
110 logf (LOG_FATAL, "r_close but no rfd match!");
114 static void r_delete (RSET ct)
116 struct rset_isamc_info *info = (struct rset_isamc_info *) ct->buf;
118 logf (LOG_DEBUG, "rsisamc_delete");
119 assert (info->ispt_list == NULL);
120 rset_term_destroy (ct->rset_terms[0]);
121 xfree (ct->rset_terms);
125 static void r_rewind (RSFD rfd)
127 logf (LOG_DEBUG, "rsisamc_rewind");
131 static int r_count (RSET ct)
136 static int r_read (RSFD rfd, void *buf, int *term_index)
138 struct rset_pp_info *pinfo = (struct rset_pp_info *) rfd;
141 r = isc_pp_read(pinfo->pt, buf);
144 if (*pinfo->countp == 0 || (*pinfo->info->cmp)(buf, pinfo->buf) > 1)
146 memcpy (pinfo->buf, buf, pinfo->info->key_size);
153 static int r_write (RSFD rfd, const void *buf)
155 logf (LOG_FATAL, "ISAMC set type is read-only");