2013-11-17 22:17:27 +00:00
|
|
|
#! /usr/bin/env perl
|
|
|
|
# -*- mode: perl; -*-
|
|
|
|
#
|
|
|
|
# file useSystemFonts.pl
|
|
|
|
# 1.) Copies lyx-files to another location
|
|
|
|
# 2.) While copying,
|
|
|
|
# 2a.) searches for relative references to files and
|
|
|
|
# replaces them with absolute ones
|
2019-02-03 21:16:35 +00:00
|
|
|
# 2b.) Changes default fonts to use non-tex-fonts
|
2013-11-17 22:17:27 +00:00
|
|
|
#
|
|
|
|
# Syntax: perl useSystemFonts.pl sourceFile destFile format
|
|
|
|
# Each param represents a path to a file
|
|
|
|
# sourceFile: full path to a lyx file
|
|
|
|
# destFile: destination path
|
|
|
|
# Each subdocument will be copied into a subdirectory of dirname(destFile)
|
|
|
|
# format: any string of the form '[a-zA-Z0-9]+', e.g. pdf5
|
|
|
|
#
|
|
|
|
# This file is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This software is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public
|
|
|
|
# License along with this software; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
# Copyright (c) 2013 Kornel Benko <kornel@lyx.org>
|
|
|
|
# (c) 2013 Scott Kostyshak <skotysh@lyx.org>
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
use File::Spec;
|
|
|
|
my $p = File::Spec->rel2abs( __FILE__ );
|
|
|
|
$p =~ s/[\/\\]?[^\/\\]+$//;
|
|
|
|
unshift(@INC, "$p");
|
|
|
|
}
|
|
|
|
use File::Basename;
|
|
|
|
use File::Path;
|
|
|
|
use File::Copy "cp";
|
|
|
|
use File::Temp qw/ :POSIX /;
|
|
|
|
use lyxStatus;
|
|
|
|
|
2014-01-10 11:34:40 +00:00
|
|
|
# Prototypes
|
|
|
|
sub printCopiedDocuments($);
|
|
|
|
sub interpretedCopy($$$$);
|
|
|
|
sub copyFoundSubdocuments($);
|
|
|
|
sub copyJob($$);
|
|
|
|
sub isrelativeFix($$$);
|
|
|
|
sub isrelative($$$);
|
2019-03-24 21:12:07 +00:00
|
|
|
sub createTemporaryFileName($$$);
|
2014-01-10 11:34:40 +00:00
|
|
|
sub copyJobPending($$);
|
|
|
|
sub addNewJob($$$$$);
|
2019-03-24 21:12:07 +00:00
|
|
|
sub addFileCopyJob($$$$$);
|
2014-01-10 11:34:40 +00:00
|
|
|
sub getNewNameOf($$);
|
2015-11-10 18:42:43 +00:00
|
|
|
sub getlangs($$);
|
2015-11-12 20:42:43 +00:00
|
|
|
sub simplifylangs($);
|
2015-11-10 18:42:43 +00:00
|
|
|
sub getLangEntry();
|
2014-01-10 11:34:40 +00:00
|
|
|
|
2013-11-17 22:17:27 +00:00
|
|
|
# convert lyx file to be compilable with xetex
|
|
|
|
|
2016-11-09 23:56:49 +00:00
|
|
|
my ($source, $dest, $format, $fontT, $encodingT, $languageFile, $rest) = @ARGV;
|
2015-11-10 18:42:43 +00:00
|
|
|
my %encodings = (); # Encoding with TeX fonts, depending on language tag
|
2013-11-17 22:17:27 +00:00
|
|
|
|
2014-01-10 11:34:40 +00:00
|
|
|
diestack("Too many arguments") if (defined($rest));
|
|
|
|
diestack("Sourcefilename not defined") if (! defined($source));
|
|
|
|
diestack("Destfilename not defined") if (! defined($dest));
|
2014-03-10 12:39:31 +00:00
|
|
|
diestack("Format (e.g. pdf4) not defined") if (! defined($format));
|
2014-01-10 11:34:40 +00:00
|
|
|
diestack("Font type (e.g. texF) not defined") if (! defined($fontT));
|
2016-11-09 23:56:49 +00:00
|
|
|
diestack("Encoding (e.g. ascii) not defined") if (! defined($encodingT));
|
2013-11-17 22:17:27 +00:00
|
|
|
|
2013-11-18 11:25:18 +00:00
|
|
|
$source = File::Spec->rel2abs($source);
|
|
|
|
$dest = File::Spec->rel2abs($dest);
|
2013-11-17 22:17:27 +00:00
|
|
|
|
|
|
|
my %font = ();
|
2013-12-16 10:36:36 +00:00
|
|
|
my $lang = "main";
|
2015-11-09 11:20:57 +00:00
|
|
|
if ($source =~ /\/([a-z][a-z](_[A-Z][A-Z])?)[\/_]/) {
|
2013-12-16 10:36:36 +00:00
|
|
|
$lang = $1;
|
2013-11-17 22:17:27 +00:00
|
|
|
}
|
2015-11-09 11:20:57 +00:00
|
|
|
|
2015-11-10 12:01:49 +00:00
|
|
|
my $inputEncoding = undef;
|
2013-12-16 10:36:36 +00:00
|
|
|
if ($fontT eq "systemF") {
|
2013-11-17 22:17:27 +00:00
|
|
|
}
|
2016-11-09 23:56:49 +00:00
|
|
|
elsif ($encodingT ne "default") {
|
|
|
|
# set input encoding to the requested value
|
|
|
|
$inputEncoding = {
|
|
|
|
"search" => '.*', # this will be substituted from '\inputencoding'-line
|
|
|
|
"out" => $encodingT,
|
|
|
|
};
|
|
|
|
}
|
2015-12-14 18:05:18 +00:00
|
|
|
elsif (0) { # set to '1' to enable setting of inputencoding
|
2013-12-16 10:36:36 +00:00
|
|
|
# use tex font here
|
2015-11-10 18:42:43 +00:00
|
|
|
my %encoding = ();
|
|
|
|
if (defined($languageFile)) {
|
2015-11-12 20:42:43 +00:00
|
|
|
# The 2 lines below does not seem to have any effect
|
|
|
|
#&getlangs($languageFile, \%encoding);
|
|
|
|
#&simplifylangs(\%encoding);
|
2015-11-10 18:42:43 +00:00
|
|
|
}
|
2015-11-10 12:01:49 +00:00
|
|
|
if ($format =~ /^(pdf4)$/) { # xelatex
|
|
|
|
# set input encoding to 'ascii' always
|
|
|
|
$inputEncoding = {
|
|
|
|
"search" => '.*', # this will be substituted from '\inputencoding'-line
|
|
|
|
"out" => "ascii",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
elsif ($format =~ /^(dvi3|pdf5)$/) { # (dvi)?lualatex
|
|
|
|
# when to set input encoding to 'ascii'?
|
2015-11-10 18:42:43 +00:00
|
|
|
if (defined($encoding{$lang})) {
|
|
|
|
$inputEncoding = {
|
2015-11-12 20:42:43 +00:00
|
|
|
"search" => '.*', # this will be substituted from '\inputencoding'-line
|
2015-11-10 18:42:43 +00:00
|
|
|
"out" => $encoding{$lang},
|
|
|
|
};
|
|
|
|
}
|
2015-11-10 12:01:49 +00:00
|
|
|
}
|
2013-11-17 22:17:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my $sourcedir = dirname($source);
|
|
|
|
my $destdir = dirname($dest);
|
|
|
|
if (! -d $destdir) {
|
2016-09-15 19:55:47 +00:00
|
|
|
diestack("could not make dir \"$destdir\"") if (! mkpath $destdir);
|
2013-11-17 22:17:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my $destdirOfSubdocuments;
|
|
|
|
{
|
|
|
|
my ($name, $pat, $suffix) = fileparse($source, qr/\.[^.]*/);
|
2019-03-24 21:12:07 +00:00
|
|
|
my $ext = $format . "-$lang";
|
2019-03-25 17:46:15 +00:00
|
|
|
$name =~ s/[%_]/-/g;
|
2019-03-24 21:12:07 +00:00
|
|
|
$destdirOfSubdocuments = "$destdir/tmp-$ext" . "-$name"; # Global var, something TODO here
|
2013-11-17 22:17:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(-d $destdirOfSubdocuments) {
|
|
|
|
rmtree($destdirOfSubdocuments);
|
|
|
|
}
|
2016-11-09 23:56:49 +00:00
|
|
|
mkpath($destdirOfSubdocuments); # for possibly included files
|
2013-11-17 22:17:27 +00:00
|
|
|
|
|
|
|
my %IncludedFiles = ();
|
|
|
|
my %type2hash = (
|
|
|
|
"copy_only" => "copyonly",
|
|
|
|
"interpret" => "interpret");
|
|
|
|
|
2014-01-10 11:34:40 +00:00
|
|
|
addNewJob($source, $dest, "interpret", {}, \%IncludedFiles);
|
2013-11-17 22:17:27 +00:00
|
|
|
|
2014-01-10 11:34:40 +00:00
|
|
|
copyFoundSubdocuments(\%IncludedFiles);
|
2013-11-17 22:17:27 +00:00
|
|
|
|
2014-01-10 11:34:40 +00:00
|
|
|
#printCopiedDocuments(\%IncludedFiles);
|
2013-11-17 22:17:27 +00:00
|
|
|
|
|
|
|
exit(0);
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
sub printCopiedDocuments($)
|
|
|
|
{
|
|
|
|
my ($rFiles) = @_;
|
|
|
|
for my $k (keys %{$rFiles}) {
|
|
|
|
my $rJob = $rFiles->{$k};
|
|
|
|
for my $j ( values %type2hash) {
|
|
|
|
if (defined($rJob->{$j})) {
|
|
|
|
print "$j: $k->$rJob->{$j}, " . $rJob->{$j . "copied"} . "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub interpretedCopy($$$$)
|
|
|
|
{
|
|
|
|
my ($source, $dest, $destdirOfSubdocuments, $rFiles) = @_;
|
|
|
|
my $sourcedir = dirname($source);
|
|
|
|
my $res = 0;
|
|
|
|
|
2014-01-10 11:34:40 +00:00
|
|
|
diestack("could not read \"$source\"") if (!open(FI, $source));
|
|
|
|
diestack("could not write \"$dest\"") if (! open(FO, '>', $dest));
|
2013-11-17 22:17:27 +00:00
|
|
|
|
2015-11-10 12:01:49 +00:00
|
|
|
initLyxStack(\%font, $fontT, $inputEncoding);
|
2013-11-17 22:17:27 +00:00
|
|
|
|
2017-10-27 11:22:17 +00:00
|
|
|
my $fi_line_no = 0;
|
|
|
|
my @path_errors = ();
|
2013-11-17 22:17:27 +00:00
|
|
|
while (my $l = <FI>) {
|
2017-10-27 11:22:17 +00:00
|
|
|
$fi_line_no += 1;
|
2015-12-29 18:12:08 +00:00
|
|
|
$l =~ s/[\n\r]+$//;
|
|
|
|
#chomp($l);
|
2019-03-31 16:06:40 +00:00
|
|
|
my $rStatus = checkLyxLine($l, $sourcedir);
|
2013-11-17 22:17:27 +00:00
|
|
|
if ($rStatus->{found}) {
|
|
|
|
my $rF = $rStatus->{result};
|
|
|
|
if ($rStatus->{"filetype"} eq "replace_only") {
|
|
|
|
# e.g. if no files involved (font chage etc)
|
|
|
|
$l = join('', @{$rF});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
my $filelist = $rStatus->{filelist};
|
|
|
|
my $fidx = $rStatus->{fileidx};
|
|
|
|
my $separator = $rStatus->{"separator"};
|
|
|
|
my $foundrelative = 0;
|
|
|
|
for my $f (@{$filelist}) {
|
2014-01-10 11:34:40 +00:00
|
|
|
my @isrel = isrelative($f,
|
2013-11-17 22:17:27 +00:00
|
|
|
$sourcedir,
|
|
|
|
$rStatus->{ext});
|
|
|
|
if ($isrel[0]) {
|
|
|
|
$foundrelative = 1;
|
|
|
|
my $ext = $isrel[1];
|
|
|
|
if ($rStatus->{"filetype"} eq "prefix_only") {
|
2014-01-10 11:34:40 +00:00
|
|
|
$f = getNewNameOf("$sourcedir/$f", $rFiles);
|
2013-11-17 22:17:27 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
my ($newname, $res1);
|
2019-03-24 21:12:07 +00:00
|
|
|
my @extlist = ();
|
2019-03-25 17:46:15 +00:00
|
|
|
if (ref($rStatus->{ext}) eq "ARRAY") {
|
|
|
|
my @extlist = @{$rStatus->{ext}};
|
|
|
|
my $created = 0;
|
|
|
|
for my $extx (@extlist) {
|
|
|
|
if (-e "$sourcedir/$f$extx") {
|
|
|
|
($newname, $res1) = addFileCopyJob("$sourcedir/$f$extx",
|
|
|
|
"$destdirOfSubdocuments",
|
|
|
|
$rStatus->{"filetype"},
|
|
|
|
$rFiles, $created);
|
|
|
|
print "Added ($res1) file \"$sourcedir/$f$extx\" to be copied to \"$newname\"\n";
|
|
|
|
if (!$created && $extx ne "") {
|
|
|
|
$newname =~ s/$extx$//;
|
|
|
|
}
|
|
|
|
$created = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print "WARNING: No prefixed file.(" . join('|', @extlist) . ") seens to exist, at \"$source:$fi_line_no\"\n" if (!$created);
|
2019-03-24 21:12:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-03-25 17:46:15 +00:00
|
|
|
($newname, $res1) = addFileCopyJob("$sourcedir/$f$ext",
|
2013-11-17 22:17:27 +00:00
|
|
|
"$destdirOfSubdocuments",
|
|
|
|
$rStatus->{"filetype"},
|
2019-03-25 17:46:15 +00:00
|
|
|
$rFiles, 0);
|
|
|
|
print "Added ($res1) file \"$sourcedir/$f$ext\" to be copied to \"$newname\"\n";
|
|
|
|
if ($ext ne "") {
|
|
|
|
$newname =~ s/$ext$//;
|
|
|
|
}
|
2019-03-24 21:12:07 +00:00
|
|
|
}
|
2013-11-17 22:17:27 +00:00
|
|
|
$f = $newname;
|
|
|
|
$res += $res1;
|
|
|
|
}
|
|
|
|
}
|
2017-10-26 19:48:33 +00:00
|
|
|
else {
|
|
|
|
if (! -e "$f") {
|
|
|
|
# Non relative (e.g. with absolute path) file should exist
|
2017-10-27 11:22:17 +00:00
|
|
|
if ($rStatus->{"filetype"} eq "interpret") {
|
|
|
|
# filetype::interpret should be interpreted by lyx or latex and therefore emit error
|
|
|
|
# We prinnt a warning instead
|
|
|
|
print "WARNING: Interpreted file \"$f\" not found, at \"$source:$fi_line_no\"\n";
|
|
|
|
}
|
|
|
|
elsif ($rStatus->{"filetype"} eq "prefix_only") {
|
|
|
|
# filetype::prefix_only should be interpreted by latex
|
|
|
|
print "WARNING: Prefixed file \"$f\" not found, at \"$source:$fi_line_no\"\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
# Collect the path-error-messages
|
|
|
|
push(@path_errors, "File \"$f(" . $rStatus->{"filetype"} . ")\" not found, at \"$source:$fi_line_no\"");
|
|
|
|
}
|
2017-10-26 19:48:33 +00:00
|
|
|
}
|
|
|
|
}
|
2013-11-17 22:17:27 +00:00
|
|
|
}
|
2019-03-31 16:06:40 +00:00
|
|
|
if ($foundrelative && $rStatus->{"filetype"} !~ /^(prefix_for_list|prefix_only)$/) {
|
2019-03-24 21:12:07 +00:00
|
|
|
# The result can be relative too
|
2019-03-31 09:34:14 +00:00
|
|
|
# but, since prefix_for_list does no copy, we have to use absolute paths
|
|
|
|
# to address files inside the source dir
|
2019-03-24 21:12:07 +00:00
|
|
|
my @rel_list = ();
|
|
|
|
for my $fr (@{$filelist}) {
|
|
|
|
push(@rel_list, File::Spec->abs2rel($fr, $destdir));
|
|
|
|
}
|
2019-03-25 17:46:15 +00:00
|
|
|
$rF->[$fidx] = join($separator, @rel_list);
|
2013-11-17 22:17:27 +00:00
|
|
|
$l = join('', @{$rF});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print FO "$l\n";
|
|
|
|
}
|
|
|
|
close(FI);
|
|
|
|
close(FO);
|
2017-10-27 11:22:17 +00:00
|
|
|
if (@path_errors > 0) {
|
|
|
|
for my $entry (@path_errors) {
|
|
|
|
print "ERROR: $entry\n";
|
|
|
|
}
|
|
|
|
diestack("Aborted because of path errors in \"$source\"");
|
|
|
|
}
|
2013-11-17 22:17:27 +00:00
|
|
|
|
2014-01-10 11:34:40 +00:00
|
|
|
closeLyxStack();
|
2013-11-17 22:17:27 +00:00
|
|
|
return($res);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub copyFoundSubdocuments($)
|
|
|
|
{
|
|
|
|
my ($rFiles) = @_;
|
|
|
|
my $res = 0;
|
|
|
|
do {
|
|
|
|
$res = 0;
|
|
|
|
my %copylist = ();
|
|
|
|
|
|
|
|
for my $filename (keys %{$rFiles}) {
|
2014-01-10 11:34:40 +00:00
|
|
|
next if (! copyJobPending($filename, $rFiles));
|
2013-11-17 22:17:27 +00:00
|
|
|
$copylist{$filename} = 1;
|
|
|
|
}
|
|
|
|
for my $f (keys %copylist) {
|
|
|
|
# Second loop needed, because here $rFiles may change
|
2014-01-10 11:34:40 +00:00
|
|
|
my ($res1, @destfiles) = copyJob($f, $rFiles);
|
2013-11-17 22:17:27 +00:00
|
|
|
$res += $res1;
|
|
|
|
for my $destfile (@destfiles) {
|
|
|
|
print "res1 = $res1 for \"$f\" to be copied to $destfile\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while($res > 0); # loop, while $rFiles changed
|
|
|
|
}
|
|
|
|
|
|
|
|
sub copyJob($$)
|
|
|
|
{
|
|
|
|
my ($source, $rFiles) = @_;
|
|
|
|
my $sourcedir = dirname($source);
|
|
|
|
my $res = 0;
|
|
|
|
my @dest = ();
|
|
|
|
|
|
|
|
for my $k (values %type2hash) {
|
|
|
|
if ($rFiles->{$source}->{$k}) {
|
|
|
|
if (! $rFiles->{$source}->{$k . "copied"}) {
|
2019-03-25 17:46:15 +00:00
|
|
|
$rFiles->{$source}->{$k . "copied"} = 1;
|
|
|
|
my $dest = $rFiles->{$source}->{$k};
|
|
|
|
push(@dest, $dest);
|
|
|
|
if ($k eq "copyonly") {
|
|
|
|
diestack("Could not copy \"$source\" to \"$dest\"") if (! cp($source, $dest));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
interpretedCopy($source, $dest, $destdirOfSubdocuments, $rFiles);
|
|
|
|
}
|
|
|
|
$res += 1;
|
2013-11-17 22:17:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return($res, @dest);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Trivial check
|
|
|
|
sub isrelativeFix($$$)
|
|
|
|
{
|
|
|
|
my ($f, $sourcedir, $ext) = @_;
|
|
|
|
|
|
|
|
return(1, $ext) if (-e "$sourcedir/$f$ext");
|
|
|
|
return(0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub isrelative($$$)
|
|
|
|
{
|
|
|
|
my ($f, $sourcedir, $ext) = @_;
|
|
|
|
|
|
|
|
if (ref($ext) eq "ARRAY") {
|
|
|
|
for my $ext2 (@{$ext}) {
|
2014-01-10 11:34:40 +00:00
|
|
|
my @res = isrelativeFix($f, $sourcedir, $ext2);
|
2013-11-17 22:17:27 +00:00
|
|
|
if ($res[0]) {
|
|
|
|
return(@res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(0,0);
|
|
|
|
}
|
|
|
|
else {
|
2014-01-10 11:34:40 +00:00
|
|
|
return(isrelativeFix($f, $sourcedir, $ext));
|
2013-11-17 22:17:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 21:12:07 +00:00
|
|
|
my $oldfname = "";
|
|
|
|
|
|
|
|
sub createTemporaryFileName($$$)
|
2013-11-17 22:17:27 +00:00
|
|
|
{
|
2019-03-24 21:12:07 +00:00
|
|
|
my ($source, $destdir, $created) = @_;
|
2013-11-17 22:17:27 +00:00
|
|
|
|
|
|
|
# get the basename to be used for the template
|
|
|
|
my ($name, $path, $suffix) = fileparse($source, qr/\.[^.]*/);
|
|
|
|
#print "source = $source, name = $name, path = $path, suffix = $suffix\n";
|
2019-03-24 21:12:07 +00:00
|
|
|
my $template = "xx-$name" . "-";
|
|
|
|
my $fname;
|
|
|
|
if (! $created) {
|
|
|
|
$fname = File::Temp::tempnam($destdir, $template);
|
|
|
|
$oldfname = $fname;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$fname = $oldfname;
|
|
|
|
}
|
2013-11-17 22:17:27 +00:00
|
|
|
|
|
|
|
# Append extension from source
|
|
|
|
if ($suffix ne "") {
|
|
|
|
$fname .= "$suffix";
|
|
|
|
}
|
|
|
|
return($fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check, if file not copied yet
|
|
|
|
sub copyJobPending($$)
|
|
|
|
{
|
|
|
|
my ($f, $rFiles) = @_;
|
|
|
|
for my $t (values %type2hash) {
|
|
|
|
if (defined($rFiles->{$f}->{$t})) {
|
|
|
|
return 1 if (! $rFiles->{$f}->{$t . "copied"});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-10 11:34:40 +00:00
|
|
|
sub addNewJob($$$$$)
|
2013-11-17 22:17:27 +00:00
|
|
|
{
|
|
|
|
my ($source, $newname, $hashname, $rJob, $rFiles) = @_;
|
|
|
|
|
|
|
|
$rJob->{$hashname} = $newname;
|
|
|
|
$rJob->{$hashname . "copied"} = 0;
|
|
|
|
$rFiles->{$source} = $rJob;
|
|
|
|
}
|
|
|
|
|
2019-03-24 21:12:07 +00:00
|
|
|
sub addFileCopyJob($$$$$)
|
2013-11-17 22:17:27 +00:00
|
|
|
{
|
2019-03-24 21:12:07 +00:00
|
|
|
my ($source, $destdirOfSubdocuments, $filetype, $rFiles, $created) = @_;
|
2013-11-17 22:17:27 +00:00
|
|
|
my ($res, $newname) = (0, undef);
|
|
|
|
my $rJob = $rFiles->{$source};
|
|
|
|
|
|
|
|
my $hashname = $type2hash{$filetype};
|
|
|
|
if (! defined($hashname)) {
|
2014-01-10 11:34:40 +00:00
|
|
|
diestack("unknown filetype \"$filetype\"");
|
2013-11-17 22:17:27 +00:00
|
|
|
}
|
|
|
|
if (!defined($rJob->{$hashname})) {
|
2014-01-10 11:34:40 +00:00
|
|
|
addNewJob($source,
|
2019-03-25 17:46:15 +00:00
|
|
|
createTemporaryFileName($source, $destdirOfSubdocuments, $created),
|
2013-11-17 22:17:27 +00:00
|
|
|
"$hashname", $rJob, $rFiles);
|
|
|
|
$res = 1;
|
|
|
|
}
|
|
|
|
$newname = $rJob->{$hashname};
|
|
|
|
return($newname, $res);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub getNewNameOf($$)
|
|
|
|
{
|
|
|
|
my ($f, $rFiles) = @_;
|
|
|
|
my $resultf = $f;
|
|
|
|
|
|
|
|
if (defined($rFiles->{$f})) {
|
|
|
|
for my $t (values %type2hash) {
|
|
|
|
if (defined($rFiles->{$f}->{$t})) {
|
|
|
|
$resultf = $rFiles->{$f}->{$t};
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return($resultf);
|
|
|
|
}
|
2015-11-10 18:42:43 +00:00
|
|
|
|
|
|
|
sub getlangs($$)
|
|
|
|
{
|
|
|
|
my ($languagefile, $rencoding) = @_;
|
|
|
|
|
|
|
|
if (open(FI, $languagefile)) {
|
|
|
|
while (my $l = <FI>) {
|
|
|
|
if ($l =~ /^Language/) {
|
|
|
|
my ($lng, $enc) = &getLangEntry();
|
|
|
|
if (defined($lng)) {
|
2015-11-12 20:42:43 +00:00
|
|
|
$rencoding->{$lng} = $enc;
|
2015-11-10 18:42:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(FI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-12 20:42:43 +00:00
|
|
|
sub simplifylangs($)
|
|
|
|
{
|
|
|
|
my ($rencoding) = @_;
|
|
|
|
my $base = "";
|
|
|
|
my $enc = "";
|
|
|
|
my $differ = 0;
|
|
|
|
my @klist = ();
|
|
|
|
my @klist2 = ();
|
|
|
|
for my $k (reverse sort keys %{$rencoding}) {
|
|
|
|
my @tag = split('_', $k);
|
|
|
|
if ($tag[0] eq $base) {
|
|
|
|
push(@klist, $k);
|
|
|
|
if ($rencoding->{$k} ne $enc) {
|
|
|
|
$differ = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
# new base, check that old base was OK
|
|
|
|
if ($base ne "") {
|
|
|
|
if ($differ == 0) {
|
|
|
|
$rencoding->{$base} = $enc;
|
|
|
|
push(@klist2, @klist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@klist = ($k);
|
|
|
|
$base = $tag[0];
|
|
|
|
$enc = $rencoding->{$k};
|
|
|
|
$differ = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($base ne "") {
|
|
|
|
# close handling for last entry too
|
|
|
|
if ($differ == 0) {
|
|
|
|
$rencoding->{$base} = $enc;
|
|
|
|
push(@klist2, @klist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for my $k (@klist2) {
|
|
|
|
delete($rencoding->{$k});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-10 18:42:43 +00:00
|
|
|
sub getLangEntry()
|
|
|
|
{
|
|
|
|
my ($lng, $enc) = (undef, undef);
|
|
|
|
while (my $l = <FI>) {
|
|
|
|
chomp($l);
|
|
|
|
if ($l =~ /^\s*Encoding\s+([^ ]+)\s*$/) {
|
|
|
|
$enc = $1;
|
|
|
|
}
|
|
|
|
elsif ($l =~ /^\s*LangCode\s+([^ ]+)\s*$/) {
|
|
|
|
$lng = $1;
|
|
|
|
}
|
|
|
|
elsif ($l =~ /^\s*End\s*$/) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (defined($lng) && defined($enc)) {
|
|
|
|
return($lng, $enc);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return(undef, undef);
|
|
|
|
}
|
|
|
|
}
|