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