summaryrefslogtreecommitdiff
path: root/packaging/var-checker
diff options
context:
space:
mode:
authorWayne Davison <wayned@samba.org>2008-07-21 00:10:22 -0700
committerWayne Davison <wayned@samba.org>2008-07-21 00:10:22 -0700
commit93465f51bcc2484a1bdf0f94ed3b812fa5c39576 (patch)
tree91193ab84f22ced214fd20496b1570b74ab93635 /packaging/var-checker
parent26a7af26aa149017e2b16a0b96d74d3bacc7a7f1 (diff)
downloadrsync-93465f51bcc2484a1bdf0f94ed3b812fa5c39576.tar.gz
Improved var-checker and tweaked all the issues it found.
Diffstat (limited to 'packaging/var-checker')
-rwxr-xr-xpackaging/var-checker73
1 files changed, 65 insertions, 8 deletions
diff --git a/packaging/var-checker b/packaging/var-checker
index eb8b32e1..b63428b7 100755
--- a/packaging/var-checker
+++ b/packaging/var-checker
@@ -1,18 +1,75 @@
-#!/usr/bin/perl
-# This script finds extraneous "extern" variables in the *.c files.
-# Run it from inside the main rsync directory.
+#!/usr/bin/perl -w
+# This script checks the *.c files for extraneous "extern" variables,
+# for vars that are defined but not used, and for inconsistent array
+# sizes. Run it from inside the main rsync directory.
use strict;
+my %add_syscall_c = map { $_ => 1 } qw( t_stub.c t_unsafe.c tls.c trimslash.c );
+my %add_util_c = map { $_ => 1 } qw( t_stub.c t_unsafe.c );
+my %sizes;
+
+open(IN, '<', 'syscall.c') or die $!;
+undef $/; my $syscall_c = <IN>; $/ = "\n";
+close IN;
+$syscall_c =~ s/^extern\s.*//mg;
+
+open(IN, '<', 'util.c') or die $!;
+undef $/; my $util_c = <IN>; $/ = "\n";
+close IN;
+$util_c =~ s/^extern\s.*//mg;
+
my @files = glob('*.c');
foreach my $fn (@files) {
- open(IN, '<', $fn) or die;
+ open(IN, '<', $fn) or die $!;
undef $/; $_ = <IN>; $/ = "\n";
close IN;
- my @externs = /^extern .*?([^[\s(*;&.]+)(?:\[.*?\])?;/mg;
- foreach my $find (@externs) {
- my @matches = /(?<!\sstruct )\b(\Q$find\E)\b/g;
- print $fn, ': ', $find, "\n" if @matches == 1;
+
+ my @vars = /^(?!(?:extern|enum)\s)([a-zA-Z]\S*\s+.*);/mg;
+ my @externs = /^extern\s+(.*);/mg;
+
+ $_ .= $syscall_c if $add_syscall_c{$fn};
+ $_ .= $util_c if $add_util_c{$fn};
+ s/INFO_GTE/info_levels/g;
+ s/DEBUG_GTE/debug_levels/g;
+
+ check_vars($fn, 'var', @vars);
+ check_vars($fn, 'extern', @externs);
+}
+
+exit;
+
+# The file's contents are in $_.
+sub check_vars
+{
+ my $fn = shift;
+ my $type = shift;
+
+ foreach my $line (@_) {
+ $line =~ s/\s*\{.*\}//;
+ $line =~ s/\s*\(.*\)//;
+ foreach my $item (split(/\s*,\s*/, $line)) {
+ $item =~ s/\s*=.*//;
+ my $sz = $item =~ s/(\[.*?\])// ? $1 : '';
+ my($var) = $item =~ /([^*\s]+)$/;
+ if (!defined $var) {
+ print "Bogus match? ($item)\n";
+ next;
+ }
+ if ($sz) {
+ if (defined $sizes{$var}) {
+ if ($sizes{$var} ne $sz) {
+ print $fn, ' has inconsistent size for "', $var,
+ "\": $sizes{$var} vs $sz\n";
+ }
+ } else {
+ $sizes{$var} = $sz;
+ }
+ }
+ my @matches = /(?<!\sstruct )\b(\Q$var\E)(?!\w)/g;
+ push(@matches, /(\QSIGACTION(\E)/g) if $var eq 'sigact';
+ print $fn, " has extraneous $type: \"", $var, "\"\n" if @matches == 1;
+ }
}
}