Merge branch 'vendor/DIFFUTILS'
[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  * $DragonFly: src/usr.sbin/rrenumd/lexer.l,v 1.4 2004/02/10 02:59:43 rob Exp $
33  */
34
35 %{
36
37 #pragma GCC diagnostic ignored "-Wsign-compare"
38 #include <sys/param.h>
39 #include <sys/ioctl.h>
40 #include <sys/socket.h>
41 #include <sys/queue.h>
42
43 #include <string.h>
44
45 #include <net/if.h>
46 #if defined(__DragonFly__) 
47 #include <net/if_var.h>
48 #endif /* __DragonFly__  */
49
50 #include <netinet/in.h>
51 #include <netinet/in_var.h>
52 #include <netinet/icmp6.h>
53
54 #include <arpa/inet.h>
55
56 #include "y.tab.h"
57
58 int lineno = 1;
59
60 #define LINEBUF_SIZE 1000
61 char linebuf[LINEBUF_SIZE];
62
63 int parse(FILE **);
64 void yyerror(const char *);
65 %}
66
67 %option noinput
68 %option nounput
69
70 /* common section */
71 nl              \n
72 ws              [ \t]+
73 digit           [0-9]
74 letter          [0-9A-Za-z]
75 hexdigit        [0-9A-Fa-f]
76 special         [()+\|\?\*,]
77 dot             \.
78 hyphen          \-
79 colon           \:
80 slash           \/
81 bcl             \{
82 ecl             \}
83 semi            \;
84 usec            {dot}{digit}{1,6}
85 comment         \#.*
86 qstring         \"[^"]*\"
87 decstring       {digit}+
88 hexpair         {hexdigit}{hexdigit}
89 hexstring       0[xX]{hexdigit}+
90 octetstring     {octet}({dot}{octet})+
91 ipv4addr        {digit}{1,3}({dot}{digit}{1,3}){0,3}
92 ipv6addr        {hexdigit}{0,4}({colon}{hexdigit}{0,4}){2,7}
93 ipaddrmask      {slash}{digit}{1,3}
94 keyword         {letter}{letter}+
95 name            {letter}(({letter}|{digit}|{hyphen})*({letter}|{digit}))*
96 hostname        {name}(({dot}{name})+{dot}?)?
97
98 timeval         {digit}{0,2}
99 days            d{timeval}
100 hours           h{timeval}
101 minutes         m{timeval}
102 seconds         s{timeval}
103
104 mprefix         match_prefix|match-prefix
105 uprefix         use_prefix|use-prefix
106
107 %%
108         /* rrenumd keywords */
109 debug           {
110                         return(DEBUG_CMD);
111                 }
112 dest            {
113                         return(DEST_CMD);
114                 }
115 retry           {
116                         return(RETRY_CMD);
117                 }
118 seqnum          {
119                         return(SEQNUM_CMD);
120                 }
121 add             {
122                         yylval.num = RPM_PCO_ADD;
123                         return(ADD);
124                 }
125 change          {
126                         yylval.num = RPM_PCO_CHANGE;
127                         return(CHANGE);
128                  }
129 setglobal       {
130                         yylval.num = RPM_PCO_SETGLOBAL;
131                         return(SETGLOBAL);
132                 }
133 {mprefix}       {
134                         return(MATCH_PREFIX_CMD);
135                 }
136 maxlen          {
137                         return(MAXLEN_CMD);
138                 }
139 minlen          {
140                         return(MINLEN_CMD);
141                 }
142 {uprefix}       {
143                         return(USE_PREFIX_CMD);
144                 }
145 keeplen         {
146                         return(KEEPLEN_CMD);
147                 }
148
149 vltime          {
150                         return(VLTIME_CMD);
151                 }
152 pltime          {
153                         return(PLTIME_CMD);
154                 }
155 raf_onlink      {
156                         return(RAF_ONLINK_CMD);
157                 }
158 raf_auto        {
159                         return(RAF_AUTO_CMD);
160                 }
161 rrf_decrvalid   {
162                         return(RAF_DECRVALID_CMD);
163                 }
164 rrf_decrprefd   {
165                         return(RAF_DECRPREFD_CMD);
166                 }
167 {days}          {
168                         yytext++;
169                         yylval.num = atoi(yytext);
170                         return(DAYS);
171                 }
172 {hours}         {
173                         yytext++;
174                         yylval.num = atoi(yytext);
175                         return(HOURS);
176                 }
177 {minutes}       {
178                         yytext++;
179                         yylval.num = atoi(yytext);
180                         return(MINUTES);
181                 }
182 {seconds}       {
183                         yytext++;
184                         yylval.num = atoi(yytext);
185                         return(SECONDS);
186                 }
187 infinity        {
188                         return(INFINITY);
189                 }
190
191 on              {
192                         yylval.num = 1;
193                         return(ON);
194                 }
195 off             {
196                         yylval.num = 0;
197                         return(OFF);
198                 }
199
200         /* basic rules */
201 {ws}            ;
202 {nl}            {
203                         lineno++;
204                 }
205 {semi}          {
206                         return EOS;
207                 }
208 {bcl}           {
209                         return BCL;
210                 }
211 {ecl}           {
212                         return ECL;
213                 }
214 {qstring}       {
215                         yylval.cs.cp = yytext;
216                         yylval.cs.len = yyleng;
217                         return QSTRING;
218                 }
219 {decstring}     {
220                         yylval.cs.cp = yytext;
221                         yylval.cs.len = yyleng;
222                         return DECSTRING;
223                 }
224 {name}          {
225                         yylval.cs.cp = yytext;
226                         yylval.cs.len = yyleng;
227                         return NAME;
228                 }
229 {ipv4addr}      {
230                         memset(&yylval.addr4, 0, sizeof(struct in_addr));
231                         if (inet_pton(AF_INET, yytext,
232                                       &yylval.addr4) == 1) {
233                                 return IPV4ADDR;
234                         } else {
235                                 return ERROR;
236                         }
237                 }
238 {ipv6addr}      {
239                         memset(&yylval.addr6, 0, sizeof(struct in6_addr));
240                         if (inet_pton(AF_INET6, yytext,
241                                       &yylval.addr6) == 1) {
242                                 return IPV6ADDR;
243                         } else {
244                                 return ERROR;
245                         }
246                 }
247 {ipaddrmask}    {
248                         yytext++;
249                         yylval.num = atoi(yytext);
250                         return(PREFIXLEN);
251                 }
252 {hostname}      {
253                         yylval.cs.cp = yytext;
254                         yylval.cs.len = yyleng;
255                         return HOSTNAME;
256                 }
257 %%
258
259 int parse(FILE **fp)
260 {
261         extern int yyparse(void);
262
263         yyin = *fp;
264
265         if (yyparse())
266                 return(-1);
267
268         return(0);
269
270 }
271
272 void
273 yyerror(const char *s)
274 {
275         printf("%s: at %s in line %d\n", s, yytext, lineno);
276 }