LPRNG con 'interfaces' tipo HP-UX y SCO UNIX

Contenido/contents:
Intro
LPRNG
/etc/printcap
mi_wrapper
interfaces
Pagina principal/Home page

Intro
En los tiempos de Red Hat 7.3 tenia tanto CUPS como LPRng y el default era este ultimo e incluso se menciona que las configuraciones son separadas y no compatibles, a partir de RedHat 9 CUPS es el default pero seguia exitiendo LPRng, y ya habia una herramienta para migrar de un manejador a otro.
Ya para Fedora Core 1 solo habia CUPS y si encontraba LPRng lo reemplazaba.
Aqui explico como instalar el programa LPRng a partir de los fuentes y ademas modificarlo para que soporte el archivo de 'interfaces' que manejaba el spooler de HP-UX y SCO Unix que reconocia opciones para cada modelo de impresora.
Pudo haber sido mejor haber aprendido CUPS y usar sus opciones pero por compatibilidad con cientos de reportes que tengo codificados que hacian uso de esas opciones, por eso opte por el 'retroceso'. Como autodefensa dire que para las maquinas linux de los usuarios finales si uso CUPS sin problemas, LPRng solo lo empleo en el servidor.
LPRNG
Como lo indica la pagina de este producto es una version mejorada de la implementacion original de Berkeley y es compatible con las instalaciones actuales, incluso mi recomendacion es que tengan ya instalado el CUPS para que cuando se instale el LPRng lo reemplace.
[root@vieja ~]# ps -ef | grep cup
root      7905     1  0 Nov13 ?        00:00:00 cups-config-daemon
root     19109     1  0 Dec10 ?        00:00:00 cupsd
root      5698  9782  0 15:14 pts/2    00:00:00 grep cup
Como es usual el primer paso es obtener el archivo con todos los programas fuentes.
[root@vieja ~]# wget http://www.lprng.com/DISTRIB/LPRng/LPRng-3.8.28.tgz
--15:18:49--  http://www.lprng.com/DISTRIB/LPRng/LPRng-3.8.28.tgz
           => `LPRng-3.8.28.tgz'
Connecting to 192.6.2.40:8080... connected.
Proxy request sent, awaiting response... 200 OK
Length: 10,212,500 (9.7M) [application/x-tar]

100%[====================================>] 10,212,500   198.66K/s    ETA 00:00

15:19:51 (161.59 KB/s) - `LPRng-3.8.28.tgz' saved [10212500/10212500]
El siguiente paso es descomprimirlo.
[root@vieja ~]# tar xvfz LPRng-3.8.28.tgz
LPRng-3.8.28/
LPRng-3.8.28/src/
LPRng-3.8.28/src/AUTHENTICATE/
LPRng-3.8.28/src/AUTHENTICATE/sserver.c
LPRng-3.8.28/src/AUTHENTICATE/sclient.c
...
...
LPRng-3.8.28/README.SSL.SECURITY
LPRng-3.8.28/TODO
LPRng-3.8.28/intl/
LPRng-3.8.28/KERBEROS_configuration
[root@vieja ~]# cd LPRng-3.8.28
[root@vieja LPRng-3.8.28]#
El siguiente paso es el ./configure, pero en este caso para no dar una por una cada opcion y ademas para no 'sufrir' buscando las opciones correctas que en muchas ocaciones no sabemos cuales son, aqui ya nos ayudan con un script que tiene las opciones 'standard' que debe de llevar en la 'mayoria' de los casos.
[root@vieja LPRng-3.8.28]# ./STANDARD_configuration
+ '[' -d /usr/share/man ']'
+ mandir=--mandir=/usr/share/man
+ for i in /usr/kerberos /usr/local/kerberos /usr/local
+ '[' -d /usr/kerberos/include ']'
+ '[' -d /usr/kerberos/lib ']'
+ for i in /usr/kerberos /usr/local/kerberos /usr/local
+ '[' -d /usr/local/kerberos/include ']'
+ '[' -d /usr/local/kerberos/lib ']'
+ for i in /usr/kerberos /usr/local/kerberos /usr/local
+ '[' -d /usr/local/include ']'
+ CPPFLAGS=' -I/usr/local/include'
+ '[' -d /usr/local/lib ']'
+ LDFLAGS=' -L/usr/local/lib'
+ sh ./configure --prefix=/usr --sysconfdir=/etc --mandir=/usr/share/man --disab
le-shared --disable-kerberos --enable-ssl --enable-force_localhost 'LDFLAGS= -L/
usr/local/lib' 'CPPFLAGS= -I/usr/local/include'
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
LOCALEDIR defaults to ${prefix}/share/locale
checking for gawk... gawk
checking for sed... /bin/sed
....
....
....
config.status: executing default-1 commands
config.status: creating po/POTFILES
config.status: creating po/Makefile
config.status: creating po/POTFILES
config.status: creating po/Makefile
config.status: executing default commands
Ahora si ya procedemos a compilar el programa con el comando make.
[root@vieja LPRng-3.8.28]# make
if [ "UTILS" = po ] ; then \
    for i in po/Makefile* ; do \
        if [ -f "$i" ] ; then \
            if grep '^mkinstalldirs.*=.*case' $i ; then \
                echo "fixing broken $i which causes wrong path to mkinstalldirs
to be used"; \
                perl -spi -e 's:^mkinstalldirs\s*=\s*.*:mkinstalldirs = \$(SHELL
) \$(MKINSTALLDIRS):' $i; \
            fi \
        fi \
    done \
fi
if [ "UTILS" != po -o "no" != "no" ] ; then \
        cd UTILS; make localedir=/usr/share/locale \
                DESTDIR= all ; \
fi
make[1]: Entering directory `/root/LPRng-3.8.28/UTILS'
make[1]: Nothing to be done for `all'.
....
....
PREREMOVE 'preremove.linux'
OSNAME=linux-gnu; case "linux-gnu" in *linux* ) OSNAME=linux;; esac; \
if test -f postremove.${OSNAME} ; then s=postremove.${OSNAME} ; else s=postremov
e.generic; fi; \
echo POSTREMOVE "'$s'"; cp $s postremove;
POSTREMOVE 'postremove.generic'
cp src/lpd.conf lpd.conf
chmod 644 lpd.conf
Por ultimo se debe de instalar el LPRng.
[root@vieja LPRng-3.8.28]# make install
if [ "UTILS" = po ] ; then \
    for i in po/Makefile* ; do \
        if [ -f "$i" ] ; then \
            if grep '^mkinstalldirs.*=.*case' $i ; then \
                echo "fixing broken $i which causes wrong path to mkinstalldirs
to be used"; \
                perl -spi -e 's:^mkinstalldirs\s*=\s*.*:mkinstalldirs = \$(SHELL
) \$(MKINSTALLDIRS):' $i; \
            fi \
        fi \
    done \
fi
if [ "UTILS" != po -o "no" != "no" ] ; then \
        cd UTILS; make localedir=/usr/share/locale \
                DESTDIR= all ; \
fi
make[1]: Entering directory `/root/LPRng-3.8.28/UTILS'
make[1]: Nothing to be done for `all'.
....
....
Installing configuration files
Installing lpd.perms.sample in /etc/lpd as /etc/lpd/lpd.perms
Directory /etc/lpd does not exist!
Installing lpd.conf.sample in /etc/lpd as /etc/lpd/lpd.conf
Installing printcap.sample in /etc as /etc/printcap
Installing init.redhat.sample in /etc/lpd as /etc/lpd/lpd
Running startup scripts
Stopping CUPS server
Stopping cups: [  OK  ]
cups-lpd: unrecognized service
Stopping LPD server
lpr: unrecognized service
lprng: unrecognized service
Stopping lpd: [FAILED]
running chkconfig
error reading information on service lpr: No such file or directory
error reading information on service lprng: No such file or directory
Checking Printcap
Warning -   changing ownership '//var/spool/lpd/prueba' to 2/2
Warning -   changing ownership '//var/spool/lpd/prueba' to 2/2
Warning -   changing ownership '//var/spool/lpd/AdobePDF' to 2/2
Warning -   changing ownership '//var/spool/lpd/AdobePDF' to 2/2
Warning -   changing ownership '//var/spool/lpd/EFISoftwarePrinter' to 2/2
Warning -   changing ownership '//var/spool/lpd/EFISoftwarePrinter' to 2/2
Warning -   changing ownership '//var/spool/lpd/EFISoftwarePrinterAT' to 2/2
Warning -   changing ownership '//var/spool/lpd/EFISoftwarePrinterAT' to 2/2
Warning -   changing ownership '//var/spool/lpd/Stylus_Photo_2200' to 2/2
Warning -   changing ownership '//var/spool/lpd/Stylus_Photo_2200' to 2/2
Running LPRng Startup Scripts
lpd             0:off   1:off   2:off   3:off   4:off   5:off   6:off
Starting Printer
Starting lpd: [  OK  ]
Printer Started
Toma nota como la instalacion, detiene el servicio CUPS y arranca el servicio LPD.
/etc/printcap
Aunque existe una utilieria para configurar en modo grafico las impresoras yo no la uso por lo cual yo modifico a mano el archivo /etc/printcap.
# /etc/printcap
laser8150:\
        :sh:\
        :ml=0:\
        :mx=0:\
        :sd=/var/spool/lpd/laser8150:\
        :lp=|/usr/share/printconf/util/jetdirectprint:\
        :lpd_bounce=true:\
        :if=/usr/share/printconf/util/mi_wrapper:
Notese que yo uso el comando mi_wrapper no el mf_wrapper que es el viene incluido con el paquete. Ademas yo mando a imprimir a impresoras conectadas en red con su tarjeta interna o servidor externo.
wrapper
LPRng incluye un programa que a traves de 'magic filter' (mf) decide cual es la mejor manera de imprimir un archivo, pero cuando tu generas el archivo con secuencias de escape la deteccion automatica falla y ademas no te puede reconocer algunas opciones que tu quieras.
Es por eso que yo hice 'mi' aplicativo para que todas opciones con que se invoque el lpr o lp sean turnadas al archivo de interfase de cada impresora para ser interpretadas.
De esa manera puedo tener un archivo de interfase para una impesora laser u otro para una impresora matricial, etc.
[root@vieja etc]# cat /usr/share/printconf/util/mi_wrapper
#!/bin/bash
#
REQ="def"
QUEUE="def"
OPTIONS="def"
TITLE="Title"
COPIES=1
for p in $*
do
   dos=`echo $p | cut -c1,2`
   resto=`echo $p | cut -c3-,`
   case "$dos" in
      -Q) QUEUE=$resto
          ;;
      -Z) OPTIONS=$resto
          ;;
      -j) REQ=$resto
          ;;
   esac
done
TMPFILE=`mktemp /tmp/printspool.XXXXXX`
cat >$TMPFILE
/var/spool/lpd/interfaces/$QUEUE $REQ $QUEUE $TITLE $COPIES $OPTIONS $TMPFILE
if [ -f $TMP_FILE ]
then
       rm -f $TMPFILE
fi
exit 0
interfaces
Estos archivos los copie de cuando tenia instalado HP-UX y SCO en mi maquina, el primero es para una impresora laser.
:
#       @(#) HPLaserJet 25.3 95/03/27
#
#       Copyright (C) 1991-1995 The Santa Cruz Operation, Inc.
#               All Rights Reserved.
#       The information in this file is provided for the exclusive use of
#       the licensees of The Santa Cruz Operation, Inc.  Such users have the
#       right to use, modify, and incorporate this code into other products
#       for purposes authorized by the license agreement provided they include
#       this notice and the associated copyright notice with any such product.
#       The information in this file is provided "AS IS" without warranty.
#
# Printer Command Language level V model

# /usr/spool/lp/model/HPLaserJet

# This script supports PCL V functionality with HP LaserJets.
# To understand all of the options available for use with the lp
# command, please review the list below.

#=======================================================================#
# OPTIONS RECOGNIZED: ( all may be preceded by a "-" )                  #
#                                                                       #
# Horizontal Pitch Selection                                            #
#       10, pica        10 characters/inch (cpi)                        #
#       12, elite       12 cpi                                          #
#       c               compressed print pitch                          #
#       e               expanded print pitch                            #
#       fp#             set primary font pitch to # cpi                 #
#       sfp#            set secondary font pitch to # cpi               #
#                           ( # may be floating point )                 #
#                           ( e.g. 16.66 = compressed )                 #
#       hsi#            set horizontal spacing increment (#/120's inch) #
#                           ( e.g. hsi10 is the same as 12 cpi)         #
#                           ( See your printer reference manual)        #
#                                                                       #
# Print Quality Selection                                               #
#       q#              set primary print quality to #                  #
#       sq#             set secondary print quality to #                #
#                           ( possible values for quality # )           #
#                           ( 0 = draft, 1 = near letter quality )      #
#                           ( 2 = letter quality )                      #
#       nlq             set primary print quality to near letter quality#
#       lq              set primary print quality to letter quality     #
#       dq              set primary print quality to draft quality      #
#                                                                       #
# Print Spacing Selection                                               #
#       ps              set primary font to proportional spacing        #
#       sps             set secondary font to proportional spacing      #
#       fs              set primary font to fixed spacing               #
#       sfs             set secondary font to fixed spacing             #
#                                                                       #
# Vertical Pitch Selection                                              #
#       lpi#            print at # lines per inch                       #
#                           ( default is 6 lpi)                         #
#       vsi#            set vertical spacing increment to (#/48's in)   #
#                           (  e.g. vsi4 is the same as 12 lpi )        #
#                           ( See your printer reference manual)        #
#                                                                       #
# Font Selection                                                        #
#       cs#$            set primary character set to #$                 #
#       scs#$           set secondary character set to #$               #
#                           ( See your printer reference manual )       #
#                           ( for possible character sets. )            #
#                           ( e.g. cs8U sets Roman 8 character set )    #
#       r8              Roman 8 character set                           #
#       k8              Kana 8 character set                            #
#       height#         set primary height to #                         #
#       sheight#        set secondary height to #                       #
#       style#          set primary font style to #                     #
#       sstyle          set secondary font style to #                   #
#                           ( possible values for style # )             #
#                           ( 0 = upright, 1 = italic, 2 = slant )      #
#       i | italics     set primary font style to italic                #
#       si | sitalics   set secondary font style to italic              #
#       upright         set primary font style to upright               #
#       supright        set secondary font style to upright             #
#       slant           set primary font style to slant                 #
#       sslant          set secondary font style to slant               #
#       type#           set primary font typeface to #                  #
#       stype#          set secondary font typeface to #                #
#       weight#         set primary font stroke weight to #             #
#       sweight#        set secondary font stroke weight to #           #
#                           ( <0 = light, 0 = medium, >0 = bold )       #
#                           ( typical range is -7 to +7         )       #
#                           ( consult printer reference manual  )       #
#       b | bold        set font stroke weight to bold ( # = 1 )        #
#                                                                       #
# Page Length Selection                                                 #
#       lnnn            set absolute length of page to nnn lines        #
#                           ( default is 66 )                           #
#       tlnnn           set text length of page to nnn lines            #
#                           ( default is 60 in portrait mode, )         #
#                           ( 45 in landscape mode )                    #
#                                                                       #
# Margin Selection                                                      #
#       lm#             set left margin in column #                     #
#       rm#             set right margin in column #                    #
#                           ( left most column = 0 )                    #
#                                                                       #
# Page Orientation: (Default portrait)                                  #
#       portrait        portrait mode orientation                       #
#       landscape       landscape mode orientation                      #
#                                                                       #
# Output filtering: (Default Cooked)                                    #
#       r  | raw        raw mode for plotting mode etc.                 #
#       n  | nroff      set up to properly print output from nroff      #
#       pr              set up to properly print output from pr         #
#       nb              do not output banner page (to save paper)       #
#                                                                       #
# Paper Control: (Default single sided feed from paper cassette)        #
#       m | man         set up for manual sheet feed                    #
#       d | double      do automatic double sided printing              #
#               * If your printer is not capable of duplex printing,    #
#                 use 'md' or 'mdouble' option.                         #
#       md | mdouble    do manual double sided printing                 #
#       ub | ubin       feed paper from upper cassette                  #
#       lb | lbin       feed paper from lower cassette                  #
#                                                                       #
# Options for hpgl2-files:                                              #
#       hpgl2   set the printer to hpgl2-mode and reset it after        #
#                printing to pcl-mode (Orientation in landscape mode)   #
#                                                                       #
#       hpgl2_p set the printer to hpgl2-mode, change the orientation   #
#               to protrait and reset after printing to pcl-mode        #
#                                                                       #
# Options for Postscript:                                               #
#       postscript      set the printer language to PostScript and      #
#                       reset it after printing to pcl-mode             #
#=======================================================================#
#
# POSSIBLE USER ENHANCEMENT: By default the laserjet printer will
# print 60 lines of text per page. It is possible to get 66 lines of
# text on the printable portion of the page when using the letter size
# (8.5 by 11 inches) paper cartridge or 70 lines per page when using
# the A4 size (297 by 210 mm) paper cartridge. The instructions for
# modifying this model to get either of these capabilities by default
# are given below under the heading "POSSIBLE USER ENHANCEMENT".
# NOTE: Use of the 'vsi', 'lpi', 'pr', 'nroff', 'l', 'orientation'
# 'half' or 'quarter' options will negate the effects of this enhancement.
# Be sure to read the above USER CAUTION before modifying this model.

if [ -x "/usr/spool/lp/bin/drain.output" ]
then
        DRAIN="/usr/spool/lp/bin/drain.output 1"
else
        DRAIN=
fi

#
# Set up FILTER environment variable.
#
#
: ${SPOOLDIR:=/usr/spool/lp}
: ${LOCALPATH:=${SPOOLDIR}/bin}
if [ ! -x "${LPCAT:=${LOCALPATH}/lp.cat}" ]
then
        LPCAT="cat"
fi

if [ -z "${FILTER}" ]
then
        FILTER="${LPCAT} 0"
fi

PATH="/bin:/usr/bin:/usr/lib"
export PATH

# Save the arguments to the model
printer=`basename $0`
request=$1
name=$2
title=$3
copies=$4
options="`echo $5 | sed 's/,/ /g'`"

if [ -z "${BANNERS}" ]
then
        nhead=1
else
        nhead=${BANNERS}
fi


# Definitions of functions used within this script

do_banner()
{
#       if      nhead=`grep "^BANNERS=" /etc/default/lpd 2>/dev/null    |
#                      line                                             |
#                       awk -F= '{ print $2 }'`
#               [ "N$nhead" = "N" ]
#       then
#               nhead=1
#       fi

        # Print the standard header
        x="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXX"
        while [ $nhead -gt 0 ]
        do
                echo -e -n "\r"
                echo -e -n "$x\n$x\n$x\n$x\n"
                user=`sed -n "s/^$name:.*:.*:.*:\(.*\):.*:.*$/\1/p" /etc/passwd`
                if [ -n "$user" ]
                then
                        echo -e -n "User: $user\n"
                else
                        echo -e -n "\n"
                fi
                echo -e -n "Request id: $request    Printer: `basename $0`\n"
                echo -e -n "Options: $options\n"
                date
                echo -e -n "\n"
                if [ -n "$title" ]
                then
                        banner "$title"
                fi
                echo -e -n "\f"
                nhead=`expr $nhead - 1`
        done
}


# Set up interface
if [ -t 1 ]
then
        stty raw 9600 -parenb cs8 ixon -istrip clocal <&1 2>/dev/null
#else
#       slp -r 2>/dev/null
fi

# Handle disable and cancel traps.
trap "echo '\nCANCELLED!!\033E';trap 15;kill -15 0;exit 0" 15


# Initialize option variables to default values
length="def"
pitch="def"
spitch="def"
hsi="def"
quality="def"
squality="def"
spacing="def"
sspacing="def"
lpi="def"
vsi="def"
charset="def"
scharset="def"
height="def"
sheight="def"
style="def"
sstyle="def"
typeface="def"
stypeface="def"
weight="def"
sweight="def"
pagelen="def"
tpagelen="def"
lmargin="def"
rmargin="def"
outputmode="cooked"
banner=""
orientation="def"
pagemode="def"
nroff=""
italics=""
duplex="simplex"
paper="letter"
format=""
outb="def"

# Determine which options have been invoked

for i in $options
do
        case "$i" in

        -postscript | postscript)
                format="PS"
                outputmode="raw";;

        -hpgl2 | hpgl2)
                format="HPGL2"
                outputmode="raw";;

        -hpgl2_p | hpgl2_p)
                format="HPGL2_P"
                outputmode="raw";;

        -10 | 10 | -pica | pica | cpi=10)       # font pitch set to 10.00 cpi
                pitch="10";;

        -12 | 12 | -elite | elite | cpi=12)     # font pitch set to 12.00 cpi
                pitch="12";;

        -c | c | -compressed | compressed)      # font pitch set to compressed p
rint
                pitch="c";;

        -e | e)         # font pitch set to expanded print
                pitch="e";;

                        # set primary font pitch to value following fp
        -fp[0-9]* | fp[0-9]* | -fp.[0-9]* | fp.[0-9]*)
                pitch="`echo -e -n "$i" | sed 's/^[-]*fp//'`";;

        -cpi=[0-9]* | cpi=[0-9]*)
                pitch="`echo -e -n "$i" | sed 's/^[-]*cpi=//'`";;

                        # set secondary font pitch to value following sfp
        -sfp[0-9]* | sfp[0-9]* | -sfp.[0-9]* | sfp.[0-9]*)
                spitch="`echo -e -n "$i" | sed 's/^[-]*sfp//'`";;

        -scpi=[0-9]* | scpi=[0-9]*)
                spitch="`echo -e -n "$i" | sed 's/^[-]*scpi=//'`";;

                        # set horizontal spacing increment to #/120 in.
        -hsi[0-9]* | hsi[0-9]*)
                hsi="`echo -e -n "$i" | sed 's/^[-]*hsi//'`";;

                        # set primary font quality to 0,1, or 2
        -q[0-2] | q[0-2])
                quality="`echo -e -n "$i" | sed 's/^[-]*q//'`";;

                        # set secondary font quality to 0,1, or 2
        -sq[0-2] | sq[0-2])
                squality="`echo -e -n "$i" | sed 's/^[-]*sq//'`";;

        -nlq | nlq)             # set font quality to near letter quality
                quality=1
                squality=1;;

        -lq | lq)       # set font quality to letter quality
                quality=2
                squality=2;;

        -dq | dq)       # set font quality to draft quality
                quality=0
                squality=0;;

        -ps | ps | prop | -prop)        # set primary font to proportional spaci
ng
                spacing=prop;;

        -sps | sps | sprop | -sprop)    # set secondary font to proportional spa
cing
                sspacing=prop;;

        -fs | fs)       # set primary font to fixed spacing
                spacing=fixed;;

        -sfs | sfs)     # set  secondary font to fixed spacing
                sspacing=fixed;;

                        # set lines per inch to value following lpi
        -lpi[0-9]* | lpi[0-9]*)
                lpi="`echo -e -n "$i" | sed 's/^[-]*lpi//'`";;

        -lpi=[0-9]* | lpi=[0-9]*)
                lpi="`echo -e -n "$i" | sed 's/^[-]*lpi=//'`";;

                        # set vertical spacing increment to #/48 inch
        -vsi[0-9]* | vsi[0-9]*)
                vsi="`echo -e -n "$i" | sed 's/^[-]*vsi//'`";;

                        # set primary character set to value following cs
        -cs[0-9]* | cs[0-9]*)
                charset="`echo -e -n "$i" | sed 's/^[-]*cs//'`";;

                        # set secondary character set to value following scs
        -scs[0-9]* | scs[0-9]*)
                scharset="`echo -e -n "$i" | sed 's/^[-]*scs//'`";;

        -r8 | r8)       # primary character set is Roman8
                charset="8U";;

        -k8 | k8)       # primary character set is Kana8
                charset="8K";;

                        # set height to value after height
        -height[0-9]*.[0-9]* | height[0-9]*.[0-9]*)
                height="`echo -e -n "$i" | sed 's/^[-]*height//'`";;

                        # set sheight to value after sheight
        -sheight[0-9]*.[0-9]* | sheight[0-9]*.[0-9]*)
                sheight="`echo -e -n "$i" | sed 's/^[-]*sheight//'`";;

                        # set font style accordingly
        -style[0-2] | style[0-2])
                style="`echo -e -n "$i" | sed 's/^[-]*style//'`";;

        -sstyle[0-2] | sstyle[0-2])
                sstyle="`echo -e -n "$i" | sed 's/^[-]*sstyle//'`";;

        -i | i | -italics | italics | italic | -italic)
                style=italic;;

        -si | si | -sitalics | sitalics | sitalic | -sitailc)
                sstyle=italic;;

        -upright | upright)
                style=upright;;

        -supright | supright)
                sstyle=upright;;

        -slant | slant)
                style=slant;;

        -sslant | sslant)
                sstyle=slant;;

                        # set primary typeface to value after type
        -type[0-9]* | type[0-9]*)
                typeface="`echo -e -n "$i" | sed 's/^[-]*type//'`";;

                        # set secondary typeface to value after stype
        -stype[0-9]* | stype[0-9]*)
                stypeface="`echo -e -n "$i" | sed 's/^[-]*stype//'`";;

                        # set primary font weight to +- #
        -weight[0-9]* | weight[0-9]* | -weight-[0-9]* | weight-[0-9]*)
                weight="`echo -e -n "$i" | sed 's/^[-]*weight//'`";;

                        # set secondary font weight to +- #
        -sweight[0-9]* | sweight[0-9]* | -sweight-[0-9]* | sweight-[0-9]*)
                sweight="`echo -e -n "$i" | sed 's/^[-]*sweight//'`";;

                        # set font weight to bold
        -b | b | -bold | bold)
                weight=1
                sweight=1;;

                        #set absolute length of page to the value following l
        -l[0-9]* | l[0-9]*)
                pagelen="`echo -e -n "$i" | sed 's/^[-]*l//'`";;

        length=[0-9]* | -length=[0-9]*)
                pagelen="`echo -e -n "$i" | sed 's/^[-]*length=//'`";;

                        #set text length of page to the value following tl
        -tl[0-9]* | tl[0-9]*)
                tpagelen="`echo -e -n "$i" | sed 's/^[-]*tl//'`";;

                        # set left margin in column given by value after lm
        -lm[0-9]* | lm[0-9]*)
                lmargin="`echo -e -n "$i" | sed 's/^[-]*lm//'`";;

        -lm=[0-9]* | lm=[0-9]*)
                lmargin="`echo -e -n "$i" | sed 's/^[-]*lm=//'`";;

                        # set right margin in column given by value after rm
        -rm[0-9]* | rm[0-9]*)
                rmargin="`echo -e -n "$i" | sed 's/^[-]*rm//'`";;

        -rm=[0-9]* | rm=[0-9]*)
                rmargin="`echo -e -n "$i" | sed 's/^[-]*rm=//'`";;

                        # raw mode for binary output to printer
        -r | r | -raw | raw)
                outputmode="raw";;

        nb | -nb | nobanner | -nobanner)        # Do not output banner page
                banner="";;

        -portrait | portrait | port | -port) # select portrait orientation
                orientation="portrait";;

        -landscape | landscape | land | -land) # select landscape orientation
                orientation="landscape";;

        -d | d | -duplex | duplex)      # set up for automatic double sided copy
                duplex="vduplex";;

        -hduplex | hduplex)     # set up for automatic double sided copy
                duplex="hduplex";;

        -legal | legal) # TamaƱficio
                paper="legal";;

        -md | md | -mdouble | mdouble)  # set up for manual double sided copy
                outputmode="mdouble";;

        -m | m | -man | man | manual | -manual) # set up printer for manual shee
t feed
                pagemode="man";;

        -ub | ub | -ubin | ubin | upper | -upper) # set up printer to feed from
upper cassette
                pagemode="ubin";;

        -lb | lb | -lbin | lbin | lower | -lower) # set up printer to feed from
lower cassette
                pagemode="lbin";;

                        # set up printer to properly print output from nroff
        -n | n | -nroff | nroff)
                nroff="-n"
                length="-l66";;

        -pr | pr)       # set up printer to properly print output from pr
                nroff="-p"
                length="";;

        bin1 | topbin)  # to top bin
                outb="UPPER" ;;

        bin2 | rearbin) # to back bin
                outb="LOWER" ;;

        bin*)
                binnum=`echo "$i" | sed 's/^bin//'`
                binnum=`expr $binnum - 1`
                outb="OPTIONALOUTBIN$binnum" ;;

        esac
done

# Assume that the rest of the arguments are files
shift;shift;shift;shift;shift
files="$*"

echo -e "\033%-12345X@PJL JOB NAME = \"spooler\""
if [ $outb != "def" ]
then
    echo "@PJL SET OUTBIN = $outb"
fi
echo "@PJL SET COPIES=1"
echo "@PJL enter language=PCL"

# Set up printer default modes
echo -e -n "\033E"              # Reset Printer
echo -e -n "\033)0B"    # Secondary character set line draw
echo -e -n "\033&k2G"   # Set line termination mode.

# print the banner if no banner not specified and reversing is not specified
if [ -n "$banner" ]
then
        case "$pagemode" in
                def);;
                man)    echo -e -n "\033&l2H";;
                ubin)   echo -e -n "\033&l1H";;
                lbin)   echo -e -n "\033&l4H";;
        esac
        do_banner
        echo -e -n "\033E"              # Reset Printer
        echo -e -n "\033)0B"    # Secondary character set line draw
        echo -e -n "\033&k2G"   # Set line termination mode.
fi


# If raw mode and RS232 interface used turn off output processing
if [ "$outputmode" = "raw" ]
then
        stty raw 9600 -opost -parenb cs8 ixon -istrip clocal tab0 <&1 2>/dev/nul
l
        echo -e -n "\033&k0G"   # Reset line termination mode
fi

# Print the spooled files
i=1
while [ $i -le $copies ]
do
        for file in $files
        do
                case "$paper" in
                        letter) echo -e -n "\033&l2A";;
                        legal)  echo -e -n "\033&l3A";;
                        def) ;;
                esac

                case "$duplex" in
                        def) ;;
                        simplex) echo -e -n "\033&l0S";;
                        vduplex) echo -e -n "\033&l1S";;
                        hduplex) echo -e -n "\033&l2S";;
                esac

                case "$orientation" in
                        def);;
                        portrait)       echo -e -n "\033&l0O";;
                        landscape)      echo -e -n "\033&l1O"
                                        length="-l66";;
                esac

                case "$vsi" in
                        def);;
                        *)      echo -e -n "\033&l${vsi}C";;
                esac

                case "$lpi" in
                        def);;
                        *)      echo -e -n "\033&l${lpi}D";;
                esac

                case "$pagelen" in
                        def)    if [ "$length" = "def" ]
                                then
                                        length="-l60"
                                fi
#
# POSSIBLE LASERJET ENHANCEMENT:
# To set the default output on the laserjet printer to be 66 lines
# per page and 80 characters per line with a 4 character left
# margin and a 2 line top margin remove the leading '#' from the
# following 7 lines.
                                if [ "$vsi" = "def" -a "$lpi" = "def" -a "$orien
tation" != "landscape" -a "$nroff" = "" -a "$dividing" = "" ]
                                then
                                        echo -e -n "\033&l66p3e7.4c66F"
                                        echo -e -n "\033&a0L"
                                        echo -e -n "\033&k11H"
                                        length="-l66"
                                fi
# If you are using A4 size paper (297 x 210 mm) and desire 70 lines per
# page instead of 66 along with the other characteristics described
# above replace the three occurrences of '66' in the above lines with
# '70' and remove the leading '#' as described.
                                ;;
                        *)      echo -e -n "\033&l${pagelen}P"
                                length="-l$pagelen";;
                esac

                case "$tpagelen" in
                        def);;
                        *)      echo -e -n "\033&l${tpagelen}F"
                                length="-l$tpagelen";;
                esac

                case "$charset" in
                        def);;
                        *)      echo -e -n "\033(${charset}";;
                esac

                case "$scharset" in
                        def);;
                        *)      echo -e -n "\033)${scharset}";;
                esac

                case "$spacing" in
                        def);;
                        prop)   echo -e -n "\033(s1P";;
                        fixed)  echo -e -n "\033(s0P";;
                esac

                case "$sspacing" in
                        def);;
                        prop)   echo -e -n "\033)s1P";;
                        fixed)  echo -e -n "\033)s0P";;
                esac

                case "$pitch" in
                        def);;
                        c)      echo -e -n "\033&k2S";;
                        e)      echo -e -n "\033&k1S";;
                        *)      echo -e -n "\033(s${pitch}H";;
                esac

                case "$spitch" in
                        def);;
                        *)      echo -e -n "\033)s${spitch}H";;
                esac

                case "$hsi" in
                        def);;
                        *)      echo -e -n "\033&k${hsi}H";;
                esac

                case "$quality" in
                        def);;
                        *)      echo -e -n "\033(s${quality}Q";;
                esac

                case "$squality" in
                        def);;
                        *)      echo -e -n "\033)s${squality}Q";;
                esac

                case "$height" in
                        def);;
                        *)      echo -e -n "\033(s${height}V";;
                esac

                case "$sheight" in
                        def);;
                        *)      echo -e -n "\033)s${sheight}V";;
                esac

                case "$style" in
                        def);;
                        italic) echo -e -n "\033(s1S"
                                italics="-i";;
                        slant)  echo -e -n "\033(s2S";;
                        *)      echo -e -n "\033(s${style}S";;
                esac

                case "$sstyle" in
                        def);;
                        italic) echo -e -n "\033)s1S";;
                        slant)  echo -e -n "\033)s2S";;
                        *)      echo -e -n "\033)s${sstyle}S";;
                esac

                case "$weight" in
                        def);;
                        *)      echo -e -n "\033(s${weight}B";;
                esac

                case "$sweight" in
                        def);;
                        *)      echo -e -n "\033)s${sweight}B";;
                esac

                case "$typeface" in
                        def);;
                        *)      echo -e -n "\033(s${typeface}T";;
                esac

                case "$stypeface" in
                        def);;
                        *)      echo -e -n "\033)s${stypeface}T";;
                esac

                case "$lmargin" in
                        def);;
                        *)      echo -e -n "\033&a${lmargin}L";;
                esac

                case "$rmargin" in
                        def);;
                        *)      echo -e -n "\033&a${rmargin}M";;
                esac

                case "$pagemode" in
                        def);;
                        man)    echo -e -n "\033&l2H";;
                        ubin)   echo -e -n "\033&l1H";;
                        lbin)   echo -e -n "\033&l4H";;
                esac

                case "$outputmode" in
                          raw)    case "$format" in
                                  HPGL2)
                                    echo -e -n "\033E"
                                    echo -e -n "\033&l3O\033%1B";;
                                  HPGL2_P)
                                    echo -e -n "\033E"
                                    echo -e -n "\033%1B";;
                                  PS)
                                    echo -e -n "\033%-12345X@PJL enter language=
postscript";;
                                  *) ;;
                                  esac
                                  cat <${file};;
                          cooked) echo -e -n "\r"
                                  cat <${file};;
                          mdouble) cat <${file}
                                   echo -e -n "\033&l2H"
                                   cat <${file}
                                   ;;
                    esac
                echo -e -n "\033E"              # Reset Printer
                echo -e -n "\033)0B"    # Secondary character set line draw
                echo -e -n "\033&k2G"   # Set line termination mode.
        done
        i=`expr $i + 1`
done

# Reset printer to PCL mode

case "$format" in
    HPGL2)
      echo -e -n "\033%1A";;
    HPGL2_P)
      echo -e -n "\033%1A";;
    PS)
      echo -e -n "\033%-12345X@PJL enter language=pcl";;
*) ;;
esac
echo -e "\033E\033%-12345X@PJL"
echo "@PJL RESET"
echo "@PJL EOJ NAME = \"spooler\""
echo -e "\033%-12345X"

# RS-232 interface insure all buffers are flushed to printer
stty raw 9600 -parenb cs8 ixon -istrip clocal <&1 2>/dev/null

#Draining characters might be necessary.
${DRAIN}

exit 0
Este otro es para impresoras matriciales que no soportan mayores opciones
:
#       @(#) crnlmap 25.2 95/03/27
#
#       Copyright (C) 1985-1995 The Santa Cruz Operation, Inc.
#               All Rights Reserved.
#       The information in this file is provided for the exclusive use of
#       the licensees of The Santa Cruz Operation, Inc.  Such users have the
#       right to use, modify, and incorporate this code into other products
#       for purposes authorized by the license agreement provided they include
#       this notice and the associated copyright notice with any such product.
#       The information in this file is provided "AS IS" without warranty.
#
#!      Serial or parallel printer requiring  mapped to 
#

printer=`basename $0`
request=$1
name=$2
title=$3
copies=$4
options=$5
shift; shift; shift; shift; shift
files=$*

# If it is necessary to change the baud rate or other stty settings for
# your serial printer add the appropriate options here:
stty ixon onlcr opost 0<&1

# border around the banner
x="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
banner="no"

if [ -z "${BANNERS}" ]
then
        nhead=1
else
        nhead=${BANNERS}
fi

#Set up some global variables.
: ${SPOOLDIR:=/usr/spool/lp}
: ${LOCALPATH:=${SPOOLDIR}/bin}

#Set up the default filter.
if [  -x "${LOCALPATH}/lp.cat" ]
then
        LPCAT="${LOCALPATH}/lp.cat 0"
else
        LPCAT="cat"
fi

#If we are not using a filter, use the default one.
if [ -z "${FILTER}" ]
then
        FILTER="${LPCAT}"
fi

if [ -x "${LOCALPATH}/drain.output" ]
then
        DRAIN="${LOCALPATH}/drain.output 1"
else
        DRAIN=
fi

salta="no"
pitch="def"
for i in $options
do
        case $i in
                nobanner)
                        banner="no"
                        ;;
                f)
                        salta="no"
                        ;;
                nlq12)
                        pitch="12"
                        ;;
                *)
                        ;;
        esac
done

# the fifth field of the /etc/passwd file is assigned to the variable user
user=`sed -n "s/^$name:.*:.*:.*:\(.*\):.*:.*$/\1/p" /etc/passwd`

# nhead gets the value of BANNERS or 1 by default
#nhead=`sed -n 's/^BANNERS=//p' /etc/default/lpd`
#[ "$nhead" -ge 0 -a "$nhead" -le 5 ] || nhead=1

# print the banner $nhead times
{
if [ "$banner" = yes ]
then
        while   [ "$nhead" -gt 0 ]
        do
                echo -e "$x\n"
                banner "$name"
                echo -e "$x\n"
                [ "$user" ] && echo -e "User: $user\n"
                echo -e "Request id: $request\n"
                echo -e "Printer: $printer\n"
                date
                echo -e
                [ "$title" ] && banner $title
                echo -e "\f\c"
                nhead=`expr $nhead - 1`
        done
fi

# send the file(s) to the standard out $copies times
while   [ "$copies" -gt 0 ]
do
        for file in $files
        do
                0<${file} eval ${FILTER} 2>&1
                if [ $salta = "yes" ]
                then
                   echo -en "\f"
                fi
        done
        copies=`expr $copies - 1`
done
}
#Draining characters might be necessary
${DRAIN}

exit 0