Function rset_open changed its wflag parameter to general flags.
[idzebra-moved-to-github.git] / rset / rsisam.c
1 /*
2  * Copyright (C) 1994-1995, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: rsisam.c,v $
7  * Revision 1.12  1995-10-10 14:00:04  adam
8  * Function rset_open changed its wflag parameter to general flags.
9  *
10  * Revision 1.11  1995/10/06  14:38:05  adam
11  * New result set method: r_score.
12  * Local no (sysno) and score is transferred to retrieveCtrl.
13  *
14  * Revision 1.10  1995/09/08  14:52:42  adam
15  * Work on relevance feedback.
16  *
17  * Revision 1.9  1995/09/07  13:58:43  adam
18  * New parameter: result-set file descriptor (RSFD) to support multiple
19  * positions within the same result-set.
20  * Boolean operators: and, or, not implemented.
21  *
22  * Revision 1.8  1995/09/06  16:11:56  adam
23  * More work on boolean sets.
24  *
25  * Revision 1.7  1995/09/06  10:35:44  adam
26  * Null set implemented.
27  *
28  * Revision 1.6  1995/09/05  11:43:24  adam
29  * Complete version of temporary sets. Not tested yet though.
30  *
31  * Revision 1.5  1995/09/04  12:33:56  adam
32  * Various cleanup. YAZ util used instead.
33  *
34  * Revision 1.4  1995/09/04  09:10:55  adam
35  * Minor changes.
36  *
37  * Revision 1.3  1994/11/22  13:15:37  quinn
38  * Simple
39  *
40  * Revision 1.2  1994/11/04  14:53:12  quinn
41  * Work
42  *
43  */
44
45 #include <stdio.h>
46 #include <assert.h>
47 #include <rsisam.h>
48 #include <alexutil.h>
49
50 static rset_control *r_create(const struct rset_control *sel, void *parms);
51 static RSFD r_open (rset_control *ct, int flag);
52 static void r_close (RSFD rfd);
53 static void r_delete (rset_control *ct);
54 static void r_rewind (RSFD rfd);
55 static int r_count (rset_control *ct);
56 static int r_read (RSFD rfd, void *buf);
57 static int r_write (RSFD rfd, const void *buf);
58 static int r_score (RSFD rfd, int *score);
59
60 static const rset_control control = 
61 {
62     "ISAM set type",
63     0,
64     r_create,
65     r_open,
66     r_close,
67     r_delete,
68     r_rewind,
69     r_count,
70     r_read,
71     r_write,
72     r_score
73 };
74
75 const rset_control *rset_kind_isam = &control;
76
77 struct rset_ispt_info {
78     ISPT   pt;
79     struct rset_ispt_info *next;
80     struct rset_isam_info *info;
81 };
82
83 struct rset_isam_info {
84     ISAM   is;
85     ISAM_P pos;
86     struct rset_ispt_info *ispt_list;
87 };
88
89 static rset_control *r_create(const struct rset_control *sel, void *parms)
90 {
91     rset_control *newct;
92     rset_isam_parms *pt = parms;
93     struct rset_isam_info *info;
94
95     newct = xmalloc(sizeof(*newct));
96     memcpy(newct, sel, sizeof(*sel));
97
98     if (!(newct->buf = xmalloc (sizeof(struct rset_isam_info))))
99         return 0;
100     info = newct->buf;
101     info->is = pt->is;
102     info->pos = pt->pos;
103     info->ispt_list = NULL;
104     return newct;
105 }
106
107 RSFD r_open (rset_control *ct, int flag)
108 {
109     struct rset_isam_info *info = ct->buf;
110     struct rset_ispt_info *ptinfo;
111
112     logf (LOG_DEBUG, "risam_open");
113     if (flag & RSETF_WRITE)
114     {
115         logf (LOG_FATAL, "ISAM set type is read-only");
116         return NULL;
117     }
118     ptinfo = xmalloc (sizeof(*ptinfo));
119     ptinfo->next = info->ispt_list;
120     info->ispt_list = ptinfo;
121     ptinfo->pt = is_position (info->is, info->pos);
122     ptinfo->info = info;
123     return ptinfo;
124 }
125
126 static void r_close (RSFD rfd)
127 {
128     struct rset_isam_info *info = ((struct rset_ispt_info*) rfd)->info;
129     struct rset_ispt_info **ptinfop;
130
131     for (ptinfop = &info->ispt_list; *ptinfop; ptinfop = &(*ptinfop)->next)
132         if (*ptinfop == rfd)
133         {
134             is_pt_free ((*ptinfop)->pt);
135             *ptinfop = (*ptinfop)->next;
136             free (rfd);
137             return;
138         }
139     logf (LOG_FATAL, "r_close but no rfd match!");
140     assert (0);
141 }
142
143 static void r_delete (rset_control *ct)
144 {
145     struct rset_isam_info *info = ct->buf;
146
147     logf (LOG_DEBUG, "rsisam_delete");
148     assert (info->ispt_list == NULL);
149     xfree (info);
150     xfree (ct);
151 }
152
153 static void r_rewind (RSFD rfd)
154 {   
155     logf (LOG_DEBUG, "rsisam_rewind");
156     is_rewind( ((struct rset_ispt_info*) rfd)->pt);
157 }
158
159 static int r_count (rset_control *ct)
160 {
161     return 0;
162 }
163
164 static int r_read (RSFD rfd, void *buf)
165 {
166     return is_readkey( ((struct rset_ispt_info*) rfd)->pt, buf);
167 }
168
169 static int r_write (RSFD rfd, const void *buf)
170 {
171     logf (LOG_FATAL, "ISAM set type is read-only");
172     return -1;
173 }
174
175 static int r_score (RSFD rfd, int *score)
176 {
177     *score = -1;
178     return -1;
179 }