From 48d5c63aec18f301e01e42bc712fe2a4f0ae254f Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 16 Jul 1999 09:52:15 +0000 Subject: [PATCH] open class file as binary handle read to return early git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@1086 379699f6-c40d-0410-875b-85095c16579e --- jode/javaDependencies.pl.in | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/jode/javaDependencies.pl.in b/jode/javaDependencies.pl.in index 2e05ff8..b8dd616 100755 --- a/jode/javaDependencies.pl.in +++ b/jode/javaDependencies.pl.in @@ -39,11 +39,22 @@ my $buff; -sub readUTF { - read FILE, $buff, 2 or die "Can't read UTF8 length"; +sub readInBuff ($) { + my $count = $_[0]; + my $offset = 0; + while ($count > 0) { + my $result = read FILE, $buff, $count, $offset or 0; + $offset += $result; + $count -= $result; + } + $offset; +} + +sub readUTF () { + readInBuff 2 or die "Can't read UTF8 length"; my $ulength = unpack("n", $buff) & 0xffff; return "" if $ulength == 0; - read FILE, $buff, $ulength or die "Can't read UTF8 string $ulength"; + readInBuff $ulength or die "Can't read UTF8 string $ulength"; unpack("a$ulength", $buff); } @@ -54,15 +65,16 @@ my ($filename, %done); %done=(); for $filename ($clazz, glob("$base\\\$*.class")) { open FILE, $filename; + binmode FILE; - read FILE, $buff, 8 or die "Can't read header"; + readInBuff 8 or die "Can't read header"; my ($magic, $minor, $major) = unpack("Nnn", $buff); die "Wrong magic $magic" if $magic != 0xcafebabe; die "Wrong minor $minor" if $minor > 3; die "Wrong minor $major" if $major != 45; - read FILE, $buff, 2 or die "Can't read cpool length"; + readInBuff 2 or die "Can't read cpool length"; my ($length) = unpack("n", $buff) & 0xffff; @@ -72,7 +84,7 @@ for $filename ($clazz, glob("$base\\\$*.class")) { my @clazzes; for ($number = 1; $number < $length; $number++) { - read FILE, $buff, 1 or die "Can't read constant tag"; + readInBuff 1 or die "Can't read constant tag"; my ($tag) = unpack("C", $buff); #print STDERR "$number/$length: $tag"; @@ -87,27 +99,27 @@ for $filename ($clazz, glob("$base\\\$*.class")) { /^(3|4|9|10|11|12)$/ && do { # INTEGER, FLOAT, FIELDREF, METHODREF, IFACEREF, NAMEANDTYPE - read FILE, $buff, 4; + readInBuff 4; last tags; }; /^(5|6)$/ && do { # LONG, DOUBLE - read FILE, $buff, 8; + readInBuff 8; $number++; last tags; }; /^7$/ && do { # CLASS - read FILE, $buff, 2; + readInBuff 2; push @clazzes, (unpack("n", $buff) & 0xffff); last tags; }; /^8$/ && do { # STRING - read FILE, $buff, 2; + readInBuff 2; last tags; }; die "Unknown tag: $tag, $number/$length, $filename"; @@ -135,6 +147,6 @@ for $filename ($clazz, glob("$base\\\$*.class")) { } if (@deplist) { print "# Dependencies of $filename\n"; - print "$clazz: ". join (" ", @deplist) . "\n"; + print "$clazz: " . join (" ", @deplist) . "\n"; } }