xref: /titanic_44/usr/src/cmd/cmd-inet/usr.sbin/nwamcfg/nwamcfg_lex.l (revision 726fad2a65f16c200a03969c29cb5c86c2d427db)
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 2010 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #include <string.h>
29 #include <libintl.h>
30 #include <sys/types.h>
31 #include "nwamcfg.h"
32 #include "nwamcfg_grammar.tab.h"
33 
34 int lex_lineno = 1;	/* line number for error reporting */
35 static int state = INITIAL;
36 extern boolean_t cmd_file_mode;
37 
38 extern void yyerror(char *s);
39 char *safe_strdup(char *s);
40 %}
41 
42 %a 7000
43 %p 5000
44 %e 2000
45 %n 800
46 %o 12000
47 
48 %{
49 /*
50  * The state below are for tokens.
51  */
52 %}
53 %s TSTATE
54 %%
55 
56 <INITIAL>"#"[^\n]*	{ }
57 
58 <INITIAL>cancel {
59 			BEGIN TSTATE;
60 			state = TSTATE;
61 			return CANCEL;
62 		}
63 
64 <INITIAL>clear	{
65 			BEGIN TSTATE;
66 			state = TSTATE;
67 			return CLEAR;
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 
83 <INITIAL>destroy {
84 			BEGIN TSTATE;
85 			state = TSTATE;
86 			return DESTROY;
87 		}
88 
89 <INITIAL>end	{
90 			BEGIN TSTATE;
91 			state = TSTATE;
92 			return END;
93 		}
94 
95 <INITIAL>exit|quit {
96 			BEGIN TSTATE;
97 			state = TSTATE;
98 			return EXIT;
99 		}
100 
101 <INITIAL>export	{
102 			BEGIN TSTATE;
103 			state = TSTATE;
104 			return EXPORT;
105 		}
106 
107 <INITIAL>get	{
108 			BEGIN TSTATE;
109 			state = TSTATE;
110 			return GET;
111 		}
112 
113 <INITIAL>"?"|help {
114 			BEGIN TSTATE;
115 			state = TSTATE;
116 			return HELP;
117 		}
118 
119 <INITIAL>list	{
120 			BEGIN TSTATE;
121 			state = TSTATE;
122 			return LIST;
123 		}
124 
125 <INITIAL>revert	{
126 			BEGIN TSTATE;
127 			state = TSTATE;
128 			return REVERT;
129 		}
130 
131 <INITIAL>select	{
132 			BEGIN TSTATE;
133 			state = TSTATE;
134 			return SELECT;
135 		}
136 
137 <INITIAL>set	{
138 			BEGIN TSTATE;
139 			state = TSTATE;
140 			return SET;
141 		}
142 
143 <INITIAL>verify	{
144 			BEGIN TSTATE;
145 			state = TSTATE;
146 			return VERIFY;
147 		}
148 
149 <INITIAL>walkprop {
150 			BEGIN TSTATE;
151 			state = TSTATE;
152 			return WALKPROP;
153 		}
154 
155 <TSTATE>[Ll][Oo][Cc]		{ return LOC; }
156 <TSTATE>[Nn][Cc][Pp]		{ return NCP; }
157 <TSTATE>[Ee][Nn][Mm]		{ return ENM; }
158 <TSTATE>[Ww][Ll][Aa][Nn]	{ return WLAN; }
159 
160 <TSTATE>[Nn][Cc][Uu]		{ return NCU; }
161 
162 <TSTATE>[Pp][Hh][Yy][Ss]	{ return PHYS; }
163 <TSTATE>[Ii][Pp]		{ return IP; }
164 
165 <TSTATE>unknown		{ return UNKNOWN; }
166 <TSTATE>activation-mode	{ return ACTIVATION_MODE; }
167 <TSTATE>conditions	{ return CONDITIONS; }
168 <TSTATE>enabled		{ return ENABLED; }
169 
170 <TSTATE>type			{ return TYPE; }
171 <TSTATE>class			{ return CLASS; }
172 <TSTATE>parent			{ return PARENT; }
173 <TSTATE>priority-group		{ return PRIORITY_GROUP; }
174 <TSTATE>priority-mode		{ return PRIORITY_MODE; }
175 <TSTATE>link-mac-addr		{ return LINK_MACADDR; }
176 <TSTATE>link-autopush		{ return LINK_AUTOPUSH; }
177 <TSTATE>link-mtu		{ return LINK_MTU; }
178 <TSTATE>ip-version		{ return IP_VERSION; }
179 <TSTATE>ipv4-addrsrc		{ return IPV4_ADDRSRC; }
180 <TSTATE>ipv4-addr		{ return IPV4_ADDR; }
181 <TSTATE>ipv4-default-route	{ return IPV4_DEFAULT_ROUTE; }
182 <TSTATE>ipv6-addrsrc		{ return IPV6_ADDRSRC; }
183 <TSTATE>ipv6-addr		{ return IPV6_ADDR; }
184 <TSTATE>ipv6-default-route	{ return IPV6_DEFAULT_ROUTE; }
185 
186 <TSTATE>state		{ return ENM_STATE; }
187 <TSTATE>fmri		{ return ENM_FMRI; }
188 <TSTATE>start		{ return ENM_START; }
189 <TSTATE>stop		{ return ENM_STOP; }
190 
191 <TSTATE>nameservices			{ return LOC_NAMESERVICES; }
192 <TSTATE>nameservices-config-file	{ return LOC_NAMESERVICES_CONFIG; }
193 <TSTATE>dns-nameservice-configsrc	{ return LOC_DNS_CONFIGSRC; }
194 <TSTATE>dns-nameservice-domain		{ return LOC_DNS_DOMAIN; }
195 <TSTATE>dns-nameservice-servers		{ return LOC_DNS_SERVERS; }
196 <TSTATE>dns-nameservice-search		{ return LOC_DNS_SEARCH; }
197 <TSTATE>nis-nameservice-configsrc	{ return LOC_NIS_CONFIGSRC; }
198 <TSTATE>nis-nameservice-servers		{ return LOC_NIS_SERVERS; }
199 <TSTATE>ldap-nameservice-configsrc	{ return LOC_LDAP_CONFIGSRC; }
200 <TSTATE>ldap-nameservice-servers	{ return LOC_LDAP_SERVERS; }
201 <TSTATE>default-domain			{ return LOC_DEFAULT_DOMAIN; }
202 <TSTATE>nfsv4-domain			{ return LOC_NFSV4_DOMAIN; }
203 <TSTATE>ipfilter-config-file		{ return LOC_IPF_CONFIG; }
204 <TSTATE>ipfilter-v6-config-file		{ return LOC_IPF_V6_CONFIG; }
205 <TSTATE>ipnat-config-file		{ return LOC_IPNAT_CONFIG; }
206 <TSTATE>ippool-config-file		{ return LOC_IPPOOL_CONFIG; }
207 <TSTATE>ike-config-file			{ return LOC_IKE_CONFIG; }
208 <TSTATE>ipsecpolicy-config-file		{ return LOC_IPSECPOL_CONFIG; }
209 
210 <TSTATE>bssids		{ return WLAN_BSSIDS; }
211 <TSTATE>priority	{ return WLAN_PRIORITY; }
212 <TSTATE>keyname		{ return WLAN_KEYNAME; }
213 <TSTATE>keyslot		{ return WLAN_KEYSLOT; }
214 <TSTATE>security-mode	{ return WLAN_SECURITY_MODE; }
215 
216 <TSTATE>=		{ return EQUAL; }
217 
218 <TSTATE>\-[adftV] {	/* matches options */
219 			yylval.strval = safe_strdup(yytext);
220 			return OPTION;
221 		}
222 
223 <TSTATE>[^ \t\n\";=\[\]\(\)]+	{	/* matches non-quoted values */
224 			yylval.strval = safe_strdup(yytext);
225 			return TOKEN;
226 		}
227 
228 <TSTATE>\"[^\"\n]*[\"\n] {	/* matches string with quotes */
229 			yylval.strval = safe_strdup(yytext);
230 			return TOKEN;
231 		}
232 
233 <TSTATE>\".*\"\,\".*\" {	/* matches string list of the form "a","b",.. */
234 			yylval.strval = safe_strdup(yytext);
235 			return TOKEN;
236 		}
237 
238 ";"		{
239 			BEGIN INITIAL;
240 			return (yytext[0]);
241 		}
242 
243 \n		{
244 			lex_lineno++;
245 			BEGIN INITIAL;
246 			return (yytext[0]);
247 		}
248 
249 [ \t]		;	/* ignore white space */
250 
251 .		{	/* matches all single otherwise unmatched characters */
252 			return (yytext[0]);
253 		}
254 
255 %%
256 
257 char *
258 safe_strdup(char *s)
259 {
260 	char *result;
261 
262 	if ((result = strdup(s)) == NULL) {
263 		yyerror("Out of memory");
264 		exit(1);
265 	}
266 	return (result);
267 }
268 
269 void
270 yyerror(char *s)
271 {
272 	/* feof(yyin) is not an error; anything else is, so we set saw_error */
273 	if (yytext[0] == '\0') {
274 		if (!feof(yyin)) {
275 			saw_error = B_TRUE;
276 			(void) fprintf(stderr, gettext("%s, token expected\n"),
277 			    s);
278 		}
279 		return;
280 	}
281 
282 	saw_error = B_TRUE;
283 	if (cmd_file_mode) {
284 		(void) fprintf(stderr, gettext("%s on line %d at '%s'\n"), s,
285 		    lex_lineno, (yytext[0] == '\n') ? "\\n" : yytext);
286 	} else {
287 		(void) fprintf(stderr, gettext("%s at '%s'\n\n"), s,
288 		    (yytext[0] == '\n') ? "\\n" : yytext);
289 	}
290 	help_wrap();
291 }
292