X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=scripts.git;a=blobdiff_plain;f=print.sh;h=c3815f4a119f284f86f27199e4caf7b03e893344;hp=fc88668de405aed9f052f1e1c0bcbc4dc91d38f6;hb=6a45dbe664eebcb3050d0c3dfe9856f7c5815aca;hpb=ea923a43955b6b07ebe087eef413dc27744d8c81 diff --git a/print.sh b/print.sh index fc88668..c3815f4 100755 --- a/print.sh +++ b/print.sh @@ -30,7 +30,13 @@ tmp=$(mktemp /tmp/print.ps.XXXXXX) opts="" printing_cmd="lpr" -for arg in $*; do +function cleanup-before-exit () { + rm ${tmp} +} + +trap cleanup-before-exit EXIT + +for arg in "$@"; do if [ "${arg}" == "-h" ] || [ "${arg}" == "--help" ]; then @@ -50,7 +56,6 @@ for arg in $*; do echo "Contact " echo "Version \$Id: print.sh,v 1.19 2006-11-10 15:53:23 fleuret Exp $" - \rm ${tmp} exit 0 elif [[ ${arg} == "-"* ]]; then @@ -63,42 +68,47 @@ for arg in $*; do # else, it is a filename to print - if [ -e ${arg} ]; then + if [ -e "${arg}" ]; then - TYPE=$(file -L ${arg}) + TYPE=$(file -L "${arg}") noprint="" case $TYPE in *"image data"*) - convert ${arg} ps:${tmp} + convert "${arg}" ps:${tmp} ;; *"TeX DVI"*) - dvips -o ${tmp} ${arg} + dvips -o ${tmp} "${arg}" ;; *"FIG image"*) - fig2dev -L ps ${arg} > ${tmp} + fig2dev -L ps "${arg}" > ${tmp} ;; *"PostScript"*) - cp ${arg} ${tmp} + cp "${arg}" ${tmp} ;; *"PDF"*) - pdf2ps ${arg} ${tmp} + pdf2ps "${arg}" ${tmp} ;; *" text"*) - # a2ps -B -R --columns=1 -f 8 -o ${tmp} ${arg} - a2ps --media=A4 --user-option=lp -o ${tmp} ${arg} + # a2ps -B -R --columns=1 -f 8 -o ${tmp} "${arg}" + # if isutf8 -q ${tmp}; then + # echo "Can not print uf8 text." + # exit 1 + # else + a2ps --media=A4 --user-option=lp -o ${tmp} "${arg}" + # fi ;; *"gzip compressed"*) echo "Unzipping " - zcat ${arg} > ${tmp} + zcat "${arg}" > ${tmp} noprint=1 $0 ${opts} ${tmp} ;; @@ -152,7 +162,6 @@ for arg in $*; do ;; *) echo "Unknown option $f" - \rm ${tmp} exit 1;; esac done @@ -176,8 +185,6 @@ for arg in $*; do done -\rm ${tmp} - if [[ ${show_queue} ]]; then lpq fi