Moved definitions of nmem_block and nmem_control.
[yaz-moved-to-github.git] / include / ccl.h
1 /*
2  * Copyright (c) 1995, the EUROPAGATE consortium (see below).
3  *
4  * The EUROPAGATE consortium members are:
5  *
6  *    University College Dublin
7  *    Danmarks Teknologiske Videnscenter
8  *    An Chomhairle Leabharlanna
9  *    Consejo Superior de Investigaciones Cientificas
10  *
11  * Permission to use, copy, modify, distribute, and sell this software and
12  * its documentation, in whole or in part, for any purpose, is hereby granted,
13  * provided that:
14  *
15  * 1. This copyright and permission notice appear in all copies of the
16  * software and its documentation. Notices of copyright or attribution
17  * which appear at the beginning of any file must remain unchanged.
18  *
19  * 2. The names of EUROPAGATE or the project partners may not be used to
20  * endorse or promote products derived from this software without specific
21  * prior written permission.
22  *
23  * 3. Users of this software (implementors and gateway operators) agree to
24  * inform the EUROPAGATE consortium of their use of the software. This
25  * information will be used to evaluate the EUROPAGATE project and the
26  * software, and to plan further developments. The consortium may use
27  * the information in later publications.
28  * 
29  * 4. Users of this software agree to make their best efforts, when
30  * documenting their use of the software, to acknowledge the EUROPAGATE
31  * consortium, and the role played by the software in their work.
32  *
33  * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
34  * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
35  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
36  * IN NO EVENT SHALL THE EUROPAGATE CONSORTIUM OR ITS MEMBERS BE LIABLE
37  * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF
38  * ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
39  * OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND
40  * ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
41  * USE OR PERFORMANCE OF THIS SOFTWARE.
42  *
43  */
44
45 /*
46  * CCL - header file
47  *
48  * $Log: ccl.h,v $
49  * Revision 1.6  1997-05-14 06:53:37  adam
50  * C++ support.
51  *
52  * Revision 1.5  1997/04/30 08:52:08  quinn
53  * Null
54  *
55  * Revision 1.4  1996/10/11  15:02:26  adam
56  * CCL parser from Europagate Email gateway 1.0.
57  *
58  * Revision 1.10  1996/01/08  08:41:22  adam
59  * Minor changes.
60  *
61  * Revision 1.9  1995/07/20  08:15:16  adam
62  * Bug fix: Token value for comma and OR were the same!
63  *
64  * Revision 1.8  1995/07/11  12:28:34  adam
65  * New function: ccl_token_simple (split into simple tokens) and
66  *  ccl_token_del (delete tokens).
67  *
68  * Revision 1.7  1995/05/16  09:39:38  adam
69  * LICENSE.
70  *
71  * Revision 1.6  1995/05/11  14:04:03  adam
72  * Changes in the reading of qualifier(s). New function: ccl_qual_fitem.
73  * New variable ccl_case_sensitive, which controls whether reserved
74  * words and field names are case sensitive or not.
75  *
76  * Revision 1.5  1995/02/23  08:32:11  adam
77  * Changed header.
78  *
79  * Revision 1.3  1995/02/16  13:20:10  adam
80  * Spell fix.
81  *
82  * Revision 1.2  1995/02/15  17:43:08  adam
83  * Minor changes to the ccl interface. Bug fix in iso2709 module.
84  *
85  * Revision 1.1  1995/02/14  19:55:21  adam
86  * Header files ccl.h/cclp.h are gone! They have been merged an
87  * moved to ../include/ccl.h.
88  *
89  */
90
91 #ifndef CCL_H
92 #define CCL_H
93
94 #ifdef __cplusplus
95 extern "C" {
96 #endif
97
98 /* CCL error numbers */
99 #define CCL_ERR_OK                0
100 #define CCL_ERR_TERM_EXPECTED     1
101 #define CCL_ERR_RP_EXPECTED       2
102 #define CCL_ERR_SETNAME_EXPECTED  3
103 #define CCL_ERR_OP_EXPECTED       4
104 #define CCL_ERR_BAD_RP            5
105 #define CCL_ERR_UNKNOWN_QUAL      6
106 #define CCL_ERR_DOUBLE_QUAL       7
107 #define CCL_ERR_EQ_EXPECTED       8
108 #define CCL_ERR_BAD_RELATION      9
109 #define CCL_ERR_TRUNC_NOT_LEFT   10
110 #define CCL_ERR_TRUNC_NOT_BOTH   11
111 #define CCL_ERR_TRUNC_NOT_RIGHT  12
112
113 /* attribute pair (type, value) */
114 struct ccl_rpn_attr {
115     struct ccl_rpn_attr *next;
116     int type;
117     int value;
118 };
119
120 #define CCL_RPN_AND 1
121 #define CCL_RPN_OR 2
122 #define CCL_RPN_NOT 3
123 #define CCL_RPN_TERM 4
124 #define CCL_RPN_SET 5
125 #define CCL_RPN_PROX 6
126
127 /* RPN tree structure */
128 struct ccl_rpn_node {
129     int kind;
130     union {
131         struct ccl_rpn_node *p[2];
132         struct {
133             char *term;
134             struct ccl_rpn_attr *attr_list;
135         } t;
136         char *setname;
137     } u;
138 };
139
140 typedef struct ccl_qualifiers *CCL_bibset;
141
142 /* use (1)
143
144    relation (2)
145                             -1  none
146                              0  ordered
147                            1-6  relation (<, <=, =, >=, >, <>)
148
149    position (3)
150                             -1  none
151                              1  first in field
152                              2  first in sub field
153                              3  any position in field
154    structure (4)
155                             -1  none
156                              0  word/phrase auto select
157                              1  phrase
158                              2  word
159                              3  key
160                              4  year
161                              5  date (normalized)
162                              6  word list 
163                            100  date (un-normalized)
164                            101  name (normalized)
165                            102  name (un-normalized)
166    truncation (5)                            
167    completeness (6)
168 */
169
170 #define CCL_BIB1_USE 1
171 #define CCL_BIB1_REL 2
172 #define CCL_BIB1_POS 3
173 #define CCL_BIB1_STR 4
174 #define CCL_BIB1_TRU 5
175 #define CCL_BIB1_COM 6
176
177 #define CCL_BIB1_STR_WP (-1)
178 #define CCL_BIB1_REL_ORDER (-1)
179
180 #define CCL_BIB1_TRU_CAN_LEFT (-1)
181 #define CCL_BIB1_TRU_CAN_RIGHT (-2)
182 #define CCL_BIB1_TRU_CAN_BOTH  (-3)
183 #define CCL_BIB1_TRU_CAN_NONE  (-4)
184
185 #define CCL_TOK_EOL   0
186 #define CCL_TOK_TERM  1
187 #define CCL_TOK_REL   2
188 #define CCL_TOK_EQ    3
189 #define CCL_TOK_PROX  4
190 #define CCL_TOK_LP    5
191 #define CCL_TOK_RP    6
192 #define CCL_TOK_COMMA 7
193 #define CCL_TOK_AND   8
194 #define CCL_TOK_OR    9
195 #define CCL_TOK_NOT   10
196 #define CCL_TOK_MINUS 11
197 #define CCL_TOK_SET   12
198
199 /* CCL token */
200 struct ccl_token {
201     char kind;
202     char len;
203     const char *name;
204     struct ccl_token *next;
205     struct ccl_token *prev;
206 };
207
208 /* CCL Qualifier */
209 struct ccl_qualifier {
210     char *name;
211     struct ccl_rpn_attr *attr_list;
212     struct ccl_qualifier *next;
213 };
214
215 /* Generate tokens from command string - obeys all CCL opererators */
216 struct ccl_token *ccl_tokenize (const char *command);
217
218 /* Generate tokens from command string - oebeys only simple tokens and 
219    quoted strings */
220 struct ccl_token *ccl_token_simple (const char *command);
221
222 /* Delete token list */
223 void ccl_token_del (struct ccl_token *list);
224
225 /* Parse CCL Find command - NULL-terminated string */
226 struct ccl_rpn_node *ccl_find_str (CCL_bibset bibset,
227                                    const char *str, int *error, int *pos);
228
229 /* Parse CCL Find command - Tokens read by ccl_tokenize */
230 struct ccl_rpn_node *ccl_find (CCL_bibset abibset, struct ccl_token *list,
231                                int *error, const char **pos);
232
233 /* Return english-readable error message */
234 char *ccl_err_msg (int ccl_errno);
235
236 /* Delete RPN tree returned by ccl_find */
237 void ccl_rpn_delete (struct ccl_rpn_node *rpn);
238
239 /* Dump RPN tree in readable format to fd_out */
240 void ccl_pr_tree (struct ccl_rpn_node *rpn, FILE *fd_out);
241
242 /* Add CCL qualifier */
243 void ccl_qual_add (CCL_bibset b, const char *name, int no, int *attr);
244
245 /* Read CCL qualifier list spec from file inf */
246 void ccl_qual_file (CCL_bibset bibset, FILE *inf);
247
248 /* Add CCL qualifier by using single-line spec */
249 void ccl_qual_fitem (CCL_bibset bibset, const char *cp, const char *qual_name);
250
251 /* Make CCL qualifier set */
252 CCL_bibset ccl_qual_mk (void);
253
254 /* Delete CCL qualifier set */
255 void ccl_qual_rm (CCL_bibset *b);
256
257 /* Misc. reserved words */
258 extern const char *ccl_token_and;
259 extern const char *ccl_token_or;
260 extern const char *ccl_token_not;
261 extern const char *ccl_token_set;
262
263 /* Whether the CCL parser is command sensitive */
264 extern int ccl_case_sensitive;
265
266 /* Char-to-upper function */
267 extern int (*ccl_toupper)(int c);
268
269 /* String utilities */
270 int ccl_stricmp (const char *s1, const char *s2);
271 int ccl_memicmp (const char *s1, const char *s2, size_t n);
272
273 /* Search for qualifier 'name' in set 'b'. */
274 struct ccl_rpn_attr *ccl_qual_search (CCL_bibset b, const char *name, int len);
275
276 #ifdef __cplusplus
277 }
278 #endif
279
280 #endif
281