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