#!/usr/bin/perl -w
sub parseTime {
# print "Parsing time @_\n";
#die;
my $timeStr = $_[0];
@timeArray = split(":", $timeStr);
# print STDERR "TimeArray: @timeArray\n";
return ($timeArray[0] + $timeArray[1]/60.0);
}
sub writeFlight {
print XMLFILE " \n";
print XMLFILE " $_[0]\n";
print XMLFILE " $_[1]\n";
print XMLFILE " $_[2]\n";
print XMLFILE " \n";
print XMLFILE " $_[3]\n";
if ($_[4] =~ /[0-6]/) { print XMLFILE " \n" }
else { print XMLFILE " \n" };
print XMLFILE " \n";
print XMLFILE " $_[6]\n";
print XMLFILE " \n";
print XMLFILE " $_[7]\n";
if ($_[8] =~ /[0-6]/) { print XMLFILE " \n" }
else { print XMLFILE " \n" };
print XMLFILE " \n";
if (($_[4] =~ /[0-6]/) && ($_[8] =~ /[0-6]/)) { print XMLFILE " WEEK\n" }
else { print XMLFILE " 24Hr\n" };
print XMLFILE " \n";
return;
}
@inputfiles = glob("???.conf");
while ($infile = shift(@inputfiles)) {
open (CONF, $infile) or die "Unable to open input configuration file";
($outname = $infile) =~ s/conf/xml/;
print "Opening $outname\n";
open XMLFILE, ">$outname";
while ($buf = readline(CONF)) {
push @DataList, $buf;
}
close (CONF);
print XMLFILE "\n";
print XMLFILE "\n";
while ($dataline = shift(@DataList)) {
# print STDERR "Dataline: $dataline\n";
@token = split(" ", $dataline);
if (scalar(@token) > 0) {
# print STDERR "Token: @token\n";
if ($token[0] eq "AC")
{
print XMLFILE " \n";
print XMLFILE " $token[12]\n";
print XMLFILE " $token[6]\n";
print XMLFILE " $token[5]\n";
print XMLFILE " $token[1]\n";
print XMLFILE " $token[3]$token[5]\n";
print XMLFILE " $token[4]\n";
print XMLFILE " $token[7]\n";
print XMLFILE " $token[8]\n";
print XMLFILE " $token[9]\n";
print XMLFILE " $token[10]\n";
print XMLFILE " $token[2]\n";
print XMLFILE " $token[11]\n";
print XMLFILE " \n";
}
if ($token[0] eq "FLIGHT") {
$weekdays = $token[3];
if (!(($weekdays =~ /^(0|\.)?(1|\.)?(2|\.)?(3|\.)?(4|\.)?(5|\.)?(6|\.)?$/) || ($weekdays eq "DAILY"))) {
die "Syntax Error! Check days $weekdays for flight no. $token[1]!\n";
}
if ($token[4] !~ /^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])$/) {
die "Syntax Error! Check departure time $token[4] for flight no. $token[1]!\n"
}
if ($token[6] !~ /^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])$/) {
die "Syntax Error! Check arrival time $token[6] for flight no. $token[1]!\n"
}
# print STDERR "Weekdays: $weekdays\n";
if ($weekdays =~ /^(0|\.)?(1|\.)?(2|\.)?(3|\.)?(4|\.)?(5|\.)?(6|\.)?$/) {
# print STDERR "Weekly for flight no. $token[1]\n";
# print STDERR "Day: $_\n";
@day = split(//, $weekdays);
foreach (@day) {
if ($_ eq "\.") {
next;
} else {
$depTime = parseTime($token[4]);
# print STDERR "depTime: $depTime\n";
$arrTime = parseTime($token[6]);
# print STDERR "arrTime: $arrTime\n";
$depDay = $_ + 1;
if ($depDay > 6) { $depDay = 0 };
$arrDay = $depDay;
if ($depTime > $arrTime) { $arrDay++ };
if ($arrDay > 6) { $arrDay = 0 };
# print STDERR "depDay: $depDay, arrDay: $arrDay\n";
writeFlight ($token[1], $token[9], $token[2], $token[5], $depDay, $token[4], $token[8], $token[7], $arrDay, $token[6]);
}
}
}
elsif ($weekdays eq "DAILY") {
# print STDERR "Daily flights for flight no. $token[1]\n";
$depTime = parseTime($token[4]);
$arrTime = parseTime($token[6]);
writeFlight ($token[1], $token[9], $token[2], $token[5], 7, $token[4], $token[8], $token[7], 7, $token[6]);
}
else {
die "System Error! Can't find days to place a flight!\n";
}
}
}
}
print XMLFILE "\n";
close XMLFILE;
# print "Closing $outname\n";
}