Examples using Bib-1 use attributes
[idzebra-moved-to-github.git] / rset / rsisams.c
1 /* This file is part of the Zebra server.
2    Copyright (C) Index Data
3
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19
20 #if HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 #include <stdio.h>
24 #include <assert.h>
25 #include <idzebra/util.h>
26 #include <rset.h>
27
28 static RSFD r_open (RSET ct, int flag);
29 static void r_close (RSFD rfd);
30 static void r_delete (RSET ct);
31 static int r_read (RSFD rfd, void *buf, TERMID *term);
32 static void r_pos (RSFD rfd, double *current, double *total);
33
34 static const struct rset_control control =
35 {
36     "isams",
37     r_delete,
38     rset_get_one_term,
39     r_open,
40     r_close,
41     0, /* no forward */
42     r_pos,
43     r_read,
44     rset_no_write,
45 };
46
47 struct rfd_private {
48     ISAMS_PP pt;
49 };
50
51 struct rset_private {
52     ISAMS   is;
53     ISAM_P pos;
54 };
55
56
57 RSET rsisams_create(NMEM nmem, struct rset_key_control *kcontrol,
58                     int scope,
59                     ISAMS is, ISAM_P pos, TERMID term)
60 {
61     RSET rnew = rset_create_base(&control, nmem, kcontrol, scope, term, 0, 0);
62     struct rset_private *info;
63     info = (struct rset_private *) nmem_malloc(rnew->nmem, sizeof(*info));
64     rnew->priv = info;
65     info->is = is;
66     info->pos = pos;
67     return rnew;
68 }
69
70 static void r_delete (RSET ct)
71 {
72     yaz_log (YLOG_DEBUG, "rsisams_delete");
73 }
74
75 RSFD r_open (RSET ct, int flag)
76 {
77     struct rset_private *info = (struct rset_private *) ct->priv;
78     RSFD rfd;
79     struct rfd_private *ptinfo;
80
81     yaz_log (YLOG_DEBUG, "risams_open");
82     if (flag & RSETF_WRITE)
83     {
84         yaz_log (YLOG_FATAL, "ISAMS set type is read-only");
85         return NULL;
86     }
87     rfd = rfd_create_base(ct);
88     if (rfd->priv)
89         ptinfo = (struct rfd_private *)(rfd->priv);
90     else {
91         ptinfo = (struct rfd_private *) nmem_malloc(ct->nmem,sizeof(*ptinfo));
92         rfd->priv = ptinfo;
93     }
94     ptinfo->pt = isams_pp_open (info->is, info->pos);
95     return rfd;
96 }
97
98 static void r_close (RSFD rfd)
99 {
100     struct rfd_private *ptinfo = (struct rfd_private *)(rfd->priv);
101
102     isams_pp_close (ptinfo->pt);
103 }
104
105
106 static int r_read (RSFD rfd, void *buf, TERMID *term)
107 {
108     struct rfd_private *ptinfo = (struct rfd_private *)(rfd->priv);
109     int rc = isams_pp_read(ptinfo->pt, buf);
110     if (rc && term)
111         *term = rfd->rset->term;
112     return rc;
113 }
114
115 static void r_pos (RSFD rfd, double *current, double *total)
116 {
117     *current=-1;  /* sorry, not implemented yet */
118     *total=-1;
119 }
120
121
122 /*
123  * Local variables:
124  * c-basic-offset: 4
125  * c-file-style: "Stroustrup"
126  * indent-tabs-mode: nil
127  * End:
128  * vim: shiftwidth=4 tabstop=8 expandtab
129  */
130