]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/rrenumd/lexer.l
Fix encoding issues with python 3
[FreeBSD/FreeBSD.git] / usr.sbin / rrenumd / lexer.l
1 /*      $KAME: lexer.l,v 1.7 2000/11/08 02:40:53 itojun Exp $   */
2
3 /*-
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. Neither the name of the project nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * $FreeBSD$
34  */
35
36 %{
37 #include <sys/param.h>
38 #include <sys/ioctl.h>
39 #include <sys/socket.h>
40 #include <sys/queue.h>
41
42 #include <string.h>
43
44 #include <net/if.h>
45 #include <netinet/in.h>
46 #include <netinet/in_var.h>
47 #include <netinet/icmp6.h>
48
49 #include <arpa/inet.h>
50
51 #include "y.tab.h"
52
53 int lineno = 1;
54
55 #define LINEBUF_SIZE 1000
56 char linebuf[LINEBUF_SIZE];
57
58 int parse(FILE **);
59 void yyerror(const char *);
60 int yylex(void);
61 %}
62
63 %option nounput
64
65 /* common section */
66 nl              \n
67 ws              [ \t]+
68 digit           [0-9]
69 letter          [0-9A-Za-z]
70 hexdigit        [0-9A-Fa-f]
71 special         [()+\|\?\*,]
72 dot             \.
73 hyphen          \-
74 colon           \:
75 slash           \/
76 bcl             \{
77 ecl             \}
78 semi            \;
79 usec            {dot}{digit}{1,6}
80 comment         \#.*
81 qstring         \"[^"]*\"
82 decstring       {digit}+
83 hexpair         {hexdigit}{hexdigit}
84 hexstring       0[xX]{hexdigit}+
85 octetstring     {octet}({dot}{octet})+
86 ipv4addr        {digit}{1,3}({dot}{digit}{1,3}){0,3}
87 ipv6addr        {hexdigit}{0,4}({colon}{hexdigit}{0,4}){2,7}
88 ipaddrmask      {slash}{digit}{1,3}
89 keyword         {letter}{letter}+
90 name            {letter}(({letter}|{digit}|{hyphen})*({letter}|{digit}))*
91 hostname        {name}(({dot}{name})+{dot}?)?
92
93 timeval         {digit}{0,2}
94 days            d{timeval}
95 hours           h{timeval}
96 minutes         m{timeval}
97 seconds         s{timeval}
98
99 mprefix         match_prefix|match-prefix
100 uprefix         use_prefix|use-prefix
101
102 %%
103         /* rrenumd keywords */
104 debug           {
105                         return(DEBUG_CMD);
106                 }
107 dest            {
108                         return(DEST_CMD);
109                 }
110 retry           {
111                         return(RETRY_CMD);
112                 }
113 seqnum          {
114                         return(SEQNUM_CMD);
115                 }
116 add             {
117                         yylval.num = RPM_PCO_ADD;
118                         return(ADD);
119                 }
120 change          {
121                         yylval.num = RPM_PCO_CHANGE;
122                         return(CHANGE);
123                  }
124 setglobal       {
125                         yylval.num = RPM_PCO_SETGLOBAL;
126                         return(SETGLOBAL);
127                 }
128 {mprefix}       {
129                         return(MATCH_PREFIX_CMD);
130                 }
131 maxlen          {
132                         return(MAXLEN_CMD);
133                 }
134 minlen          {
135                         return(MINLEN_CMD);
136                 }
137 {uprefix}       {
138                         return(USE_PREFIX_CMD);
139                 }
140 keeplen         {
141                         return(KEEPLEN_CMD);
142                 }
143
144 vltime          {
145                         return(VLTIME_CMD);
146                 }
147 pltime          {
148                         return(PLTIME_CMD);
149                 }
150 raf_onlink      {
151                         return(RAF_ONLINK_CMD);
152                 }
153 raf_auto        {
154                         return(RAF_AUTO_CMD);
155                 }
156 rrf_decrvalid   {
157                         return(RAF_DECRVALID_CMD);
158                 }
159 rrf_decrprefd   {
160                         return(RAF_DECRPREFD_CMD);
161                 }
162 {days}          {
163                         yytext++;
164                         yylval.num = atoi(yytext);
165                         return(DAYS);
166                 }
167 {hours}         {
168                         yytext++;
169                         yylval.num = atoi(yytext);
170                         return(HOURS);
171                 }
172 {minutes}       {
173                         yytext++;
174                         yylval.num = atoi(yytext);
175                         return(MINUTES);
176                 }
177 {seconds}       {
178                         yytext++;
179                         yylval.num = atoi(yytext);
180                         return(SECONDS);
181                 }
182 infinity        {
183                         return(INFINITY);
184                 }
185
186 on              {
187                         yylval.num = 1;
188                         return(ON);
189                 }
190 off             {
191                         yylval.num = 0;
192                         return(OFF);
193                 }
194
195         /* basic rules */
196 {ws}            ;
197 {nl}            {
198                         lineno++;
199                 }
200 {semi}          {
201                         return EOS;
202                 }
203 {bcl}           {
204                         return BCL;
205                 }
206 {ecl}           {
207                         return ECL;
208                 }
209 {qstring}       {
210                         yylval.cs.cp = yytext;
211                         yylval.cs.len = yyleng;
212                         return QSTRING;
213                 }
214 {decstring}     {
215                         yylval.cs.cp = yytext;
216                         yylval.cs.len = yyleng;
217                         return DECSTRING;
218                 }
219 {name}          {
220                         yylval.cs.cp = yytext;
221                         yylval.cs.len = yyleng;
222                         return NAME;
223                 }
224 {ipv4addr}      {
225                         memset(&yylval.addr4, 0, sizeof(struct in_addr));
226                         if (inet_pton(AF_INET, yytext,
227                                       &yylval.addr4) == 1) {
228                                 return IPV4ADDR;
229                         } else {
230                                 return ERROR;
231                         }
232                 }
233 {ipv6addr}      {
234                         memset(&yylval.addr6, 0, sizeof(struct in6_addr));
235                         if (inet_pton(AF_INET6, yytext,
236                                       &yylval.addr6) == 1) {
237                                 return IPV6ADDR;
238                         } else {
239                                 return ERROR;
240                         }
241                 }
242 {ipaddrmask}    {
243                         yytext++;
244                         yylval.num = atoi(yytext);
245                         return(PREFIXLEN);
246                 }
247 {hostname}      {
248                         yylval.cs.cp = yytext;
249                         yylval.cs.len = yyleng;
250                         return HOSTNAME;
251                 }
252 %%
253
254 int parse(FILE **fp)
255 {
256         extern int yyparse(void);
257
258         yyin = *fp;
259
260         if (yyparse())
261                 return(-1);
262
263         return(0);
264
265 }
266
267 void
268 yyerror(const char *s)
269 {
270         printf("%s: at %s in line %d\n", s, yytext, lineno);
271 }