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