Compare two files in workspace

Instructional HowTos, posted by users. No questions here please.

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
lotus298
Posts: 6
Joined: Fri Jun 01, 2007 1:20 am

Compare two files in workspace

Post by lotus298 »

This perl script will launch a gui that lets you select two files from your workspace and compare them with tkdiff (of whatever tool you choose).

Remember to save your workspace before running this, as it parses the last saved workspace. Anyone know if "save workspace" is macro-able?

Code: Select all

# TKDiff for Textpad
# 
# DOS command should be:
#    perl c:\userdata\temp\textpad\filecompare.pl "$WspDir\$WspBaseName.tws" "$File"
#
# Default uses tkdiff for windows (http://texttest.carmen.se/TextTest/docs/tkdiffInstall.zip)
# Could be updated to use about any diff tool.
#
# Note that this always parses a TWS file to get list of filenames.  Make sure to save workspace before
#   running this.
#

use Tk;

my $twsfilename = $ARGV[0];

open (INFILE, "<$twsfilename") || die "Failed to open $twsfilename";
my @twslines = (<INFILE>);
close INFILE;

my $main = MainWindow->new();
#$main->minsize( qw(250 250) );
$main->title("Compare Textpad files");
#$main->configure(-background=>'cyan');
#$main->geometry('+10+300');

my $file0frame = $main->Frame()->pack(-side=>'left');
my $file1frame = $main->Frame()->pack(-side=>'left');

my $filename0 = $ARGV[1];
my $filename1;

my @filenames = ();
foreach (@twslines) {
  split(/ECOD../, $_);
  foreach (@_) {
    if ($_ =~ /^(.+?)\x01/gi) {
      my $tmpfilename = $1;
      unless (-f $tmpfilename) {next;}
      @filenames = (@filenames, $tmpfilename);
      $file0frame->Radiobutton(-variable=>\$filename0, -text=>'', -value=>$tmpfilename)->pack(-side=>'top', -anchor=>'w');
      $file1frame->Radiobutton(-variable=>\$filename1, -text=>$tmpfilename, -value=>$tmpfilename)->pack(-side=>'top', -anchor=>'w');
    }
  }
}

my $btnFrm   = $main->Frame()->pack(-side=>'bottom', -fill=>'y');
my $runbutton = $btnFrm->Button(-text=>'Compare', -command=> sub {&compare})->pack(-side=>'right',-pady=>2,-anchor=>'w');

MainLoop;

sub compare {
  if (($filename0 ne "") && ($filename1 ne "")) {
    print "comparing $filename0 $filename1\n";
    #my $cmd = "\"BC2.exe\" \"$filename0\" \"$filename1\"";
    my $cmd = "\"tkdiff\" \"$filename0\" \"$filename1\"";
    print "$cmd\n";
    `$cmd`;
    exit 0;
  } else {
    print "something isn't selected\n";
  }
}

Last edited by lotus298 on Fri Jun 01, 2007 5:46 pm, edited 1 time in total.
lotus298
Posts: 6
Joined: Fri Jun 01, 2007 1:20 am

Post by lotus298 »

Updated original post. Changed command to

perl c:\userdata\temp\textpad\filecompare.pl "$WspDir\$WspBaseName.tws" "$File"
Post Reply