forked from lightbend/genjavadoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
treechange.pl
executable file
·46 lines (42 loc) · 941 Bytes
/
treechange.pl
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
#!/usr/bin/perl -w
use strict;
local $/ = "\n[[syntax trees at end of";
my $previous;
while (<>) {
next unless /^\s*(\w+)]](.*?)$(.*)/sm;
my ($phase, $status, $text) = ($1, $2, $3);
print "*** $phase ***\n";
if (!defined($previous)) {
print $text;
} elsif ($status =~ /tree is unchanged since/) {
$text = $previous;
} else {
&diff($previous, $text);
}
$previous = $text;
}
sub diff {
my ($old, $new) = @_;
local $^F = 1000;
pipe my $oldr, my $oldw;
pipe my $newr, my $neww;
my $diff = fork;
unless ($diff) {
close $oldw;
close $neww;
my $old = "/dev/fd/".fileno($oldr);
my $new = "/dev/fd/".fileno($newr);
exec { '/usr/bin/diff' } 'diff', '-wu', $old, $new or die "cannot exec with $old $new: $!\n";
}
close $oldr;
close $newr;
unless (fork) {
close $neww;
print $oldw $old;
exit;
}
close $oldw;
print $neww $new;
close $neww;
waitpid $diff, 0;
}