#!/usr/local/bin/perl

# input:   a tab-delimited "phonelist"
# output:  an PRE(-formatted) table "phonepre.html"
#
# Rob Salgado (salgado@npac.syr.edu) 2 Jun 1995


open(OUT,">phonepre.html");
open(IN, "cat phonelist |") || die "phonelist missing\n";

print OUT "<HTML>\n";
print OUT "<H1>NPAC Phone List</H1>\n<HR>";


#### Not elegant...but it works.
#
# make a first pass to determine the column widths
#

FILE0:
while (<IN>) {
	chop $_;
	($name_last, $name_first, $phone, $login, $office) = split(/\t/,$_); 
  $l_name_last  = length($name_last)  if length($name_last)  > $l_name_last;
  $l_name_first = length($name_first) if length($name_first) > $l_name_first;
  $l_phone      = length($phone)      if length($phone)      > $l_phone;
  $l_login      = length($login)      if length($login)      > $l_login;
  $l_office     = length($office)     if length($office)     > $l_office;
	next FILE0;
}

# start over at the beginning and make the preformatted table
#

close(IN);
open(IN, "cat phonelist |") || die "phonelist missing\n";

print OUT "<PRE>\n";

    print OUT "Last Name", " " x ($l_name_last  - length("Last Name")),   " ";
    print OUT "First Name", " " x ($l_name_first - length("First Name")), "  ";
    print OUT "Ext",        " " x ($l_phone    - length("Ext")),  "  ";
    print OUT "Email Address"," " x ($l_login - length("Email Address")), "  ";
    print OUT "Office",       " " x ($l_office   - length("Office")),     "\n";
    print OUT "<HR>\n";


FILE:
while (<IN>) {
	chop $_;
	($name_last, $name_first, $phone, $login, $office) = split(/\t/,$_); 

    print OUT "$name_last", " " x ($l_name_last  - length($name_last)), " ";
    print OUT "$name_first"," " x ($l_name_first - length($name_first)),"  ";
    print OUT "$phone",     " " x ($l_phone      - length($phone)),     "  ";
    print OUT "$login",     " " x ($l_login      - length($login)),     "  ";
    print OUT "$office",    " " x ($l_office     - length($office)),    "\n";
	next FILE;
}
close(IN);

print OUT "</PRE>\n";
print OUT "<HR>\n";

print OUT "<DT> All phone extensions are <b><tt>(315)-443-xxxx</tt></b>.\n";
print OUT "<DT> All email addresses are <b><tt>@npac.syr.edu</tt></b> unless otherwise noted.<HR>\n";


#
# generate timestamps
#

open(UPDATE, "ls -l phonelist |") || die "phonelist missing\n";
while(<UPDATE>){
    chop $_;
    ($mod, $num, $owner, $size, $month, $date, $time, $name)=split(/\s+/,$_);
    print OUT "<I>Data last updated: $date $month <BR>\n";
}
close(UPDATE);

    require "ctime.pl";
    ($day, $month, $date, $time, $year)=split(/\s+/,&ctime(time));
    print OUT "Table generated: $date $month $year </I>\n";

print OUT "</HTML>\n";















