2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 my $completelangiso_var = $ENV{COMPLETELANGISO_VAR
};
20 my $lastcompletelangiso_var = "";
24 my $globalcounter = 0;
25 my $globallinecounter = 0;
28 if ( !defined $completelangiso_var) {
29 print STDERR
"ERROR: No language defined!\n";
35 # if ( "$completelangiso_var" eq "$lastcompletelangiso_var" ) {
36 # print STDERR "No new languages. Keeping old file\n";
40 my @completelangiso = split " +", $completelangiso_var;
42 open OUTFILE
, ">$outfile" or die "$0 ERROR: cannot open $outfile for writing!\n";
43 print OUTFILE
"// generated file, do not edit\n\n";
44 print OUTFILE
"// languages used for last time generation\n";
45 print OUTFILE
"// completelangiso: $completelangiso_var\n\n";
52 print STDERR
"Wrote modules for $globalcounter languages ($globallinecounter lines)!\n" if $verbose;
53 if ( $globalcounter == 0 )
55 print STDERR
"ERROR: No languages found!\n";
59 if ( $globallinecounter == 0 )
61 print STDERR
"ERROR: No lines written!\n";
71 my $linecount = $#infile + 1;
72 # print STDERR "Lines in inputfile: $linecount!\n";
74 foreach $lang (@completelangiso) {
78 $languagebig_ = uc($lang);
79 $languagebig_ =~ s/-/_/;
81 my $sortkey = 100 * $counter;
83 for ( $i = 0; $i <= $#infile; $i++) {
84 my $line = $infile[$i];
85 if (( $line =~ /^\s*\*/ ) || ( $line =~ /^\s*\/\
*/ )) { next; }
86 $line =~ s/\<LANGUAGE\>/$language/g;
87 $line =~ s/\<LANGUAGE_\>/$language_/g;
88 $line =~ s/\<LANGUAGEBIG_\>/$languagebig_/g;
89 $line =~ s/\<SORTKEY\>/$sortkey/g;
97 $globalcounter = $counter;
98 $globallinecounter = $linecounter;
107 if ( $ARGV[0] eq "-verbose" )
112 elsif ( $ARGV[0] eq "-quiet" )
114 # no special quiet flag/mode
119 for ( $i=0; $i <= $#ARGV; $i++) {
120 if ( "$ARGV[$i]" eq "-o" ) {
121 if ( defined $ARGV[ $i + 1] ) {
122 $outfile = $ARGV[ $i + 1];
125 } elsif ( "$ARGV[$i]" eq "-i" ) {
126 if ( defined $ARGV[ $i + 1] ) {
127 $infile = $ARGV[ $i + 1];
136 usage
() if "$outfile" eq "";
137 usage
() if "$infile" eq "";
139 if ( -f
"$infile" ) {
140 open INFILE
, "$infile" or die "$0 - ERROR: $infile exists but isn't readable.\n";
143 print STDERR
"Reading template file: $infile\n" if $verbose;
144 my $num = $#infile + 1;
145 # print STDERR "Number of lines: $num\n";
147 die "Template file \"$infile\" not found!\n";
151 if ( -f
"$outfile" ) {
152 # changed script - run always
153 return if (stat($0))[9] > (stat("$outfile"))[9] ;
154 # changed template file - run always
155 return if (stat($infile))[9] > (stat("$outfile"))[9] ;
157 open OLDFILE
, "$outfile" or die "$0 - ERROR: $outfile exists but isn't readable.\n";
158 while ( $line = <OLDFILE
> ) {
159 if ( $line =~ /^\/\
/.*completelangiso:/ ) {
160 $lastcompletelangiso_var = $line;
161 chomp $lastcompletelangiso_var;
162 $lastcompletelangiso_var =~ s/^\/\/.*completelangiso
:\s
*//;
173 print STDERR
"Generate language modules from language script particle template (*.sct file)\n";
174 print STDERR
"perl $0 [-verbose] -o outputfile -i inputfile\n";