/usr/share/doc/libconvert-binhex-perl/examples/binhex.pl is in libconvert-binhex-perl 1.125-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | #!/usr/bin/perl -w
=head1 NAME
binhex.pl - use Convert::BinHex to encode files as BinHex
=head1 USAGE
Usage:
binhex.pl [options] file ... file
Where the options are:
-o dir Output in given directory (default outputs in file's directory)
-v Verbose output (normally just one line per file is shown)
=head1 DESCRIPTION
Each file is converted to file.hqx.
=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");
our $VERSION = '1.125'; # VERSION
use strict;
use vars qw(
$opt_o
$opt_v
);
my $DEBUG = 0;
#------------------------------------------------------------
# main
#------------------------------------------------------------
sub main {
# What usage?
@ARGV or usage();
getopts('o:v');
$DEBUG = $opt_v;
# Process files:
my $file;
foreach $file (@ARGV) {
binhex($file);
}
}
exit(&main ? 0 : -1);
#------------------------------------------------------------
# usage
#------------------------------------------------------------
# Get usage from me.
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.";
}
print STDERR "\n$msg$usage";
exit -1;
}
#------------------------------------------------------------
# binhex FILE
#------------------------------------------------------------
# Encode the given FILE.
#
sub binhex {
my $inpath = shift || die "No filename given $!";
local *BHEX;
my ($has, $dlength, $rlength, $finfo, $flags);
# Create new BinHex interface:
my $hqx = Convert::BinHex->new;
# Get input directory/filename:
my ($inname, $indir) = fileparse($inpath);
die "filename $inname too long!" if ((length($inname)+4) > 31);
$hqx->filename($inname);
# Set up output directory/filename:
my $outname = "$inname.hqx";
my $outdir = $opt_o || $indir;
my $outpath = "$outdir/$outname"; $outpath =~ s{/+}{/}g;
# If we're on a Mac, we can get the real resource info:
if ($^O||'' eq "MacOS") {
# Get and set up type, creator, flags:
$has = Mac::Files::FSpGetCatInfo($inpath);
$finfo = $has->{ioFlFndrInfo};
$dlength = $has->{ioFlLgLen};
$rlength = $has->{ioFlRLgLen};
$hqx->type($finfo->{fdType});
$hqx->creator($finfo->{fdCreator});
$hqx->flags($finfo->{fdFlags} & 0xfeff); # turn off inited bit
# Set up data fork:
$hqx->data(Path=>$inpath);
$hqx->data->length($dlength);
# Set up resource fork:
$hqx->resource(Path=>$inpath, Fork => "RSRC");
$hqx->resource->length($rlength);
}
else { # not a Mac: fake it...
# Set up data fork:
$hqx->data(Path => $inpath);
$dlength = (-s $inpath);
# Set up resource fork:
if (-e "$inpath.rsrc") {
$hqx->resource(Path => "$inpath.rsrc");
$rlength = (-s "$inpath.rsrc");
}
else {
$hqx->resource(Data => '');
$rlength = 0;
}
}
# Ready!
print "BinHexing: $inpath\n";
if ($DEBUG) {
print " Resource size: $rlength\n" if defined($rlength);
print " Data size: $dlength\n" if defined($dlength);
}
open BHEX, ">$outpath" or croak("Unable to open $outpath");
$hqx->encode(\*BHEX);
close BHEX;
print "Wrote: $outpath\n";
}
#------------------------------------------------------------
1;
|