#!/usr/bin/perl -w # # twhexdiff - Command-line tool to invoke TextWrangler's Find Differences command # on file hex dumps on Mac OS X. # by Eric Blair # http://www.raol.com/ # # Version 1.1 # Fri Feb 6, 2004 # # Based heavily on bbdiff, by John Gruber # http://daringfireball.net/projects/bbdiff/ # # See POD for details (type "perldoc twhexdiff"). # use strict; use File::Spec::Unix; use Getopt::Long; use File::Basename; # command line options for generating hex files my $hexdump = "/usr/bin/hexdump -C"; my $background = "false"; my $case_sensitive = "true"; my $ignore_whitespace = "false"; my $old_hex = ""; my $new_hex = ""; our (%opts); # hash to store command-line switches Getopt::Long::Configure("auto_abbrev"); Getopt::Long::Configure("permute"); Getopt::Long::Configure("bundling"); Getopt::Long::GetOptions(\%opts, 'b', 'i', 's', 'o|old_hex=s' => \$old_hex, 'n|new_hex=s' => \$new_hex, ); if ($opts{'b'}) { $background = "true"; } if ($opts{'i'}) { $case_sensitive = "false"; } if ($opts{'s'}) { $ignore_whitespace = "true"; } # Make sure each argument is an existing plain file. foreach (@ARGV) { ( -f ) or die $_ . " is not a file.\n"; } # Get full paths to file arguments. my ($old_file, $new_file) = @ARGV; my $new_file_full = File::Spec::Unix->rel2abs( $new_file ); my $old_file_full = File::Spec::Unix->rel2abs( $old_file ); my $t1 = ""; my $t2 = ""; if($old_hex eq "") { $old_file = basename( $old_file ); $old_hex = "/tmp/$old_file.hex_o"; } else { $old_hex = File::Spec::Unix->rel2abs( $old_hex ); }; if($new_hex eq "") { $new_file = basename( $new_file ); $new_hex = "/tmp/$new_file.hex_n"; } else { $new_hex = File::Spec::Unix->rel2abs( $new_hex ); }; if($new_hex eq $old_hex) { die "Hex file names must be unique.\n"; } system ( "$hexdump \"$old_file_full\" > \"$old_hex\"" ); system ( "$hexdump \"$new_file_full\" > \"$new_hex\"" ); my $a_script = qq[ tell application "TextWrangler" set comp_opts to {case sensitive:$case_sensitive, ignore leading spaces:$ignore_whitespace, ignore trailing spaces:$ignore_whitespace} set comp_result to compare POSIX file "$new_hex" against POSIX file "$old_hex" options comp_opts if differences found of comp_result then if not $background then activate return "Differences found." else set the_reason to reason for no differences of comp_result return "No differences found: " & the_reason end if end tell ]; system ( "/usr/bin/osascript -e '$a_script'" ); __END__ =pod =head1 NAME B - Command-line tool to invoke TextWrangler's Find Differences command on file hex dumps on Mac OS X. Based upon bbdiff. =head1 SYNOPSIS twhexdiff [-b -i -s] [-o oldhex] [-n newhex] oldfile newfile =head1 OPTIONS B accepts these options: =over 4 =item B<-b> Keep TextWrangler in the background. By default, TextWrangler will activate if differences are found. =item B<-i> Case insensitive comparison. =item B<-s> Ignore leading and trailing whitespace on lines. =item B<-o oldhex> Specify a file name for the hex dump from the old file. If this option is not specified, a temporary file will be created in the /tmp directory. Can also be specified with --old_hex. =item B<-n newhex> Specify a file name for the hex dump from the new file. If this option is not specified, a temporary file will be created in the /tmp directory. Can optionally be specified with --new_hex. =back =head1 VERSION HISTORY 1.1: Fri Feb 6, 2004 Initial release, based off bbhexdiff 1.1. =head1 AUTHOR Eric Blair http://www.raoli.com/projects/twhexdiff/ bbdiff by John Gruber http://daringfireball.net/projects/bbdiff/ =head1 COPYRIGHT and LICENSE Copyright (c) 2004 Eric Blair bbdiff Copyright (c) 2002 John Gruber. This program is free and open software. You may use, copy, modify, distribute, and sell this program (and any modified variants) in any way you wish, provided you do not restrict others from doing the same. =cut