Minor changes.
[idzebra-moved-to-github.git] / rset / rsisam.c
1 /*
2  * Copyright (C) 1994, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: rsisam.c,v $
7  * Revision 1.4  1995-09-04 09:10:55  adam
8  * Minor changes.
9  *
10  * Revision 1.3  1994/11/22  13:15:37  quinn
11  * Simple
12  *
13  * Revision 1.2  1994/11/04  14:53:12  quinn
14  * Work
15  *
16  */
17
18 /* TODO: Memory management
19    LINK DELETE TO CLOSE!  */
20
21 #include <rsisam.h>
22 #include <util.h>
23
24 static rset_control *r_create(const struct rset_control *sel, void *parms);
25 static int r_open(rset_control *ct, int wflag);
26 static void r_close(rset_control *ct);
27 static void r_delete(rset_control *ct);
28 static void r_rewind(rset_control *ct);
29 static int r_count(rset_control *ct);
30 static int r_read();
31 static int r_write();
32
33 static const rset_control control = 
34 {
35     "ISAM set type",
36     0,
37     r_create,
38     r_open,
39     r_close,
40     r_delete,
41     r_rewind,
42     r_count,
43     r_read,
44     r_write
45 };
46
47 const rset_control *rset_kind_isam = &control;
48
49 static rset_control *r_create(const struct rset_control *sel, void *parms)
50 {
51     rset_control *newct;
52     rset_isam_parms *pt = parms;
53
54     log(LOG_DEBUG, "risam_create(%s)", sel->desc);
55     newct = xmalloc(sizeof(*newct));
56     memcpy(newct, sel, sizeof(*sel));
57     if (!(newct->buf = (char*) is_position(pt->is, pt->pos)))
58         return 0;
59     return newct;
60 }
61
62 static int r_open(rset_control *ct, int wflag)
63 {
64     log(LOG_DEBUG, "risam_open");
65     if (wflag)
66     {
67         log(LOG_FATAL, "ISAM set type is read-only");
68         return -1;
69     }
70     r_rewind(ct);
71     return 0;
72 }
73
74 static void r_close(rset_control *ct)
75 {
76     /* NOP */
77 }
78
79 static void r_delete(rset_control *ct)
80 {
81     log(LOG_DEBUG, "risam_delete");
82     is_pt_free((ISPT) ct->buf);
83     xfree(ct);
84 }
85
86 static void r_rewind(rset_control *ct)
87 {
88     log(LOG_DEBUG, "risam_rewind");
89     is_rewind((ISPT) ct->buf);
90 }
91
92 static int r_count(rset_control *ct)
93 {return 0;}
94
95 static int r_read(rset_control *ct, void *buf)
96 {
97     return is_readkey((ISPT) ct->buf, buf);
98 }
99
100 static int r_write()
101 {
102     log(LOG_FATAL, "ISAM set type is read-only");
103     return -1;
104 }