C++ compilation.
[idzebra-moved-to-github.git] / rset / rsisamc.c
1 /*
2  * Copyright (C) 1994-1999, Index Data
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: rsisamc.c,v $
7  * Revision 1.7  1999-05-26 07:49:14  adam
8  * C++ compilation.
9  *
10  * Revision 1.6  1999/02/02 14:51:35  adam
11  * Updated WIN32 code specific sections. Changed header.
12  *
13  * Revision 1.5  1998/03/05 08:36:28  adam
14  * New result set model.
15  *
16  * Revision 1.4  1997/12/18 10:54:25  adam
17  * New method result set method rs_hits that returns the number of
18  * hits in result-set (if known). The ranked result set returns real
19  * number of hits but only when not combined with other operands.
20  *
21  * Revision 1.3  1997/10/31 12:37:01  adam
22  * Code calls xfree() instead of free().
23  *
24  * Revision 1.2  1996/11/08 11:15:57  adam
25  * Compressed isam fully supported.
26  *
27  * Revision 1.1  1996/10/29 13:41:48  adam
28  * First use of isamc.
29  *
30  */
31
32 #include <stdio.h>
33 #include <assert.h>
34 #include <rsisamc.h>
35 #include <zebrautl.h>
36
37 static void *r_create(RSET ct, const struct rset_control *sel, void *parms);
38 static RSFD r_open (RSET ct, int flag);
39 static void r_close (RSFD rfd);
40 static void r_delete (RSET ct);
41 static void r_rewind (RSFD rfd);
42 static int r_count (RSET ct);
43 static int r_read (RSFD rfd, void *buf, int *term_index);
44 static int r_write (RSFD rfd, const void *buf);
45
46 static const struct rset_control control = 
47 {
48     "isamc",
49     r_create,
50     r_open,
51     r_close,
52     r_delete,
53     r_rewind,
54     r_count,
55     r_read,
56     r_write,
57 };
58
59 const struct rset_control *rset_kind_isamc = &control;
60
61 struct rset_pp_info {
62     ISAMC_PP pt;
63     struct rset_pp_info *next;
64     struct rset_isamc_info *info;
65 };
66
67 struct rset_isamc_info {
68     ISAMC   is;
69     ISAMC_P pos;
70     struct rset_pp_info *ispt_list;
71 };
72
73 static void *r_create(RSET ct, const struct rset_control *sel, void *parms)
74 {
75     rset_isamc_parms *pt = (rset_isamc_parms *) parms;
76     struct rset_isamc_info *info;
77
78     ct->flags |= RSET_FLAG_VOLATILE;
79     info = (struct rset_isamc_info *) xmalloc (sizeof(*info));
80     info->is = pt->is;
81     info->pos = pt->pos;
82     info->ispt_list = NULL;
83     ct->no_rset_terms = 1;
84     ct->rset_terms = (RSET_TERM *) xmalloc (sizeof(*ct->rset_terms));
85     ct->rset_terms[0] = pt->rset_term;
86     return info;
87 }
88
89 RSFD r_open (RSET ct, int flag)
90 {
91     struct rset_isamc_info *info = (struct rset_isamc_info *) ct->buf;
92     struct rset_pp_info *ptinfo;
93
94     logf (LOG_DEBUG, "risamc_open");
95     if (flag & RSETF_WRITE)
96     {
97         logf (LOG_FATAL, "ISAMC set type is read-only");
98         return NULL;
99     }
100     ptinfo = (struct rset_pp_info *) xmalloc (sizeof(*ptinfo));
101     ptinfo->next = info->ispt_list;
102     info->ispt_list = ptinfo;
103     ptinfo->pt = isc_pp_open (info->is, info->pos);
104     ptinfo->info = info;
105     if (ct->rset_terms[0]->nn < 0)
106         ct->rset_terms[0]->nn = isc_pp_num (ptinfo->pt);
107     return ptinfo;
108 }
109
110 static void r_close (RSFD rfd)
111 {
112     struct rset_isamc_info *info = ((struct rset_pp_info*) rfd)->info;
113     struct rset_pp_info **ptinfop;
114
115     for (ptinfop = &info->ispt_list; *ptinfop; ptinfop = &(*ptinfop)->next)
116         if (*ptinfop == rfd)
117         {
118             isc_pp_close ((*ptinfop)->pt);
119             *ptinfop = (*ptinfop)->next;
120             xfree (rfd);
121             return;
122         }
123     logf (LOG_FATAL, "r_close but no rfd match!");
124     assert (0);
125 }
126
127 static void r_delete (RSET ct)
128 {
129     struct rset_isamc_info *info = (struct rset_isamc_info *) ct->buf;
130
131     logf (LOG_DEBUG, "rsisamc_delete");
132     assert (info->ispt_list == NULL);
133     rset_term_destroy (ct->rset_terms[0]);
134     xfree (ct->rset_terms);
135     xfree (info);
136 }
137
138 static void r_rewind (RSFD rfd)
139 {   
140     logf (LOG_DEBUG, "rsisamc_rewind");
141     abort ();
142 }
143
144 static int r_count (RSET ct)
145 {
146     return 0;
147 }
148
149 static int r_read (RSFD rfd, void *buf, int *term_index)
150 {
151     *term_index = 0;
152     return isc_pp_read( ((struct rset_pp_info*) rfd)->pt, buf);
153 }
154
155 static int r_write (RSFD rfd, const void *buf)
156 {
157     logf (LOG_FATAL, "ISAMC set type is read-only");
158     return -1;
159 }