#!/bin/sh
exec 2>/dev/null
if [ $# -eq 1 ]; then
  if [ "$1" = "-h" ]; then
  echo "\tPermet d'envoyer une requete d'impression sur une autre machine"
  echo "\ten concervant la possibilite de specifier des options specifiques"
  echo "\ta l'imprimante comme si celle-ci etait locale a la station."
  echo " "
  echo "\t\tLa commande standard \"lp\" doit etre accessible."
  echo " "
  echo "usage: $0 [-d printer] [-nN] [-oOption] [-tTitre] <fichier1> <fichier2> .... "
  exit 0
  fi
fi
#
copies=1
printer=idfimp
tmp=/tmp/lpimp.$$
inp=/tmp/lpimp.inp$$
#
set -- `getopt d:n:o:t: $*`
if [ $? -ne 0 ]; then
  echo "usage: $0 [-d printer] [-nN] [-oOption] [-tTitre] <fichier1> <fichier2> .... "
  exit 1
fi
while [ $# -gt 0 ]; do
   case $1 in
   -d )
      printer=$2; shift 2;;
   -n )
      copies=$2; shift 2;;
   -o )
      options="$options $2"; shift 2;;
   -t )
      title=$2; shift 2;;
   -- )
      shift; break;;
   esac
done
if [ -z "$title" ]; then
  title="`basename $1`"
fi
echo "$title:$copies:$options" > $tmp
if [ "$*" ]; then
  lp -c -d$printer $tmp $*
else 		# c'est l'entree standard
  cat - > $inp
  lp -c -d$printer $tmp $inp
fi
rm -f $tmp $inp 2>/dev/null
exit 0

