#!/bin/bash
#
# Convert from standard unix text format to a text format suitable for
# sending to a HP Laserjet.
#
# Karl O. Pinc
#
# April 1, 1995
#
# This conversion consists of adding a carrage return to the end of each
# line and outputting a form-feed at the end.
#
# The $() and echo -ne are both bash specific.
filter=1
indent=1
while getopts :cw:l:i:n:h: arg ; do
   case $arg in
      c)   filter=0 ;;
      i)   if [ $OPTARG -ge 0 ] ; then
              ind=$OPTARG
              indent=0
           fi ;;
   esac
done

if [ $filter ] ; then
   sed -e s/$/$(echo -ne '\r')/
else
   # The lpr command was invoked with -l -- pass control chars literally.
   cat
fi | if [ $indent ] ; then
        # The lpr command was invoked with -i -- indent some spaces.
        sed -e "s/^/$( i=1
                       while [ $[i] -le $[ind] ] ; do
                          echo -n ' '
                          i=$i+1 
                       done )/"
     else
        cat
     fi
echo -ne '\f'

