function getSummary($tree, $id, $type) { if ($type != "starred" && $type != "notstarred" && $type != "reftest") { die("invalid type passed to getSummary"); } $reftest = $type == "reftest"; $starred = $type == "starred"; $file = "../summaries/" . $tree . "_" . $id . "_" . $type; if (file_exists($file)) { return file_get_contents($file); } $host = "tinderbox.mozilla.org"; $page = "/showlog.cgi?log=" . $tree . "/" . $id; // . 1233853948.1233859186.27458.gz"; $fp = fsockopen($host, 80, $errno, $errdesc); if (!$fp) { return "Couldn't connect to {$host}:\nError: {$errno}\nDesc: {$errdesc}\n"; } $request = "GET {$page} HTTP/1.0\r\n"; $request .= "Host: {$host}\r\n"; $request .= "User-Agent: PHP test client\r\n\r\n"; $lines = array(); fputs($fp, $request); stream_set_timeout($fp, 20); stream_set_blocking($fp, 0); $foundSummaryStart = false; $foundLogStart = false; $fileExistedAfterAll = false; $isStillRunning = false; global $signature; $signature = ""; while (!feof($fp)) { if (file_exists($file)) { $fileExistedAfterAll = true; break; } $line = fgets_whole_line($fp); if ($line != "") { if (!$foundSummaryStart && !$foundLogStart) { if (preg_match("/Build Error Summary.*Build Error Log.*No More Errors/i", $line)) { $isStillRunning = true; break; } if (preg_match("/Build Error Summary.*Build Error Log/i", $line)) { // Summary is empty. break; } } if ($reftest) { if (!$foundLogStart) { if (preg_match("/Build Error Log.*<PRE>(.*)\$/i", $line, $m)) { $line = $m[0] . "\n"; $foundLogStart = true; } else { continue; } } if (preg_match("/(REFTEST (?:TEST-UNEXPECTED| *IMAGE|number of).*)/", $line, $m)) { $line = $m[0] . "\n"; $line = strip_tags($line); $lines[] = $line; } } else { if (!$foundSummaryStart) { if (preg_match_all("/Build Error Summary.*<PRE>(.*)\$/i", $line, $m)) { $foundSummaryStart = true; $line = $m[1][0] . "\n"; $line = strip_tags($line); $lines[] = $line; if (!$starred) { processLine($lines, $line); } } if (strlen($signature) == 0 && preg_match("#<b>(.*\\d{4}/\\d{2}/\\d{2} \\d{2}:\\d{2}:\\d{2})</b>#i", $line, $matches)) { $signature = $matches[1]; } } else { if (preg_match("/Build Error Log/i", $line)) { break; } $line = strip_tags($line); $lines[] = $line; if (!$starred) { processLine($lines, $line); } } } } else { usleep(80 * 1000); } } fclose($fp); $summary = $fileExistedAfterAll ? file_get_contents($file) : implode($lines); if (!file_exists($file) && !$isStillRunning) { file_put_contents($file, $summary); } return $summary; }
function processLines($data) { global $ignores; $hash=array(); $data=str_replace("\r", '', $data); $lines=explode("\n", $data); $total=count($lines); for($i=0;$i<$total;$i++) { processLine($lines[$i], $hash); } return $total; }
//$currentLevel = -1; //Holds info about incompleted squares $captures = array(); if ($handle) { $buffer = fgets($handle, 4096); //read in row and columns lengths $rowsColumns = explode(" ", trim($buffer)); $numberRows = $rowsColumns[0]; $numberColumns = $rowsColumns[1]; echo "Number of Rows: {$numberRows} \nNumber of Columns: {$numberColumns}\n"; //while(($buffer = fgets($handle, 4096)) !== false) { for ($rowIndex = 0; $rowIndex < $numberRows; $rowIndex += 1) { $buffer = fgets($handle, 4096); //print_r(str_split($buffer)); $currentLevel = -1; processLine(str_split($buffer), $currentLevel, $captures, $numberColumns, $rowIndex, $numberRows); echo "\n"; } // echo "\n"; // print_r($captures); fclose($handle); } else { echo "{$filename} could not be opened!\n"; } //Read each character in line from left to right: //If a + is encountered store this in array //every time we encounter a | we need to check if this ends or begins a square and adjust level accordingly //how to know if | is end or beginning? check if it's related + (closest one above it) function processLine($line, &$currentLevel, &$captures, $numColumns, $currentRow, $numberRows) { $cornerExists = false;