xref: /titanic_50/usr/src/cmd/zonecfg/zonecfg_lex.l (revision 44c4f64b9f50f21ae3e51ad48a595c85f53db4bc)
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>inherit-pkg-dir	{ return IPD; }
159 
160 <TSTATE>device	{ return DEVICE; }
161 
162 <TSTATE>rctl	{ return RCTL; }
163 
164 <TSTATE>attr	{ return ATTR; }
165 
166 <TSTATE>admin	{ return ADMIN; }
167 
168 <TSTATE>zonename	{ return ZONENAME; }
169 <CSTATE>zonename	{ return ZONENAME; }
170 
171 <TSTATE>dataset	{ return DATASET; }
172 
173 <TSTATE>dedicated-cpu	{ return PSET; }
174 
175 <TSTATE>capped-cpu	{ return PCAP; }
176 
177 <TSTATE>capped-memory	{ return MCAP; }
178 
179 <TSTATE>zonepath	{ return ZONEPATH; }
180 <CSTATE>zonepath	{ return ZONEPATH; }
181 
182 <TSTATE>brand	{ return BRAND; }
183 <CSTATE>brand	{ return BRAND; }
184 
185 <TSTATE>autoboot	{ return AUTOBOOT; }
186 <CSTATE>autoboot	{ return AUTOBOOT; }
187 
188 <TSTATE>ip-type		{ return IPTYPE; }
189 <CSTATE>ip-type		{ return IPTYPE; }
190 
191 <TSTATE>pool	{ return POOL; }
192 <CSTATE>pool	{ return POOL; }
193 
194 <TSTATE>limitpriv	{ return LIMITPRIV; }
195 <CSTATE>limitpriv	{ return LIMITPRIV; }
196 
197 <TSTATE>bootargs	{ return BOOTARGS; }
198 <CSTATE>bootargs	{ return BOOTARGS; }
199 
200 <TSTATE>type	{ return TYPE; }
201 <CSTATE>type	{ return TYPE; }
202 
203 <TSTATE>value	{ return VALUE; }
204 <CSTATE>value	{ return VALUE; }
205 
206 <TSTATE>options	{ return OPTIONS; }
207 <CSTATE>options	{ return OPTIONS; }
208 
209 <TSTATE>address	{ return ADDRESS; }
210 <CSTATE>address	{ return ADDRESS; }
211 
212 <TSTATE>physical	{ return PHYSICAL; }
213 <CSTATE>physical	{ return PHYSICAL; }
214 
215 <TSTATE>defrouter	{ return DEFROUTER; }
216 <CSTATE>defrouter	{ return DEFROUTER; }
217 
218 <TSTATE>dir	{ return DIR; }
219 <CSTATE>dir	{ return DIR; }
220 
221 <TSTATE>special	{ return SPECIAL; }
222 <CSTATE>special	{ return SPECIAL; }
223 
224 <TSTATE>raw	{ return RAW; }
225 <CSTATE>raw	{ return RAW; }
226 
227 <TSTATE>name	{ return NAME; }
228 <CSTATE>name	{ return NAME; }
229 
230 <TSTATE>match	{ return MATCH; }
231 <CSTATE>match	{ return MATCH; }
232 
233 <TSTATE>priv	{ return PRIV; }
234 <CSTATE>priv	{ return PRIV; }
235 
236 <TSTATE>limit	{ return LIMIT; }
237 <CSTATE>limit	{ return LIMIT; }
238 
239 <TSTATE>action	{ return ACTION; }
240 <CSTATE>action	{ return ACTION; }
241 
242 <TSTATE>ncpus	{ return NCPUS; }
243 <CSTATE>ncpus	{ return NCPUS; }
244 
245 <TSTATE>locked	{ return LOCKED; }
246 <CSTATE>locked	{ return LOCKED; }
247 
248 <TSTATE>swap	{ return SWAP; }
249 <CSTATE>swap	{ return SWAP; }
250 
251 <TSTATE>importance	{ return IMPORTANCE; }
252 <CSTATE>importance	{ return IMPORTANCE; }
253 
254 <TSTATE>cpu-shares	{ return SHARES; }
255 <CSTATE>cpu-shares	{ return SHARES; }
256 
257 <TSTATE>max-lwps	{ return MAXLWPS; }
258 <CSTATE>max-lwps	{ return MAXLWPS; }
259 
260 <TSTATE>max-shm-memory	{ return MAXSHMMEM; }
261 <CSTATE>max-shm-memory	{ return MAXSHMMEM; }
262 
263 <TSTATE>max-shm-ids	{ return MAXSHMIDS; }
264 <CSTATE>max-shm-ids	{ return MAXSHMIDS; }
265 
266 <TSTATE>max-msg-ids	{ return MAXMSGIDS; }
267 <CSTATE>max-msg-ids	{ return MAXMSGIDS; }
268 
269 <TSTATE>max-sem-ids	{ return MAXSEMIDS; }
270 <CSTATE>max-sem-ids	{ return MAXSEMIDS; }
271 
272 <TSTATE>scheduling-class	{ return SCHED; }
273 <CSTATE>scheduling-class	{ return SCHED; }
274 
275 <TSTATE>hostid		{ return HOSTID; }
276 <CSTATE>hostid		{ return HOSTID; }
277 
278 <TSTATE>user	{ return USER; }
279 <CSTATE>user	{ return USER; }
280 
281 <TSTATE>auths	{ return AUTHS; }
282 <CSTATE>auths	{ return AUTHS; }
283 
284 <TSTATE>=	{ return EQUAL; }
285 <LSTATE>=	{ return EQUAL; }
286 <CSTATE>=	{ return EQUAL; }
287 
288 <TSTATE>"["	{
289 			BEGIN LSTATE;
290 			state = LSTATE;
291 			return OPEN_SQ_BRACKET;
292 		}
293 
294 <LSTATE>"]"	{
295 			BEGIN TSTATE;
296 			state = TSTATE;
297 			return CLOSE_SQ_BRACKET;
298 		}
299 
300 <TSTATE>"("	{
301 			BEGIN CSTATE;
302 			return OPEN_PAREN;
303 		}
304 
305 <LSTATE>"("	{
306 			BEGIN CSTATE;
307 			return OPEN_PAREN;
308 		}
309 
310 <CSTATE>")"	{
311 			BEGIN state;
312 			return CLOSE_PAREN;
313 		}
314 
315 <LSTATE>","	{ return COMMA; }
316 <CSTATE>","	{ return COMMA; }
317 
318 <TSTATE>[^ \t\n\";=\[\]\(\)]+	{
319 			yylval.strval = safe_strdup(yytext);
320 			return TOKEN;
321 		}
322 
323 <LSTATE>[^ \t\n\",;=\[\]\(\)]+	{
324 			yylval.strval = safe_strdup(yytext);
325 			return TOKEN;
326 		}
327 
328 <CSTATE>[^ \t\n\",;=\(\)]+	{
329 			yylval.strval = safe_strdup(yytext);
330 			return TOKEN;
331 		}
332 
333 <TSTATE>\"[^\"\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 <LSTATE>\"[^\"\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 ";"		{
348 			BEGIN INITIAL;
349 			return (yytext[0]);
350 		}
351 
352 \n		{
353 			lex_lineno++;
354 			BEGIN INITIAL;
355 			return (yytext[0]);
356 		}
357 
358 [ \t]		;	/* Ignore whitespace */
359 
360 .		{
361 			return (yytext[0]);
362 		}
363 
364 %%
365 
366 char *
367 safe_strdup(char *s)
368 {
369 	char *result;
370 
371 	if ((result = strdup(s)) == NULL) {
372 		yyerror("Out of memory");
373 		exit(Z_ERR);
374 	}
375 	return (result);
376 }
377 
378 void
379 yyerror(char *s)
380 {
381 	/* feof(yyin) is not an error; anything else is, so we set saw_error */
382 	if (yytext[0] == '\0') {
383 		if (!feof(yyin)) {
384 			saw_error = B_TRUE;
385 			(void) fprintf(stderr, gettext("%s, token expected\n"),
386 			    s);
387 		}
388 		return;
389 	}
390 
391 	saw_error = B_TRUE;
392 	if (cmd_file_mode)
393 		(void) fprintf(stderr, gettext("%s on line %d at '%s'\n"), s,
394 		    lex_lineno, (yytext[0] == '\n') ? "\\n" : yytext);
395 	else
396 		(void) fprintf(stderr, gettext("%s at '%s'\n"), s,
397 		    (yytext[0] == '\n') ? "\\n" : yytext);
398 	usage(B_FALSE, HELP_SUBCMDS);
399 }
400