From 4b660977b3a9c1a1fc5c78ebbcea353f5051e59f Mon Sep 17 00:00:00 2001 From: wpaul Date: Thu, 11 Dec 2003 22:38:14 +0000 Subject: Commit the ndiscvt(8) utility too. (Missed it in the last import.) --- usr.sbin/ndiscvt/inf-token.l | 91 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 usr.sbin/ndiscvt/inf-token.l (limited to 'usr.sbin/ndiscvt/inf-token.l') diff --git a/usr.sbin/ndiscvt/inf-token.l b/usr.sbin/ndiscvt/inf-token.l new file mode 100644 index 0000000..4f192c5 --- /dev/null +++ b/usr.sbin/ndiscvt/inf-token.l @@ -0,0 +1,91 @@ +%{ +/* + * $Id: inf-token.l,v 1.2 2003/11/30 20:41:06 winter Exp $ + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include "y.tab.h" + +int lineno = 1; +#define YY_NO_UNPUT + +int yylex(void); +void yyerror(const char *); + +static void +update_lineno(const char *cp) +{ + while (*cp) + if (*cp++ == '\n') + lineno++; +} + +%} + +%% + +[ \t]+ ; +\n { lineno++; return EOL; } +\r ; +;.*$ ; += { return EQUALS; } +, { return COMMA; } +\"(\\\"|[^"])*\" { + int len = strlen(yytext) - 2; + int blen = len + 1; + char *walker; + int i; + update_lineno(yytext); + yylval.str = (char *)malloc(blen); + if (yylval.str == NULL) + goto out; + walker = yylval.str; + for (i = 1; i <= len; i++) { + if (yytext[i] == '\\') { + switch (yytext[i + 1]) { + case '\n': + i += 2; + while(isspace(yytext[i])) + i++; + break; + case '\"': + i++; + break; + case '(': + i++; + break; + default: + break; + } + } + *walker++ = yytext[i]; + } + *walker++ = '\0'; + out:; + return STRING; + } +\[[a-zA-Z0-9%&\{\}\-\.\/_\\\*\ ]+\] { + int len = strlen(yytext); + yytext[len-1] = '\0'; + yylval.str = strdup(yytext+1); + return SECTION; + } +[a-zA-Z0-9%&\{\}\-\.\/_\\\*]+ { + yylval.str = strdup(yytext); + return WORD; + } +%% + +void +yyerror(const char *s) +{ + errx(1, "line %d: %s%s %s.", lineno, yytext, yytext?":":"", s); +} -- cgit v1.1