#============================================================ # TokyuText #============================================================ package TokyuText; use NextTrain::NextTrain; @ISA = qw(NextTrain); use strict; #============================================================ # コンストラクタ、デストラクタ #============================================================ BEGIN { } sub new { my ($module, $App) = @_; my $this = {}; bless $this; $this->SetApplication($App); $this->InitializeNotes(); return $this; } sub DESTROY { my $this = shift; # $this->SUPER::DESTROY(@_); } #=============================================== # 変数取得関数 #=============================================== sub InitializeNotes { my ($this) = @_; $this->{Mark} = 'A'; $this->{pNoteMarkArray} = []; $this->{pNoteHash} = {}; my %NoteMark0; $NoteMark0{"急"} = "e"; $this->{pNoteHash}{"急"} = "急行"; $NoteMark0{"準"} = "s"; $this->{pNoteHash}{"準"} = "準急"; $NoteMark0{"−"} = "p"; $this->{pNoteHash}{"−"} = "通過"; $this->{pNoteMarkArray}[0] = \%NoteMark0; } #=============================================== # 一般メンバー関数 #=============================================== sub SplitMinites { my ($this, $line) = @_; $line = NextTrain::Zen2Han($line); my ($s1, $note2) = Utils::Split("\\s+", $line); my ($note1, $min) = ($s1 =~ /^\s*(\D*)\s*(−|\d*)\s*$/); return ($note1, $min, $note2); } sub ReadAllNotes { my ($this, $pInputFiles) = @_; for(my $i = 0 ; $i < @$pInputFiles ; $i++) { my $InFile = $pInputFiles->[$i]; $this->ReadNotes($i, $InFile); } } sub ReadNotes { my ($this, $idx, $InFile) = @_; my $pMark = $this->pMark(); my $pNoteMarkOriginal = $this->pNoteMarkOriginal(); my $pNoteMark = $this->pNoteMark($idx); my $pNoteHash = $this->pNoteHash(); my $in = new JFile; if(!$in->Open($InFile, "r")) { $this->print("Error: Can not read [$InFile].\n"); return; } #print "Read [$InFile]\n"; my $line = $in->SkipTo("\\d{4}"); while(1) { $line = $in->ReadLine(); last if($in->eof()); Jcode::convert(\$line, "sjis"); #print "l: $line"; last if($line =~ /駅情報トップ/); } while(1) { $line = $in->ReadLine(); last if($in->eof()); Jcode::convert(\$line, "sjis"); $line =~ s/ / /g; Utils::DelSpace($line); next if($line eq ''); #print "line: $line\n"; my ($note, $comment) = ($line =~ /^(\S+)\s+(.*)$/); if($line =~ /^※/) { #print "***line: $line\n"; ($note, $comment) = ($line =~ /^(..)\s*(.*)$/); } next if($note eq '' or $note eq '無印'); $comment =~ s/ //g; $comment =~ s/ //g; foreach my $k (keys %$pNoteHash) { if($pNoteHash->{$k} eq $comment) { my $key = $pNoteMarkOriginal->{$note}; $pNoteMark->{$note} = $key; $this->print("note0[$InFile]: $note [$key] $comment\n"); } } if(!defined $pNoteMark->{$note}) { $this->print("note1[$InFile]: $note [$$pMark] $comment\n"); $pNoteMark->{$note} = $$pMark; $pNoteMarkOriginal->{$note} = $$pMark; $pNoteHash->{$note} = $comment; if($$pMark eq 'Z') { $$pMark = 'a'; } else { $$pMark++; } if($$pMark =~ /[esp]/) { $$pMark++;; } } } return; } sub GetModifiedDate { my ($this, $FileName) = @_; my $in = new JFile; if(!$in->Open($FileName, "r")) { return ''; } my $line = $in->SkipTo("\\d{4}"); $in->Close(); $line = '' if(!defined $line); Jcode::convert(\$line, "sjis"); Utils::DelSpace($line); return $line; } sub WriteNotes { my ($this, $out) = @_; my @pNoteMark = $this->NoteMarkArray(); my %NoteMark = $this->pNoteMarkOriginal(); #NoteMark(0); my %NoteHash = $this->NoteHash(); $out->print(";備考データ\n"); #マークでソートするため、$pNoteMark[0]のKeyと値を入れ替えたハッシュを作る my %Reverse = Utils::RevertHash($pNoteMark[0]); foreach my $k (sort keys %Reverse) { my $n = $Reverse{$k}; my $s = $NoteHash{$n}; my $m = $pNoteMark[0]->{$n}; $out->print("$m:$s\n"); } $out->print("\n"); } sub MakeTimeTable { my ($this, $pInputFiles, $pDayKey, $OutputFile) = @_; $this->ReadAllNotes($pInputFiles); my $out = $this->OpenTableFile($OutputFile, "w"); return if(!defined $out); my $Title = $this->MakeTitleFromFileName($pInputFiles->[0]); my $ModifiedDate = $this->GetModifiedDate($pInputFiles->[0]); $out->print(";$Title \n"); #print("ModifiedDate: [$ModifiedDate]"); $out->print(";$ModifiedDate \n"); $out->print("\n"); $this->WriteNotes($out); my @pNoteMark = $this->NoteMarkArray(); my %NoteHash = $this->NoteHash(); for(my $i = 0 ; $i < @$pInputFiles ; $i++) { my $InFile = $pInputFiles->[$i]; my $DayKey = $pDayKey->[$i]; my %NoteMark = $this->NoteMark($i); $Title = $this->MakeTitleFromFileName($pInputFiles->[$i]); $out->print("$DayKey\n") if($DayKey ne ''); $out->print("#$Title\n"); my $in = $this->OpenTextFile($InFile, "r"); return if(!defined $in); my $line = $in->SkipTo("\\d{4}"); my $prevmin = -1; while(1) { $line = $in->SkipTo("\\d\\d"); last if($in->eof()); Utils::DelSpace($line); Jcode::convert(\$line, "sjis"); $line =~ s/ / /g; my ($time, $note) = Utils::Split("\\s+", $line); $this->print("$time: "); $out->printf("%02d:", $time); $prevmin = -1; while(1) { $line = $in->ReadLine(); $line =~ s/ / /g; Utils::DelSpace($line); last if($line eq ''); Jcode::convert(\$line, "sjis"); my ($note1, $min, $note2) = $this->SplitMinites($line); if($min eq '' or $min !~ /^\d+$/) { $min = $prevmin + 1; } $note = "$note1$note"; my $noteprev = $note; $note = $this->ConverteMark($note); $this->print(" ${min}[$noteprev-$note]"); $out->printf(" %s%02d", $note, $min); $note = $note2; $prevmin = $min; } $out->print("\n"); $this->print("\n"); } $out->print("\n"); $this->CloseTextFile(); } $this->CloseTableFile(); }