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