#!/usr/bin/perl

# Script to colorize the output of the debug-information from the kernel module

use strict;

use Term::ANSIColor qw(:constants);
$Term::ANSIColor::AUTORESET = 1;

while(<>){
	chomp;
	my $time = $_;
	$time =~ s/^.{10}(\d\d:\d\d).*/$1/;
	print "$time ";
	s/.*kernel: //;
	if(/AODV RREQ|AODV RREP/){
		s/;//g;
		my @line = split / /;
		for (@line){
			if(/RREQ:$/){
				print BOLD YELLOW "$_ ";
			}elsif(/RREP/){
				print BOLD MAGENTA "$_ ";
			}elsif(/E:|A:|T:/){
				s/AODV//;
				print "$_";
			}elsif(/ORIG/){
				print RED "$_ ";
			}elsif(/SRC/){
				print CYAN "$_ ";
			}elsif(/DST-IP|DST-SEQ/){
				print YELLOW "$_ ";
			}elsif(/DST/){
				print BOLD CYAN "$_ ";
			}elsif(/\d+\.\d+\.\d+\.\d+/){
				s/\.(\d)$/.0$1/;
				print BOLD GREEN "$_ ";
			}elsif(/\d+/){
				print BOLD BLUE "$_ ";
			}elsif(/Has|extension|Hopcount|RREQ-ID|Lifetime/){
				print "$_ ";
			}
		}
		print "\n";
	}else{
		print BOLD RED ON_WHITE $_;
		print "\n";
	}
}
