Now that the base issue is fixed, enable -Wsign-compare again in scanners.
[dragonfly.git] / usr.sbin / ndiscvt / inf-token.l
CommitLineData
799e5dd9
MD
1%{
2/*
3 * Copyright (c) 2003
4 * Bill Paul <wpaul@windriver.com>. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Bill Paul.
17 * 4. Neither the name of the author nor the names of any co-contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 *
efba76b4 33 * $FreeBSD: src/usr.sbin/ndiscvt/inf-token.l,v 1.3 2004/01/11 21:10:35 mdodd Exp $
799e5dd9
MD
34 */
35
efba76b4 36#include <regex.h>
799e5dd9
MD
37#include <ctype.h>
38#include <err.h>
39#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
799e5dd9
MD
42#include "y.tab.h"
43
44int lineno = 1;
799e5dd9 45
799e5dd9
MD
46void yyerror(const char *);
47
48static void
49update_lineno(const char *cp)
50{
51 while (*cp)
52 if (*cp++ == '\n')
53 lineno++;
54}
55
56%}
57
eb74dec6
JM
58%option noinput
59%option nounput
60
799e5dd9
MD
61%%
62
63[ \t]+ ;
64\n { lineno++; return EOL; }
65\r ;
66;.*$ ;
67\/\/.*$ ;
68= { return EQUALS; }
69, { return COMMA; }
70\"(\\\"|[^"]|\"\")*\" {
71 int len = strlen(yytext) - 2;
72 int blen = len + 1;
73 char *walker;
74 int i;
75 update_lineno(yytext);
76 yylval.str = (char *)malloc(blen);
77 if (yylval.str == NULL)
78 goto out;
79 walker = yylval.str;
80 for (i = 1; i <= len; i++) {
81 if (yytext[i] == '\"') {
82 switch (yytext[i + 1]) {
83 case '\"':
84 i++;
85 break;
86 default:
87 break;
88 }
89 }
90 if (yytext[i] == '\\') {
91 switch (yytext[i + 1]) {
92 case '\n':
93 i += 2;
94 while(isspace(yytext[i]))
95 i++;
96 break;
97 case '\"':
98 i++;
99 break;
100 case '(':
101 i++;
102 break;
103 default:
104 break;
105 }
106 }
107 *walker++ = yytext[i];
108 }
109 *walker++ = '\0';
110 out:;
111 return STRING;
112 }
113\[[a-zA-Z0-9%&\{\}\-\.\/_\\\*\ ]+\] {
114 int len = strlen(yytext);
115 yytext[len-1] = '\0';
116 yylval.str = strdup(yytext+1);
117 return SECTION;
118 }
119[a-zA-Z0-9%&\{\}\-\.\/_\\\*]+ {
120 yylval.str = strdup(yytext);
121 return WORD;
122 }
123%%
124
125void
126yyerror(const char *s)
127{
128 errx(1, "line %d: %s%s %s.", lineno, yytext, yytext?":":"", s);
129}