1*d44a5ed1SThomas Cort /* $NetBSD: msgscan.l,v 1.7 2012/03/06 16:26:01 mbalmer Exp $ */
2*d44a5ed1SThomas Cort
3*d44a5ed1SThomas Cort /*
4*d44a5ed1SThomas Cort * Copyright 1997 Piermont Information Systems Inc.
5*d44a5ed1SThomas Cort * All rights reserved.
6*d44a5ed1SThomas Cort *
7*d44a5ed1SThomas Cort * Written by Philip A. Nelson for Piermont Information Systems Inc.
8*d44a5ed1SThomas Cort *
9*d44a5ed1SThomas Cort * Redistribution and use in source and binary forms, with or without
10*d44a5ed1SThomas Cort * modification, are permitted provided that the following conditions
11*d44a5ed1SThomas Cort * are met:
12*d44a5ed1SThomas Cort * 1. Redistributions of source code must retain the above copyright
13*d44a5ed1SThomas Cort * notice, this list of conditions and the following disclaimer.
14*d44a5ed1SThomas Cort * 2. Redistributions in binary form must reproduce the above copyright
15*d44a5ed1SThomas Cort * notice, this list of conditions and the following disclaimer in the
16*d44a5ed1SThomas Cort * documentation and/or other materials provided with the distribution.
17*d44a5ed1SThomas Cort * 3. The name of Piermont Information Systems Inc. may not be used to endorse
18*d44a5ed1SThomas Cort * or promote products derived from this software without specific prior
19*d44a5ed1SThomas Cort * written permission.
20*d44a5ed1SThomas Cort *
21*d44a5ed1SThomas Cort * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
22*d44a5ed1SThomas Cort * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23*d44a5ed1SThomas Cort * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24*d44a5ed1SThomas Cort * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
25*d44a5ed1SThomas Cort * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26*d44a5ed1SThomas Cort * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27*d44a5ed1SThomas Cort * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28*d44a5ed1SThomas Cort * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29*d44a5ed1SThomas Cort * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30*d44a5ed1SThomas Cort * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31*d44a5ed1SThomas Cort * THE POSSIBILITY OF SUCH DAMAGE.
32*d44a5ed1SThomas Cort *
33*d44a5ed1SThomas Cort */
34*d44a5ed1SThomas Cort
35*d44a5ed1SThomas Cort %{
36*d44a5ed1SThomas Cort /* scan.l: scanner description for message compiler. */
37*d44a5ed1SThomas Cort
38*d44a5ed1SThomas Cort #include <sys/cdefs.h>
39*d44a5ed1SThomas Cort
40*d44a5ed1SThomas Cort #if defined(__RCSID) && !defined(lint)
41*d44a5ed1SThomas Cort __RCSID("$NetBSD: msgscan.l,v 1.7 2012/03/06 16:26:01 mbalmer Exp $");
42*d44a5ed1SThomas Cort #endif
43*d44a5ed1SThomas Cort
44*d44a5ed1SThomas Cort
45*d44a5ed1SThomas Cort #include <stdio.h>
46*d44a5ed1SThomas Cort #include <string.h>
47*d44a5ed1SThomas Cort #include "defs.h"
48*d44a5ed1SThomas Cort #include "msgparse.h"
49*d44a5ed1SThomas Cort
50*d44a5ed1SThomas Cort static int level; /* For nested comments. */
51*d44a5ed1SThomas Cort
52*d44a5ed1SThomas Cort %}
53*d44a5ed1SThomas Cort
54*d44a5ed1SThomas Cort %x COMMENT
55*d44a5ed1SThomas Cort %x BRACE
56*d44a5ed1SThomas Cort
57*d44a5ed1SThomas Cort %option noinput
58*d44a5ed1SThomas Cort
59*d44a5ed1SThomas Cort %%
60*d44a5ed1SThomas Cort
61*d44a5ed1SThomas Cort [ \t]+ { /* ignore spaces and tabs */ }
62*d44a5ed1SThomas Cort
63*d44a5ed1SThomas Cort [\n] { line_no++; }
64*d44a5ed1SThomas Cort
65*d44a5ed1SThomas Cort ";" { return (int)yytext[0]; }
66*d44a5ed1SThomas Cort
67*d44a5ed1SThomas Cort message { return MESSAGE; }
68*d44a5ed1SThomas Cort
69*d44a5ed1SThomas Cort [a-zA-Z][a-zA-Z0-9_]* {
70*d44a5ed1SThomas Cort yylval.s_value = strdup(yytext);
71*d44a5ed1SThomas Cort return(NAME);
72*d44a5ed1SThomas Cort }
73*d44a5ed1SThomas Cort
74*d44a5ed1SThomas Cort "/*" { level = 1; BEGIN COMMENT; }
75*d44a5ed1SThomas Cort
76*d44a5ed1SThomas Cort <COMMENT>"/*" { level++; }
77*d44a5ed1SThomas Cort
78*d44a5ed1SThomas Cort <COMMENT>"*/" { if (level-- == 1) BEGIN 0; }
79*d44a5ed1SThomas Cort
80*d44a5ed1SThomas Cort <COMMENT>"\n" { line_no++; }
81*d44a5ed1SThomas Cort
82*d44a5ed1SThomas Cort <COMMENT><<EOF>> { yyerror ("EOF inside a comment."); exit (1); }
83*d44a5ed1SThomas Cort
84*d44a5ed1SThomas Cort <COMMENT>. {/* eat character */}
85*d44a5ed1SThomas Cort
86*d44a5ed1SThomas Cort "{" { level = 1; BEGIN BRACE; }
87*d44a5ed1SThomas Cort
88*d44a5ed1SThomas Cort <BRACE>"\\{" { buff_add_ch('{'); }
89*d44a5ed1SThomas Cort
90*d44a5ed1SThomas Cort <BRACE>"\\}" { buff_add_ch('}'); }
91*d44a5ed1SThomas Cort
92*d44a5ed1SThomas Cort <BRACE>"{" { buff_add_ch(yytext[0]); level++; }
93*d44a5ed1SThomas Cort
94*d44a5ed1SThomas Cort <BRACE>"}" { if (level-- == 1) {
95*d44a5ed1SThomas Cort BEGIN 0;
96*d44a5ed1SThomas Cort yylval.s_value = buff_copy();
97*d44a5ed1SThomas Cort return VALUE;
98*d44a5ed1SThomas Cort } else
99*d44a5ed1SThomas Cort buff_add_ch (yytext[0]);
100*d44a5ed1SThomas Cort }
101*d44a5ed1SThomas Cort
102*d44a5ed1SThomas Cort <BRACE>"\n" { buff_add_ch (yytext[0]); line_no++; }
103*d44a5ed1SThomas Cort
104*d44a5ed1SThomas Cort <BRACE>. { buff_add_ch (yytext[0]); }
105*d44a5ed1SThomas Cort
106*d44a5ed1SThomas Cort . {
107*d44a5ed1SThomas Cort if (yytext[0] < ' ')
108*d44a5ed1SThomas Cort yyerror ("illegal character: ^%c",yytext[0] + '@');
109*d44a5ed1SThomas Cort else
110*d44a5ed1SThomas Cort if (yytext[0] > '~')
111*d44a5ed1SThomas Cort yyerror ("illegal character: \\%3d", (int) yytext[0]);
112*d44a5ed1SThomas Cort else
113*d44a5ed1SThomas Cort yyerror ("illegal character: %s",yytext);
114*d44a5ed1SThomas Cort
115*d44a5ed1SThomas Cort /* To quiet the compiler */
116*d44a5ed1SThomas Cort if (0) unput(0);
117*d44a5ed1SThomas Cort }
118*d44a5ed1SThomas Cort %%
119*d44a5ed1SThomas Cort
120*d44a5ed1SThomas Cort #ifdef SCAN
121*d44a5ed1SThomas Cort YYSTYPE yylval;
122*d44a5ed1SThomas Cort
main()123*d44a5ed1SThomas Cort main()
124*d44a5ed1SThomas Cort {
125*d44a5ed1SThomas Cort int val;
126*d44a5ed1SThomas Cort
127*d44a5ed1SThomas Cort line_no = 1;
128*d44a5ed1SThomas Cort while ( (val = yylex()) != 0 )
129*d44a5ed1SThomas Cort printf ("val = %d\n yytext = %s\n", val, yytext);
130*d44a5ed1SThomas Cort }
131*d44a5ed1SThomas Cort #endif
132