Deleted Added
full compact
scan.l (16073) scan.l (18950)
1%x string name charmap
1%x string name charmap defn nchar subs
2%{
3/*-
4 * Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
5 * at Electronni Visti IA, Kiev, Ukraine.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions

--- 11 unchanged lines hidden (view full) ---

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
27 * SUCH DAMAGE.
28 *
2%{
3/*-
4 * Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
5 * at Electronni Visti IA, Kiev, Ukraine.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions

--- 11 unchanged lines hidden (view full) ---

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
27 * SUCH DAMAGE.
28 *
29 * $Id: scan.l,v 1.1 1995/02/17 17:29:49 ache Exp $
29 * $Id: scan.l,v 1.3 1996/06/02 17:18:18 phk Exp $
30 */
31
30 */
31
32#include <ctype.h>
32#include <err.h>
33#include <unistd.h>
34#include <string.h>
35#include <sysexits.h>
36#include "collate.h"
37#include "y.tab.h"
38
33#include <err.h>
34#include <unistd.h>
35#include <string.h>
36#include <sysexits.h>
37#include "collate.h"
38#include "y.tab.h"
39
39int line_no = 1;
40int line_no = 1, save_no;
40u_char buf[STR_LEN], *ptr;
41FILE *map_fp;
41u_char buf[STR_LEN], *ptr;
42FILE *map_fp;
43extern char map_name[];
42YY_BUFFER_STATE main_buf, map_buf;
43#ifdef FLEX_DEBUG
44YYSTYPE yylval;
45#endif /* FLEX_DEBUG */
46%}
47%%
44YY_BUFFER_STATE main_buf, map_buf;
45#ifdef FLEX_DEBUG
46YYSTYPE yylval;
47#endif /* FLEX_DEBUG */
48%}
49%%
48<INITIAL,charmap>[ \t] ;
49\" { ptr = buf; BEGIN(string); }
50\< { ptr = buf; BEGIN(name); }
50<INITIAL,charmap,nchar,subs>[ \t]+ ;
51<subs>\" { ptr = buf; BEGIN(string); }
52<INITIAL>\< { ptr = buf; BEGIN(name); }
51^#.*\n line_no++;
52^\n line_no++;
53^#.*\n line_no++;
54^\n line_no++;
53\\\n line_no++;
54\\t { yylval.ch = '\t'; return CHAR; }
55\\n { yylval.ch = '\n'; return CHAR; }
56\\b { yylval.ch = '\b'; return CHAR; }
57\\f { yylval.ch = '\f'; return CHAR; }
58\\v { yylval.ch = '\v'; return CHAR; }
59\\r { yylval.ch = '\r'; return CHAR; }
60\\a { yylval.ch = '\a'; return CHAR; }
61\\. { yylval.ch = yytext[1]; return CHAR; }
62<INITIAL,charmap>\n { line_no++; return '\n'; }
63[;,{}()] return *yytext;
64substitute return SUBSTITUTE;
65with return WITH;
66order return ORDER;
67charmap BEGIN(charmap);
68;[ \t]*\.\.\.[ \t]*; return RANGE;
69\\[0-7]{3} {
55<INITIAL>\\\n line_no++;
56<INITIAL,nchar>\\t { yylval.ch = '\t'; return CHAR; }
57<INITIAL,nchar>\\n { yylval.ch = '\n'; return CHAR; }
58<INITIAL,nchar>\\b { yylval.ch = '\b'; return CHAR; }
59<INITIAL,nchar>\\f { yylval.ch = '\f'; return CHAR; }
60<INITIAL,nchar>\\v { yylval.ch = '\v'; return CHAR; }
61<INITIAL,nchar>\\r { yylval.ch = '\r'; return CHAR; }
62<INITIAL,nchar>\\a { yylval.ch = '\a'; return CHAR; }
63<INITIAL,nchar>\\. { yylval.ch = yytext[1]; return CHAR; }
64<subs>\n {
65 line_no++;
66 BEGIN(INITIAL);
67 return '\n';
68}
69<INITIAL,nchar>\n {
70 line_no++;
71 if (map_fp != NULL) {
72 ptr = buf;
73 BEGIN(defn);
74 }
75 return '\n';
76}
77<INITIAL>[;,{}()] return *yytext;
78<INITIAL>substitute { BEGIN(subs); return SUBSTITUTE; }
79<subs>with return WITH;
80<INITIAL>order return ORDER;
81<INITIAL>charmap BEGIN(charmap);
82<INITIAL>;[ \t]*\.\.\.[ \t]*; return RANGE;
83<INITIAL,nchar>\\[0-7]{3} {
70 u_int v;
71
72 sscanf(&yytext[1], "%o", &v);
73 yylval.ch = (u_char)v;
74 return CHAR;
75}
84 u_int v;
85
86 sscanf(&yytext[1], "%o", &v);
87 yylval.ch = (u_char)v;
88 return CHAR;
89}
76\\x[0-9a-z]{2} {
90<INITIAL,nchar>\\x[0-9a-z]{2} {
77 u_int v;
78
79 sscanf(&yytext[2], "%x", &v);
80 yylval.ch = (u_char)v;
81 return CHAR;
82}
91 u_int v;
92
93 sscanf(&yytext[2], "%x", &v);
94 yylval.ch = (u_char)v;
95 return CHAR;
96}
83[^;,{}() \t\n"<]+ {
97<INITIAL>[^;,{}() \t\n"<]+ {
84 if(yyleng == 1) {
85 yylval.ch = *yytext;
86 return CHAR;
87 }
88 if(yyleng > STR_LEN - 1)
89 errx(EX_UNAVAILABLE, "chain buffer overflaw near line %u",
90 line_no);
91 strcpy(yylval.str, yytext);
92 return CHAIN;
93}
98 if(yyleng == 1) {
99 yylval.ch = *yytext;
100 return CHAR;
101 }
102 if(yyleng > STR_LEN - 1)
103 errx(EX_UNAVAILABLE, "chain buffer overflaw near line %u",
104 line_no);
105 strcpy(yylval.str, yytext);
106 return CHAIN;
107}
94<name>\\\> {
108<nchar>. {
109 yylval.ch = *yytext;
110 return CHAR;
111}
112<defn>[ \t]+ {
113 if (ptr == buf)
114 errx(EX_UNAVAILABLE, "map expected near line %u of %s",
115 line_no, map_name);
116 *ptr = '\0';
117 strcpy(yylval.str, buf);
118 BEGIN(nchar);
119 return DEFN;
120}
121<name>\/\/ {
95 if(ptr >= buf + sizeof(buf) - 1)
122 if(ptr >= buf + sizeof(buf) - 1)
96 errx(EX_UNAVAILABLE, "name/string buffer overflaw near line %u",
123 errx(EX_UNAVAILABLE, "name buffer overflaw near line %u, character '/'",
97 line_no);
124 line_no);
125 *ptr++ = '/';
126}
127<name>\/\> {
128 if(ptr >= buf + sizeof(buf) - 1)
129 errx(EX_UNAVAILABLE, "name buffer overflaw near line %u, character '>'",
130 line_no);
98 *ptr++ = '>';
99}
100<string>\\\" {
101 if(ptr >= buf + sizeof(buf) - 1)
131 *ptr++ = '>';
132}
133<string>\\\" {
134 if(ptr >= buf + sizeof(buf) - 1)
102 errx(EX_UNAVAILABLE, "name/string buffer overflaw near line %u",
135 errx(EX_UNAVAILABLE, "string buffer overflaw near line %u, character '\"'",
103 line_no);
104 *ptr++ = '"';
105}
106<name>\> {
136 line_no);
137 *ptr++ = '"';
138}
139<name>\> {
140 if (ptr == buf)
141 errx(EX_UNAVAILABLE, "name expected near line %u",
142 line_no);
107 *ptr = '\0';
108 strcpy(yylval.str, buf);
109 BEGIN(INITIAL);
110 return NAME;
111}
112<string>\" {
113 *ptr = '\0';
114 strcpy(yylval.str, buf);
143 *ptr = '\0';
144 strcpy(yylval.str, buf);
145 BEGIN(INITIAL);
146 return NAME;
147}
148<string>\" {
149 *ptr = '\0';
150 strcpy(yylval.str, buf);
115 BEGIN(INITIAL);
151 BEGIN(subs);
116 return STRING;
117}
152 return STRING;
153}
118<name,string>. {
154<name,defn>. {
155 char *s = (map_fp != NULL) ? map_name : "input";
156
157 if (!isascii(*yytext) || !isprint(*yytext))
158 errx(EX_UNAVAILABLE, "non-ASCII or non-printable character 0x%02x not allowed in the map/name near line %u of %s",
159 *yytext, line_no, s);
119 if(ptr >= buf + sizeof(buf) - 1)
160 if(ptr >= buf + sizeof(buf) - 1)
120 errx(EX_UNAVAILABLE, "name/string buffer overflaw near line %u",
121 line_no);
161 errx(EX_UNAVAILABLE, "map/name buffer overflaw near line %u of %s, character '%c'",
162 line_no, s, *yytext);
122 *ptr++ = *yytext;
123}
163 *ptr++ = *yytext;
164}
124<name,string>\\t {
165<string>\\t {
125 if(ptr >= buf + sizeof(buf) - 1)
166 if(ptr >= buf + sizeof(buf) - 1)
126 errx(EX_UNAVAILABLE, "name/string buffer overflaw near line %u",
167 errx(EX_UNAVAILABLE, "string buffer overflaw near line %u, character '\\t'",
127 line_no);
128 *ptr++ = '\t';
129}
168 line_no);
169 *ptr++ = '\t';
170}
130<name,string>\\b {
171<string>\\b {
131 if(ptr >= buf + sizeof(buf) - 1)
172 if(ptr >= buf + sizeof(buf) - 1)
132 errx(EX_UNAVAILABLE, "name/string buffer overflaw near line %u",
173 errx(EX_UNAVAILABLE, "string buffer overflaw near line %u, character '\\b'",
133 line_no);
134 *ptr++ = '\b';
135}
174 line_no);
175 *ptr++ = '\b';
176}
136<name,string>\\f {
177<string>\\f {
137 if(ptr >= buf + sizeof(buf) - 1)
178 if(ptr >= buf + sizeof(buf) - 1)
138 errx(EX_UNAVAILABLE, "name/string buffer overflaw near line %u",
179 errx(EX_UNAVAILABLE, "string buffer overflaw near line %u, character '\\f'",
139 line_no);
140 *ptr++ = '\f';
141}
180 line_no);
181 *ptr++ = '\f';
182}
142<name,string>\\v {
183<string>\\v {
143 if(ptr >= buf + sizeof(buf) - 1)
184 if(ptr >= buf + sizeof(buf) - 1)
144 errx(EX_UNAVAILABLE, "name/string buffer overflaw near line %u",
185 errx(EX_UNAVAILABLE, "string buffer overflaw near line %u, character '\\v'",
145 line_no);
146 *ptr++ = '\v';
147}
186 line_no);
187 *ptr++ = '\v';
188}
148<name,string>\\n {
189<string>\\n {
149 if(ptr >= buf + sizeof(buf) - 1)
190 if(ptr >= buf + sizeof(buf) - 1)
150 errx(EX_UNAVAILABLE, "name/string buffer overflaw near line %u",
191 errx(EX_UNAVAILABLE, "string buffer overflaw near line %u, character '\\n'",
151 line_no);
152 *ptr++ = '\n';
153}
192 line_no);
193 *ptr++ = '\n';
194}
154<name,string>\\r {
195<string>\\r {
155 if(ptr >= buf + sizeof(buf) - 1)
196 if(ptr >= buf + sizeof(buf) - 1)
156 errx(EX_UNAVAILABLE, "name/string buffer overflaw near line %u",
197 errx(EX_UNAVAILABLE, "string buffer overflaw near line %u, character '\\r'",
157 line_no);
158 *ptr++ = '\r';
159}
198 line_no);
199 *ptr++ = '\r';
200}
160<name,string>\\a {
201<string>\\a {
161 if(ptr >= buf + sizeof(buf) - 1)
202 if(ptr >= buf + sizeof(buf) - 1)
162 errx(EX_UNAVAILABLE, "name/string buffer overflaw near line %u",
203 errx(EX_UNAVAILABLE, "string buffer overflaw near line %u, character '\\a'",
163 line_no);
164 *ptr++ = '\a';
165}
204 line_no);
205 *ptr++ = '\a';
206}
166<name,string><<EOF>> {
167 errx(EX_UNAVAILABLE, "unterminated name/string near line %u", line_no);
207<name,string,defn>\n {
208 char *s = (map_fp != NULL) ? map_name : "input";
209
210 errx(EX_UNAVAILABLE, "unterminated map/name/string near line %u of %s", line_no, s);
168}
211}
169<name,string>\\x[0-9a-f]{2} {
212<name,string,nchar><<EOF>> {
213 char *s = (map_fp != NULL) ? map_name : "input";
214
215 errx(EX_UNAVAILABLE, "premature EOF in the name/string/char near line %u of %s", line_no, s);
216}
217<string>\\x[0-9a-f]{2} {
170 u_int v;
171
172 sscanf(&yytext[2], "%x", &v);
173 *ptr++ = (u_char)v;
174}
218 u_int v;
219
220 sscanf(&yytext[2], "%x", &v);
221 *ptr++ = (u_char)v;
222}
175<name,string>\\[0-7]{3} {
223<string>\\[0-7]{3} {
176 u_int v;
177
178 sscanf(&yytext[1], "%o", &v);
179 *ptr++ = (u_char)v;
180}
224 u_int v;
225
226 sscanf(&yytext[1], "%o", &v);
227 *ptr++ = (u_char)v;
228}
229<string>\\. {
230 if(ptr >= buf + sizeof(buf) - 1)
231 errx(EX_UNAVAILABLE, "string buffer overflaw near line %u, character '%c'",
232 line_no, yytext[1]);
233 *ptr++ = yytext[1];
234}
235<string>. {
236 if(ptr >= buf + sizeof(buf) - 1)
237 errx(EX_UNAVAILABLE, "string buffer overflaw near line %u, character '%c'",
238 line_no, *yytext);
239 *ptr++ = *yytext;
240}
181<charmap>[^ \t\n]+ {
241<charmap>[^ \t\n]+ {
182 if((map_fp = fopen(yytext, "r")) == 0)
183 err(EX_UNAVAILABLE, "can't open charmap file %s near line %u",
184 yytext, line_no);
242 strcat(map_name, "/");
243 strcat(map_name, yytext);
244 if((map_fp = fopen(map_name, "r")) == NULL)
245 err(EX_UNAVAILABLE, "can't open 'charmap' file %s",
246 map_name);
247 save_no = line_no;
248 line_no = 1;
185 map_buf = yy_new_buffer(map_fp, YY_BUF_SIZE);
186 main_buf = YY_CURRENT_BUFFER;
187 yy_switch_to_buffer(map_buf);
249 map_buf = yy_new_buffer(map_fp, YY_BUF_SIZE);
250 main_buf = YY_CURRENT_BUFFER;
251 yy_switch_to_buffer(map_buf);
188 BEGIN(INITIAL);
252 ptr = buf;
253 BEGIN(defn);
189}
254}
190<charmap><<EOF>> {
191 errx(EX_UNAVAILABLE, "charmap file name expected near line %u",
255<charmap>\n {
256 errx(EX_UNAVAILABLE, "'charmap' file name expected near line %u",
192 line_no);
193}
257 line_no);
258}
194<<EOF>> {
195 if(map_fp) {
259<charmap><<EOF>> {
260 errx(EX_UNAVAILABLE, "'charmap' file name expected near line %u",
261 line_no);
262}
263<INITIAL,defn><<EOF>> {
264 if(map_fp != NULL) {
265 if (ptr != buf)
266 errx(EX_UNAVAILABLE, "premature EOF in the map near line %u of %s", line_no, map_name);
196 yy_switch_to_buffer(main_buf);
197 yy_delete_buffer(map_buf);
198 fclose(map_fp);
267 yy_switch_to_buffer(main_buf);
268 yy_delete_buffer(map_buf);
269 fclose(map_fp);
199 map_fp = 0;
200 }
201 else
270 map_fp = NULL;
271 line_no = save_no;
272 BEGIN(INITIAL);
273 } else
202 yyterminate();
203}
204%%
205#ifdef FLEX_DEBUG
206main()
207{
208 while(yylex())
209 ;
210 return 0;
211}
212#endif /* FLEX_DEBUG */
274 yyterminate();
275}
276%%
277#ifdef FLEX_DEBUG
278main()
279{
280 while(yylex())
281 ;
282 return 0;
283}
284#endif /* FLEX_DEBUG */