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