summaryrefslogtreecommitdiff
path: root/scripts/doc-check
blob: aac4e04709b2c712d1354cc78f4c33a782607af9 (plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/perl -w
#
# This script checks if the translations of the documents are up to date.
#

use Getopt::Std;
use File::Find;
$opt_d = $opt_h = $opt_r = $opt_s = $opt_v = $opt_V = 0;
getopts('hr:dsvV');
# You may set this to your default language code
$lang = shift || "pl";
if ($opt_r and $opt_r !~ /[0-9]+/) {
	warn "Please enter a revision number for parameter -r.\n";
	exit 1
}

sub usage
{
	printf <<HERE, $lang;
Usage: $0 [options] [<language>]

  -h        print this help message.
  -d        print what has changed in the original since last translation.
  -r <rev>  take the diff against the revision number <rev> instead of the
	    latest revision of the English original.
  -s        show also all files marked untranslated.
  -v        be verbose.
  -V        be slightly more verbose.

  Current <language> is '%s'.
HERE
	exit 0;
}

sub checkdiff
{
	my ($plfname, $enfname) = (@_);
	my ($plrev, $enrev, $untrans) = getrev($plfname, $enfname);
	$plrev and $enrev or return;
	if ( "$plrev" ne "$enrev" ) {
		if ($opt_d and $opt_r and $opt_r < $enrev) {
			$enrev = $opt_r;
		}
		if ($untrans) {
			print "$enfname : $plrev -> $enrev (untranslated)\n";
		} else {
			print "$enfname : $plrev -> $enrev\n";
		}
		if ($opt_d) {
			my $s = "svn diff -r $plrev:$enrev $enfname";
			warn "running $s:\n" if ($opt_V);
			system($s);
		}
	} else {
		if ($untrans && $opt_s) {
			print "$plfname: untranslated\n";
		}
	}
}

sub getrev
{
	my ($plfname, $enfname) = (@_);
	my ($plrev, $enrev, $untrans, $notconverted) = (0, 0, 0, 0);

	warn "checking $plfname:\n" if $opt_v;
	open FILE, $plfname or warn "$plfname: $!\n" and return;
	while (<FILE>) {
		if (/<!--\s*original version\D*([\d\.]+)\s*-->/) {
			$plrev = $1;
			last;
		}
		if (/<!--\s*original version\D*(\d+)\s*untranslated\s*-->/) {
			$plrev = $1;
			$untrans = 1;
			last;
		}
		# Also check for revision comments of original documents
		if (/<!--\s*\$Id: \S+ (\d+) /) {
			$plrev = $1;
			$notconverted = 1;
			$untrans = 1;
			last;
		}
		# Also support CVS style revision comments (depreciated)
		if (/<!--\s*original document: en\/\S+, revision ([\d\.]+)\s*-->/) {
			$plrev = $1;
			last;
		}
	}
	warn "checking $enfname:\n" if $opt_v;
	open FILE, $enfname or warn "$enfname: $!\n" and return;
	while (<FILE>) {
		if (/\$Id: \S+ (\d+) /) {
			$enrev = $1;
			last;
		}
		# Also support CVS style revision comments (depreciated)
		if (/\$Revision: (\d+) \$/) {
			$enrev = $1;
			last;
		}
	}
	close FILE;
	warn "failed to find revision for $plfname\n" unless $plrev;
	warn "failed to find revision for $enfname\n" unless $enrev;
	if ($notconverted) {
		warn "$plfname: contains revision comment for original document\n";
		warn "   use 'rev-update' to convert\n";
	}
	return ($plrev, $enrev, $untrans);
}

sub process
{
	my $enfname = $File::Find::name;
	return unless $enfname =~ m/\.xml$/;
	my $plfname = $enfname;
	$plfname =~ s,^en/,$lang/,;
	checkdiff($plfname, $enfname);
}

sub process_obsolete
{
	my $plfname = $File::Find::name;
	return unless $plfname =~ m/\.xml$/;
	my $enfname = $plfname;
	$enfname =~ s,^$lang/,en/,;
	open FILE, $enfname or warn "$plfname: Probably obsoleted\n" and return;
	close FILE;
}

usage() if $opt_h;

warn "\nChecking for outdated or missing translations...\n" if $opt_v;
File::Find::find({ wanted => \&process, no_chdir => 1 }, 'en');
warn "\nChecking for obsoleted translations...\n" if $opt_v;
File::Find::find({ wanted => \&process_obsolete, no_chdir => 1 }, $lang);

#checkdiff("build/install.$lang.xml", "build/install.en.xml");
#checkdiff("release-notes.$lang.sgml","release-notes.sgml");
#checkdiff("index.$lang.html.m4","index.en.html.m4");
#checkdiff("dselect-beginner.$lang.sgml","dselect-beginner.sgml");

warn "All done.\n" if $opt_v;