%PDF- %PDF-
Direktori : /usr/lib/cups/filter/ |
Current File : //usr/lib/cups/filter/brftopagedbrf |
#!/bin/bash # # Copyright (c) 2015-2018 Samuel Thibault <samuel.thibault@ens-lyon.org> # # Licensed under Apache License v2.0. See the file "LICENSE" for more # information. # # Make sure we have enough options if [ $# != 5 -a $# != 6 ]; then echo "ERROR: $0 jobid user name nb options [filename]" >&2 exit 1 fi NB=$4 OPTIONS=$5 FILE=$6 . /usr/share/cups/braille/cups-braille.sh shopt -s extglob # Construct list of pages from PAGERANGES PAGES=" " # Explicit list of pages AFTER= # All pages including and after this BEFORE= # All pages before and including this [ -n "$PAGERANGES" ] || PAGERANGES="1-" while [ -n "${PAGERANGES}" ] do PAGERANGE=${PAGERANGES/,*} PAGERANGE=${PAGERANGE%%*( )} PAGERANGE=${PAGERANGE##*( )} if [ -n "${PAGERANGES/*,*}" ] then # last range PAGERANGES="" else # Remove leading range PAGERANGES="${PAGERANGES#*,}" fi if [ -n "${PAGERANGE/*-*}" ] then # single-page PAGES="$PAGES$PAGERANGE " elif [ -z "${PAGERANGE%%*-}" ] then # To the end FIRST=${PAGERANGE%%-*} if [ -z "$AFTER" ] || [ "$FIRST" -lt "$AFTER" ] then AFTER="$FIRST" fi elif [ -z "${PAGERANGE##-*}" ] then # From the beginning LAST=${PAGERANGE##*-} if [ -z "$BEFORE" ] || [ "$LAST" -gt "$BEFORE" ] then BEFORE="$LAST" fi else # page range FIRST=${PAGERANGE/-*} LAST=${PAGERANGE/*-} PAGES="$PAGES$(seq "$FIRST" "$LAST" | tr $'\012' ' ')" fi done # Determine whether to print this page doprint() { PAGE="$1" if [ -n "$BEFORE" ] && [ "$PAGE" -le "$BEFORE" ] then echo 1 return elif [ -n "$AFTER" ] && [ "$PAGE" -ge "$AFTER" ] then echo 1 return fi case "$PAGES" in *\ $PAGE\ *) echo 1 return ;; esac echo 0 } if [ -z "$FILE" ] then cat else cat "$FILE" fi | ( P=1 DOPRINT=$(doprint $P) IFS=$'\n' read -r LINE EOF=$? while [ "$EOF" = 0 -o -n "$LINE" ] do while [ -n "$LINE" -a -z "${LINE/*$'\014'*}" ] do # Possibly print before FF HEAD=${LINE%%$'\014'*} [ $DOPRINT == 0 ] || printf %s "$HEAD"$'\014' # Next page P=$(($P + 1)) DOPRINT=$(doprint $P) # Drop head of line LINE=${LINE#*$'\014'} done # Remainder of line if [ "$EOF" = 0 ] then NL="\n" else NL="" fi [ $DOPRINT == 0 ] || printf "%s$NL" "$LINE" IFS=$'\n' read -r LINE EOF=$? done ) echo "INFO: Ready" >&2 exit 0