C++ compilation.
[idzebra-moved-to-github.git] / rset / rsnull.c
1 /*
2  * Copyright (C) 1994-1999, Index Data
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: rsnull.c,v $
7  * Revision 1.12  1999-05-26 07:49:14  adam
8  * C++ compilation.
9  *
10  * Revision 1.11  1999/02/02 14:51:36  adam
11  * Updated WIN32 code specific sections. Changed header.
12  *
13  * Revision 1.10  1998/03/05 08:36:28  adam
14  * New result set model.
15  *
16  * Revision 1.9  1997/12/18 10:54:25  adam
17  * New method result set method rs_hits that returns the number of
18  * hits in result-set (if known). The ranked result set returns real
19  * number of hits but only when not combined with other operands.
20  *
21  * Revision 1.8  1996/10/29 13:55:24  adam
22  * Include of zebrautl.h instead of alexutil.h.
23  *
24  * Revision 1.7  1995/12/11 09:15:25  adam
25  * New set types: sand/sor/snot - ranked versions of and/or/not in
26  * ranked/semi-ranked result sets.
27  * Note: the snot not finished yet.
28  * New rset member: flag.
29  * Bug fix: r_delete in rsrel.c did free bad memory block.
30  *
31  * Revision 1.6  1995/10/12  12:41:57  adam
32  * Private info (buf) moved from struct rset_control to struct rset.
33  * Bug fixes in relevance.
34  *
35  * Revision 1.5  1995/10/10  14:00:04  adam
36  * Function rset_open changed its wflag parameter to general flags.
37  *
38  * Revision 1.4  1995/10/06  14:38:06  adam
39  * New result set method: r_score.
40  * Local no (sysno) and score is transferred to retrieveCtrl.
41  *
42  * Revision 1.3  1995/09/08  14:52:42  adam
43  * Work on relevance feedback.
44  *
45  * Revision 1.2  1995/09/07  13:58:43  adam
46  * New parameter: result-set file descriptor (RSFD) to support multiple
47  * positions within the same result-set.
48  * Boolean operators: and, or, not implemented.
49  *
50  * Revision 1.1  1995/09/06  10:35:44  adam
51  * Null set implemented.
52  *
53  */
54
55 #include <stdio.h>
56 #include <rsnull.h>
57 #include <zebrautl.h>
58
59 static void *r_create(RSET ct, const struct rset_control *sel, void *parms);
60 static RSFD r_open (RSET ct, int flag);
61 static void r_close (RSFD rfd);
62 static void r_delete (RSET ct);
63 static void r_rewind (RSFD rfd);
64 static int r_count (RSET ct);
65 static int r_read (RSFD rfd, void *buf, int *term_index);
66 static int r_write (RSFD rfd, const void *buf);
67
68 static const struct rset_control control = 
69 {
70     "null",
71     r_create,
72     r_open,
73     r_close,
74     r_delete,
75     r_rewind,
76     r_count,
77     r_read,
78     r_write,
79 };
80
81 const struct rset_control *rset_kind_null = &control;
82
83 static void *r_create(RSET ct, const struct rset_control *sel, void *parms)
84 {
85     rset_null_parms *null_parms = (rset_null_parms *) parms;
86
87     ct->no_rset_terms = 1;
88     ct->rset_terms = (RSET_TERM *) xmalloc (sizeof(*ct->rset_terms));
89     if (parms)
90         ct->rset_terms[0] = null_parms->rset_term;
91     else
92         ct->rset_terms[0] = rset_term_create ("term", -1, "rank-0");
93     ct->rset_terms[0]->nn = 0;
94
95     return NULL;
96 }
97
98 static RSFD r_open (RSET ct, int flag)
99 {
100     if (flag & RSETF_WRITE)
101     {
102         logf (LOG_FATAL, "NULL set type is read-only");
103         return NULL;
104     }
105     return "";
106 }
107
108 static void r_close (RSFD rfd)
109 {
110 }
111
112 static void r_delete (RSET ct)
113 {
114     rset_term_destroy (ct->rset_terms[0]);
115     xfree (ct->rset_terms);
116 }
117
118 static void r_rewind (RSFD rfd)
119 {
120     logf (LOG_DEBUG, "rsnull_rewind");
121 }
122
123 static int r_count (RSET ct)
124 {
125     return 0;
126 }
127
128 static int r_read (RSFD rfd, void *buf, int *term_index)
129 {
130     *term_index = -1;
131     return 0;
132 }
133
134 static int r_write (RSFD rfd, const void *buf)
135 {
136     logf (LOG_FATAL, "NULL set type is read-only");
137     return -1;
138 }
139