summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ndiscvt/inf-token.l
diff options
context:
space:
mode:
authorwpaul <wpaul@FreeBSD.org>2003-12-11 22:38:14 +0000
committerwpaul <wpaul@FreeBSD.org>2003-12-11 22:38:14 +0000
commit4b660977b3a9c1a1fc5c78ebbcea353f5051e59f (patch)
tree7c2d5abaacdb24db0fe7ad5dd49024bfe7023096 /usr.sbin/ndiscvt/inf-token.l
parent7e1ac581496c0d5c9235e96f48e6664b7783122e (diff)
downloadFreeBSD-src-4b660977b3a9c1a1fc5c78ebbcea353f5051e59f.zip
FreeBSD-src-4b660977b3a9c1a1fc5c78ebbcea353f5051e59f.tar.gz
Commit the ndiscvt(8) utility too. (Missed it in the last import.)
Diffstat (limited to 'usr.sbin/ndiscvt/inf-token.l')
-rw-r--r--usr.sbin/ndiscvt/inf-token.l91
1 files changed, 91 insertions, 0 deletions
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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <regex.h>
+#include <ctype.h>
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#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);
+}
OpenPOWER on IntegriCloud