2 * Copyright (c) 1995, the EUROPAGATE consortium (see below).
4 * The EUROPAGATE consortium members are:
6 * University College Dublin
7 * Danmarks Teknologiske Videnscenter
8 * An Chomhairle Leabharlanna
9 * Consejo Superior de Investigaciones Cientificas
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,
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.
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.
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.
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.
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.
44 /* CCL - lexical analysis
47 * $Log: ccltoken.c,v $
48 * Revision 1.9 1995/05/16 09:39:28 adam
51 * Revision 1.8 1995/05/11 14:03:57 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.7 1995/04/19 12:11:24 adam
59 * Revision 1.6 1995/04/17 09:31:48 adam
60 * Improved handling of qualifiers. Aliases or reserved words.
62 * Revision 1.5 1995/02/23 08:32:00 adam
65 * Revision 1.3 1995/02/15 17:42:16 adam
66 * Minor changes of the api of this module. FILE* argument added
69 * Revision 1.2 1995/02/14 19:55:13 adam
70 * Header files ccl.h/cclp.h are gone! They have been merged an
71 * moved to ../include/ccl.h.
72 * Node kind(s) in ccl_rpn_node have changed names.
74 * Revision 1.1 1995/02/13 12:35:21 adam
75 * First version of CCL. Qualifiers aren't handled yet.
86 const char *ccl_token_and = "and";
87 const char *ccl_token_or = "or";
88 const char *ccl_token_not = "not andnot";
89 const char *ccl_token_set = "set";
90 int ccl_case_sensitive = 1;
93 * token_cmp: Compare token with keyword(s)
94 * kw: Keyword list. Each keyword is separated by space.
96 * return: 1 if token string matches one of the keywords in list;
99 static int token_cmp (const char *kw, struct ccl_token *token)
101 const char *cp1 = kw;
105 while ((cp2 = strchr (cp1, ' ')))
107 if (token->len == cp2-cp1)
108 if (ccl_case_sensitive)
110 if (!memcmp (cp1, token->name, token->len))
115 if (!ccl_memicmp (cp1, token->name, token->len))
120 if (ccl_case_sensitive)
121 return token->len == strlen(cp1)
122 && !memcmp (cp1, token->name, token->len);
123 return token->len == strlen(cp1) &&
124 !ccl_memicmp (cp1, token->name, token->len);
128 * ccl_tokenize: tokenize CCL command string.
129 * return: CCL token list.
131 struct ccl_token *ccl_tokenize (const char *command)
133 const char *cp = command;
134 struct ccl_token *first = NULL;
135 struct ccl_token *last = NULL;
139 while (*cp && strchr (" \t\r\n", *cp))
146 first = last = malloc (sizeof (*first));
152 last->next = malloc (sizeof(*first));
154 last->next->prev = last;
163 last->kind = CCL_TOK_EOL;
166 last->kind = CCL_TOK_LP;
169 last->kind = CCL_TOK_RP;
172 last->kind = CCL_TOK_COMMA;
176 last->kind = CCL_TOK_PROX;
177 while (*cp == '%' || *cp == '!')
186 if (*cp == '=' || *cp == '<' || *cp == '>')
189 last->kind = CCL_TOK_REL;
192 else if (cp[-1] == '=')
193 last->kind = CCL_TOK_EQ;
195 last->kind = CCL_TOK_REL;
198 last->kind = CCL_TOK_MINUS;
201 last->kind = CCL_TOK_TERM;
204 while (*cp && *cp != '\"')
213 while (*cp && !strchr ("(),%!><=- \t\n\r", *cp))
218 if (token_cmp (ccl_token_and, last))
219 last->kind = CCL_TOK_AND;
220 else if (token_cmp (ccl_token_or, last))
221 last->kind = CCL_TOK_OR;
222 else if (token_cmp (ccl_token_not, last))
223 last->kind = CCL_TOK_NOT;
224 else if (token_cmp (ccl_token_set, last))
225 last->kind = CCL_TOK_SET;
227 last->kind = CCL_TOK_TERM;