1 /* CCL - lexical analysis
5 * Revision 1.2 1995-09-27 15:02:44 quinn
6 * Modified function heads & prototypes.
8 * Revision 1.1 1995/04/10 10:28:22 quinn
11 * Revision 1.5 1995/02/23 08:32:00 adam
14 * Revision 1.3 1995/02/15 17:42:16 adam
15 * Minor changes of the api of this module. FILE* argument added
18 * Revision 1.2 1995/02/14 19:55:13 adam
19 * Header files ccl.h/cclp.h are gone! They have been merged an
20 * moved to ../include/ccl.h.
21 * Node kind(s) in ccl_rpn_node have changed names.
23 * Revision 1.1 1995/02/13 12:35:21 adam
24 * First version of CCL. Qualifiers aren't handled yet.
35 static int strin (const char *s, const char *cset)
45 const char *ccl_token_and = "and";
46 const char *ccl_token_or = "or";
47 const char *ccl_token_not = "not";
48 const char *ccl_token_set = "set";
50 struct ccl_token MDF *ccl_tokenize (const char *command)
52 const char *cp = command;
53 struct ccl_token *first = NULL;
54 struct ccl_token *last = NULL;
58 while (*cp && strin (cp, " \t\r\n"))
65 first = last = malloc (sizeof (*first));
71 last->next = malloc (sizeof(*first));
73 last->next->prev = last;
82 last->kind = CCL_TOK_EOL;
85 last->kind = CCL_TOK_LP;
88 last->kind = CCL_TOK_RP;
91 last->kind = CCL_TOK_COMMA;
95 last->kind = CCL_TOK_PROX;
96 while (*cp == '%' || *cp == '!')
105 if (*cp == '=' || *cp == '<' || *cp == '>')
108 last->kind = CCL_TOK_REL;
111 else if (cp[-1] == '=')
112 last->kind = CCL_TOK_EQ;
114 last->kind = CCL_TOK_REL;
117 last->kind = CCL_TOK_MINUS;
120 last->kind = CCL_TOK_TERM;
123 while (*cp && *cp != '\"')
132 while (*cp && !strin (cp, "(),%!><=- \t\n\r"))
137 if (strlen (ccl_token_and)==last->len &&
138 !memcmp (ccl_token_and, last->name, last->len))
139 last->kind = CCL_TOK_AND;
140 else if (strlen (ccl_token_or)==last->len &&
141 !memcmp (ccl_token_or, last->name, last->len))
142 last->kind = CCL_TOK_OR;
143 else if (strlen (ccl_token_not)==last->len &&
144 !memcmp (ccl_token_not, last->name, last->len))
145 last->kind = CCL_TOK_NOT;
146 else if (strlen (ccl_token_set)==last->len &&
147 !memcmp (ccl_token_set, last->name, last->len))
148 last->kind = CCL_TOK_SET;
150 last->kind = CCL_TOK_TERM;