diffcol
3.23 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/perl
if ($#ARGV < 1)
{
die "usage: diffcol file1.tab file2.tab [expn-reg] [expn-reg] [...] \n";
}
$File1Name = shift;
$File2Name = shift;
open(FILE1, $File1Name) || die "Can't open file $File1Name";
open(FILE2, $File2Name) || die "Can't open file $File2Name";
$HeaderCount = 0;
while(<FILE1>)
{
last if (/^\s*\d+/);
if (!/^#/ && !/^\s*$/ && !/.*\(.*\)/)
{
($SignalName, $Foo) = split;
$SignalName =~ s/\[.*\]//;
$SignalNumbers[$HeaderCount] = $SignalName;
$SignalNames{$SignalName} = sprintf("%.3d", $HeaderCount++-1);
}
}
$File1LineNumber = $.;
$HeaderCount--;
$Line1 = $_;
while(<FILE2>)
{
last if (/^\s*\d+/);
}
$File2LineNumber = $.;
$Line2 = $_;
if ($File1LineNumber != $File2LineNumber)
{
die "Error, tab files from different dumps";
}
if ($#ARGV == -1)
{
open(EXPAND, "expand 0-$HeaderCount |");
@ExpandNumbers = <EXPAND>;
close(EXPAND);
chop @ExpandNumbers;
}
while ($#ARGV > -1)
{
$ExpandString = shift;
if ($ExpandString =~ /^\d/)
{
open(EXPAND, "expand $ExpandString |");
@TempExpandNumbers = <EXPAND>;
close(EXPAND);
chop @TempExpandNumbers;
@ExpandNumbers = (@ExpandNumbers, @TempExpandNumbers);
}
else
{
@SignalDumpNames = split(/,/, $ExpandString);
foreach $i (0..$#SignalDumpNames)
{
if ($SignalDumpNames[$i] =~ /-/)
{
($Signal1, $Signal2) = split(/-/, $SignalDumpNames[$i]);
die "Error, signal $Signal1 undefined \n" if !($SignalNames{$Signal1});
die "Error, signal $Signal2 undefined \n" if !($SignalNames{$Signal2});
open(EXPAND, "expand $SignalNames{$Signal1}-$SignalNames{$Signal2} |");
@TempExpandNumbers = <EXPAND>;
close(EXPAND);
chop @TempExpandNumbers;
@ExpandNumbers = (@ExpandNumbers, @TempExpandNumbers);
}
else
{
die "Error, signal $SignalDumpNames[$i] undefined \n" if !($SignalNames{$SignalDumpNames[$i]});
@ExpandNumbers = (@ExpandNumbers, $SignalNames{$SignalDumpNames[$i]});
}
}
}
}
$VectorNumber = 0;
while ($Line1)
{
die "Error, files misaligned"
if ((($Line1 =~ /^#/) && !($Line2 =~ /^#/)) || (!($Line1 =~ /^#/) && ($Line2 =~ /^#/)));
if (($Line1 =~ /^#/) && ($Line2 =~ /^#/))
{
$Line1 = <FILE1>;
$Line2 = <FILE2>;
$File1LineNumber++;
$File2LineNumber++;
next;
}
@Line1Values = split(/[ \t\n]+/, $Line1);
@Line2Values = split(/[ \t\n]+/, $Line2);
die "Error, different number of columns in input files" if ($#Line1Values != $#Line2Values);
foreach $i (0 .. $#ExpandNumbers)
{
die "Error, signal $ExpandNumbers[$i] out of range 0-$HeaderCount" if ($ExpandNumbers[$i] > $HeaderCount);
if ($Line1Values[$ExpandNumbers[$i]] ne $Line2Values[$ExpandNumbers[$i]])
{
printf("Vector %4.4d, line %4.4d\t\t%s[%-18.18s,%s]->%-18.18s %s[%-18.18s,%s]->%s \n",
$VectorNumber, $File1LineNumber,
$File1Name, $SignalNumbers[$ExpandNumbers[$i]], $ExpandNumbers[$i], $Line1Values[$ExpandNumbers[$i]],
$File2Name, $SignalNumbers[$ExpandNumbers[$i]], $ExpandNumbers[$i], $Line2Values[$ExpandNumbers[$i]]);
}
}
$Line1 = <FILE1>;
$Line2 = <FILE2>;
$File1LineNumber++;
$File2LineNumber++;
$VectorNumber++;
}