#! /bin/bash
# ll
# Daniel Hottinger <hodaniel@student.ethz.ch>
# 2001-2-28
#
# converts text files e.g. listings to postscript using enscript.
# 
# Changes:
#   2001-4-28 Added "-g" option

pageform="--margins=79:51:56"
eth="--fancy-header=eth" 
# --fancy-header=../../..$HOME/yourheader

while getopts "hrlB" OPT ; do
case $OPT in 
h )	echo
	echo "Usage: $0 [-r] [-l] filename [-g filenames] ..."
	echo
	echo "converts text files to postscript using enscript"
	echo
	echo "Options:"
	echo "  -r: landscape"
	echo "  -l: program listing style"
	echo "  -B: do not print the ETH header"
	echo "  -g: group files into one '.ps' file"
	echo
	exit ;;
r )	pageform="-2r" ;;
l )	listargs="-E -C -H" ;;
B )	eth="" ;;
esac
done

# shift $[$OPTIND-1]

ARGS=""
MYIFS=" "
while [ ! -z $1 ] ; do
  case $1 in
    -g) ARGS=$ARGS" "; MYIFS="%" ;;
    -?) ;;
    *)  ARGS=$ARGS$MYIFS$1 ;;
  esac
  shift
done

for a in $ARGS; do
  b=`echo $a | sed -e 's/^%//g; s/%/ /g'`

  enscript --mark-wrapped-lines=arrow \
    -o ps_`echo $b | sed -e 's/ /_/g; s/\./_/g'`.ps \
    $listargs $pageform $eth $b
done

