1999-02-13 14:14:47 +00:00
|
|
|
%x string name charmap defn nchar subs subs2
|
1995-02-17 17:29:50 +00:00
|
|
|
%{
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
|
|
|
|
* at Electronni Visti IA, Kiev, Ukraine.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2001-12-02 23:40:46 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1996-10-15 22:05:18 +00:00
|
|
|
#include <ctype.h>
|
1995-02-17 17:29:50 +00:00
|
|
|
#include <err.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sysexits.h>
|
|
|
|
#include "collate.h"
|
2001-11-27 23:11:05 +00:00
|
|
|
#include "common.h"
|
1996-06-02 17:22:01 +00:00
|
|
|
#include "y.tab.h"
|
1995-02-17 17:29:50 +00:00
|
|
|
|
1999-02-13 14:14:47 +00:00
|
|
|
int line_no = 1, save_no, fromsubs;
|
2001-11-28 09:50:24 +00:00
|
|
|
u_char buf[BUFSIZE], *ptr;
|
1995-02-17 17:29:50 +00:00
|
|
|
FILE *map_fp;
|
|
|
|
YY_BUFFER_STATE main_buf, map_buf;
|
|
|
|
#ifdef FLEX_DEBUG
|
|
|
|
YYSTYPE yylval;
|
|
|
|
#endif /* FLEX_DEBUG */
|
2001-12-02 23:40:46 +00:00
|
|
|
int yylex(void);
|
1995-02-17 17:29:50 +00:00
|
|
|
%}
|
|
|
|
%%
|
1999-02-13 14:14:47 +00:00
|
|
|
<INITIAL,charmap,nchar,subs,subs2>[ \t]+ ;
|
|
|
|
<subs2>\" { ptr = buf; BEGIN(string); }
|
|
|
|
<subs>\< { ptr = buf; fromsubs = 1; BEGIN(name); }
|
|
|
|
<INITIAL>\< { ptr = buf; fromsubs = 0; BEGIN(name); }
|
1995-02-17 17:29:50 +00:00
|
|
|
^#.*\n line_no++;
|
|
|
|
^\n line_no++;
|
1996-10-15 22:05:18 +00:00
|
|
|
<INITIAL>\\\n line_no++;
|
1999-02-13 14:14:47 +00:00
|
|
|
<INITIAL,nchar,subs>\\t { yylval.ch = '\t'; return CHAR; }
|
|
|
|
<INITIAL,nchar,subs>\\n { yylval.ch = '\n'; return CHAR; }
|
|
|
|
<INITIAL,nchar,subs>\\b { yylval.ch = '\b'; return CHAR; }
|
|
|
|
<INITIAL,nchar,subs>\\f { yylval.ch = '\f'; return CHAR; }
|
|
|
|
<INITIAL,nchar,subs>\\v { yylval.ch = '\v'; return CHAR; }
|
|
|
|
<INITIAL,nchar,subs>\\r { yylval.ch = '\r'; return CHAR; }
|
|
|
|
<INITIAL,nchar,subs>\\a { yylval.ch = '\a'; return CHAR; }
|
|
|
|
<INITIAL,nchar,subs>\\. { yylval.ch = yytext[1]; return CHAR; }
|
|
|
|
<subs2>\n {
|
1996-10-15 22:05:18 +00:00
|
|
|
line_no++;
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
return '\n';
|
|
|
|
}
|
|
|
|
<INITIAL,nchar>\n {
|
|
|
|
line_no++;
|
|
|
|
if (map_fp != NULL) {
|
|
|
|
ptr = buf;
|
|
|
|
BEGIN(defn);
|
|
|
|
}
|
|
|
|
return '\n';
|
|
|
|
}
|
|
|
|
<INITIAL>[;,{}()] return *yytext;
|
|
|
|
<INITIAL>substitute { BEGIN(subs); return SUBSTITUTE; }
|
1999-02-13 14:14:47 +00:00
|
|
|
<subs>with { BEGIN(subs2); return WITH; }
|
1996-10-15 22:05:18 +00:00
|
|
|
<INITIAL>order return ORDER;
|
|
|
|
<INITIAL>charmap BEGIN(charmap);
|
|
|
|
<INITIAL>;[ \t]*\.\.\.[ \t]*; return RANGE;
|
1999-02-13 14:14:47 +00:00
|
|
|
<INITIAL,nchar,subs>\\[0-7]{3} {
|
1995-02-17 17:29:50 +00:00
|
|
|
u_int v;
|
|
|
|
|
|
|
|
sscanf(&yytext[1], "%o", &v);
|
|
|
|
yylval.ch = (u_char)v;
|
|
|
|
return CHAR;
|
|
|
|
}
|
1999-02-13 14:14:47 +00:00
|
|
|
<INITIAL,nchar,subs>\\x[0-9a-z]{2} {
|
1995-02-17 17:29:50 +00:00
|
|
|
u_int v;
|
|
|
|
|
|
|
|
sscanf(&yytext[2], "%x", &v);
|
|
|
|
yylval.ch = (u_char)v;
|
|
|
|
return CHAR;
|
|
|
|
}
|
1996-10-15 22:05:18 +00:00
|
|
|
<INITIAL>[^;,{}() \t\n"<]+ {
|
1995-02-17 17:29:50 +00:00
|
|
|
if(yyleng == 1) {
|
|
|
|
yylval.ch = *yytext;
|
|
|
|
return CHAR;
|
|
|
|
}
|
2001-11-28 09:50:24 +00:00
|
|
|
if(yyleng > BUFSIZE - 1)
|
1999-02-12 20:39:06 +00:00
|
|
|
errx(EX_UNAVAILABLE, "chain buffer overflow near line %u",
|
1995-02-17 17:29:50 +00:00
|
|
|
line_no);
|
|
|
|
strcpy(yylval.str, yytext);
|
|
|
|
return CHAIN;
|
|
|
|
}
|
1999-02-13 14:14:47 +00:00
|
|
|
<nchar,subs>. {
|
1996-10-15 22:05:18 +00:00
|
|
|
yylval.ch = *yytext;
|
|
|
|
return CHAR;
|
|
|
|
}
|
1999-10-03 01:21:33 +00:00
|
|
|
<defn>^#.*\n line_no++;
|
1996-10-15 22:05:18 +00:00
|
|
|
<defn>[ \t]+ {
|
|
|
|
if (ptr == buf)
|
|
|
|
errx(EX_UNAVAILABLE, "map expected near line %u of %s",
|
|
|
|
line_no, map_name);
|
|
|
|
*ptr = '\0';
|
|
|
|
strcpy(yylval.str, buf);
|
|
|
|
BEGIN(nchar);
|
|
|
|
return DEFN;
|
|
|
|
}
|
|
|
|
<name>\/\/ {
|
1995-02-17 17:29:50 +00:00
|
|
|
if(ptr >= buf + sizeof(buf) - 1)
|
1999-02-12 20:39:06 +00:00
|
|
|
errx(EX_UNAVAILABLE, "name buffer overflow near line %u, character '/'",
|
1996-10-15 22:05:18 +00:00
|
|
|
line_no);
|
|
|
|
*ptr++ = '/';
|
|
|
|
}
|
|
|
|
<name>\/\> {
|
|
|
|
if(ptr >= buf + sizeof(buf) - 1)
|
1999-02-12 20:39:06 +00:00
|
|
|
errx(EX_UNAVAILABLE, "name buffer overflow near line %u, character '>'",
|
1995-02-17 17:29:50 +00:00
|
|
|
line_no);
|
|
|
|
*ptr++ = '>';
|
|
|
|
}
|
|
|
|
<string>\\\" {
|
|
|
|
if(ptr >= buf + sizeof(buf) - 1)
|
1999-02-12 20:39:06 +00:00
|
|
|
errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\"'",
|
1995-02-17 17:29:50 +00:00
|
|
|
line_no);
|
|
|
|
*ptr++ = '"';
|
|
|
|
}
|
|
|
|
<name>\> {
|
1996-10-16 03:12:22 +00:00
|
|
|
u_int i;
|
|
|
|
|
1996-10-15 22:05:18 +00:00
|
|
|
if (ptr == buf)
|
1996-10-16 03:12:22 +00:00
|
|
|
errx(EX_UNAVAILABLE, "non-empty name expected near line %u",
|
1996-10-15 22:05:18 +00:00
|
|
|
line_no);
|
1995-02-17 17:29:50 +00:00
|
|
|
*ptr = '\0';
|
2001-11-28 09:50:24 +00:00
|
|
|
for (i = 0; i <= UCHAR_MAX; i++) {
|
1996-10-16 03:12:22 +00:00
|
|
|
if (strcmp(charmap_table[i], buf) == 0)
|
|
|
|
goto findit;
|
2001-11-28 09:50:24 +00:00
|
|
|
}
|
1996-10-16 03:12:22 +00:00
|
|
|
errx(EX_UNAVAILABLE, "name <%s> not 'charmap'-defined near line %u",
|
|
|
|
buf, line_no);
|
2001-11-28 09:50:24 +00:00
|
|
|
findit:
|
1996-10-16 03:12:22 +00:00
|
|
|
yylval.ch = i;
|
1999-02-13 14:14:47 +00:00
|
|
|
if (fromsubs)
|
|
|
|
BEGIN(subs);
|
|
|
|
else
|
|
|
|
BEGIN(INITIAL);
|
1996-10-16 03:12:22 +00:00
|
|
|
return CHAR;
|
1995-02-17 17:29:50 +00:00
|
|
|
}
|
|
|
|
<string>\" {
|
|
|
|
*ptr = '\0';
|
|
|
|
strcpy(yylval.str, buf);
|
1999-02-13 14:14:47 +00:00
|
|
|
BEGIN(subs2);
|
1995-02-17 17:29:50 +00:00
|
|
|
return STRING;
|
|
|
|
}
|
1996-10-15 22:05:18 +00:00
|
|
|
<name,defn>. {
|
2001-12-02 23:40:46 +00:00
|
|
|
const char *s = (map_fp != NULL) ? map_name : "input";
|
1996-10-15 22:05:18 +00:00
|
|
|
|
|
|
|
if (!isascii(*yytext) || !isprint(*yytext))
|
|
|
|
errx(EX_UNAVAILABLE, "non-ASCII or non-printable character 0x%02x not allowed in the map/name near line %u of %s",
|
|
|
|
*yytext, line_no, s);
|
1995-02-17 17:29:50 +00:00
|
|
|
if(ptr >= buf + sizeof(buf) - 1)
|
1999-02-12 20:39:06 +00:00
|
|
|
errx(EX_UNAVAILABLE, "map/name buffer overflow near line %u of %s, character '%c'",
|
1996-10-15 22:05:18 +00:00
|
|
|
line_no, s, *yytext);
|
1995-02-17 17:29:50 +00:00
|
|
|
*ptr++ = *yytext;
|
|
|
|
}
|
1996-10-15 22:05:18 +00:00
|
|
|
<string>\\t {
|
1995-02-17 17:29:50 +00:00
|
|
|
if(ptr >= buf + sizeof(buf) - 1)
|
1999-02-12 20:39:06 +00:00
|
|
|
errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\t'",
|
1995-02-17 17:29:50 +00:00
|
|
|
line_no);
|
|
|
|
*ptr++ = '\t';
|
|
|
|
}
|
1996-10-15 22:05:18 +00:00
|
|
|
<string>\\b {
|
1995-02-17 17:29:50 +00:00
|
|
|
if(ptr >= buf + sizeof(buf) - 1)
|
1999-02-12 20:39:06 +00:00
|
|
|
errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\b'",
|
1995-02-17 17:29:50 +00:00
|
|
|
line_no);
|
|
|
|
*ptr++ = '\b';
|
|
|
|
}
|
1996-10-15 22:05:18 +00:00
|
|
|
<string>\\f {
|
1995-02-17 17:29:50 +00:00
|
|
|
if(ptr >= buf + sizeof(buf) - 1)
|
1999-02-12 20:39:06 +00:00
|
|
|
errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\f'",
|
1995-02-17 17:29:50 +00:00
|
|
|
line_no);
|
|
|
|
*ptr++ = '\f';
|
|
|
|
}
|
1996-10-15 22:05:18 +00:00
|
|
|
<string>\\v {
|
1995-02-17 17:29:50 +00:00
|
|
|
if(ptr >= buf + sizeof(buf) - 1)
|
1999-02-12 20:39:06 +00:00
|
|
|
errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\v'",
|
1995-02-17 17:29:50 +00:00
|
|
|
line_no);
|
|
|
|
*ptr++ = '\v';
|
|
|
|
}
|
1996-10-15 22:05:18 +00:00
|
|
|
<string>\\n {
|
1995-02-17 17:29:50 +00:00
|
|
|
if(ptr >= buf + sizeof(buf) - 1)
|
1999-02-12 20:39:06 +00:00
|
|
|
errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\n'",
|
1995-02-17 17:29:50 +00:00
|
|
|
line_no);
|
|
|
|
*ptr++ = '\n';
|
|
|
|
}
|
1996-10-15 22:05:18 +00:00
|
|
|
<string>\\r {
|
1995-02-17 17:29:50 +00:00
|
|
|
if(ptr >= buf + sizeof(buf) - 1)
|
1999-02-12 20:39:06 +00:00
|
|
|
errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\r'",
|
1995-02-17 17:29:50 +00:00
|
|
|
line_no);
|
|
|
|
*ptr++ = '\r';
|
|
|
|
}
|
1996-10-15 22:05:18 +00:00
|
|
|
<string>\\a {
|
1995-02-17 17:29:50 +00:00
|
|
|
if(ptr >= buf + sizeof(buf) - 1)
|
1999-02-12 20:39:06 +00:00
|
|
|
errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\a'",
|
1995-02-17 17:29:50 +00:00
|
|
|
line_no);
|
|
|
|
*ptr++ = '\a';
|
|
|
|
}
|
1996-10-15 22:05:18 +00:00
|
|
|
<name,string,defn>\n {
|
2001-12-02 23:40:46 +00:00
|
|
|
const char *s = (map_fp != NULL) ? map_name : "input";
|
1996-10-15 22:05:18 +00:00
|
|
|
|
|
|
|
errx(EX_UNAVAILABLE, "unterminated map/name/string near line %u of %s", line_no, s);
|
1995-02-17 17:29:50 +00:00
|
|
|
}
|
1996-10-15 22:05:18 +00:00
|
|
|
<name,string,nchar><<EOF>> {
|
2001-12-02 23:40:46 +00:00
|
|
|
const char *s = (map_fp != NULL) ? map_name : "input";
|
1996-10-15 22:05:18 +00:00
|
|
|
|
|
|
|
errx(EX_UNAVAILABLE, "premature EOF in the name/string/char near line %u of %s", line_no, s);
|
|
|
|
}
|
|
|
|
<string>\\x[0-9a-f]{2} {
|
1995-02-17 17:29:50 +00:00
|
|
|
u_int v;
|
|
|
|
|
|
|
|
sscanf(&yytext[2], "%x", &v);
|
|
|
|
*ptr++ = (u_char)v;
|
|
|
|
}
|
1996-10-15 22:05:18 +00:00
|
|
|
<string>\\[0-7]{3} {
|
1995-02-17 17:29:50 +00:00
|
|
|
u_int v;
|
|
|
|
|
|
|
|
sscanf(&yytext[1], "%o", &v);
|
|
|
|
*ptr++ = (u_char)v;
|
|
|
|
}
|
1996-10-15 22:05:18 +00:00
|
|
|
<string>\\. {
|
|
|
|
if(ptr >= buf + sizeof(buf) - 1)
|
1999-02-12 20:39:06 +00:00
|
|
|
errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '%c'",
|
1996-10-15 22:05:18 +00:00
|
|
|
line_no, yytext[1]);
|
|
|
|
*ptr++ = yytext[1];
|
|
|
|
}
|
|
|
|
<string>. {
|
|
|
|
if(ptr >= buf + sizeof(buf) - 1)
|
1999-02-12 20:39:06 +00:00
|
|
|
errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '%c'",
|
1996-10-15 22:05:18 +00:00
|
|
|
line_no, *yytext);
|
|
|
|
*ptr++ = *yytext;
|
|
|
|
}
|
1995-02-17 17:29:50 +00:00
|
|
|
<charmap>[^ \t\n]+ {
|
1996-10-15 22:05:18 +00:00
|
|
|
strcat(map_name, "/");
|
|
|
|
strcat(map_name, yytext);
|
|
|
|
if((map_fp = fopen(map_name, "r")) == NULL)
|
|
|
|
err(EX_UNAVAILABLE, "can't open 'charmap' file %s",
|
|
|
|
map_name);
|
|
|
|
save_no = line_no;
|
|
|
|
line_no = 1;
|
1995-02-17 17:29:50 +00:00
|
|
|
map_buf = yy_new_buffer(map_fp, YY_BUF_SIZE);
|
|
|
|
main_buf = YY_CURRENT_BUFFER;
|
|
|
|
yy_switch_to_buffer(map_buf);
|
1996-10-15 22:05:18 +00:00
|
|
|
ptr = buf;
|
|
|
|
BEGIN(defn);
|
1995-02-17 17:29:50 +00:00
|
|
|
}
|
1996-10-15 22:05:18 +00:00
|
|
|
<charmap>\n {
|
|
|
|
errx(EX_UNAVAILABLE, "'charmap' file name expected near line %u",
|
1995-02-17 17:29:50 +00:00
|
|
|
line_no);
|
|
|
|
}
|
1996-10-15 22:05:18 +00:00
|
|
|
<charmap><<EOF>> {
|
|
|
|
errx(EX_UNAVAILABLE, "'charmap' file name expected near line %u",
|
|
|
|
line_no);
|
|
|
|
}
|
|
|
|
<INITIAL,defn><<EOF>> {
|
|
|
|
if(map_fp != NULL) {
|
|
|
|
if (ptr != buf)
|
|
|
|
errx(EX_UNAVAILABLE, "premature EOF in the map near line %u of %s", line_no, map_name);
|
1995-02-17 17:29:50 +00:00
|
|
|
yy_switch_to_buffer(main_buf);
|
|
|
|
yy_delete_buffer(map_buf);
|
|
|
|
fclose(map_fp);
|
1996-10-15 22:05:18 +00:00
|
|
|
map_fp = NULL;
|
|
|
|
line_no = save_no;
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
} else
|
1995-02-17 17:29:50 +00:00
|
|
|
yyterminate();
|
|
|
|
}
|
|
|
|
%%
|
|
|
|
#ifdef FLEX_DEBUG
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
while(yylex())
|
|
|
|
;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* FLEX_DEBUG */
|