1 %x string name charmap defn nchar subs subs2
4 * Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
5 * at Electronni Visti IA, Kiev, Ukraine.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
42 int line_no = 1, save_no, fromsubs;
43 u_char buf[BUFSIZE], *ptr;
45 YY_BUFFER_STATE main_buf, map_buf;
48 #endif /* FLEX_DEBUG */
52 <INITIAL,charmap,nchar,subs,subs2>[ \t]+ ;
53 <subs2>\" { ptr = buf; BEGIN(string); }
54 <subs>\< { ptr = buf; fromsubs = 1; BEGIN(name); }
55 <INITIAL>\< { ptr = buf; fromsubs = 0; BEGIN(name); }
58 <INITIAL>\\\n line_no++;
59 <INITIAL,nchar,subs>\\t { yylval.ch = '\t'; return CHAR; }
60 <INITIAL,nchar,subs>\\n { yylval.ch = '\n'; return CHAR; }
61 <INITIAL,nchar,subs>\\b { yylval.ch = '\b'; return CHAR; }
62 <INITIAL,nchar,subs>\\f { yylval.ch = '\f'; return CHAR; }
63 <INITIAL,nchar,subs>\\v { yylval.ch = '\v'; return CHAR; }
64 <INITIAL,nchar,subs>\\r { yylval.ch = '\r'; return CHAR; }
65 <INITIAL,nchar,subs>\\a { yylval.ch = '\a'; return CHAR; }
79 <INITIAL>[;,{}()] return *yytext;
80 <INITIAL>substitute { BEGIN(subs); return SUBSTITUTE; }
81 <subs>with { BEGIN(subs2); return WITH; }
82 <INITIAL>order return ORDER;
83 <INITIAL>charmap BEGIN(charmap);
84 <INITIAL>;[ \t]*\.\.\.[ \t]*; return RANGE;
85 <INITIAL,nchar,subs>\\[0-7]{3} {
88 sscanf(&yytext[1], "%o", &v);
89 yylval.ch = (u_char)v;
92 <INITIAL,nchar,subs>\\x[0-9a-fA-F]{2} {
95 sscanf(&yytext[2], "%x", &v);
96 yylval.ch = (u_char)v;
99 <INITIAL,nchar,subs>\\. { yylval.ch = yytext[1]; return CHAR; }
100 <INITIAL,nchar,subs>. { yylval.ch = *yytext; return CHAR; }
101 <defn>^#.*\n line_no++;
104 errx(EX_UNAVAILABLE, "map expected near line %u of %s",
107 strcpy(yylval.str, buf);
112 if(ptr >= buf + sizeof(buf) - 1)
113 errx(EX_UNAVAILABLE, "name buffer overflow near line %u, character '/'",
118 if(ptr >= buf + sizeof(buf) - 1)
119 errx(EX_UNAVAILABLE, "name buffer overflow near line %u, character '>'",
124 if(ptr >= buf + sizeof(buf) - 1)
125 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\"'",
133 errx(EX_UNAVAILABLE, "non-empty name expected near line %u",
136 for (i = 0; i <= UCHAR_MAX; i++) {
137 if (strcmp(charmap_table[i], buf) == 0)
140 errx(EX_UNAVAILABLE, "name <%s> not 'charmap'-defined near line %u",
152 strcpy(yylval.str, buf);
157 const char *s = (map_fp != NULL) ? map_name : "input";
159 if (!isascii(*yytext) || !isprint(*yytext))
160 errx(EX_UNAVAILABLE, "non-ASCII or non-printable character 0x%02x not allowed in the map/name near line %u of %s",
161 *yytext, line_no, s);
162 if(ptr >= buf + sizeof(buf) - 1)
163 errx(EX_UNAVAILABLE, "map/name buffer overflow near line %u of %s, character '%c'",
164 line_no, s, *yytext);
168 if(ptr >= buf + sizeof(buf) - 1)
169 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\t'",
174 if(ptr >= buf + sizeof(buf) - 1)
175 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\b'",
180 if(ptr >= buf + sizeof(buf) - 1)
181 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\f'",
186 if(ptr >= buf + sizeof(buf) - 1)
187 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\v'",
192 if(ptr >= buf + sizeof(buf) - 1)
193 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\n'",
198 if(ptr >= buf + sizeof(buf) - 1)
199 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\r'",
204 if(ptr >= buf + sizeof(buf) - 1)
205 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\a'",
209 <name,string,defn>\n {
210 const char *s = (map_fp != NULL) ? map_name : "input";
212 errx(EX_UNAVAILABLE, "unterminated map/name/string near line %u of %s", line_no, s);
214 <name,string,nchar><<EOF>> {
215 const char *s = (map_fp != NULL) ? map_name : "input";
217 errx(EX_UNAVAILABLE, "premature EOF in the name/string/char near line %u of %s", line_no, s);
219 <string>\\x[0-9a-f]{2} {
222 sscanf(&yytext[2], "%x", &v);
228 sscanf(&yytext[1], "%o", &v);
232 if(ptr >= buf + sizeof(buf) - 1)
233 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '%c'",
238 if(ptr >= buf + sizeof(buf) - 1)
239 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '%c'",
244 strcat(map_name, "/");
245 strcat(map_name, yytext);
246 if((map_fp = fopen(map_name, "r")) == NULL)
247 err(EX_UNAVAILABLE, "can't open 'charmap' file %s",
251 map_buf = yy_new_buffer(map_fp, YY_BUF_SIZE);
252 main_buf = YY_CURRENT_BUFFER;
253 yy_switch_to_buffer(map_buf);
258 errx(EX_UNAVAILABLE, "'charmap' file name expected near line %u",
262 errx(EX_UNAVAILABLE, "'charmap' file name expected near line %u",
265 <INITIAL,defn><<EOF>> {
268 errx(EX_UNAVAILABLE, "premature EOF in the map near line %u of %s", line_no, map_name);
269 yy_switch_to_buffer(main_buf);
270 yy_delete_buffer(map_buf);
286 #endif /* FLEX_DEBUG */