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