1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: work.pm,v $
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 #*************************************************************************
33 package pre2par
::work
;
37 use pre2par
::pathanalyzer
;
39 ############################################
40 # pre2par working module
41 ############################################
43 ############################################
44 # procedure to split a line, that contains
45 # more than one par file lines
46 ############################################
50 my ($line, $parfile) = @_;
52 while ( $line =~ /^((?:[^"]|\"(?:[^"\\]|\\.)*\")*?\;\s+)\s*(.*)$/ )
56 pre2par
::remover
::remove_leading_and_ending_whitespaces
(\
$oneline);
57 $oneline = $oneline . "\n";
58 push(@
{$parfile}, $oneline);
60 if ( $line =~ /^\s*End\s+(\w+.*$)/i )
63 push(@
{$parfile}, "End\n\n");
69 pre2par
::remover
::remove_leading_and_ending_whitespaces
(\
$line);
71 push(@
{$parfile}, $line);
73 if ( $line =~ /^\s*End\s*$/i ) { push(@
{$parfile}, "\n"); }
76 ###################################################################
77 # Preprocessing the pre file to split all lines with semicolon
78 ###################################################################
86 for ( my $i = 0; $i <= $#{$prefile}; $i++ )
88 my $oneline = ${$prefile}[$i];
89 if ( $oneline =~ /\;\s*\w+/ )
91 split_line
($oneline, \
@newprefile);
95 push(@newprefile, $oneline);
102 ############################################
103 # main working procedure
104 ############################################
112 my $iscodesection = 0;
113 my $ismultiliner = 0;
116 # Preprocessing the pre file to split all lines with semicolon
117 $prefile = preprocess_macros
($prefile);
119 for ( my $i = 0; $i <= $#{$prefile}; $i++ )
121 my $oneline = ${$prefile}[$i];
125 if ( $oneline =~ /^\s*\}\;\s*$/ )
129 else # nothing to do for code inside a code section
131 push(@parfile, $oneline);
136 if ( $oneline =~ /^\s*$/ ) { next; }
138 if ( $oneline =~ /^\s*Code\s+\=\s+\{/ )
143 pre2par
::remover
::remove_leading_and_ending_whitespaces
(\
$oneline);
145 my $insertemptyline = 0;
147 if ( $oneline =~ /^\s*End\s*$/i ) { $insertemptyline = 1; }
149 # Sometimes the complete file is in one line, then the gid line has to be separated
151 if ( $oneline =~ /^\s*(\w+\s+\w+)\s+(\w+\s+\=.*$)/ ) # three words before the equal sign
155 $gidline = $gidline . "\n";
157 push(@parfile, $gidline);
160 if ( $oneline =~ /\;\s*\w+/ )
162 split_line
($oneline, \
@parfile);
166 # searching for lines with brackets, like Customs = { ..., which can be parted above several lines
168 if ( $oneline =~ /^\s*\w+\s+\=\s*\(.*\)\s*\;\s*$/ ) # only one line
170 if (( ! ( $oneline =~ /^\s*Assignment\d+\s*\=/ )) && ( ! ( $oneline =~ /^\s*PatchAssignment\d+\s*\=/ )))
172 $oneline =~ s/\s//g; # removing whitespaces in lists
173 $oneline =~ s/\=/\ \=\ /; # adding whitespace around equals sign
177 if ( $oneline =~ /^\s*\w+\s+\=\s*$/ )
179 $oneline =~ s/\s*$//;
180 pre2par
::exiter
::exit_program
("Error: Illegal syntax, no line break after eqals sign allowed. Line: \"$oneline\"", "convert");
183 if (( $oneline =~ /^\s*\w+\s+\=\s*\(/ ) && (!( $oneline =~ /\)\s*\;\s*$/ ))) # several lines
187 $globalline .= $oneline;
188 next; # not including yet
194 $globalline .= $oneline;
196 if ( $oneline =~ /\)\s*\;\s*$/ ) { $ismultiliner = 0; }
198 if (! ( $ismultiliner ))
200 $globalline =~ s/\=/\ \=\ /; # adding whitespace around equals sign
202 push(@parfile, $globalline);
209 $oneline = $oneline . "\n";
211 $oneline =~ s/\s*\=\s*/ \= /; # nice, to have only one whitespace around equal signs
213 # Concatenate adjacent string literals:
217 (?
:[^"]*[^[:blank:]"][^"]*\"(?:[^\\"]|\\.)*\")*)*
225 push(@parfile, $oneline);
227 if ($insertemptyline) { push(@parfile, "\n"); }
234 ############################################
235 # formatting the par file
236 ############################################
242 my $iscodesection = 0;
245 my $isinsideitem = 0;
248 for ( my $i = 0; $i <= $#{$parfile}; $i++ )
250 my $oneline = ${$parfile}[$i];
253 if (! $isinsideitem )
255 for ( my $j = 0; $j <= $#pre2par::globals::allitems; $j++ )
257 if ( $oneline =~ /^\s*$pre2par::globals::allitems[$j]\s+\w+\s*$/ )
259 $currentitem = $pre2par::globals::allitems[$j];
270 next; # nothing to do
273 if ( $oneline =~ /^\s*end\s*$/i )
281 $oneline = "\t" . $oneline;
282 ${$parfile}[$i] = $oneline;
287 ###################################################
288 # Returning the language file name
289 ###################################################
293 return $pre2par::globals::langfilename;
296 ###################################################
297 # Creating the ulf file name from the
298 # corresponding pre file name
299 ###################################################
303 my ($prefilename) = @_;
305 my $ulffilename = $prefilename;
306 $ulffilename =~ s/\.pre\s*$/\.ulf/;
307 pre2par::pathanalyzer::make_absolute_filename_to_relative_filename(\$ulffilename);
312 ############################################
313 # Checking if a file exists
314 ############################################
318 my ($langfilename) = @_;
322 if( -f $langfilename ) { $fileexists = 1; }
327 ############################################
328 # Checking the existence of ulf and
330 ############################################
332 sub check_existence_of_langfiles
334 my ($langfilename, $ulffilename) = @_;
338 if (( fileexists($ulffilename) ) && ( ! fileexists($langfilename) )) { pre2par::exiter::exit_program("Error
: Did
not find language file
$langfilename", "check_existence_of_langfiles
"); }
339 if (( fileexists($ulffilename) ) && ( fileexists($langfilename) )) { $do_localize = 1; }
344 ############################################
345 # Checking that the pre file has content
346 ############################################
350 my ($filecontent, $filename) = @_;
352 if ( $#{$filecontent} < 0 ) { pre2par::exiter::exit_program("Error
: $filename has
no content
!", "check_content
"); }
355 ############################################
356 # Checking content of par files.
357 # Currently only size.
358 ############################################
362 my ($content1, $content2, $filename) = @_;
364 if ( $#{$content1} != $#{$content2} ) { pre2par::exiter::exit_program("Error
: $filename was
not saved correctly
!", "diff_content
"); }