Subject: | Various coding errors in bin/debinhex.pl fixed (mswin32) |
Script bin/debinhex.pl won't even compile on MSWin32 (or any non-Mac
platform, I believe). Fixed multiple coding errors. Patch attached:
* 02_debinhex.patch
Subject: | 02_debinhex.patch |
*** tmp/local/build/.cpan/build/Convert-BinHex-1.119/bin/debinhex.pl Sat Jun 28 00:39:59 1997
--- usr/local/build/.cpan/build/Convert-BinHex-1.119/bin/debinhex.pl Thu Feb 16 17:16:15 2006
***************
*** 27,53 ****
=head1 WARNINGS
Largely untested.
! =head1 AUTHOR
Paul J. Schinder (NASA/GSFC) mostly, though Eryq can't seem to keep
his grubby paws off anything...
=cut
! use lib "./lib";
use Getopt::Std;
use Convert::BinHex;
use POSIX;
use Fcntl;
use File::Basename;
use Carp;
- require Mac::Files if ($^O||'' eq "MacOS");
use strict;
use vars qw(
$opt_o
$opt_v
--- 27,55 ----
=head1 WARNINGS
Largely untested.
! =head1 AUTHORS
Paul J. Schinder (NASA/GSFC) mostly, though Eryq can't seem to keep
his grubby paws off anything...
+ Sören M. Andersen (somian), made it actually work under Perl 5.8.7 on MSWin32.
=cut
! my $The_OS;
! BEGIN { $The_OS = $^O ? $^O : q// }
! eval { require Mac::Files } if ($The_OS eq "MacOS");
use Getopt::Std;
use Convert::BinHex;
use POSIX;
use Fcntl;
use File::Basename;
use Carp;
use strict;
use vars qw(
$opt_o
$opt_v
***************
*** 80,91 ****
sub usage {
my $msg = shift || '';
my $usage = '';
if (open(USAGE, "<$0")) {
! while ($_ = <USAGE> and !/^=head1 USAGE/) {};
! while ($_ = <USAGE> and !/^=head1/) {$usage .= $_};
close USAGE;
}
else {
$usage = "Usage unavailable; please see the script itself.";
}
--- 82,93 ----
sub usage {
my $msg = shift || '';
my $usage = '';
if (open(USAGE, "<$0")) {
! while (defined($_ = <USAGE>) and !/^=head1 USAGE/) {};
! while (defined($_ = <USAGE>) and !/^=head1/) {$usage .= $_};
close USAGE;
}
else {
$usage = "Usage unavailable; please see the script itself.";
}
***************
*** 105,114 ****
--- 107,117 ----
print "DeBinHexing: $inpath\n";
# Open BinHex file:
open(BHEX,"<$inpath") || croak("Unable to open $inpath: $!");
+ binmode BHEX;
# Create converter interface on stream:
my $hqx = Convert::BinHex->open(FH => \*BHEX);
# Read header, and output as string if debugging:
***************
*** 120,141 ****
my $outname = $hqx->filename || 'NONAME';
my $outdir = $opt_o || $indir;
my $outpath = "$outdir/$outname"; $outpath =~ s{/+}{/}g;
# Create Mac file:
! if ($^O||'' eq "MacOS") {
Mac::Files::FSpCreate($outpath, $hqx->creator, $hqx->type)
or croak("Unable to create Mac file $outpath");
}
# Get lengths of forks:
my $dlength = $hqx->data_length;
my $rlength = $hqx->resource_length;
# Write data fork:
print "Writing: $outpath\n";
! $fd = POSIX::open($outpath, (&POSIX::O_WRONLY | &POSIX::O_CREAT), 0755);
$testlength = 0;
while (defined($data = $hqx->read_data)) {
$length = length($data);
POSIX::write($fd, $data, $length)
or croak("couldn't write $length bytes: $!");
--- 123,144 ----
my $outname = $hqx->filename || 'NONAME';
my $outdir = $opt_o || $indir;
my $outpath = "$outdir/$outname"; $outpath =~ s{/+}{/}g;
# Create Mac file:
! if ($The_OS eq "MacOS") {
Mac::Files::FSpCreate($outpath, $hqx->creator, $hqx->type)
or croak("Unable to create Mac file $outpath");
}
# Get lengths of forks:
my $dlength = $hqx->data_length;
my $rlength = $hqx->resource_length;
# Write data fork:
print "Writing: $outpath\n";
! $fd = POSIX::open($outpath, (&POSIX::O_WRONLY | &POSIX::O_CREAT | &Fcntl::O_BINARY), 0755);
$testlength = 0;
while (defined($data = $hqx->read_data)) {
$length = length($data);
POSIX::write($fd, $data, $length)
or croak("couldn't write $length bytes: $!");
***************
*** 149,165 ****
# Write resource fork?
if ($rlength) {
# Determine how to open fork file appropriately:
my ($rpath, $rflags);
! if (($^O||'') eq "MacOS") {
$rpath = $outpath;
$rflags = (&POSIX::O_WRONLY | &POSIX::O_CREAT | &Fcntl::O_RSRC);
}
else {
$rpath = "$outpath.rsrc";
! $rflags = (&POSIX::O_WRONLY | &POSIX::O_CREAT);
}
# Write resource fork...
$fd = POSIX::open($rpath, $rflags, 0755);
$testlength = 0;
--- 152,168 ----
# Write resource fork?
if ($rlength) {
# Determine how to open fork file appropriately:
my ($rpath, $rflags);
! if ($The_OS eq "MacOS") {
$rpath = $outpath;
$rflags = (&POSIX::O_WRONLY | &POSIX::O_CREAT | &Fcntl::O_RSRC);
}
else {
$rpath = "$outpath.rsrc";
! $rflags = (&POSIX::O_WRONLY | &POSIX::O_CREAT | &Fcntl::O_BINARY);
}
# Write resource fork...
$fd = POSIX::open($rpath, $rflags, 0755);
$testlength = 0;
***************
*** 174,184 ****
"expected $rlength, wrote $testlength")
if $testlength != $rlength;
}
# Set Mac attributes:
! if (($^O||'') eq "MacOS") {
my $has = Mac::Files::FSpGetCatInfo($outpath);
my $finfo = $has->{ioFlFndrInfo};
$finfo->{fdFlags} = $hqx->flags & 0xfeff; #turn off inited bit
$finfo->{fdType} = $hqx->type || "????";
$finfo->{fdCreator} = $hqx->creator || "????";
--- 177,187 ----
"expected $rlength, wrote $testlength")
if $testlength != $rlength;
}
# Set Mac attributes:
! if ($The_OS eq "MacOS") {
my $has = Mac::Files::FSpGetCatInfo($outpath);
my $finfo = $has->{ioFlFndrInfo};
$finfo->{fdFlags} = $hqx->flags & 0xfeff; #turn off inited bit
$finfo->{fdType} = $hqx->type || "????";
$finfo->{fdCreator} = $hqx->creator || "????";
***************
*** 203,211 ****
}
1;
}
#------------------------------------------------------------
! 1;
!
!
!
--- 206,212 ----
}
1;
}
#------------------------------------------------------------
! __END__
! # Last modified: 16 Feb 2006 at 05:16 PM EST