Use NSInteger where absolutely required.
[MacTF.git] / to-UTF-16.pl
blob042e93a4ce0fdb04575d2276a37980f73f7bd81a
1 #! /usr/bin/perl
3 use strict;
4 use warnings;
6 my($in_name, $out_name) = @ARGV;
8 open my $in_h, "<", $in_name or die "$in_name: $!";
9 binmode $in_h or die "$in_name: $!";
10 my $head;
11 defined(read $in_h, $head, 4) or die "$in_name: $!";
12 close $in_h or die "$in_name: $!";
14 my $charset;
15 if ($head =~ /^\x00\x00\xFF\xFE/) {
16 print "$in_name: Found big-endian UTF-32 BOM\n";
17 $charset = "UTF-32";
18 } elsif ($head =~ /^\xFE\xFF\x00\x00/) {
19 print "$in_name: Found little-endian UTF-32 BOM\n";
20 $charset = "UTF-32";
21 } elsif ($head =~ /^\xFE\xFF/) {
22 print "$in_name: Found big-endian UTF-16 BOM\n";
23 $charset = "UTF-16";
24 } elsif ($head =~ /^\xFF\xFE/) {
25 print "$in_name: Found little-endian UTF-16 BOM\n";
26 $charset = "UTF-16";
27 } elsif ($head =~ /^\xEF\xBB\xBF/) {
28 print "$in_name: Found UTF-8 BOM\n";
29 $charset = "UTF-8";
30 } else {
31 print "$in_name: No BOM found -- assuming UTF-8\n";
32 $charset = "UTF-8";
35 open STDOUT, ">", $out_name or die "$out_name: $!";
36 exec "iconv", "-f", $charset, "-t", "UTF-16", $in_name
37 or die "exec iconv: $!";