update dev300-m58
[ooovba.git] / scp2 / source / templates / modules.pl
blob4287e0e0c7198b423534da47cc854a4e675e2f4e
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;
40 if ( !defined $completelangiso_var) {
41 print STDERR "ERROR: No language defined!\n";
42 exit 1;
45 startup_check();
47 # if ( "$completelangiso_var" eq "$lastcompletelangiso_var" ) {
48 # print STDERR "No new languages. Keeping old file\n";
49 # exit 0;
50 # }
52 my @completelangiso = split " +", $completelangiso_var;
54 open OUTFILE, ">$outfile" or die "$0 ERROR: cannot open $outfile for writing!\n";
55 print OUTFILE "// generated file, do not edit\n\n";
56 print OUTFILE "// languages used for last time generation\n";
57 print OUTFILE "// completelangiso: $completelangiso_var\n\n";
58 write_ALL_MODULES();
59 close OUTFILE;
60 check_counter();
62 sub check_counter
64 print STDERR "Wrote modules for $globalcounter languages ($globallinecounter lines)!\n";
65 if ( $globalcounter == 0 )
67 print STDERR "ERROR: No languages found!\n";
68 exit 1;
71 if ( $globallinecounter == 0 )
73 print STDERR "ERROR: No lines written!\n";
74 exit 1;
79 sub write_ALL_MODULES
81 my $counter = 0;
82 my $linecounter = 0;
83 my $linecount = $#infile + 1;
84 # print STDERR "Lines in inputfile: $linecount!\n";
86 foreach $lang (@completelangiso) {
87 $language = $lang;
88 $language_ = $lang;
89 $language_ =~ s/-/_/;
90 $languagebig_ = uc($lang);
91 $languagebig_ =~ s/-/_/;
92 $counter++;
93 my $sortkey = 100 * $counter;
95 for ( $i = 0; $i <= $#infile; $i++) {
96 my $line = $infile[$i];
97 if (( $line =~ /^\s*\*/ ) || ( $line =~ /^\s*\/\*/ )) { next; }
98 $line =~ s/\<LANGUAGE\>/$language/g;
99 $line =~ s/\<LANGUAGE_\>/$language_/g;
100 $line =~ s/\<LANGUAGEBIG_\>/$languagebig_/g;
101 $line =~ s/\<SORTKEY\>/$sortkey/g;
102 print OUTFILE $line;
103 $linecounter++;
105 print OUTFILE "\n";
107 print OUTFILE "\n";
109 $globalcounter = $counter;
110 $globallinecounter = $linecounter;
113 sub startup_check
115 my $i;
116 for ( $i=0; $i <= $#ARGV; $i++) {
117 if ( "$ARGV[$i]" eq "-o" ) {
118 if ( defined $ARGV[ $i + 1] ) {
119 $outfile = $ARGV[ $i + 1];
120 $i++;
122 } elsif ( "$ARGV[$i]" eq "-i" ) {
123 if ( defined $ARGV[ $i + 1] ) {
124 $infile = $ARGV[ $i + 1];
125 $i++;
127 } else {
128 usage();
132 usage() if $i < 3;
133 usage() if "$outfile" eq "";
134 usage() if "$infile" eq "";
136 if ( -f "$infile" ) {
137 open INFILE, "$infile" or die "$0 - ERROR: $infile exists but isn't readable.\n";
138 @infile = <INFILE>;
139 close( INFILE );
140 print STDERR "Reading template file: $infile\n";
141 my $num = $#infile + 1;
142 # print STDERR "Number of lines: $num\n";
143 } else {
144 die "Template file \"$infile\" not found!\n";
145 exit 1;
148 if ( -f "$outfile" ) {
149 # changed script - run always
150 return if (stat($0))[9] > (stat("$outfile"))[9] ;
151 # changed template file - run always
152 return if (stat($infile))[9] > (stat("$outfile"))[9] ;
154 open OLDFILE, "$outfile" or die "$0 - ERROR: $outfile exists but isn't readable.\n";
155 while ( $line = <OLDFILE> ) {
156 if ( $line =~ /^\/\/.*completelangiso:/ ) {
157 $lastcompletelangiso_var = $line;
158 chomp $lastcompletelangiso_var;
159 $lastcompletelangiso_var =~ s/^\/\/.*completelangiso:\s*//;
160 last;
163 close OLDFILE;
168 sub usage
170 print STDERR "Generate language modules from language script particle template (*.sct file)\n";
171 print STDERR "perl $0 -o outputfile -i inputfile\n";
172 exit 1;