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,37 +59,61 @@ while ($_ = $ARGV[0], /^-/) { ...@@ -65,37 +59,61 @@ 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";
$templates{$template} = \%entry;
} else {
# split locale = "value" into 2 strings
my ($locale, $value) = split(' = ', $line);
close(TEMPLATE); if ( $locale ne $line ) {
# replace en-US with en
$locale=~s/en-US/en/;
if (close(OUTFILE)) { # use just anything inside the ""
system "mv -f $outfile.tmp $outfile\n"; $value = substr($value, index($value, "\"") + 1, rindex($value, "\"") - 1);
# replace resource placeholder
$value=~s/%PRODUCTNAME/$productname/g;
$locale=~s/-/_/;
$templates{$template}->{'locale'} = $locale;
$templates{$template}->{'value'} = $value;
}
} }
}
$_ = substr($line, 1, index($line,"]")-1); close(SOURCE);
$outfile = "$workdir/$prefix$_.$ext";
# process templates
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 # open the template file - ignore sections for which no
# templates exist # templates exist
...@@ -110,32 +128,17 @@ while (<SOURCE>) { ...@@ -110,32 +128,17 @@ while (<SOURCE>) {
exit -1; exit -1;
} }
# Pass the head of the template to the output file # emit the template to the output file
KEY: while (<TEMPLATE>) { while (<TEMPLATE>) {
$keyline = $_; my $keyline = $_;
last KEY if (/$key/); $keyline =~ s/^$key/$outkey/;
print OUTFILE;
}
$keyline=~s/^$key/$outkey/;
print OUTFILE $keyline; print OUTFILE $keyline;
if (/$key/) {
} else { my $locale = $templates{$template}->{'locale'};
# split locale = "value" into 2 strings my $value = $templates{$template}->{'value'};
($locale, $value) = split(' = ', $line); print "locale is $locale\n";
print "value is $value\n";
if ( $locale ne $line ) { if ($value) {
# replace en-US with en
$locale=~s/en-US/en/;
# use just anything inside the ""
$value = substr($value, index($value, "\"") + 1, rindex($value, "\"") - 1);
# replace resource placeholder
$value=~s/%PRODUCTNAME/$productname/g;
$locale=~s/-/_/;
if (not $value eq '') {
if ($ext eq "desktop") { if ($ext eq "desktop") {
print OUTFILE "$outkey\[$locale\]=$value\n"; print OUTFILE "$outkey\[$locale\]=$value\n";
} else { } else {
...@@ -144,14 +147,10 @@ KEY: while (<TEMPLATE>) { ...@@ -144,14 +147,10 @@ KEY: while (<TEMPLATE>) {
} }
} }
} }
}
while (<TEMPLATE>) { close(TEMPLATE);
print OUTFILE;
}
if (close(OUTFILE)) { if (close(OUTFILE)) {
system "mv -f $outfile.tmp $outfile\n"; system "mv -f $outfile.tmp $outfile\n";
}
} }
close(TEMPLATE);
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