summaryrefslogtreecommitdiff
path: root/stub
diff options
context:
space:
mode:
authorJean Delvare <jdelvare@suse.de>2010-03-08 13:59:47 +0000
committerJean Delvare <jdelvare@suse.de>2010-03-08 13:59:47 +0000
commit0ccc954c5a7543c57ffc0f41d5f1608e480ac377 (patch)
tree8507b4de611354e3d3ab3daa20f294f5d8e10c50 /stub
parent9a6022de1be1ae759179ecc462e808f047dfd029 (diff)
downloadi2c-tools-git-0ccc954c5a7543c57ffc0f41d5f1608e480ac377.tar.gz
Use fewer global variables, to make the code easier to read and
modify. git-svn-id: http://lm-sensors.org/svn/i2c-tools/trunk@5829 7894878c-1315-0410-8ee3-d5d059ff63e0
Diffstat (limited to 'stub')
-rwxr-xr-xstub/i2c-stub-from-dump38
1 files changed, 19 insertions, 19 deletions
diff --git a/stub/i2c-stub-from-dump b/stub/i2c-stub-from-dump
index 5b15496..3b6fbfc 100755
--- a/stub/i2c-stub-from-dump
+++ b/stub/i2c-stub-from-dump
@@ -22,7 +22,7 @@
# a device you do not have access to, but of which you have a dump.
use strict;
-use vars qw($bus_nr $addr $bytes $words $err);
+use vars qw($bus_nr $addr $err);
# Kernel version detection code by Mark M. Hoffman,
# copied from sensors-detect.
@@ -116,8 +116,9 @@ sub load_kernel_drivers
sub process_dump
{
- my $dump = shift;
+ my ($addr, $dump) = @_;
my $err = 0;
+ my ($bytes, $words);
open(DUMP, $dump) || die "Can't open $dump: $!\n";
OUTER_LOOP:
@@ -156,6 +157,21 @@ sub process_dump
}
close(DUMP);
+ if ($bytes) {
+ printf SAVEOUT "$bytes byte values written to \%d-\%04x\n",
+ $bus_nr, $addr;
+ }
+
+ if ($words) {
+ printf SAVEOUT "$words word values written to \%d-\%04x\n",
+ $bus_nr, $addr;
+ }
+
+ if (!$err && !$bytes && !$words) {
+ printf SAVEOUT "Only garbage found in dump file $dump\n";
+ $err = 1;
+ }
+
return $err;
}
@@ -179,27 +195,11 @@ if ($addr !~ m/^0x[0-7][0-9a-f]$/i) {
initialize_kernel_version();
$bus_nr = load_kernel_drivers($addr);
-$bytes = $words = 0;
# We don't want to see the output of 256 i2cset
open(SAVEOUT, ">&STDOUT");
open(STDOUT, ">/dev/null");
-$err = process_dump($ARGV[1]);
+$err = process_dump(oct $addr, $ARGV[1]);
close(STDOUT);
-if ($bytes) {
- printf SAVEOUT "$bytes byte values written to \%d-\%04x\n",
- $bus_nr, oct($addr);
-}
-
-if ($words) {
- printf SAVEOUT "$words word values written to \%d-\%04x\n",
- $bus_nr, oct($addr);
-}
-
-if (!$err && ($bytes + $words == 0)) {
- printf SAVEOUT "Only garbage found in dump file $ARGV[1]\n";
- exit(1);
-}
-
exit($err);