xref: /trunk/main/scp2/source/templates/modules.pl (revision cdf0e10c)
1*cdf0e10cSrcweir#*************************************************************************
2*cdf0e10cSrcweir#
3*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir#
5*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir#
7*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir#
9*cdf0e10cSrcweir# This file is part of OpenOffice.org.
10*cdf0e10cSrcweir#
11*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir# only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir#
15*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir#
21*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir# version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir# <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir# for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir#
26*cdf0e10cSrcweir#*************************************************************************
27*cdf0e10cSrcweir
28*cdf0e10cSrcweirmy $completelangiso_var = $ENV{COMPLETELANGISO_VAR};
29*cdf0e10cSrcweirmy $lastcompletelangiso_var = "";
30*cdf0e10cSrcweirmy $outfile = "";
31*cdf0e10cSrcweirmy $infile = "";
32*cdf0e10cSrcweirmy @infile = ();
33*cdf0e10cSrcweirmy $globalcounter = 0;
34*cdf0e10cSrcweirmy $globallinecounter = 0;
35*cdf0e10cSrcweirmy $verbose = 0;
36*cdf0e10cSrcweir
37*cdf0e10cSrcweirif ( !defined $completelangiso_var) {
38*cdf0e10cSrcweir	print STDERR "ERROR: No language defined!\n";
39*cdf0e10cSrcweir	exit 1;
40*cdf0e10cSrcweir}
41*cdf0e10cSrcweir
42*cdf0e10cSrcweirstartup_check();
43*cdf0e10cSrcweir
44*cdf0e10cSrcweir# if ( "$completelangiso_var" eq "$lastcompletelangiso_var" ) {
45*cdf0e10cSrcweir#    print STDERR "No new languages. Keeping old file\n";
46*cdf0e10cSrcweir#    exit 0;
47*cdf0e10cSrcweir# }
48*cdf0e10cSrcweir
49*cdf0e10cSrcweirmy @completelangiso = split " +", $completelangiso_var;
50*cdf0e10cSrcweir
51*cdf0e10cSrcweiropen OUTFILE, ">$outfile" or die "$0 ERROR: cannot open $outfile for writing!\n";
52*cdf0e10cSrcweirprint OUTFILE "// generated file, do not edit\n\n";
53*cdf0e10cSrcweirprint OUTFILE "// languages used for last time generation\n";
54*cdf0e10cSrcweirprint OUTFILE "// completelangiso: $completelangiso_var\n\n";
55*cdf0e10cSrcweirwrite_ALL_MODULES();
56*cdf0e10cSrcweirclose OUTFILE;
57*cdf0e10cSrcweircheck_counter();
58*cdf0e10cSrcweir
59*cdf0e10cSrcweirsub check_counter
60*cdf0e10cSrcweir{
61*cdf0e10cSrcweir	print STDERR "Wrote modules for $globalcounter languages ($globallinecounter lines)!\n" if $verbose;
62*cdf0e10cSrcweir	if ( $globalcounter == 0 )
63*cdf0e10cSrcweir	{
64*cdf0e10cSrcweir		print STDERR "ERROR: No languages found!\n";
65*cdf0e10cSrcweir		exit 1;
66*cdf0e10cSrcweir	}
67*cdf0e10cSrcweir
68*cdf0e10cSrcweir	if ( $globallinecounter == 0 )
69*cdf0e10cSrcweir	{
70*cdf0e10cSrcweir		print STDERR "ERROR: No lines written!\n";
71*cdf0e10cSrcweir		exit 1;
72*cdf0e10cSrcweir	}
73*cdf0e10cSrcweir}
74*cdf0e10cSrcweir
75*cdf0e10cSrcweir
76*cdf0e10cSrcweirsub write_ALL_MODULES
77*cdf0e10cSrcweir{
78*cdf0e10cSrcweir	my $counter = 0;
79*cdf0e10cSrcweir	my $linecounter = 0;
80*cdf0e10cSrcweir	my $linecount = $#infile + 1;
81*cdf0e10cSrcweir	# print STDERR "Lines in inputfile: $linecount!\n";
82*cdf0e10cSrcweir
83*cdf0e10cSrcweir	foreach $lang (@completelangiso) {
84*cdf0e10cSrcweir		$language = $lang;
85*cdf0e10cSrcweir		$language_ = $lang;
86*cdf0e10cSrcweir		$language_ =~ s/-/_/;
87*cdf0e10cSrcweir		$languagebig_ = uc($lang);
88*cdf0e10cSrcweir		$languagebig_ =~ s/-/_/;
89*cdf0e10cSrcweir		$counter++;
90*cdf0e10cSrcweir		my $sortkey = 100 * $counter;
91*cdf0e10cSrcweir
92*cdf0e10cSrcweir		for ( $i = 0; $i <= $#infile; $i++) {
93*cdf0e10cSrcweir			my $line = $infile[$i];
94*cdf0e10cSrcweir			if (( $line =~  /^\s*\*/ ) || ( $line =~  /^\s*\/\*/ )) { next; }
95*cdf0e10cSrcweir			$line =~ s/\<LANGUAGE\>/$language/g;
96*cdf0e10cSrcweir			$line =~ s/\<LANGUAGE_\>/$language_/g;
97*cdf0e10cSrcweir			$line =~ s/\<LANGUAGEBIG_\>/$languagebig_/g;
98*cdf0e10cSrcweir			$line =~ s/\<SORTKEY\>/$sortkey/g;
99*cdf0e10cSrcweir			print OUTFILE $line;
100*cdf0e10cSrcweir			$linecounter++;
101*cdf0e10cSrcweir		}
102*cdf0e10cSrcweir		print OUTFILE "\n";
103*cdf0e10cSrcweir	}
104*cdf0e10cSrcweir	print OUTFILE "\n";
105*cdf0e10cSrcweir
106*cdf0e10cSrcweir	$globalcounter = $counter;
107*cdf0e10cSrcweir	$globallinecounter = $linecounter;
108*cdf0e10cSrcweir}
109*cdf0e10cSrcweir
110*cdf0e10cSrcweirsub startup_check
111*cdf0e10cSrcweir{
112*cdf0e10cSrcweir	my $i;
113*cdf0e10cSrcweir
114*cdf0e10cSrcweir    if ( $#ARGV >= 0 )
115*cdf0e10cSrcweir    {
116*cdf0e10cSrcweir        if ( $ARGV[0] eq "-verbose" )
117*cdf0e10cSrcweir        {
118*cdf0e10cSrcweir            $verbose = 1;
119*cdf0e10cSrcweir            shift @ARGV;
120*cdf0e10cSrcweir        }
121*cdf0e10cSrcweir        elsif ( $ARGV[0] eq "-quiet" )
122*cdf0e10cSrcweir        {
123*cdf0e10cSrcweir            # no special quiet flag/mode
124*cdf0e10cSrcweir            shift @ARGV;
125*cdf0e10cSrcweir        }
126*cdf0e10cSrcweir    }
127*cdf0e10cSrcweir
128*cdf0e10cSrcweir    for ( $i=0; $i <= $#ARGV; $i++) {
129*cdf0e10cSrcweir        if ( "$ARGV[$i]" eq "-o" ) {
130*cdf0e10cSrcweir            if ( defined $ARGV[ $i + 1] ) {
131*cdf0e10cSrcweir                $outfile = $ARGV[ $i + 1];
132*cdf0e10cSrcweir                $i++;
133*cdf0e10cSrcweir            }
134*cdf0e10cSrcweir        } elsif ( "$ARGV[$i]" eq "-i" ) {
135*cdf0e10cSrcweir            if ( defined $ARGV[ $i + 1] ) {
136*cdf0e10cSrcweir                $infile = $ARGV[ $i + 1];
137*cdf0e10cSrcweir                $i++;
138*cdf0e10cSrcweir            }
139*cdf0e10cSrcweir        } else {
140*cdf0e10cSrcweir            usage();
141*cdf0e10cSrcweir        }
142*cdf0e10cSrcweir    }
143*cdf0e10cSrcweir
144*cdf0e10cSrcweir    usage() if $i < 3;
145*cdf0e10cSrcweir    usage() if "$outfile" eq "";
146*cdf0e10cSrcweir    usage() if "$infile" eq "";
147*cdf0e10cSrcweir
148*cdf0e10cSrcweir    if ( -f "$infile" ) {
149*cdf0e10cSrcweir		open INFILE, "$infile" or die "$0 - ERROR: $infile exists but isn't readable.\n";
150*cdf0e10cSrcweir		@infile = <INFILE>;
151*cdf0e10cSrcweir		close( INFILE );
152*cdf0e10cSrcweir		print STDERR "Reading template file: $infile\n" if $verbose;
153*cdf0e10cSrcweir		my $num = $#infile + 1;
154*cdf0e10cSrcweir		# print STDERR "Number of lines: $num\n";
155*cdf0e10cSrcweir    } else {
156*cdf0e10cSrcweir    	die "Template file \"$infile\" not found!\n";
157*cdf0e10cSrcweir    	exit 1;
158*cdf0e10cSrcweir    }
159*cdf0e10cSrcweir
160*cdf0e10cSrcweir    if ( -f "$outfile" ) {
161*cdf0e10cSrcweir        # changed script - run always
162*cdf0e10cSrcweir        return if (stat($0))[9] > (stat("$outfile"))[9] ;
163*cdf0e10cSrcweir        # changed template file - run always
164*cdf0e10cSrcweir        return if (stat($infile))[9] > (stat("$outfile"))[9] ;
165*cdf0e10cSrcweir
166*cdf0e10cSrcweir        open OLDFILE, "$outfile" or die "$0 - ERROR: $outfile exists but isn't readable.\n";
167*cdf0e10cSrcweir        while ( $line = <OLDFILE> ) {
168*cdf0e10cSrcweir            if ( $line =~ /^\/\/.*completelangiso:/ ) {
169*cdf0e10cSrcweir                $lastcompletelangiso_var = $line;
170*cdf0e10cSrcweir                chomp $lastcompletelangiso_var;
171*cdf0e10cSrcweir                $lastcompletelangiso_var =~ s/^\/\/.*completelangiso:\s*//;
172*cdf0e10cSrcweir                last;
173*cdf0e10cSrcweir            }
174*cdf0e10cSrcweir        }
175*cdf0e10cSrcweir        close OLDFILE;
176*cdf0e10cSrcweir    }
177*cdf0e10cSrcweir
178*cdf0e10cSrcweir}
179*cdf0e10cSrcweir
180*cdf0e10cSrcweirsub usage
181*cdf0e10cSrcweir{
182*cdf0e10cSrcweir    print STDERR "Generate language modules from language script particle template (*.sct file)\n";
183*cdf0e10cSrcweir    print STDERR "perl $0 [-verbose] -o outputfile -i inputfile\n";
184*cdf0e10cSrcweir    exit  1;
185*cdf0e10cSrcweir}
186