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