#!/afs/athena/contrib/perl/p

&inittricks;

while(<>){
    $blankline = 1 if /^\s*$/;	# Clear state for a blank line
#    print("{$state}<br>");

    if(/minutes of the sipb meeting/i){
	/^\s*(.+)\s*$/;
	print("<title>$1</title>\n");
	print("<h1>$1</h1>\n");
	$body = 1;
    }
    next unless $body;

    if($state eq 'attendance' && !$blankline){
	$attendance=1;
	s/,/ /g;
	if(/(.+):(.+)/){
	    $membertype = $1;
	    $memberlist = $2;

	    if($memberlist=~/\S/){
		print("\n<dt>$membertype\n");
		print("<dd>") ;
		&printmemberlist($memberlist);
	    }
	}
	else{
	    &printmemberlist($_);
	}
    }

    if(/in attendance were/i){
	$state = 'attendance';
	print("<h2>In attendance were</h2>\n");
	print("<dl>\n");
    }

    if($blankline && $attendance){
	print"</dl>\n" unless $dlended;

	$dlended=1;
	$state = 'reports';
    }
    if($state =~ /report/){
	if(/^\t([^\t\n]+):\s*$/ || /^       *([^\t\n]+):\s*$/ ||
	   /^([^\t\n]+):\s*$/){
	    print("<h2><a name=\"$1\">$1</a></h2>\n");
	    $reports=1;
	    $state = 'reportheader';
	}
	elsif($reports && $blankline){
	    print "<p>\n";
	}
	else{
	    $state = 'reporttext';
	    foreach $member (@people){
		s/\b($member)\b/<strong>$1<\/strong>/gi;
	    }
#	    s,(/afs/[^ \,]+[^\.\, ])([ \,]+),<a href="http://www.mit.edu:8001$1">$1</a>$2,g;
	    s,(/afs/[^ \,]+\b)([ \,]+),<a href="http://www.mit.edu:8001$1">$1</a>$2,g;

	    foreach $trick (@tricks){
		eval("\$_ =~ s/\\b$trick\\b/$treplace{$trick}/g");;
#		print(STDERR "Applying s/\\b$trick\\b/$treplace{$trick}/\n");
#		print(STDERR "to $_\n");
	    }

	    print $_;
	}
    }
    $blankline = 0;
}

sub printmemberlist{
    local($list) = @_;

    @members = split(/[ \t\n]+/, $list);
    for $mem (@members){
	next unless $mem;
	next if $mem eq '|';

	if($mem =~ /\@/){
	    print("$mem ");
	}
	else{
	    &printlinkname($mem);
	}
	push(@people, $mem);
    }
}

sub printlinkname{
    local($m) = @_;

    print("<a href=\"http://www.mit.edu:8001/home?$m\">$m</a> ");
}

sub inittricks{
   &addtrick('(i[A-Z\-][^ ]\+)', '<em>$1<\/em>');
   &addtrick('SIPB', '<a href=\"http:\/\/www.mit.edu:8001\/sipb\/sipb.html\">SIPB<\/a>');
   &addtrick('webster', '<a href=\"http:\/\/www.mit.edu:8001\/sipb\/office-manual\/webster.html\">webster<\/a>');
#   &addtrick('SIPB', 'DIPB');
}

sub addtrick {
    local($tname, $trickdo) = @_;

    push(@tricks, $tname);
    $treplace{$tname} = $trickdo;
}

# members
# office
# AFS
# machine?
# server?
# MIT
# deal?
# prospectives
# service
# cell?
# offline
# IS
# elections
# news
# web, www
# linux
# coke
# ultimate
# bylaws
# alumni
# jerk, sucks, bonehead, kill
# LSC
# MCC
# DCNS
# c64
# outland
# perl
# webmaster(s)
# matthew and jake, m&j
# RSN


