home *** CD-ROM | disk | FTP | other *** search
/ ftp.mayn.de / ftp.mayn.de-pub.zip / ftp.mayn.de-pub / apple / apple_unix / Sys_stuff / at_interface < prev    next >
Text File  |  2017-03-06  |  9KB  |  369 lines

  1. # System V line printer spooler model for PostScript/TranScript printer
  2. # Copyright (c) 1985 Adobe Systems Incorporated
  3. # PostScript and TranScript are trademarks of Adobe Systems Incorporated
  4. # Modified from RCSID: $Header: psinterface,v 2.1 85/11/24 12:20:16 shore Rel $
  5. #
  6. # "@(#)at_interface: 2.0, 2.1; 9/25/89; Copyright 1988-89, Apple Computer, Inc."
  7.  
  8. # This interface program accepts the following option args passed in via 
  9. # lp -o[option] -o["option string"]
  10. #
  11. #    -h - No Banner Page
  12. #    -r - Don't reverse the pages
  13. #    -o - object, passed to at_printer for AppleTalk NBP lookup, any object is "="
  14. #    -l - Output is giong to a laserwriter, run through Postscript utilities
  15. #    -t - Type, used to specify the type of printer, "LaserWriter" is the 
  16. #         only special type recognized at this point.  If user specifies
  17. #         "LaserWriter" the output is piped through the PS utils.  This option is
  18. #         also pased to the at_printer prog for use in the AppleTalk NBP lookup.
  19. #    -z - Zone to look in for printer, passed to at_printer
  20. #          Remember that the appletalk "this zone" id is the char '*',
  21. #         any printer, any type is the char '='.
  22.  
  23. # Set DEBUG non-zero for debug information
  24.  
  25. DEBUG=0
  26.  
  27. set -f
  28.  
  29. # This interface program is ment to adapt the System V LP Spooler to the
  30. # Appletalk network / LaserWriter world. It's not a perfect match.
  31. # You may wish to modify this file to your own special needs.
  32.  
  33. # Location of the directory containing the Adobe Systems PostScript (ps) tools
  34.  
  35. PSLIBDIR=/usr/lib/ps
  36. PSLOGDIR=transcript
  37. PSTEMPDIR=/tmp
  38.  
  39. # Location of the binary the does the actual transfer over appletalk 
  40.  
  41. atprinter=/usr/bin/at_printer
  42.  
  43. # Some useful vars
  44.  
  45. pstmp=$PSTEMPDIR/pstmp$$
  46. psrtmp=$PSTEMPDIR/psrtmp$$
  47. psfinal=$PSTEMPDIR/psfinal$$
  48. prog=$0
  49. pr=`basename $prog`
  50. cwd=`pwd`
  51. ptime=`date`
  52.  
  53. # This logging is not part of the "normal" lp spooler software but
  54. # is supplied by Adobe.
  55.  
  56. log=$cwd/${PSLOGDIR}/${pr}-log
  57. if [ ! -w "$log" ] ; then
  58.     if [ $DEBUG != 0 ] ; then
  59.         echo "Creating adobe log file $log."
  60.     fi
  61.     cp /dev/null $log
  62.     if [ $? != 0 ] ; then
  63.         disable -r"can't access log file $log" $pr 1>/dev/console 2>&1
  64.         exit 1
  65.     fi
  66.     chmod 644 $log
  67. fi
  68.  
  69. # These are the Adobe PostScript tools necessary to convert standard ascii to
  70. # PostScript format. Set psrv to null if you don't want page (order) reversal.
  71.  
  72. banner=$PSLIBDIR/psbanner
  73. psrv=$PSLIBDIR/psrv
  74. format=$PSLIBDIR/pstext
  75. BANNERPRO=$PSLIBDIR/banner.pro
  76. # Pick one or the other
  77. BANNERFIRST=1
  78. BANNERLAST=0
  79. REVERSE=0
  80. export BANNERPRO BANNERFIRST BANNERLAST PSTEMPDIR REVERSE PSLIBDIR
  81.  
  82. # printer-specific options file (can change any of the above)
  83.  
  84. test -r ./${PSLOGDIR}/${pr}.opt && . ./${PSLOGDIR}/${pr}.opt
  85.  
  86. if [ "$REVERSE" != "1" ] ; then
  87.     psrv=
  88. fi
  89.  
  90. # lpsched invokes us the following command line:
  91.  
  92. #    argv[0] is the interface program: interface/PRINTERNAME
  93. #    argv[1] is the request id:      PRINTERNAME-#id
  94. #    argv[2] is the requesters id:      USERNAME
  95. #    argv[3] is the number of copys:      #COPYS
  96. #    argv[4] is the list of options:      -OPTIONS 
  97. #    argv[5] is the list of files:      /usr/spool/lp/request/PRINTERNAME/d0-#id
  98.  
  99. # Now parse it.
  100.  
  101. if [ $DEBUG != 0 ] ; then
  102.     echo "$*"
  103. fi
  104.  
  105. seqid=$1
  106. name=$2
  107. title="$3"
  108. copies=$4
  109. options="$5"
  110. shift; shift; shift; shift; shift
  111. files="$*"
  112.  
  113. if [ $DEBUG != 0 ] ; then
  114.     echo "seqid = $seqid, title = $title, copies = $copies"
  115.     echo "options = $options, files = $files"
  116. fi
  117.  
  118. if [ -z "$title" ] ; then
  119.     title=`basename $1`
  120. fi
  121.  
  122. # parse remaining user options
  123. #
  124. # NOTE: There are two kind of options:
  125. # 1. Style options for the PS utilities
  126. # 2. Appletalk routing information used by at_printer.
  127. #    In addition the LaserWriter flag "-l" signals use of the Adobe PS tools.
  128.  
  129. # set $1 = output of getopt[1]
  130.  
  131. set -- `getopt hmro:lt:z:f: $options` ;
  132. if [ $? != 0 ] ; then
  133.     echo "$pr: $seqid bad user options $options [hmr]" >> $log
  134.     exit 2
  135. fi
  136.  
  137. # Adobe PostScript filters, which do we use and how?
  138.  
  139. Hflag="" Mflag="" Rflag="" ATopt="" DashL="" Tflag=""
  140.  
  141. while [ ! -z   `getopt hmro:lt:z:f: $options`  ]
  142. do
  143.     if [ $DEBUG != 0 ] ; then
  144.         echo $1
  145.     fi
  146.     case $1 in
  147.  
  148.     -h|h)    Hflag=$1; shift;;        # no banner page
  149.     -m|m)    Mflag=$1; shift;;        # mail stream output if any
  150.     -r|r)    Rflag=$1; shift;;        # Don't reverse page order
  151.                         # Handle postscript for laserwriter
  152.     -t)    Tflag=$1; Type=$2; shift; ATopt="$ATopt $Tflag";;
  153.     -l)    DoPS="True";DashL="True"; shift;;
  154.     --)    break;;                # Do not move this option
  155.      *)    ATopt="$ATopt $1"; shift;;    # These must be for at_printer
  156.     esac
  157. done
  158.  
  159. if [ $DEBUG != 0 ] ; then
  160.     echo ""
  161.     echo "PS flags - $Hflag  $Mflag  $Rflag"
  162.     echo "AT flags - $ATopt"
  163. fi
  164.  
  165. # If user has not indicated -l option, but has choosen a printer
  166. # which is a laserwriter, or have specified -t LaserWriter on the
  167. # command line, set DoPs to true, and -l option.
  168.  
  169. if [ -z "$DoPS" ]; then
  170.     if [ ! -z "$Tflag" ] ; then
  171.         if [ "$Type" = "LaserWriter" ] ; then
  172.             DoPS="true"
  173.             if [ -z "$DashL" ] ; then
  174.                 ATopt="$ATopt -l"
  175.             fi
  176.         fi
  177.              
  178.     else 
  179.         Pchoice=`atstatus | grep LaserWriter`
  180.         if [ ! -z "$Pchoice" ] ; then
  181.             DoPS="true"  
  182.             ATopt="$ATopt -l"
  183.         fi
  184.     fi
  185. fi
  186.  
  187. # set up to send the job
  188.  
  189. if [ ! -x $atprinter ] ; then
  190.     disable -r "can't find $atprinter program" $pr
  191.     exit 1
  192. fi
  193.  
  194. # If this request is for a LaserWriter, run Adobe PostScript tools
  195.  
  196. if [ ! -z "$DoPS" ] ; then
  197.  
  198. # Adobe log of transaction start.
  199.  
  200.     echo "$pr: $seqid $name "$title" start - $ptime" >> $log
  201.  
  202. # Generate banner page, but don't add it in till later.
  203.  
  204.     if [ -z "$Hflag" -a \( "$BANNERFIRST" = "1" -o "$BANNERLAST" = "1" \) ] ; then
  205.         if [ ! -x $banner ] ; then
  206.             disable -r "can't exec $banner program" $pr
  207.             exit 1
  208.         fi
  209.         bannerf=$PSTEMPDIR/b$seqid.$$
  210.         if [ ! -r $BANNERPRO ] ; then
  211.             disable -r "can't access banner prolog" $pr
  212.             exit 1
  213.         fi
  214.         $banner $pr $seqid $name "$title" "$ptime" > $bannerf
  215.     fi
  216.  
  217. # Do we print banner page first? (or last?)
  218.  
  219.     if [ -z "$Hflag" -a "$BANNERFIRST" = "1" ] ; then
  220.         if [ $DEBUG != 0 ] ; then
  221.             echo "Printing banner first"
  222.         fi
  223.         cat $bannerf > $psfinal
  224.     fi
  225.  
  226.  
  227. # Set up to mail job output if user flag set
  228. #
  229. # ***** MAKE THIS FUNCTION CORRECTLY *****
  230. #
  231. # if [ -n "$Mflag" ] ; then
  232. #     JOBOUTPUT=${PSTEMPDIR}/o$seqid.$$
  233. #     export JOBOUTPUT
  234. # fi
  235.  
  236.  
  237. # Now process the print files.
  238. #
  239. # IMPORTANT: Remember that the request must be batched with
  240. # only one call to function at_printer.
  241.  
  242.     for f in $files
  243.     do
  244.         echo "$pr: $seqid `basename $f` - `date`"        >> $log
  245.         cop=$copies
  246.         if [ $DEBUG != 0 ] ; then
  247.             echo "Printing $copies copy(s) of file $f"
  248.         fi
  249.  
  250. # check for magic number and format if plain text
  251.  
  252.         magic=`line <$f | cut -c1-11`
  253.         rev= 
  254.         case "$magic" in
  255.             %!PS-Adobe-*)
  256.                 cat $f > $pstmp ; rev=1 ;;
  257.             *)
  258.                 $format <$f > $pstmp ; rev=1;;
  259.         esac
  260.  
  261. # if multiple copies, reverse only once
  262.  
  263.         if [ -n "$rev" -a -n "$psrv" -a -z "$Rflag" ] ; then
  264.             if [ $DEBUG != 0 ] ; then
  265.                 echo "Reverse done"
  266.             fi
  267.             $psrv <$pstmp >$psrtmp
  268.         fi
  269.  
  270. # print all the copies, reversing as necessary
  271.  
  272.         while [ $cop -ge 1 ] 
  273.         do    
  274.             if [ -n "$rev" -a -n "$psrv" -a -z "$Rflag" ] ; then
  275.                 if [ $DEBUG != 0 ] ; then
  276.                     echo "Adding reverse"
  277.                 fi
  278.                 cat $psrtmp >> $psfinal
  279.             else
  280.                 if [ $DEBUG != 0 ] ; then
  281.                     echo "Adding copy"
  282.                 fi
  283.                 cat $pstmp >> $psfinal
  284.             fi 
  285.             cop=`expr $cop - 1`
  286.         done
  287.     done
  288.  
  289. # Do we print the banner page last? (or first?)
  290.  
  291.     if [ -z "$Hflag" -a "$BANNERLAST" = "1" ] ; then
  292.         if [ $DEBUG != 0 ] ; then
  293.             echo "Printing banner last"
  294.         fi
  295.         cat $bannerf >> $psfinal
  296.     fi
  297. else
  298.  
  299. # This is not a Postscript printer,
  300. # we must supply our own banner function.
  301.  
  302. x="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
  303.  
  304.     if [ -z "$Hflag" ] ; then        # print a banner?
  305. #        echo "\014\c"
  306.         echo "$x\n$x\n$x\n$x\n" > $psfinal
  307.         banner "$name" >> $psfinal
  308.         echo "\n" >> $psfinal
  309.         user=`grep "^$name:" /etc/passwd | line | cut -d: -f5` >> $psfinal
  310.         if [ -n "$user" ] ; then >> $psfinal
  311.             echo "User: $user\n" >> $psfinal
  312.         else
  313.             echo "\n" >> $psfinal
  314.         fi
  315.         echo "Request id: $seqid    Printer: $pr\n" >> $psfinal
  316.         date >> $psfinal
  317.         echo "\n" >> $psfinal
  318.         if [ -n "$title" ] ; then
  319.             banner "$title" >> $psfinal
  320.         fi
  321.         echo "\014\c" >> $psfinal
  322.     fi
  323.  
  324.     for f in $files
  325.     do
  326.         cop=$copies
  327.         if [ $DEBUG != 0 ] ; then
  328.             echo "Printing $copies copy(s) of file $f"
  329.         fi
  330.         cat $f > $psfinal
  331.     done
  332. fi    
  333.  
  334. # if [ ! -z "$DoPS" ] ; then
  335. # mail user the job ouput if flag set
  336. #
  337. # ****** THIS NEEDS WORK AS WELL ******
  338. #
  339. #    if [ -n "$Mflag" ] ; then
  340. #        if [ -s "$JOBOUTPUT" ] ; then
  341. #            (echo Subject: output from PostScript print job $seqid follows
  342. #            cat $JOBOUTPUT ) | mail $name
  343. #        fi
  344. #        rm -f $JOBOUTPUT
  345. #    fi
  346. # fi
  347.  
  348. # Because appletalk cannot grant exclusive access to a printer,
  349. # send the entire job in one call.
  350.  
  351. if [ $DEBUG != 0 ] ; then
  352.     echo "$atprinter $ATopt < $psfinal"
  353.     cat < $psfinal
  354. else
  355.     $atprinter $ATopt < $psfinal
  356. fi
  357.  
  358. if [ ! -z "$DoPS" ] ; then
  359. # Adobe log of job finish
  360.  
  361.     echo "$pr: $seqid end - `date`"        >> $log
  362. fi
  363.  
  364. # clean up tmp files
  365.  
  366. if [ $DEBUG = 0 ] ; then
  367.     rm -f $bannerf $pstmp $psrtmp $psfinal
  368. fi
  369.