2 /*-------------------------------------------------------------------------
3 snap.php - snapshot builds page
5 Copyright (C) 2011, Borut Razem <borut.razem AT gmail.com>
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2.1, or (at your option) any
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this library; see the file COPYING. If not, write to the
19 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
21 -------------------------------------------------------------------------*/
28 public function dump()
34 public function __construct()
36 $this->root
= array("files" => array(), "name" => "/");
37 $this->curdir
= &$this->root
;
41 public function chDir($path, $relative = false)
44 $cur = &$this->curdir
;
50 $cur = &$this->travel($cur, $path);
53 $this->curdir
= &$cur;
62 public function mkDir($path, $relative = false)
65 $cur = &$this->curdir
;
71 $this->travel($cur, $path, true);
75 protected function _exists($dir, $path)
77 return array_key_exists($path, $dir["files"]);
81 public function exists($path)
83 return $this->_exists($this->curdir
, $path);
87 protected function _isDir($dir, $path)
89 return $this->_exists($dir, $path) && array_key_exists("files", $dir["files"][$path]);
93 public function isDir($path)
95 return $this->_isDir($this->curdir
, $path);
99 protected function _pwd(&$res, &$dir)
101 foreach (array_keys($dir["files"]) as $file) {
102 if ($this->_isDir($dir, $file)) {
103 if ($this->_pwd($res1, $dir["files"][$file]))
104 $res .= $file . "/" . $res1;
114 public function pwd()
116 if ($this->_pwd($res, $this->root
)) {
125 public function add($path, $attr)
127 if ($this->exists($path)) {
130 $this->curdir
["files"][$path] = $attr;
134 public function getAttr($path)
136 if (!$this->exists($path)) {
139 return $this->curdir
["files"][$path];
143 public function entries()
145 return array_keys($this->curdir
["files"]);
149 protected function &travel(&$cur, $path, $create = false)
151 if (!is_array($path)) {
155 $path = preg_split("/\/+/", preg_replace("|^/*(.*)/*$|", "$1", $path));
158 foreach($path as $file) {
159 if (!$this->_exists($cur, $file)) {
161 $cur["files"][$file] = array("files" => array(), "name" => $file);
167 if ($this->_isDir($cur, $file)) {
168 $cur = &$cur["files"][$file];
179 function green_bar($text, $name)
181 echo "<h2><a name=\"" . $name . "\"></a>" . $text . "</h2>\n";
184 function file_name_to_snapshot_id($fname)
186 $ret = preg_replace('/sdcc-snapshot-([^-]+-[^-]+-[^ ]+-\d{8}-\d+)\..*/', '$1', $fname);
187 if ($ret === $fname) {
188 $ret = preg_replace('/sdcc-snapshot-([^-]+-[^ ]+-\d{8}-\d+)\..*/', '$1', $fname);
190 $ret = preg_replace('/.*-([^-]+-[^-]+-[^ ]+-\d{8}-\d+)\..*/', '$1', $fname);
196 function file_name_to_revision($fname)
198 return preg_replace('/.*-\d{8}-(\d+).*/', '$1', $fname);
201 function rt_failed($fname)
203 if ($handle = fopen($fname, "r")) {
204 while ($line = fgets($handle)) {
205 # Summary for 'host': 0 failures, 4244 tests, 596 test cases, 0 bytes, 0 ticks
206 if (preg_match('/^Summary/', $line)) {
207 $failures = preg_replace('/^Summary for \'.+\':.* (\d+) failures, \d+ tests, \d+ test cases, \d+ bytes, \d+ ticks/',
209 if ($failures && $failures > 0)
212 if (preg_match('/Error/', $line) ||
preg_match('/invalid instructions/', $line))
222 function display_files($descdir, $lsDir, $cldir, $rtdir, $subdir)
225 $lsDir->chDir($subdir);
227 foreach ($lsDir->entries() as $file) {
228 if ($file != "HEADER.html" && $file != ".htaccess") {
229 $attr = $lsDir->getAttr($file);
230 $file_name[$numfiles] = $file;
231 $file_size[$numfiles] = $attr["size"];
232 $file_date[$numfiles] = $attr["date"];
236 # dates are in text format, so the sort is not working as expected
237 # files seems to be already sorted by the date in tree.txe, so additional sorting is not needed!
238 #if ($numfiles > 0) {
239 # array_multisort($file_date, SORT_DESC, $file_name, $file_size);
242 echo "<p><img src=\"/images/folder-B4-6-32x32.png\" border=\"0\" align=\"bottom\" alt=\"Folder\" />";
243 echo "<font face=\"Arial,Helvetica,Geneva,Swiss,SunSans-Regular\"><b><i>";
244 if (is_file($descdir. "/" . $subdir . ".desc")) {
245 include $descdir. "/" . $subdir . ".desc";
247 echo "($subdir)</i></b></font></p>\n";
248 echo "<div style=\"padding-left: 2em\">\n";
249 echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\"><tr>";
250 echo "<th align=\"left\"><font color=\"#660000\" face=\"Arial,Helvetica,Geneva,Swiss,SunSans-Regular\">Filename</font></th>";
251 echo "<th align=\"left\"><font color=\"#660000\" face=\"Arial,Helvetica,Geneva,Swiss,SunSans-Regular\">Size</font></th>";
252 echo "<th align=\"left\"><font color=\"#660000\" face=\"Arial,Helvetica,Geneva,Swiss,SunSans-Regular\">Snapshot Date</font></th>";
254 echo "<th align=\"left\"><font color=\"#660000\" face=\"Arial,Helvetica,Geneva,Swiss,SunSans-Regular\">CL</font></th>";
256 echo "<th align=\"left\"><font color=\"#660000\" face=\"Arial,Helvetica,Geneva,Swiss,SunSans-Regular\">RT</font></th>";
259 # set the default timezone to use. Available since PHP 5.1
260 date_default_timezone_set("UTC");
262 for ($i = 0; $i < $numfiles; ++
$i) {
263 $fs = round($file_size[$i] / 1024, 0);
264 $subdirpp = preg_replace("/\s/","%20","$subdir");
265 $filep = preg_replace("/\s/","%20",$file_name[$i]);
266 #$modDate = date("M j H:i T", $file_date[$i]);
267 $modDate = $file_date[$i];
272 $clpath = $cldir . '/changelog-head-' . file_name_to_revision($file_name[$i]) . '.txt';
273 if (is_file($clpath)) {
274 $clpathp = preg_replace("/\s/", "%20", $clpath);
275 $clIcon = '18dot5a.gif';
276 $cl = "<a href=\"$clpathp\"><img src=\"/images/$clIcon\" border=\"0\" alt=\"ChangeLog Head\" /></a>";
283 $rtpath = $rtdir . '/' . $subdir . '/regression-test-' . file_name_to_snapshot_id($file_name[$i]) . '.log';
284 if (is_file($rtpath)) {
285 $rtpathp = preg_replace("/\s/", "%20", $rtpath);
286 $failed = rt_failed($rtpathp);
288 $rtIcon = $failed ?
'18dot1a.gif' : '18dot4a.gif';
290 $rtIcon = '18dot2a.gif';
291 $rt = "<a href=\"$rtpathp\"><img src=\"/images/$rtIcon\" border=\"0\" alt=\"Regression Test Log\" /></a>";
295 $dispthisdir = "<tr>" .
296 "<td align=\"left\"><a href=\"http://sourceforge.net/projects/sdcc/files/snapshot_builds/$subdirpp/$filep/download\">$file_name[$i]</a></td>" .
297 "<td align=\"left\">$fs K</td>" .
298 "<td align=\"left\">$modDate</td>" .
299 "<td align=\"left\">$cl</td>" .
300 "<td align=\"left\">$rt</td>".
305 echo "</table></div>\n";
309 function line2stat($line)
311 $res = preg_split("/\s+/", $line, 9);
312 $path = explode('/', $res[8], 2);
313 if ($path[1] != "") {
314 $path[0] = $path[1] . '/' . $path[0];
316 return array($path[0], substr($res[0], 0, 1), array("size" => $res[4], "date" => $res[5] . " " . $res[6] . " " . $res[7]));
320 function &tree_array($file)
322 $lsDir = new LsDir();
324 foreach (file($file) as $line) {
325 $stat = line2stat(rtrim($line));
329 if (!$lsDir->isDir($file)) {
330 $lsDir->mkDir($file);
332 $lsDir->chDir($file);
335 $lsDir->add($file, $stat[2]);
343 function parse_dir($descdir, $scanthis, $cldir, $rtdir)
345 $linux_num = $windows_num = $windows64_num = $macosx_num = $docs_num = $other_docs_num = $source_num = $other_num = 0;
347 $lsDir = tree_array($scanthis);
350 foreach ($lsDir->entries() as $file) {
351 if ($lsDir->isDir($file)) {
352 if (preg_match('/(i386|amd64)-.*-linux/', $file)) {
353 $linux_dir[$linux_num++
] = $file;
355 elseif (preg_match('/msvc/', $file)) {
356 $windows_dir[$windows_num++
] = $file;
358 elseif (preg_match('/x86_64-w64/', $file)) {
359 $windows64_dir[$windows64_num++
] = $file;
361 elseif (preg_match('/macosx/', $file)) {
362 $macosx_dir[$macosx_num++
] = $file;
364 elseif (preg_match('/docs$/', $file)) {
365 $docs_dir[$docs_num++
] = $file;
367 elseif (preg_match('/docs_/', $file)) {
368 $other_docs_dir[$other_docs_num++
] = $file;
370 elseif (preg_match('/-src/', $file)) {
371 $source_dir[$source_num++
] = $file;
374 $other_dir[$other_num++
] = $file;
379 green_bar("Supported Linux Binaries", "Linux");
380 for ($i = 0; $i < $linux_num; $i++
) {
381 display_files($descdir, $lsDir, $cldir, $rtdir, $linux_dir[$i]);
384 green_bar("Supported Windows - x86 Binaries", "Windows32");
385 for ($i = 0; $i < $windows_num; $i++
) {
386 display_files($descdir, $lsDir, $cldir, $rtdir, $windows_dir[$i]);
389 green_bar("Supported Windows - x86_64 Binaries", "Windows64");
390 for ($i = 0; $i < $windows64_num; $i++
) {
391 display_files($descdir, $lsDir, $cldir, $rtdir, $windows64_dir[$i]);
394 green_bar("Supported Mac OS X Binaries", "MacOSX");
395 for ($i = 0; $i < $macosx_num; $i++
) {
396 display_files($descdir, $lsDir, $cldir, $rtdir, $macosx_dir[$i]);
399 green_bar("Documentation", "Docs");
400 for ($i = 0; $i < $docs_num; $i++
) {
401 display_files($descdir, $lsDir, $cldir, false, $docs_dir[$i]);
403 for ($i = 0; $i < $other_docs_num; $i++
) {
404 display_files($descdir, $lsDir, false, false, $other_docs_dir[$i]);
407 green_bar("Source Code", "Source");
408 for ($i = 0; $i < $source_num; $i++
) {
409 display_files($descdir, $lsDir, $cldir, false, $source_dir[$i]);
412 if ($other_num > 0) green_bar("Other Files", "Other");
413 for ($i = 0; $i < $other_num; $i++
) {
414 display_files($descdir, $lsDir, $cldir, $rtdir, $other_dir[$i]);
416 }//end-function declaration
418 require 'snap_header.php';
420 parse_dir('snapshots.desc', 'tree.txt', 'changelog_heads', 'regression_test_results');
422 require 'snap_footer.php';