Kaydet (Commit) b9c37611 authored tarafından David Tardon's avatar David Tardon

rewrite a horrible perl script to saner form

The old form duplicated the last line of the processed file if the key
was not present. This was not a problem before we added Unity-specific
keys to the desktop files, because all keys were always present...

Change-Id: Ifef6a90250fd303b913807944c7a23e04a5aafb1
üst 00240d04
...@@ -29,15 +29,9 @@ eval 'exec perl -wS $0 ${1+"$@"}' ...@@ -29,15 +29,9 @@ eval 'exec perl -wS $0 ${1+"$@"}'
# #
#************************************************************************* #*************************************************************************
#*********************************************************************
#
# main
#
my ($prefix, $ext, $key); my ($prefix, $ext, $key);
$productname = "LibreOffice"; my $productname = "LibreOffice";
$workdir = "."; my $workdir = ".";
while ($_ = $ARGV[0], /^-/) { while ($_ = $ARGV[0], /^-/) {
shift; shift;
...@@ -65,63 +59,36 @@ while ($_ = $ARGV[0], /^-/) { ...@@ -65,63 +59,36 @@ while ($_ = $ARGV[0], /^-/) {
} }
# hack for unity section # hack for unity section
$outkey = $key; my $outkey = $key;
if ( $outkey eq "UnityQuicklist" ) { if ( $outkey eq "UnityQuicklist" ) {
$outkey = "Name"; $outkey = "Name";
} }
my %templates;
# open input file # open input file
unless (open(SOURCE, $ARGV[0])) { unless (open(SOURCE, $ARGV[0])) {
print STDERR "Can't open $ARGV[0] file: $!\n"; print STDERR "Can't open $ARGV[0] file: $!\n";
return; return;
} }
# currently read template
my $template;
# For every section in the specified ulf file there should exist # read ulf file
# a template file in $workdir ..
while (<SOURCE>) { while (<SOURCE>) {
$line = $_; my $line = $_;
if ( "[" eq substr($line, 0, 1) ) { if ( "[" eq substr($line, 0, 1) ) {
# Pass the tail of the template to the output file $template = substr($line, 1, index($line,"]")-1);
while (<TEMPLATE>) { my %entry;
print OUTFILE; # For every section in the specified ulf file there should exist
} # a template file in $workdir ..
$entry{'outfile'} = "$workdir/$prefix$template.$ext";
close(TEMPLATE); $templates{$template} = \%entry;
if (close(OUTFILE)) {
system "mv -f $outfile.tmp $outfile\n";
}
$_ = substr($line, 1, index($line,"]")-1);
$outfile = "$workdir/$prefix$_.$ext";
# open the template file - ignore sections for which no
# templates exist
unless(open(TEMPLATE, $outfile)) {
print STDERR "Warning: No template found for item $_: $outfile: $!\n";
next;
}
# open output file
unless (open(OUTFILE, "> $outfile.tmp")) {
print STDERR "Can't create output file $outfile.tmp: $!\n";
exit -1;
}
# Pass the head of the template to the output file
KEY: while (<TEMPLATE>) {
$keyline = $_;
last KEY if (/$key/);
print OUTFILE;
}
$keyline=~s/^$key/$outkey/;
print OUTFILE $keyline;
} else { } else {
# split locale = "value" into 2 strings # split locale = "value" into 2 strings
($locale, $value) = split(' = ', $line); my ($locale, $value) = split(' = ', $line);
if ( $locale ne $line ) { if ( $locale ne $line ) {
# replace en-US with en # replace en-US with en
...@@ -135,23 +102,55 @@ KEY: while (<TEMPLATE>) { ...@@ -135,23 +102,55 @@ KEY: while (<TEMPLATE>) {
$locale=~s/-/_/; $locale=~s/-/_/;
if (not $value eq '') { $templates{$template}->{'locale'} = $locale;
if ($ext eq "desktop") { $templates{$template}->{'value'} = $value;
print OUTFILE "$outkey\[$locale\]=$value\n";
} else {
print OUTFILE "\t\[$locale\]$outkey=$value\n";
}
}
} }
} }
} }
while (<TEMPLATE>) { close(SOURCE);
print OUTFILE;
}
if (close(OUTFILE)) { # process templates
system "mv -f $outfile.tmp $outfile\n"; foreach $template (keys %templates) {
} my $outfile = $templates{$template}->{'outfile'};
print "processing template $template in $outfile\n";
# open the template file - ignore sections for which no
# templates exist
unless(open(TEMPLATE, $outfile)) {
print STDERR "Warning: No template found for item $_: $outfile: $!\n";
next;
}
# open output file
unless (open(OUTFILE, "> $outfile.tmp")) {
print STDERR "Can't create output file $outfile.tmp: $!\n";
exit -1;
}
close(TEMPLATE); # emit the template to the output file
while (<TEMPLATE>) {
my $keyline = $_;
$keyline =~ s/^$key/$outkey/;
print OUTFILE $keyline;
if (/$key/) {
my $locale = $templates{$template}->{'locale'};
my $value = $templates{$template}->{'value'};
print "locale is $locale\n";
print "value is $value\n";
if ($value) {
if ($ext eq "desktop") {
print OUTFILE "$outkey\[$locale\]=$value\n";
} else {
print OUTFILE "\t\[$locale\]$outkey=$value\n";
}
}
}
}
close(TEMPLATE);
if (close(OUTFILE)) {
system "mv -f $outfile.tmp $outfile\n";
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment