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