line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/local/bin/perl -w |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/) |
5
|
|
|
|
|
|
|
# All rights reserved. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Stream::FileInputStream; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
@FileInputStream::ISA = qw(Stream::FileInputStream); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# FileInputStream |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# Inherits from InputStream, redefining all of it's member |
16
|
|
|
|
|
|
|
# functions: |
17
|
|
|
|
|
|
|
# read |
18
|
|
|
|
|
|
|
# skip |
19
|
|
|
|
|
|
|
# readAll |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
# Perhaps we should consider making this inherit from FileHandle? |
23
|
|
|
|
|
|
|
# |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
26
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
76
|
|
27
|
1
|
|
|
1
|
|
993
|
use FileHandle; |
|
1
|
|
|
|
|
14501
|
|
|
1
|
|
|
|
|
6
|
|
28
|
1
|
|
|
1
|
|
1351
|
use POSIX; |
|
1
|
|
|
|
|
8239
|
|
|
1
|
|
|
|
|
7
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub usage |
32
|
|
|
|
|
|
|
{ |
33
|
0
|
|
|
0
|
0
|
0
|
my ($package, $filename, $line, $subr) = caller(1); |
34
|
0
|
|
|
|
|
0
|
$Carp::CarpLevel = 2; |
35
|
0
|
|
|
|
|
0
|
croak "Usage: $subr(@_)"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new |
39
|
|
|
|
|
|
|
{ |
40
|
2
|
50
|
|
2
|
0
|
78
|
usage("FileHandle | filename") unless @_ == 2; |
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
|
|
3
|
my $type = shift; my $self = {}; bless $self, $type; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
4
|
|
43
|
2
|
|
33
|
|
|
7
|
my $arg = shift || usage("FileHandle | filename"); |
44
|
|
|
|
|
|
|
|
45
|
2
|
50
|
|
|
|
6
|
if (ref($arg)) |
46
|
|
|
|
|
|
|
{ |
47
|
0
|
0
|
|
|
|
0
|
if (ref($arg) eq 'FileHandle') |
48
|
|
|
|
|
|
|
{ |
49
|
0
|
|
|
|
|
0
|
$self->{'fh'} = $arg; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else |
52
|
|
|
|
|
|
|
{ |
53
|
0
|
|
|
|
|
0
|
usage("FileHandle | filename"); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else |
57
|
|
|
|
|
|
|
{ |
58
|
2
|
|
|
|
|
11
|
$self->{'fh'} = new FileHandle $arg, 'r'; |
59
|
2
|
50
|
|
|
|
227
|
defined($self->{'fh'}) || return "Could not open $arg"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
6
|
$self; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub close |
66
|
|
|
|
|
|
|
{ |
67
|
0
|
|
|
0
|
0
|
0
|
shift->{'fh'}->close(); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub read |
71
|
|
|
|
|
|
|
{ |
72
|
34
|
50
|
|
34
|
0
|
129
|
usage("count") unless @_ == 2; |
73
|
|
|
|
|
|
|
|
74
|
34
|
|
|
|
|
37
|
my $self = shift; |
75
|
34
|
|
|
|
|
33
|
my $count = shift; |
76
|
34
|
|
|
|
|
35
|
my $fh = $self->{'fh'}; |
77
|
|
|
|
|
|
|
|
78
|
34
|
|
|
|
|
35
|
my $retval = ""; |
79
|
34
|
50
|
|
|
|
100
|
read($fh, $retval, $count) || return; |
80
|
34
|
|
|
|
|
88
|
$retval; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub seek |
84
|
|
|
|
|
|
|
{ |
85
|
1
|
50
|
|
1
|
0
|
13
|
usage("type count") unless @_ == 3; |
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
|
|
2
|
my $self = shift; |
88
|
1
|
|
|
|
|
2
|
my $type = shift; |
89
|
1
|
|
|
|
|
2
|
my $count = shift; |
90
|
1
|
|
|
|
|
7
|
$self->{'fh'}->seek($type, $count); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub skip |
94
|
|
|
|
|
|
|
{ |
95
|
0
|
|
|
0
|
0
|
0
|
croak("Not yet implemented"); |
96
|
0
|
0
|
|
|
|
0
|
usage("count") unless @_ == 2; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
0
|
my $self = shift; |
99
|
0
|
|
|
|
|
0
|
my $count = shift; |
100
|
0
|
|
|
|
|
0
|
my $fh = $self->{'fh'}; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
0
|
my $data = $fh->read($count); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub readAll |
106
|
|
|
|
|
|
|
{ |
107
|
1
|
50
|
|
1
|
0
|
14
|
usage unless @_ == 1; |
108
|
|
|
|
|
|
|
|
109
|
1
|
|
|
|
|
2
|
my $self = shift; |
110
|
1
|
|
|
|
|
2
|
my $fh = $self->{'fh'}; |
111
|
|
|
|
|
|
|
|
112
|
1
|
|
|
|
|
3
|
my $save_sep = $/; |
113
|
1
|
|
|
|
|
4
|
undef $/; |
114
|
1
|
|
|
|
|
32
|
my $retval = <$fh>; |
115
|
1
|
|
|
|
|
3
|
$/ = $save_sep; |
116
|
|
|
|
|
|
|
|
117
|
1
|
|
|
|
|
5
|
$retval; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub eoi |
121
|
|
|
|
|
|
|
{ |
122
|
0
|
0
|
|
0
|
0
|
|
usage unless @_ == 1; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
eof(shift->{'fh'}); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |