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