File: check-diff.pl

package info (click to toggle)
ns2 2.35%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 78,796 kB
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 816; awk: 525; csh: 355
file content (72 lines) | stat: -rwxr-xr-x 1,546 bytes parent folder | download | duplicates (8)
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
#!/usr/bin/perl -w
#
# $Header: /cvsroot/nsnam/ns-2/bin/check-diff.pl,v 1.2 2000/10/17 18:10:08 haoboy Exp $

use strict;
use Carp;

sub convert_line_left { 
    my ($line, $res) = @_;
    my ($pos);
    $pos = length($line);
    $pos-- while (! (substr($line,$pos,1) =~ /[0-9,\]\)\(]/));
    $line = substr($line, 0, $pos);
    $line =~ s/\(/\\\(/g;
    $line =~ s/\)/\\\)/g;
    $line =~ s/\[/\\\[/g;
    $line =~ s/\]/\\\]/g;
    $line =~ s/\*/\\\*/g;
    return $line;
}

sub convert_line_right {
    my ($line, $res) = @_;
    my ($pos);
    chop($line);
    $pos = 0;
    $pos++ while (! (substr($line,$pos,1) =~ /[0-9]/));
    $line = substr($line, $pos);
    $line =~ s/\(/\\\(/g;
    $line =~ s/\)/\\\)/g;
    $line =~ s/\[/\\\[/g;
    $line =~ s/\]/\\\]/g;
    $line =~ s/\*/\\\*/g;
    return $line;
}

if ($#ARGV != 2) {
	print "Usage: check-diff.pl <test_out1> <test_out2> left|right\n";
	exit 0;
}

my ($buf, $file1, $file2, $ret);

$file1 = $ARGV[0];
$file2 = $ARGV[1];

open(FP, "diff --side-by-side --suppress-common-lines $file1 $file2 |") || 
    die "can't open pipe.\n";

while (<FP>) {
    /  </ && do {
	next if ($ARGV[2] ne "left");
	$buf = convert_line_left($_);
	$ret = `egrep -e '$buf' $file2`;
	if ($? >> 8) {
	    chop;
	    print "line not found in file $file2:\n\t$buf\n";
	}
	next;
    };
    /  >/ && do {
	next if ($ARGV[2] ne "right");
	$buf = convert_line_right($_);
	$ret = `egrep -e '$buf' $file1`;
	if ($? >> 8) {
	    chop;
	    print "line not found in file $file1:\n\t$buf\n";
	}
	next;
    };
}
exit 0;