4 CACHEDIR
=$HOME/.cache
/llpp
14 command -v "$1" >/dev
/null
2>&1
18 cat >"$CACHEDIR/fonts/text" <<EOF
19 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
20 eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
21 minim veniam, quis nostrud exercitation ullamco laboris nisi ut
22 aliquip ex ea commodo consequat. Duis aute irure dolor in
23 reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
24 pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
25 culpa qui officia deserunt mollit anim id est laborum.
26 Posting Soccer Goals On Vine Is Illegal, Say England's Premier League
27 abcdefghizklmnopqrstwxyz
28 ABCDEFGHIZKLMNOPQRSTWXYZ
37 trap 'test -n "$casp" && rm -f "$casp"' 0
39 test -d "$CACHEDIR" || die
"cache directory '$CACHEDIR' does not exist"
40 while getopts m
:t
:f opt
; do
45 ?
) die
"usage: $0 [-m mime/type] [-t filter] [-f] [path|url]";;
48 shift $
(($OPTIND - 1))
49 test -z "$1" && die
"usage $0: path"
51 test ! -e "$1" && expr >/dev
/null
"$1" : "\(ftp\|https\?\)://" && {
52 if executable_p wget
; then
54 wget
-q -c -nc $1 -O $2
57 if executable_p curl
; then
62 echo "no program to fetch remote urls found"
67 md5of
="$CACHEDIR/$(basename "$1")"
68 dl
"$1" "$md5of" ||
test -e "$md5of"
69 set -- "$md5of" ${2+"@"}
75 ft
=$
(file -L --mime-type -b "$1") || die
"$ft"
79 application
/x-gzip | application
/x-compress
) dc=zcat
;;
80 application
/x-xz
) dc=xzcat
;;
81 application
/x-bzip2
) dc=bzcat
;;
85 filt
='"${dc-cat}" "$1" |'
87 if test -z "$type"; then
88 test -z "$dc" || ft
=$
(file -L --mime-type -bz "$1") || die
"$ft"
92 application
/postscript
) type=ps
;;
93 application
/pdf
) type=pdf
;;
94 image
/vnd.djvu
) type=djvu
;;
95 text
/html
) type=html
;;
96 application
/msword
) type=word
;;
97 application
/vnd.openxmlformats-officedocument.
* \
98 | application
/vnd.ms-powerpoint \
99 | application
/vnd.ms-excel \
100 | application
/vnd.oasis.opendocument.
*) type=uno
;;
101 image
/svg
+xml
) type=svg
;;
102 image
/png | image
/jpeg
) test -n "$dc" && type="image" ||
type="image2";;
103 image
/*) type=image
;;
104 application
/x-dvi
) type=dvi
;;
105 application
/x-font-ttf | application
/vnd.ms-opentype
) type=font
;;
106 *) die
"unhandled file type: '$mime'";;
111 ps
) conv
='ps2pdf - "$casp"';;
112 image2|pdf
) test -z "$dc" && exec llpp
"$@" || conv
='cat >"$casp"';;
113 djvu
) conv
='djvups - | ps2pdf - "$casp"';;
115 test -n "$dc" && die
"can not convert compressed '$mime'"
117 conv
='prince "$1" -o "$casp"'
120 if executable_p unoconv
&& test -z "$dc"; then
122 conv
='unoconv -o "$casp" "$1"'
124 conv
='antiword -m 8859-1.txt -a a4 - >"$casp"'
128 test -n "$dc" && die
"can not convert compressed '$mime'"
130 conv
='unoconv -o "$casp" "$1"'
133 executable_p rsvg-convert \
134 && conv
='rsvg-convert -f pdf -o "$casp"' \
135 || conv
='inkscape -z -A "$casp" -'
138 if test -e "$2"; then
141 arg
="--waterfall $CACHEDIR/fonts/text"
144 # https://mail.gnome.org/archives/gtk-i18n-list/2010-June/msg00000.html
145 eval $filt cat >$CACHEDIR/fonts
/font
146 cat >$CACHEDIR/fonts
/fonts.conf
<<EOF
147 <?xml version="1.0"?>
148 <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
150 <dir>$CACHEDIR/fonts/</dir>
151 <cachedir>$CACHEDIR/fonts/</cachedir>
156 conv
='FONTCONFIG_PATH=$CACHEDIR/fonts/ pango-view -q $arg -o $casp'
160 if test -e "$2"; then
163 arg
="--waterfall $CACHEDIR/fonts/text"
166 conv
='pango-view --font="$1" -q $arg -o $casp'
172 image
) conv
='convert - pdf:"$casp"';;
174 test -n "$dc" && die
"can not convert compressed '$mime'"
176 conv
='dvipdf "$1" "$casp"'
178 *) die
"unhandled filter type: '$type'";;
181 hash=$
(md5sum "$md5of") || die
"$hash"
182 casp
=$CACHEDIR/${hash%% *}$caspsuf
183 (test -n "$force" -o ! -e "$casp") && eval "$filt" "$conv"
185 exec llpp
-origin "$@" "$casp"