xref: /titanic_44/usr/src/cmd/zonecfg/zonecfg_lex.l (revision 3c112a2b34403220c06c3e2fcac403358cfba168)
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>fs-allowed	{ return FS_ALLOWED; }
285 <CSTATE>fs-allowed	{ return FS_ALLOWED; }
286 
287 <TSTATE>=	{ return EQUAL; }
288 <LSTATE>=	{ return EQUAL; }
289 <CSTATE>=	{ return EQUAL; }
290 
291 <TSTATE>"["	{
292 			BEGIN LSTATE;
293 			state = LSTATE;
294 			return OPEN_SQ_BRACKET;
295 		}
296 
297 <LSTATE>"]"	{
298 			BEGIN TSTATE;
299 			state = TSTATE;
300 			return CLOSE_SQ_BRACKET;
301 		}
302 
303 <TSTATE>"("	{
304 			BEGIN CSTATE;
305 			return OPEN_PAREN;
306 		}
307 
308 <LSTATE>"("	{
309 			BEGIN CSTATE;
310 			return OPEN_PAREN;
311 		}
312 
313 <CSTATE>")"	{
314 			BEGIN state;
315 			return CLOSE_PAREN;
316 		}
317 
318 <LSTATE>","	{ return COMMA; }
319 <CSTATE>","	{ return COMMA; }
320 
321 <TSTATE>[^ \t\n\";=\[\]\(\)]+	{
322 			yylval.strval = safe_strdup(yytext);
323 			return TOKEN;
324 		}
325 
326 <LSTATE>[^ \t\n\",;=\[\]\(\)]+	{
327 			yylval.strval = safe_strdup(yytext);
328 			return TOKEN;
329 		}
330 
331 <CSTATE>[^ \t\n\",;=\(\)]+	{
332 			yylval.strval = safe_strdup(yytext);
333 			return TOKEN;
334 		}
335 
336 <TSTATE>\"[^\"\n]*[\"\n] {
337 			yylval.strval = safe_strdup(yytext + 1);
338 			if (yylval.strval[yyleng - 2] == '"')
339 				yylval.strval[yyleng - 2] = 0;
340 			return TOKEN;
341 		}
342 
343 <LSTATE>\"[^\"\n]*[\"\n] {
344 			yylval.strval = safe_strdup(yytext + 1);
345 			if (yylval.strval[yyleng - 2] == '"')
346 				yylval.strval[yyleng - 2] = 0;
347 			return TOKEN;
348 		}
349 
350 ";"		{
351 			BEGIN INITIAL;
352 			return (yytext[0]);
353 		}
354 
355 \n		{
356 			lex_lineno++;
357 			BEGIN INITIAL;
358 			return (yytext[0]);
359 		}
360 
361 [ \t]		;	/* Ignore whitespace */
362 
363 .		{
364 			return (yytext[0]);
365 		}
366 
367 %%
368 
369 char *
370 safe_strdup(char *s)
371 {
372 	char *result;
373 
374 	if ((result = strdup(s)) == NULL) {
375 		yyerror("Out of memory");
376 		exit(Z_ERR);
377 	}
378 	return (result);
379 }
380 
381 void
382 yyerror(char *s)
383 {
384 	/* feof(yyin) is not an error; anything else is, so we set saw_error */
385 	if (yytext[0] == '\0') {
386 		if (!feof(yyin)) {
387 			saw_error = B_TRUE;
388 			(void) fprintf(stderr, gettext("%s, token expected\n"),
389 			    s);
390 		}
391 		return;
392 	}
393 
394 	saw_error = B_TRUE;
395 	if (cmd_file_mode)
396 		(void) fprintf(stderr, gettext("%s on line %d at '%s'\n"), s,
397 		    lex_lineno, (yytext[0] == '\n') ? "\\n" : yytext);
398 	else
399 		(void) fprintf(stderr, gettext("%s at '%s'\n"), s,
400 		    (yytext[0] == '\n') ? "\\n" : yytext);
401 	usage(B_FALSE, HELP_SUBCMDS);
402 }
403