lexer.l revision 225736
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: stable/9/usr.sbin/rrenumd/lexer.l 173412 2007-11-07 10:53:41Z kevlo $ 32 */ 33 34%{ 35#define YY_NO_UNPUT 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#if defined(__FreeBSD__) && __FreeBSD__ >= 3 46#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(FILE **); 63void yyerror(const char *); 64int yylex(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(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