#!FOOPERL

#
# Copyright (c) Xerox Corporation 1997, 1998. All rights reserved.
#
# License is granted to copy, to use, and to make and to use derivative
# works, provided that Xerox is acknowledged in all documentation
# pertaining to any such copy or derivative work. Xerox grants no other
# licenses expressed or implied. The Xerox trade name should not be used
# in any advertising without its written permission.
#
# XEROX CORPORATION MAKES NO REPRESENTATIONS CONCERNING EITHER THE
# MERCHANTABILITY OF THIS SOFTWARE OR THE SUITABILITY OF THIS SOFTWARE
# FOR ANY PARTICULAR PURPOSE.  The software is provided "as is" without
# express or implied warranty of any kind.
#
# These notices must be retained in any copies of any part of this software.
#


# set this to the directory where the data is stored
$webdir = "FOOWEBDIR";
# set this to the name of the file where the data is stored
$datafile = "$webdir/route_stats";

require ("Fields.pl");
require ("Html.pl");


#----- main program ------
&declare_fields;
&init_fields;
&html_start("Multicast Routing Report");
&parse_input;
&file_open;
&start_table;
&table_header_time(4);
&table_header_fields(4);
&table_header_range(2);
&search_data;
&end_table;
&html_definitions;
&html_end;


# read in the stats for each known source and see if it matches the search
sub search_data {
   $match = 0;
   while($line = <DATAFILE>) {
      # check to see if we include this source in the output
      @array = split(" ",$line);
      $valid = &check_match;
      # if matched search paramters print a table line
      if ($valid == 1) {
         $result[$match] = $line;
         $match = $match + 1;
      }
   }
   @sorted = sort sortfield @result;
   for($j=0; $j < $match; $j++) {
      @array = split(" ",@sorted[$j]);
      print "<tr> <td align=left> $array[0]</td>"; #src left aligned
      for($i=1; $i < $special; $i++) {
         if ($use[$i] == 1) {
	    if ($i == 3) {
		# change date needs special handling...
		($psc,$pmn,$phr,$pdy,$pmo,$pyr,$pwd,$pyd,$pisd) = 
	          gmtime($array[$i]);
		$pmo = $pmo +1;
		$pdate = "$pmo/$pdy/$pyr,$phr:$pmn";
		print "<td align=center> $pdate </td>";
	    } else {
                print "<td align=center> $array[$i] </td>";
	    }
         }
      }
      for($i=$special; $i < $total; $i++) {
         if ($use[$i] == 1) {
            $myout = int($array[$i]);
            print "<td align=center> $myout </td>";
         }
      }
      print "</tr>\n";
   }
}

