xref: /titanic_44/usr/src/cmd/zonecfg/zonecfg_lex.l (revision 02e56f3f1bfc8d9977bafb8cb5202f576dcded27)
1 %{
2 /*
3  * CDDL HEADER START
4  *
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
8  * with the License.
9  *
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.
14  *
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]
20  *
21  * CDDL HEADER END
22  *
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <string.h>
30 #include <libintl.h>
31 #include "zonecfg.h"
32 #include "zonecfg_grammar.tab.h"
33 
34 int lex_lineno = 1;	/* line number for error reporting */
35 static int state = INITIAL;
36 extern bool cmd_file_mode;
37 extern bool saw_error;
38 extern void yyerror(char *s);
39 char *safe_strdup(char *s);
40 %}
41 
42 %a 3000
43 
44 %{
45 /*
46  * The three states below are for tokens, lists and complex property values.
47  * Note that simple property values are a subset of tokens.
48  */
49 %}
50 %s TSTATE
51 %s LSTATE
52 %s CSTATE
53 %%
54 
55 <INITIAL>"#"[^\n]*	{ }
56 
57 <INITIAL>add	{
58 			BEGIN TSTATE;
59 			state = TSTATE;
60 			return ADD;
61 		}
62 
63 <INITIAL>cancel	{
64 			BEGIN TSTATE;
65 			state = TSTATE;
66 			return CANCEL;
67 		}
68 
69 <INITIAL>commit	{
70 			BEGIN TSTATE;
71 			state = TSTATE;
72 			return COMMIT;
73 		}
74 
75 <INITIAL>create	{
76 			BEGIN TSTATE;
77 			state = TSTATE;
78 			return CREATE;
79 		}
80 
81 <INITIAL>delete {
82 			BEGIN TSTATE;
83 			state = TSTATE;
84 			return DELETE;
85 		}
86 
87 <INITIAL>end	{
88 			BEGIN TSTATE;
89 			state = TSTATE;
90 			return END;
91 		}
92 
93 <INITIAL>exit	{
94 			BEGIN TSTATE;
95 			state = TSTATE;
96 			return EXIT;
97 		}
98 
99 <INITIAL>export	{
100 			BEGIN TSTATE;
101 			state = TSTATE;
102 			return EXPORT;
103 		}
104 
105 <INITIAL>"?"|help {
106 			BEGIN TSTATE;
107 			state = TSTATE;
108 			return HELP;
109 		}
110 
111 <INITIAL>info	{
112 			BEGIN TSTATE;
113 			state = TSTATE;
114 			return INFO;
115 		}
116 
117 <INITIAL>remove	{
118 			BEGIN TSTATE;
119 			state = TSTATE;
120 			return REMOVE;
121 		}
122 
123 <INITIAL>revert	{
124 			BEGIN TSTATE;
125 			state = TSTATE;
126 			return REVERT;
127 		}
128 
129 <INITIAL>select {
130 			BEGIN TSTATE;
131 			state = TSTATE;
132 			return SELECT;
133 		}
134 
135 <INITIAL>set {
136 			BEGIN TSTATE;
137 			state = TSTATE;
138 			return SET;
139 		}
140 
141 <INITIAL>verify	{
142 			BEGIN TSTATE;
143 			state = TSTATE;
144 			return VERIFY;
145 		}
146 
147 <TSTATE>net	{ return NET; }
148 
149 <TSTATE>fs	{ return FS; }
150 
151 <TSTATE>inherit-pkg-dir	{ return IPD; }
152 
153 <TSTATE>device	{ return DEVICE; }
154 
155 <TSTATE>rctl	{ return RCTL; }
156 
157 <TSTATE>attr	{ return ATTR; }
158 
159 <TSTATE>zonename	{ return ZONENAME; }
160 <CSTATE>zonename	{ return ZONENAME; }
161 
162 <TSTATE>zonepath	{ return ZONEPATH; }
163 <CSTATE>zonepath	{ return ZONEPATH; }
164 
165 <TSTATE>autoboot	{ return AUTOBOOT; }
166 <CSTATE>autoboot	{ return AUTOBOOT; }
167 
168 <TSTATE>pool	{ return POOL; }
169 <CSTATE>pool	{ return POOL; }
170 
171 <TSTATE>type	{ return TYPE; }
172 <CSTATE>type	{ return TYPE; }
173 
174 <TSTATE>value	{ return VALUE; }
175 <CSTATE>value	{ return VALUE; }
176 
177 <TSTATE>options	{ return OPTIONS; }
178 <CSTATE>options	{ return OPTIONS; }
179 
180 <TSTATE>address	{ return ADDRESS; }
181 <CSTATE>address	{ return ADDRESS; }
182 
183 <TSTATE>physical	{ return PHYSICAL; }
184 <CSTATE>physical	{ return PHYSICAL; }
185 
186 <TSTATE>dir	{ return DIR; }
187 <CSTATE>dir	{ return DIR; }
188 
189 <TSTATE>special	{ return SPECIAL; }
190 <CSTATE>special	{ return SPECIAL; }
191 
192 <TSTATE>raw	{ return RAW; }
193 <CSTATE>raw	{ return RAW; }
194 
195 <TSTATE>name	{ return NAME; }
196 <CSTATE>name	{ return NAME; }
197 
198 <TSTATE>match	{ return MATCH; }
199 <CSTATE>match	{ return MATCH; }
200 
201 <TSTATE>priv	{ return PRIV; }
202 <CSTATE>priv	{ return PRIV; }
203 
204 <TSTATE>limit	{ return LIMIT; }
205 <CSTATE>limit	{ return LIMIT; }
206 
207 <TSTATE>action	{ return ACTION; }
208 <CSTATE>action	{ return ACTION; }
209 
210 <TSTATE>=	{ return EQUAL; }
211 <LSTATE>=	{ return EQUAL; }
212 <CSTATE>=	{ return EQUAL; }
213 
214 <TSTATE>"["	{
215 			BEGIN LSTATE;
216 			state = LSTATE;
217 			return OPEN_SQ_BRACKET;
218 		}
219 
220 <LSTATE>"]"	{
221 			BEGIN TSTATE;
222 			state = TSTATE;
223 			return CLOSE_SQ_BRACKET;
224 		}
225 
226 <TSTATE>"("	{
227 			BEGIN CSTATE;
228 			return OPEN_PAREN;
229 		}
230 
231 <LSTATE>"("	{
232 			BEGIN CSTATE;
233 			return OPEN_PAREN;
234 		}
235 
236 <CSTATE>")"	{
237 			BEGIN state;
238 			return CLOSE_PAREN;
239 		}
240 
241 <LSTATE>","	{ return COMMA; }
242 <CSTATE>","	{ return COMMA; }
243 
244 <TSTATE>[^ \t\n\";=\[\]\(\)]+	{
245 			yylval.strval = safe_strdup(yytext);
246 			return TOKEN;
247 		}
248 
249 <LSTATE>[^ \t\n\",;=\[\]\(\)]+	{
250 			yylval.strval = safe_strdup(yytext);
251 			return TOKEN;
252 		}
253 
254 <CSTATE>[^ \t\n\",;=\(\)]+	{
255 			yylval.strval = safe_strdup(yytext);
256 			return TOKEN;
257 		}
258 
259 <TSTATE>\"[^\"\n]*[\"\n] {
260 			yylval.strval = safe_strdup(yytext + 1);
261 			if (yylval.strval[yyleng - 2] == '"')
262 				yylval.strval[yyleng - 2] = 0;
263 			return TOKEN;
264 		}
265 
266 <LSTATE>\"[^\"\n]*[\"\n] {
267 			yylval.strval = safe_strdup(yytext + 1);
268 			if (yylval.strval[yyleng - 2] == '"')
269 				yylval.strval[yyleng - 2] = 0;
270 			return TOKEN;
271 		}
272 
273 ";"		{
274 			BEGIN INITIAL;
275 			return (yytext[0]);
276 		}
277 
278 \n		{
279 			lex_lineno++;
280 			BEGIN INITIAL;
281 			return (yytext[0]);
282 		}
283 
284 [ \t]		;	/* Ignore whitespace */
285 
286 .		{
287 			return (yytext[0]);
288 		}
289 
290 %%
291 
292 char *
293 safe_strdup(char *s)
294 {
295 	char *result;
296 
297 	if ((result = strdup(s)) == NULL) {
298 		yyerror("Out of memory");
299 		exit(Z_ERR);
300 	}
301 	return (result);
302 }
303 
304 void
305 yyerror(char *s)
306 {
307 	/* feof(yyin) is not an error; anything else is, so we set saw_error */
308 	if (yytext[0] == '\0') {
309 		if (!feof(yyin)) {
310 			saw_error = TRUE;
311 			(void) fprintf(stderr, gettext("%s, token expected\n"),
312 			    s);
313 		}
314 		return;
315 	}
316 
317 	saw_error = TRUE;
318 	if (cmd_file_mode)
319 		(void) fprintf(stderr, gettext("%s on line %d at '%s'\n"), s,
320 		    lex_lineno, (yytext[0] == '\n') ? "\\n" : yytext);
321 	else
322 		(void) fprintf(stderr, gettext("%s at '%s'\n"), s,
323 		    (yytext[0] == '\n') ? "\\n" : yytext);
324 	usage(FALSE, HELP_SUBCMDS);
325 }
326