", Array( "" => "", ... )) // Note that the result may contain several versions of the same package function parse_packages( $filename ) { $lines = (strpos($filename, ".gz") !== False) ? gzfile($filename) : file($filename); $i = -1; $curtag = false; $newtag = true; $value = ""; $res = Array(); foreach( $lines as $line ) { $matches = Array(); if ( preg_match("/^([^ ]*):( )?(.*)$/", $line, $matches) ) { if ( $curtag !== false && $i >= 0 ) $res[$i][1][$curtag] = $value; $curtag = $matches[1]; $value = $matches[3]; if ( $curtag == "Package" ) $res[++$i] = Array(0 => $value, 1 => Array()); $newtag = true; } else { if ( trim($line) !== "." ) { if ( $newtag || substr($line, 0, 2) == " " ) $value .= "\n"; else $value .= " "; $value .= trim($line); } else $value .= "\n\n"; $newtag = false; } } if ( $curtag !== false && $i >= 0 ) $res[$i][1][$curtag] = $value; return $res; } // Convert given byte-size to more human readable format function human_format_size( $bytes ) { $formats = Array("%d Bytes", "%.1f KB", "%.1f MB", "%.1f GB", "%.1f TB"); $logsize = min((int)(log($bytes)/log(1024)), count($formats)-1); return sprintf($formats[$logsize], $bytes/pow(1024, $logsize)); } // Extract URLs from text, make them links and output // the whole thing as HTML function link_aware_htmlize( $txt ) { $res = ""; $linkpattern = "!([a-z]+://[^ \n \)$]+)!is"; $frags = preg_split($linkpattern, $txt, -1, PREG_SPLIT_DELIM_CAPTURE); foreach( $frags as $f ) { if ( preg_match($linkpattern, $f) ) $res .= "" . htmlentities($f) . ""; else $res .= htmlentities($f); } return str_replace("\n", "
\n", $res); } function parse_section( $section ) { $res = ""; if ( preg_match("!(contrib/[a-z]+)!is", $section) ) $res .= ", contrib"; else if ( preg_match("!(non-free/[a-z]+)!is", $section) ) $res .= ", non-free"; else $res .= ", main"; return $res . ""; } // We simply check, if the created filename fits exactly the beginning of // the name of the given file. If yes, we have our // This adds quite a bit of disk access so if your server is very busy, // you might want to comment the function call out. function chb_file_match( $file, $version, $field ) { $res = false; if ( strpos( $file, $field . "_" . $version, 0 ) !== False ) return $file; else return $res; } // Get a directory and which files to search for. Try to make a file link. // This adds quite a bit of disk access so if your server is very busy, // you might want to comment the function call out. function chb_file_link_from_directory( $dir, $ext, $myfields, $mysrcdields ) { global $base_url; $dhandle = false; $version = preg_replace("/^[0-9]+\:/", "", $myfields["Version"]); // If no special directory was given, we set the directory found in // the "Directory" field of the Sources(.gz) entry as search path. if ( $dir == False ) $dir = $mysrcdields["Directory"]; if ( $dir !== False && $dhandle = opendir($dir) ) { $chfile = False; while ( false !== ($file = readdir($dhandle)) ) { $fileinfo = pathinfo($file); // Only check files, that are not '.' or '..' and have the // necessary file extension. This maybe reduces the workload. if ( $file != "." && $file != ".." && $fileinfo["extension"] == $ext ) { // Packages with multiple binaries or a source-package // name != binary-package name normally have a // "Source"-field in Packages(.{gz,bz2}). if ( isset($myfields["Source"]) ) $chfile = chb_file_match($file, $version, $myfields["Source"]); // If there is no "Source"-field, just try to use the // Packages-field in Sources(.{gz,bz2}). else if ( isset($mysrcdields["Package"]) ) $chfile = chb_file_match($file, $version, $mysrcdields["Package"]); // And at least simply try the "Package"-field from // Packages(.{gz,bz2}) for those packages, that do not // have a Sources(.{gz,bz2}) entry. else $chfile = chb_file_match($file, $version, $myfields["Package"]); } if ( $chfile !== False ) { print "| " . "." . htmlentities($ext) . "" . "\n"; break; } } closedir($dhandle); } } // Parse given files and write out a nice summary in HTML. // This is the main function. function parse_and_list( $packagesgzfiles, $sourcesgzfile, $shared_changesdir = False, $shared_buildlogsdir = False ) { global $base_url; if ( !is_array($sourcesgzfile) ) $sourcesgzfile = Array($sourcesgzfile); // Rebuild sources array $sources = Array(); foreach( $sourcesgzfile as $f ) { $sources_temp = parse_packages($f); while( list($i, $p) = each($sources_temp) ) $sources[$p[0]] = $p[1]; } if ( !is_array($packagesgzfiles) ) $packagesgzfiles = Array($packagesgzfiles); // Merge different architectures into one $packages array $packages = Array(); foreach( $packagesgzfiles as $f ) { $pkgs = parse_packages($f); while( list($i, $p) = each($pkgs) ) { $name_and_ver = $p[0] . "-" . $p[1]["Version"]; if ( !isset($packages[$name_and_ver]) ) $packages[$name_and_ver] = Array(); $packages[$name_and_ver][$p[1]["Architecture"]] = $p; } } // Walk through the packages and print out the info while( list($name_and_ver, $archs) = each($packages) ) { print "
\n"; // $first = false; // use the first arch for description etc. ksort($archs); list($pkg, $fields) = reset($archs); $srcfields = false; if ( isset($fields["Source"]) && isset($sources[$fields["Source"]]) ) $srcfields = $sources[$fields["Source"]]; else if ( isset($sources[$pkg]) ) $srcfields = $sources[$pkg]; print "" . htmlentities($fields["Package"]) . " " . "(" . htmlentities($fields["Version"]) . parse_section($fields["Section"]) . ")" . "\n"; if ( strlen(trim($fields["Description"])) ) print " - " . htmlentities(preg_replace("/[\n].*/", "", $fields["Description"])); print "
\n"; $archlinks = Array(); while( list($arch_name, list(, $arch_fields)) = each($archs) ) $archlinks[] = "" . htmlentities($arch_name) . " (" . human_format_size($arch_fields["Size"]) . ")"; print "Binary for arch " . join(", ", $archlinks) . "\n"; // If sources are available, print out location. if ( isset($srcfields["Directory"]) ) { print "| Source dir" . "\n"; } // Now create .changes and .build file links. chb_file_link_from_directory( $shared_changesdir, "changes", $fields, $srcfields ); // The file extenion for build-log should be changeable. For the // moment we set it to the debuild/pdebuild default '.build'. chb_file_link_from_directory( $shared_buildlogsdir, "build", $fields, $srcfields ); print ""; // Output the package description. print "

\n" . "

\n" . link_aware_htmlize( preg_replace("/^[^\n]*\n/", "", $fields["Description"])) . "\n

\n" . "
\n
\n"; } } ?>