#!/usr/bin/perl
#: Turns ASCII text into Unicode Asian wide ("fullwidth") letters.
#======================================================================

# sburke@cpan.org
#  Last Modified Time-stamp: "2010-07-25 02:42:58 AKDT sburke@cpan.org"

unless(@ARGV) {
  print
"Usage:  widen [files...]
  Reads from files, converts simple characters
   to fullwidth forms, and writes to STDOUT.
  To read from STDIN, specify '-' as
   the input file.
  Input files are assumed to be plain ASCII, or utf8.
";
  exit;
}

foreach my $x (*STDERR, *STDOUT, *STDIN) {
  binmode($x, ":utf8")
   or die "Can't binmode-utf8 $x : $!\n "
}

my $stdin = *STDIN; # so we only get to use it once.
foreach my $fs (@ARGV) {
  my $IN;
  if($fs eq '-') {
    next unless $stdin;
    $IN = $stdin;
    undef $stdin;
  } else {
    open $IN, "<", $fs
     or die "Can't read-open $fs: $!\n ";
    binmode($IN, ":utf8")
     or die "Can't binmode-utf8 $x : $!\n "
  }

  # FINALLY:
  while(<$IN>) {   
    tr[\x{0020}\x{0021}-\x{007E}]
      [\x{3000}\x{FF01}-\x{FF7E}];
    print $_;
  }

  close($IN) or die "Can't close $IN: $!\n ";
}
__END__
