xref: /titanic_52/usr/src/cmd/zonecfg/zonecfg_lex.l (revision b6c3f7863936abeae522e48a13887dddeb691a45)
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 2008 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>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-shm-memory	{ return MAXSHMMEM; }
262 <CSTATE>max-shm-memory	{ return MAXSHMMEM; }
263 
264 <TSTATE>max-shm-ids	{ return MAXSHMIDS; }
265 <CSTATE>max-shm-ids	{ return MAXSHMIDS; }
266 
267 <TSTATE>max-msg-ids	{ return MAXMSGIDS; }
268 <CSTATE>max-msg-ids	{ return MAXMSGIDS; }
269 
270 <TSTATE>max-sem-ids	{ return MAXSEMIDS; }
271 <CSTATE>max-sem-ids	{ return MAXSEMIDS; }
272 
273 <TSTATE>scheduling-class	{ return SCHED; }
274 <CSTATE>scheduling-class	{ return SCHED; }
275 
276 <TSTATE>=	{ return EQUAL; }
277 <LSTATE>=	{ return EQUAL; }
278 <CSTATE>=	{ return EQUAL; }
279 
280 <TSTATE>"["	{
281 			BEGIN LSTATE;
282 			state = LSTATE;
283 			return OPEN_SQ_BRACKET;
284 		}
285 
286 <LSTATE>"]"	{
287 			BEGIN TSTATE;
288 			state = TSTATE;
289 			return CLOSE_SQ_BRACKET;
290 		}
291 
292 <TSTATE>"("	{
293 			BEGIN CSTATE;
294 			return OPEN_PAREN;
295 		}
296 
297 <LSTATE>"("	{
298 			BEGIN CSTATE;
299 			return OPEN_PAREN;
300 		}
301 
302 <CSTATE>")"	{
303 			BEGIN state;
304 			return CLOSE_PAREN;
305 		}
306 
307 <LSTATE>","	{ return COMMA; }
308 <CSTATE>","	{ return COMMA; }
309 
310 <TSTATE>[^ \t\n\";=\[\]\(\)]+	{
311 			yylval.strval = safe_strdup(yytext);
312 			return TOKEN;
313 		}
314 
315 <LSTATE>[^ \t\n\",;=\[\]\(\)]+	{
316 			yylval.strval = safe_strdup(yytext);
317 			return TOKEN;
318 		}
319 
320 <CSTATE>[^ \t\n\",;=\(\)]+	{
321 			yylval.strval = safe_strdup(yytext);
322 			return TOKEN;
323 		}
324 
325 <TSTATE>\"[^\"\n]*[\"\n] {
326 			yylval.strval = safe_strdup(yytext + 1);
327 			if (yylval.strval[yyleng - 2] == '"')
328 				yylval.strval[yyleng - 2] = 0;
329 			return TOKEN;
330 		}
331 
332 <LSTATE>\"[^\"\n]*[\"\n] {
333 			yylval.strval = safe_strdup(yytext + 1);
334 			if (yylval.strval[yyleng - 2] == '"')
335 				yylval.strval[yyleng - 2] = 0;
336 			return TOKEN;
337 		}
338 
339 ";"		{
340 			BEGIN INITIAL;
341 			return (yytext[0]);
342 		}
343 
344 \n		{
345 			lex_lineno++;
346 			BEGIN INITIAL;
347 			return (yytext[0]);
348 		}
349 
350 [ \t]		;	/* Ignore whitespace */
351 
352 .		{
353 			return (yytext[0]);
354 		}
355 
356 %%
357 
358 char *
359 safe_strdup(char *s)
360 {
361 	char *result;
362 
363 	if ((result = strdup(s)) == NULL) {
364 		yyerror("Out of memory");
365 		exit(Z_ERR);
366 	}
367 	return (result);
368 }
369 
370 void
371 yyerror(char *s)
372 {
373 	/* feof(yyin) is not an error; anything else is, so we set saw_error */
374 	if (yytext[0] == '\0') {
375 		if (!feof(yyin)) {
376 			saw_error = TRUE;
377 			(void) fprintf(stderr, gettext("%s, token expected\n"),
378 			    s);
379 		}
380 		return;
381 	}
382 
383 	saw_error = TRUE;
384 	if (cmd_file_mode)
385 		(void) fprintf(stderr, gettext("%s on line %d at '%s'\n"), s,
386 		    lex_lineno, (yytext[0] == '\n') ? "\\n" : yytext);
387 	else
388 		(void) fprintf(stderr, gettext("%s at '%s'\n"), s,
389 		    (yytext[0] == '\n') ? "\\n" : yytext);
390 	usage(FALSE, HELP_SUBCMDS);
391 }
392