"Fossies" - the Fresh Open Source Software Archive

Member "apsfilter/bin/aps2file.in" (24 Feb 2002, 2906 Bytes) of archive /linux/misc/old/apsfilter-7.2.8.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #! @shell@
    2 # -*- sh -*-
    3 #
    4 # $ApsCVS: src/apsfilter/bin/aps2file.in,v 1.1.2.7 2002/02/24 20:47:48 andreas Exp $
    5 #
    6 # aps2file, by Michael Loßin
    7 #
    8 # pass input data through apsfilter into a file ("print to file" mode)
    9 #
   10 # doesn't work with fake duplex mode, since two PostScript documents
   11 # (even and odd pages) will end up in one
   12 #
   13 
   14 unset Z_OPTS APSFILTER OUTPUT_FILE INPUT_FILE DEBUG
   15 QUEUE=${PRINTER:-lp}
   16 
   17 
   18 usage()
   19 {
   20     cat >&2 <<EOF
   21 aps2file: print to file using apsfilter
   22 
   23 Usage:
   24 	aps2file [-h] [-D] [-P queue] [-Z options] [-o output] [input]
   25 
   26 Options:
   27 	-h		show this help
   28 	-D		run apsfilter in debug mode ('set -x')
   29 	-P queue	name of printer queue to be used for apsfilter
   30 			(default: value of '\$PRINTER'; otherwise 'lp')
   31 	-Z options	comma separated option list
   32 			(default: empty)
   33 	-o output	output file
   34 			(default: stdout)
   35 	input		input file
   36 			(default: stdin)
   37 EOF
   38     exit 0
   39 }
   40 
   41 error()
   42 {
   43     echo >&2 "aps2file: $@"
   44     exit 1
   45 }
   46 
   47 parse_commandline()
   48 {
   49     while [ "$1" ]; do
   50 	case "$1" in
   51 	    -P)		shift; QUEUE="$1" ;;
   52 	    -P*)	QUEUE="${1#-P}" ;;
   53 
   54 	    -Z)		shift; Z_OPTS="-Z$1" ;;
   55 	    -Z*)	Z_OPTS="$1" ;;
   56 
   57 	    -o)		shift; OUTPUT_FILE="$1" ;;
   58 	    -o*)	OUTPUT_FILE="${1#-o}" ;;
   59 
   60 	    -h|--help)	usage ;;
   61 
   62 	    -D)		DEBUG="-x" ;;
   63 
   64 	    -*)		error "unknown option '$1'" ;;
   65 
   66 	    *)		if [ "$INPUT_FILE" ]; then
   67 			    error "at most one input file allowed"
   68 			else
   69 			    INPUT_FILE="$1"
   70 			fi ;;
   71 	esac
   72 	shift
   73     done
   74 }
   75 
   76 check_queue_name()
   77 {
   78     local q
   79 
   80     # apspreview provides a special configuration directory to aps2file
   81     # (supplied in environment variable APS_CONFDIR) and the proper queue
   82     # name, so we don't need to re-check it
   83     if [ -z "$APS_CONFDIR" ]; then
   84 	APS_CONFDIR="@sysconfdir@/apsfilter"
   85 
   86 	# if the queue name is an alias, parse printcap for the original name
   87 	if [ ! -d "$APS_CONFDIR/$QUEUE" ]; then
   88 	    # quote forward slashes
   89 	    q=$(echo "$QUEUE" | sed 's%/%\\/%')
   90 	    q=$("@awk@" -F":" "/^${q}[|:]|^[^#].*\|${q}[|:]/,/^#/ \
   91 		{ if (\$0 ~ /:sd=/) print \$2 }" < "@printcap@")
   92 	    if [ "$q" ]; then
   93 		QUEUE="${q##*/}"
   94 	    else
   95 		error "couldn't resolve printer name '$QUEUE' in @printcap@"
   96 	    fi
   97 	fi
   98     fi
   99 }
  100 
  101 print2file()
  102 {
  103     APSFILTER="$APS_CONFDIR/basedir/bin/apsfilter"
  104     if [ ! -x "$APSFILTER" ]; then
  105 	error "apsfilter not found at '$APSFILTER'"
  106     elif [ ! -f "$APS_CONFDIR/$QUEUE/apsfilterrc" ]; then
  107 	error "no configuration file found for queue '$QUEUE'"
  108     fi
  109 
  110     : ${INPUT_FILE:=/dev/stdin} ${OUTPUT_FILE:=/dev/stdout}
  111 
  112     # start with an almost empty environment to emulate running under LPRng;
  113     # input must not come from a file connected to a terminal
  114     cat "$INPUT_FILE" | env -i CONTROL=dummy APS2FILE_CONTEXT=dummy \
  115 	SPOOL_DIR="$QUEUE" "@shell@" $DEBUG "$APSFILTER" -h"$HOSTNAME" \
  116 	-n"$USER" -f$(basename "$INPUT_FILE") $Z_OPTS > "$OUTPUT_FILE"
  117 }
  118 
  119 #
  120 # main controls
  121 #
  122 
  123 parse_commandline "$@"
  124 check_queue_name
  125 print2file