update readme and add gitignore
[client-tools.git] / tools / crashCompare.pl
blob0886ed6fa785f89a8c28b6779dada0e70e419490
1 #!/usr/bin/perl -w
2 use strict;
4 my (%keys, %rows);
5 my (@files, $file);
6 my $row = 0;
7 my $spaced = 0;
9 die "$0: Usage: $0 <directory>\n" unless(@ARGV);
11 if($ARGV[0] eq "-s")
13 $spaced=1;
14 shift;
17 opendir(DIR, "$ARGV[0]") || die "$0: Can't open directory $ARGV[0]\n";
18 while($_ = readdir(DIR))
20 next unless($_ =~ m%\.txt$% && $_ !~ m%^_%);
21 push(@files, $_);
23 closedir(DIR);
25 exit if($#files == -1);
27 foreach $file(@files)
29 open(INPUT, "<$ARGV[0]/$file") || die "$0: Can't open $_: $!\n";
30 $keys{"z-filename"}=1;
31 while(<INPUT>)
33 $/="\n\n";
34 my $trash = <INPUT>;
35 $trash = <INPUT>;
36 $/="\n";
37 while($_ = <INPUT>)
39 chomp;
40 if(/:/)
42 my($key, $value) = split(/:/, $_, 2);
43 $value =~ s%\s+% %g;
44 $value =~ s%^\s+%%;
45 $value =~ s%\s+$%%;
46 my @elements = split(/\s/, $value);
47 if($spaced && $#elements > 0)
49 my $origkey = $key;
50 for(0 .. $#elements)
52 $key = $origkey . ($_+1);
53 $rows{$row}{$key} = $elements[$_];
54 $keys{$key} = 1;
57 else
59 $rows{$row}{$key} = $value;
60 $keys{$key} = 1;
63 $rows{$row}{"z-filename"} = $file;
66 close(INPUT);
67 $row++;
70 print join("\t", sort(keys(%keys)));
71 print "\n";
73 $row--;
75 my $colcount;
76 for(0..$row)
78 $colcount = 1;
79 if (defined $rows{$_})
81 my %current = %{$rows{$_}};
82 foreach my $column (sort(keys(%keys)))
84 if(defined($current{$column}))
86 print $current{$column};
88 else
90 print "-";
92 print "\t" unless(scalar(keys(%keys)) == $colcount);
93 $colcount++;
95 print "\n";