= 6) {
            $sLine = substr($sLine,0,-1);  // drop newline
            switch($nLine++) {
                case 0:
                    $system = new SYSTEM;
                    $system->sName = substr($sLine,0,4);
                    $system->sAuthor = substr($sLine,4);
                    break;
                case 1:
                    $system->sSite = $sLine;
                    break;
                case 2:
                    $system->sURL = $sLine;
                    $g_systems[] = $system;
                    break;
            }
        } else $nLine = 0;
    }
    fclose($pfIn);
    $nSystems = count($g_systems);

$massey = "";
// RT #346765
$fpIn = @fopen($compare,"rb");
while (!@feof($fpIn)) {
  $massey .= @fread($fpIn, 8192);
  echo ".";
}
@fclose($fpIn);
echo "\nGot Massey comparison of ".strlen($massey)." bytes\n";

    $sLines = explode("\n",$massey);
    $nLines = count($sLines);
    $iLine = 0;
    while($iLine < $nLines) {
        $sLine = $sLines[$iLine++];
        if(!strncmp($sLine,"  

",6)) { $nEnd = strpos($sLine," ("); if($nEnd) { $sDate = substr($sLine,6,$nEnd-6); break; } } } while($iLine < $nLines) { $sLine = $sLines[$iLine++]; if(!strncmp($sLine,"",22)) { for($iSystem=0; $iSystem<$nSystems; $iSystem++) { $pLine = strpos($sLine,$g_systems[$iSystem]->sName,22); if($pLine) { $nSystemsFound++; $g_systems[$iSystem]->pRank = $pLine - 22; } else { echo $g_systems[$iSystem]->sName."not found\n"; } } $pTeam = strpos($sLine,"Rank, Team",22) - 22; break; } } echo sprintf("%d of %d systems found on Kenneth Massey's page for %s\n", $nSystemsFound,$nSystems,$sDate); if(!$nSystemsFound) die; if($nSystemsFound % 2) { $middle1 = $middle2 = ($nSystemsFound-1)/2; } else { $middle1 = $nSystemsFound/2; $middle2 = $middle1 - 1; } while($iLine < $nLines) { $sLine = $sLines[$iLine++]; if(!strncmp($sLine,"----------",10)) break; if(!strncmp($sLine,"",22)) continue; if(strlen($sLine)<60) continue; // remove <...> html tags from $sLine $pos = 0; $newLine = ''; while(($pos = strpos($sLine,'<')) !== FALSE) { $end = strpos($sLine,'>',$pos+2); $newLine .= substr($sLine,0,$pos); $sLine = substr($sLine,$end+1); } $sLine = $newLine . $sLine; $team = new TEAM; $team->sName = substr($sLine,$pTeam,16); $nRanks = array(); for($iSystem=0; $iSystem<$nSystems; $iSystem++) { $pRank = $g_systems[$iSystem]->pRank; if($pRank) { $nRank = substr($sLine,$pRank,3) + 0; if($nRank > 30 && count($g_teams) < 15) echo sprintf( "Suspicious ranking: %s ranks %s as #%d\n", $g_systems[$iSystem]->sAuthor,$team->sName,$nRank); if($nRank <= 30) $team->nTop30++; if($nRank <= 10) $team->nTop10++; if($nRank <= 5) $team->nTop5++; if($nRank <= 1) $team->nTop1++; $team->nSumRanks += $nRank; $nRanks[] = $nRank; } } sort($nRanks); $team->dMedian = ($nRanks[$middle1]+$nRanks[$middle2])*0.5; $g_teams[] = $team; } $pfOut = fopen("index.shtml","w"); $pfIn = fopen("start.htm","r"); while($sLine=fgets($pfIn)) { if(!strcmp($sLine,"DATE\n")) fprintf($pfOut,"%s (%d systems)\n", $sDate,$nSystemsFound); else if(!strcmp($sLine,"LIST\n")) { for($iSystem=0;$iSystem<$nSystems;$iSystem++) { fprintf($pfOut, "
  • %s - %s", $g_systems[$iSystem]->sURL,$g_systems[$iSystem]->sAuthor, $g_systems[$iSystem]->sSite); if(!$g_systems[$iSystem]->pRank) fputs($pfOut," Data missing"); fputs($pfOut,"
  • \n"); } } else fputs($pfOut,$sLine); } fclose($pfIn); $nTeams = count($g_teams); $dRatings = array(); for($iTeam=0; $iTeam<$nTeams; $iTeam++) { // calculate ratings $dRating = 101.0 - ($g_teams[$iTeam]->nSumRanks/(double)$nSystemsFound + $g_teams[$iTeam]->dMedian)/2.0; $dRatings[] = $dRating; } arsort($dRatings); $n = 0; foreach($dRatings as $iTeam=>$dRating) { if(($n < 30 || $iTeam < 30) && $n != $iTeam) echo $g_teams[$iTeam]->sName." moved from ".($iTeam+1)." to ". ($n+1)."\n"; $dAverage = $g_teams[$iTeam]->nSumRanks/(double)$nSystemsFound; fprintf($pfOut,"%4d %s%7.3f%9.3f%7.1f%6d%6d%5d%5d\n", ++$n,$g_teams[$iTeam]->sName, $dRating,$dAverage, $g_teams[$iTeam]->dMedian,$g_teams[$iTeam]->nTop30, $g_teams[$iTeam]->nTop10,$g_teams[$iTeam]->nTop5, $g_teams[$iTeam]->nTop1); } $pfIn = fopen("end.htm","r"); while($sLine=fgets($pfIn)) { if(!strcmp($sLine,"LIST\n")) { for($iSystem=0;$iSystem<$nSystems;$iSystem++) { fprintf($pfOut,"

    %s", $g_systems[$iSystem]->sSite); if(!$g_systems[$iSystem]->pRank) fputs($pfOut," Data missing"); fprintf($pfOut,"
    \n%s

    \n", $g_systems[$iSystem]->sURL); } } else fputs($pfOut,$sLine); } fclose($pfIn); fclose($pfOut); ?>