示例#1
0
文件: scripts.php 项目: rair/yacs
 /**
  * get the diff as a table of lines
  *
  * @param string a file name of the original content
  * @param string a file for the updated content
  * @return an ASCII string
  */
 public static function diff($original, $updated)
 {
     global $context;
     // read the original file
     $stat = Safe::stat($context['path_to_root'] . $original);
     if (!is_array($stat)) {
         return sprintf(i18n::s('Impossible to read %s.'), $original);
     }
     $original_lines = Safe::file($context['path_to_root'] . $original);
     // read the updated file
     $stat = Safe::stat($context['path_to_root'] . $updated);
     if (!is_array($stat)) {
         return sprintf(i18n::s('Impossible to read %s.'), $updated);
     }
     $updated_lines = Safe::file($context['path_to_root'] . $updated);
     // compare the two sequences
     $sequence = Scripts::compare($original_lines, $updated_lines);
     // format the output string
     $text = '';
     foreach ($sequence as $item) {
         list($tag, $left, $right) = $item;
         $text .= Scripts::adjust('	' . $tag, 5) . ' ' . Scripts::adjust($left) . ' ' . Scripts::adjust($right) . "\n";
     }
     // return the result of the whole comparison
     $text = Scripts::adjust(i18n::s('Delta'), 5) . ' ' . Scripts::adjust($original) . ' ' . Scripts::adjust($updated) . "\n" . str_replace("\t", '  ', $text) . "\n";
     return $text;
 }