#!/usr/bin/perl -w # # bbhexdiff - Command-line tool to invoke BBEdit's Find Differences command # on file hex dumps on Mac OS X. # by Eric Blair # http://www.raol.com/ # # Version 1.1 # Fri Mar 28, 2003 # # Based beavily on bbdiff, by John Gruber # http://daringfireball.net/projects/bbdiff/ # # See POD for details (type "perldoc bbhexdiff"). # 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 "BBEdit" 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 BBEdit's Find Differences command on file hex dumps on Mac OS X. Based upon bbdiff. =head1 SYNOPSIS bbhexdiff [-b -i -s] [-o oldhex] [-n newhex] oldfile newfile =head1 OPTIONS B accepts these options: =over 4 =item B<-b> Keep BBEdit in the background. By default, BBEdit 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.0: Thu Mar 27, 2003 Initial release. 1.1: Fri Mar 28, 2003 Fix bug so you can compare files of the same name without saving the hex files. Make sure hex names are unique in all usage cases. Remove debugging code for printing names of hex files with -o and -n options. Correct date of 1.0 release -- yesterday was not a Monday. =head1 AUTHOR Eric Blair http://www.raoli.com/projects/bbhexdiff/ bbdiff by John Gruber http://daringfireball.net/projects/bbdiff/ =head1 COPYRIGHT and LICENSE Copyright (c) 2003 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