aboutsummaryrefslogtreecommitdiff
path: root/libjava/scripts/encodings.pl
blob: 9af108769855c085e29b872d13cce227a802e992 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# encodings.pl - Download IANA text and compute alias list.
# Assumes you are running this program from gnu/gcj/convert/.
# Output suitable for direct inclusion in IOConverter.java.

# Map IANA canonical names onto our canonical names.
%map = (
	'ANSI_X3.4-1968' => 'ASCII',
	'ISO_8859-1:1987' => '8859_1',
	'UTF-8' => 'UTF8',
	'Shift_JIS' => 'SJIS',
	'Extended_UNIX_Code_Packed_Format_for_Japanese' => 'EUCJIS',
	'UTF16-LE' => 'UnicodeLittle',
	'UTF16-BE' => 'UnicodeBig' 
	);

if ($ARGV[0] eq '')
{
    $file = 'character-sets';
    if (! -f $file)
    {
	# Too painful to figure out how to get Perl to do it.
	system 'wget -o .wget-log http://www.iana.org/assignments/character-sets';
    }
}
else
{
    $file = $ARGV[0];
}

# Include canonical names in the output.
foreach $key (keys %map)
{
    $output{lc ($key)} = $map{$key};
}

open (INPUT, "< $file") || die "couldn't open $file: $!";

$body = 0;
$current = '';
while (<INPUT>)
{
    chop;
    $body = 1 if /^Name:/;
    next unless $body;

    if (/^$/)
    {
	$current = '';
	next;
    }

    ($type, $name) = split (/\s+/);
    # Encoding names are case-insensitive.  We do all processing on
    # the lower-case form.
    my $lower = lc ($name);
    if ($type eq 'Name:')
    {
	$current = $map{$name};
	if ($current)
	{
	    $output{$lower} = $current;
	}
    }
    elsif ($type eq 'Alias:')
    {
	# The IANA list has some ugliness.
	if ($name ne '' && $lower ne 'none' && $current)
	{
	    $output{$lower} = $current;
	}
    }
}

close (INPUT);

foreach $key (sort keys %output)
{
    print "    hash.put (\"$key\", \"$output{$key}\");\n";
}