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