More work on boolean sets.
[idzebra-moved-to-github.git] / rset / rsbool.c
1 /*
2  * Copyright (C) 1994-1995, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: rsbool.c,v $
7  * Revision 1.2  1995-09-06 16:11:55  adam
8  * More work on boolean sets.
9  *
10  * Revision 1.1  1995/09/06  13:27:15  adam
11  * New set type: bool. Not finished yet.
12  *
13  */
14
15 #include <stdio.h>
16 #include <rsbool.h>
17 #include <alexutil.h>
18
19 static rset_control *r_create(const struct rset_control *sel, void *parms);
20 static int r_open (rset_control *ct, int wflag);
21 static void r_close (rset_control *ct);
22 static void r_delete (rset_control *ct);
23 static void r_rewind (rset_control *ct);
24 static int r_count (rset_control *ct);
25 static int r_read (rset_control *ct, void *buf);
26 static int r_write (rset_control *ct, const void *buf);
27
28 static const rset_control control = 
29 {
30     "BOOL set type",
31     0,
32     r_create,
33     r_open,
34     r_close,
35     r_delete,
36     r_rewind,
37     r_count,
38     r_read,
39     r_write
40 };
41
42 const rset_control *rset_kind_bool = &control;
43
44 struct rset_bool_info {
45     int key_size;
46     int op;
47     RSET rset_l;
48     RSET rset_r;
49     int more_l;
50     int more_r;
51     void *buf_l;
52     void *buf_r;
53     int (*cmp)(const void *p1, const void *p2);
54 };
55
56 static rset_control *r_create(const struct rset_control *sel, void *parms)
57 {
58     rset_control *newct;
59     rset_bool_parms *bool_parms = parms;
60     struct rset_bool_info *info;
61
62     logf (LOG_DEBUG, "rsbool_create(%s)", sel->desc);
63     newct = xmalloc(sizeof(*newct));
64     memcpy (newct, sel, sizeof(*sel));
65     newct->buf = xmalloc (sizeof(struct rset_bool_info));
66     info = (struct rset_bool_info*) newct->buf;
67     info->key_size = bool_parms->key_size;
68     info->op = bool_parms->op;
69     info->rset_l = bool_parms->rset_l;
70     info->rset_r = bool_parms->rset_r;
71     info->cmp = bool_parms->cmp;
72     info->buf_l = xmalloc (info->key_size);
73     info->buf_r = xmalloc (info->key_size);
74     return newct;
75 }
76
77 static int r_open(rset_control *ct, int wflag)
78 {
79     struct rset_bool_info *info = ct->buf;
80
81     if (wflag)
82     {
83         logf (LOG_FATAL, "bool set type is read-only");
84         return -1;
85     }
86     rset_open (info->rset_l, wflag);
87     rset_open (info->rset_r, wflag);
88     info->more_l = rset_read (info->rset_l, info->buf_l);
89     info->more_r = rset_read (info->rset_r, info->buf_r);
90     return 0;
91 }
92
93 static void r_close(rset_control *ct)
94 {
95     struct rset_bool_info *info = ct->buf;
96
97     rset_close (info->rset_l);
98     rset_close (info->rset_r);
99 }
100
101 static void r_delete(rset_control *ct)
102 {
103     struct rset_bool_info *info = ct->buf;
104
105     rset_delete (info->rset_l);
106     rset_delete (info->rset_r);
107     xfree (info->buf_l);
108     xfree (info->buf_r);
109     xfree (ct->buf);
110     xfree (ct);
111 }
112
113 static void r_rewind(rset_control *ct)
114 {
115     struct rset_bool_info *info = ct->buf;
116
117     logf (LOG_DEBUG, "rsbool_rewind");
118     rset_rewind (info->rset_l);
119     rset_rewind (info->rset_r);
120 }
121
122 static int r_count (rset_control *ct)
123 {
124     return 0;
125 }
126
127 static int r_read (rset_control *ct, void *buf)
128 {
129     struct rset_bool_info *info = ct->buf;
130
131     if (!info->more_l && !info->more_r)
132         return 0;
133     return 0;
134 }
135
136 static int r_write (rset_control *ct, const void *buf)
137 {
138     logf (LOG_FATAL, "bool set type is read-only");
139     return -1;
140 }