From 4c03edadcecea0c57b406e1f3a6e8337b650bcc6 Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Thu, 15 Oct 2020 16:30:45 +0200 Subject: [PATCH] Loffice: Create empty LibreOffice file if file does not exist. --- Loffice/Loffice | 76 +++++++++++++++++++ Makefile | 11 +-- binsearch/binsearch | 180 -------------------------------------------- 3 files changed, 82 insertions(+), 185 deletions(-) create mode 100755 Loffice/Loffice delete mode 100755 binsearch/binsearch diff --git a/Loffice/Loffice b/Loffice/Loffice new file mode 100755 index 0000000..ee66549 --- /dev/null +++ b/Loffice/Loffice @@ -0,0 +1,76 @@ +#!/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; +} diff --git a/Makefile b/Makefile index 7be0e25..87b6fd0 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,11 @@ CMD = blink 2grep 2search burncpu drac duplicate-packets em emoticons \ encdir field find-first-fail forever fxkill G gitnext gitundo \ - goodpasswd histogram mtrr mirrorpdf neno off parsort pdfman \ - pidcmd pidtree plotpipe puniq ramusage rand rclean rina rn \ - rrm seekmaniac shython sound-reload splitvideo stdout swapout \ - T teetime timestamp tracefile transpose upsidedown vid \ - w4it-for-port-open whitehash wifi-reload wssh ytv yyyymmdd + goodpasswd histogram Loffice mtrr mirrorpdf neno off parsort \ + pdfman pidcmd pidtree plotpipe puniq ramusage rand rclean \ + rina rn rrm seekmaniac shython sound-reload splitvideo stdout \ + swapout T teetime timestamp tracefile transpose upsidedown \ + vid w4it-for-port-open whitehash wifi-reload wssh ytv \ + yyyymmdd all: blink/blink.1 2search/2grep.1 2search/2search.1 \ burncpu/burncpu.1 drac/drac.1 encdir/encdir.1 field/field.1 \ diff --git a/binsearch/binsearch b/binsearch/binsearch deleted file mode 100755 index 31dbf6b..0000000 --- a/binsearch/binsearch +++ /dev/null @@ -1,180 +0,0 @@ -#!/bin/bash - -: <<'=cut' -=encoding utf8 - -=head1 NAME - -binsearch - do binary search to find a numeric limit - - -=head1 SYNOPSIS - -B I - - -=head1 DESCRIPTION - -B runs I with a single number. It returns highest -value that I succeeds for. - - -=head1 OPTIONS - -=over 4 - -=item B<-2> - -Instead of the command a single argument, give the command 2 argument: -I I. - -=item B<-q> - -Quiet. Ignore output from B. - - -=back - - -=head1 EXAMPLES - -=head2 Find the last file - -This is a silly way to find the last non-existing file (namely 244): - - touch {245..800} - binsearch ls - -This is a silly way to find the last file (namely 800): - - touch {1..800} - binsearch ls - -=head2 Test a bash function - -Test how long an argument /bin/echo can take - - . $(which binsearch) - singleecho() { - /bin/echo $(perl -e 'print "x"x'$1) >/dev/null - } - binsearch singleecho - -=head2 Test a bash function that takes from and to as arguments - -Use a function that takes two arguments - - . $(which binsearch) - greplines() { - env | perl -ne "$1..$2 and print" | grep HOME= - } - binsearch -2 -q greplines - - -=head1 AUTHOR - -Copyright (C) 2020 Ole Tange, -http://ole.tange.dk and Free Software Foundation, Inc. - - -=head1 LICENSE - -Copyright (C) 2012 Free Software Foundation, Inc. - -This program 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 3 of the License, or -at your option any later version. - -This program 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 program. If not, see . - - -=head1 SEE ALSO - -B(1) - -=cut - -binsearch() { - _binsearch() { - low=$1 - high=$2 - # echo $low-$high - if [ $low -gt $(($high - 2)) ]; then - return - fi - shift - shift - middle=$(( ( $low + $high ) / 2 )) - if _run $low $middle "$@" ; then - low=$middle - else - high=$middle - fi - _binsearch $low $high "$@" - } - - _run() { - local a="$1" - local b="$2" - shift - shift - # echo "a=$a b=$b $@" - if $opt2 ; then - eval "$not" "$@ $a $b" "$quiet" - else - eval "$not" "$@ $b" "$quiet" - fi - } - - quiet="" - opt2=false - args=$(getopt 'q2' $*) || exit - # now we have the sanitized args... replace the original with it - set -- $args - - while true; do - case $1 in - (-2) opt2=true; shift;; - (-q) quiet=">/dev/null 2>/dev/null"; shift;; - (--) shift; break;; - esac - done - - # If function(1) = false: run 'not function()' instead - if _run 1 1 "$@" ; then - not='' - else - not='!' - fi - # exponential search for the first value that is false - # low = previous value (function($low) == true) - # high = low * 2 (function($high) == false) - high=1 - while _run 1 $high "$@" ; do - low=$high - high=$(( $high*2 )) - if [ $high -gt 4611686018427387900 ] ; then - echo "$0: Error: exit value does not change of '$@'" >&2 - return - fi - done - # echo "low: $low high: $high not: $not" - _binsearch $low $high "$@" 2>/dev/null - echo $low -} - -if [ -z "$*" ] ; then - # source the bash function - # . $(which binsearch) - true -else - # binsearch command - binsearch "$@" -fi