2
## Copyright (C) 2003-2006 Red Hat, Inc.
3
## Copyright (C) 2003-2006 Tim Waugh <twaugh@redhat.com>
4
## Changed on 2007/05/17, Opher Shachar, LADPC Ltd.
5
## Added support for page-ranges option.
6
## Added page accounting.
8
## This program is free software; you can redistribute it and/or modify
9
## it under the terms of the GNU General Public License as published by
10
## the Free Software Foundation; either version 2 of the License, or
11
## (at your option) any later version.
13
## This program is distributed in the hope that it will be useful,
14
## but WITHOUT ANY WARRANTY; without even the implied warranty of
15
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
## GNU General Public License for more details.
18
## You should have received a copy of the GNU General Public License
19
## along with this program; if not, write to the Free Software
20
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
echo >&2 "ERROR: $0 job-id user title copies options [file]"
27
# Extract the papersize
28
SENDFF=`grep '^\*DefaultSendFF' "$PPD" | cut -d\ -f2`
34
if [ "$COPIES" -gt 1 ] && [ $# -lt 6 ]; then
36
trap -- 'rm -f "$TMPFILE"' EXIT
37
TMPFILE=$(mktemp ${TMPDIR:-/tmp}/textonly.XXXXXX)
44
# Do options specify page-ranges?
45
if [[ "$PR" != "$5" ]]; then
53
TMPFILE2=$(mktemp ${TMPDIR:-/tmp}/textonly2.XXXXXX)
58
pl=${PR%%,*} ;# take first subrange
59
PR=${PR#$pl};PR=${PR#,} ;# remove from range list
60
pu=${pl#*-} ;# extract upper and lower
61
pl=${pl%-*} ;# pages of subrange
62
# Allows interpreting 0-5,3-10 as 1-5,6-10 rejects 5-1 or 1-
63
(( pagenum >= pl )) && pl=$(( pagenum + 1 ))
64
(( pl > pu )) && continue
66
# Loop reading pages until at or over lower page of subrange.
67
while read -d `echo -ne '\f'` -r; do
69
(( pagenum == pl )) && break
71
# Did we reach lower page of subrange or EOF?
72
if (( pagenum < pl )); then
73
[[ ! "$REPLY" ]] && break ;# empty last page - we're done.
77
# Output page and report to page log
78
if (( pagenum == pl )); then
79
echo -n "${REPLY}" >>"$TMPFILE2"
80
# If EOF then page has no final FF
81
[[ ! "$EOF" ]] && echo -ne '\f' >>"$TMPFILE2"
82
echo "PAGE: $pagenum $COPIES" >&2
85
# Is the current subrange a single page?
86
(( pagenum == pu )) && continue
87
while read -d `echo -ne '\f'` -r; do
89
echo -ne "${REPLY}\f" >>"$TMPFILE2"
90
echo "PAGE: $pagenum $COPIES" >&2
91
(( pagenum == pu )) && break
93
# Could be that we reached EOF before page boundry
94
if (( pagenum < pu )); then
95
if [[ "$REPLY" ]]; then
97
echo -n "${REPLY}" >>"$TMPFILE2"
98
echo "PAGE: $pagenum $COPIES" >&2
106
pc=$(grep -co `echo -ne '\f'` "$TMPFILE2")
107
pc=$(( pc * $COPIES ))
111
while [ "$COPIES" -gt 0 ]; do
112
# Just translate LF->CRLF at the moment, until the PPD has options added.
113
sed -e 's/$/'`echo -ne '\r'`'/g' "$TMPFILE2"
115
if [ "$SENDFF" == "True" ]
120
COPIES=$(($COPIES - 1))
123
[[ "$TMPFILE" != "$TMPFILE2" ]] && rm -f "$TMPFILE2"