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