1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 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.
38 * Revision 1.10 1996/01/08 08:41:22 adam
41 * Revision 1.9 1995/07/20 08:15:16 adam
42 * Bug fix: Token value for comma and OR were the same!
44 * Revision 1.8 1995/07/11 12:28:34 adam
45 * New function: ccl_token_simple (split into simple tokens) and
46 * ccl_token_del (delete tokens).
48 * Revision 1.7 1995/05/16 09:39:38 adam
51 * Revision 1.6 1995/05/11 14:04:03 adam
52 * Changes in the reading of qualifier(s). New function: ccl_qual_fitem.
53 * New variable ccl_case_sensitive, which controls whether reserved
54 * words and field names are case sensitive or not.
56 * Revision 1.5 1995/02/23 08:32:11 adam
59 * Revision 1.3 1995/02/16 13:20:10 adam
62 * Revision 1.2 1995/02/15 17:43:08 adam
63 * Minor changes to the ccl interface. Bug fix in iso2709 module.
65 * Revision 1.1 1995/02/14 19:55:21 adam
66 * Header files ccl.h/cclp.h are gone! They have been merged an
67 * moved to ../include/ccl.h.
74 #include <yaz/yconfig.h>
76 #include <yaz/xmalloc.h>
77 #include <yaz/wrbuf.h>
84 #define CCL_ERR_TERM_EXPECTED 1
85 #define CCL_ERR_RP_EXPECTED 2
86 #define CCL_ERR_SETNAME_EXPECTED 3
87 #define CCL_ERR_OP_EXPECTED 4
88 #define CCL_ERR_BAD_RP 5
89 #define CCL_ERR_UNKNOWN_QUAL 6
90 #define CCL_ERR_DOUBLE_QUAL 7
91 #define CCL_ERR_EQ_EXPECTED 8
92 #define CCL_ERR_BAD_RELATION 9
93 #define CCL_ERR_TRUNC_NOT_LEFT 10
94 #define CCL_ERR_TRUNC_NOT_BOTH 11
95 #define CCL_ERR_TRUNC_NOT_RIGHT 12
96 #define CCL_ERR_TRUNC_NOT_EMBED 13
97 #define CCL_ERR_TRUNC_NOT_SINGLE 14
99 /** \brief attribute node (type, value) pair as used in RPN */
100 struct ccl_rpn_attr {
101 /** \brief next attribute */
102 struct ccl_rpn_attr *next;
103 /** \brief attribute set */
105 /** \brief attribute type, Bib-1: 1=use, 2=relation, 3=position, etc */
107 /** \brief attribute value type (numeric or string) */
109 #define CCL_RPN_ATTR_NUMERIC 1
110 #define CCL_RPN_ATTR_STRING 2
112 /** \brief numeric attribute value */
114 /** \brief string attribute value */
119 /** \brief node type or RPN tree generated by the CCL parser */
129 /** \brief RPN tree structure node */
130 struct ccl_rpn_node {
131 /** \brief node type, one of CCL_RPN_AND, CCL_RPN_OR, etc */
132 enum ccl_rpn_kind kind;
134 /** \brief Boolean including proximity 0=left, 1=right, 2=prox parms */
135 struct ccl_rpn_node *p[3];
136 /** \brief Attributes + Term */
140 struct ccl_rpn_attr *attr_list;
147 /** \brief CCL bibset, AKA profile */
148 typedef struct ccl_qualifiers *CCL_bibset;
150 /** \brief CCL parser */
151 typedef struct ccl_parser *CCL_parser;
154 \brief parse CCL find string using CCL profile return RPN tree
156 Parses a CCL Find command in a simple C string. Returns CCL parse
157 tree node describing RPN if parsing is successful. If parsing is
158 unsuccesful, NULL is returned and error and pos is set accordingly.
161 struct ccl_rpn_node *ccl_find_str(CCL_bibset bibset,
162 const char *str, int *error, int *pos);
166 \brief parse CCL find string with parser and return RPN tree
168 Parses a CCL Find command in a simple C string. Returns CCL parse
169 tree node describing RPN if parsing is successful. If parsing is
170 unsuccesful, NULL is returned and error and pos is set accordingly.
173 struct ccl_rpn_node *ccl_parser_find_str(CCL_parser cclp, const char *str);
175 /** Set case sensitivity for parser */
177 void ccl_parser_set_case(CCL_parser p, int case_sensitivity_flag);
179 /** Return english-readable error message for CCL parser error number */
181 const char *ccl_err_msg(int ccl_errno);
183 /** Delete RPN tree returned by ccl_find */
185 void ccl_rpn_delete(struct ccl_rpn_node *rpn);
187 /** Dump RPN tree in readable format to fd_out */
189 void ccl_pr_tree(struct ccl_rpn_node *rpn, FILE *fd_out);
191 /** Add qualifier and supply attribute pairs for it */
193 void ccl_qual_add(CCL_bibset b, const char *name, int no, int *attr);
195 /** Add qualifier and supply attributes pairs+attribute set for it */
197 void ccl_qual_add_set(CCL_bibset b, const char *name, int no,
198 int *type, int *value, char **svalue, char **attsets);
200 /** Add special qualifier */
202 void ccl_qual_add_special(CCL_bibset bibset, const char *n, const char *cp);
204 /** Add combo qualifier */
206 void ccl_qual_add_combi(CCL_bibset b, const char *n, const char **names);
208 /** Read CCL qualifier list spec from file inf */
210 void ccl_qual_file(CCL_bibset bibset, FILE *inf);
212 /** Read CCL qualifier list spec from file inf */
214 int ccl_qual_fname(CCL_bibset bibset, const char *fname);
216 /** Add CCL qualifier as buf spec(multiple lines). */
218 void ccl_qual_buf(CCL_bibset bibset, const char *buf);
220 /** Add CCL qualifier as line spec. Note: line is _modified_ */
222 void ccl_qual_line(CCL_bibset bibset, char *line);
224 /* Add CCL qualifier by using qual_name + value pair */
226 void ccl_qual_fitem(CCL_bibset bibset, const char *value,
227 const char *qual_name);
229 int ccl_qual_fitem2(CCL_bibset bibset, const char *value,
230 const char *qual_name, const char **addinfo);
232 /** Make CCL qualifier set */
234 CCL_bibset ccl_qual_mk(void);
236 /** Make CCL qualifier set from an existing one (duplicate it) */
238 CCL_bibset ccl_qual_dup(CCL_bibset b);
240 /** Delete CCL qualifier set */
242 void ccl_qual_rm(CCL_bibset *b);
244 /** Char-to-upper function */
245 extern int(*ccl_toupper)(int c);
247 /** CCL version of ccl_stricmp */
249 int ccl_stricmp(const char *s1, const char *s2);
251 /** CCL version of ccl_memicmp */
253 int ccl_memicmp(const char *s1, const char *s2, size_t n);
255 /** Create CCL parser */
257 CCL_parser ccl_parser_create(CCL_bibset bibset);
259 /** Destroy CCL parser */
261 void ccl_parser_destroy(CCL_parser p);
263 /** Search for special qualifier */
265 const char **ccl_qual_search_special(CCL_bibset b, const char *name);
266 /** Pretty-print CCL RPN node tree to WRBUF */
268 void ccl_pquery(WRBUF w, struct ccl_rpn_node *p);
271 int ccl_parser_get_error(CCL_parser cclp, int *pos);
274 struct ccl_rpn_node *ccl_rpn_node_create(enum ccl_rpn_kind kind);
277 void ccl_add_attr_numeric(struct ccl_rpn_node *p, const char *set,
278 int type, int value);
281 void ccl_add_attr_string(struct ccl_rpn_node *p, const char *set,
282 int type, char *value);
285 int ccl_search_stop(CCL_bibset bibset, const char *qname,
286 const char *src_str, size_t src_len);
289 /** \brief stop words handle (pimpl) */
290 typedef struct ccl_stop_words *ccl_stop_words_t;
292 /** \brief creates stop words handle */
294 ccl_stop_words_t ccl_stop_words_create(void);
296 /** \brief destroys stop words handle */
298 void ccl_stop_words_destroy(ccl_stop_words_t csw);
300 /** \brief removes stop words from RPN tree */
302 int ccl_stop_words_tree(ccl_stop_words_t csw,
303 CCL_bibset bibset, struct ccl_rpn_node **t);
305 /** \brief returns information about removed "stop" words */
307 int ccl_stop_words_info(ccl_stop_words_t csw, int idx,
308 const char **qualname, const char **term);
311 struct ccl_rpn_attr *ccl_parser_qual_search(CCL_parser cclp, const char *name,
316 #define ccl_assert(x) ;
320 /** \brief common attributes
327 1-6 relation (<, <=, =, >=, >, <>)
333 3 any position in field
336 0 word/phrase auto select
343 100 date (un-normalized)
344 101 name (normalized)
345 102 name (un-normalized)
350 #define CCL_BIB1_USE 1
351 #define CCL_BIB1_REL 2
352 #define CCL_BIB1_POS 3
353 #define CCL_BIB1_STR 4
354 #define CCL_BIB1_TRU 5
355 #define CCL_BIB1_COM 6
357 #define CCL_BIB1_STR_WP (-1)
358 #define CCL_BIB1_STR_AND_LIST (-2)
359 #define CCL_BIB1_STR_OR_LIST (-3)
360 #define CCL_BIB1_STR_AUTO_GROUP (-4)
361 #define CCL_BIB1_REL_ORDER (-1)
362 #define CCL_BIB1_REL_PORDER (-2)
363 #define CCL_BIB1_REL_OMIT_EQUALS (-3)
365 #define CCL_BIB1_TRU_CAN_LEFT (-1)
366 #define CCL_BIB1_TRU_CAN_RIGHT (-2)
367 #define CCL_BIB1_TRU_CAN_BOTH (-3)
368 #define CCL_BIB1_TRU_CAN_NONE (-4)
369 #define CCL_BIB1_TRU_CAN_REGEX (-5)
370 #define CCL_BIB1_TRU_CAN_Z3958 (-6)
380 * c-file-style: "Stroustrup"
381 * indent-tabs-mode: nil
383 * vim: shiftwidth=4 tabstop=8 expandtab