1 %x string s_name charmap defn nchar subs subs2 ldef elem
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: src/usr.bin/colldef/scan.l,v 1.19 2002/08/23 04:18:26 ache Exp $");
40 #include <sys/types.h>
45 int line_no = 1, save_no, fromsubs;
46 wchar_t buf0[BUFSIZE], *ptr;
48 wchar_t bufstr[BUFSIZE], *ptrsave;
50 YY_BUFFER_STATE main_buf, map_buf;
53 #endif /* FLEX_DEBUG */
55 static int localedefmode = 0;
59 <INITIAL,charmap,nchar,subs,subs2,ldef>[ \t]+ ;
60 <subs2,ldef>\" { ptr = buf; BEGIN(string); }
67 if(ptr >= buf + BUFSIZE - 1)
68 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '<'",
73 <subs>\< { ptr = buf; fromsubs = 1; BEGIN(s_name); }
74 <ldef>[,;] return *yytext;
75 <ldef>forward { yylval.ch = DIRECTIVE_FORWARD; return ORDER_DIRECTIVE; }
76 <ldef>backward { yylval.ch = DIRECTIVE_BACKWARD; return ORDER_DIRECTIVE; }
77 <ldef>position { yylval.ch = DIRECTIVE_POSITION; return ORDER_DIRECTIVE; }
78 <ldef>collating[-_]element return COLLATING_ELEMENT;
79 <ldef>collating[-_]symbol return COLLATING_SYMBOL;
80 <ldef>from return FROM;
81 <ldef>\.\.\. return ELLIPSIS;
82 <ldef>IGNORE return IGNORE;
83 <ldef>UNDEFINED return UNDEFINED;
84 <ldef>order[-_]start return ORDER_START;
86 char line[YY_BUF_SIZE];
89 /* The first pass only defined the left-most symbol. We reread the
90 * order lines, and forward references should now be resolved. */
95 if (fgets(line, sizeof(line), yyin) == NULL)
96 errx(EX_UNAVAILABLE, "EOF rescanning for order_start");
99 if (strstr(line, "order_start") != NULL)
102 return ORDER_SECOND_PASS;
104 <ldef>END[ \t]+LC_COLLATE return END_LC_COLLATE;
109 <ldef>\< { ptr = buf; BEGIN(elem); }
110 <INITIAL>\< { ptr = buf; fromsubs = 0; BEGIN(s_name); }
113 <INITIAL>\\\n line_no++;
114 <INITIAL,nchar,subs>\\t { yylval.ch = '\t'; return CHAR; }
115 <INITIAL,nchar,subs>\\n { yylval.ch = '\n'; return CHAR; }
116 <INITIAL,nchar,subs>\\b { yylval.ch = '\b'; return CHAR; }
117 <INITIAL,nchar,subs>\\f { yylval.ch = '\f'; return CHAR; }
118 <INITIAL,nchar,subs>\\v { yylval.ch = '\v'; return CHAR; }
119 <INITIAL,nchar,subs>\\r { yylval.ch = '\r'; return CHAR; }
120 <INITIAL,nchar,subs>\\a { yylval.ch = '\a'; return CHAR; }
128 if (map_fp != NULL) {
134 <INITIAL>[;,{}()] return *yytext;
135 <INITIAL>substitute { BEGIN(subs); return SUBSTITUTE; }
136 <INITIAL>LC_COLLATE { BEGIN(ldef); localedefmode++; return START_LC_COLLATE; }
137 <subs>with { BEGIN(subs2); return WITH; }
138 <INITIAL>order return ORDER;
139 <INITIAL,ldef>charmap BEGIN(charmap);
140 <INITIAL>;[ \t]*\.\.\.[ \t]*; return RANGE;
141 <INITIAL,nchar,subs>\\([0-7]{3}) {
144 sscanf(&yytext[1], "%o", &v);
148 <INITIAL,nchar,subs>\\x\{([0-9a-fA-F]{2,8})\} {
151 sscanf(&yytext[3], "%x", &v);
155 <INITIAL,nchar,subs>\\x([0-9a-fA-F]{2}) {
158 sscanf(&yytext[2], "%x", &v);
162 <INITIAL,nchar,subs>\\. { yylval.ch = yytext[1]; return CHAR; }
163 <INITIAL,nchar,subs>. { yylval.ch = *(u_char *)yytext; return CHAR; }
167 errx(EX_UNAVAILABLE, "map expected near line %u of %s",
170 if (localedefmode && *buf == '<' && ptr[-1] == '>') {
172 errx(EX_UNAVAILABLE, "map expected near line %u of %s",
175 wcscpy(yylval.str, buf + 1);
177 wcscpy(yylval.str, buf);
182 if(ptr >= buf + BUFSIZE - 1)
183 errx(EX_UNAVAILABLE, "name buffer overflow near line %u, character '/'",
188 if(ptr >= buf + BUFSIZE - 1)
189 errx(EX_UNAVAILABLE, "name buffer overflow near line %u, character '>'",
194 if(ptr >= buf + BUFSIZE - 1)
195 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\"'",
201 errx(EX_UNAVAILABLE, "non-empty name expected near line %u",
204 wcscpy(yylval.str, buf);
212 errx(EX_UNAVAILABLE, "non-empty name expected near line %u",
215 s = getsymbol(buf, EXISTS);
220 errx(EX_UNAVAILABLE, "name <%s> is chain type near line %u",
221 showwcs(buf, CHARMAP_SYMBOL_LEN), line_no);
223 errx(EX_UNAVAILABLE, "name <%s> is symbol type near line %u",
224 showwcs(buf, CHARMAP_SYMBOL_LEN), line_no);
226 errx(EX_UNAVAILABLE, "name <%s>: unknown symbol type (%d) near line %u",
227 showwcs(buf, CHARMAP_SYMBOL_LEN), s->type, line_no);
232 if(ptr >= buf + BUFSIZE - 1)
233 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character <%s>",
234 line_no, showwcs(bufstr, CHARMAP_SYMBOL_LEN));
248 wcscpy(yylval.str, buf);
255 <s_name,defn,elem>. {
256 const char *s = (map_fp != NULL) ? map_name : "input";
258 if (!isascii(*yytext) || !isprint(*yytext))
259 errx(EX_UNAVAILABLE, "non-ASCII or non-printable character 0x%02x not allowed in the map/name near line %u of %s",
260 *yytext, line_no, s);
261 if(ptr >= buf + BUFSIZE - 1)
262 errx(EX_UNAVAILABLE, "map/name buffer overflow near line %u of %s, character '%c'",
263 line_no, s, *yytext);
267 if(ptr >= buf + BUFSIZE - 1)
268 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\t'",
273 if(ptr >= buf + BUFSIZE - 1)
274 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\b'",
279 if(ptr >= buf + BUFSIZE - 1)
280 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\f'",
285 if(ptr >= buf + BUFSIZE - 1)
286 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\v'",
291 if(ptr >= buf + BUFSIZE - 1)
292 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\n'",
297 if(ptr >= buf + BUFSIZE - 1)
298 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\r'",
303 if(ptr >= buf + BUFSIZE - 1)
304 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\a'",
308 <s_name,string,defn,elem>\n {
309 const char *s = (map_fp != NULL) ? map_name : "input";
311 errx(EX_UNAVAILABLE, "unterminated map/name/string near line %u of %s", line_no, s);
313 <s_name,string,nchar,elem><<EOF>> {
314 const char *s = (map_fp != NULL) ? map_name : "input";
316 errx(EX_UNAVAILABLE, "premature EOF in the name/string/char near line %u of %s", line_no, s);
318 <string>\\x\{([0-9a-f]{2,8})\} {
321 sscanf(&yytext[3], "%x", &v);
324 <string>\\x([0-9a-f]{2}) {
327 sscanf(&yytext[2], "%x", &v);
330 <string>\\([0-7]{3}) {
333 sscanf(&yytext[1], "%o", &v);
337 if(ptr >= buf + BUFSIZE - 1)
338 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '%c'",
343 if(ptr >= buf + BUFSIZE - 1)
344 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '%c'",
350 strcpy(map_name, yytext);
352 strcat(map_name, "/");
353 strcat(map_name, yytext);
355 if((map_fp = fopen(map_name, "r")) == NULL)
356 err(EX_UNAVAILABLE, "can't open 'charmap' file %s",
360 map_buf = yy_new_buffer(map_fp, YY_BUF_SIZE);
361 main_buf = YY_CURRENT_BUFFER;
362 yy_switch_to_buffer(map_buf);
367 errx(EX_UNAVAILABLE, "'charmap' file name expected near line %u",
371 errx(EX_UNAVAILABLE, "'charmap' file name expected near line %u",
374 <INITIAL,defn><<EOF>> {
377 errx(EX_UNAVAILABLE, "premature EOF in the map near line %u of %s", line_no, map_name);
378 yy_switch_to_buffer(main_buf);
379 yy_delete_buffer(map_buf);
398 #endif /* FLEX_DEBUG */