} else { if (preg_match('/([0-9]+)[acd]/', $buf, $matches, PREG_OFFSET_CAPTURE) > 0) { $ls = $le = (int) $matches[1][0]; } } if (preg_match('/[acd]([0-9]+),([0-9]+)/', $buf, $matches, PREG_OFFSET_CAPTURE) > 0) { $rs = (int) $matches[1][0]; $re = (int) $matches[2][0]; } else { if (preg_match('/[acd]([0-9]+)/', $buf, $matches, PREG_OFFSET_CAPTURE) > 0) { $rs = $re = (int) $matches[1][0]; } } // printf("Found: $ls-$le $rs-$re\n"); //printf("\n"); $n_diff += $le - $ls + 1 + $re - $rs; } $dvalue = $n_diff / ($lc1 + $lc2); fclose($fp); unlink($diff); return $dvalue; } if ($argc != 3) { printf("\n\tE.g. CalcTextFileSim file1 file2\n\n"); exit(-1); } $dvalue = CalcTextFileDissim($argv[1], $argv[2]); printf("dissimilarity = {$dvalue}\n"); ?>
if (filetype($dir) != "dir") { continue; } if ($ID_FILTER != 'all' && $ID_FILTER != $file) { continue; } $code_file = "/tmp/dummy_shouild_not_exist"; $ds = 0; if ($argc >= 4) { $code_file = CreateFullPath($dir, "code"); $k = 1; do { if (!file_exists($code_file)) { break; } $ds = CalcTextFileDissim($code_file, $argv[3]); if ($ds < 0 || $ds > 0.3) { break; } $code_file = CreateFullPath($dir, "code.{$k}"); $k++; } while (1); } if (!file_exists($code_file)) { $code_file = CreateFullPath($dir, "code"); } if (!file_exists($code_file)) { continue; } $queue_file = CreateFullPath(CreateFullPath($HOMEWORK_DIR, "queue"), $file); printf("Processing %s (ds=%f)\n", $code_file, $ds);