- Support for page-ranges and accounting in the textonly filter (bug

#244979).
This commit is contained in:
Tim Waugh 2007-07-05 15:41:27 +00:00
parent 812ed7011a
commit 5f9fdee8f6
2 changed files with 79 additions and 2 deletions

View File

@ -6,7 +6,7 @@
Summary: Common Unix Printing System
Name: cups
Version: 1.2.11
Release: 4%{?dist}
Release: 5%{?dist}
License: GPL
Group: System Environment/Daemons
Source: ftp://ftp.easysw.com/pub/cups/%{version}/cups-%{version}-source.tar.bz2
@ -445,6 +445,9 @@ rm -rf $RPM_BUILD_ROOT
%{cups_serverbin}/daemon/cups-lpd
%changelog
* Thu Jul 5 2007 Tim Waugh <twaugh@redhat.com> 1:1.2.11-5
- Support for page-ranges and accounting in the textonly filter (bug #244979).
* Wed Jul 4 2007 Tim Waugh <twaugh@redhat.com> 1:1.2.11-4
- Better paper-out detection patch still (bug #246222).

View File

@ -1,6 +1,9 @@
#!/bin/bash
## Copyright (C) 2003-2006 Red Hat, Inc.
## Copyright (C) 2003-2006 Tim Waugh <twaugh@redhat.com>
## Changed on 2007/05/17, Opher Shachar, LADPC Ltd.
## Added support for page-ranges option.
## Added page accounting.
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
@ -37,9 +40,77 @@ else
TMPFILE="$6"
fi
PR=${5#*page-ranges=}
# Do options specify page-ranges?
if [[ "$PR" != "$5" ]]; then
PR=${PR%% *}
else
#unset PR
PR=1-999999
fi
if [[ "$PR" ]]; then
TMPFILE2=$(mktemp ${TMPDIR:-/tmp}/textonly2.XXXXXX)
pagenum=0
EOF=
{
while [[ "$PR" ]]; do
pl=${PR%%,*} ;# take first subrange
PR=${PR#$pl};PR=${PR#,} ;# remove from range list
pu=${pl#*-} ;# extract upper and lower
pl=${pl%-*} ;# pages of subrange
# Allows interpreting 0-5,3-10 as 1-5,6-10 rejects 5-1 or 1-
(( pagenum >= pl )) && pl=$(( pagenum + 1 ))
(( pl > pu )) && continue
# Loop reading pages until at or over lower page of subrange.
while read -d `echo -ne '\f'` -r; do
(( pagenum++ ))
(( pagenum == pl )) && break
done
# Did we reach lower page of subrange or EOF?
if (( pagenum < pl )); then
[[ ! "$REPLY" ]] && break ;# empty last page - we're done.
(( pagenum++ ))
EOF=y
fi
# Output page and report to page log
if (( pagenum == pl )); then
echo -n "${REPLY}" >>"$TMPFILE2"
# If EOF then page has no final FF
[[ ! "$EOF" ]] && echo -ne '\f' >>"$TMPFILE2"
echo "PAGE: $pagenum $COPIES" >&2
fi
[[ "$EOF" ]] && break
# Is the current subrange a single page?
(( pagenum == pu )) && continue
while read -d `echo -ne '\f'` -r; do
(( pagenum++ ))
echo -ne "${REPLY}\f" >>"$TMPFILE2"
echo "PAGE: $pagenum $COPIES" >&2
(( pagenum == pu )) && break
done
# Could be that we reached EOF before page boundry
if (( pagenum < pu )); then
if [[ "$REPLY" ]]; then
(( pagenum++ ))
echo -n "${REPLY}" >>"$TMPFILE2"
echo "PAGE: $pagenum $COPIES" >&2
fi
break
fi
done
} <"$TMPFILE"
else
TMPFILE2="$TMPFILE"
pc=$(grep -co `echo -ne '\f'` "$TMPFILE2")
pc=$(( pc * $COPIES ))
echo "PAGE: $pc" >&2
fi
while [ "$COPIES" -gt 0 ]; do
# Just translate LF->CRLF at the moment, until the PPD has options added.
sed -e 's/$/'`echo -ne '\r'`'/g' "$TMPFILE"
sed -e 's/$/'`echo -ne '\r'`'/g' "$TMPFILE2"
if [ "$SENDFF" == "True" ]
then
@ -48,3 +119,6 @@ while [ "$COPIES" -gt 0 ]; do
COPIES=$(($COPIES - 1))
done
# Cleanup
[[ "$TMPFILE" != "$TMPFILE2" ]] && rm -f "$TMPFILE2"
exit 0