Debian Codegraph @

make_unicd_maps

raw
1 #!/usr/bin/perl -w
2
3 my $cdroot = shift || "CD";
4 die "Need Unicode-CD location as argument\n" unless -d "$cdroot/mappings";
5 # The content of the Unicode-CD is also available from
6 # ftp://ftp.unicode.org/Public
7
8 unless (-d "maps") {
9 print STDERR "Making directory 'maps'\n";
10 mkdir('maps', 0777) || die "Can't create directory: $!";
11 }
12
13 if (open(ALIASES, "maps/aliases")) {
14 while (<ALIASES>) {
15 next if /^\s*\#/;
16 next if /^\s*$/;
17 chomp;
18 my($charset, @aliases) = split(' ', $_);
19 $aliases{$charset} = { map {$_ => 1} @aliases };
20 }
21 }
22
23
24 # Adobe encodings
25 for $enc ("stdenc", "symbol", "zdingbat") {
26 my $file = "$cdroot/mappings/vendors/adobe/$enc.txt";
27 if (open(F, $file) ||
28 (-f "$file.gz" && open(F, "gunzip -c $file.gz|"))
29 ) {
30 $name = $enc;
31 @map = ();
32 while (<F>) {
33 if (/^\#\s*Name:\s*(.*)/) {
34 $name = $1;
35 } elsif (/^([0-9A-Fa-f]{4})\s+([0-9A-Fa-f]{2})/) {
36 push(@map, [$2, $1]);
37 }
38 }
39 close(F);
40 next unless @map;
41
42 $name =~ s/ Encoding to Unicode$//;
43 $name =~ s/\s+/-/g;
44
45 my $lc = lc($name);
46 $aliases{$name}{$lc}++ if $lc ne $name;
47
48 print STDERR "$name\n";
49 open(BINMAP, "| ./map8_txt2bin >maps/$name.bin") || die;
50 for (sort {$a->[0] cmp $b->[0]} @map) {
51 printf BINMAP "0x%s 0x%s\n", @$_;
52 }
53 close(BINMAP);
54 }
55 }
56
57 # Microsoft stuff
58 use File::Find;
59 find(sub {
60 return unless /\.txt(\.gz)?$/;
61 push(@enc, $File::Find::name);
62 },
63 "$cdroot/mappings/vendors/micsft");
64
65 for $enc (@enc) {
66
67 @map = ();
68 $cp = undef;
69 $name = undef;
70
71 $fname = $enc;
72 $fname =~ s/\.gz$//;
73 $fname =~ s/\.txt$//;
74 $fname =~ s,.*/,,;
75
76 $enc = "gunzip -c $enc|" if $enc =~ /\.gz$/;
77 #print "$fname\n";
78 open(F, $enc) || next;
79
80 while (<F>) {
81 if (/^\#\s*Name:\s*(.*)/) {
82 $name = $1;
83 $name =~ s/ to Unicode table$//;
84 $name =~ s/\s*\(.*\)\s*//;
85 $cp = $1 if $name =~ s/(^cp\d+)_//;
86 } elsif (/^0x([0-9A-Fa-f]+)\s+0x([0-9A-Fa-f]+)/ && $name) {
87 my $u8 = hex($1);
88 if ($u8 > 0xFF) {
89 printf STDERR "Skipping $fname ($name), not 8-bit charset\n";
90 undef($name);
91 last;
92 }
93 my $u16 = hex($2);
94 push(@map, [$u8, $u16]);
95 }
96 }
97 close(F);
98
99 next unless $name;
100
101 my $file = $cp || $name;
102 $aliases{$file}{$name}++ if $name ne $file;
103
104 print STDERR "$file\n";
105 open(BINMAP, "| ./map8_txt2bin >maps/$file.bin") || die;
106 for (@map) {
107 printf BINMAP "0x%02X 0x%04X\n", @$_;
108 }
109 close(BINMAP);
110 }
111
112
113
114
115
116
117 open(ALIASES, ">maps/aliases") || die "Can't write aliases: $!";
118 for (sort keys %aliases) {
119 print ALIASES "$_ ", join(" ", sort keys %{$aliases{$_}}), "\n";
120 }
121 close(ALIASES);