xref: /titanic_50/usr/src/cmd/zonecfg/zonecfg_lex.l (revision c9a6ea2e938727c95af7108c5e00eee4c890c7ae)
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 (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
25  */
26 
27 #include <string.h>
28 #include <libintl.h>
29 #include "zonecfg.h"
30 #include "zonecfg_grammar.tab.h"
31 
32 int lex_lineno = 1;	/* line number for error reporting */
33 static int state = INITIAL;
34 extern boolean_t cmd_file_mode;
35 extern boolean_t saw_error;
36 extern void yyerror(char *s);
37 char *safe_strdup(char *s);
38 %}
39 
40 %a 7000
41 %p 5000
42 %e 2000
43 %n 1000
44 
45 %{
46 /*
47  * The three states below are for tokens, lists and complex property values.
48  * Note that simple property values are a subset of tokens.
49  */
50 %}
51 %s TSTATE
52 %s LSTATE
53 %s CSTATE
54 %%
55 
56 <INITIAL>"#"[^\n]*	{ }
57 
58 <INITIAL>add	{
59 			BEGIN TSTATE;
60 			state = TSTATE;
61 			return ADD;
62 		}
63 
64 <INITIAL>cancel	{
65 			BEGIN TSTATE;
66 			state = TSTATE;
67 			return CANCEL;
68 		}
69 
70 <INITIAL>commit	{
71 			BEGIN TSTATE;
72 			state = TSTATE;
73 			return COMMIT;
74 		}
75 
76 <INITIAL>create	{
77 			BEGIN TSTATE;
78 			state = TSTATE;
79 			return CREATE;
80 		}
81 
82 <INITIAL>delete {
83 			BEGIN TSTATE;
84 			state = TSTATE;
85 			return DELETE;
86 		}
87 
88 <INITIAL>end	{
89 			BEGIN TSTATE;
90 			state = TSTATE;
91 			return END;
92 		}
93 
94 <INITIAL>exit	{
95 			BEGIN TSTATE;
96 			state = TSTATE;
97 			return EXIT;
98 		}
99 
100 <INITIAL>export	{
101 			BEGIN TSTATE;
102 			state = TSTATE;
103 			return EXPORT;
104 		}
105 
106 <INITIAL>"?"|help {
107 			BEGIN TSTATE;
108 			state = TSTATE;
109 			return HELP;
110 		}
111 
112 <INITIAL>info	{
113 			BEGIN TSTATE;
114 			state = TSTATE;
115 			return INFO;
116 		}
117 
118 <INITIAL>remove	{
119 			BEGIN TSTATE;
120 			state = TSTATE;
121 			return REMOVE;
122 		}
123 
124 <INITIAL>revert	{
125 			BEGIN TSTATE;
126 			state = TSTATE;
127 			return REVERT;
128 		}
129 
130 <INITIAL>select {
131 			BEGIN TSTATE;
132 			state = TSTATE;
133 			return SELECT;
134 		}
135 
136 <INITIAL>set {
137 			BEGIN TSTATE;
138 			state = TSTATE;
139 			return SET;
140 		}
141 
142 <INITIAL>clear {
143 			BEGIN TSTATE;
144 			state = TSTATE;
145 			return CLEAR;
146 		}
147 
148 <INITIAL>verify	{
149 			BEGIN TSTATE;
150 			state = TSTATE;
151 			return VERIFY;
152 		}
153 
154 <TSTATE>net	{ return NET; }
155 
156 <TSTATE>fs	{ return FS; }
157 
158 <TSTATE>device	{ return DEVICE; }
159 
160 <TSTATE>rctl	{ return RCTL; }
161 
162 <TSTATE>attr	{ return ATTR; }
163 
164 <TSTATE>admin	{ return ADMIN; }
165 
166 <TSTATE>zonename	{ return ZONENAME; }
167 <CSTATE>zonename	{ return ZONENAME; }
168 
169 <TSTATE>dataset	{ return DATASET; }
170 
171 <TSTATE>dedicated-cpu	{ return PSET; }
172 
173 <TSTATE>capped-cpu	{ return PCAP; }
174 
175 <TSTATE>capped-memory	{ return MCAP; }
176 
177 <TSTATE>zonepath	{ return ZONEPATH; }
178 <CSTATE>zonepath	{ return ZONEPATH; }
179 
180 <TSTATE>brand	{ return BRAND; }
181 <CSTATE>brand	{ return BRAND; }
182 
183 <TSTATE>autoboot	{ return AUTOBOOT; }
184 <CSTATE>autoboot	{ return AUTOBOOT; }
185 
186 <TSTATE>ip-type		{ return IPTYPE; }
187 <CSTATE>ip-type		{ return IPTYPE; }
188 
189 <TSTATE>pool	{ return POOL; }
190 <CSTATE>pool	{ return POOL; }
191 
192 <TSTATE>limitpriv	{ return LIMITPRIV; }
193 <CSTATE>limitpriv	{ return LIMITPRIV; }
194 
195 <TSTATE>bootargs	{ return BOOTARGS; }
196 <CSTATE>bootargs	{ return BOOTARGS; }
197 
198 <TSTATE>type	{ return TYPE; }
199 <CSTATE>type	{ return TYPE; }
200 
201 <TSTATE>value	{ return VALUE; }
202 <CSTATE>value	{ return VALUE; }
203 
204 <TSTATE>options	{ return OPTIONS; }
205 <CSTATE>options	{ return OPTIONS; }
206 
207 <TSTATE>allowed-address { return ALLOWED_ADDRESS; }
208 <CSTATE>allowed-address { return ALLOWED_ADDRESS; }
209 
210 <TSTATE>address	{ return ADDRESS; }
211 <CSTATE>address	{ return ADDRESS; }
212 
213 <TSTATE>physical	{ return PHYSICAL; }
214 <CSTATE>physical	{ return PHYSICAL; }
215 
216 <TSTATE>defrouter	{ return DEFROUTER; }
217 <CSTATE>defrouter	{ return DEFROUTER; }
218 
219 <TSTATE>dir	{ return DIR; }
220 <CSTATE>dir	{ return DIR; }
221 
222 <TSTATE>special	{ return SPECIAL; }
223 <CSTATE>special	{ return SPECIAL; }
224 
225 <TSTATE>raw	{ return RAW; }
226 <CSTATE>raw	{ return RAW; }
227 
228 <TSTATE>name	{ return NAME; }
229 <CSTATE>name	{ return NAME; }
230 
231 <TSTATE>match	{ return MATCH; }
232 <CSTATE>match	{ return MATCH; }
233 
234 <TSTATE>priv	{ return PRIV; }
235 <CSTATE>priv	{ return PRIV; }
236 
237 <TSTATE>limit	{ return LIMIT; }
238 <CSTATE>limit	{ return LIMIT; }
239 
240 <TSTATE>action	{ return ACTION; }
241 <CSTATE>action	{ return ACTION; }
242 
243 <TSTATE>ncpus	{ return NCPUS; }
244 <CSTATE>ncpus	{ return NCPUS; }
245 
246 <TSTATE>locked	{ return LOCKED; }
247 <CSTATE>locked	{ return LOCKED; }
248 
249 <TSTATE>swap	{ return SWAP; }
250 <CSTATE>swap	{ return SWAP; }
251 
252 <TSTATE>importance	{ return IMPORTANCE; }
253 <CSTATE>importance	{ return IMPORTANCE; }
254 
255 <TSTATE>cpu-shares	{ return SHARES; }
256 <CSTATE>cpu-shares	{ return SHARES; }
257 
258 <TSTATE>max-lwps	{ return MAXLWPS; }
259 <CSTATE>max-lwps	{ return MAXLWPS; }
260 
261 <TSTATE>max-processes	{ return MAXPROCS; }
262 <CSTATE>max-processes	{ return MAXPROCS; }
263 
264 <TSTATE>max-shm-memory	{ return MAXSHMMEM; }
265 <CSTATE>max-shm-memory	{ return MAXSHMMEM; }
266 
267 <TSTATE>max-shm-ids	{ return MAXSHMIDS; }
268 <CSTATE>max-shm-ids	{ return MAXSHMIDS; }
269 
270 <TSTATE>max-msg-ids	{ return MAXMSGIDS; }
271 <CSTATE>max-msg-ids	{ return MAXMSGIDS; }
272 
273 <TSTATE>max-sem-ids	{ return MAXSEMIDS; }
274 <CSTATE>max-sem-ids	{ return MAXSEMIDS; }
275 
276 <TSTATE>scheduling-class	{ return SCHED; }
277 <CSTATE>scheduling-class	{ return SCHED; }
278 
279 <TSTATE>hostid		{ return HOSTID; }
280 <CSTATE>hostid		{ return HOSTID; }
281 
282 <TSTATE>user	{ return USER; }
283 <CSTATE>user	{ return USER; }
284 
285 <TSTATE>auths	{ return AUTHS; }
286 <CSTATE>auths	{ return AUTHS; }
287 
288 <TSTATE>fs-allowed	{ return FS_ALLOWED; }
289 <CSTATE>fs-allowed	{ return FS_ALLOWED; }
290 
291 <TSTATE>=	{ return EQUAL; }
292 <LSTATE>=	{ return EQUAL; }
293 <CSTATE>=	{ return EQUAL; }
294 
295 <TSTATE>"["	{
296 			BEGIN LSTATE;
297 			state = LSTATE;
298 			return OPEN_SQ_BRACKET;
299 		}
300 
301 <LSTATE>"]"	{
302 			BEGIN TSTATE;
303 			state = TSTATE;
304 			return CLOSE_SQ_BRACKET;
305 		}
306 
307 <TSTATE>"("	{
308 			BEGIN CSTATE;
309 			return OPEN_PAREN;
310 		}
311 
312 <LSTATE>"("	{
313 			BEGIN CSTATE;
314 			return OPEN_PAREN;
315 		}
316 
317 <CSTATE>")"	{
318 			BEGIN state;
319 			return CLOSE_PAREN;
320 		}
321 
322 <LSTATE>","	{ return COMMA; }
323 <CSTATE>","	{ return COMMA; }
324 
325 <TSTATE>[^ \t\n\";=\[\]\(\)]+	{
326 			yylval.strval = safe_strdup(yytext);
327 			return TOKEN;
328 		}
329 
330 <LSTATE>[^ \t\n\",;=\[\]\(\)]+	{
331 			yylval.strval = safe_strdup(yytext);
332 			return TOKEN;
333 		}
334 
335 <CSTATE>[^ \t\n\",;=\(\)]+	{
336 			yylval.strval = safe_strdup(yytext);
337 			return TOKEN;
338 		}
339 
340 <TSTATE>\"[^\"\n]*[\"\n] {
341 			yylval.strval = safe_strdup(yytext + 1);
342 			if (yylval.strval[yyleng - 2] == '"')
343 				yylval.strval[yyleng - 2] = 0;
344 			return TOKEN;
345 		}
346 
347 <LSTATE>\"[^\"\n]*[\"\n] {
348 			yylval.strval = safe_strdup(yytext + 1);
349 			if (yylval.strval[yyleng - 2] == '"')
350 				yylval.strval[yyleng - 2] = 0;
351 			return TOKEN;
352 		}
353 
354 ";"		{
355 			BEGIN INITIAL;
356 			return (yytext[0]);
357 		}
358 
359 \n		{
360 			lex_lineno++;
361 			BEGIN INITIAL;
362 			return (yytext[0]);
363 		}
364 
365 [ \t]		;	/* Ignore whitespace */
366 
367 .		{
368 			return (yytext[0]);
369 		}
370 
371 %%
372 
373 char *
374 safe_strdup(char *s)
375 {
376 	char *result;
377 
378 	if ((result = strdup(s)) == NULL) {
379 		yyerror("Out of memory");
380 		exit(Z_ERR);
381 	}
382 	return (result);
383 }
384 
385 void
386 yyerror(char *s)
387 {
388 	/* feof(yyin) is not an error; anything else is, so we set saw_error */
389 	if (yytext[0] == '\0') {
390 		if (!feof(yyin)) {
391 			saw_error = B_TRUE;
392 			(void) fprintf(stderr, gettext("%s, token expected\n"),
393 			    s);
394 		}
395 		return;
396 	}
397 
398 	saw_error = B_TRUE;
399 	if (cmd_file_mode)
400 		(void) fprintf(stderr, gettext("%s on line %d at '%s'\n"), s,
401 		    lex_lineno, (yytext[0] == '\n') ? "\\n" : yytext);
402 	else
403 		(void) fprintf(stderr, gettext("%s at '%s'\n"), s,
404 		    (yytext[0] == '\n') ? "\\n" : yytext);
405 	usage(B_FALSE, HELP_SUBCMDS);
406 }
407