From 5f9fdee8f675e7c19240f206ee8ecaa24ca2e2ef Mon Sep 17 00:00:00 2001 From: Tim Waugh Date: Thu, 5 Jul 2007 15:41:27 +0000 Subject: [PATCH] - Support for page-ranges and accounting in the textonly filter (bug #244979). --- cups.spec | 5 +++- textonly.filter | 76 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/cups.spec b/cups.spec index c6f796c..9befd7a 100644 --- a/cups.spec +++ b/cups.spec @@ -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 1:1.2.11-5 +- Support for page-ranges and accounting in the textonly filter (bug #244979). + * Wed Jul 4 2007 Tim Waugh 1:1.2.11-4 - Better paper-out detection patch still (bug #246222). diff --git a/textonly.filter b/textonly.filter index 098bb35..25850cc 100755 --- a/textonly.filter +++ b/textonly.filter @@ -1,6 +1,9 @@ #!/bin/bash ## Copyright (C) 2003-2006 Red Hat, Inc. ## Copyright (C) 2003-2006 Tim Waugh +## 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