Changeset 5829

Show
Ignore:
Timestamp:
03/08/10 14:59:47 (4 years ago)
Author:
khali
Message:

Use fewer global variables, to make the code easier to read and
modify.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • i2c-tools/trunk/stub/i2c-stub-from-dump

    r5828 r5829  
    2323 
    2424use strict; 
    25 use vars qw($bus_nr $addr $bytes $words $err); 
     25use vars qw($bus_nr $addr $err); 
    2626 
    2727# Kernel version detection code by Mark M. Hoffman, 
     
    117117sub process_dump 
    118118{ 
    119         my $dump = shift; 
     119        my ($addr, $dump) = @_; 
    120120        my $err = 0; 
     121        my ($bytes, $words); 
    121122 
    122123        open(DUMP, $dump) || die "Can't open $dump: $!\n"; 
     
    157158        close(DUMP); 
    158159 
     160        if ($bytes) { 
     161                printf SAVEOUT "$bytes byte values written to \%d-\%04x\n", 
     162                        $bus_nr, $addr; 
     163        } 
     164 
     165        if ($words) { 
     166                printf SAVEOUT "$words word values written to \%d-\%04x\n", 
     167                        $bus_nr, $addr; 
     168        } 
     169 
     170        if (!$err && !$bytes && !$words) { 
     171                printf SAVEOUT "Only garbage found in dump file $dump\n"; 
     172                $err = 1; 
     173        } 
     174 
    159175        return $err; 
    160176} 
     
    180196 
    181197$bus_nr = load_kernel_drivers($addr); 
    182 $bytes = $words = 0; 
    183198 
    184199# We don't want to see the output of 256 i2cset 
    185200open(SAVEOUT, ">&STDOUT"); 
    186201open(STDOUT, ">/dev/null"); 
    187 $err = process_dump($ARGV[1]); 
     202$err = process_dump(oct $addr, $ARGV[1]); 
    188203close(STDOUT); 
    189204 
    190 if ($bytes) { 
    191         printf SAVEOUT "$bytes byte values written to \%d-\%04x\n", 
    192                 $bus_nr, oct($addr); 
    193 } 
    194  
    195 if ($words) { 
    196         printf SAVEOUT "$words word values written to \%d-\%04x\n", 
    197                 $bus_nr, oct($addr); 
    198 } 
    199  
    200 if (!$err && ($bytes + $words == 0)) { 
    201         printf SAVEOUT "Only garbage found in dump file $ARGV[1]\n"; 
    202         exit(1); 
    203 } 
    204  
    205205exit($err);