xref: /titanic_41/usr/src/cmd/zonecfg/zonecfg_lex.l (revision 6185db853e024a486ff8837e6784dd290d866112)
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 4000
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>verify	{
143 			BEGIN TSTATE;
144 			state = TSTATE;
145 			return VERIFY;
146 		}
147 
148 <TSTATE>net	{ return NET; }
149 
150 <TSTATE>fs	{ return FS; }
151 
152 <TSTATE>inherit-pkg-dir	{ return IPD; }
153 
154 <TSTATE>device	{ return DEVICE; }
155 
156 <TSTATE>rctl	{ return RCTL; }
157 
158 <TSTATE>attr	{ return ATTR; }
159 
160 <TSTATE>zonename	{ return ZONENAME; }
161 <CSTATE>zonename	{ return ZONENAME; }
162 
163 <TSTATE>dataset	{ return DATASET; }
164 
165 <TSTATE>zonepath	{ return ZONEPATH; }
166 <CSTATE>zonepath	{ return ZONEPATH; }
167 
168 <TSTATE>brand	{ return BRAND; }
169 <CSTATE>brand	{ return BRAND; }
170 
171 <TSTATE>autoboot	{ return AUTOBOOT; }
172 <CSTATE>autoboot	{ return AUTOBOOT; }
173 
174 <TSTATE>pool	{ return POOL; }
175 <CSTATE>pool	{ return POOL; }
176 
177 <TSTATE>limitpriv	{ return LIMITPRIV; }
178 <CSTATE>limitpriv	{ return LIMITPRIV; }
179 
180 <TSTATE>bootargs	{ return BOOTARGS; }
181 <CSTATE>bootargs	{ return BOOTARGS; }
182 
183 <TSTATE>type	{ return TYPE; }
184 <CSTATE>type	{ return TYPE; }
185 
186 <TSTATE>value	{ return VALUE; }
187 <CSTATE>value	{ return VALUE; }
188 
189 <TSTATE>options	{ return OPTIONS; }
190 <CSTATE>options	{ return OPTIONS; }
191 
192 <TSTATE>address	{ return ADDRESS; }
193 <CSTATE>address	{ return ADDRESS; }
194 
195 <TSTATE>physical	{ return PHYSICAL; }
196 <CSTATE>physical	{ return PHYSICAL; }
197 
198 <TSTATE>dir	{ return DIR; }
199 <CSTATE>dir	{ return DIR; }
200 
201 <TSTATE>special	{ return SPECIAL; }
202 <CSTATE>special	{ return SPECIAL; }
203 
204 <TSTATE>raw	{ return RAW; }
205 <CSTATE>raw	{ return RAW; }
206 
207 <TSTATE>name	{ return NAME; }
208 <CSTATE>name	{ return NAME; }
209 
210 <TSTATE>match	{ return MATCH; }
211 <CSTATE>match	{ return MATCH; }
212 
213 <TSTATE>priv	{ return PRIV; }
214 <CSTATE>priv	{ return PRIV; }
215 
216 <TSTATE>limit	{ return LIMIT; }
217 <CSTATE>limit	{ return LIMIT; }
218 
219 <TSTATE>action	{ return ACTION; }
220 <CSTATE>action	{ return ACTION; }
221 
222 <TSTATE>=	{ return EQUAL; }
223 <LSTATE>=	{ return EQUAL; }
224 <CSTATE>=	{ return EQUAL; }
225 
226 <TSTATE>"["	{
227 			BEGIN LSTATE;
228 			state = LSTATE;
229 			return OPEN_SQ_BRACKET;
230 		}
231 
232 <LSTATE>"]"	{
233 			BEGIN TSTATE;
234 			state = TSTATE;
235 			return CLOSE_SQ_BRACKET;
236 		}
237 
238 <TSTATE>"("	{
239 			BEGIN CSTATE;
240 			return OPEN_PAREN;
241 		}
242 
243 <LSTATE>"("	{
244 			BEGIN CSTATE;
245 			return OPEN_PAREN;
246 		}
247 
248 <CSTATE>")"	{
249 			BEGIN state;
250 			return CLOSE_PAREN;
251 		}
252 
253 <LSTATE>","	{ return COMMA; }
254 <CSTATE>","	{ return COMMA; }
255 
256 <TSTATE>[^ \t\n\";=\[\]\(\)]+	{
257 			yylval.strval = safe_strdup(yytext);
258 			return TOKEN;
259 		}
260 
261 <LSTATE>[^ \t\n\",;=\[\]\(\)]+	{
262 			yylval.strval = safe_strdup(yytext);
263 			return TOKEN;
264 		}
265 
266 <CSTATE>[^ \t\n\",;=\(\)]+	{
267 			yylval.strval = safe_strdup(yytext);
268 			return TOKEN;
269 		}
270 
271 <TSTATE>\"[^\"\n]*[\"\n] {
272 			yylval.strval = safe_strdup(yytext + 1);
273 			if (yylval.strval[yyleng - 2] == '"')
274 				yylval.strval[yyleng - 2] = 0;
275 			return TOKEN;
276 		}
277 
278 <LSTATE>\"[^\"\n]*[\"\n] {
279 			yylval.strval = safe_strdup(yytext + 1);
280 			if (yylval.strval[yyleng - 2] == '"')
281 				yylval.strval[yyleng - 2] = 0;
282 			return TOKEN;
283 		}
284 
285 ";"		{
286 			BEGIN INITIAL;
287 			return (yytext[0]);
288 		}
289 
290 \n		{
291 			lex_lineno++;
292 			BEGIN INITIAL;
293 			return (yytext[0]);
294 		}
295 
296 [ \t]		;	/* Ignore whitespace */
297 
298 .		{
299 			return (yytext[0]);
300 		}
301 
302 %%
303 
304 char *
305 safe_strdup(char *s)
306 {
307 	char *result;
308 
309 	if ((result = strdup(s)) == NULL) {
310 		yyerror("Out of memory");
311 		exit(Z_ERR);
312 	}
313 	return (result);
314 }
315 
316 void
317 yyerror(char *s)
318 {
319 	/* feof(yyin) is not an error; anything else is, so we set saw_error */
320 	if (yytext[0] == '\0') {
321 		if (!feof(yyin)) {
322 			saw_error = TRUE;
323 			(void) fprintf(stderr, gettext("%s, token expected\n"),
324 			    s);
325 		}
326 		return;
327 	}
328 
329 	saw_error = TRUE;
330 	if (cmd_file_mode)
331 		(void) fprintf(stderr, gettext("%s on line %d at '%s'\n"), s,
332 		    lex_lineno, (yytext[0] == '\n') ? "\\n" : yytext);
333 	else
334 		(void) fprintf(stderr, gettext("%s at '%s'\n"), s,
335 		    (yytext[0] == '\n') ? "\\n" : yytext);
336 	usage(FALSE, HELP_SUBCMDS);
337 }
338