#!/bin/tcsh

set filter=0
set range=
set out=

while ( 1 )
  set in=$1
  switch ( $in )
  case -a:
    set range="-a $2"
    shift
    shift
    breaksw
  case -c:
    set filter=1
    shift
    breaksw
  case -h:
    echo "print_listing [-a page-range] [-c] [-a range] [-o output] [-P printer] [input]"
    echo "  -c means 'convert from 1401 using ansi filter'"
    echo "  Range is page range first-last, default 1-eof"
    echo "  if '-o output' is absent, send output to default printer"
    echo "  if '-o output' is '-o -', send output to stdout"
    echo "  if input is absent, take from stdin"
    exit
  case -o:
    set out="-o $2"
    shift
    shift
    breaksw
  case -P:
    set out="-P $2"
    shift
    shift
    breaksw
  default:
    break
  endsw
end

if ( $filter ) then
  if ( .$in == . ) then
    ansi | a2ps --borders=no -B --columns=1 $range -r -l 135 $out
  else
    ansi < $in | a2ps --borders=no -B --columns=1 $range -r -l 135 $out
  endif
else
  a2ps --borders=no -B --columns=1 $range -r -l 135 $out $in
endif
