merge the formfield patch from ooo-build
[ooovba.git] / scp2 / source / templates / modules.pl
blobad75acaf9723f8f8d97a1a1c86989757f60aa1fe
1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: modules.pl,v $
11 # $Revision: 1.3 $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 my $completelangiso_var = $ENV{COMPLETELANGISO_VAR};
33 my $lastcompletelangiso_var = "";
34 my $outfile = "";
35 my $infile = "";
36 my @infile = ();
37 my $globalcounter = 0;
38 my $globallinecounter = 0;
39 my $verbose = 0;
41 if ( !defined $completelangiso_var) {
42 print STDERR "ERROR: No language defined!\n";
43 exit 1;
46 startup_check();
48 # if ( "$completelangiso_var" eq "$lastcompletelangiso_var" ) {
49 # print STDERR "No new languages. Keeping old file\n";
50 # exit 0;
51 # }
53 my @completelangiso = split " +", $completelangiso_var;
55 open OUTFILE, ">$outfile" or die "$0 ERROR: cannot open $outfile for writing!\n";
56 print OUTFILE "// generated file, do not edit\n\n";
57 print OUTFILE "// languages used for last time generation\n";
58 print OUTFILE "// completelangiso: $completelangiso_var\n\n";
59 write_ALL_MODULES();
60 close OUTFILE;
61 check_counter();
63 sub check_counter
65 print STDERR "Wrote modules for $globalcounter languages ($globallinecounter lines)!\n";
66 if ( $globalcounter == 0 )
68 print STDERR "ERROR: No languages found!\n";
69 exit 1;
72 if ( $globallinecounter == 0 )
74 print STDERR "ERROR: No lines written!\n";
75 exit 1;
80 sub write_ALL_MODULES
82 my $counter = 0;
83 my $linecounter = 0;
84 my $linecount = $#infile + 1;
85 # print STDERR "Lines in inputfile: $linecount!\n";
87 foreach $lang (@completelangiso) {
88 $language = $lang;
89 $language_ = $lang;
90 $language_ =~ s/-/_/;
91 $languagebig_ = uc($lang);
92 $languagebig_ =~ s/-/_/;
93 $counter++;
94 my $sortkey = 100 * $counter;
96 for ( $i = 0; $i <= $#infile; $i++) {
97 my $line = $infile[$i];
98 if (( $line =~ /^\s*\*/ ) || ( $line =~ /^\s*\/\*/ )) { next; }
99 $line =~ s/\<LANGUAGE\>/$language/g;
100 $line =~ s/\<LANGUAGE_\>/$language_/g;
101 $line =~ s/\<LANGUAGEBIG_\>/$languagebig_/g;
102 $line =~ s/\<SORTKEY\>/$sortkey/g;
103 print OUTFILE $line;
104 $linecounter++;
106 print OUTFILE "\n";
108 print OUTFILE "\n";
110 $globalcounter = $counter;
111 $globallinecounter = $linecounter;
114 sub startup_check
116 my $i;
117 for ( $i=0; $i <= $#ARGV; $i++) {
118 if ( "$ARGV[$i]" eq "-o" ) {
119 if ( defined $ARGV[ $i + 1] ) {
120 $outfile = $ARGV[ $i + 1];
121 $i++;
123 } elsif ( "$ARGV[$i]" eq "-i" ) {
124 if ( defined $ARGV[ $i + 1] ) {
125 $infile = $ARGV[ $i + 1];
126 $i++;
128 } else {
129 usage();
133 usage() if $i < 3;
134 usage() if "$outfile" eq "";
135 usage() if "$infile" eq "";
137 if ( -f "$infile" ) {
138 open INFILE, "$infile" or die "$0 - ERROR: $infile exists but isn't readable.\n";
139 @infile = <INFILE>;
140 close( INFILE );
141 print STDERR "Reading template file: $infile\n";
142 my $num = $#infile + 1;
143 # print STDERR "Number of lines: $num\n";
144 } else {
145 die "Template file \"$infile\" not found!\n";
146 exit 1;
149 if ( -f "$outfile" ) {
150 # changed script - run always
151 return if (stat($0))[9] > (stat("$outfile"))[9] ;
152 # changed template file - run always
153 return if (stat($infile))[9] > (stat("$outfile"))[9] ;
155 open OLDFILE, "$outfile" or die "$0 - ERROR: $outfile exists but isn't readable.\n";
156 while ( $line = <OLDFILE> ) {
157 if ( $line =~ /^\/\/.*completelangiso:/ ) {
158 $lastcompletelangiso_var = $line;
159 chomp $lastcompletelangiso_var;
160 $lastcompletelangiso_var =~ s/^\/\/.*completelangiso:\s*//;
161 last;
164 close OLDFILE;
169 sub usage
171 print STDERR "Generate language modules from language script particle template (*.sct file)\n";
172 print STDERR "perl $0 [-verbose] -o outputfile -i inputfile\n";
173 exit 1;