Improved installation. Moved header files to include/yaz.
[yaz-moved-to-github.git] / include / yaz / 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.1  1999-11-30 13:47:11  adam
50  * Improved installation. Moved header files to include/yaz.
51  *
52  * Revision 1.9  1998/02/11 11:53:33  adam
53  * Changed code so that it compiles as C++.
54  *
55  * Revision 1.8  1997/09/29 09:01:19  adam
56  * Changed CCL parser to be thread safe. New type, CCL-parser, declared
57  * and a create/destructor ccl_parser_create/ccl_parser_destroy has been
58  * added.
59  *
60  * Revision 1.7  1997/09/01 08:49:47  adam
61  * New windows NT/95 port using MSV5.0. To export DLL functions the
62  * YAZ_EXPORT modifier was added. Defined in yconfig.h.
63  *
64  * Revision 1.6  1997/05/14 06:53:37  adam
65  * C++ support.
66  *
67  * Revision 1.5  1997/04/30 08:52:08  quinn
68  * Null
69  *
70  * Revision 1.4  1996/10/11  15:02:26  adam
71  * CCL parser from Europagate Email gateway 1.0.
72  *
73  * Revision 1.10  1996/01/08  08:41:22  adam
74  * Minor changes.
75  *
76  * Revision 1.9  1995/07/20  08:15:16  adam
77  * Bug fix: Token value for comma and OR were the same!
78  *
79  * Revision 1.8  1995/07/11  12:28:34  adam
80  * New function: ccl_token_simple (split into simple tokens) and
81  *  ccl_token_del (delete tokens).
82  *
83  * Revision 1.7  1995/05/16  09:39:38  adam
84  * LICENSE.
85  *
86  * Revision 1.6  1995/05/11  14:04:03  adam
87  * Changes in the reading of qualifier(s). New function: ccl_qual_fitem.
88  * New variable ccl_case_sensitive, which controls whether reserved
89  * words and field names are case sensitive or not.
90  *
91  * Revision 1.5  1995/02/23  08:32:11  adam
92  * Changed header.
93  *
94  * Revision 1.3  1995/02/16  13:20:10  adam
95  * Spell fix.
96  *
97  * Revision 1.2  1995/02/15  17:43:08  adam
98  * Minor changes to the ccl interface. Bug fix in iso2709 module.
99  *
100  * Revision 1.1  1995/02/14  19:55:21  adam
101  * Header files ccl.h/cclp.h are gone! They have been merged an
102  * moved to ../include/ccl.h.
103  *
104  */
105
106 #ifndef CCL_H
107 #define CCL_H
108
109 #ifdef __cplusplus
110 extern "C" {
111 #endif
112     
113 /* CCL error numbers */
114 #define CCL_ERR_OK                0
115 #define CCL_ERR_TERM_EXPECTED     1
116 #define CCL_ERR_RP_EXPECTED       2
117 #define CCL_ERR_SETNAME_EXPECTED  3
118 #define CCL_ERR_OP_EXPECTED       4
119 #define CCL_ERR_BAD_RP            5
120 #define CCL_ERR_UNKNOWN_QUAL      6
121 #define CCL_ERR_DOUBLE_QUAL       7
122 #define CCL_ERR_EQ_EXPECTED       8
123 #define CCL_ERR_BAD_RELATION      9
124 #define CCL_ERR_TRUNC_NOT_LEFT   10
125 #define CCL_ERR_TRUNC_NOT_BOTH   11
126 #define CCL_ERR_TRUNC_NOT_RIGHT  12
127     
128 /* attribute pair (type, value) */
129 struct ccl_rpn_attr {
130     struct ccl_rpn_attr *next;
131     int type;
132     int value;
133 };
134
135 #define CCL_RPN_AND 1
136 #define CCL_RPN_OR 2
137 #define CCL_RPN_NOT 3
138 #define CCL_RPN_TERM 4
139 #define CCL_RPN_SET 5
140 #define CCL_RPN_PROX 6
141
142 /* RPN tree structure */
143 struct ccl_rpn_node {
144     int kind;
145     union {
146         struct ccl_rpn_node *p[2];
147         struct {
148             char *term;
149             struct ccl_rpn_attr *attr_list;
150         } t;
151         char *setname;
152     } u;
153 };
154
155 typedef struct ccl_qualifiers *CCL_bibset;
156
157 /* use (1)
158
159    relation (2)
160                             -1  none
161                              0  ordered
162                            1-6  relation (<, <=, =, >=, >, <>)
163
164    position (3)
165                             -1  none
166                              1  first in field
167                              2  first in sub field
168                              3  any position in field
169    structure (4)
170                             -1  none
171                              0  word/phrase auto select
172                              1  phrase
173                              2  word
174                              3  key
175                              4  year
176                              5  date (normalized)
177                              6  word list 
178                            100  date (un-normalized)
179                            101  name (normalized)
180                            102  name (un-normalized)
181    truncation (5)                            
182    completeness (6)
183 */
184
185 #define CCL_BIB1_USE 1
186 #define CCL_BIB1_REL 2
187 #define CCL_BIB1_POS 3
188 #define CCL_BIB1_STR 4
189 #define CCL_BIB1_TRU 5
190 #define CCL_BIB1_COM 6
191
192 #define CCL_BIB1_STR_WP (-1)
193 #define CCL_BIB1_REL_ORDER (-1)
194
195 #define CCL_BIB1_TRU_CAN_LEFT (-1)
196 #define CCL_BIB1_TRU_CAN_RIGHT (-2)
197 #define CCL_BIB1_TRU_CAN_BOTH  (-3)
198 #define CCL_BIB1_TRU_CAN_NONE  (-4)
199
200 #define CCL_TOK_EOL   0
201 #define CCL_TOK_TERM  1
202 #define CCL_TOK_REL   2
203 #define CCL_TOK_EQ    3
204 #define CCL_TOK_PROX  4
205 #define CCL_TOK_LP    5
206 #define CCL_TOK_RP    6
207 #define CCL_TOK_COMMA 7
208 #define CCL_TOK_AND   8
209 #define CCL_TOK_OR    9
210 #define CCL_TOK_NOT   10
211 #define CCL_TOK_MINUS 11
212 #define CCL_TOK_SET   12
213
214 /* CCL token */
215 struct ccl_token {
216     char kind;
217     size_t len;
218     const char *name;
219     struct ccl_token *next;
220     struct ccl_token *prev;
221 };
222
223 /* CCL Qualifier */
224 struct ccl_qualifier {
225     char *name;
226     struct ccl_rpn_attr *attr_list;
227     struct ccl_qualifier *next;
228 };
229
230 struct ccl_parser {
231 /* current lookahead token */
232     struct ccl_token *look_token;
233     
234 /* holds error code if error occur (and approx position of error) */
235     int error_code;
236     const char *error_pos;
237     
238 /* current bibset */
239     CCL_bibset bibset;
240     
241     char *ccl_token_and;
242     char *ccl_token_or;
243     char *ccl_token_not;
244     char *ccl_token_set;
245     int ccl_case_sensitive;
246 };
247     
248 typedef struct ccl_parser *CCL_parser;
249     
250 /* Generate tokens from command string - obeys all CCL opererators */
251 struct ccl_token *ccl_parser_tokenize (CCL_parser cclp,
252                                        const char *command);
253 struct ccl_token *ccl_tokenize (const char *command);
254     
255 /* Generate tokens from command string - oebeys only simple tokens and 
256    quoted strings */
257 struct ccl_token *ccl_token_simple (const char *command);
258
259 /* Delete token list */
260 void ccl_token_del (struct ccl_token *list);
261
262 /* Parse CCL Find command - NULL-terminated string */
263 struct ccl_rpn_node *ccl_find_str (CCL_bibset bibset,
264                                    const char *str, int *error, int *pos);
265
266 /* Parse CCL Find command - Tokens read by ccl_tokenize */
267 struct ccl_rpn_node *ccl_find (CCL_bibset abibset, struct ccl_token *list,
268                                int *error, const char **pos);
269
270 /* Return english-readable error message */
271 const char *ccl_err_msg (int ccl_errno);
272
273 /* Delete RPN tree returned by ccl_find */
274 void ccl_rpn_delete (struct ccl_rpn_node *rpn);
275
276 /* Dump RPN tree in readable format to fd_out */
277 void ccl_pr_tree (struct ccl_rpn_node *rpn, FILE *fd_out);
278
279 /* Add CCL qualifier */
280 void ccl_qual_add (CCL_bibset b, const char *name, int no, int *attr);
281
282 /* Read CCL qualifier list spec from file inf */
283 void ccl_qual_file (CCL_bibset bibset, FILE *inf);
284
285 /* Add CCL qualifier by using single-line spec */
286 void ccl_qual_fitem (CCL_bibset bibset, const char *cp, const char *qual_name);
287
288 /* Make CCL qualifier set */
289 CCL_bibset ccl_qual_mk (void);
290
291 /* Delete CCL qualifier set */
292 void ccl_qual_rm (CCL_bibset *b);
293
294 /* Char-to-upper function */
295 extern int (*ccl_toupper)(int c);
296
297 /* String utilities */
298 int ccl_stricmp (const char *s1, const char *s2);
299 int ccl_memicmp (const char *s1, const char *s2, size_t n);
300
301 /* Search for qualifier 'name' in set 'b'. */
302 struct ccl_rpn_attr *ccl_qual_search (CCL_parser cclp, const char *name,
303                                       size_t len);
304
305 /* Create CCL parser */
306 CCL_parser ccl_parser_create (void);
307
308 /* Destroy CCL parser */
309 void ccl_parser_destroy (CCL_parser p);
310
311 #ifdef __cplusplus
312 }
313 #endif
314
315 #endif
316