1#! FOOBAR
2#
3# colormake.pl 0.2
4#
5# Copyright: (C) 1999, Bjarni R. Einarsson <bre@netverjar.is>
6#                      http://www.mmedia.is/~bre/
7#
8#   This program is free software; you can redistribute it and/or modify
9#   it under the terms of the GNU General Public License as published by
10#   the Free Software Foundation; either version 2 of the License, or
11#   (at your option) any later version.
12#
13#   This program is distributed in the hope that it will be useful,
14#   but WITHOUT ANY WARRANTY; without even the implied warranty of
15#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16#   GNU General Public License for more details.
17#
18#   You should have received a copy of the GNU General Public License
19#   along with this program; if not, write to the Free Software
20#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21#
22
23# Some useful color codes, see end of file for more.
24#
25$col_ltgray =       "\033[37m";
26$col_purple =       "\033[35m";
27$col_red    =       "\033[31m";
28$col_blue    =      "\033[34m";
29$col_green =        "\033[32m";
30$col_cyan =         "\033[36m";
31$col_brown =        "\033[33m";
32$col_norm =	    "\033[00m";
33$col_background =   "\033[07m";
34$col_brighten =     "\033[01m";
35$col_underline =    "\033[04m";
36$col_blink = 	    "\033[05m";
37
38# Customize colors here...
39#
40$col_default =      $col_green;
41$col_gcc =          $col_blue;
42$col_make =         $col_cyan;
43$col_filename =     $col_purple;
44$col_linenum =      $col_cyan;
45$col_trace =        $col_brown;
46$col_warning =      $col_purple . $col_brighten;
47$col_error =        "Error: " . $col_red . $col_brighten;
48$error_highlight =  $col_brighten;
49
50# Get size of terminal
51#
52$lines = shift @ARGV || 0;
53$cols  = shift @ARGV || 0;
54$cols -= 19;
55
56$in = 'unknown';
57while (<>)
58{
59	$thisline = $_;
60
61	# Truncate lines.
62	# I suppose this is bad, but it's better than what less does!
63	if ($cols >= 0)
64	{
65	    $thisline =~ s/^(.{$cols}).....*(.{15})$/$1 .. $2/;
66	}
67
68	# make[1]: Entering directory `/blah/blah/blah'
69	if ($thisline =~ s/^(make\[)/$col_make$1/x)
70	{
71		$in = 'make';
72	}
73	elsif ($thisline =~ s/^((gcc|cc|g\+\+|c\+\+).*)$/$col_gcc$1$col_norm/)
74	{
75		$in = 'gcc';
76	}
77	elsif ($thisline =~ /^(echo|rm|ar|sed|find|mv|cp|install|make|perl|awk|set|for)/)
78	{
79		$in = $1;
80	}
81
82	if ($in eq 'gcc')
83	{
84		# Do interesting things if make is compiling something.
85
86		if (($thisline !~ /[,:]$/) && ($thisline !~ /warning/))
87		{
88			# error?
89			$thisline =~ s/(\d+:\s+)/$1$col_default$col_error/;
90			$thisline = $error_highlight . $thisline . $col_norm;
91		}
92		else
93		{
94			# warning
95			$thisline =~ s|(warning:\s+)(.*)$|$1$col_warning$2|;
96		}
97
98		# In file included from main.cpp:38:
99		# main.cpp: In function int main(...)':
100		$thisline =~ s/(In f(unction|ile))/$col_trace$1/x;
101
102		# /blah/blah/blah.cpp:123:
103		$thisline =~ s|^([^:]+)|$col_filename$1$col_default|;
104		$thisline =~ s|:(\d+)([:,])|:$col_linenum$1$col_default$2|;
105	}
106
107	if ($thisline !~ /^\s+/)
108	{
109		print $col_norm, $col_default;
110	}
111	print $thisline;
112}
113
114print $col_norm;
115
116# UNUSED:
117#
118#%colors = (
119#    'black'     => "\033[30m",
120#    'red'       => "\033[31m",
121#    'green'     => "\033[32m",
122#    'yellow'    => "\033[33m",
123#    'blue'      => "\033[34m",
124#    'magenta'   => "\033[35m",
125#    'purple'    => "\033[35m",
126#    'cyan'      => "\033[36m",
127#    'white'     => "\033[37m",
128#    'darkgray'  => "\033[30m");
129
130