OSDN Git Service

Fix for PR libgcj/1736. Thanks to Robert Boehne and Alexandre Oliva
[pf3gnuchains/gcc-fork.git] / libjava / scripts / blocks.pl
1 #! /usr/bin/perl
2
3 if ($ARGV[0] eq '')
4 {
5     $file = 'Blocks.txt';
6     if (! -f $file)
7     {
8         # Too painful to figure out how to get Perl to do it.
9         system 'wget -o .wget-log http://www.unicode.org/Public/UNIDATA/Blocks.txt';
10     }
11 }
12 else
13 {
14     $file = $ARGV[0];
15 }
16
17 open (INPUT, "< $file") || die "couldn't open $file: $!";
18
19 @array = ();
20 while (<INPUT>)
21 {
22     next if /^#/;
23     chop;
24     next if /^$/;
25
26     ($start, $to, $text) = split (/; /);
27     ($symbol = $text) =~ tr/a-z/A-Z/;
28     $symbol =~ s/[- ]/_/g;
29
30     # Special case for one of the SPECIALS.
31     next if $start eq 'FEFF';
32
33     # Special case some areas that our heuristic mishandles.
34     if ($symbol eq 'HIGH_SURROGATES')
35     {
36         $symbol = 'SURROGATES_AREA';
37         $text = 'Surrogates Area';
38         $to = 'DFFF';
39     }
40     elsif ($symbol =~ /SURROGATES/)
41     {
42         next;
43     }
44     elsif ($symbol eq 'PRIVATE_USE')
45     {
46         $symbol .= '_AREA';
47         $text = 'Private Use Area';
48     }
49
50     printf "    public static final UnicodeBlock %s = new UnicodeBlock (\"%s\", '\\u%s', '\\u%s');\n",
51            $symbol, $text, $start, $to;
52
53     push (@array, $symbol);
54 }
55
56 printf "    private static final UnicodeBlock[] blocks = {\n";
57 foreach (@array)
58 {
59     printf "      %s", $_;
60     printf "," unless $_ eq 'SPECIALS';
61     printf "\n";
62 }
63 printf "    };\n";
64
65 close (INPUT);