2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / scripts / encodings.pl
blob5e802c1f5fcb2aca42d375295c336c01dbbf40d4
1 # encodings.pl - Download IANA text and compute alias list.
2 # Assumes you are running this program from gnu/gcj/convert/.
3 # Output suitable for direct inclusion in IOConverter.java.
5 # Map IANA canonical names onto our canonical names.
6 %map = (
7 'ANSI_X3.4-1968' => 'ASCII',
8 'ISO_8859-1:1987' => '8859_1',
9 'UTF-8' => 'UTF8',
10 'Shift_JIS' => 'SJIS',
11 'Extended_UNIX_Code_Packed_Format_for_Japanese' => 'EUCJIS'
14 if ($ARGV[0] eq '')
16 $file = 'character-sets';
17 if (! -f $file)
19 # Too painful to figure out how to get Perl to do it.
20 system 'wget -o .wget-log http://www.iana.org/assignments/character-sets';
23 else
25 $file = $ARGV[0];
28 open (INPUT, "< $file") || die "couldn't open $file: $!";
30 $body = 0;
31 $current = '';
32 while (<INPUT>)
34 chop;
35 $body = 1 if /^Name:/;
36 next unless $body;
38 if (/^$/)
40 $current = '';
41 next;
44 ($type, $name) = split (/\s+/);
45 # Encoding names are case-insensitive. We do all processing on
46 # the lower-case form.
47 my $lower = lc ($name);
48 if ($type eq 'Name:')
50 $current = $map{$name};
51 if ($current)
53 print " hash.put (\"$lower\", \"$current\");\n";
56 elsif ($type eq 'Alias:')
58 # The IANA list has some ugliness.
59 if ($name ne '' && $name ne 'NONE' && $current)
61 print " hash.put (\"$lower\", \"$current\");\n";
66 close (INPUT);