#============================================================ # NextTrain #============================================================ package NextTrain; use Exporter; use Common; @ISA = qw(Exporter Common); 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 Zen2Han { my ($str) = @_; Jcode::convert(\$str, "sjis"); $str =~ s/0/0/g; $str =~ s/1/1/g; $str =~ s/2/2/g; $str =~ s/3/3/g; $str =~ s/4/4/g; $str =~ s/5/5/g; $str =~ s/6/6/g; $str =~ s/7/7/g; $str =~ s/8/8/g; $str =~ s/9/9/g; return $str; } #=============================================== # 変数取得関数 #=============================================== #.tblファイルに書き込む際のコメントへのマーク sub Mark { return shift->{Mark}; } sub pMark { return \(shift->{Mark}); }; #.txtファイルのマークと.tblファイルへ書き込む際のマークの対応のハッシュ配列 sub pNoteMarkArray { return shift->{pNoteMarkArray}; } sub NoteMarkArray { my $pNoteMarkArray = shift->pNoteMarkArray(); return @$pNoteMarkArray; } #全部の.txtファイルのマークと.tblファイルへ書き込む際のマークの対応を記録したハッシュ sub pNoteMarkOriginal { return shift->pNoteMarkArray()->[0]; } #$idx晩目の.txtファイルのマークと.tblファイルへ書き込む際のマークの対応を記録したハッシュ sub pNoteMark { my ($this, $idx) = @_; my $p = $this->pNoteMarkArray()->[$idx]; if(!$p) { $this->pNoteMarkArray()->[$idx] = {}; } return $this->pNoteMarkArray()->[$idx]; } sub NoteMark { my ($this, $idx) = @_; my $pNoteMark = $this->pNoteMark($idx); return %$pNoteMark; } #$idx晩目の.txtファイルのマークと.tblファイルへ書き込む際のコメントの対応を記録したハッシュ sub pNoteHash { return shift->{pNoteHash}; } sub NoteHash { my $pNoteHash = shift->pNoteHash(); return %$pNoteHash; } #=============================================== # 一般メンバー関数 #=============================================== sub InitializeNotes { my ($this) = @_; $this->{Mark} = 'A'; $this->{pNoteMarkArray} = []; $this->{pNoteHash} = {}; $this->{pNoteMarkArray}[0] = {}; } sub ConverteMark { my ($this, $note) = @_; my $pNoteMarkArray = $this->{pNoteMarkArray}; my $pNoteMark = $pNoteMarkArray->[0]; my $newnote = ''; for(my $i = 0 ; $note ne '' ; $i++) { #print "\nnew[$i/$note]: $newnote\n"; if($note =~ /^[a-zA-Z][0-9]/) { my ($c, $s) = ($note =~ /^(..)(.*)$/); my $c2 = $pNoteMark->{$c}; #print "c:$c s:$s c2:$c2\n"; $newnote .= $c2; $note = $s; next; } elsif($note =~ /^[a-zA-Z]/) { my ($c, $s) = ($note =~ /^(.)(.*)$/); my $c2 = $pNoteMark->{$c}; #print "c:$c s:$s c2:$c2\n"; $newnote .= $c2; $note = $s; next; } elsif($note =~ /^\[/) { my ($c, $s) = ($note =~ /^(\[.*?\])(.*)$/); if($c) { my $c2 = $pNoteMark->{$c}; $newnote .= $c2; $note = $s; next; } } my ($c, $s) = ($note =~ /^(..)(.*)$/); my $c2 = $pNoteMark->{$c}; #print "c:$c s:$s c2:$c2\n"; $newnote .= $c2; $note = $s; } #print "new[l/$note]: $newnote\n"; return $newnote; } sub OpenTableFile { my ($this, $path, $mode) = @_; $this->CloseTableFile(); my $out = new JFile; if(!$out->Open($path, $mode)) { $this->print("Error: Can not write to [$path].\n") if($mode =~ /w/i); $this->print("Error: Can not read [$path].\n") if($mode =~ /r/i); return undef; } $this->{HandleTableFile} = $out; return $out; } sub CloseTableFile { my ($this) = @_; if($this->{HandleTableFile}) { $this->{HandleTableFile}->Close(); delete $this->{HandleTableFile}; } } sub OpenTextFile { my ($this, $path, $mode) = @_; $this->CloseTextFile(); my $in = new JFile; if(!$in->Open($path, $mode)) { $this->print("Error: Can not write to [$path].\n") if($mode =~ /w/i); $this->print("Error: Can not read [$path].\n") if($mode =~ /r/i); return undef; } $this->{HandleTextFile} = $in; return $in; } sub CloseTextFile { my ($this) = @_; if($this->{HandleTextFile}) { $this->{HandleTextFile}->Close(); delete $this->{HandleTextFile}; } } sub MakeTitleFromFileName { my ($this, $FileName) = @_; $FileName =~ s/(\.[^\.]*)?$//; return $FileName; }