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
29 * $FreeBSD: src/usr.bin/colldef/scan.l,v 1.11.2.2 2002/10/11 10:43:45 ache Exp $
30 * $DragonFly: src/usr.bin/colldef/scan.l,v 1.4 2008/10/16 01:52:32 swildner Exp $
44 int line_no = 1, save_no, fromsubs;
45 static u_char buffer[BUFSIZE], *buf_ptr;
47 YY_BUFFER_STATE main_buf, map_buf;
50 #endif /* FLEX_DEBUG */
55 <INITIAL,charmap,nchar,subs,subs2>[ \t]+ ;
56 <subs2>\" { buf_ptr = buffer; BEGIN(string); }
57 <subs>\< { buf_ptr = buffer; fromsubs = 1; BEGIN(name); }
58 <INITIAL>\< { buf_ptr = buffer; fromsubs = 0; BEGIN(name); }
61 <INITIAL>\\\n line_no++;
62 <INITIAL,nchar,subs>\\t { yylval.ch = '\t'; return CHAR; }
63 <INITIAL,nchar,subs>\\n { yylval.ch = '\n'; return CHAR; }
64 <INITIAL,nchar,subs>\\b { yylval.ch = '\b'; return CHAR; }
65 <INITIAL,nchar,subs>\\f { yylval.ch = '\f'; return CHAR; }
66 <INITIAL,nchar,subs>\\v { yylval.ch = '\v'; return CHAR; }
67 <INITIAL,nchar,subs>\\r { yylval.ch = '\r'; return CHAR; }
68 <INITIAL,nchar,subs>\\a { yylval.ch = '\a'; return CHAR; }
82 <INITIAL>[;,{}()] return *yytext;
83 <INITIAL>substitute { BEGIN(subs); return SUBSTITUTE; }
84 <subs>with { BEGIN(subs2); return WITH; }
85 <INITIAL>order return ORDER;
86 <INITIAL>charmap BEGIN(charmap);
87 <INITIAL>;[ \t]*\.\.\.[ \t]*; return RANGE;
88 <INITIAL,nchar,subs>\\[0-7]{3} {
91 sscanf(&yytext[1], "%o", &v);
92 yylval.ch = (u_char)v;
95 <INITIAL,nchar,subs>\\x[0-9a-fA-F]{2} {
98 sscanf(&yytext[2], "%x", &v);
99 yylval.ch = (u_char)v;
102 <INITIAL,nchar,subs>\\. { yylval.ch = yytext[1]; return CHAR; }
103 <INITIAL,nchar,subs>. { yylval.ch = *yytext; return CHAR; }
104 <defn>^#.*\n line_no++;
106 if (buf_ptr == buffer)
107 errx(EX_UNAVAILABLE, "map expected near line %u of %s",
110 strcpy(yylval.str, buffer);
115 if(buf_ptr >= buffer + sizeof(buffer) - 1)
116 errx(EX_UNAVAILABLE, "name buffer overflow near line %u, character '/'",
121 if(buf_ptr >= buffer + sizeof(buffer) - 1)
122 errx(EX_UNAVAILABLE, "name buffer overflow near line %u, character '>'",
127 if(buf_ptr >= buffer + sizeof(buffer) - 1)
128 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\"'",
135 if (buf_ptr == buffer)
136 errx(EX_UNAVAILABLE, "non-empty name expected near line %u",
139 for (i = 0; i <= UCHAR_MAX; i++) {
140 if (strcmp(charmap_table[i], buffer) == 0)
143 errx(EX_UNAVAILABLE, "name <%s> not 'charmap'-defined near line %u",
155 strcpy(yylval.str, buffer);
160 const char *s = (map_fp != NULL) ? map_name : "input";
162 if (!isascii(*yytext) || !isprint(*yytext))
163 errx(EX_UNAVAILABLE, "non-ASCII or non-printable character 0x%02x not allowed in the map/name near line %u of %s",
164 *yytext, line_no, s);
165 if(buf_ptr >= buffer + sizeof(buffer) - 1)
166 errx(EX_UNAVAILABLE, "map/name buffer overflow near line %u of %s, character '%c'",
167 line_no, s, *yytext);
168 *buf_ptr++ = *yytext;
171 if(buf_ptr >= buffer + sizeof(buffer) - 1)
172 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\t'",
177 if(buf_ptr >= buffer + sizeof(buffer) - 1)
178 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\b'",
183 if(buf_ptr >= buffer + sizeof(buffer) - 1)
184 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\f'",
189 if(buf_ptr >= buffer + sizeof(buffer) - 1)
190 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\v'",
195 if(buf_ptr >= buffer + sizeof(buffer) - 1)
196 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\n'",
201 if(buf_ptr >= buffer + sizeof(buffer) - 1)
202 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\r'",
207 if(buf_ptr >= buffer + sizeof(buffer) - 1)
208 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\a'",
212 <name,string,defn>\n {
213 const char *s = (map_fp != NULL) ? map_name : "input";
215 errx(EX_UNAVAILABLE, "unterminated map/name/string near line %u of %s", line_no, s);
217 <name,string,nchar><<EOF>> {
218 const char *s = (map_fp != NULL) ? map_name : "input";
220 errx(EX_UNAVAILABLE, "premature EOF in the name/string/char near line %u of %s", line_no, s);
222 <string>\\x[0-9a-f]{2} {
225 sscanf(&yytext[2], "%x", &v);
226 *buf_ptr++ = (u_char)v;
231 sscanf(&yytext[1], "%o", &v);
232 *buf_ptr++ = (u_char)v;
235 if(buf_ptr >= buffer + sizeof(buffer) - 1)
236 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '%c'",
238 *buf_ptr++ = yytext[1];
241 if(buf_ptr >= buffer + sizeof(buffer) - 1)
242 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '%c'",
244 *buf_ptr++ = *yytext;
247 strcat(map_name, "/");
248 strcat(map_name, yytext);
249 if((map_fp = fopen(map_name, "r")) == NULL)
250 err(EX_UNAVAILABLE, "can't open 'charmap' file %s",
254 map_buf = yy_new_buffer(map_fp, YY_BUF_SIZE);
255 main_buf = YY_CURRENT_BUFFER;
256 yy_switch_to_buffer(map_buf);
261 errx(EX_UNAVAILABLE, "'charmap' file name expected near line %u",
265 errx(EX_UNAVAILABLE, "'charmap' file name expected near line %u",
268 <INITIAL,defn><<EOF>> {
270 if (buf_ptr != buffer)
271 errx(EX_UNAVAILABLE, "premature EOF in the map near line %u of %s", line_no, map_name);
272 yy_switch_to_buffer(main_buf);
273 yy_delete_buffer(map_buf);
289 #endif /* FLEX_DEBUG */