/usr/bin/diffpp is in enscript 1.6.5.90-2+b1.
This file is owned by root:root, with mode 0o755.
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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | #!/usr/bin/perl
# -*- perl -*-
#
# Pretty-print diff outputs with GNU enscript.
# Copyright (c) 1996-1998 Markku Rossi
#
# Author: Markku Rossi <mtr@iki.fi>
#
#
# This file is part of GNU Enscript.
#
# Enscript is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Enscript is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Enscript. If not, see <http://www.gnu.org/licenses/>.
#
#
# Original idea by Trent Fisher <trent@informix.com>
# Thanks to:
# - Tero Kivinen <kivinen@iki.fi> for the first prototype
# - Tait Cyrus <tait.cyrus@mci.com> for fixes and cleanups
#
$file = shift(@ARGV);
$add_gray = ".80";
$del_gray = ".60";
$program = $0;
$program =~ s/.*\///g;
sub usage {
warn "Usage: $program ORIGINAL_FILE < DIFF\n\n";
warn "Program reads a diff file from its standard input and annotates
ORIGINAL_FILE to show the changes made to the file. The easiest way to use
this program is to use it as an input filter for GNU enscript:
\$ enscript -G2re --filter='rcsdiff %s | diffpp %s' *.c *.h
\$ enscript -G2re --filter='diff %s~ %s | diffpp %s' *.c *.h
";
}
if (!defined($file) || defined($ARGV[0])) {
&usage;
exit 1;
}
if ($file eq "--help") {
&usage;
exit 0;
}
if ($file eq "--version") {
warn "diffpp 1.0\n";
exit 0;
}
# Read in original file into internal array.
open(FP, $file) || die "$program: couldn't open file `$file' for input: $!\n";
@orig_file = <FP>;
close(FP);
$[ = 1;
$orig_line_num = 1;
$orig_num_lines = @orig_file;
# Now read in file of diffs into internal array.
@diffs = <STDIN>;
$diff_line_num = 1;
$diff_num_lines = @diffs;
while ($diff_line_num <= $diff_num_lines) {
$_ = $diffs[$diff_line_num];
if (/a/) {
do_add($_);
} elsif (/d/) {
do_delete($_);
} elsif (/c/) {
do_change($_);
}
}
while ($orig_line_num <= $orig_num_lines) {
print $orig_file[$orig_line_num++];
}
# Handle new/added lines
#
# Formats used:
# #a#
# #a#,#
sub do_add {
($line) = @_;
if ($line =~ /(\d+)a(\d+),(\d+)/) {
$insert_at_line = $1;
$num_new_lines = $3 - $2 + 1;
} elsif ($line =~ /(\d+)a(\d+)/) {
$insert_at_line = $1;
$num_new_lines = 1;
}
&skip_to_line($insert_at_line);
printf("\000shade{$add_gray}");
&mark_to_line($num_new_lines, "+");
printf("\000shade{1.0}");
}
# Handle deleted/removed lines
#
# Formats used:
# #d#
# #,#d#
sub do_delete {
($line) = @_;
if ($line =~ /(\d+),(\d+)d(\d+)/) {
$num_del_lines = $2 - $1 + 1;
} elsif ($line =~ /(\d+)d(\d+)/) {
$num_del_lines = 1;
}
$del_from = $1;
&skip_to_line($del_from - 1);
printf("\000shade{$del_gray}");
&mark_to_line($num_del_lines, "-");
printf("\000shade{1.0}");
$orig_line_num += $num_del_lines;
}
# Handle changed/modified lines
#
# Formats used:
# #,#c#,#
# #,#c#
# #c#,#
# #c#
sub do_change {
($line) = @_;
if ($line =~ /(\d+),(\d+)c(\d+),(\d+)/) {
$num_old_lines = $2 - $1 + 1;
$num_new_lines = $4 - $3 + 1;
$change_at_line = $1;
} elsif ($line =~ /(\d+),(\d+)c(\d+)/) {
$num_old_lines = $2 - $1 + 1;
$num_new_lines = 1;
$change_at_line = $1;
} elsif ($line =~ /(\d+)c(\d+),(\d+)/) {
$num_old_lines = 1;
$num_new_lines = $3 - $2 + 1;
$change_at_line = $1;
} elsif ($line =~ /(\d+)c(\d+)/) {
$num_old_lines = 1;
$num_new_lines = 1;
$change_at_line = $1;
}
# Mark old lines
&skip_to_line($change_at_line - 1);
$orig_line_num += $num_old_lines; # skip over changed lines
printf("\000shade{$del_gray}");
&mark_to_line($num_old_lines, "-");
printf("\000shade{1.0}");
# Mark new lines
printf("\000shade{$add_gray}");
&mark_to_line($num_new_lines, "+");
printf("\000shade{1.0}");
}
sub skip_to_line {
($line) = @_;
while ($orig_line_num <= $line) {
print $orig_file[$orig_line_num];
$orig_line_num++;
}
}
sub mark_to_line {
($num_lines, $marker) = @_;
$diff_line_num++; # skip over diff command
while ($num_lines > 0) {
$diff_line = substr($diffs[$diff_line_num++],3);
print "\000ps{gsave -5 0 rmoveto ($marker) show grestore}";
print $diff_line;
$num_lines--;
}
}
|