From 7c4355120cf09c987a6ac0234f7166062218282e Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Wed, 16 Oct 1996 03:12:22 +0000 Subject: [PATCH] Simplify and improve parser. Clarify manpage. --- usr.bin/colldef/colldef.1 | 40 ++++--- usr.bin/colldef/parse.y | 227 -------------------------------------- usr.bin/colldef/scan.l | 15 ++- 3 files changed, 38 insertions(+), 244 deletions(-) diff --git a/usr.bin/colldef/colldef.1 b/usr.bin/colldef/colldef.1 index 4c44cf7d0dc7..d7e7998c8cd8 100644 --- a/usr.bin/colldef/colldef.1 +++ b/usr.bin/colldef/colldef.1 @@ -124,11 +124,7 @@ representation, and can be only one character in length. .Pp Symbol names cannot be specified in .Ar substitute -fields. Symbol names also cannot be combined with -any other representation, such as, h, c, -\ex68, or . Symbol names can be used with -primary and secondary ordering as in the following -example. +fields. .Pp The .Ar charmap @@ -153,14 +149,15 @@ statement is optional. .Ar order order_list .Pp .Ar order_list -is a list of symbols, separated by semi colons, that defines the collating sequence. The +is a list of symbols, separated by semi colons, that defines the +collating sequence. The special symbol .Ar ... specifies, in a short-hand form, symbols that are sequential in machine code order. .Pp -A symbol can be up to two characters in length and +An order list element can be represented in any one of the following ways: .Bl -bullet @@ -208,18 +205,33 @@ Symbols .Ar \er , .Ar \ev are permitted in its usual C-language meaning +.It +The symbol range (for example, +.Ar a;...;z ) +.It +Comma-separated symbols, ranges and chains enclosed in parenthesis (for example +.Ar \&( +.Ar sym1 , +.Ar sym2 , +.Ar ... +.Ar \&) ) +are assigned the +same primary ordering but different secondary +ordering. +.It +Comma-separated symbols, ranges and chains enclosed in curly brackets (for example +.Ar \&{ +.Ar sym1 , +.Ar sym2 , +.Ar ... +.Ar \&} ) +are assigned the same primary ordering only. .El .Pp The backslash character .Ar \e is used for continuation. In this case, no characters are permitted -after the backslash character. And as a quotation mark. -.Pp -Symbols enclosed in parentheses are assigned the -same primary ordering but different secondary -ordering. Symbols enclosed in curly brackets are -assigned only the same primary ordering -and different secondary ordering. +after the backslash character. .Sh EXIT STATUS .Ar colldef exits with the following values: diff --git a/usr.bin/colldef/parse.y b/usr.bin/colldef/parse.y index 55067c54a552..58236892a49e 100644 --- a/usr.bin/colldef/parse.y +++ b/usr.bin/colldef/parse.y @@ -61,7 +61,6 @@ char *out_file = "LC_COLLATE"; } %token SUBSTITUTE WITH ORDER RANGE %token STRING -%token NAME %token CHAIN %token DEFN %token CHAR @@ -116,17 +115,6 @@ item : CHAR { __collate_char_pri_table[$1].prim = prim_pri++; } yyerror("__collate_chain_pri_table overflow"); strcpy(__collate_chain_pri_table[chain_index].str, $1); __collate_chain_pri_table[chain_index++].prim = prim_pri++; -} - | NAME { - u_int i; - - for (i = 0; i <= UCHAR_MAX; i++) - if (strcmp(charmap_table[i], $1) == 0) - goto findi; - yyerror("Name <%s> not defined", $1); - findi: - - __collate_char_pri_table[i].prim = prim_pri++; } | CHAR RANGE CHAR { u_int i; @@ -136,68 +124,6 @@ item : CHAR { __collate_char_pri_table[$1].prim = prim_pri++; } for (i = $1; i <= $3; i++) __collate_char_pri_table[(u_char)i].prim = prim_pri++; -} - | NAME RANGE CHAR { - u_int i, c1; - - for (i = 0; i <= UCHAR_MAX; i++) - if (strcmp(charmap_table[i], $1) == 0) { - c1 = i; - goto find1; - } - yyerror("Name <%s> not defined", $1); - find1: - - if ($3 <= c1) - yyerror("Illegal range 0x%02x -- 0x%02x", - c1, $3); - - for (i = c1; i <= $3; i++) - __collate_char_pri_table[(u_char)i].prim = prim_pri++; -} - | CHAR RANGE NAME { - u_int i, c3; - - for (i = 0; i <= UCHAR_MAX; i++) - if (strcmp(charmap_table[i], $3) == 0) { - c3 = i; - goto find3; - } - yyerror("Name <%s> not defined", $3); - find3: - - if (c3 <= $1) - yyerror("Illegal range 0x%02x -- 0x%02x", - $1, c3); - - for (i = $1; i <= c3; i++) - __collate_char_pri_table[(u_char)i].prim = prim_pri++; -} - | NAME RANGE NAME { - u_int i, c1, c3; - - for (i = 0; i <= UCHAR_MAX; i++) - if (strcmp(charmap_table[i], $1) == 0) { - c1 = i; - goto find21; - } - yyerror("Name <%s> not defined", $1); - find21: - - for (i = 0; i <= UCHAR_MAX; i++) - if (strcmp(charmap_table[i], $3) == 0) { - c3 = i; - goto find23; - } - yyerror("Name <%s> not defined", $3); - find23: - - if (c3 <= c1) - yyerror("Illegal range 0x%02x -- 0x%02x", - c1, c3); - - for (i = c1; i <= c3; i++) - __collate_char_pri_table[(u_char)i].prim = prim_pri++; } | '{' prim_order_list '}' { prim_pri++; @@ -225,79 +151,6 @@ prim_sub_item : CHAR { for (i = $1; i <= $3; i++) __collate_char_pri_table[(u_char)i].prim = prim_pri; -} - | NAME RANGE CHAR { - u_int i, c1; - - for (i = 0; i <= UCHAR_MAX; i++) - if (strcmp(charmap_table[i], $1) == 0) { - c1 = i; - goto findpsi1; - } - yyerror("Name <%s> not defined", $1); - findpsi1: - - if ($3 <= c1) - yyerror("Illegal range 0x%02x -- 0x%02x", - c1, $3); - - for (i = c1; i <= $3; i++) - __collate_char_pri_table[(u_char)i].prim = prim_pri; -} - | CHAR RANGE NAME { - u_int i, c3; - - for (i = 0; i <= UCHAR_MAX; i++) - if (strcmp(charmap_table[i], $3) == 0) { - c3 = i; - goto findpsi3; - } - yyerror("Name <%s> not defined", $3); - findpsi3: - - if (c3 <= $1) - yyerror("Illegal range 0x%02x -- 0x%02x", - $1, c3); - - for (i = $1; i <= c3; i++) - __collate_char_pri_table[(u_char)i].prim = prim_pri; -} - | NAME RANGE NAME { - u_int i, c1, c3; - - for (i = 0; i <= UCHAR_MAX; i++) - if (strcmp(charmap_table[i], $1) == 0) { - c1 = i; - goto findpsi21; - } - yyerror("Name <%s> not defined", $1); - findpsi21: - - for (i = 0; i <= UCHAR_MAX; i++) - if (strcmp(charmap_table[i], $3) == 0) { - c3 = i; - goto findpsi23; - } - yyerror("Name <%s> not defined", $3); - findpsi23: - - if (c3 <= c1) - yyerror("Illegal range 0x%02x -- 0x%02x", - c1, c3); - - for (i = c1; i <= c3; i++) - __collate_char_pri_table[(u_char)i].prim = prim_pri; -} - | NAME { - u_int i; - - for (i = 0; i <= UCHAR_MAX; i++) - if (strcmp(charmap_table[i], $1) == 0) - goto findpsi; - yyerror("Name <%s> not defined", $1); - findpsi: - - __collate_char_pri_table[i].prim = prim_pri; } | CHAIN { if (chain_index >= TABLE_SIZE - 1) @@ -321,86 +174,6 @@ sec_sub_item : CHAR { __collate_char_pri_table[(u_char)i].prim = prim_pri; __collate_char_pri_table[(u_char)i].sec = sec_pri++; } -} - | NAME RANGE CHAR { - u_int i, c1; - - for (i = 0; i <= UCHAR_MAX; i++) - if (strcmp(charmap_table[i], $1) == 0) { - c1 = i; - goto findssi1; - } - yyerror("Name <%s> not defined", $1); - findssi1: - - if ($3 <= c1) - yyerror("Illegal range 0x%02x -- 0x%02x", - c1, $3); - - for (i = c1; i <= $3; i++) { - __collate_char_pri_table[(u_char)i].prim = prim_pri; - __collate_char_pri_table[(u_char)i].sec = sec_pri++; - } -} - | CHAR RANGE NAME { - u_int i, c3; - - for (i = 0; i <= UCHAR_MAX; i++) - if (strcmp(charmap_table[i], $3) == 0) { - c3 = i; - goto findssi3; - } - yyerror("Name <%s> not defined", $3); - findssi3: - - if (c3 <= $1) - yyerror("Illegal range 0x%02x -- 0x%02x", - $1, c3); - - for (i = $1; i <= c3; i++) { - __collate_char_pri_table[(u_char)i].prim = prim_pri; - __collate_char_pri_table[(u_char)i].sec = sec_pri++; - } -} - | NAME RANGE NAME { - u_int i, c1, c3; - - for (i = 0; i <= UCHAR_MAX; i++) - if (strcmp(charmap_table[i], $1) == 0) { - c1 = i; - goto findssi21; - } - yyerror("Name <%s> not defined", $1); - findssi21: - - for (i = 0; i <= UCHAR_MAX; i++) - if (strcmp(charmap_table[i], $3) == 0) { - c3 = i; - goto findssi23; - } - yyerror("Name <%s> not defined", $3); - findssi23: - - if (c3 <= c1) - yyerror("Illegal range 0x%02x -- 0x%02x", - c1, c3); - - for (i = c1; i <= c3; i++) { - __collate_char_pri_table[(u_char)i].prim = prim_pri; - __collate_char_pri_table[(u_char)i].sec = sec_pri++; - } -} - | NAME { - u_int i; - - for (i = 0; i <= UCHAR_MAX; i++) - if (strcmp(charmap_table[i], $1) == 0) - goto findssi; - yyerror("Name <%s> not defined", $1); - findssi: - - __collate_char_pri_table[i].prim = prim_pri; - __collate_char_pri_table[i].sec = sec_pri++; } | CHAIN { if (chain_index >= TABLE_SIZE - 1) diff --git a/usr.bin/colldef/scan.l b/usr.bin/colldef/scan.l index 6a7d0cf6dec1..d8c111612a51 100644 --- a/usr.bin/colldef/scan.l +++ b/usr.bin/colldef/scan.l @@ -41,6 +41,7 @@ int line_no = 1, save_no; u_char buf[STR_LEN], *ptr; FILE *map_fp; extern char map_name[]; +extern u_char charmap_table[UCHAR_MAX + 1][STR_LEN]; YY_BUFFER_STATE main_buf, map_buf; #ifdef FLEX_DEBUG YYSTYPE yylval; @@ -137,13 +138,21 @@ YYSTYPE yylval; *ptr++ = '"'; } \> { + u_int i; + if (ptr == buf) - errx(EX_UNAVAILABLE, "name expected near line %u", + errx(EX_UNAVAILABLE, "non-empty name expected near line %u", line_no); *ptr = '\0'; - strcpy(yylval.str, buf); + for (i = 0; i <= UCHAR_MAX; i++) + if (strcmp(charmap_table[i], buf) == 0) + goto findit; + errx(EX_UNAVAILABLE, "name <%s> not 'charmap'-defined near line %u", + buf, line_no); + findit: + yylval.ch = i; BEGIN(INITIAL); - return NAME; + return CHAR; } \" { *ptr = '\0';