#! /usr/bin/perl

while(<DATA>) {  # read translation table
    s/\s+$//;
    last if /^column/;
    ($tag, $text) = (/^\s*(\S+)\s+(.*)/);
    $xlated{$text} = $tag if $text ne "";
    push(@tags, $tag);
}

$maxrow = 0;
@cols = ();

while(/column\s+(\S+)/) {
    my(@col);
    @col = ( $1 );

    while(<DATA>) {
	last if /column/;
	if(/option value="(\d+)">(.+)<\/option>/) {
	    my($code, $text) = ($1, $2);
	    if(defined($xlated{$text})) {
		$tag = $xlated{$text};
	    } else {
		print STDERR "\"xlate\" didn't list anything for \"$text\" (code $code)\n";
		$tag = $text;
	    }
	    push(@col, "<A HREF=\"http://www.cumtd.com/routeschedules/ByRoute.aspx?ID=$code\" title=\"$text\">$tag</A>");
	}
    }
    $maxrow = $#col if $maxrow < $#col;
    push(@cols, [ @col ]);
}


print <<EOF;
<HEAD><TITLE>C-U MTD Schedules</TITLE></HEAD>
<BODY>
<BASE HREF="http://www.cumtd.com/routeschedules/">
Here is a table of links for all bus routes run by the
<A HREF="http://www.cumtd.com/">Champaign-Urbana MTD http://www.cumtd.com/</A>
<BR>
These are links to the always-current CUMTD page for each route, not to copies of their pages.
Effectively this is a table of shortcuts around the two layers of menus on CUMTD's
<A HREF="http://www.cumtd.com/routeschedules/Default.aspx"><I>Routes and Schedules</I></A> page.
 -- <small><I>Stuart Levy</I></small>
<TABLE BORDER=1>
EOF

for($row = 0; $row <= $maxrow; $row++) {
    print "<TR>\n";
    foreach $cref (@cols) {
	print " <TD>${$cref}[$row]\n";
    }
}
print "</TABLE>\n";

__DATA__

1	1 Yellow
2N	2 Red Northbound
2S	2 Red Southbound
3N	3 Lavender Northbound
3S	3 Lavender Southbound
4E	4 Blue Eastbound
4W	4 Blue Westbound
5E	5 Green Eastbound
5W	5 Green Westbound
5Eexp	5 Green Express Eastbound
5Wexp	5 Green Express Westbound
6E	6 Orange Eastbound
6W	6 Orange Westbound
7E	7 Grey Eastbound
7W	7 Grey Westbound
8E	8 Bronze Eastbound
8W	8 Bronze Westbound
9A	9A Brown
9B	9B Brown
10	10 Gold
12	12 Teal
13	13 Silver
14E	14 Navy Eastbound
14W	14 Navy Westbound
15	15 Pink
20	20 Red
22	22 Illini
27	27 Air Bus
30	30 Lavender
50	50 Green
50E	50 Green East
50W	50 Green West
70E	70 Grey East
70W	70 Grey West
100	100 Yellow
100N	100 Yellow North
100S	100 Yellow South
120	120 Teal
130	130 Silver
150	150 Pink
220	220 Illini
270Air	270 Air Bus
280sport	280 tranSPORT
331NEDir	331 Northeast Direct
333SWDir	333 Southwest Direct
334WDir	334 West Direct
335Safe	335 SafeRides


column WkDay	weekday-day
	<option value="267">1 Yellow</option>
	<option value="138">2 Red Northbound</option>
	<option value="139">2 Red Southbound</option>
	<option value="140">3 Lavender Northbound</option>
	<option value="141">3 Lavender Southbound</option>
	<option value="142">4 Blue Eastbound</option>
	<option value="143">4 Blue Westbound</option>
	<option value="145">5 Green Eastbound</option>
	<option value="146">5 Green Westbound</option>
	<option value="148">5 Green Express Eastbound</option>
	<option value="149">5 Green Express Westbound</option>
	<option value="150">6 Orange Eastbound</option>
	<option value="151">6 Orange Westbound</option>
	<option value="152">7 Grey Eastbound</option>
	<option value="154">7 Grey Westbound</option>


column WkDay	weekday-day2
	<option value="155">8 Bronze Westbound</option>
	<option value="156">8 Bronze Eastbound</option>
	<option value="158">9A Brown</option>
	<option value="159">9B Brown</option>
	<option value="270">10 Gold</option>
	<option value="162">12 Teal</option>
	<option value="163">13 Silver</option>
	<option value="164">14 Navy Eastbound</option>
	<option value="165">14 Navy Westbound</option>
	<option value="166">15 Pink</option>
	<option value="266">22 Illini</option>
	<option value="171">27 Air Bus</option>
	<option value="172">331 Northeast Direct</option>
	<option value="173">334 West Direct</option>

column WkEve	weekday-eve
	<option value="178">50 Green East</option>
	<option value="176">50 Green West</option>
	<option value="180">70 Grey East</option>
	<option value="181">70 Grey West</option>
	<option value="182">100 Yellow North</option>
	<option value="183">100 Yellow South</option>
	<option value="185">120 Teal</option>
	<option value="187">130 Silver</option>
	<option value="256">150 Pink</option>
	<option value="263">220 Illini</option>
	<option value="234">331 Northeast Direct</option>
	<option value="235">333 Southwest Direct</option>
	<option value="236">335 SafeRides</option>

column WkLate	weekday-late
	<option value="177">50 Green East</option>
	<option value="179">50 Green West</option>
	<option value="184">100 Yellow</option>
	<option value="186">120 Teal</option>
	<option value="188">130 Silver</option>
	<option value="265">220 Illini</option>
	<option value="238">335 SafeRides</option>

column SatDay	saturday-day
	<option value="253">20 Red</option>
	<option value="255">30 Lavender</option>
	<option value="194">50 Green East</option>
	<option value="200">50 Green West</option>
	<option value="203">70 Grey East</option>
	<option value="205">70 Grey West</option>
	<option value="189">100 Yellow North</option>
	<option value="212">100 Yellow South</option>
	<option value="224">120 Teal</option>
	<option value="251">130 Silver</option>
	<option value="232">150 Pink</option>
	<option value="261">220 Illini</option>
	<option value="246">270 Air Bus</option>
	<option value="239">280 tranSPORT</option>
	<option value="247">331 Northeast Direct</option>
	<option value="241">333 Southwest Direct</option>

column SatEve	saturday-eve
	<option value="197">50 Green East</option>
	<option value="201">50 Green West</option>
	<option value="204">70 Grey East</option>
	<option value="206">70 Grey West</option>
	<option value="209">100 Yellow North</option>
	<option value="219">100 Yellow South</option>
	<option value="257">130 Silver</option>
	<option value="237">150 Pink</option>
	<option value="262">220 Illini</option>
	<option value="242">333 Southwest Direct</option>
	<option value="243">335 SafeRides</option>

column SatLate	saturday-late
	<option value="199">50 Green East</option>
	<option value="202">50 Green West</option>
	<option value="210">100 Yellow North</option>
	<option value="222">100 Yellow South</option>
	<option value="226">120 Teal</option>
	<option value="258">130 Silver</option>
	<option value="264">220 Illini</option>
	<option value="244">335 SafeRides</option>

column SunDay	sunday-day
	<option value="268">50 Green</option>
	<option value="211">70 Grey East</option>
	<option value="213">70 Grey West</option>
	<option value="214">100 Yellow North</option>
	<option value="216">100 Yellow South</option>
	<option value="220">120 Teal</option>
	<option value="230">130 Silver</option>
	<option value="240">150 Pink</option>
	<option value="252">220 Illini</option>
	<option value="245">270 Air Bus</option>
	<option value="248">331 Northeast Direct</option>
	<option value="249">333 Southwest Direct</option>

column SunLate	sunday-late
	<option value="269">50 Green</option>
	<option value="218">100 Yellow</option>
	<option value="221">120 Teal</option>
	<option value="259">130 Silver</option>
	<option value="254">220 Illini</option>
	<option value="250">335 SafeRides</option>
