Happy new year.
[idzebra-moved-to-github.git] / rset / rsnull.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1994-2011 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 #include <stdio.h>
21 #include <assert.h>
22 #include <idzebra/util.h>
23 #include <rset.h>
24
25 static RSFD r_open(RSET ct, int flag);
26 static void r_close(RSFD rfd);
27 static void r_delete(RSET ct);
28 static void r_pos(RSFD rfd, double *current, double *total);
29 static int r_read(RSFD rfd, void *buf, TERMID *term);
30 static int r_write(RSFD rfd, const void *buf);
31
32 static const struct rset_control control = 
33 {
34     "null",
35     r_delete,
36     rset_get_one_term,
37     r_open,
38     r_close,
39     0, /* no forward */
40     r_pos,
41     r_read,
42     r_write,
43 };
44
45 RSET rset_create_null(NMEM nmem, struct rset_key_control *kcontrol,
46                       TERMID term)
47 {
48     RSET rnew = rset_create_base(&control, nmem, kcontrol, 0, term, 0, 0);
49     rnew->priv = 0;
50     return rnew;
51 }
52
53 static RSFD r_open(RSET ct, int flag)
54 {
55     RSFD rfd;
56     if (flag & RSETF_WRITE)
57     {
58         yaz_log (YLOG_FATAL, "NULL set type is read-only");
59         return NULL;
60     }
61     rfd = rfd_create_base(ct);
62     rfd->priv = 0;
63     return rfd;
64 }
65
66 static void r_close(RSFD rfd)
67 {
68 }
69
70 static void r_delete(RSET ct)
71 {
72 }
73
74 static void r_pos(RSFD rfd, double *current, double *total)
75 {
76     assert(rfd);
77     assert(current);
78     assert(total);
79     *total = 0;
80     *current = 0;
81 }
82
83 static int r_read(RSFD rfd, void *buf, TERMID *term)
84 {
85     if (term)
86         *term = 0;
87     return 0;
88 }
89
90 static int r_write(RSFD rfd, const void *buf)
91 {
92     yaz_log(YLOG_FATAL, "NULL set type is read-only");
93     return -1;
94 }
95 /*
96  * Local variables:
97  * c-basic-offset: 4
98  * c-file-style: "Stroustrup"
99  * indent-tabs-mode: nil
100  * End:
101  * vim: shiftwidth=4 tabstop=8 expandtab
102  */
103