#!/usr/local/bin/perl # # # Keio Line Time Table Converter # Version 1.2 # Copyritht (c) 1999 IWAMA Naozumi # # This script was written in SJIS originaly and # tested on jperl version 4 (WIN32.Pentium, SJIS). # You may run on perl 5 in EUC. # # This software is absolutely no warranty! $tablel = 0; # Nesting level of table. $tablel1c = 0; # Counter of nesting level 1 table # The time table is the second one. $titlef = 0; # Flag for $trf = 0; # Flag for <TR> $tdf = 0; # Flag for <TD> $bf = 0; # Flag for <B> $commentf = 0; # Flag for <!-- $inokashiraf = 0; # Flag for Inokashira Line $sunholf = 0; # Flag for Sunday & Holiday $satf = 0; # Flag for Saturday # Main loop while (<>) { chop; &processline; } # Print general data sub printdata { print "\n;備考データ\n"; print "S:特急\n"; print "E:急行\n"; print "F:急行(不定期)\n"; print "K:快速\n"; print "T:通快\n"; print "t:つつじヶ丘\n"; print "c:調布\n"; print "f:府中\n"; print "u:府中競馬場正門前\n"; print "d:高幡不動\n"; print "y:高尾山口\n"; print "w:若葉台\n"; print "s:京王多摩センター\n"; print "h:橋本\n"; print "o:大島\n"; print "i:岩本町\n"; print "z:笹塚\n"; print "j:桜上水\n"; print "n:新線新宿\n"; print "p:多摩動物公園\n"; print "m:本八幡\n"; print "e:東府中\n"; print "k:北野\n"; print "g:富士見ヶ丘\n"; if ($satf == 1) { print "[SAT]"; } if ($sunholf == 1) { print "[SUN][HOL]"; } # Print table title print "\n#" . $title . "\n"; } # Transfer symbols sub transsym { $sym =~ (s/●/S/); $sym =~ (s/○/E/); $sym =~ (s/□/F/); $sym =~ (s/▲/K/); $sym =~ (s/△/T/); $sym =~ (s/ //); # Zenkaku Space $sym =~ (s/ツ/t/); $sym =~ (s/チ/c/); $sym =~ (s/ケ/u/); $sym =~ (s/タ/d/); $sym =~ (s/ヤ/y/); $sym =~ (s/ワ/w/); $sym =~ (s/セ/s/); $sym =~ (s/ハ/h/); $sym =~ (s/オ/o/); $sym =~ (s/イ/i/); $sym =~ (s/サ/z/); $sym =~ (s/さ/j/); $sym =~ (s/シ/n/); $sym =~ (s/ト/p/); $sym =~ (s/モ/m/); $sym =~ (s/ヒ/e/); $sym =~ (s/キ/k/); if ($inokashiraf == 1) { $sym =~ (s/フ/g/); } else { $sym =~ (s/フ/f/); } } # Process tag with parameter(s) sub tagparam { if ($a =~ (/^\s*\<TD/)) { # <TD PRAM> print " "; $tdf = 1; } elsif ($a =~ (/^\s*\<TABLE/)) { # <TABLE PRAM> $tablel = $tablel + 1; if ($tablel == 1) { $tablel1c = $tablel1c + 1; } } } # Process tag sub tag { if ($a =~ (/^\s*\<TITLE\>/)) { # <TITLE> print ";"; $titlef = 1; } elsif ($a =~ (/^\s*\<TABLE\>/)) { $tablel = $tablel + 1; if ($tablel == 1) { $tablel1c = $tablel1c + 1; } } elsif ($a =~ (/^\s*\<TR\>/)) { # <TR> if ($tablel > 0) { $trf = $trf + 1; } } elsif ($a =~ (/^\s*\<TD\>/)) { # <TD> $tdf = 1; } elsif ($a =~ (/^\s*\<B\>/)) { # <B> $bf = 1; } } sub endtag { if ($a =~ (/^\s*\<\/TITLE\>/)) { # &printdata; $titlef = 0; } elsif ($a =~ (/^\s*\<\/TABLE\>/)) { $tablel = $tablel - 1; if ($tablel < 0) { } } elsif ($a =~ (/^\s*\<\/TR\>/)) { # if ($tablel > 0) { $trf = $trf - 1; } } elsif ($a =~ (/^\s*\<\/TD\>/)) { # $tdf = 0; } elsif ($a =~ (/^\s*\<\/B\>/)) { # $bf = 0; } } # Process a line sub processline { while (! /^$/) { if (s/^\s*\<\/\w+\>//) { # $a = $&; &endtag; } elsif (s/^\s*\<\w+\>//) { # $a = $&; &tag; } elsif (s/^\s*\<(\w+)\s+(([^\>]|\\\>)*)\>//) { # $a = $&; &tagparam; } elsif (s/^\s*\<\!\-\-//) { # comment begin # $commentf = 0; } elsif (s/^\s*([^\<]*)\foo print $1; $title = $a = $1; # Check info. if ($a =~ (/井の頭/)) { $inokashiraf = 1; } if ($a =~ (/休日/)) { $sunholf = 1; } if ($a =~ (/土/)) { $satf = 1; } } elsif ($tablel1c == 2) { # The time table is the second one. if ($bf == 1) { # Print an hour element of the time table print "\n" . $1 . ": "; } else { # Print a minute element of the time table $sym = $1; &transsym; print $sym; } } } else { (s/(^.*)//); # Print the rest of line (which contains no tag) if (($tablel1c == 2) && ($tdf > 0) && ($commentf == 0)) { # Print minute element of the time table $sym = $1; &transsym; print $sym; } else { # Other comment if ($commentf == 0) { print "\n" . ";" . $& . "\n"; } } } } }