5 CACHEDIR
=$HOME/.cache
/llpp
13 command -v "$1" >/dev
/null
2>&1
16 trap 'test -n "$casp" && rm -f "$casp"' 0
18 test -d "$CACHEDIR" || die
"cache directory $CACHEDIR does not exist"
19 while getopts m
:t
:f opt
; do
25 die
"usage: $0 [-m mime/type] [-t filter] [-f] path";
29 shift $
(($OPTIND - 1))
30 test -z "$1" && die
"usage $0: path"
32 ft
=$
(file -L --mime-type -b "$1") || die
"$ft"
35 application
/x-gzip | application
/x-compress
) dc=zcat
;;
36 application
/x-xz
) dc=xzcat
;;
37 application
/x-bzip2
) dc=bzcat
;;
41 filt
='"${dc-cat}" "$1" |'
43 if test -z "$type"; then
44 test -z "$dc" || ft
=$
(file -L --mime-type -bz "$1") || die
"$ft"
48 application
/postscript
) type=ps
;;
49 application
/pdf
) type=pdf
;;
50 image
/vnd.djvu
) type=djvu
;;
51 text
/html
) type=html
;;
52 application
/msword
) type=word
;;
53 application
/vnd.openxmlformats-officedocument.
* \
54 | application
/vnd.ms-powerpoint \
55 | application
/vnd.ms-excel \
56 | application
/vnd.oasis.opendocument.
*) type=uno
;;
57 image
/svg
+xml
) type=svg
;;
59 application
/x-dvi
) type=dvi
;;
60 *) die
"unhandled file type: $mime";;
65 ps
) conv
='ps2pdf - "$casp"';;
66 pdf
) test -z "$dc" && exec llpp
"$@" || conv
='cat >"$casp"';;
67 djvu
) conv
='djvups - | ps2pdf - "$casp"';;
69 test -n "$dc" && die
"can not convert compressed $mime"
71 conv
='prince "$1" -o "$casp"'
74 if executable_p unoconv
&& test -z "$dc"; then
76 conv
='unoconv -o "$casp" "$1"'
78 conv
='antiword -m 8859-1.txt -a a4 - >"$casp"'
82 test -n "$dc" && die
"can not convert compressed $mime"
84 conv
='unoconv -o "$casp" "$1"'
87 executable_p rsvg-convert \
88 && conv
='rsvg-convert -f pdf -o "$casp"' \
89 || conv
='inkscape -z -A "$casp" -'
91 image
) conv
='convert - pdf:"$casp"';;
93 test -n "$dc" && die
"can not convert compressed $mime"
95 conv
='dvipdf "$1" "$casp"'
97 *) die
"unhandled filter type: $type";;
100 hash=$
(md5sum "$1") || die
"$hash"
101 casp
=$CACHEDIR/${hash%% *}
102 (test -n "$force" -o ! -e "$casp") && eval "$filt" "$conv"
104 exec llpp
-origin "$@" "$casp"