Simple
[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.3  1994-11-22 13:15:37  quinn
8  * Simple
9  *
10  * Revision 1.2  1994/11/04  14:53:12  quinn
11  * Work
12  *
13  */
14
15 /* TODO: Memory management
16    LINK DELETE TO CLOSE!  */
17
18 #include <rsisam.h>
19 #include <util.h>
20
21 rset_control *r_create(const struct rset_control *sel, void *parms);
22 static int r_open(rset_control *ct, int wflag);
23 static void r_close(rset_control *ct);
24 static void r_delete(rset_control *ct);
25 static void r_rewind(rset_control *ct);
26 static int r_count(rset_control *ct);
27 static int r_read();
28 static int r_write();
29
30 static const rset_control control = 
31 {
32     "ISAM set type",
33     0,
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 };
43
44 const rset_control *rset_kind_isam = &control;
45
46 rset_control *r_create(const struct rset_control *sel, void *parms)
47 {
48     rset_control *newct;
49     rset_isam_parms *pt = parms;
50
51     log(LOG_DEBUG, "risam_create(%s)", sel->desc);
52     newct = xmalloc(sizeof(*newct));
53     memcpy(newct, sel, sizeof(*sel));
54     if (!(newct->buf = (char*) is_position(pt->is, pt->pos)))
55         return 0;
56     return newct;
57 }
58
59 static int r_open(rset_control *ct, int wflag)
60 {
61     log(LOG_DEBUG, "risam_open");
62     if (wflag)
63     {
64         log(LOG_FATAL, "ISAM set type is read-only");
65         return -1;
66     }
67     r_rewind(ct);
68     return 0;
69 }
70
71 static void r_close(rset_control *ct)
72 {
73     /* NOP */
74 }
75
76 static void r_delete(rset_control *ct)
77 {
78     log(LOG_DEBUG, "risam_delete");
79     is_pt_free((ISPT) ct->buf);
80     xfree(ct);
81 }
82
83 static void r_rewind(rset_control *ct)
84 {
85     log(LOG_DEBUG, "risam_rewind");
86     is_rewind((ISPT) ct->buf);
87 }
88
89 static int r_count(rset_control *ct)
90 {return 0;}
91
92 static int r_read(rset_control *ct, void *buf)
93 {
94     return is_readkey((ISPT) ct->buf, buf);
95 }
96
97 static int r_write()
98 {
99     log(LOG_FATAL, "ISAM set type is read-only");
100     return -1;
101 }