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 .
20 package pre2par
::work
;
24 use pre2par
::pathanalyzer
;
26 ############################################
27 # pre2par working module
28 ############################################
30 ############################################
31 # procedure to split a line, that contains
32 # more than one par file lines
33 ############################################
37 my ($line, $parfile) = @_;
39 while ( $line =~ /^((?:[^"]|\"(?:[^"\\]|\\.)*\")*?\;\s+)\s*(.*)$/ )
43 pre2par
::remover
::remove_leading_and_ending_whitespaces
(\
$oneline);
44 $oneline = $oneline . "\n";
45 push(@
{$parfile}, $oneline);
47 if ( $line =~ /^\s*End\s+(\w+.*$)/i )
50 push(@
{$parfile}, "End\n\n");
56 pre2par
::remover
::remove_leading_and_ending_whitespaces
(\
$line);
58 push(@
{$parfile}, $line);
60 if ( $line =~ /^\s*End\s*$/i ) { push(@
{$parfile}, "\n"); }
63 ###################################################################
64 # Preprocessing the pre file to split all lines with semicolon
65 ###################################################################
73 for ( my $i = 0; $i <= $#{$prefile}; $i++ )
75 my $oneline = ${$prefile}[$i];
76 if ( $oneline =~ /\;\s*\w+/ )
78 split_line
($oneline, \
@newprefile);
82 push(@newprefile, $oneline);
89 ############################################
90 # main working procedure
91 ############################################
99 my $iscodesection = 0;
100 my $ismultiliner = 0;
103 # Preprocessing the pre file to split all lines with semicolon
104 $prefile = preprocess_macros
($prefile);
106 for ( my $i = 0; $i <= $#{$prefile}; $i++ )
108 my $oneline = ${$prefile}[$i];
112 if ( $oneline =~ /^\s*\}\;\s*$/ )
116 else # nothing to do for code inside a code section
118 push(@parfile, $oneline);
123 if ( $oneline =~ /^\s*$/ ) { next; }
125 if ( $oneline =~ /^\s*Code\s+\=\s+\{/ )
130 pre2par
::remover
::remove_leading_and_ending_whitespaces
(\
$oneline);
132 my $insertemptyline = 0;
134 if ( $oneline =~ /^\s*End\s*$/i ) { $insertemptyline = 1; }
136 # Sometimes the complete file is in one line, then the gid line has to be separated
138 if ( $oneline =~ /^\s*(\w+\s+\w+)\s+(\w+\s+\=.*$)/ ) # three words before the equal sign
142 $gidline = $gidline . "\n";
144 push(@parfile, $gidline);
147 if ( $oneline =~ /\;\s*\w+/ )
149 split_line
($oneline, \
@parfile);
153 # searching for lines with brackets, like Customs = { ..., which can be parted above several lines
155 if ( $oneline =~ /^\s*\w+\s+\=\s*\(.*\)\s*\;\s*$/ ) # only one line
157 if (( ! ( $oneline =~ /^\s*Assignment\d+\s*\=/ )) && ( ! ( $oneline =~ /^\s*PatchAssignment\d+\s*\=/ )))
159 $oneline =~ s/\s//g; # removing whitespaces in lists
160 $oneline =~ s/\=/\ \=\ /; # adding whitespace around equals sign
164 if ( $oneline =~ /^\s*\w+\s+\=\s*$/ )
166 $oneline =~ s/\s*$//;
167 pre2par
::exiter
::exit_program
("Error: Illegal syntax, no line break after eqals sign allowed. Line: \"$oneline\"", "convert");
170 if (( $oneline =~ /^\s*\w+\s+\=\s*\(/ ) && (!( $oneline =~ /\)\s*\;\s*$/ ))) # several lines
174 $globalline .= $oneline;
175 next; # not including yet
181 $globalline .= $oneline;
183 if ( $oneline =~ /\)\s*\;\s*$/ ) { $ismultiliner = 0; }
185 if (! ( $ismultiliner ))
187 $globalline =~ s/\=/\ \=\ /; # adding whitespace around equals sign
189 push(@parfile, $globalline);
196 $oneline = $oneline . "\n";
198 $oneline =~ s/\s*\=\s*/ \= /; # nice, to have only one whitespace around equal signs
200 # Concatenate adjacent string literals:
204 (?
:[^"]*[^[:blank:]"][^"]*\"(?:[^\\"]|\\.)*\")*)*
212 push(@parfile, $oneline);
214 if ($insertemptyline) { push(@parfile, "\n"); }
221 ############################################
222 # formatting the par file
223 ############################################
229 my $iscodesection = 0;
232 my $isinsideitem = 0;
235 for ( my $i = 0; $i <= $#{$parfile}; $i++ )
237 my $oneline = ${$parfile}[$i];
240 if (! $isinsideitem )
242 for ( my $j = 0; $j <= $#pre2par::globals::allitems; $j++ )
244 if ( $oneline =~ /^\s*$pre2par::globals::allitems[$j]\s+\w+\s*$/ )
246 $currentitem = $pre2par::globals::allitems[$j];
257 next; # nothing to do
260 if ( $oneline =~ /^\s*end\s*$/i )
268 $oneline = "\t" . $oneline;
269 ${$parfile}[$i] = $oneline;
274 ###################################################
275 # Returning the language file name
276 ###################################################
280 return $pre2par::globals::langfilename;
283 ############################################
284 # Checking if a file exists
285 ############################################
289 my ($langfilename) = @_;
293 if( -f $langfilename ) { $fileexists = 1; }
298 ############################################
299 # Checking the existence of ulf file
300 ############################################
302 sub check_existence_of_langfiles
304 my ($langfilename) = @_;
308 if ( fileexists($langfilename) ) { $do_localize = 1; }
313 ############################################
314 # Checking that the pre file has content
315 ############################################
319 my ($filecontent, $filename) = @_;
321 if ( $#{$filecontent} < 0 ) { pre2par::exiter::exit_program("Error
: $filename has
no content
!", "check_content
"); }
324 ############################################
325 # Checking content of par files.
326 # Currently only size.
327 ############################################
331 my ($content1, $content2, $filename) = @_;
333 if ( $#{$content1} != $#{$content2} ) { pre2par::exiter::exit_program("Error
: $filename was
not saved correctly
!", "diff_content
"); }