Loffice: Much simpler solution: Simply touch the file.

This commit is contained in:
Ole Tange 2023-05-06 09:16:04 +02:00
parent cca4f04bd1
commit 787c137b8a

View file

@ -1,76 +1,8 @@
#!/usr/bin/perl
# If argument does not exist: Create a new file of the given type
use File::Temp qw(tempfile);
my @files = grep { not /^-/ and not -e $_ } @ARGV;
my $gen = {
"fodt" => odt,
"odt" => odt,
"fods" => ods,
"ods" => ods,
"fodp" => odp,
"odp" => odp,
"fodd" => odd,
"odd" => odd,
};
for(@files) {
my $extension = (/\.([^.]+)/)[0] || die;
$gen->{$extension}($_,$extension);
}
# If argument does not exist: Create a new file
my @files = grep { not /^-/ } @ARGV;
my @newfiles = grep { not -e $_ } @files;
@newfiles and system("touch",@newfiles);
exec 'loffice', @ARGV;
sub ods {
my $file = shift;
my $extension = shift;
my($tmphandle,$tmpname) = tempfile(TEMPLATE => 'loffXXXX', SUFFIX => ".csv");
system(qw(unoconv -d spreadsheet -f), $extension, '-o', $file, $tmpname);
unlink $tmpname;
}
sub odt {
my $file = shift;
my $extension = shift;
my($tmphandle,$tmpname) = tempfile(TEMPLATE => 'loffXXXX', SUFFIX => ".txt");
system(qw(unoconv -d document -f), $extension, '-o', $file, $tmpname);
unlink $tmpname;
}
sub odp {
my $file = shift;
my $extension = shift;
my($tmphandle,$tmpname) = tempfile(TEMPLATE => 'loffXXXX', SUFFIX => ".svg");
print $tmphandle q{<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg viewBox="0 0 28000 15750"
xmlns:ooo="http://xml.openoffice.org/svg/export">
<defs>
<g id="ooo:meta_slides" ooo:number-of-slides="1" ooo:start-slide-number="0">
</g>
</defs>
</svg>
};
close $tmphandle;
system(qw(unoconv -d presentation -f), $extension, '-o', $file, $tmpname);
unlink $tmpname;
}
sub odd {
my $file = shift;
my $extension = shift;
my($tmphandle,$tmpname) = tempfile(TEMPLATE => 'loffXXXX', SUFFIX => ".svg");
print $tmphandle q{<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg viewBox="0 0 21000 29700">
</svg>
};
close $tmphandle;
system(qw(unoconv -d graphics -f), $extension, '-o', $file, $tmpname);
unlink $tmpname;
}