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
;;
58 image
/png | image
/jpeg
) test -n "$dc" && type="image" ||
type="image2";;
60 application
/x-dvi
) type=dvi
;;
61 *) die
"unhandled file type: '$mime'";;
69 ps
) conv
='ps2pdf - "$casp"';;
70 pdf
) test -z "$dc" && exec llpp
"$@" || conv
='cat >"$casp"';;
71 djvu
) conv
='djvups - | ps2pdf - "$casp"';;
73 test -n "$dc" && die
"can not convert compressed '$mime'"
75 conv
='prince "$1" -o "$casp"'
78 if executable_p unoconv
&& test -z "$dc"; then
80 conv
='unoconv -o "$casp" "$1"'
82 conv
='antiword -m 8859-1.txt -a a4 - >"$casp"'
86 test -n "$dc" && die
"can not convert compressed '$mime'"
88 conv
='unoconv -o "$casp" "$1"'
91 executable_p rsvg-convert \
92 && conv
='rsvg-convert -f pdf -o "$casp"' \
93 || conv
='inkscape -z -A "$casp" -'
95 image
) conv
='convert - pdf:"$casp"';;
99 conv
='zip -0q "$casp" "$1"'
102 test -n "$dc" && die
"can not convert compressed '$mime'"
104 conv
='dvipdf "$1" "$casp"'
106 *) die
"unhandled filter type: '$type'";;
109 hash=$
(md5sum "$1") || die
"$hash"
110 casp
=$CACHEDIR/${hash%% *}$suff
111 (test -n "$force" -o ! -e "$casp") && eval "$filt" "$conv"
113 exec llpp
$opts -origin "$@" "$casp"