summaryrefslogtreecommitdiff
path: root/fml/lib/IO/Adapter/File.pm
diff options
context:
space:
mode:
authorfukachan <fukachan>2001-01-28 07:32:40 +0000
committerfukachan <fukachan>2001-01-28 07:32:40 +0000
commit7ee280e93c6797fef8ab87454869272bd2df3526 (patch)
tree347ba0d76613c58a77f30301999bb013a248fd3c /fml/lib/IO/Adapter/File.pm
parent6d5d0c61438aa90bde9e1b368f09be53151ed188 (diff)
downloadfml8-7ee280e93c6797fef8ab87454869272bd2df3526.tar.gz
fml8-7ee280e93c6797fef8ab87454869272bd2df3526.tar.bz2
fml8-7ee280e93c6797fef8ab87454869272bd2df3526.zip
move file IO codes to a file adapter sub-layer (sub-class)
Diffstat (limited to 'fml/lib/IO/Adapter/File.pm')
-rw-r--r--fml/lib/IO/Adapter/File.pm91
1 files changed, 90 insertions, 1 deletions
diff --git a/fml/lib/IO/Adapter/File.pm b/fml/lib/IO/Adapter/File.pm
index df999494..73c17a69 100644
--- a/fml/lib/IO/Adapter/File.pm
+++ b/fml/lib/IO/Adapter/File.pm
@@ -8,7 +8,7 @@
# $FML$
#
-package IO::MapAdapter::File;
+package IO::Adapter::File;
use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
use Carp;
@@ -26,6 +26,95 @@ sub new
}
+sub open
+{
+ my ($self, $args) = @_;
+
+ my $file = $args->{ file };
+ my $flag = $args->{ flag };
+ my $fh;
+ use FileHandle;
+ $fh = new FileHandle $file, $flag;
+ if (defined $fh) {
+ $self->{_fh} = $fh;
+ return $fh;
+ }
+ else {
+ $self->_error_reason("Error: cannot open $file $flag");
+ return undef;
+ }
+}
+
+
+# debug tools
+my $c = 0;
+my $ec = 0;
+sub line_count { my ($self) = @_; return "${ec}/${c}";}
+
+
+sub get_next_value
+{
+ my ($self) = @_;
+
+ my ($buf) = '';
+ my $fh = $self->{_fh};
+
+ if (defined $fh) {
+ INPUT:
+ while ($buf = <$fh>) {
+ $c++; # for benchmark (debug)
+ next INPUT if not defined $buf;
+ next INPUT if $buf =~ /^\s*$/o;
+ next INPUT if $buf =~ /^\#/o;
+ next INPUT if $buf =~ /\sm=/o;
+ next INPUT if $buf =~ /\sr=/o;
+ next INPUT if $buf =~ /\ss=/o;
+ last INPUT;
+ }
+
+ if (defined $buf) {
+ my @buf = split(/\s+/, $buf);
+ $buf = $buf[0];
+ $buf =~ s/[\r\n]*$//o;
+ $ec++;
+ }
+ return $buf;
+ }
+ return undef;
+}
+
+
+sub getops
+{
+ my ($self) = @_;
+ my $fh = $self->{_fh};
+ defined $fh ? tell($fh) : undef;
+}
+
+
+sub setops
+{
+ my ($self, $pos) = @_;
+ my $fh = $self->{_fh};
+ seek($fh, $pos, 0);
+}
+
+
+sub eof
+{
+ my ($self) = @_;
+ my $fh = $self->{_fh};
+ $fh->eof if defined $fh;
+}
+
+
+sub close
+{
+ my ($self) = @_;
+ $self->{_fh}->close if defined $self->{_fh};
+}
+
+
#####
##### This is just a dummy yet now.
#####