#!/usr/local/bin/perl5 # this is Perl, so don't expect any pretty coding. i'm exposing this # code so that next year's maintainer can exploit my work for his or # her lazy gain. # # Eric Tilton, tilt+@cs.cmu.edu, August/September of 1998 # Seth Copen Goldstein, seth@cs.cmu.edu, August of 1999 # Spiros Papadimitriou, spapadim@cs.cmu.edu, August of 1999 # require "links.pl"; $webDir = "/afs/cs/user/seth/public_html/IC99"; $numRows = 48; $headerFile = "header.html"; $footerFile = "footer.html"; $outFile = "sched.html"; if ($ARGV[0]) { $headerFile = "header-$ARGV[0].html"; $footerFile = "footer-$ARGV[0].html"; $outFile = "sched-$ARGV[0].html"; } # structure of day{}: # :{title,total,item#} # :title -- title of the day # :total -- total number of items # :item#:time -- time of the item # :item#:data -- data of the item sub readsched { local($sourceFile) = @_; open(SCHEDULE, $sourceFile); $day = 0; while() { chop; if (/^(.+\d) +WEEK/) { $title = $1; if ($prev_day =~ /Friday/ && $title !~ /Saturday/) { # add an empty saturday if needed $day++; $prev_day =~ /\w+, (\w+) (\d+)/; # this will BREAK if the friday is the end of the month. # happily, this is not my problem. $day{$day . ":title"} = "Saturday, " . $1 . " " . ($2 + 1); } $day++; $total_days = $day; # bogus compatibility hack $day{$day . ":title"} = $title; $prev_day = $title; $ignore = ; $count = 0; while (($item = ) && $item ne "\n") { chop($item); if ($item =~ /^\t\t(.*)/) { $day{$day . ":" . ($count - 1) . ":data"} .= " " . $1; next; } ($time, $data) = split("\t", $item); $day{$day . ":" . $count . ":time"} = $time; $day{$day . ":" . $count . ":data"} = $data; $count++; $day{$day . ":total"} = $count; } } } # add a trailing saturday if needed if ($prev_day =~ /Friday/) { $day++; $prev_day =~ /\w+, (\w+) (\d+)/; # this will BREAK if the friday is the end of the month. # happily, this is not my problem. $day{$day . ":title"} = "Saturday, " . $1 . " " . ($2 + 1); } close(SCHEDULE); } sub timetonum { # returns 9:00 as 0, 9:15 as 1, 9:30 as 2, etc. # ???? is -1. local($time, $index) = @_; local($hour, $minute, $result); if ($time =~ /\?/) { return(-1); } ($hour, $minute) = split(":", $time); if ($hour < 9) { # assume 1-8 is PM $hour += 12; } if ($index == 1 && $hour == 9 && $minute == 0) { # 9:00 in second half is probably 9pm $hour += 12; } $result = ($hour * 4 + ($minute / 15)) - 36; } sub convert { local($time) = @_; local(@time); local($begin, $end); $time =~ /([0-9:]+) - *([0-9:\?]+)/; $time[0] = $1; $time[1] = $2; $begin = &timetonum($time[0], 0); $end = &timetonum($time[1], 1); if (($end != -1) && ($end < $begin)) { # probably guessed wrong about am/pm $end=$end+12*4; } if ($end == -1) { # special case of time-unbounded parties $end=$begin+8; } if ($end > $numRows) { # special case of LONG events $end = $numRows; } return($begin, $end - $begin); } sub printsched { local ($webDir, $outFile, $headerFile, $footerFile) = @_; close(STDOUT); open(STDOUT, ">$webDir/$outFile"); &readlinks(); ## Header open(HEADER,$headerFile); while(
) { print; } ## Do that funky thing print("\n"); for ($start = 1; $start < $total_days; $start += 6) { local(%grid); local(@title); # generate a 6 day grid $earliest = 0; $latest = 0; for ($loop = $start; $loop < $start + 6; $loop++) { $title[$loop - $start] = $day{$loop . ":title"}; for ($loop2 = 0; $loop2 < $day{$loop . ":total"}; $loop2++) { ($begin, $length) = &convert($day{$loop . ":" . $loop2 . ":time"}); ## HACKS # shameless PG hack if ($day{$loop . ":" . $loop2 . ":data"} =~ /Pretty Good Race/ && $day{$loop . ":" . $loop2 . ":data"} !~ /Pretty Good Race TG/) { $length = 2; } # shameless labor day hack if ($day{$loop . ":" . $loop2 . ":time"} =~ /LABOR DAY/) { $begin = 2; $length = $numRows-12; } $scratch = $length . "\t" . $day{$loop . ":" . $loop2 . ":time"}; $scratch .= "\t" . $day{$loop . ":" . $loop2 . ":data"}; $grid{$loop - $start,$begin} = $scratch; for ($loop3 = $begin + 1; $loop3 < ($begin + $length); $loop3++) { $grid{$loop - $start,$loop3} = "XXX"; } if (($begin + $length) > $latest) { $latest = $begin + $length; } } } # output a 5 day grid $week = int(($start / 6) + 1); $last_week = int(($total_days / 6) + 1); if ($week == 1) { print "\n\n"; } if ($week == 2) { print "\n\n"; } if ($week == 3) { print "\n\n"; } print "\n"; } print "\n\n"; ## Footer print "\n\n"; print "
"; print "Week One"; if ($last_week > 1) { print " | Week Two"; } if ($last_week > 2) { print " | Week Three"; } print " | Top
"; print "Week One"; print " | Week Two"; if ($last_week > 2) { print " | Week Three"; } print " | Top
"; print "Week One"; print " | Week Two"; print " | Week Three"; print " | Top
\n"; print "\n"; local($title_temp); local($title_width); for ($loop = 0; $loop < 6; $loop++) { $title_temp = $title[$loop]; if ($title_temp =~ /Saturday/) { $title_width = "10%"; } else { $title_width = "16%"; } print "\n"; } print "\n"; for ($loop = $earliest; $loop < $latest; $loop++) { print "\n"; print ""; unless ($loop % 4) { print "\n"; } else { print "\n"; } local($entry_width); for ($loop2 = 0; $loop2 < 6; $loop2++) { if ($loop2 == 5) { $entry_width = "10%"; } else { $entry_width = "16%"; } if ($grid{$loop2, $loop} eq "XXX") { # print nothing } elsif ($grid{$loop2, $loop}) { ($length, $time, $data) = split("\t", $grid{$loop2, $loop}); print "\n"; } else { print ""; } } print "\n"; } print "
Time "; $title_temp =~ s/Monday/Mon/; $title_temp =~ s/Tuesday/Tue/; $title_temp =~ s/Wednesday/Wed/; $title_temp =~ s/Thursday/Thu/; $title_temp =~ s/Friday/Fri/; $title_temp =~ s/Saturday/Sat/; $title_temp =~ s/August/Aug/; $title_temp =~ s/September/Sep/; print $title_temp; print "
"; $hour = int(($loop / 4) + 9); if ($hour >= 12) { $meridian = "pm"; if ($hour > 12) { $hour -= 12; } } else { $meridian = "am"; } print "$hour:00 $meridian"; print " \n"; print "" . $time . "
\n"; $data = &addlinks($data); print $data; print "
 
"; print "Week One"; if ($last_week > 1) { print " | Week Two"; } if ($last_week > 2) { print " | Week Three"; } print " | Top

Last generated: "; require "ctime.pl"; print &ctime(time); print "
\n"; print "Seth Copen Goldstein <seth+\@cs.cmu.edu>

\n"; open(FOOTER,$footerFile); while(