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