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