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