1#!/usr/bin/perl -w
2#
3# whereintheworld
4# Parses "make world" output and summarize where it's been so far.
5#
6# Bill Fenner <fenner@freebsd.org> 11 January 2000
7# Dag-Erling Sm��rgrav <des@freebsd.org> 09 January 2003
8#
9# $Id: whereintheworld,v 1.3 2000/01/28 00:42:32 fenner Exp $
10# $FreeBSD$
11#
12
13use strict;
14
15my $line;
16my $inside = 0;
17my @lines = ();
18my $thresh = 10;
19my $lastwasdash = 0;
20my $width = $ENV{COLUMNS} || 80;
21my $error = 0;
22my $elided = 0;
23
24while ($line = <>) {
25	if ($line =~ /^------------/) {
26		$inside = !$inside;
27		print $line unless ($lastwasdash);
28		$lastwasdash = 1;
29		@lines = ();
30		next;
31	}
32	if ($inside && $line =~ /^>>>/) {
33		print $line;
34		$lastwasdash = 0;
35		next;
36	}
37	if ($line =~ /^TB /) {
38		print $line;
39		next;
40	}
41	if ($line =~ /^=+>/) {
42		@lines = ();
43	}
44	push(@lines, $line);
45	if ($line =~ /^\*\*\* Error/ && $line !~ /\(ignored\)/) {
46		$error = 1;
47		while ($line = <>) {
48			push(@lines, $line);
49		}
50		last;
51	}
52}
53
54if (@lines && !$error) {
55	print shift(@lines);
56	while (@lines > $thresh) {
57		shift(@lines);
58		++$elided;
59	}
60	if ($elided > 0) {
61		print "[$elided lines elided]\n";
62	}
63}
64foreach $line (@lines) {
65	if (!$error && $line !~ m/^TB / && length($line) >= $width) {
66		substr($line, $width - 7) = " [...]\n";
67	}
68	print $line;
69}
70