ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/util/gen_uts46data
Revision: 1.1
Committed: Tue Dec 15 05:49:13 2009 UTC (14 years, 6 months ago) by root
Branch: MAIN
Log Message:
much less memory

File Contents

# User Rev Content
1 root 1.1 #!/opt/bin/perl
2    
3     # creates lib/AnyEvent/Util/uts46.pl - better do not run it!
4    
5     use common::sense;
6     use utf8;
7     no warnings 'utf8';
8    
9     binmode STDOUT, ":utf8";
10    
11     open my $fh, "GET http://www.unicode.org/Public/idna/5.2.0/IdnaMappingTable.txt |"
12     or die;
13    
14     my $valid;
15     my $imap; # index map \x00 char replacement
16    
17     while (<$fh>) {
18     next unless /^[0-9A-F]/;
19    
20     /^
21     ([0-9A-F]{4,}) (?: \.\.([0-9A-F]{4,}) )?
22     \s*;\s*(\S+)
23     (?: \s*;\s*([0-9A-F ]+?) )?
24     \s*
25     (?: \#.* )?
26     $
27     /x or die "$_: unparsable";
28    
29     my ($r1, $r2, $type, $map) = (hex $1, hex $2, $3, $4);
30    
31     my $R1 = chr $r1;
32     my $R2 = chr $r2;
33    
34     $map = join "", map chr hex, split ' ', $map;
35    
36     given ($type) {
37     when ("disallowed") {
38     # nop
39     }
40     when (/mapped|deviation|ignored/) {
41     $map .= "\x01" if $type eq "deviation";
42    
43     $imap .= "\x00" . chr . $map
44     for $r1 .. $r2 || $r1;
45     }
46     when ("valid") {
47     (vec $valid, $_, 1) = 1
48     for $r1 .. $r2 || $r1;
49     }
50     default {
51     die "default: $R1,$R2,$type,$map;\n";
52     }
53     }
54     }
55    
56     open my $fh, ">lib/AnyEvent/Util/uts46data.pl"
57     or die;
58     binmode $fh, ":perlio";
59     print $fh "# created by gen_uts46data\n";
60    
61     utf8::encode $imap;
62     0 > index $imap, "\x02" # it's not supposed to be anywhere in there
63     or die "imap contains \\x02";
64     print $fh "\$uts46_imap = q\x02$imap\x00\x02;\n";
65    
66     # try to find a valid quoting character - there usually are many legal combos
67     for (1..127) { # stay out of utf-8 range
68     if (0 >= index $valid, chr) {
69     print $fh "\$uts46_valid = q", chr, $valid, chr, ";\n";
70     goto valid_ok;
71     }
72     }
73     die "unable to found valid quoting character";
74     valid_ok:;
75    
76     print $fh "1;\n";
77     close $fh;
78