LICENSE.
[egate.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.7  1995/05/16 09:39:38  adam
50  * LICENSE.
51  *
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.
56  *
57  * Revision 1.5  1995/02/23  08:32:11  adam
58  * Changed header.
59  *
60  * Revision 1.3  1995/02/16  13:20:10  adam
61  * Spell fix.
62  *
63  * Revision 1.2  1995/02/15  17:43:08  adam
64  * Minor changes to the ccl interface. Bug fix in iso2709 module.
65  *
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.
69  *
70  */
71
72 #ifndef CCL_H
73 #define CCL_H
74
75 /* CCL error numbers */
76 #define CCL_ERR_OK                0
77 #define CCL_ERR_TERM_EXPECTED     1
78 #define CCL_ERR_RP_EXPECTED       2
79 #define CCL_ERR_SETNAME_EXPECTED  3
80 #define CCL_ERR_OP_EXPECTED       4
81 #define CCL_ERR_BAD_RP            5
82 #define CCL_ERR_UNKNOWN_QUAL      6
83 #define CCL_ERR_DOUBLE_QUAL       7
84 #define CCL_ERR_EQ_EXPECTED       8
85 #define CCL_ERR_BAD_RELATION      9
86 #define CCL_ERR_TRUNC_NOT_LEFT   10
87 #define CCL_ERR_TRUNC_NOT_BOTH   11
88 #define CCL_ERR_TRUNC_NOT_RIGHT  12
89
90 /* attribute pair (type, value) */
91 struct ccl_rpn_attr {
92     struct ccl_rpn_attr *next;
93     int type;
94     int value;
95 };
96
97 /* RPN tree structure */
98 struct ccl_rpn_node {
99     enum rpn_node_kind {
100         CCL_RPN_AND, CCL_RPN_OR, CCL_RPN_NOT,
101         CCL_RPN_TERM,
102         CCL_RPN_SET,
103         CCL_RPN_PROX
104     } kind;
105     union {
106         struct ccl_rpn_node *p[2];
107         struct {
108             char *term;
109             struct ccl_rpn_attr *attr_list;
110         } t;
111         char *setname;
112     } u;
113 };
114
115 typedef struct ccl_qualifiers *CCL_bibset;
116
117 /* use (1)
118
119    relation (2)
120                             -1  none
121                              0  ordered
122                            1-6  relation (<, <=, =, >=, >, <>)
123
124    position (3)
125                             -1  none
126                              1  first in field
127                              2  first in sub field
128                              3  any position in field
129    structure (4)
130                             -1  none
131                              0  word/phrase auto select
132                              1  phrase
133                              2  word
134                              3  key
135                              4  year
136                              5  date (normalized)
137                              6  word list 
138                            100  date (un-normalized)
139                            101  name (normalized)
140                            102  name (un-normalized)
141    truncation (5)                            
142    completeness (6)
143 */
144
145 #define CCL_BIB1_USE 1
146 #define CCL_BIB1_REL 2
147 #define CCL_BIB1_POS 3
148 #define CCL_BIB1_STR 4
149 #define CCL_BIB1_TRU 5
150 #define CCL_BIB1_COM 6
151
152 #define CCL_BIB1_STR_WP (-1)
153 #define CCL_BIB1_REL_ORDER (-1)
154
155 #define CCL_BIB1_TRU_CAN_LEFT (-1)
156 #define CCL_BIB1_TRU_CAN_RIGHT (-2)
157 #define CCL_BIB1_TRU_CAN_BOTH  (-3)
158 #define CCL_BIB1_TRU_CAN_NONE  (-4)
159
160 #define CCL_TOK_EOL   0
161 #define CCL_TOK_TERM  1
162 #define CCL_TOK_REL   2
163 #define CCL_TOK_EQ    3
164 #define CCL_TOK_PROX  4
165 #define CCL_TOK_LP    5
166 #define CCL_TOK_RP    6
167 #define CCL_TOK_COMMA 7
168 #define CCL_TOK_AND   8
169 #define CCL_TOK_OR    7
170 #define CCL_TOK_NOT   9
171 #define CCL_TOK_MINUS 10
172 #define CCL_TOK_SET   11
173
174 struct ccl_token {
175     char kind;
176     char len;
177     const char *name;
178     struct ccl_token *next;
179     struct ccl_token *prev;
180 };
181
182 struct ccl_qualifier {
183     char *name;
184     struct ccl_rpn_attr *attr_list;
185     struct ccl_qualifier *next;
186 };
187
188 struct ccl_token *ccl_tokenize (const char *command);
189
190 struct ccl_rpn_node *ccl_find_str (CCL_bibset bibset,
191                                    const char *str, int *error, int *pos);
192
193 struct ccl_rpn_node *ccl_find (CCL_bibset abibset, struct ccl_token *list,
194                                int *error, const char **pos);
195 char *ccl_err_msg (int ccl_errno);
196 void ccl_rpn_delete (struct ccl_rpn_node *rpn);
197 void ccl_pr_tree (struct ccl_rpn_node *rpn, FILE *fd_out);
198
199 void ccl_qual_add (CCL_bibset b, const char *name, int no, int *attr);
200 void ccl_qual_file (CCL_bibset bibset, FILE *inf);
201 void ccl_qual_fitem (CCL_bibset bibset, const char *cp, const char *qual_name);
202 CCL_bibset ccl_qual_mk (void);
203 void ccl_qual_rm (CCL_bibset *b);
204
205 extern const char *ccl_token_and;
206 extern const char *ccl_token_or;
207 extern const char *ccl_token_not;
208 extern const char *ccl_token_set;
209 extern int ccl_case_sensitive;
210 extern int (*ccl_toupper)(int c);
211
212 int ccl_stricmp (const char *s1, const char *s2);
213 int ccl_memicmp (const char *s1, const char *s2, size_t n);
214
215 struct ccl_rpn_attr *ccl_qual_search (CCL_bibset b, const char *name, int len);
216 #endif
217