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