1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2008 Index Data.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Index Data nor the names of its contributors
13 * may be used to endorse or promote products derived from this
14 * software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 \brief Header with public definitions for CCL.
35 * $Id: ccl.h,v 1.29 2007-05-01 12:22:10 adam Exp $
39 * Revision 1.10 1996/01/08 08:41:22 adam
42 * Revision 1.9 1995/07/20 08:15:16 adam
43 * Bug fix: Token value for comma and OR were the same!
45 * Revision 1.8 1995/07/11 12:28:34 adam
46 * New function: ccl_token_simple (split into simple tokens) and
47 * ccl_token_del (delete tokens).
49 * Revision 1.7 1995/05/16 09:39:38 adam
52 * Revision 1.6 1995/05/11 14:04:03 adam
53 * Changes in the reading of qualifier(s). New function: ccl_qual_fitem.
54 * New variable ccl_case_sensitive, which controls whether reserved
55 * words and field names are case sensitive or not.
57 * Revision 1.5 1995/02/23 08:32:11 adam
60 * Revision 1.3 1995/02/16 13:20:10 adam
63 * Revision 1.2 1995/02/15 17:43:08 adam
64 * Minor changes to the ccl interface. Bug fix in iso2709 module.
66 * Revision 1.1 1995/02/14 19:55:21 adam
67 * Header files ccl.h/cclp.h are gone! They have been merged an
68 * moved to ../include/ccl.h.
75 #include <yaz/yconfig.h>
77 #include <yaz/xmalloc.h>
78 #include <yaz/wrbuf.h>
83 #define CCL_ERR_TERM_EXPECTED 1
84 #define CCL_ERR_RP_EXPECTED 2
85 #define CCL_ERR_SETNAME_EXPECTED 3
86 #define CCL_ERR_OP_EXPECTED 4
87 #define CCL_ERR_BAD_RP 5
88 #define CCL_ERR_UNKNOWN_QUAL 6
89 #define CCL_ERR_DOUBLE_QUAL 7
90 #define CCL_ERR_EQ_EXPECTED 8
91 #define CCL_ERR_BAD_RELATION 9
92 #define CCL_ERR_TRUNC_NOT_LEFT 10
93 #define CCL_ERR_TRUNC_NOT_BOTH 11
94 #define CCL_ERR_TRUNC_NOT_RIGHT 12
96 /** \brief attribute node (type, value) pair as used in RPN */
98 /** \brief next attribute */
99 struct ccl_rpn_attr *next;
100 /** \brief attribute set */
102 /** \brief attribute type, Bib-1: 1=use, 2=relation, 3=position, .. */
104 /** \brief attribute value type (numeric or string) */
106 #define CCL_RPN_ATTR_NUMERIC 1
107 #define CCL_RPN_ATTR_STRING 2
109 /** \brief numeric attribute value */
111 /** \brief string attribute value */
116 /** \brief node type or RPN tree generated by the CCL parser */
126 /** \brief RPN tree structure node */
127 struct ccl_rpn_node {
128 /** \brief node type, one of CCL_RPN_AND, CCL_RPN_OR,.. */
129 enum ccl_rpn_kind kind;
131 /** \brief Boolean including proximity 0=left, 1=right, 2=prox parms */
132 struct ccl_rpn_node *p[3];
133 /** \brief Attributes + Term */
137 struct ccl_rpn_attr *attr_list;
144 /** \brief CCL bibset, AKA profile */
145 typedef struct ccl_qualifiers *CCL_bibset;
147 /** \brief CCL parser */
148 typedef struct ccl_parser *CCL_parser;
151 \brief parse CCL find string using CCL profile return RPN tree
153 Parses a CCL Find command in a simple C string. Returns CCL parse
154 tree node describing RPN if parsing is successful. If parsing is
155 unsuccesful, NULL is returned and error and pos is set accordingly.
158 struct ccl_rpn_node *ccl_find_str(CCL_bibset bibset,
159 const char *str, int *error, int *pos);
163 \brief parse CCL find string with parser and return RPN tree
165 Parses a CCL Find command in a simple C string. Returns CCL parse
166 tree node describing RPN if parsing is successful. If parsing is
167 unsuccesful, NULL is returned and error and pos is set accordingly.
170 struct ccl_rpn_node *ccl_parser_find_str(CCL_parser cclp, const char *str);
172 /** Set case sensitivity for parser */
174 void ccl_parser_set_case(CCL_parser p, int case_sensitivity_flag);
176 /** Return english-readable error message for CCL parser error number */
178 const char *ccl_err_msg(int ccl_errno);
180 /** Delete RPN tree returned by ccl_find */
182 void ccl_rpn_delete(struct ccl_rpn_node *rpn);
184 /** Dump RPN tree in readable format to fd_out */
186 void ccl_pr_tree(struct ccl_rpn_node *rpn, FILE *fd_out);
188 /** Add qualifier and supply attribute pairs for it */
190 void ccl_qual_add(CCL_bibset b, const char *name, int no, int *attr);
192 /** Add qualifier and supply attributes pairs+attribute set for it */
194 void ccl_qual_add_set(CCL_bibset b, const char *name, int no,
195 int *type, int *value, char **svalue, char **attsets);
197 /** Add special qualifier */
199 void ccl_qual_add_special(CCL_bibset bibset, const char *n, const char *cp);
201 /** Add combo qualifier */
203 void ccl_qual_add_combi(CCL_bibset b, const char *n, const char **names);
205 /** Read CCL qualifier list spec from file inf */
207 void ccl_qual_file(CCL_bibset bibset, FILE *inf);
209 /** Read CCL qualifier list spec from file inf */
211 int ccl_qual_fname(CCL_bibset bibset, const char *fname);
213 /** Add CCL qualifier as buf spec(multiple lines). */
215 void ccl_qual_buf(CCL_bibset bibset, const char *buf);
217 /** Add CCL qualifier as line spec. Note: line is _modified_ */
219 void ccl_qual_line(CCL_bibset bibset, char *line);
221 /* Add CCL qualifier by using qual_name + value pair */
223 void ccl_qual_fitem(CCL_bibset bibset, const char *value,
224 const char *qual_name);
226 /** Make CCL qualifier set */
228 CCL_bibset ccl_qual_mk(void);
230 /** Delete CCL qualifier set */
232 void ccl_qual_rm(CCL_bibset *b);
234 /** Char-to-upper function */
235 extern int(*ccl_toupper)(int c);
237 /** CCL version of ccl_stricmp */
239 int ccl_stricmp(const char *s1, const char *s2);
241 /** CCL version of ccl_memicmp */
243 int ccl_memicmp(const char *s1, const char *s2, size_t n);
245 /** Create CCL parser */
247 CCL_parser ccl_parser_create(CCL_bibset bibset);
249 /** Destroy CCL parser */
251 void ccl_parser_destroy(CCL_parser p);
253 /** Search for special qualifier */
255 const char **ccl_qual_search_special(CCL_bibset b, const char *name);
256 /** Pretty-print CCL RPN node tree to WRBUF */
258 void ccl_pquery(WRBUF w, struct ccl_rpn_node *p);
261 int ccl_parser_get_error(CCL_parser cclp, int *pos);
264 struct ccl_rpn_node *ccl_rpn_node_create(enum ccl_rpn_kind kind);
267 void ccl_add_attr_numeric(struct ccl_rpn_node *p, const char *set,
268 int type, int value);
271 void ccl_add_attr_string(struct ccl_rpn_node *p, const char *set,
272 int type, char *value);
275 int ccl_search_stop(CCL_bibset bibset, const char *qname,
276 const char *src_str, size_t src_len);
279 /** \brief stop words handle (pimpl) */
280 typedef struct ccl_stop_words *ccl_stop_words_t;
282 /** \brief creates stop words handle */
284 ccl_stop_words_t ccl_stop_words_create(void);
286 /** \brief destroys stop words handle */
288 void ccl_stop_words_destroy(ccl_stop_words_t csw);
290 /** \brief removes stop words from RPN tree */
292 int ccl_stop_words_tree(ccl_stop_words_t csw,
293 CCL_bibset bibset, struct ccl_rpn_node **t);
295 /** \brief returns information about removed "stop" words */
297 int ccl_stop_words_info(ccl_stop_words_t csw, int idx,
298 const char **qualname, const char **term);
301 #define ccl_assert(x) ;
305 /** \brief common attributes
312 1-6 relation (<, <=, =, >=, >, <>)
318 3 any position in field
321 0 word/phrase auto select
328 100 date (un-normalized)
329 101 name (normalized)
330 102 name (un-normalized)
335 #define CCL_BIB1_USE 1
336 #define CCL_BIB1_REL 2
337 #define CCL_BIB1_POS 3
338 #define CCL_BIB1_STR 4
339 #define CCL_BIB1_TRU 5
340 #define CCL_BIB1_COM 6
342 #define CCL_BIB1_STR_WP (-1)
343 #define CCL_BIB1_STR_AND_LIST (-2)
344 #define CCL_BIB1_STR_OR_LIST (-3)
345 #define CCL_BIB1_REL_ORDER (-1)
346 #define CCL_BIB1_REL_PORDER (-2)
348 #define CCL_BIB1_TRU_CAN_LEFT (-1)
349 #define CCL_BIB1_TRU_CAN_RIGHT (-2)
350 #define CCL_BIB1_TRU_CAN_BOTH (-3)
351 #define CCL_BIB1_TRU_CAN_NONE (-4)
362 * indent-tabs-mode: nil
364 * vim: shiftwidth=4 tabstop=8 expandtab