xref: /titanic_51/usr/src/cmd/zonecfg/zonecfg_lex.l (revision 8dc347db08e4faa48cceabd314cab6c0136ed5c2)
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-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>dir	{ return DIR; }
215 <CSTATE>dir	{ return DIR; }
216 
217 <TSTATE>special	{ return SPECIAL; }
218 <CSTATE>special	{ return SPECIAL; }
219 
220 <TSTATE>raw	{ return RAW; }
221 <CSTATE>raw	{ return RAW; }
222 
223 <TSTATE>name	{ return NAME; }
224 <CSTATE>name	{ return NAME; }
225 
226 <TSTATE>match	{ return MATCH; }
227 <CSTATE>match	{ return MATCH; }
228 
229 <TSTATE>priv	{ return PRIV; }
230 <CSTATE>priv	{ return PRIV; }
231 
232 <TSTATE>limit	{ return LIMIT; }
233 <CSTATE>limit	{ return LIMIT; }
234 
235 <TSTATE>action	{ return ACTION; }
236 <CSTATE>action	{ return ACTION; }
237 
238 <TSTATE>ncpus	{ return NCPUS; }
239 <CSTATE>ncpus	{ return NCPUS; }
240 
241 <TSTATE>locked	{ return LOCKED; }
242 <CSTATE>locked	{ return LOCKED; }
243 
244 <TSTATE>swap	{ return SWAP; }
245 <CSTATE>swap	{ return SWAP; }
246 
247 <TSTATE>importance	{ return IMPORTANCE; }
248 <CSTATE>importance	{ return IMPORTANCE; }
249 
250 <TSTATE>cpu-shares	{ return SHARES; }
251 <CSTATE>cpu-shares	{ return SHARES; }
252 
253 <TSTATE>max-lwps	{ return MAXLWPS; }
254 <CSTATE>max-lwps	{ return MAXLWPS; }
255 
256 <TSTATE>max-shm-memory	{ return MAXSHMMEM; }
257 <CSTATE>max-shm-memory	{ return MAXSHMMEM; }
258 
259 <TSTATE>max-shm-ids	{ return MAXSHMIDS; }
260 <CSTATE>max-shm-ids	{ return MAXSHMIDS; }
261 
262 <TSTATE>max-msg-ids	{ return MAXMSGIDS; }
263 <CSTATE>max-msg-ids	{ return MAXMSGIDS; }
264 
265 <TSTATE>max-sem-ids	{ return MAXSEMIDS; }
266 <CSTATE>max-sem-ids	{ return MAXSEMIDS; }
267 
268 <TSTATE>scheduling-class	{ return SCHED; }
269 <CSTATE>scheduling-class	{ return SCHED; }
270 
271 <TSTATE>=	{ return EQUAL; }
272 <LSTATE>=	{ return EQUAL; }
273 <CSTATE>=	{ return EQUAL; }
274 
275 <TSTATE>"["	{
276 			BEGIN LSTATE;
277 			state = LSTATE;
278 			return OPEN_SQ_BRACKET;
279 		}
280 
281 <LSTATE>"]"	{
282 			BEGIN TSTATE;
283 			state = TSTATE;
284 			return CLOSE_SQ_BRACKET;
285 		}
286 
287 <TSTATE>"("	{
288 			BEGIN CSTATE;
289 			return OPEN_PAREN;
290 		}
291 
292 <LSTATE>"("	{
293 			BEGIN CSTATE;
294 			return OPEN_PAREN;
295 		}
296 
297 <CSTATE>")"	{
298 			BEGIN state;
299 			return CLOSE_PAREN;
300 		}
301 
302 <LSTATE>","	{ return COMMA; }
303 <CSTATE>","	{ return COMMA; }
304 
305 <TSTATE>[^ \t\n\";=\[\]\(\)]+	{
306 			yylval.strval = safe_strdup(yytext);
307 			return TOKEN;
308 		}
309 
310 <LSTATE>[^ \t\n\",;=\[\]\(\)]+	{
311 			yylval.strval = safe_strdup(yytext);
312 			return TOKEN;
313 		}
314 
315 <CSTATE>[^ \t\n\",;=\(\)]+	{
316 			yylval.strval = safe_strdup(yytext);
317 			return TOKEN;
318 		}
319 
320 <TSTATE>\"[^\"\n]*[\"\n] {
321 			yylval.strval = safe_strdup(yytext + 1);
322 			if (yylval.strval[yyleng - 2] == '"')
323 				yylval.strval[yyleng - 2] = 0;
324 			return TOKEN;
325 		}
326 
327 <LSTATE>\"[^\"\n]*[\"\n] {
328 			yylval.strval = safe_strdup(yytext + 1);
329 			if (yylval.strval[yyleng - 2] == '"')
330 				yylval.strval[yyleng - 2] = 0;
331 			return TOKEN;
332 		}
333 
334 ";"		{
335 			BEGIN INITIAL;
336 			return (yytext[0]);
337 		}
338 
339 \n		{
340 			lex_lineno++;
341 			BEGIN INITIAL;
342 			return (yytext[0]);
343 		}
344 
345 [ \t]		;	/* Ignore whitespace */
346 
347 .		{
348 			return (yytext[0]);
349 		}
350 
351 %%
352 
353 char *
354 safe_strdup(char *s)
355 {
356 	char *result;
357 
358 	if ((result = strdup(s)) == NULL) {
359 		yyerror("Out of memory");
360 		exit(Z_ERR);
361 	}
362 	return (result);
363 }
364 
365 void
366 yyerror(char *s)
367 {
368 	/* feof(yyin) is not an error; anything else is, so we set saw_error */
369 	if (yytext[0] == '\0') {
370 		if (!feof(yyin)) {
371 			saw_error = TRUE;
372 			(void) fprintf(stderr, gettext("%s, token expected\n"),
373 			    s);
374 		}
375 		return;
376 	}
377 
378 	saw_error = TRUE;
379 	if (cmd_file_mode)
380 		(void) fprintf(stderr, gettext("%s on line %d at '%s'\n"), s,
381 		    lex_lineno, (yytext[0] == '\n') ? "\\n" : yytext);
382 	else
383 		(void) fprintf(stderr, gettext("%s at '%s'\n"), s,
384 		    (yytext[0] == '\n') ? "\\n" : yytext);
385 	usage(FALSE, HELP_SUBCMDS);
386 }
387