From fb38e9d43a9a77c578cd404b35ca34a59eb866a3 Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Sat, 13 Feb 1999 14:14:47 +0000 Subject: [PATCH] syntax change: allow symbolic names as substitute first arg --- usr.bin/colldef/colldef.1 | 18 +++++++-------- usr.bin/colldef/parse.y | 16 +++++--------- usr.bin/colldef/scan.l | 46 +++++++++++++++++++++------------------ 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/usr.bin/colldef/colldef.1 b/usr.bin/colldef/colldef.1 index b668d1aeac3..66bb90f6d53 100644 --- a/usr.bin/colldef/colldef.1 +++ b/usr.bin/colldef/colldef.1 @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $Id$ +.\" $Id: colldef.1,v 1.5 1997/06/26 11:25:16 charnier Exp $ .\" .Dd January, 27 1995 .Dt COLLDEF 1 @@ -124,26 +124,24 @@ representation, and can be only one character in length. .br .Ar ... .Pp -Symbol names cannot be specified in -.Ar substitute -fields. -.Pp The .Ar charmap statement is optional. .Pp .Ar substitute -"\fIchar\fR" +\fIsymbol\fR .Ar with -"\fIrepl\fR" +"\fIrepl_string\fR" .Pp The .Ar substitute statement substitutes the character -.Ar char +.Ar symbol with the string -.Ar repl . -.Pp +.Ar repl_string . +Symbol names cannot be specified in +.Ar repl_string +field. The .Ar substitute statement is optional. diff --git a/usr.bin/colldef/parse.y b/usr.bin/colldef/parse.y index 8a817262b51..da485dacd98 100644 --- a/usr.bin/colldef/parse.y +++ b/usr.bin/colldef/parse.y @@ -25,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: parse.y,v 1.12 1999/02/12 20:39:05 ache Exp $ + * $Id: parse.y,v 1.13 1999/02/12 20:56:49 ache Exp $ */ #include @@ -83,16 +83,12 @@ charmap : DEFN CHAR { strcpy(charmap_table[$2], $1); } ; -substitute : SUBSTITUTE STRING WITH STRING { - u_char ch = $2[0]; - - if (strlen($2) > 1) - yyerror("Only characters can be substituted, not strings"); - if (ch == '\0') +substitute : SUBSTITUTE CHAR WITH STRING { + if ($2 == '\0') yyerror("NUL character can't be substituted"); - if (strchr($4, ch) != NULL) - yyerror("Char 0x%02x substitution is recursive", ch); - strcpy(__collate_substitute_table[ch], $4); + if (strchr($4, $2) != NULL) + yyerror("Char 0x%02x substitution is recursive", $2); + strcpy(__collate_substitute_table[$2], $4); } ; order : ORDER order_list { diff --git a/usr.bin/colldef/scan.l b/usr.bin/colldef/scan.l index 27439f46a73..405068d5a27 100644 --- a/usr.bin/colldef/scan.l +++ b/usr.bin/colldef/scan.l @@ -1,4 +1,4 @@ -%x string name charmap defn nchar subs +%x string name charmap defn nchar subs subs2 %{ /*- * Copyright (c) 1995 Alex Tatmanjants @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: scan.l,v 1.7 1997/02/22 19:54:32 peter Exp $ + * $Id: scan.l,v 1.8 1999/02/12 20:39:06 ache Exp $ */ #include @@ -37,7 +37,7 @@ #include "collate.h" #include "y.tab.h" -int line_no = 1, save_no; +int line_no = 1, save_no, fromsubs; u_char buf[STR_LEN], *ptr; FILE *map_fp; extern char map_name[]; @@ -48,21 +48,22 @@ YYSTYPE yylval; #endif /* FLEX_DEBUG */ %} %% -[ \t]+ ; -\" { ptr = buf; BEGIN(string); } -\< { ptr = buf; BEGIN(name); } +[ \t]+ ; +\" { ptr = buf; BEGIN(string); } +\< { ptr = buf; fromsubs = 1; BEGIN(name); } +\< { ptr = buf; fromsubs = 0; BEGIN(name); } ^#.*\n line_no++; ^\n line_no++; \\\n line_no++; -\\t { yylval.ch = '\t'; return CHAR; } -\\n { yylval.ch = '\n'; return CHAR; } -\\b { yylval.ch = '\b'; return CHAR; } -\\f { yylval.ch = '\f'; return CHAR; } -\\v { yylval.ch = '\v'; return CHAR; } -\\r { yylval.ch = '\r'; return CHAR; } -\\a { yylval.ch = '\a'; return CHAR; } -\\. { yylval.ch = yytext[1]; return CHAR; } -\n { +\\t { yylval.ch = '\t'; return CHAR; } +\\n { yylval.ch = '\n'; return CHAR; } +\\b { yylval.ch = '\b'; return CHAR; } +\\f { yylval.ch = '\f'; return CHAR; } +\\v { yylval.ch = '\v'; return CHAR; } +\\r { yylval.ch = '\r'; return CHAR; } +\\a { yylval.ch = '\a'; return CHAR; } +\\. { yylval.ch = yytext[1]; return CHAR; } +\n { line_no++; BEGIN(INITIAL); return '\n'; @@ -77,18 +78,18 @@ YYSTYPE yylval; } [;,{}()] return *yytext; substitute { BEGIN(subs); return SUBSTITUTE; } -with return WITH; +with { BEGIN(subs2); return WITH; } order return ORDER; charmap BEGIN(charmap); ;[ \t]*\.\.\.[ \t]*; return RANGE; -\\[0-7]{3} { +\\[0-7]{3} { u_int v; sscanf(&yytext[1], "%o", &v); yylval.ch = (u_char)v; return CHAR; } -\\x[0-9a-z]{2} { +\\x[0-9a-z]{2} { u_int v; sscanf(&yytext[2], "%x", &v); @@ -106,7 +107,7 @@ YYSTYPE yylval; strcpy(yylval.str, yytext); return CHAIN; } -. { +. { yylval.ch = *yytext; return CHAR; } @@ -151,13 +152,16 @@ YYSTYPE yylval; buf, line_no); findit: yylval.ch = i; - BEGIN(INITIAL); + if (fromsubs) + BEGIN(subs); + else + BEGIN(INITIAL); return CHAR; } \" { *ptr = '\0'; strcpy(yylval.str, buf); - BEGIN(subs); + BEGIN(subs2); return STRING; } . {