1*7e90fac2SAndrew Rist#************************************************************** 2*7e90fac2SAndrew Rist# 3*7e90fac2SAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 4*7e90fac2SAndrew Rist# or more contributor license agreements. See the NOTICE file 5*7e90fac2SAndrew Rist# distributed with this work for additional information 6*7e90fac2SAndrew Rist# regarding copyright ownership. The ASF licenses this file 7*7e90fac2SAndrew Rist# to you under the Apache License, Version 2.0 (the 8*7e90fac2SAndrew Rist# "License"); you may not use this file except in compliance 9*7e90fac2SAndrew Rist# with the License. You may obtain a copy of the License at 10*7e90fac2SAndrew Rist# 11*7e90fac2SAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 12*7e90fac2SAndrew Rist# 13*7e90fac2SAndrew Rist# Unless required by applicable law or agreed to in writing, 14*7e90fac2SAndrew Rist# software distributed under the License is distributed on an 15*7e90fac2SAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*7e90fac2SAndrew Rist# KIND, either express or implied. See the License for the 17*7e90fac2SAndrew Rist# specific language governing permissions and limitations 18*7e90fac2SAndrew Rist# under the License. 19*7e90fac2SAndrew Rist# 20*7e90fac2SAndrew Rist#************************************************************** 21*7e90fac2SAndrew Rist 22*7e90fac2SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweirmy $completelangiso_var = $ENV{COMPLETELANGISO_VAR}; 25cdf0e10cSrcweirmy $lastcompletelangiso_var = ""; 26cdf0e10cSrcweirmy $outfile = ""; 27cdf0e10cSrcweirmy $infile = ""; 28cdf0e10cSrcweirmy @infile = (); 29cdf0e10cSrcweirmy $globalcounter = 0; 30cdf0e10cSrcweirmy $globallinecounter = 0; 31cdf0e10cSrcweirmy $verbose = 0; 32cdf0e10cSrcweir 33cdf0e10cSrcweirif ( !defined $completelangiso_var) { 34cdf0e10cSrcweir print STDERR "ERROR: No language defined!\n"; 35cdf0e10cSrcweir exit 1; 36cdf0e10cSrcweir} 37cdf0e10cSrcweir 38cdf0e10cSrcweirstartup_check(); 39cdf0e10cSrcweir 40cdf0e10cSrcweir# if ( "$completelangiso_var" eq "$lastcompletelangiso_var" ) { 41cdf0e10cSrcweir# print STDERR "No new languages. Keeping old file\n"; 42cdf0e10cSrcweir# exit 0; 43cdf0e10cSrcweir# } 44cdf0e10cSrcweir 45cdf0e10cSrcweirmy @completelangiso = split " +", $completelangiso_var; 46cdf0e10cSrcweir 47cdf0e10cSrcweiropen OUTFILE, ">$outfile" or die "$0 ERROR: cannot open $outfile for writing!\n"; 48cdf0e10cSrcweirprint OUTFILE "// generated file, do not edit\n\n"; 49cdf0e10cSrcweirprint OUTFILE "// languages used for last time generation\n"; 50cdf0e10cSrcweirprint OUTFILE "// completelangiso: $completelangiso_var\n\n"; 51cdf0e10cSrcweirwrite_ALL_MODULES(); 52cdf0e10cSrcweirclose OUTFILE; 53cdf0e10cSrcweircheck_counter(); 54cdf0e10cSrcweir 55cdf0e10cSrcweirsub check_counter 56cdf0e10cSrcweir{ 57cdf0e10cSrcweir print STDERR "Wrote modules for $globalcounter languages ($globallinecounter lines)!\n" if $verbose; 58cdf0e10cSrcweir if ( $globalcounter == 0 ) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir print STDERR "ERROR: No languages found!\n"; 61cdf0e10cSrcweir exit 1; 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir if ( $globallinecounter == 0 ) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir print STDERR "ERROR: No lines written!\n"; 67cdf0e10cSrcweir exit 1; 68cdf0e10cSrcweir } 69cdf0e10cSrcweir} 70cdf0e10cSrcweir 71cdf0e10cSrcweir 72cdf0e10cSrcweirsub write_ALL_MODULES 73cdf0e10cSrcweir{ 74cdf0e10cSrcweir my $counter = 0; 75cdf0e10cSrcweir my $linecounter = 0; 76cdf0e10cSrcweir my $linecount = $#infile + 1; 77cdf0e10cSrcweir # print STDERR "Lines in inputfile: $linecount!\n"; 78cdf0e10cSrcweir 79cdf0e10cSrcweir foreach $lang (@completelangiso) { 80cdf0e10cSrcweir $language = $lang; 81cdf0e10cSrcweir $language_ = $lang; 82cdf0e10cSrcweir $language_ =~ s/-/_/; 83cdf0e10cSrcweir $languagebig_ = uc($lang); 84cdf0e10cSrcweir $languagebig_ =~ s/-/_/; 85cdf0e10cSrcweir $counter++; 86cdf0e10cSrcweir my $sortkey = 100 * $counter; 87cdf0e10cSrcweir 88cdf0e10cSrcweir for ( $i = 0; $i <= $#infile; $i++) { 89cdf0e10cSrcweir my $line = $infile[$i]; 90cdf0e10cSrcweir if (( $line =~ /^\s*\*/ ) || ( $line =~ /^\s*\/\*/ )) { next; } 91cdf0e10cSrcweir $line =~ s/\<LANGUAGE\>/$language/g; 92cdf0e10cSrcweir $line =~ s/\<LANGUAGE_\>/$language_/g; 93cdf0e10cSrcweir $line =~ s/\<LANGUAGEBIG_\>/$languagebig_/g; 94cdf0e10cSrcweir $line =~ s/\<SORTKEY\>/$sortkey/g; 95cdf0e10cSrcweir print OUTFILE $line; 96cdf0e10cSrcweir $linecounter++; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir print OUTFILE "\n"; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir print OUTFILE "\n"; 101cdf0e10cSrcweir 102cdf0e10cSrcweir $globalcounter = $counter; 103cdf0e10cSrcweir $globallinecounter = $linecounter; 104cdf0e10cSrcweir} 105cdf0e10cSrcweir 106cdf0e10cSrcweirsub startup_check 107cdf0e10cSrcweir{ 108cdf0e10cSrcweir my $i; 109cdf0e10cSrcweir 110cdf0e10cSrcweir if ( $#ARGV >= 0 ) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir if ( $ARGV[0] eq "-verbose" ) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir $verbose = 1; 115cdf0e10cSrcweir shift @ARGV; 116cdf0e10cSrcweir } 117cdf0e10cSrcweir elsif ( $ARGV[0] eq "-quiet" ) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir # no special quiet flag/mode 120cdf0e10cSrcweir shift @ARGV; 121cdf0e10cSrcweir } 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir for ( $i=0; $i <= $#ARGV; $i++) { 125cdf0e10cSrcweir if ( "$ARGV[$i]" eq "-o" ) { 126cdf0e10cSrcweir if ( defined $ARGV[ $i + 1] ) { 127cdf0e10cSrcweir $outfile = $ARGV[ $i + 1]; 128cdf0e10cSrcweir $i++; 129cdf0e10cSrcweir } 130cdf0e10cSrcweir } elsif ( "$ARGV[$i]" eq "-i" ) { 131cdf0e10cSrcweir if ( defined $ARGV[ $i + 1] ) { 132cdf0e10cSrcweir $infile = $ARGV[ $i + 1]; 133cdf0e10cSrcweir $i++; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir } else { 136cdf0e10cSrcweir usage(); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir usage() if $i < 3; 141cdf0e10cSrcweir usage() if "$outfile" eq ""; 142cdf0e10cSrcweir usage() if "$infile" eq ""; 143cdf0e10cSrcweir 144cdf0e10cSrcweir if ( -f "$infile" ) { 145cdf0e10cSrcweir open INFILE, "$infile" or die "$0 - ERROR: $infile exists but isn't readable.\n"; 146cdf0e10cSrcweir @infile = <INFILE>; 147cdf0e10cSrcweir close( INFILE ); 148cdf0e10cSrcweir print STDERR "Reading template file: $infile\n" if $verbose; 149cdf0e10cSrcweir my $num = $#infile + 1; 150cdf0e10cSrcweir # print STDERR "Number of lines: $num\n"; 151cdf0e10cSrcweir } else { 152cdf0e10cSrcweir die "Template file \"$infile\" not found!\n"; 153cdf0e10cSrcweir exit 1; 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir if ( -f "$outfile" ) { 157cdf0e10cSrcweir # changed script - run always 158cdf0e10cSrcweir return if (stat($0))[9] > (stat("$outfile"))[9] ; 159cdf0e10cSrcweir # changed template file - run always 160cdf0e10cSrcweir return if (stat($infile))[9] > (stat("$outfile"))[9] ; 161cdf0e10cSrcweir 162cdf0e10cSrcweir open OLDFILE, "$outfile" or die "$0 - ERROR: $outfile exists but isn't readable.\n"; 163cdf0e10cSrcweir while ( $line = <OLDFILE> ) { 164cdf0e10cSrcweir if ( $line =~ /^\/\/.*completelangiso:/ ) { 165cdf0e10cSrcweir $lastcompletelangiso_var = $line; 166cdf0e10cSrcweir chomp $lastcompletelangiso_var; 167cdf0e10cSrcweir $lastcompletelangiso_var =~ s/^\/\/.*completelangiso:\s*//; 168cdf0e10cSrcweir last; 169cdf0e10cSrcweir } 170cdf0e10cSrcweir } 171cdf0e10cSrcweir close OLDFILE; 172cdf0e10cSrcweir } 173cdf0e10cSrcweir 174cdf0e10cSrcweir} 175cdf0e10cSrcweir 176cdf0e10cSrcweirsub usage 177cdf0e10cSrcweir{ 178cdf0e10cSrcweir print STDERR "Generate language modules from language script particle template (*.sct file)\n"; 179cdf0e10cSrcweir print STDERR "perl $0 [-verbose] -o outputfile -i inputfile\n"; 180cdf0e10cSrcweir exit 1; 181cdf0e10cSrcweir} 182