Working.
[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.1  1994-11-04 13:21:29  quinn
8  * Working.
9  *
10  */
11
12 /* TODO: Memory management */
13
14 #include <rsisam.h>
15 #include <util.h>
16
17 rset_control *r_create(const struct rset_control *sel, void *parms);
18 static int r_open(rset_control *ct, int wflag);
19 static void r_close(rset_control *ct);
20 static void r_delete(rset_control *ct);
21 static void r_rewind(rset_control *ct);
22 static int r_count(rset_control *ct);
23 static int r_read();
24 static int r_write();
25
26 static const rset_control control = 
27 {
28     "ISAM set type",
29     0,
30     r_create,
31     r_open,
32     r_close,
33     r_delete,
34     r_rewind,
35     r_count,
36     r_read,
37     r_write
38 };
39
40 const rset_control *rset_kind_isam = &control;
41
42 rset_control *r_create(const struct rset_control *sel, void *parms)
43 {
44     rset_control *newct;
45     rset_isam_parms *pt = parms;
46
47     newct = xmalloc(sizeof(*newct));
48     if (!(newct->buf = (char*) is_position(pt->is, pt->pos)))
49         return 0;
50     return newct;
51 }
52
53 static int r_open(rset_control *ct, int wflag)
54 {
55     r_rewind(ct);
56     return 0;
57 }
58
59 static void r_close(rset_control *ct)
60 {
61     /* NOP */
62 }
63
64 static void r_delete(rset_control *ct)
65 {
66     is_pt_free((ISPT) ct->buf);
67     xfree(ct);
68 }
69
70 static void r_rewind(rset_control *ct)
71 {
72     is_rewind((ISPT) ct->buf);
73 }
74
75 static int r_count(rset_control *ct)
76 {return 0;}
77
78 static int r_read(rset_control *ct, void *buf)
79 {
80     return is_readkey((ISPT) ct->buf, buf);
81 }
82
83 static int r_write(rset_control *ct, const void *buf)
84 {
85     log(LOG_FATAL, "ISAM set type is read-only");
86     return -1;
87 }