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.3 2005/03/02 07:16:23 joerg Exp $
42 int line_no = 1, save_no, fromsubs;
43 static u_char buffer[BUFSIZE], *buf_ptr;
45 YY_BUFFER_STATE main_buf, map_buf;
48 #endif /* FLEX_DEBUG */
53 <INITIAL,charmap,nchar,subs,subs2>[ \t]+ ;
54 <subs2>\" { buf_ptr = buffer; BEGIN(string); }
55 <subs>\< { buf_ptr = buffer; fromsubs = 1; BEGIN(name); }
56 <INITIAL>\< { buf_ptr = buffer; fromsubs = 0; BEGIN(name); }
59 <INITIAL>\\\n line_no++;
60 <INITIAL,nchar,subs>\\t { yylval.ch = '\t'; return CHAR; }
61 <INITIAL,nchar,subs>\\n { yylval.ch = '\n'; return CHAR; }
62 <INITIAL,nchar,subs>\\b { yylval.ch = '\b'; return CHAR; }
63 <INITIAL,nchar,subs>\\f { yylval.ch = '\f'; return CHAR; }
64 <INITIAL,nchar,subs>\\v { yylval.ch = '\v'; return CHAR; }
65 <INITIAL,nchar,subs>\\r { yylval.ch = '\r'; return CHAR; }
66 <INITIAL,nchar,subs>\\a { yylval.ch = '\a'; return CHAR; }
80 <INITIAL>[;,{}()] return *yytext;
81 <INITIAL>substitute { BEGIN(subs); return SUBSTITUTE; }
82 <subs>with { BEGIN(subs2); return WITH; }
83 <INITIAL>order return ORDER;
84 <INITIAL>charmap BEGIN(charmap);
85 <INITIAL>;[ \t]*\.\.\.[ \t]*; return RANGE;
86 <INITIAL,nchar,subs>\\[0-7]{3} {
89 sscanf(&yytext[1], "%o", &v);
90 yylval.ch = (u_char)v;
93 <INITIAL,nchar,subs>\\x[0-9a-fA-F]{2} {
96 sscanf(&yytext[2], "%x", &v);
97 yylval.ch = (u_char)v;
100 <INITIAL,nchar,subs>\\. { yylval.ch = yytext[1]; return CHAR; }
101 <INITIAL,nchar,subs>. { yylval.ch = *yytext; return CHAR; }
102 <defn>^#.*\n line_no++;
104 if (buf_ptr == buffer)
105 errx(EX_UNAVAILABLE, "map expected near line %u of %s",
108 strcpy(yylval.str, buffer);
113 if(buf_ptr >= buffer + sizeof(buffer) - 1)
114 errx(EX_UNAVAILABLE, "name buffer overflow near line %u, character '/'",
119 if(buf_ptr >= buffer + sizeof(buffer) - 1)
120 errx(EX_UNAVAILABLE, "name buffer overflow near line %u, character '>'",
125 if(buf_ptr >= buffer + sizeof(buffer) - 1)
126 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\"'",
133 if (buf_ptr == buffer)
134 errx(EX_UNAVAILABLE, "non-empty name expected near line %u",
137 for (i = 0; i <= UCHAR_MAX; i++) {
138 if (strcmp(charmap_table[i], buffer) == 0)
141 errx(EX_UNAVAILABLE, "name <%s> not 'charmap'-defined near line %u",
153 strcpy(yylval.str, buffer);
158 const char *s = (map_fp != NULL) ? map_name : "input";
160 if (!isascii(*yytext) || !isprint(*yytext))
161 errx(EX_UNAVAILABLE, "non-ASCII or non-printable character 0x%02x not allowed in the map/name near line %u of %s",
162 *yytext, line_no, s);
163 if(buf_ptr >= buffer + sizeof(buffer) - 1)
164 errx(EX_UNAVAILABLE, "map/name buffer overflow near line %u of %s, character '%c'",
165 line_no, s, *yytext);
166 *buf_ptr++ = *yytext;
169 if(buf_ptr >= buffer + sizeof(buffer) - 1)
170 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\t'",
175 if(buf_ptr >= buffer + sizeof(buffer) - 1)
176 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\b'",
181 if(buf_ptr >= buffer + sizeof(buffer) - 1)
182 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\f'",
187 if(buf_ptr >= buffer + sizeof(buffer) - 1)
188 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\v'",
193 if(buf_ptr >= buffer + sizeof(buffer) - 1)
194 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\n'",
199 if(buf_ptr >= buffer + sizeof(buffer) - 1)
200 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\r'",
205 if(buf_ptr >= buffer + sizeof(buffer) - 1)
206 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\a'",
210 <name,string,defn>\n {
211 const char *s = (map_fp != NULL) ? map_name : "input";
213 errx(EX_UNAVAILABLE, "unterminated map/name/string near line %u of %s", line_no, s);
215 <name,string,nchar><<EOF>> {
216 const char *s = (map_fp != NULL) ? map_name : "input";
218 errx(EX_UNAVAILABLE, "premature EOF in the name/string/char near line %u of %s", line_no, s);
220 <string>\\x[0-9a-f]{2} {
223 sscanf(&yytext[2], "%x", &v);
224 *buf_ptr++ = (u_char)v;
229 sscanf(&yytext[1], "%o", &v);
230 *buf_ptr++ = (u_char)v;
233 if(buf_ptr >= buffer + sizeof(buffer) - 1)
234 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '%c'",
236 *buf_ptr++ = yytext[1];
239 if(buf_ptr >= buffer + sizeof(buffer) - 1)
240 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '%c'",
242 *buf_ptr++ = *yytext;
245 strcat(map_name, "/");
246 strcat(map_name, yytext);
247 if((map_fp = fopen(map_name, "r")) == NULL)
248 err(EX_UNAVAILABLE, "can't open 'charmap' file %s",
252 map_buf = yy_new_buffer(map_fp, YY_BUF_SIZE);
253 main_buf = YY_CURRENT_BUFFER;
254 yy_switch_to_buffer(map_buf);
259 errx(EX_UNAVAILABLE, "'charmap' file name expected near line %u",
263 errx(EX_UNAVAILABLE, "'charmap' file name expected near line %u",
266 <INITIAL,defn><<EOF>> {
268 if (buf_ptr != buffer)
269 errx(EX_UNAVAILABLE, "premature EOF in the map near line %u of %s", line_no, map_name);
270 yy_switch_to_buffer(main_buf);
271 yy_delete_buffer(map_buf);
287 #endif /* FLEX_DEBUG */