summaryrefslogtreecommitdiffstats
path: root/solenv/bin/modules/pre2par
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /solenv/bin/modules/pre2par
parentInitial commit. (diff)
downloadlibreoffice-upstream/4%7.4.7.tar.xz
libreoffice-upstream/4%7.4.7.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'solenv/bin/modules/pre2par')
-rw-r--r--solenv/bin/modules/pre2par/directory.pm45
-rw-r--r--solenv/bin/modules/pre2par/exiter.pm61
-rw-r--r--solenv/bin/modules/pre2par/files.pm55
-rw-r--r--solenv/bin/modules/pre2par/globals.pm51
-rw-r--r--solenv/bin/modules/pre2par/language.pm135
-rw-r--r--solenv/bin/modules/pre2par/parameter.pm144
-rw-r--r--solenv/bin/modules/pre2par/pathanalyzer.pm67
-rw-r--r--solenv/bin/modules/pre2par/remover.pm34
-rw-r--r--solenv/bin/modules/pre2par/systemactions.pm81
-rw-r--r--solenv/bin/modules/pre2par/work.pm297
10 files changed, 970 insertions, 0 deletions
diff --git a/solenv/bin/modules/pre2par/directory.pm b/solenv/bin/modules/pre2par/directory.pm
new file mode 100644
index 000000000..02cfed6f9
--- /dev/null
+++ b/solenv/bin/modules/pre2par/directory.pm
@@ -0,0 +1,45 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+package pre2par::directory;
+
+use pre2par::pathanalyzer;
+use pre2par::systemactions;
+
+############################################
+# Checking, whether the output directories
+# exist. If not, they are created.
+############################################
+
+sub check_directory
+{
+ my ($parfilename) = @_;
+
+ my $productdirectory = $parfilename;
+ pre2par::pathanalyzer::get_path_from_fullqualifiedname(\$productdirectory);
+ $productdirectory =~ s/\Q$pre2par::globals::separator\E\s*$//;
+
+ my $pardirectory = $productdirectory;
+ pre2par::pathanalyzer::get_path_from_fullqualifiedname(\$pardirectory);
+ $pardirectory =~ s/\Q$pre2par::globals::separator\E\s*$//;
+
+ if ( ! -d $pardirectory ) { pre2par::systemactions::create_directory($pardirectory); }
+ if ( ! -d $productdirectory ) { pre2par::systemactions::create_directory($productdirectory); }
+}
+
+1; \ No newline at end of file
diff --git a/solenv/bin/modules/pre2par/exiter.pm b/solenv/bin/modules/pre2par/exiter.pm
new file mode 100644
index 000000000..d07675ac4
--- /dev/null
+++ b/solenv/bin/modules/pre2par/exiter.pm
@@ -0,0 +1,61 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+package pre2par::exiter;
+
+use pre2par::files;
+use pre2par::globals;
+
+############################################
+# Exiting the program with an error
+# This function is used instead of "die"
+############################################
+
+sub exit_program
+{
+ my ($message, $function) = @_;
+
+ my $infoline;
+
+ $infoline = "\n***************************************************************\n";
+ push(@pre2par::globals::logfileinfo, $infoline);
+ print("$infoline");
+
+ $infoline = "$message\n";
+ push(@pre2par::globals::logfileinfo, $infoline);
+ print("$infoline");
+
+ $infoline = "in function: $function\n";
+ push(@pre2par::globals::logfileinfo, $infoline);
+ print("$infoline");
+
+ $infoline = "***************************************************************\n";
+ push(@pre2par::globals::logfileinfo, $infoline);
+
+ if ($pre2par::globals::logging)
+ {
+ pre2par::files::save_file($pre2par::globals::logfilename ,\@pre2par::globals::logfileinfo);
+ print("Saved logfile: $pre2par::globals::logfilename\n");
+ }
+
+ print("$infoline");
+
+ exit(-1);
+}
+
+1;
diff --git a/solenv/bin/modules/pre2par/files.pm b/solenv/bin/modules/pre2par/files.pm
new file mode 100644
index 000000000..ddc8d9157
--- /dev/null
+++ b/solenv/bin/modules/pre2par/files.pm
@@ -0,0 +1,55 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+package pre2par::files;
+
+use pre2par::exiter;
+
+############################################
+# File Operations
+############################################
+
+sub read_file
+{
+ my ($localfile) = @_;
+
+ my @localfile = ();
+
+ open( IN, "<$localfile" ) || pre2par::exiter::exit_program("ERROR: Cannot open file: $localfile", "read_file");
+ while ( <IN> ) { push(@localfile, $_); }
+ close( IN );
+
+ return \@localfile;
+}
+
+###########################################
+# Saving files
+###########################################
+
+sub save_file
+{
+ my ($savefile, $savecontent) = @_;
+ if (-f $savefile) { unlink $savefile };
+ if (-f $savefile) { pre2par::exiter::exit_program("ERROR: Cannot delete existing file: $savefile", "save_file"); };
+ open( OUT, ">$savefile" );
+ print OUT @{$savecontent};
+ close( OUT);
+ if (! -f $savefile) { pre2par::exiter::exit_program("ERROR: Cannot write file: $savefile", "save_file"); }
+}
+
+1;
diff --git a/solenv/bin/modules/pre2par/globals.pm b/solenv/bin/modules/pre2par/globals.pm
new file mode 100644
index 000000000..08d79b06b
--- /dev/null
+++ b/solenv/bin/modules/pre2par/globals.pm
@@ -0,0 +1,51 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+
+package pre2par::globals;
+
+############################################
+# Global settings
+############################################
+
+BEGIN
+{
+ $prog="pre2par";
+
+ $prefilename = "";
+ $parfilename = "";
+ $langfilename = "";
+
+ @allitems = ("Installation", "ScpAction", "HelpText", "Directory", "DataCarrier", "StarRegistry", "File",
+ "Shortcut", "Custom", "Unixlink", "Procedure", "Module", "Profile", "ProfileItem",
+ "Folder", "FolderItem", "FolderItemProperty", "RegistryItem", "StarRegistryItem",
+ "WindowsCustomAction", "MergeModule");
+
+ $logging = 0;
+ $logfilename = "logfile.log"; # the default logfile name for global errors
+ @logfileinfo = ();
+
+ $plat = $^O;
+
+ $separator = "/";
+ $pathseparator = "\:";
+ $isunix = 1;
+ $iswin = 0;
+}
+
+1;
diff --git a/solenv/bin/modules/pre2par/language.pm b/solenv/bin/modules/pre2par/language.pm
new file mode 100644
index 000000000..332bb985f
--- /dev/null
+++ b/solenv/bin/modules/pre2par/language.pm
@@ -0,0 +1,135 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+package pre2par::language;
+
+use strict;
+
+##############################################################
+# Returning a specific language string from the block
+# of all translations
+##############################################################
+
+sub get_language_string_from_language_block
+{
+ my ($language_block, $language) = @_;
+
+ my $newstring = "";
+
+ for ( my $i = 0; $i <= $#{$language_block}; $i++ )
+ {
+
+ if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
+ {
+ $newstring = $1;
+ $newstring = "\"" . $newstring . "\"";
+ last;
+ }
+ }
+
+ # defaulting to english!
+
+ if ( $newstring eq "" )
+ {
+ $language = "en-US"; # defaulting to english
+
+ for ( my $i = 0; $i <= $#{$language_block}; $i++ )
+ {
+ if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*(\".*\")\s*$/ )
+ {
+ $newstring = $1;
+ last;
+ }
+ }
+ }
+
+ return $newstring;
+}
+
+############################################
+# collecting all replace variables
+# in a language file
+############################################
+
+sub get_all_replace_variables
+{
+ my ($langfile) = @_;
+
+ my %allvars = ();
+
+ for ( my $i = 0; $i <= $#{$langfile}; $i++ )
+ {
+ if ( ${$langfile}[$i] =~ /^\s*\[\s*(.*?)\s*\]\s*$/ )
+ {
+ my $variable = $1;
+# print "lang block '$variable'\n";
+ my @lang_block = ();
+ my $counter;
+
+ # Store the complete block in all languages for a specified variable
+ for ( $counter = $i + 1; $counter <= $#{$langfile}; $counter++ ) {
+ my $line = ${$langfile}[$counter];
+ last if ($line =~ /^s*\[/); # next decl.
+ push @lang_block, $line;
+ }
+# print "$variable = '@lang_block'\n";
+ $allvars{$variable} = \@lang_block;
+ $i = $counter - 1;
+ }
+ }
+
+ return \%allvars;
+}
+
+############################################
+# localizing the par file with the
+# corresponding language file
+############################################
+
+sub localize
+{
+ my ($parfile, $langfile) = @_;
+
+ my $replace_hash = get_all_replace_variables($langfile);
+
+ # parse lines of the form Name (st) = STR_NAME_MODULE_HELPPACK_OC;
+ # for variable substitution
+ my $langlinere = qr/^\s*\w+\s*\(([\w-]+)\)\s*\=\s*([\w-]+)\s*;/;
+ for ( my $i = 0; $i <= $#{$parfile}; $i++ )
+ {
+ my $oneline = ${$parfile}[$i];
+
+ if ( $oneline =~ $langlinere) {
+ my $language = $1; # can be "01" or "en" or "en-US" or ...
+ my $variable = $2;
+
+# print "line '$oneline' split to '$language' '$variable'\n";
+
+ if (defined $replace_hash->{$variable}) {
+ my $newstring = get_language_string_from_language_block($replace_hash->{$variable}, $language);
+ if ( $newstring eq "" ) { $newstring = "\"" . $variable . "\""; }
+
+ $oneline =~ s/$variable/$newstring/g;
+
+ ${$parfile}[$i] = $oneline;
+ }
+ }
+ }
+}
+
+1;
diff --git a/solenv/bin/modules/pre2par/parameter.pm b/solenv/bin/modules/pre2par/parameter.pm
new file mode 100644
index 000000000..aa9fe3399
--- /dev/null
+++ b/solenv/bin/modules/pre2par/parameter.pm
@@ -0,0 +1,144 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+
+package pre2par::parameter;
+
+use Cwd;
+use pre2par::globals;
+use pre2par::systemactions;
+
+############################################
+# Parameter Operations
+############################################
+
+sub usage
+{
+ print <<End;
+---------------------------------------------------------
+$pre2par::globals::prog
+The following parameter are needed:
+-s: path to the pre file
+-o: path to the par file
+-l: path to the ulf file (mlf or jlf file)
+-v: log process (optional)
+
+Example:
+
+perl pre2par.pl -l test.mlf -s readme.pre -o readme.par -v
+
+---------------------------------------------------------
+End
+ exit(-1);
+}
+
+#####################################
+# Reading parameter
+#####################################
+
+sub getparameter
+{
+ while ( $#ARGV >= 0 )
+ {
+ my $param = shift(@ARGV);
+
+ if ($param eq "-s") { $pre2par::globals::prefilename = shift(@ARGV); }
+ elsif ($param eq "-o") { $pre2par::globals::parfilename = shift(@ARGV); }
+ elsif ($param eq "-l") { $pre2par::globals::langfilename = shift(@ARGV); }
+ elsif ($param eq "-v") { $pre2par::globals::logging = 1; }
+ else
+ {
+ print("\n*************************************\n");
+ print("Sorry, unknown parameter: $param");
+ print("\n*************************************\n");
+ usage();
+ exit(-1);
+ }
+ }
+}
+
+############################################
+# Controlling the fundamental parameter
+# (required for every process)
+############################################
+
+sub control_parameter
+{
+ if ($pre2par::globals::prefilename eq "")
+ {
+ print "\n************************************************\n";
+ print "Error: Name of the input file not set (-s)!";
+ print "\n************************************************\n";
+ usage();
+ exit(-1);
+ }
+
+ if (!(-f $pre2par::globals::prefilename))
+ {
+ print "\n************************************************\n";
+ print "Error: Input file does not exist!";
+ print "\n************************************************\n";
+ usage();
+ exit(-1);
+ }
+
+ if ($pre2par::globals::parfilename eq "")
+ {
+ print "\n************************************************\n";
+ print "Error: Name of the output file not set (-o)!";
+ print "\n************************************************\n";
+ usage();
+ exit(-1);
+ }
+
+ if (!($pre2par::globals::prefilename =~ /\.pre\s*$/))
+ {
+ print "\n************************************************\n";
+ print "Error: Input file is no .pre file!";
+ print "\n************************************************\n";
+ usage();
+ exit(-1);
+ }
+
+ if (!($pre2par::globals::parfilename =~ /\.par\s*$/))
+ {
+ print "\n************************************************\n";
+ print "Error: Output file is no .par file!";
+ print "\n************************************************\n";
+ usage();
+ exit(-1);
+ }
+}
+
+#####################################
+# Writing parameter to shell
+#####################################
+
+sub outputparameter
+{
+ $pre2par::globals::logging ? ($logoption = " -v") : ($logoption = "");
+ print "\n$pre2par::globals::prog -l $pre2par::globals::langfilename -s $pre2par::globals::prefilename -o $pre2par::globals::parfilename$logoption\n";
+
+# print "\n********************************************************\n";
+# print "This is $pre2par::globals::prog, version 1.0\n";
+# print "Input file: $pre2par::globals::prefilename\n";
+# print "Output file: $pre2par::globals::parfilename\n";
+# print "********************************************************\n";
+}
+
+1;
diff --git a/solenv/bin/modules/pre2par/pathanalyzer.pm b/solenv/bin/modules/pre2par/pathanalyzer.pm
new file mode 100644
index 000000000..4d2eb31ae
--- /dev/null
+++ b/solenv/bin/modules/pre2par/pathanalyzer.pm
@@ -0,0 +1,67 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+
+package pre2par::pathanalyzer;
+
+use pre2par::globals;
+
+###########################################
+# Path analyzer
+###########################################
+
+sub get_path_from_fullqualifiedname
+{
+ my ($longfilenameref) = @_;
+
+ if ( $$longfilenameref =~ /\Q$pre2par::globals::separator\E/ ) # Is there a separator in the path? Otherwise the path is empty.
+ {
+ if ( $$longfilenameref =~ /^\s*(\S.*\S\Q$pre2par::globals::separator\E)(\S.+?\S)/ )
+ {
+ $$longfilenameref = $1;
+ }
+ }
+ else
+ {
+ $$longfilenameref = ""; # there is no path
+ }
+}
+
+sub make_absolute_filename_to_relative_filename
+{
+ my ($longfilenameref) = @_;
+
+ if ( $pre2par::globals::isunix )
+ {
+ if ( $$longfilenameref =~ /^.*\/(?=\S)([^\/]+)(?<=\S)/ )
+ {
+ $$longfilenameref = $1;
+ }
+ }
+
+ if ( $pre2par::globals::iswin )
+ {
+ # Either '/' or '\'.
+ if ( $$longfilenameref =~ /^.*[\/\\](?=\S)([^\/\\]+)(?<=\S)/ )
+ {
+ $$longfilenameref = $1;
+ }
+ }
+}
+
+1;
diff --git a/solenv/bin/modules/pre2par/remover.pm b/solenv/bin/modules/pre2par/remover.pm
new file mode 100644
index 000000000..029d09a4e
--- /dev/null
+++ b/solenv/bin/modules/pre2par/remover.pm
@@ -0,0 +1,34 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+
+package pre2par::remover;
+
+############################################
+# Remover
+############################################
+
+sub remove_leading_and_ending_whitespaces
+{
+ my ( $stringref ) = @_;
+
+ $$stringref =~ s/^\s*//g;
+ $$stringref =~ s/\s*$//g;
+}
+
+1;
diff --git a/solenv/bin/modules/pre2par/systemactions.pm b/solenv/bin/modules/pre2par/systemactions.pm
new file mode 100644
index 000000000..7848b6495
--- /dev/null
+++ b/solenv/bin/modules/pre2par/systemactions.pm
@@ -0,0 +1,81 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+
+package pre2par::systemactions;
+
+use File::Copy;
+use pre2par::exiter;
+use pre2par::globals;
+
+######################################################
+# Creating a new directory
+######################################################
+
+sub create_directory
+{
+ my ($directory) = @_;
+
+ my $returnvalue = 1;
+ my $infoline = "";
+
+ if ($directory eq "" )
+ {
+ return 0;
+ }
+
+ if (!(-d $directory))
+ {
+ $returnvalue = mkdir($directory, 0775);
+
+ if ($returnvalue)
+ {
+ $infoline = "Created directory: $directory\n";
+ push(@pre2par::globals::logfileinfo, $infoline);
+
+ if ($pre2par::globals::isunix)
+ {
+ my $localcall = "chmod 775 $directory \>\/dev\/null 2\>\&1";
+ system($localcall);
+ }
+ }
+ else
+ {
+ # New solution in parallel packing: It is possible, that the directory now exists, although it
+ # was not created in this process. There is only an important error, if the directory does not
+ # exist now.
+
+ if (!(-d $directory))
+ {
+ pre2par::exiter::exit_program("Error: Could not create directory: $directory", "create_directory");
+ }
+ else
+ {
+ $infoline = "\nAnother process created this directory in exactly this moment :-) : $directory\n";
+ push(@pre2par::globals::logfileinfo, $infoline);
+ }
+ }
+ }
+ else
+ {
+ $infoline = "\nAlready existing directory, did not create: $directory\n";
+ push(@pre2par::globals::logfileinfo, $infoline);
+ }
+}
+
+1;
diff --git a/solenv/bin/modules/pre2par/work.pm b/solenv/bin/modules/pre2par/work.pm
new file mode 100644
index 000000000..6ee87ec37
--- /dev/null
+++ b/solenv/bin/modules/pre2par/work.pm
@@ -0,0 +1,297 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+
+package pre2par::work;
+
+use pre2par::exiter;
+use pre2par::remover;
+use pre2par::pathanalyzer;
+
+############################################
+# pre2par working module
+############################################
+
+############################################
+# procedure to split a line, that contains
+# more than one par file lines
+############################################
+
+sub split_line
+{
+ my ($line, $parfile) = @_;
+
+ while ( $line =~ /^((?:[^"]|\"(?:[^"\\]|\\.)*\")*?\;\s+)\s*(.*)$/ )
+ {
+ my $oneline = $1;
+ $line = $2;
+ pre2par::remover::remove_leading_and_ending_whitespaces(\$oneline);
+ $oneline = $oneline . "\n";
+ push(@{$parfile}, $oneline);
+
+ if ( $line =~ /^\s*End\s+(\w+.*$)/i )
+ {
+ $line = $1;
+ push(@{$parfile}, "End\n\n");
+ }
+ }
+
+ # the last line
+
+ pre2par::remover::remove_leading_and_ending_whitespaces(\$line);
+ $line = $line . "\n";
+ push(@{$parfile}, $line);
+
+ if ( $line =~ /^\s*End\s*$/i ) { push(@{$parfile}, "\n"); }
+}
+
+###################################################################
+# Preprocessing the pre file to split all lines with semicolon
+###################################################################
+
+sub preprocess_macros
+{
+ my ($prefile) = @_;
+
+ my @newprefile = ();
+
+ for ( my $i = 0; $i <= $#{$prefile}; $i++ )
+ {
+ my $oneline = ${$prefile}[$i];
+ if ( $oneline =~ /\;\s*\w+/ )
+ {
+ split_line($oneline, \@newprefile);
+ }
+ else
+ {
+ push(@newprefile, $oneline);
+ }
+ }
+
+ return \@newprefile;
+}
+
+############################################
+# main working procedure
+############################################
+
+sub convert
+{
+ my ($prefile) = @_;
+
+ my @parfile = ();
+
+ my $iscodesection = 0;
+ my $ismultiliner = 0;
+ my $globalline = "";
+
+ # Preprocessing the pre file to split all lines with semicolon
+ $prefile = preprocess_macros($prefile);
+
+ for ( my $i = 0; $i <= $#{$prefile}; $i++ )
+ {
+ my $oneline = ${$prefile}[$i];
+
+ if ($iscodesection)
+ {
+ if ( $oneline =~ /^\s*\}\;\s*$/ )
+ {
+ $iscodesection = 0;
+ }
+ else # nothing to do for code inside a code section
+ {
+ push(@parfile, $oneline);
+ next;
+ }
+ }
+
+ if ( $oneline =~ /^\s*$/ ) { next; }
+
+ if ( $oneline =~ /^\s*Code\s+\=\s+\{/ )
+ {
+ $iscodesection = 1;
+ }
+
+ pre2par::remover::remove_leading_and_ending_whitespaces(\$oneline);
+
+ my $insertemptyline = 0;
+
+ if ( $oneline =~ /^\s*End\s*$/i ) { $insertemptyline = 1; }
+
+ # Sometimes the complete file is in one line, then the gid line has to be separated
+
+ if ( $oneline =~ /^\s*(\w+\s+\w+)\s+(\w+\s+\=.*$)/ ) # three words before the equal sign
+ {
+ my $gidline = $1;
+ $oneline = $2;
+ $gidline = $gidline . "\n";
+
+ push(@parfile, $gidline);
+ }
+
+ if ( $oneline =~ /\;\s*\w+/ )
+ {
+ split_line($oneline, \@parfile);
+ next;
+ }
+
+ # searching for lines with brackets, like Customs = { ..., which can be parted above several lines
+
+ if ( $oneline =~ /^\s*\w+\s+\=\s*\(.*\)\s*\;\s*$/ ) # only one line
+ {
+ if (( ! ( $oneline =~ /^\s*Assignment\d+\s*\=/ )) && ( ! ( $oneline =~ /^\s*PatchAssignment\d+\s*\=/ )))
+ {
+ $oneline =~ s/\s//g; # removing whitespaces in lists
+ $oneline =~ s/\=/\ \=\ /; # adding whitespace around equals sign
+ }
+ }
+
+ if ( $oneline =~ /^\s*\w+\s+\=\s*$/ )
+ {
+ $oneline =~ s/\s*$//;
+ pre2par::exiter::exit_program("Error: Illegal syntax, no line break after eqals sign allowed. Line: \"$oneline\"", "convert");
+ }
+
+ if (( $oneline =~ /^\s*\w+\s+\=\s*\(/ ) && (!( $oneline =~ /\)\s*\;\s*$/ ))) # several lines
+ {
+ $ismultiliner = 1;
+ $oneline =~ s/\s//g;
+ $globalline .= $oneline;
+ next; # not including yet
+ }
+
+ if ( $ismultiliner )
+ {
+ $oneline =~ s/\s//g;
+ $globalline .= $oneline;
+
+ if ( $oneline =~ /\)\s*\;\s*$/ ) { $ismultiliner = 0; }
+
+ if (! ( $ismultiliner ))
+ {
+ $globalline =~ s/\=/\ \=\ /; # adding whitespace around equals sign
+ $globalline .= "\n";
+ push(@parfile, $globalline);
+ $globalline = "";
+ }
+
+ next;
+ }
+
+ $oneline = $oneline . "\n";
+
+ $oneline =~ s/\s*\=\s*/ \= /; # nice, to have only one whitespace around equal signs
+
+ # Concatenate adjacent string literals:
+ while ($oneline =~
+ s/^((?:[^"]*
+ \"(?:[^\\"]|\\.)*\"
+ (?:[^"]*[^[:blank:]"][^"]*\"(?:[^\\"]|\\.)*\")*)*
+ [^"]*
+ \"(?:[^\\"]|\\.)*)
+ \"[[:blank:]]*\"
+ ((?:[^\\"]|\\.)*\")
+ /\1\2/x)
+ {}
+
+ push(@parfile, $oneline);
+
+ if ($insertemptyline) { push(@parfile, "\n"); }
+
+ }
+
+ return \@parfile;
+}
+
+############################################
+# formatting the par file
+############################################
+
+sub formatter
+{
+ my ($parfile) = @_;
+
+ my $iscodesection = 0;
+
+ my $tabcounter = 0;
+ my $isinsideitem = 0;
+ my $currentitem;
+
+ for ( my $i = 0; $i <= $#{$parfile}; $i++ )
+ {
+ my $oneline = ${$parfile}[$i];
+ my $isitemline = 0;
+
+ if (! $isinsideitem )
+ {
+ for ( my $j = 0; $j <= $#pre2par::globals::allitems; $j++ )
+ {
+ if ( $oneline =~ /^\s*$pre2par::globals::allitems[$j]\s+\w+\s*$/ )
+ {
+ $currentitem = $pre2par::globals::allitems[$j];
+ $isitemline = 1;
+ $isinsideitem = 1;
+ $tabcounter = 0;
+ last;
+ }
+ }
+ }
+
+ if ( $isitemline )
+ {
+ next; # nothing to do
+ }
+
+ if ( $oneline =~ /^\s*end\s*$/i )
+ {
+ $isinsideitem = 0;
+ $tabcounter--;
+ }
+
+ if ( $isinsideitem )
+ {
+ $oneline = "\t" . $oneline;
+ ${$parfile}[$i] = $oneline;
+ }
+ }
+}
+
+############################################
+# Checking that the pre file has content
+############################################
+
+sub check_content
+{
+ my ($filecontent, $filename) = @_;
+
+ if ( $#{$filecontent} < 0 ) { pre2par::exiter::exit_program("Error: $filename has no content!", "check_content"); }
+}
+
+############################################
+# Checking content of par files.
+# Currently only size.
+############################################
+
+sub diff_content
+{
+ my ($content1, $content2, $filename) = @_;
+
+ if ( $#{$content1} != $#{$content2} ) { pre2par::exiter::exit_program("Error: $filename was not saved correctly!", "diff_content"); }
+}
+
+1;