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
24 ?
) die
"usage: $0 [-m mime/type] [-t filter] [-f] path";;
27 shift $
(($OPTIND - 1))
28 test -z "$1" && die
"usage $0: path"
30 ft
=$
(file -L --mime-type -b "$1") || die
"$ft"
33 application
/x-gzip | application
/x-compress
) dc=zcat
;;
34 application
/x-xz
) dc=xzcat
;;
35 application
/x-bzip2
) dc=bzcat
;;
39 filt
='"${dc-cat}" "$1" |'
41 if test -z "$type"; then
42 test -z "$dc" || ft
=$
(file -L --mime-type -bz "$1") || die
"$ft"
46 application
/postscript
) type=ps
;;
47 application
/pdf
) type=pdf
;;
48 image
/vnd.djvu
) type=djvu
;;
49 text
/html
) type=html
;;
50 application
/msword
) type=word
;;
51 application
/vnd.openxmlformats-officedocument.
* \
52 | application
/vnd.ms-powerpoint \
53 | application
/vnd.ms-excel \
54 | application
/vnd.oasis.opendocument.
*) type=uno
;;
55 image
/svg
+xml
) type=svg
;;
56 image
/png | image
/jpeg
) test -n "$dc" && type="image" ||
type="image2";;
58 application
/x-dvi
) type=dvi
;;
59 *) die
"unhandled file type: '$mime'";;
66 ps
) conv
='ps2pdf - "$casp"';;
67 image2|pdf
) test -z "$dc" && exec llpp
"$@" || conv
='cat >"$casp"';;
68 djvu
) conv
='djvups - | ps2pdf - "$casp"';;
70 test -n "$dc" && die
"can not convert compressed '$mime'"
72 conv
='prince "$1" -o "$casp"'
75 if executable_p unoconv
&& test -z "$dc"; then
77 conv
='unoconv -o "$casp" "$1"'
79 conv
='antiword -m 8859-1.txt -a a4 - >"$casp"'
83 test -n "$dc" && die
"can not convert compressed '$mime'"
85 conv
='unoconv -o "$casp" "$1"'
88 executable_p rsvg-convert \
89 && conv
='rsvg-convert -f pdf -o "$casp"' \
90 || conv
='inkscape -z -A "$casp" -'
92 image
) conv
='convert - pdf:"$casp"';;
94 test -n "$dc" && die
"can not convert compressed '$mime'"
96 conv
='dvipdf "$1" "$casp"'
98 *) die
"unhandled filter type: '$type'";;
101 hash=$
(md5sum "$1") || die
"$hash"
102 casp
=$CACHEDIR/${hash%% *}
103 (test -n "$force" -o ! -e "$casp") && eval "$filt" "$conv"
105 exec llpp
$opts -origin "$@" "$casp"