Imported from antiword-0.37.tar.gz.
[antiword.git] / kantiword
blob0cc7af55a29b203f8b956496c98626556873d564
1 #!/bin/bash
2 #!/bin/sh
4 # Script to make drag and drop in KDE possible
5 #set -x
8 if [ $# -lt 2 ]
9 then
10 exit 0
13 # Determine the temp directory
14 if [ -d "$TMPDIR" ] && [ -w "$TMPDIR" ]
15 then
16 tmp_dir=$TMPDIR
17 elif [ -d "$TEMP" ] && [ -w "$TEMP" ]
18 then
19 tmp_dir=$TEMP
20 else
21 tmp_dir="/tmp"
22 fi
24 # Try to create the temp files in a secure way
25 if [ -x /bin/tempfile ]
26 then
27 out_file=`/bin/tempfile -d "$tmp_dir" -p antiword -s ".ps"` || exit 1
28 err_file=`/bin/tempfile -d "$tmp_dir" -p antiword -s ".err"`
29 if [ $? -ne 0 ]
30 then
31 rm -f "$out_file"
32 exit 1
34 elif [ -x /bin/mktemp ]
35 then
36 out_file=`/bin/mktemp -q -p "$tmp_dir" antiword.ps.XXXXXXXXX` || exit 1
37 err_file=`/bin/mktemp -q -p "$tmp_dir" antiword.err.XXXXXXXXX`
38 if [ $? -ne 0 ]
39 then
40 rm -f "$out_file"
41 exit 1
43 else
44 # Creating the temp files in an un-secure way
45 out_file=$tmp_dir"/antiword.$$.ps"
46 err_file=$tmp_dir"/antiword.$$.err"
49 # Determine the paper size
50 paper_size=$1
51 shift
53 # Make the PostScript file
54 antiword -p $paper_size -i 0 "$@" 2>"$err_file" >"$out_file"
55 if [ $? -ne 0 ]
56 then
57 # Something went wrong
58 if [ -r "$err_file" ] && [ -s "$err_file" ]
59 then
60 konsole --caption "Error from Antword" -e less "$err_file"
62 # Clean up
63 rm -f "$out_file" "$err_file"
64 exit 1
67 # Show the PostScript file
68 gv "$out_file" -nocentre -media $paper_size
70 # Clean up
71 rm -f "$out_file" "$err_file"
72 exit 0