lexer.l revision 62638
162638Skris/* $KAME$ */ 262638Skris 355505Sshin/* 455505Sshin * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 555505Sshin * All rights reserved. 655505Sshin * 755505Sshin * Redistribution and use in source and binary forms, with or without 855505Sshin * modification, are permitted provided that the following conditions 955505Sshin * are met: 1055505Sshin * 1. Redistributions of source code must retain the above copyright 1155505Sshin * notice, this list of conditions and the following disclaimer. 1255505Sshin * 2. Redistributions in binary form must reproduce the above copyright 1355505Sshin * notice, this list of conditions and the following disclaimer in the 1455505Sshin * documentation and/or other materials provided with the distribution. 1555505Sshin * 3. Neither the name of the project nor the names of its contributors 1655505Sshin * may be used to endorse or promote products derived from this software 1755505Sshin * without specific prior written permission. 1855505Sshin * 1955505Sshin * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 2055505Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2155505Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2255505Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 2355505Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2455505Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2555505Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2655505Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2755505Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2855505Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2955505Sshin * SUCH DAMAGE. 3055505Sshin * 3155505Sshin * $FreeBSD: head/usr.sbin/rrenumd/lexer.l 62638 2000-07-05 11:12:53Z kris $ 3255505Sshin */ 3355505Sshin 3455505Sshin%{ 3555505Sshin#include <sys/param.h> 3655505Sshin#include <sys/ioctl.h> 3755505Sshin#include <sys/socket.h> 3855505Sshin 3955505Sshin#include <string.h> 4055505Sshin 4155505Sshin#include <net/if.h> 4262638Skris#if defined(__FreeBSD__) && __FreeBSD__ >= 3 4355505Sshin#include <net/if_var.h> 4462638Skris#endif /* __FreeBSD__ >= 3 */ 4555505Sshin 4655505Sshin#include <netinet/in.h> 4755505Sshin#include <netinet/in_var.h> 4855505Sshin#include <netinet/icmp6.h> 4962638Skris 5062638Skris#include <arpa/inet.h> 5162638Skris 5255505Sshin#include "y.tab.h" 5355505Sshin 5455505Sshinint lineno = 1; 5555505Sshin 5662638Skris#define LINEBUF_SIZE 1000 5755505Sshinchar linebuf[LINEBUF_SIZE]; 5855505Sshin%} 5955505Sshin 6055505Sshin/* common section */ 6155505Sshinnl \n 6255505Sshinws [ \t]+ 6355505Sshindigit [0-9] 6455505Sshinletter [0-9A-Za-z] 6555505Sshinhexdigit [0-9A-Fa-f] 6655505Sshinspecial [()+\|\?\*,] 6755505Sshindot \. 6855505Sshinhyphen \- 6955505Sshincolon \: 7055505Sshinslash \/ 7155505Sshinbcl \{ 7255505Sshinecl \} 7355505Sshinsemi \; 7455505Sshinusec {dot}{digit}{1,6} 7555505Sshincomment \#.* 7655505Sshinqstring \"[^"]*\" 7755505Sshindecstring {digit}+ 7855505Sshinhexpair {hexdigit}{hexdigit} 7955505Sshinhexstring 0[xX]{hexdigit}+ 8055505Sshinoctetstring {octet}({dot}{octet})+ 8155505Sshinipv4addr {digit}{1,3}({dot}{digit}{1,3}){0,3} 8255505Sshinipv6addr {hexdigit}{0,4}({colon}{hexdigit}{0,4}){2,7} 8355505Sshinipaddrmask {slash}{digit}{1,3} 8455505Sshinkeyword {letter}{letter}+ 8555505Sshinname {letter}(({letter}|{digit}|{hyphen})*({letter}|{digit}))* 8655505Sshinhostname {name}(({dot}{name})+{dot}?)? 8755505Sshin 8855505Sshintimeval {digit}{0,2} 8955505Sshindays d{timeval} 9055505Sshinhours h{timeval} 9155505Sshinminutes m{timeval} 9255505Sshinseconds s{timeval} 9355505Sshin 9455505Sshinmprefix match_prefix|match-prefix 9555505Sshinuprefix use_prefix|use-prefix 9655505Sshin 9755505Sshin%% 9855505Sshin /* rrenumd keywords */ 9955505Sshindebug { 10055505Sshin return(DEBUG_CMD); 10155505Sshin } 10255505Sshindest { 10355505Sshin return(DEST_CMD); 10455505Sshin } 10555505Sshinretry { 10655505Sshin return(RETRY_CMD); 10755505Sshin } 10855505Sshinseqnum { 10955505Sshin return(SEQNUM_CMD); 11055505Sshin } 11155505Sshinadd { 11255505Sshin yylval.num = RPM_PCO_ADD; 11355505Sshin return(ADD); 11455505Sshin } 11555505Sshinchange { 11655505Sshin yylval.num = RPM_PCO_CHANGE; 11755505Sshin return(CHANGE); 11855505Sshin } 11955505Sshinsetglobal { 12055505Sshin yylval.num = RPM_PCO_SETGLOBAL; 12155505Sshin return(SETGLOBAL); 12255505Sshin } 12355505Sshin{mprefix} { 12455505Sshin return(MATCH_PREFIX_CMD); 12555505Sshin } 12655505Sshinmaxlen { 12755505Sshin return(MAXLEN_CMD); 12855505Sshin } 12955505Sshinminlen { 13055505Sshin return(MINLEN_CMD); 13155505Sshin } 13255505Sshin{uprefix} { 13355505Sshin return(USE_PREFIX_CMD); 13455505Sshin } 13555505Sshinkeeplen { 13655505Sshin return(KEEPLEN_CMD); 13755505Sshin } 13855505Sshin 13955505Sshinvltime { 14055505Sshin return(VLTIME_CMD); 14155505Sshin } 14255505Sshinpltime { 14355505Sshin return(PLTIME_CMD); 14455505Sshin } 14555505Sshinraf_onlink { 14655505Sshin return(RAF_ONLINK_CMD); 14755505Sshin } 14855505Sshinraf_auto { 14955505Sshin return(RAF_AUTO_CMD); 15055505Sshin } 15155505Sshinrrf_decrvalid { 15255505Sshin return(RAF_DECRVALID_CMD); 15355505Sshin } 15455505Sshinrrf_decrprefd { 15555505Sshin return(RAF_DECRPREFD_CMD); 15655505Sshin } 15755505Sshin{days} { 15855505Sshin yytext++; 15955505Sshin yylval.num = atoi(yytext); 16055505Sshin return(DAYS); 16155505Sshin } 16255505Sshin{hours} { 16355505Sshin yytext++; 16455505Sshin yylval.num = atoi(yytext); 16555505Sshin return(HOURS); 16655505Sshin } 16755505Sshin{minutes} { 16855505Sshin yytext++; 16955505Sshin yylval.num = atoi(yytext); 17055505Sshin return(MINUTES); 17155505Sshin } 17255505Sshin{seconds} { 17355505Sshin yytext++; 17455505Sshin yylval.num = atoi(yytext); 17555505Sshin return(SECONDS); 17655505Sshin } 17755505Sshininfinity { 17855505Sshin return(INFINITY); 17955505Sshin } 18055505Sshin 18155505Sshinon { 18255505Sshin yylval.num = 1; 18355505Sshin return(ON); 18455505Sshin } 18555505Sshinoff { 18655505Sshin yylval.num = 0; 18755505Sshin return(OFF); 18855505Sshin } 18955505Sshin 19055505Sshin /* basic rules */ 19155505Sshin{ws} ; 19255505Sshin{nl} { 19355505Sshin lineno++; 19455505Sshin } 19555505Sshin{semi} { 19655505Sshin return EOS; 19755505Sshin } 19855505Sshin{bcl} { 19955505Sshin return BCL; 20055505Sshin } 20155505Sshin{ecl} { 20255505Sshin return ECL; 20355505Sshin } 20455505Sshin{qstring} { 20555505Sshin yylval.cs.cp = yytext; 20655505Sshin yylval.cs.len = yyleng; 20755505Sshin return QSTRING; 20855505Sshin } 20955505Sshin{decstring} { 21055505Sshin yylval.cs.cp = yytext; 21155505Sshin yylval.cs.len = yyleng; 21255505Sshin return DECSTRING; 21355505Sshin } 21455505Sshin{name} { 21555505Sshin yylval.cs.cp = yytext; 21655505Sshin yylval.cs.len = yyleng; 21755505Sshin return NAME; 21855505Sshin } 21962638Skris{ipv4addr} { 22062638Skris memset(&yylval.addr4, 0, sizeof(struct in_addr)); 22162638Skris if (inet_pton(AF_INET, yytext, 22262638Skris &yylval.addr4) == 1) { 22362638Skris return IPV4ADDR; 22462638Skris } else { 22562638Skris return ERROR; 22662638Skris } 22762638Skris } 22855505Sshin{ipv6addr} { 22955505Sshin memset(&yylval.addr6, 0, sizeof(struct in6_addr)); 23055505Sshin if (inet_pton(AF_INET6, yytext, 23155505Sshin &yylval.addr6) == 1) { 23255505Sshin return IPV6ADDR; 23355505Sshin } else { 23455505Sshin return ERROR; 23555505Sshin } 23655505Sshin } 23755505Sshin{ipaddrmask} { 23855505Sshin yytext++; 23955505Sshin yylval.num = atoi(yytext); 24055505Sshin return(PREFIXLEN); 24155505Sshin } 24255505Sshin{hostname} { 24355505Sshin yylval.cs.cp = yytext; 24455505Sshin yylval.cs.len = yyleng; 24555505Sshin return HOSTNAME; 24655505Sshin } 24755505Sshin%% 24855505Sshin 24955505Sshinint parse(FILE **fp) 25055505Sshin{ 25155505Sshin yyin = *fp; 25255505Sshin 25355505Sshin if(yyparse()) 25455505Sshin return(-1); 25555505Sshin 25655505Sshin return(0); 25755505Sshin 25855505Sshin} 25955505Sshin 26055505Sshinvoid 26155505Sshinyyerror(const char *s) 26255505Sshin{ 26355505Sshin printf("%s: at %s in line %d\n", s, yytext, lineno); 26455505Sshin} 265