tangetools/Loffice/Loffice

77 lines
2 KiB
Perl
Executable file

#!/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);
}
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;
}