On Thu, Jun 30, 2005 at 05:48:03PM +0200, Mohammed Adnène Trojette wrote:
> Indeed. To be exhaustive, one should write a command-line parser that
> would affect the options to lp or lpr accordingly to their respective
> syntax.
> 
> That is what I try to do with this patch against the script, but only
> for the lp -d/lpr -P option, using getopt, from the essential package
> util-linux.

It didn't work for me, because apparently here a2ps gives -d to
a2ps-lpr-wrapper, instead of -P. I made a new version that accepts both:


--- a2ps-lpr-wrapper    2005-01-20 22:47:16.000000000 +0100
+++ a2ps-lpr-wrapper.fg 2005-07-01 11:27:29.000000000 +0200
@@ -1,12 +1,30 @@
-#!/bin/sh
+#!/bin/bash
 #
 # a2ps-lpr-wrapper - lp/lpr wrapper script for GNU a2ps on Debian
 #
 
+TEMP=`getopt -o d: -n 'a2ps-lpr-wrapper' -- "$@"`
+PRINTER=""
+
+if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
+
+# Note the quotes around `$TEMP': they are essential!
+eval set -- "$TEMP"
+
+while true ; do
+       case "$1" in
+               -d) PRINTER=$2; shift 2; break ;;
+               -P) PRINTER=$2; shift 2; break ;;
+               *) echo "usage: a2ps-lpr-wrapper -P [printer] [files]" ; exit 1 
;;
+       esac
+done
+
 # If /usr/bin/lp (from cupsys-client) exists, just use it.
 if [ -x /usr/bin/lp ]; then
-  /usr/bin/lp $*
+  if [ "x$PRINTER" != "x" ]; then d="-d $PRINTER"; else d=""; fi
+  /usr/bin/lp $d "$@"
 else
   # In case /usr/bin/lp is not available, then fall back /usr/bin/lpr.
-  /usr/bin/lpr $*
+  if [ "x$PRINTER" != "x" ]; then P="-P $PRINTER"; else P=""; fi
+  /usr/bin/lpr $P "$@"
 fi



-- 
Frank Gevaerts                                 [EMAIL PROTECTED]
fks bvba - Formal and Knowledge Systems        http://www.fks.be/
Stationsstraat 108                             Tel:  ++32-(0)11-21 49 11
B-3570 ALKEN                                   Fax:  ++32-(0)11-22 04 19

Reply via email to