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