--- /dev/null
+#!/usr/bin/perl -w
+
+package SCX::LogReader;
+
+use strict;
+
+sub new {
+ my ($class, $args) = @_;
+
+ open my $fh, '<', $args->{filename}
+ or die "Can't open $args->{filename}: $!";
+
+ my $self = {
+ begin_time => $args->{begin_time} || 0,
+ end_time => $args->{end_time} || (1<<32),
+ fh => $fh,
+ };
+
+ bless $self, $class;
+
+ return $self;
+}
+
+sub get_data {
+ my ($self) = @_;
+
+ my $fh = $self->{fh};
+
+ my ($line, $l_time, @data);
+ do {
+ $line = <$fh>;
+ return undef if !defined $line;
+
+ chomp $line;
+ $line =~ s/\A\s+//xms;
+
+ ($l_time, @data) = split(/\s+/, $line);
+ } while ($l_time < $self->{begin_time});
+
+ return undef if $l_time > $self->{end_time};
+
+ return ($l_time, map { hex $_ } @data);
+}
+
+1;
+
use strict;
use Getopt::Std;
+use SCX::LogReader;
use SCX::LogPrinter;
my %opt;
my $logfile = shift @ARGV;
-open my $logfh, '<', $logfile
- or die "Can't open $logfile: $!";
+my $reader = SCX::LogReader->new({
+ filename => $logfile,
+});
my %args;
my $printer = SCX::LogPrinter->new(\%args);
-while (my $line = <$logfh>) {
- chomp $line;
- $line =~ s/\A\s+//xms;
- my ($l_time, @data) = split(/\s+/, $line);
-
- $printer->add_data($l_time, map { hex $_ } @data);
+while (my ($l_time, @data) = $reader->get_data()) {
+ $printer->add_data($l_time, @data);
}