5 # This file and its contents are supplied under the terms of the
6 # Common Development and Distribution License ("CDDL"), version 1.0.
7 # You may only use this file in accordance with the terms of version
10 # A full copy of the text of the CDDL should have accompanied this
11 # source. A copy is of the CDDL is also available via the Internet
12 # at http://www.illumos.org/license/CDDL.
16 # Copyright 2010 Nexenta Systems, Inc. All rights reserved.
17 # Copyright 2015 John Marino <draco@marino.st>
20 # This converts MAPPING files to localedef character maps
21 # suitable for use with the UTF-8 derived localedef data.
29 $utf8 = sprintf("\\x%02X", $ucs).$utf8;
30 } elsif ($ucs <= 0x7ff) {
31 $utf8 = sprintf("\\x%02X", ($ucs & 0x3f) | 0x80).$utf8;
33 $utf8 = sprintf("\\x%02X", $ucs | 0xc0).$utf8;
35 } elsif ($ucs <= 0xffff) {
36 $utf8 = sprintf("\\x%02X", ($ucs & 0x3f) | 0x80).$utf8;
38 $utf8 = sprintf("\\x%02X", ($ucs & 0x3f) | 0x80).$utf8;
40 $utf8 = sprintf("\\x%02X", $ucs | 0xe0).$utf8;
42 } elsif ($ucs <= 0x1fffff) {
43 $utf8 = sprintf("\\x%02X", ($ucs & 0x3f) | 0x80).$utf8;
45 $utf8 = sprintf("\\x%02X", ($ucs & 0x3f) | 0x80).$utf8;
47 $utf8 = sprintf("\\x%02X", ($ucs & 0x3f) | 0x80).$utf8;
49 $utf8 = sprintf("\\x%02X", $ucs | 0xf0).$utf8;
51 } elsif ($ucs <= 0x03ffffff) {
52 $utf8 = sprintf("\\x%02X", ($ucs & 0x3f) | 0x80).$utf8;
54 $utf8 = sprintf("\\x%02X", ($ucs & 0x3f) | 0x80).$utf8;
56 $utf8 = sprintf("\\x%02X", ($ucs & 0x3f) | 0x80).$utf8;
58 $utf8 = sprintf("\\x%02X", ($ucs & 0x3f) | 0x80).$utf8;
60 $utf8 = sprintf("\\x%02X", $ucs | 0xf8).$utf8;
63 $utf8 = sprintf("\\x%02X", ($ucs & 0x3f) | 0x80).$utf8;
65 $utf8 = sprintf("\\x%02X", ($ucs & 0x3f) | 0x80).$utf8;
67 $utf8 = sprintf("\\x%02X", ($ucs & 0x3f) | 0x80).$utf8;
69 $utf8 = sprintf("\\x%02X", ($ucs & 0x3f) | 0x80).$utf8;
71 $utf8 = sprintf("\\x%02X", ($ucs & 0x3f) | 0x80).$utf8;
73 $utf8 = sprintf("\\x%02X", $ucs | 0xf8).$utf8;
83 # This is not a general purpose Character Map parser, but its good enough
84 # for the stock one supplied with CLDR.
90 open(UTF8, "$file") || die "open";
95 next if (/^\s*CHARMAP\s*$/);
96 next if (/^\s*END\s*CHARMAP\s*$/);
100 $utf8val = $words[1];
102 if (defined($unames{$utf8val})) {
103 $unames{$utf8val} .= "\n" .$name;
105 $unames{$utf8val} = $name;
107 $uvalues{$name} = $utf8val;
118 open(MAP, "$file") || die "open";
123 next if (/^0x..\+0x../);
124 next if (/^0x[0-9A-F]{4}\t0x[0-9A-F]{4} 0x[0-9A-F]{4}/);
125 next if (/^0x[0-9A-F]{2}\s+#/);
126 next if (/# ... NO MAPPING .../);
128 @words = split /\s+/;
130 $utf8 =~ s/^\\x[0]*//;
131 $utf8 = ucs_to_utf8(hex($utf8));
133 if (defined ($map{$val})) {
134 $map{$val} .= " ".$utf8;
151 $str = sprintf("\\x%02x", $val & 0xff).$str;
158 $codeset = shift(@ARGV);
161 load_utf8_cm("etc/final-maps/map.UTF-8");
165 if ($codeset eq "SJIS") { $max_mb = 2 }
166 elsif ($codeset eq "eucCN") { $max_mb = 2 }
167 elsif ($codeset eq "eucJP") { $max_mb = 3 }
168 elsif ($codeset eq "eucKR") { $max_mb = 2 }
169 elsif ($codeset eq "GBK") { $max_mb = 2 }
170 elsif ($codeset eq "GB2312") { $max_mb = 2 }
171 elsif ($codeset eq "Big5") { $max_mb = 2 }
172 else { $max_mb = 1 };
173 print("<code_set_name> \"$codeset\"\n");
174 print("<mb_cur_min> 1\n");
175 print("<mb_cur_max> $max_mb\n");
178 foreach $val (sort (keys (%map))) {
180 foreach $utf8 (split / /, $map{$val}) {
181 $ref = $unames{$utf8};
182 foreach $name (sort (split /\n/, $ref)) {
184 my $nt = int((64 - length($name) + 7) / 8);
189 print mb_str($val)."\n";
193 print "END CHARMAP\n";