14930
|
1 |
#!/usr/bin/env bash
|
|
2 |
#
|
|
3 |
# $Id$
|
|
4 |
# Author: Markus Wenzel, TU Muenchen
|
|
5 |
#
|
15218
|
6 |
# DESCRIPTION: display document (in DVI or PDF format)
|
14930
|
7 |
|
|
8 |
|
|
9 |
PRG="$(basename "$0")"
|
|
10 |
|
|
11 |
function usage()
|
|
12 |
{
|
|
13 |
echo
|
|
14 |
echo "Usage: $PRG [OPTIONS] FILE"
|
|
15 |
echo
|
|
16 |
echo " Options are:"
|
|
17 |
echo " -c cleanup -- remove FILE after use"
|
|
18 |
echo
|
15218
|
19 |
echo " Display document FILE (in DVI or PDF format)."
|
14930
|
20 |
echo
|
|
21 |
exit 1
|
|
22 |
}
|
|
23 |
|
|
24 |
function fail()
|
|
25 |
{
|
|
26 |
echo "$1" >&2
|
|
27 |
exit 2
|
|
28 |
}
|
|
29 |
|
|
30 |
|
|
31 |
## process command line
|
|
32 |
|
|
33 |
# options
|
|
34 |
|
|
35 |
CLEAN=""
|
|
36 |
|
|
37 |
while getopts "c" OPT
|
|
38 |
do
|
|
39 |
case "$OPT" in
|
|
40 |
c)
|
|
41 |
CLEAN=true
|
|
42 |
;;
|
|
43 |
\?)
|
|
44 |
usage
|
|
45 |
;;
|
|
46 |
esac
|
|
47 |
done
|
|
48 |
|
|
49 |
shift $(($OPTIND - 1))
|
|
50 |
|
|
51 |
|
|
52 |
# args
|
|
53 |
|
|
54 |
[ "$#" -ne 1 ] && usage
|
|
55 |
|
|
56 |
FILE="$1"; shift
|
|
57 |
|
|
58 |
|
|
59 |
## main
|
|
60 |
|
|
61 |
[ -f "$FILE" ] || fail "Bad file: $FILE"
|
|
62 |
|
15703
|
63 |
case "$FILE" in
|
|
64 |
*.dvi)
|
|
65 |
VIEWER="$DVI_VIEWER"
|
|
66 |
;;
|
|
67 |
*.pdf)
|
|
68 |
VIEWER="$PDF_VIEWER"
|
|
69 |
;;
|
|
70 |
*)
|
|
71 |
fail "Unknown file type: $FILE";
|
|
72 |
esac
|
|
73 |
|
14930
|
74 |
if [ -n "$CLEAN" ]; then
|
15703
|
75 |
PRIVATE_FILE="$ISABELLE_TMP/$$"$(basename "$FILE")
|
|
76 |
mv "$FILE" "$PRIVATE_FILE" || fail "Cannot move file: $FILE"
|
|
77 |
$VIEWER "$PRIVATE_FILE"
|
14930
|
78 |
rm -f "$PRIVATE_FILE"
|
|
79 |
else
|
15703
|
80 |
exec $VIEWER "$FILE"
|
14930
|
81 |
fi
|
15718
|
82 |
|