Added copy of CCL.
[yaz-moved-to-github.git] / include / ccl.h
1 /* CCL - header file
2  * Europagate, 1995
3  *
4  * $Log: ccl.h,v $
5  * Revision 1.1  1995-04-10 10:28:27  quinn
6  * Added copy of CCL.
7  *
8  * Revision 1.5  1995/02/23  08:32:11  adam
9  * Changed header.
10  *
11  * Revision 1.3  1995/02/16  13:20:10  adam
12  * Spell fix.
13  *
14  * Revision 1.2  1995/02/15  17:43:08  adam
15  * Minor changes to the ccl interface. Bug fix in iso2709 module.
16  *
17  * Revision 1.1  1995/02/14  19:55:21  adam
18  * Header files ccl.h/cclp.h are gone! They have been merged an
19  * moved to ../include/ccl.h.
20  *
21  */
22
23 #ifndef CCL_H
24 #define CCL_H
25
26 /* CCL error numbers */
27 #define CCL_ERR_OK                0
28 #define CCL_ERR_TERM_EXPECTED     1
29 #define CCL_ERR_RP_EXPECTED       2
30 #define CCL_ERR_SETNAME_EXPECTED  3
31 #define CCL_ERR_OP_EXPECTED       4
32 #define CCL_ERR_BAD_RP            5
33 #define CCL_ERR_UNKNOWN_QUAL      6
34 #define CCL_ERR_DOUBLE_QUAL       7
35 #define CCL_ERR_EQ_EXPECTED       8
36 #define CCL_ERR_BAD_RELATION      9
37 #define CCL_ERR_TRUNC_NOT_LEFT   10
38 #define CCL_ERR_TRUNC_NOT_BOTH   11
39 #define CCL_ERR_TRUNC_NOT_RIGHT  12
40
41 /* attribute pair (type, value) */
42 struct ccl_rpn_attr {
43     struct ccl_rpn_attr *next;
44     int type;
45     int value;
46 };
47
48 /* RPN tree structure */
49 struct ccl_rpn_node {
50     enum rpn_node_kind {
51         CCL_RPN_AND, CCL_RPN_OR, CCL_RPN_NOT,
52         CCL_RPN_TERM,
53         CCL_RPN_SET,
54         CCL_RPN_PROX
55     } kind;
56     union {
57         struct ccl_rpn_node *p[2];
58         struct {
59             char *term;
60             struct ccl_rpn_attr *attr_list;
61         } t;
62         char *setname;
63     } u;
64 };
65
66 typedef struct ccl_qualifiers *CCL_bibset;
67
68 /* use (1)
69
70    relation (2)
71                             -1  none
72                              0  ordered
73                            1-6  relation (<, <=, =, >=, >, <>)
74
75    position (3)
76                             -1  none
77                              1  first in field
78                              2  first in sub field
79                              3  any position in field
80    structure (4)
81                             -1  none
82                              0  word/phrase auto select
83                              1  phrase
84                              2  word
85                              3  key
86                              4  year
87                              5  date (normalized)
88                              6  word list 
89                            100  date (un-normalized)
90                            101  name (normalized)
91                            102  name (un-normalized)
92    truncation (5)                            
93    completeness (6)
94 */
95
96 #define CCL_BIB1_USE 1
97 #define CCL_BIB1_REL 2
98 #define CCL_BIB1_POS 3
99 #define CCL_BIB1_STR 4
100 #define CCL_BIB1_TRU 5
101 #define CCL_BIB1_COM 6
102
103 #define CCL_BIB1_STR_WP (-1)
104 #define CCL_BIB1_REL_ORDER (-1)
105
106 #define CCL_BIB1_TRU_CAN_LEFT (-1)
107 #define CCL_BIB1_TRU_CAN_RIGHT (-2)
108 #define CCL_BIB1_TRU_CAN_BOTH  (-3)
109 #define CCL_BIB1_TRU_CAN_NONE  (-4)
110
111 #define CCL_TOK_EOL   0
112 #define CCL_TOK_TERM  1
113 #define CCL_TOK_REL   2
114 #define CCL_TOK_EQ    3
115 #define CCL_TOK_PROX  4
116 #define CCL_TOK_LP    5
117 #define CCL_TOK_RP    6
118 #define CCL_TOK_COMMA 7
119 #define CCL_TOK_AND   8
120 #define CCL_TOK_OR    7
121 #define CCL_TOK_NOT   9
122 #define CCL_TOK_MINUS 10
123 #define CCL_TOK_SET   11
124
125 struct ccl_token {
126     char kind;
127     char len;
128     const char *name;
129     struct ccl_token *next;
130     struct ccl_token *prev;
131 };
132
133 struct ccl_qualifier {
134     char *name;
135     struct ccl_rpn_attr *attr_list;
136     struct ccl_qualifier *next;
137 };
138
139 struct ccl_token *ccl_tokenize (const char *command);
140
141 struct ccl_rpn_node *ccl_find_str (CCL_bibset bibset,
142                                    const char *str, int *error, int *pos);
143
144 struct ccl_rpn_node *ccl_find (CCL_bibset abibset, struct ccl_token *list,
145                                int *error, const char **pos);
146 char *ccl_err_msg (int ccl_errno);
147 void ccl_rpn_delete (struct ccl_rpn_node *rpn);
148 void ccl_pr_tree (struct ccl_rpn_node *rpn, FILE *fd_out);
149
150 void ccl_qual_add (CCL_bibset b, const char *name, int no, int *attr);
151 void ccl_qual_file (CCL_bibset bibset, FILE *inf);
152 CCL_bibset ccl_qual_mk (void);
153 void ccl_qual_rm (CCL_bibset *b);
154
155 extern const char *ccl_token_and;
156 extern const char *ccl_token_or;
157 extern const char *ccl_token_not;
158 extern const char *ccl_token_set;
159
160
161 struct ccl_rpn_attr *ccl_qual_search (CCL_bibset b, const char *name, int len);
162 #endif
163