} } $F1 = fopen("{$in_file}", 'r') or die("can't open file: {$php_errormsg}\n"); /* look for the top 1000 projects, when found, write the project entry to a file. NOTE: I'm bothered by something here... while one gets the top 1000, there could be drastic differences (not likely between any two days, but possible)....It doesn't really affect this code, but could affect users of the output files. */ $Output = fopen("{$out_file}", 'w') or die("Can' open: {$php_errormsg}\n"); echo "Extracting the top {$HowMany_projects} projects from:\n{$in_file}\n"; echo "\nWriting the top {$HowMany_projects} projects to: {$out_file}\n"; // need a valid doc, write the header 1st, and open tag write_hdr($Output); while (false != ($line = fgets($F1, 1024))) { # echo "Line is:\n$line\n"; if (preg_match('/<project>/', $line)) { $proj_mark = ftell($F1); } elseif (preg_match('/<popularity_rank>[0-9].*</', $line)) { $pos = strpos($line, '>'); $rank_pos = $pos + 1; $rank_end = strpos($line, '</', $rank_pos); $rank_len = $rank_end - $rank_pos; $rank = substr($line, $rank_pos, $rank_len); if ((int) $rank <= $HowMany_projects) { //pdbg("Processing rank:$rank"); write_entry($F1, $proj_mark, $Output); } }
//pdbg("diffs are:",$adiffs); // If no diffs, exit 0, nothing to do, remove files and stop $diffs_found = count($adiffs); if ($diffs_found == 0) { echo "NOTE: No differences were found. \n"; $junk = exec("rm -f {$projs2update} {$xml_changes}", $dummy, $rtn); if ($rtn != 0) { echo "cound not remove files {$projs2update}\nand\n{$xml_changes}\n"; echo "Please remove them manually"; } exit($diffs_found); // should be 0 } // differences found, save them up in the files. We only save from // file 1 as that is the newest file. write_hdr($Cxml); while (false != ($f1_line = fgets($F1, 1024))) { $proj1 = array(); if (preg_match('/<project>/', $f1_line)) { $m1 = ftell($F1); $proj1 = get_entry($F1, $m1); //pdbg("DIFFM: P1 Entries:",$proj1); } else { continue; } // we now have a project, is it one of the ones that need updating? // If so, save it, and record the project name and version. $proj_name = xtract($proj1[4]); foreach ($adiffs as $name => $version) { if ($proj_name == $name) { //pdbg("Found $name, saving");