Compressed isam fully supported.
[idzebra-moved-to-github.git] / rset / rsisamc.c
1 /*
2  * Copyright (C) 1994-1996, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: rsisamc.c,v $
7  * Revision 1.2  1996-11-08 11:15:57  adam
8  * Compressed isam fully supported.
9  *
10  * Revision 1.1  1996/10/29 13:41:48  adam
11  * First use of isamc.
12  *
13  */
14
15 #include <stdio.h>
16 #include <assert.h>
17 #include <rsisamc.h>
18 #include <zebrautl.h>
19
20 static void *r_create(const struct rset_control *sel, void *parms,
21                       int *flags);
22 static RSFD r_open (RSET ct, int flag);
23 static void r_close (RSFD rfd);
24 static void r_delete (RSET ct);
25 static void r_rewind (RSFD rfd);
26 static int r_count (RSET ct);
27 static int r_read (RSFD rfd, void *buf);
28 static int r_write (RSFD rfd, const void *buf);
29 static int r_score (RSFD rfd, int *score);
30
31 static const rset_control control = 
32 {
33     "isamc",
34     r_create,
35     r_open,
36     r_close,
37     r_delete,
38     r_rewind,
39     r_count,
40     r_read,
41     r_write,
42     r_score
43 };
44
45 const rset_control *rset_kind_isamc = &control;
46
47 struct rset_pp_info {
48     ISAMC_PP pt;
49     struct rset_pp_info *next;
50     struct rset_isamc_info *info;
51 };
52
53 struct rset_isamc_info {
54     ISAMC   is;
55     ISAMC_P pos;
56     struct rset_pp_info *ispt_list;
57 };
58
59 static void *r_create(const struct rset_control *sel, void *parms,
60                       int *flags)
61 {
62     rset_isamc_parms *pt = parms;
63     struct rset_isamc_info *info;
64
65     *flags |= RSET_FLAG_VOLATILE;
66     info = xmalloc (sizeof(*info));
67     info->is = pt->is;
68     info->pos = pt->pos;
69     info->ispt_list = NULL;
70     return info;
71 }
72
73 RSFD r_open (RSET ct, int flag)
74 {
75     struct rset_isamc_info *info = ct->buf;
76     struct rset_pp_info *ptinfo;
77
78     logf (LOG_DEBUG, "risamc_open");
79     if (flag & RSETF_WRITE)
80     {
81         logf (LOG_FATAL, "ISAMC set type is read-only");
82         return NULL;
83     }
84     ptinfo = xmalloc (sizeof(*ptinfo));
85     ptinfo->next = info->ispt_list;
86     info->ispt_list = ptinfo;
87     ptinfo->pt = isc_pp_open (info->is, info->pos);
88     ptinfo->info = info;
89     return ptinfo;
90 }
91
92 static void r_close (RSFD rfd)
93 {
94     struct rset_isamc_info *info = ((struct rset_pp_info*) rfd)->info;
95     struct rset_pp_info **ptinfop;
96
97     for (ptinfop = &info->ispt_list; *ptinfop; ptinfop = &(*ptinfop)->next)
98         if (*ptinfop == rfd)
99         {
100             isc_pp_close ((*ptinfop)->pt);
101             *ptinfop = (*ptinfop)->next;
102             free (rfd);
103             return;
104         }
105     logf (LOG_FATAL, "r_close but no rfd match!");
106     assert (0);
107 }
108
109 static void r_delete (RSET ct)
110 {
111     struct rset_isamc_info *info = ct->buf;
112
113     logf (LOG_DEBUG, "rsisamc_delete");
114     assert (info->ispt_list == NULL);
115     xfree (info);
116 }
117
118 static void r_rewind (RSFD rfd)
119 {   
120     logf (LOG_DEBUG, "rsisamc_rewind");
121     abort ();
122 }
123
124 static int r_count (RSET ct)
125 {
126     return 0;
127 }
128
129 static int r_read (RSFD rfd, void *buf)
130 {
131     return isc_pp_read( ((struct rset_pp_info*) rfd)->pt, buf);
132 }
133
134 static int r_write (RSFD rfd, const void *buf)
135 {
136     logf (LOG_FATAL, "ISAMC set type is read-only");
137     return -1;
138 }
139
140 static int r_score (RSFD rfd, int *score)
141 {
142     *score = -1;
143     return -1;
144 }