5 * The contents of this file are subject to the terms of the
6 * Common Development and Distribution License, Version 1.0 only
7 * (the "License"). You may not use this file except in compliance
10 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 * or http://www.opensolaris.org/os/licensing.
12 * See the License for the specific language governing permissions
13 * and limitations under the License.
15 * When distributing Covered Code, include this CDDL HEADER in each
16 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 * If applicable, add the following below this CDDL HEADER, with the
18 * fields enclosed by brackets "[]" replaced with your own identifying
19 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
28 #pragma error_messages(off, E_STATEMENT_NOT_REACHED)
34 * poolcfg.l implements a lexer for the poolcfg(1) utility.The lexer uses
35 * the token definitions generated by YACC in the file poolcfg_Grammar.h.
36 * To make token recognition simpler, the lexer uses a separate state for
37 * each of the different data types supported by poolcfg(1).
40 * Lex provides the ability to minimise conflict between qualifying regexps
41 * by providing states. A regexp that is qualified by a state will only be
42 * used when the state is entered (using the BEGIN <state> command). (The
43 * exception to this rule, is that rules defined in the default state are
44 * available in all states.)
46 * poolcfg.l makes use of type states, one for each of the poolcfg(1)
47 * supported data types:
52 * SSTATE => const char *
55 * and a further state, CPUSTATE, to indicate the difference between matching
56 * a valid "name" (i.e. id) for a cpu and a valid name for other components of
59 * When a token indicating a variable declaration is matched, the corresponding
60 * state is saved in the state variable. Once the assignment ('=') token is
61 * matched, the stored state is entered and the additional state specific
62 * matching regular expressions become available. Once a state specific
63 * token is matched, the default state is restored.
67 #include <sys/types.h>
76 #include "poolcfg_grammar.h"
78 static int lex_lineno = 1; /* line-number for error reporting */
79 static int state = INITIAL; /* state to be used */
80 extern void yyerror(char *s);
81 extern int dofile; /* are we processing a file? */
99 info { return PCC_INFO; }
101 create { return PCC_CREATE; }
103 destroy { return PCC_DESTROY; }
105 modify { return PCC_MODIFY; }
107 associate { return PCC_ASSOC; }
114 discover { return PCC_DISC; }
116 rename { return PCC_RENAME; }
118 to { return PCK_TO; }
120 from { return PCK_FROM; }
152 pset { return PCE_PSET; }
154 pool { return PCE_POOL; }
156 system { return PCE_SYSTEM; }
158 \( { return PCK_OPENLST; }
160 \) { return PCK_CLOSELST; }
167 \; { return PCK_SEPLST; }
169 ~ { return PCK_UNDEF; }
172 yylval.ival = strtoll(yytext, NULL, 0);
173 if (errno == EINVAL || errno == ERANGE) {
174 yyerror(gettext("Invalid value"));
182 yylval.uval = strtoull(yytext, NULL, 0);
183 if (errno == EINVAL || errno == ERANGE) {
184 yyerror(gettext("Invalid value"));
193 if (strcmp(yytext, "true") == 0)
198 return PCV_VAL_BOOLEAN;
201 <SSTATE>\"[^\"\n]*[\"\n] {
202 if((yylval.sval = strdup(yytext+1)) == NULL) {
203 yyerror(gettext("Out of memory"));
206 if (yylval.sval[yyleng-2] =='"')
207 yylval.sval[yyleng-2] = 0;
209 return PCV_VAL_STRING;
212 <DSTATE>([0-9]+|([0-9]*\.[0-9]+)([eE][-+]?[0-9]+)?) {
213 yylval.dval = strtod(yytext, (char **)NULL);
214 if (errno == EINVAL || errno == ERANGE) {
215 yyerror(gettext("Invalid value"));
219 return PCV_VAL_FLOAT;
222 [A-Za-z][A-Za-z0-9,._-]* {
223 if ((yylval.sval = strdup(yytext)) == NULL) {
224 yyerror(gettext("Out of memory"));
231 if ((yylval.sval = strdup(yytext)) == NULL) {
232 yyerror(gettext("Out of memory"));
239 yyerror(gettext("Illegal character"));
248 if (dofile == PO_TRUE) {
249 if (yytext[0] == '\0') {
250 (void) warn(gettext("line %d, %s, token expected\n"),
254 (void) warn(gettext("line %d, %s at '%s'\n"), lex_lineno, s,
257 if (yytext[0] == '\0') {
258 (void) warn(gettext("%s, token expected\n"), s);
261 (void) warn(gettext("%s at '%s'\n"), s, yytext);