More work on boolean sets.
[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.8  1995-09-06 16:11:56  adam
8  * More work on boolean sets.
9  *
10  * Revision 1.7  1995/09/06  10:35:44  adam
11  * Null set implemented.
12  *
13  * Revision 1.6  1995/09/05  11:43:24  adam
14  * Complete version of temporary sets. Not tested yet though.
15  *
16  * Revision 1.5  1995/09/04  12:33:56  adam
17  * Various cleanup. YAZ util used instead.
18  *
19  * Revision 1.4  1995/09/04  09:10:55  adam
20  * Minor changes.
21  *
22  * Revision 1.3  1994/11/22  13:15:37  quinn
23  * Simple
24  *
25  * Revision 1.2  1994/11/04  14:53:12  quinn
26  * Work
27  *
28  */
29
30 #include <stdio.h>
31 #include <rsisam.h>
32 #include <alexutil.h>
33
34 static rset_control *r_create(const struct rset_control *sel, void *parms);
35 static int r_open (rset_control *ct, int wflag);
36 static void r_close (rset_control *ct);
37 static void r_delete (rset_control *ct);
38 static void r_rewind (rset_control *ct);
39 static int r_count (rset_control *ct);
40 static int r_read (rset_control *ct, void *buf);
41 static int r_write (rset_control *ct, const void *buf);
42
43 static const rset_control control = 
44 {
45     "ISAM set type",
46     0,
47     r_create,
48     r_open,
49     r_close,
50     r_delete,
51     r_rewind,
52     r_count,
53     r_read,
54     r_write
55 };
56
57 const rset_control *rset_kind_isam = &control;
58
59 static rset_control *r_create(const struct rset_control *sel, void *parms)
60 {
61     rset_control *newct;
62     rset_isam_parms *pt = parms;
63
64     logf (LOG_DEBUG, "rsisam_create(%s)", sel->desc);
65     newct = xmalloc(sizeof(*newct));
66     memcpy(newct, sel, sizeof(*sel));
67     if (!(newct->buf = (char*) is_position(pt->is, pt->pos)))
68         return 0;
69     return newct;
70 }
71
72 static int r_open(rset_control *ct, int wflag)
73 {
74     logf (LOG_DEBUG, "risam_open");
75     if (wflag)
76     {
77         logf (LOG_FATAL, "ISAM set type is read-only");
78         return -1;
79     }
80     r_rewind(ct);
81     return 0;
82 }
83
84 static void r_close(rset_control *ct)
85 {
86     /* NOP */
87 }
88
89 static void r_delete(rset_control *ct)
90 {
91     logf (LOG_DEBUG, "rsisam_delete");
92     is_pt_free((ISPT) ct->buf);
93     xfree(ct);
94 }
95
96 static void r_rewind(rset_control *ct)
97 {
98     logf (LOG_DEBUG, "rsisam_rewind");
99     is_rewind((ISPT) ct->buf);
100 }
101
102 static int r_count (rset_control *ct)
103 {
104     return 0;
105 }
106
107 static int r_read (rset_control *ct, void *buf)
108 {
109     return is_readkey((ISPT) ct->buf, buf);
110 }
111
112 static int r_write (rset_control *ct, const void *buf)
113 {
114     logf (LOG_FATAL, "ISAM set type is read-only");
115     return -1;
116 }