#!/bin/csh -f

# Choose the largest type size from 5pt to 25pt to create a one page
# postscript file $1 from the text files given by $argv[2-].  If there
# is only one argument, it is the input, and the output is $1:r.ps.
# If no type size is small enough, the conversion is done in 5pt type
# with line truncation.

# ps1 does portrait, and ps1landscape does landscape

set fullprogname = $0
set progname = $fullprogname:t

if ($#argv < 1) echo 'Usage: $progname output filename ...  OR  $progname filename'

switch ($progname)
case *landscape:
  set rotation = "--landscape"
  breaksw
default:
  set rotation = ""
endsw

set outfile = $1
set infiles = ($argv[2-])

if ($#argv < 2) then
  set outfile = $1:r.ps
  set infiles = $1
endif

set fontsize = `binsearch 25 5 check2pages $rotation -p$outfile $infiles`

if ($status) then
  set fontsize = 5
  echo "${progname}: Will not fit on one page."
endif

echo "${progname}: printing with ${fontsize}pt font."
enscript -c -fCourier$fontsize $rotation -p$outfile $infiles
