home *** CD-ROM | disk | FTP | other *** search
/ Carousel / CAROUSEL.cdr / mactosh / unix / paintps.sha / psfilter.csh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1986-07-08  |  6.6 KB  |  218 lines

  1. #! /bin/csh -f
  2. #
  3. # psfilter - filter for the Apple LaserWriter (Postscript) printer
  4. #
  5. #  DON'T edit this file directly, edit the source in 
  6. #  /usr/src/local/prop/transcript/src/psfilter.sh, run make psfilter
  7. #  and install the result.  I had to retrofit changes once, please consider
  8. #  the poor slob who has to change it next time.  (R.H. 5/85)
  9. #
  10. # Each of these files is merely a link to the current file, and we look at
  11. # argument 0 to see which one we are being called by.  Alternatively, you
  12. # may wish to modify printjob.c (/usr/src/usr.lib/lpr/printjob.c) to pass
  13. # the name of the filter you wish to use as the argument following the -f
  14. # switch.
  15. #
  16.  
  17.  
  18. set name host filter x y indent width length acct pid printer title
  19. setenv TERMCAP /etc/printcap
  20. umask 0
  21.  
  22. if ($?0) set filter = $0
  23.  
  24. top:
  25.     if($#argv > 0) then
  26.         switch ($argv[1])
  27.         case -f:    # filter desired
  28.             shift argv
  29.             if ($#argv > 0) then
  30.                 set filter = $argv[1]
  31.                 shift argv
  32.             endif
  33.             goto top
  34.  
  35.         case -h:    # host spooling file
  36.             shift argv
  37.             if ($#argv > 0) then
  38.                 set host = $argv[1]
  39.                 shift argv
  40.             endif
  41.             goto top
  42.  
  43.         case -i*:    # indentation, ignored for now
  44.             set i=$argv[1]
  45.             shift argv
  46.             goto top
  47.  
  48.         case -l*:    # page length, ignored for now
  49.             set l=$argv[1]
  50.             shift argv
  51.             goto top
  52.  
  53.         case -n:    # uid of spooling user
  54.             shift argv
  55.             if ($#argv > 0) then
  56.                 set name = $argv[1]
  57.                 shift argv
  58.             endif
  59.             goto top
  60.  
  61.         case -p:    # printer to be used
  62.             shift argv
  63.             if ($#argv > 0) then
  64.                 set printer = (-i $argv[1])
  65.                 set pset
  66.                 shift argv
  67.             endif
  68.             goto top
  69.  
  70.         case -w*:    # page width, ignored for now
  71.             set width=$argv[1]
  72.             shift argv
  73.             goto top
  74.  
  75.         case -x*:    # starting x position, ignored for now
  76.             set x=$argv[1]
  77.             shift argv
  78.             goto top
  79.  
  80.         case -y*:    # starting y position, ignored for now
  81.             set y=$argv[1]
  82.             shift argv
  83.             goto top
  84.  
  85.         default:    # currently assumed to be the accounting file
  86.                 # This name is defined as af in printcap
  87.                 # tail of name must match printer name
  88.             set acct=$argv[1]
  89.             set pid=(-P$argv[1]:t)
  90.             set logfile=/usr/adm/log-$argv[1]:t
  91.             shift argv
  92.             goto top
  93.         endsw
  94.     endif
  95.  
  96.  
  97. set lockfile=lock                # doubtful anything else
  98. set cffile=`cat $lockfile | grep cf | head -1`    # grok the name of the cf
  99. set title=`grep N $cffile | head -1 | sed s/N//`    # get job title
  100. set mtmp="/tmp/spoolmail$$"            # name of temp mail file
  101. set policy=.policy                # text file to be mailed
  102. if ( ! -f $policy ) set policy=/dev/null    # subject will have to do
  103. set taunt="Permission to use laser printer denied"
  104.  
  105. # Contrary to it's name, psif is the filter which talks to the printer. It's
  106. # intended to be specified as the if filter in the printcap.  This works
  107. # fine if everything is processed to PostScript before being spooled, but in
  108. # this setup it is used as the tail of the filter chain.  Psof should be
  109. # specified as the of entry in the printcap and the sh (short header) boolean
  110. # should be set.  It formats a banner maker and psif sends it after EOF on
  111. # the file it is processing.
  112.  
  113. # Modified June 86 to support LW's on Bridges also.  The printer name in
  114. # the form -Pname (as determined above) is passed to psif.  Psif does a
  115. # gethostbyname call, if the printer name is defined (in /etc/hosts or to
  116. # the nameserver as applicable) then a network socket is opened to that
  117. # address.  The address for the name is actually assigned to a Bridge serial
  118. # port to which the LW is connected.  Psif then treats the socket as its
  119. # stdout and does its normal processing, the output stream will flow across
  120. # the net to the remote LW.  If the gethostbyname call fails then nothing
  121. # special is done and psif behaves as before, assuming its stdout is
  122. # connected to the physical printer device (as setup by lpd).
  123. #  Ron Hitchens
  124.  
  125. onintr intrupt                    # vector int's to error section
  126.  
  127. # Get the filetype portion of the filter name
  128. switch ($filter:r)
  129.  
  130.     case /usr/local/lib/psasc:            # ascii document
  131.     case psasc:
  132.         set filtype="ascii"
  133.         if ( "$title" == "" ) set title="ascii document"
  134. # -------------------------------------
  135. # Permission checking/accounting hacks should be hooked in here
  136. # similar entries for each case below
  137. #        /usr/local/lib/laser_ok $host $name # returns 0 if valid user
  138. #        if ( $status ) then
  139. #            Mail -s "$taunt" $name@$host < $policy
  140. #            exit 2        # spool file is discarded
  141. #        endif
  142. # -------------------------------------
  143.  
  144.         /usr/local/lib/psif -h $host -n $name $pid $acct
  145.         if ( $status ) breaksw            # go handle error
  146.         exit 0                    # all is well
  147.  
  148.     case /usr/local/lib/psdvi:            # TeX document
  149.     case psdvi:
  150.         set filtype="TeX"
  151.         if ( "$title" == "" ) set title="TeX document"
  152.         /usr/local/lib/dvi2ps -i -q  \
  153.             -h /usr/local/lib/allfonts/postscript/tex.ps \
  154.             | /usr/local/lib/psif -h $host -n $name $pid $acct
  155.         if ( $status ) breaksw        # drop down and handle error
  156.         exit 0                # success
  157.  
  158.     case /usr/local/lib/psditroff:            # ditroff document
  159.     case psditroff:
  160.         set filtype="Ditroff"
  161.         if ( "$title" == "" ) set title="Ditroff document"
  162.         /usr/local/lib/psdit | /usr/local/lib/psrev | \
  163.             /usr/local/lib/psif -h $host -n $name $pid $acct
  164.         if ( $status ) breaksw            # go handle error
  165.         exit 0
  166.  
  167.     case /usr/local/lib/psmac:        # PS file made by a mac
  168.     case psmac:                # uses rf (fortran) type
  169.         set filtype="Macintosh"
  170.         if ( "$title" == "" ) set title="Mac laser document"
  171.         cat /usr/local/lib/allfonts/postscript/laser-prep.pro - | \
  172.             /usr/local/lib/macfilter | \
  173.             /usr/local/lib/psif -h $host -n $name $pid $acct
  174.         if ( $status ) breaksw        # go handle error
  175.         exit 0
  176.  
  177.     case /usr/local/lib/pscat:            # old troff, no no
  178.     case pscat:
  179.         set filtype="old style troff"
  180.         if ( "$title" == "" ) set title="old troff document"
  181.         echo "Old style troff is not supported on the LaserWriter" \
  182.             > $mtmp
  183.         echo "Please use ditroff instead." >> $mtmp
  184.         set nolog
  185.         breaksw
  186.         exit 0        # superstition
  187.  
  188.     default:
  189.         set filtype="LaserWriter"
  190.         if ( "$title" == "" ) set title="document"
  191.         echo "No support for that file type on the LaserWriter" > $mtmp
  192.         set nolog
  193.         breaksw
  194.         exit 0        # superstition
  195.  
  196. endsw
  197.  
  198. intrupt:            # a place to catch interrupts, hopefully these
  199.                 # shell vars have been set, will be if lpd 
  200.                 # kills a running filter, like psif
  201.  
  202. if ( ! $?nolog ) then
  203.   echo "Error returned by $filtype filter.  Here are the last few lines from" \
  204.     > $mtmp
  205.   echo "the error log, yours should be last:" >> $mtmp
  206.   echo "" >> $mtmp
  207.   tail -8 $logfile >> $mtmp
  208. endif
  209.  
  210. Mail -s "Error spooling $title to $pid" $name@$host < $mtmp
  211. rm $mtmp
  212.  
  213. echo "There was a problem with your $filtype job spooled for $pid" > $mtmp
  214. echo "A mail message was sent to you at $host with further details" >> $mtmp
  215. ( /usr/local/telegram $name@$host < $mtmp > /dev/null ; rm $mtmp ) &
  216.  
  217. exit 2                # throw the file away
  218.