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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#!/usr/bin/perl
#
# tcsim_pretty - Pretty printer for tcsim traces
#
# Written 2001,2002 by Werner Almesberger
# Copyright 2001 EPFL-ICA
# Copyright 2002 Bivio Networks
#
$WIDTH = 79;
$INDENT = 13;
$wrap = 1;
$last_time = -1;
sub id
{
local ($time,$skb,$len) = @_;
if ($time != $last_time) {
$s = sprintf("%.6f",$time);
print (("-"x(13-length($s)))." $s ".("-"x($WIDTH-15))."\n");
$last_time = $time;
}
if ($skb eq "0x0") {
print sprintf(" %-10s ","n/a");
}
elsif ($skb eq $last_skb) {
print sprintf(" %-10s ","=");
}
else {
print sprintf(" %-10s ",$skb);
$last_skb = $skb;
}
}
sub print
{
local ($s) = @_;
$pos = $INDENT;
for (split(" ",$s)) {
if ($wrap && $pos+1+length >= $WIDTH && $pos != 14) {
$pos = $INDENT+2;
print "\n".(" "x$INDENT)."+ ";
}
print " " unless $pos == $INDENT;
print;
$pos += 1+length;
}
print "\n";
}
while ($ARGV[0] =~ /^-/) {
$opt = shift;
if ($opt eq "-l") { $wrap = 0; }
elsif ($opt eq "-w" && $ARGV[0] =~ /^\d+$/) { $WIDTH = shift; }
else {
print STDERR "usage: $0 [-l] [-w width] [file ...]\n";
exit(1);
}
}
while (<>) {
chop;
if (/^(\d+\.\d+) ([IED]) : (0x[0-9a-f]+) (\d+) : /) {
undef $last_skb if $2 ne "D";
&id($1,$3,$4);
&print("$2 $4: $'");
next;
}
if (/^(\d+\.\d+) T : /) {
&id($1,"0x0",0);
&print("T $'");
next;
}
if (/^(\d+\.\d+) \* : (0x[0-9a-f]+) (\d+) : /) {
&id($1,$2,$3);
&print("* $'");
next;
}
if (/^(\d+\.\d+) \* : /) {
&id($1,"0x0",0);
&print("* $'");
next;
}
if (/^(\d+\.\d+) ([iedxrcp]) : (0x[0-9a-f]+) (\d+) : <(\d+)> /) {
&id($1,$3,$4);
&print("$2 ".(" "x$5).$');
next;
}
print "ERROR: unrecognizable input line\n$_\n";
exit(1);
}
|