Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / scp2 / source / templates / modules.pl
blob4cf828869f4a6777a7b6ff8008cb966e7d083c31
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 = "";
21 my $outfile = "";
22 my $infile = "";
23 my @infile = ();
24 my $globalcounter = 0;
25 my $globallinecounter = 0;
26 my $verbose = 0;
28 if ( !defined $completelangiso_var) {
29 print STDERR "ERROR: No language defined!\n";
30 exit 1;
33 startup_check();
35 # if ( "$completelangiso_var" eq "$lastcompletelangiso_var" ) {
36 # print STDERR "No new languages. Keeping old file\n";
37 # exit 0;
38 # }
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";
46 write_ALL_MODULES();
47 close OUTFILE;
48 check_counter();
50 sub check_counter
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";
56 exit 1;
59 if ( $globallinecounter == 0 )
61 print STDERR "ERROR: No lines written!\n";
62 exit 1;
67 sub write_ALL_MODULES
69 my $counter = 0;
70 my $linecounter = 0;
71 my $linecount = $#infile + 1;
72 # print STDERR "Lines in inputfile: $linecount!\n";
74 foreach $lang (@completelangiso) {
75 $language = $lang;
76 $language_ = $lang;
77 $language_ =~ s/-/_/;
78 $languagebig_ = uc($lang);
79 $languagebig_ =~ s/-/_/;
80 $counter++;
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;
90 print OUTFILE $line;
91 $linecounter++;
93 print OUTFILE "\n";
95 print OUTFILE "\n";
97 $globalcounter = $counter;
98 $globallinecounter = $linecounter;
101 sub startup_check
103 my $i;
105 if ( $#ARGV >= 0 )
107 if ( $ARGV[0] eq "-verbose" )
109 $verbose = 1;
110 shift @ARGV;
112 elsif ( $ARGV[0] eq "-quiet" )
114 # no special quiet flag/mode
115 shift @ARGV;
119 for ( $i=0; $i <= $#ARGV; $i++) {
120 if ( "$ARGV[$i]" eq "-o" ) {
121 if ( defined $ARGV[ $i + 1] ) {
122 $outfile = $ARGV[ $i + 1];
123 $i++;
125 } elsif ( "$ARGV[$i]" eq "-i" ) {
126 if ( defined $ARGV[ $i + 1] ) {
127 $infile = $ARGV[ $i + 1];
128 $i++;
130 } else {
131 usage();
135 usage() if $i < 3;
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";
141 @infile = <INFILE>;
142 close( INFILE );
143 print STDERR "Reading template file: $infile\n" if $verbose;
144 my $num = $#infile + 1;
145 # print STDERR "Number of lines: $num\n";
146 } else {
147 die "Template file \"$infile\" not found!\n";
148 exit 1;
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*//;
163 last;
166 close OLDFILE;
171 sub usage
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";
175 exit 1;