#!/usr/bin/perl -w # -*- tcl -*- # colordiff is Copyright 1998 Todd David Rudick # Released under the Gnu general public license, # Questions and comments to rudick@gmail.com # use strict; use FileHandle; my $COLOR_XTERM="rxvt"; my $GNUDIFF="diff"; my $GNULESS="less"; sub usage { my $progname = shift; return qq|Usage:\n$progname file1 file2|; } if (scalar(@ARGV)!=2) { die usage($0); } my $tagString="ToddDavidRudickColorDiff-$$"; my $fh=new FileHandle("-|") || exec($GNUDIFF,"-D",$tagString,"-b","-B",@ARGV); my $state=1; my %opening = ( 1 => "", 2 => "\e[01;33m", 3 => "\e[01;37;44m", ); my $less = new FileHandle("|-") || exec($GNULESS,"-u","-f","-r","-P", "Key-\e[0m Both \e[01;37;44m$ARGV[0]\e[0m \e[01;33m$ARGV[1]\e[0m" ); while (<$fh>) { chomp; if (/$tagString/) { /^#ifdef/ && do { $state=2; next; }; /^#ifndef/ && do { $state=3; next; }; /^#endif/ && do { $state=1; next; }; /^#else/ && do { $state=5-$state; next; }; # flip } else { print $less $opening{$state},$_,"\e[0m\n"; } }