hxtools/sdevel/diff2php

74 lines
1.8 KiB
Perl
Executable File

#!/usr/bin/perl
# SPDX-License-Identifier: MIT
#
# diff2php - turn a .diff into a multi-purpose PHP script
# written by Jan Engelhardt, 2004-2007
use strict;
my %C = qw(black 000000 red AA0000 green 00AA00 brown AA5500
blue 0000AA magenta AA00AA cyan 00AAAA gray AAAAAA
dgray 555555 hred FF0000 hgreen 00FF00 yellow FFFF00
hblue 0000FF hmagenta FF00FF hcyan 00FFFF white FFFFFF
dblue 000080);
my $F = "</font>";
my %D;
my @keep;
foreach my $key (keys %C) {
$D{$key} = "<font color=\"".$C{$key}."\">";
}
print <<"--EOF";
<?php
if (getenv("QUERY_STRING") == "1") {
header("Content-Type: text/plain\n");
?>
--EOF
while (defined(my $ln = <STDIN>)) {
push(@keep, $ln);
$ln =~ s{<\?}{<\?php echo "<?"; ?>}g;
print $ln;
}
print <<"--EOF";
<?php } else { ?>
<html>
<style type="text/css">
a { color: B0B0B0; }
</style>
<body style="background-color: #$C{dblue}; color: #$C{gray};">
<p><a href="?1"><i>Download this file as TXT</i></a></p>
<hr />
<pre>
--EOF
while (defined(my $line = shift @keep)) {
chomp($line);
$line =~ s/&/&amp;/gso;
$line =~ s/</&lt;/gso;
$line =~ s/>/&gt;/gso;
$line =~ s/^(#.*)/$D{yellow}$1$F/ ||
$line =~ s/^(\@\@.+\@\@)(.*)/$D{cyan}$1$F$D{hcyan}$2$F/ ||
$line =~ s/^(Index:\s.*)/$D{black}$1$F/ ||
$line =~ s/^(diff.*)/<span style="background-color: #$C{red};">$D{white}$1$F<\/span>/ ||
$line =~ s/^((---|\+\+\+|\*\*\*).*)/$D{hmagenta}$1$F/ ||
$line =~ s/^(===.*)/$D{brown}$1$F/ ||
$line =~ s/^([\+\>].*)/$D{hgreen}$1$F/ ||
$line =~ s/^([\-\<].*)/$D{hred}$1$F/ ||
$line =~ s/^(\!.*)/$D{yellow}$1$F/ ||
$line =~ s/^(\?.*)/$D{brown}$1$F/ ||
$line =~ s/^((RCS|retrieving)\s.*)/$D{brown}$1$F/ ||
$line =~ s/^((Only|Common|File|Files|Binary)\s.*)/$D{hblue}$1$F/;
print $line, "\n";
}
print <<"--EOF";
</pre>
</body>
</html>
<?php } ?>
--EOF