#!/usr/bin/perl # assume width info in locale are not overlapping # load big5/unicode mapping table open F,$ARGV[0] or die $!; while() { next if /^#/; my($b,$u)=split /\s+/; $big5[hex $u]=1; } close F; open F,$ARGV[1] or die $!; # fix locale data while() { if(!/^SWIDTH/) { print; next; } my($width)=substr $_,6,1; my @seq=&parse($_); my @newseq1; my @newseq2; for(@seq) { my($f,$t)=@$_; for(my $i=$f;$i<=$t;$i++) { if($width==2 || $big5[$i]) { push @newseq2, $i; } else { push @newseq1, $i; } $big5[$i]=0; } } &output(1,@newseq1); &output(2,@newseq2); } close F; &output(2,grep { $big5[$_] } 0 .. 0xffff); sub parse { my($str)=@_; my @token = split /\s+/,$str; my @seq; for(my $i=1;$i<@token;$i++) { my($f,$t); $f=$t=$token[$i]; if($token[$i+1] eq '-') { $t=$token[$i+2]; $i+=2; } push @seq, [hex $f, hex $t]; } return @seq; } sub output { my($width,@a)=@_; my @seq; for(my$i=0;$i<@a;$i++) { my($f,$t); $f=$t=$a[$i]; $t=$a[++$i] while $t+1==$a[$i+1]; push @seq, [$f,$t]; } if(@seq) { print "SWIDTH$width "; for(@seq) { print " "; &output_pair($_); } print "\n"; } } sub output_pair { my($p)=@_; printf "0x%04x",$p->[0]; if($p->[0]!=$p->[1]) { print ' '; } if($p->[1]>$p->[0]+1) { print '-'; } if($p->[0]!=$p->[1]) { printf " 0x%04x", $p->[1]; } }