File: diff2php

package info (click to toggle)
hxtools 20221119-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,760 kB
  • sloc: ansic: 5,114; perl: 3,612; cpp: 2,727; sh: 1,622; makefile: 156
file content (73 lines) | stat: -rwxr-xr-x 1,850 bytes parent folder | download | duplicates (2)
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
#!/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