#!/usr/local/bin/perl
#
# whereintheworld
# Parses "make world" output and summarize where it's been so far.
#
# Bill Fenner <fenner@freebsd.org> 11 January 2000
#
# $Id: whereintheworld,v 1.3 2003/12/09 22:25:14 anarcat Exp $
#
use strict;

my $lastarrow = undef;
my $inside = 0;
my @lines = ();
my $thresh = 5;
my $lastwasdash = 0;
my $file = $ARGV[0] || (-f "/usr/src/world.out" ? "/usr/src/world.out" : "-");
open(LOG, $file) || die "$file: $!\n";
while (<LOG>) {
	if (/^------------/) {
		$inside = !$inside;
		print unless ($lastwasdash);
		$lastwasdash = 1;
		@lines = ();
		next;
	}
	if ($inside && /^>>>/) {
		chomp;
		printf "%-70.70s\n", $_;
		$lastwasdash = 0;
		next;
	}
	push(@lines, $_);
	if (/^===>/) {
		chomp;
		$| = 1;
		printf "%-70.70s\r", $_;
	}
	if ($#lines > $thresh) {
		my $line = shift(@lines);
		$lastarrow = $line if ($line =~ /^===>/);
	}
}
if ($lines[0] !~ /^===>/ && $lastarrow) {
	print $lastarrow, "...\n";
}
print @lines;
