#!/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{
};
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{
};
close $tmphandle;
system(qw(unoconv -d graphics -f), $extension, '-o', $file, $tmpname);
unlink $tmpname;
}