1 /* CCL - lexical analysis
5 * Revision 1.8 1995/05/11 14:03:57 adam
6 * Changes in the reading of qualifier(s). New function: ccl_qual_fitem.
7 * New variable ccl_case_sensitive, which controls whether reserved
8 * words and field names are case sensitive or not.
10 * Revision 1.7 1995/04/19 12:11:24 adam
13 * Revision 1.6 1995/04/17 09:31:48 adam
14 * Improved handling of qualifiers. Aliases or reserved words.
16 * Revision 1.5 1995/02/23 08:32:00 adam
19 * Revision 1.3 1995/02/15 17:42:16 adam
20 * Minor changes of the api of this module. FILE* argument added
23 * Revision 1.2 1995/02/14 19:55:13 adam
24 * Header files ccl.h/cclp.h are gone! They have been merged an
25 * moved to ../include/ccl.h.
26 * Node kind(s) in ccl_rpn_node have changed names.
28 * Revision 1.1 1995/02/13 12:35:21 adam
29 * First version of CCL. Qualifiers aren't handled yet.
40 const char *ccl_token_and = "and";
41 const char *ccl_token_or = "or";
42 const char *ccl_token_not = "not andnot";
43 const char *ccl_token_set = "set";
44 int ccl_case_sensitive = 1;
47 * token_cmp: Compare token with keyword(s)
48 * kw: Keyword list. Each keyword is separated by space.
50 * return: 1 if token string matches one of the keywords in list;
53 static int token_cmp (const char *kw, struct ccl_token *token)
59 while ((cp2 = strchr (cp1, ' ')))
61 if (token->len == cp2-cp1)
62 if (ccl_case_sensitive)
64 if (!memcmp (cp1, token->name, token->len))
69 if (!ccl_memicmp (cp1, token->name, token->len))
74 if (ccl_case_sensitive)
75 return token->len == strlen(cp1)
76 && !memcmp (cp1, token->name, token->len);
77 return token->len == strlen(cp1) &&
78 !ccl_memicmp (cp1, token->name, token->len);
82 * ccl_tokenize: tokenize CCL command string.
83 * return: CCL token list.
85 struct ccl_token *ccl_tokenize (const char *command)
87 const char *cp = command;
88 struct ccl_token *first = NULL;
89 struct ccl_token *last = NULL;
93 while (*cp && strchr (" \t\r\n", *cp))
100 first = last = malloc (sizeof (*first));
106 last->next = malloc (sizeof(*first));
108 last->next->prev = last;
117 last->kind = CCL_TOK_EOL;
120 last->kind = CCL_TOK_LP;
123 last->kind = CCL_TOK_RP;
126 last->kind = CCL_TOK_COMMA;
130 last->kind = CCL_TOK_PROX;
131 while (*cp == '%' || *cp == '!')
140 if (*cp == '=' || *cp == '<' || *cp == '>')
143 last->kind = CCL_TOK_REL;
146 else if (cp[-1] == '=')
147 last->kind = CCL_TOK_EQ;
149 last->kind = CCL_TOK_REL;
152 last->kind = CCL_TOK_MINUS;
155 last->kind = CCL_TOK_TERM;
158 while (*cp && *cp != '\"')
167 while (*cp && !strchr ("(),%!><=- \t\n\r", *cp))
172 if (token_cmp (ccl_token_and, last))
173 last->kind = CCL_TOK_AND;
174 else if (token_cmp (ccl_token_or, last))
175 last->kind = CCL_TOK_OR;
176 else if (token_cmp (ccl_token_not, last))
177 last->kind = CCL_TOK_NOT;
178 else if (token_cmp (ccl_token_set, last))
179 last->kind = CCL_TOK_SET;
181 last->kind = CCL_TOK_TERM;