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