2 * Copyright (c) 1995, the EUROPAGATE consortium (see below).
4 * The EUROPAGATE consortium members are:
6 * University College Dublin
7 * Danmarks Teknologiske Videnscenter
8 * An Chomhairle Leabharlanna
9 * Consejo Superior de Investigaciones Cientificas
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,
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.
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.
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.
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.
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.
49 * Revision 1.5 2000-05-02 17:19:58 adam
50 * Removed MINUS token.
52 * Revision 1.4 2000/03/14 09:06:11 adam
53 * Added POSIX threads support for frontend server.
55 * Revision 1.3 2000/02/08 10:39:53 adam
56 * Added a few functions to set name of operands, etc.
58 * Revision 1.2 2000/01/31 13:15:21 adam
59 * Removed uses of assert(3). Cleanup of ODR. CCL parser update so
60 * that some characters are not surrounded by spaces in resulting term.
63 * Revision 1.1 1999/11/30 13:47:11 adam
64 * Improved installation. Moved header files to include/yaz.
66 * Revision 1.9 1998/02/11 11:53:33 adam
67 * Changed code so that it compiles as C++.
69 * Revision 1.8 1997/09/29 09:01:19 adam
70 * Changed CCL parser to be thread safe. New type, CCL-parser, declared
71 * and a create/destructor ccl_parser_create/ccl_parser_destroy has been
74 * Revision 1.7 1997/09/01 08:49:47 adam
75 * New windows NT/95 port using MSV5.0. To export DLL functions the
76 * YAZ_EXPORT modifier was added. Defined in yconfig.h.
78 * Revision 1.6 1997/05/14 06:53:37 adam
81 * Revision 1.5 1997/04/30 08:52:08 quinn
84 * Revision 1.4 1996/10/11 15:02:26 adam
85 * CCL parser from Europagate Email gateway 1.0.
87 * Revision 1.10 1996/01/08 08:41:22 adam
90 * Revision 1.9 1995/07/20 08:15:16 adam
91 * Bug fix: Token value for comma and OR were the same!
93 * Revision 1.8 1995/07/11 12:28:34 adam
94 * New function: ccl_token_simple (split into simple tokens) and
95 * ccl_token_del (delete tokens).
97 * Revision 1.7 1995/05/16 09:39:38 adam
100 * Revision 1.6 1995/05/11 14:04:03 adam
101 * Changes in the reading of qualifier(s). New function: ccl_qual_fitem.
102 * New variable ccl_case_sensitive, which controls whether reserved
103 * words and field names are case sensitive or not.
105 * Revision 1.5 1995/02/23 08:32:11 adam
108 * Revision 1.3 1995/02/16 13:20:10 adam
111 * Revision 1.2 1995/02/15 17:43:08 adam
112 * Minor changes to the ccl interface. Bug fix in iso2709 module.
114 * Revision 1.1 1995/02/14 19:55:21 adam
115 * Header files ccl.h/cclp.h are gone! They have been merged an
116 * moved to ../include/ccl.h.
129 /* CCL error numbers */
131 #define CCL_ERR_TERM_EXPECTED 1
132 #define CCL_ERR_RP_EXPECTED 2
133 #define CCL_ERR_SETNAME_EXPECTED 3
134 #define CCL_ERR_OP_EXPECTED 4
135 #define CCL_ERR_BAD_RP 5
136 #define CCL_ERR_UNKNOWN_QUAL 6
137 #define CCL_ERR_DOUBLE_QUAL 7
138 #define CCL_ERR_EQ_EXPECTED 8
139 #define CCL_ERR_BAD_RELATION 9
140 #define CCL_ERR_TRUNC_NOT_LEFT 10
141 #define CCL_ERR_TRUNC_NOT_BOTH 11
142 #define CCL_ERR_TRUNC_NOT_RIGHT 12
144 /* attribute pair (type, value) */
145 struct ccl_rpn_attr {
146 struct ccl_rpn_attr *next;
151 #define CCL_RPN_AND 1
153 #define CCL_RPN_NOT 3
154 #define CCL_RPN_TERM 4
155 #define CCL_RPN_SET 5
156 #define CCL_RPN_PROX 6
158 /* RPN tree structure */
159 struct ccl_rpn_node {
162 struct ccl_rpn_node *p[2];
165 struct ccl_rpn_attr *attr_list;
171 typedef struct ccl_qualifiers *CCL_bibset;
178 1-6 relation (<, <=, =, >=, >, <>)
184 3 any position in field
187 0 word/phrase auto select
194 100 date (un-normalized)
195 101 name (normalized)
196 102 name (un-normalized)
201 #define CCL_BIB1_USE 1
202 #define CCL_BIB1_REL 2
203 #define CCL_BIB1_POS 3
204 #define CCL_BIB1_STR 4
205 #define CCL_BIB1_TRU 5
206 #define CCL_BIB1_COM 6
208 #define CCL_BIB1_STR_WP (-1)
209 #define CCL_BIB1_REL_ORDER (-1)
211 #define CCL_BIB1_TRU_CAN_LEFT (-1)
212 #define CCL_BIB1_TRU_CAN_RIGHT (-2)
213 #define CCL_BIB1_TRU_CAN_BOTH (-3)
214 #define CCL_BIB1_TRU_CAN_NONE (-4)
216 #define CCL_TOK_EOL 0
217 #define CCL_TOK_TERM 1
218 #define CCL_TOK_REL 2
220 #define CCL_TOK_PROX 4
223 #define CCL_TOK_COMMA 7
224 #define CCL_TOK_AND 8
226 #define CCL_TOK_NOT 10
227 #define CCL_TOK_SET 11
234 struct ccl_token *next;
235 struct ccl_token *prev;
239 struct ccl_qualifier {
241 struct ccl_rpn_attr *attr_list;
242 struct ccl_qualifier *next;
246 /* current lookahead token */
247 struct ccl_token *look_token;
249 /* holds error code if error occur (and approx position of error) */
251 const char *error_pos;
260 int ccl_case_sensitive;
263 typedef struct ccl_parser *CCL_parser;
265 /* Generate tokens from command string - obeys all CCL opererators */
266 struct ccl_token *ccl_parser_tokenize (CCL_parser cclp,
267 const char *command);
268 struct ccl_token *ccl_tokenize (const char *command);
270 /* Generate tokens from command string - oebeys only simple tokens and
272 struct ccl_token *ccl_token_simple (const char *command);
274 /* Delete token list */
275 void ccl_token_del (struct ccl_token *list);
277 /* Parse CCL Find command - NULL-terminated string */
278 struct ccl_rpn_node *ccl_find_str (CCL_bibset bibset,
279 const char *str, int *error, int *pos);
281 /* Parse CCL Find command - Tokens read by ccl_tokenize */
282 struct ccl_rpn_node *ccl_find (CCL_bibset abibset, struct ccl_token *list,
283 int *error, const char **pos);
285 /* Parse CCL Find command */
286 struct ccl_rpn_node *ccl_parser_find (CCL_parser cclp, struct ccl_token *list);
288 /* Set various OPs */
289 void ccl_parser_set_op_and (CCL_parser p, const char *op);
290 void ccl_parser_set_op_or (CCL_parser p, const char *op);
291 void ccl_parser_set_op_not (CCL_parser p, const char *op);
292 void ccl_parser_set_op_set (CCL_parser p, const char *op);
294 void ccl_parser_set_case (CCL_parser p, int case_sensitivity_flag);
296 /* Return english-readable error message */
297 const char *ccl_err_msg (int ccl_errno);
299 /* Delete RPN tree returned by ccl_find */
300 void ccl_rpn_delete (struct ccl_rpn_node *rpn);
302 /* Dump RPN tree in readable format to fd_out */
303 void ccl_pr_tree (struct ccl_rpn_node *rpn, FILE *fd_out);
305 /* Add CCL qualifier */
306 void ccl_qual_add (CCL_bibset b, const char *name, int no, int *attr);
308 /* Read CCL qualifier list spec from file inf */
309 void ccl_qual_file (CCL_bibset bibset, FILE *inf);
311 /* Add CCL qualifier by using single-line spec */
312 void ccl_qual_fitem (CCL_bibset bibset, const char *cp, const char *qual_name);
314 /* Make CCL qualifier set */
315 CCL_bibset ccl_qual_mk (void);
317 /* Delete CCL qualifier set */
318 void ccl_qual_rm (CCL_bibset *b);
320 /* Char-to-upper function */
321 extern int (*ccl_toupper)(int c);
323 /* String utilities */
324 int ccl_stricmp (const char *s1, const char *s2);
325 int ccl_memicmp (const char *s1, const char *s2, size_t n);
327 /* Search for qualifier 'name' in set 'b'. */
328 struct ccl_rpn_attr *ccl_qual_search (CCL_parser cclp, const char *name,
331 /* Create CCL parser */
332 CCL_parser ccl_parser_create (void);
334 /* Destroy CCL parser */
335 void ccl_parser_destroy (CCL_parser p);
339 #define ccl_assert(x) ;