#!/bin/sh -u # # Convert input to PostScript. # - Cameron Simpson 12dec1996 # # Convert to MIME basis. - cameron 29apr2004 # : ${TMPDIR:=/tmp} me=$0 cmd=`basename "$0"` usage="Usage: $cmd [-m medium] [-L] [-P] [-i itype] [-T title] [file]" a2ps_aspect="-R --columns=1" title= badopts= mtype= medium=A4 txtconv= while [ $# -gt 0 ] do case $1 in -T) title=$2; shift ;; -L) a2ps_aspect="-r --columns=1" ;; -P) a2ps_aspect="-R --columns=1" ;; -m) medium=$2; shift ;; -i) mtype=$2; shift case "$mtype" in any|'') mtype= ;; ps|postscript) mtype=application/postscript ;; pdf) mtype=application/pdf ;; mentor) mtype=application/mentor ;; text) mtype=text/plain ;; */*) ;; *) echo "$cmd: unrecognised file type \"$mtype\"" >&2 badopts=1 ;; esac ;; --) shift; break ;; -*) echo "$cmd: unrecognised option: $1" >&2 badopts=1 ;; *) break ;; esac shift done txtconv="$txtconv $a2ps_aspect" [ -n "$title" ] && txtxconv="$txtconv \"--footer=\$title\"" if [ $# = 0 ] then file=- else file=$1; shift [ $# = 0 ] || { echo "$cmd: extra arguments after file: $*" >&2; badopts=1; } fi [ $badopts ] && { echo "$usage" >&2; exit 2; } tmpfile=$TMPDIR/$cmd$$ filetitle=$file if [ "x$file" = x- ] then filetitle=stdin trap 'rm -f "$tmpfile"' 0 1 2 13 15 cat >"$tmpfile" || exit 1 file=$tmpfile fi [ -n "$title" ] || title=$filetitle [ -n "$mtype" ] || mtype=`file2mime "$file"` || exit 1 conv_mentor='mentor2ps -m "$medium"' conv_pdf=acroread2ps conv_text='a2ps -q -1 -o- --stdin "$title" -T 8 -i --borders=no -b $a2ps_aspect --medium=$medium -f 10' conv_html=unhtml conv_image='convert - ps:-' case "$mtype" in application/pdf) conv=$conv_pdf ;; application/postscript) conv=cat ;; application/mentor) conv=$conv_mentor ;; application/x-sh) conv=$conv_text ;; application/x-csh) conv=$conv_text ;; text/plain) conv=$conv_text ;; text/html) conv=$conv_html ;; text/*) conv=$conv_text ;; image/*) conv=$conv_image ;; *) echo "$cmd: supported input type \"$mtype\"" >&2 exit 1 ;; esac ## echo "title=[$title], conv=[$conv]" >&2 ## set | egrep -i '(asp|conv)' >&2 ##set -v eval "exec <\"\$file\"; $conv"