File: diff_en_rev.php

package info (click to toggle)
php-doc 20100521-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 59,992 kB
  • ctags: 4,085
  • sloc: xml: 796,833; php: 21,338; cpp: 500; sh: 117; makefile: 58; awk: 28
file content (92 lines) | stat: -rw-r--r-- 3,574 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/php -q
<?php
/*
  +----------------------------------------------------------------------+
  | PHP Version 4                                                        |
  +----------------------------------------------------------------------+
  | Copyright (c) 1997-2010 The PHP Group                                |
  +----------------------------------------------------------------------+
  | This source file is subject to version 3.0 of the PHP license,       |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | http://www.php.net/license/3_0.txt.                                  |
  | If you did not receive a copy of the PHP license and are unable to   |
  | obtain it through the world-wide-web, please send a note to          |
  | license@php.net so we can mail you a copy immediately.               |
  +----------------------------------------------------------------------+
  | Authors:    Jakub Vrana <vrana@php.net>                              |
  +----------------------------------------------------------------------+

  $Id: diff_en_rev.php 293138 2010-01-05 10:21:11Z rquadling $
*/

/*
This script should stay in phpdoc-lang/scripts/ directory.
The local cvs-root is determined by its location.
*/

function exit1($status) {
	fwrite(STDERR, $status);
	exit(1);
}

if ($_SERVER["argc"] < 2 || $_SERVER["argc"] > 3) {
	exit1("Prints diff of current English file and the file used for the translation.\n"
		."Usage: ". basename(__FILE__) ." translated_file [cvs_executable]\n"
		."Example: ". basename(__FILE__) ." ../cs/appendices/about.xml /bin/cvs\n"
	);
}

// returns first 500 bytes of $filename
function head($filename) {
	$fp = fopen($filename, "rb");
	$return = fread($fp, 500);
	fclose($fp);
	return $return;
}

// find filename
$cvs_executable = (isset($_SERVER["argv"][2]) ? $_SERVER["argv"][2] : "cvs");
$root = str_replace('\\', '/', dirname(__FILE__)); // for Windows
$root = substr($root, 0, strrpos($root, '/')); // up-dir from scripts/
$filename = str_replace('\\', '/', realpath($_SERVER["argv"][1]));
if (!file_exists($filename)) {
	exit1("Error: File ". $_SERVER["argv"][1] ." not found.\n");
}
if (!ereg('^'. quotemeta($root) ."/([^/]*/.*)", $filename, $regs)) {
	exit1("Error: File ". $_SERVER["argv"][1] ." is outside CVS root.\n");
}
$filename = $regs[1];

chdir($root);
$files = (is_dir($filename) ? glob("$filename/*") : array($filename));
foreach ($files as $lang_filename) {
	if (!is_file($lang_filename)) { // do not recurse
		continue;
	}
	$en_filename = ereg_replace('^[^/]*', 'en', $lang_filename);
	
	// find EN-Revision tag
	if (!eregi("(.*)<!-- *EN-Revision: +([^ ]*)", head($lang_filename), $regs)) {
		fwrite(STDERR, "Error: Can't find EN-Revision tag in first 500 bytes of $lang_filename.\n");
	}
	$line_no = substr_count($regs[1], "\n") + 1;
	$revision = $regs[2];
	
	// compare with local version
	$same_revision = (file_exists($en_filename) && eregi('<!-- *\\$'.'Revision: +([0-9.])', head($en_filename), $regs) && $regs[1] == $revision); // '.' due to storing to CVS repository
	if (is_dir($filename)) {
		// for directories just print the list of modified files
		if (!$same_revision) {
			echo "Change in ". realpath($lang_filename) ." on line $line_no\n";
		}
	} elseif ($same_revision) {
		echo "No change in local file $en_filename.\n";
	} else {
		// execute diff
		$command = "$cvs_executable diff -u -r $revision $en_filename";
		fwrite(STDERR, "$command\n");
		passthru($command);
	}
}
?>