123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- #!/usr/bin/perl
- use strict;
- use inc::Module::Install;
- my $DefaultVersion = 'v5.0.0';
- my $DefaultDate = '2006-02-15';
- _build_pm();
- name 'Unicode-EastAsianWidth';
- all_from 'lib/Unicode/EastAsianWidth.pm';
- auto_provides;
- sign; WriteAll;
- sub _build_pm {
- my $file;
- foreach (@INC) {
- $file = "$_/unicore/EastAsianWidth.txt";
- last if -e $file;
- }
- my $use_bundled = 1;
- TRY: {
- unless (-e $file) {
- print "*** Cannot find unicore/EastAsianWidth.txt\n";
- last TRY;
- }
- unless (open EAW, $file) {
- print "*** Cannot open $file for reading: $!\n";
- last TRY;
- }
- unless (<EAW> =~ /EastAsianWidth/) {
- print "*** Cannot parse $file.\n";
- last TRY;
- }
- unless (<EAW> =~ /Date: (\d+-\d+-\d+)/ and $1 gt $DefaultDate) {
- print "*** Installed table not newer than the bundled version.\n";
- last TRY;
- }
- $use_bundled = 0;
- }
- if ($use_bundled) {
- print "*** Using bundled EastAsianWidth table ($DefaultVersion).\n";
- return;
- }
- my %ToFullName = (
- N => 'InEastAsianNeutral',
- A => 'InEastAsianAmbiguous',
- H => 'InEastAsianHalfwidth',
- W => 'InEastAsianWide',
- F => 'InEastAsianFullwidth',
- Na => 'InEastAsianNarrow',
- );
- my ($prev_code, $prev_categ) = '';
- my $prev_code_end = '';
- my %categ;
- while (<EAW>) {
- if (/^(\w+);(\w+)/) {
- my ($code, $categ) = ($1, $2);
- if ($prev_categ ne $categ) {
- $categ{$ToFullName{$prev_categ}} .= "$prev_code\\t$prev_code_end\n" if $prev_categ;
- $prev_code = $code;
- $prev_categ = $categ;
- }
- $prev_code_end = $code;
- }
- elsif (/^(\w+)\.\.(\w+);(\w+)/) {
- $categ{$ToFullName{$prev_categ}} .= "$prev_code\\t$prev_code_end\n" if $prev_categ;
- $categ{$ToFullName{$3}} .= "$1\\t$2\n";
- $prev_categ = '';
- }
- }
- my $out;
- unless (open PM, 'lib/Unicode/EastAsianWidth.pm') {
- print "*** Cannot read module ($!), falling back to default ($DefaultVersion)\n";
- return;
- }
- while (<PM>) { $out .= $_; last if /^### BEGIN ###$/ }
- $out .= "our \@EXPORT = qw(\n" . join(
- "\n", sort(values %ToFullName), qw(InFullwidth InHalfwidth)
- ) . "\n);\n\n";
- for my $name (sort values %ToFullName) {
- $out .= << ".";
- sub $name {
- return <<"END";
- $categ{$name}END
- }
- .
- }
- while (<PM>) { $out .= $_ and last if /^### END ###$/ }
- while (<PM>) { $out .= $_ }
- close PM;
- chmod 0644, 'lib/Unicode/EastAsianWidth.pm';
- unless (open PM, '>', 'lib/Unicode/EastAsianWidth.pm') {
- print "*** Cannot write to module ($!), falling back to default ($DefaultVersion)\n";
- return;
- }
- print PM $out;
- close PM;
- }
|