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 copies the file named on the command line to the translation
# named in copypage.conf, and adds the translation-check header to it.
# It also will create the destination directory if necessary, and copy the
# Makefile from the source.
# Written on 2000-02-26 by peter karlsson <peter@softwolves.pp.se>
# © Copyright 2000 Software in the public interest, Inc.
# This program is released under the GNU General Public License, v2.
# $Id$
# Check usage.
if ($#ARGV == -1)
{
print "Usage: $0 page ...\n\n";
print "Copies the page from the english/ directory to the $language/ directory\n";
print "and adds the translation-check header\n";
print "If the directory does not exist, it will be created, and the Makefile\n";
print "copied.\n\n";
print "You can either keep or not keep the 'english/' part of the path.\n";
exit;
}
# Get configuration
if (open CONF, "<language.conf")
{
$language = <CONF>;
chomp $language;
close CONF;
}
else
{
$language = 'swedish';
}
# Loop over commnad line
foreach $page (@ARGV)
{
# Check if valid source
if ($page =~ /wml$/)
{
©($page);
}
else
{
print "$page does not seem to be a valid page.\n";
}
}
# Subroutine to copy a page
sub copy
{
my $page = shift;
print "Processing $page...\n";
# Remove english/ from path
if ($page =~ m[^english/])
{
$page =~ s[^english/][];
}
# Create needed file and directory names
my $srcfile = "english/$page"; # Source file path
$dstfile = "$language/$page"; # Destination file path
my $srcdir = $srcfile;
$srcdir =~ s[(.*/).*][$1]; # Source directory (trailing /)
my $dstdir = $dstfile;
$dstdir =~ s[(.*/).*][$1]; # Desination directory (trailing /)
my $filename = $srcfile;
$filename =~ s[$srcdir][]; # Pathless filename
my $cvsfile = "$srcdir/CVS/Entries";# Name of file with CVS revisions
my $srcmake = $srcdir . "Makefile"; # Name of source Makefile
my $dstmake = $dstdir . "Makefile"; # Name of destination Makefile
# Sanity checks
die "Directory $srcdir does not exist\n" unless -d $srcdir;
die "File $srcfile does not exist\n" unless -e $srcfile;
die "File $dstfile already exists\n" if -e $dstfile;
# Check if destination exists, if not - create it
unless (-d $dstdir)
{
print "Destination directory $dstdir does not exist,\n";
print "creating and copying $dstmake\n";
mkdir $dstdir, 0755
or die "Could not create $dstdir: $!\n";
system "cp $srcmake $dstmake";
}
# Open the files
open CVS, $cvsfile
or die "Could not read $cvsfile ($!)\n";
open SRC, $srcfile
or die "Could not read $srcfile ($!)\n";
open DST, ">$dstfile"
or die "Could not create $dstfile ($!)\n";
# Retrieve CVS revision number
my $revision;
while (<CVS>)
{
if (m[^/$filename/([0-9]*\.[0-9]*)/]o)
{
$revision = $1;
}
}
close CVS;
unless ($revision)
{
print "Could not get revision number - bug in script?\n";
$revision = '1.1';
}
# Copy the file and insert the revision number
my $insertedrevision = 0;
while (<SRC>)
{
unless ($insertedrevision || /^#/)
{
print DST qq'#use wml::debian::translation-check translation="$revision"\n';
$insertedrevision = 1;
}
print DST $_;
}
close SRC;
close DST;
# We're done
print "Copied $page, remember to edit $dstfile\n";
}
|