/usr/bin/apspreview is in apsfilter 7.2.6-1.3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | #! /bin/sh
# -*- sh -*-
#
# $ApsCVS: src/apsfilter/bin/apspreview.in,v 1.1.2.6 2002/03/03 20:21:14 andreas Exp $
#
# apspreview by Michael Loßin
#
# create a temporary PostScript file using apsfilter and preview it
#
error()
{
echo >&2 "error: $1"
rm -rf "$APS_TMPDIR"
exit 1
}
usage()
{
cat >&2 <<EOF
apspreview: preview a file as it would be printed by apsfilter
Usage:
apspreview [-h] [-P queue] [-Z options] [input...]
Options:
-h show this help
-P queue name of printer queue to be used for apsfilter
(default: value of '\$PRINTER'; otherwise 'lp')
-Z options comma separated option list
(default: empty)
input input file(s)
(default: stdin)
EOF
exit 0
}
# look for a PostScript viewer
if type gv > /dev/null 2>&1; then
viewer=gv
elif type kghostview > /dev/null 2>&1; then
viewer=kghostview
elif type ghostview > /dev/null 2>&1; then
viewer=ghostview
else
error "can't find a suitable PostScript viewer"
fi
QUEUE=${PRINTER:-lp}
unset Z_OPTS INPUT_FILES
# parse commandline
while [ "$1" ]; do
case "$1" in
-P) shift; QUEUE="$1" ;;
-P*) QUEUE="${1#-P}" ;;
-Z) shift; Z_OPTS="-Z$1" ;;
-Z*) Z_OPTS="$1" ;;
-h|--help) usage ;;
-*) error "unknown option '$1'" ;;
*) # silly construction to allow spaces in filenames
INPUT_FILES="$INPUT_FILES
$1" ;;
esac
shift
done
# if the queue name is an alias, parse printcap for the original name
if [ ! -d "$APS_CONFDIR/$QUEUE" ]; then
# quote forward slashes
q=$(echo "$QUEUE" | sed 's%/%\\/%')
q=$("/usr/bin/awk" -F":" "/^${q}[|:]|^[^#].*\|${q}[|:]/,/^#/ \
{ if (\$0 ~ /:sd=/) print \$2 }" < "/etc/printcap")
if [ "$q" ]; then
QUEUE="${q##*/}"
else
error "couldn't resolve printer name '$QUEUE' in /etc/printcap"
fi
fi
if [ ! -f "/etc/apsfilter/$QUEUE/apsfilterrc" ]; then
error "no configuration file found for queue '$QUEUE'"
fi
# create temporary configuration directory
: ${TMPDIR:=/tmp}
APS_TMPDIR="$TMPDIR/apspreview$$"
rm -rf "$APS_TMPDIR"
mkdir -m 700 "$APS_TMPDIR"
if [ $? -ne 0 ]; then
APS_TMPDIR=`mktemp -q -d "$TMPDIR/apspreview.XXXXXX"` \
|| error "can't create temporary directory"
chmod 700 "$APS_TMPDIR"
fi
trap 'rm -rf "$APS_TMPDIR"' 0
ln -s "/usr/share/apsfilter" "$APS_TMPDIR/basedir"
mkdir "$APS_TMPDIR/$QUEUE" || error "can't create temporary directory"
# use global configuration files (if available)
if [ -f "/etc/apsfilter/apsfilterrc" ]; then
ln -s "/etc/apsfilter/apsfilterrc" "$APS_TMPDIR/apsfilterrc"
fi
if [ -f "/etc/apsfilter/restrictions" ]; then
ln -s "/etc/apsfilter/restrictions" "$APS_TMPDIR/restrictions"
fi
if [ -f "/etc/apsfilter/$QUEUE/restrictions" ]; then
ln -s "/etc/apsfilter/$QUEUE/restrictions" \
"$APS_TMPDIR/$QUEUE/restrictions"
fi
# create local configuration file from the original one
{
cat "/etc/apsfilter/$QUEUE/apsfilterrc"
# overwrite the PRINTER setting for previewing
echo "PRINTER=PS"
# let's say we have a good PostScript printer :^)
echo "HARDWARE_DUPLEX=set"
echo "HARDWARE_COPIES=set"
} > "$APS_TMPDIR/$QUEUE/apsfilterrc"
export APS_CONFDIR="$APS_TMPDIR"
# convert file to PostScript (one after another), then preview it
: ${INPUT_FILES:=/dev/stdin}
# regain file list (potentially spaces) with strange IFS setting
IFS="
"
for file in $INPUT_FILES; do
echo "converting '$file'..."
/usr/bin/aps2file "$file" -P"$QUEUE" $Z_OPTS -o "$APS_TMPDIR/apspreview.ps"
filetype=$(file "$APS_TMPDIR/apspreview.ps")
case $(echo ${filetype#$APS_TMPDIR/apspreview.ps: } | tr A-Z a-z) in
postscript*)
echo "previewing PostScript data with $viewer..."
$viewer "$APS_TMPDIR/apspreview.ps" ;;
*)
echo "aps2file didn't yield PostScript, skipping '$file'..." ;;
esac
done
|