#!/usr/local/bin/perl
require "/home/roger/lib/weblib.lib";
&htmlopen("Six Degrees of Separation|");
&ReadParse;
if($in{Name}){$name=$in{Name};}
while($return=&loaddata($name)){
	if($return > 0){
		@keep=@sixdegrees;
	}
}
if($name eq $sixdegrees[$#sixdegrees-1]){@keep=@sixdegrees;}
if($name){@sixdegrees=@keep;}
else{$name=$names[$#names];}
&htmlhead(1,"From TR to $name");
$|=1;
$connections=0;
	for($i=0;$i<=$#sixdegrees;$i+=2){
		print "<blockquote>\n";
		$star=$sixdegrees[$i];
		$explain=$sixdegrees[$i+1];
		print "$explain\n";
		$connections++;
		last if $star eq $name;
	}
print "</blockquote>"x$connections,"\n";
print "<form action=$weblib::URL method=POST>\n";
print "<select name=Name>\n";
print "<option>",join("\n<option>",sort bylastname @names),"\n";
print "</select><br>\n";
print "<input type=submit value=\"Show the Connection\">\n";
print "</form>\n";
print <<EOF;
<HR><FORM METHOD=POST
 ACTION=http://www.cs.virginia.edu/cgi-bin/cgiwrap?user=bct7m&script=star_links>
<TABLE bgcolor=GRAY cellpadding=2 border=1><TR><TD>
<INPUT TYPE=Submit VALUE=Link><INPUT TYPE=TEXT NAME=name1 VALUE="Rundgren, Todd"
 MAXLENGTH=100 SIZE=18>
to <INPUT TYPE=TEXT NAME=name2 VALUE="Last, First" MAXLENGTH=100 SIZE=18>
using <SELECT NAME=options>
<OPTION VALUE=movies>Movies Only
<OPTION VALUE=both SELECTED>Movies and TV
<OPTION VALUE=tv>TV Only</SELECT></TD></TR></TABLE></FORM>
EOF
&htmlclose;
sub loaddata{
	local($name)=shift;
	@sixdegrees=();
	$position=0;
	$returnvalue=-1;
	while(<DATA>){
		return 0 if /^EOF$/;
		last if /^EOD$/;
		chop;
		if($inexplain){
			if($_=~s/%//){
				$explain.=" $_";
				$inexplain=0;
				push(@sixdegrees,$explain);
			}
			else{$explain.=" $_";}
		}
		else{
			if($_=~s/^%//){
				$inexplain=1;
				$explain="";
				if($_=~s/%$//){
					$explain.=" " if $explain;
					$explain.=$_;
					$inexplain=0;
					push(@sixdegrees,$explain);
				}
				else{$explain.=$_;}
			}
			else{
				$position++;
				$returnvalue=$position if $name eq $_;
				push(@names,$_);
				push(@sixdegrees,$_);
			}
		}
	}
	return $returnvalue;
}
sub bylastname {
local(@aname)=split(/ /,$a);
local(@bname)=split(/ /,$b);
local($alast)=$aname[$#aname];
local($blast)=$bname[$#bname];
if($alast eq "Mugnaio"){$alast="Del Mugnaio"}
if($blast eq "Mugnaio"){$blast="Del Mugnaio"}
$alast." ".$a cmp $blast." ".$b;
}
__END__
Meat Loaf
%Todd Rundgren produced Meat Loaf's most successful album "Bat Out Of Hell"%
Tim Curry
%Meat Loaf was in the movie "Rocky Horror Picture Show" with Tim Curry%
EOD
Mark "Moogy" Klingman
%Todd Rundgren and Mark "Moogy" Klingman participated in many ventures, from Todd's first solo album to the original incarnation of Utopia.%
Jeff "Skunk" Baxter
%Mark "Moogy" Klingman and
Jeff "Skunk" Baxter
were musicians on Carly Simon's first album%
EOD
Warren Zevon
%Todd Rundgren introduced Warren Zevon when he appeared on the Midnight Special%
Linda Ronstadt
%Warren Zevon wrote several songs performed by Linda Ronstadt%
Rex Smith
%Linda Ronstadt sang opposite Rex Smith in "Pirates of Penzance."%
EOD
Roger Linder
%Todd Rundgren invited Roger Linder to be the on stage stenographer at the
Edge in Palo Alto during the Channel Surfing tour%
EOD
Ringo Starr
%Todd Rundgren played guitar in two incarnations of Ringo Starr's All-Starr
Band%
Paul McCartney
%Ringo Starr was in a band with Paul McCartney called The Beatles%
EOD
EOF
