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