home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / ps / behand.ler < prev    next >
Text File  |  1991-05-20  |  8KB  |  216 lines

  1. %!
  2. % behandler.ps, v1.3, Mar 23 1990, a modified version of Adobe's ehandler.ps
  3. % Original program copyright (c) 1986 Adobe Systems Incorporated
  4. % Modified by Fredric Ihren, for support contact fred@nada.kth.se or write to
  5. %   Fredric Ihren; Moerbydalen 17; S-182 32 D-RYD; Sweden
  6. % Adobe will not keep maintenance of this program.
  7. % Distributed with permission from Adobe Systems Incorporated
  8.  
  9. 0000 % serverloop password
  10. /$brkpage where not {
  11.   dup serverdict begin statusdict begin checkpassword
  12.     { (Error Handler downloaded.\n) print flush exitserver }
  13.     { pop (Bad Password on loading error handler.\n) print flush stop }
  14.   ifelse
  15. } {
  16.   pop pop (Error Handler in place - not loaded again\n) print flush stop
  17. } ifelse
  18. /$brkpage 64 dict def
  19. $brkpage begin
  20.   /== { /cp 0 def typeprint nl } def
  21.   /printpage {
  22.     /prnt {
  23.       dup type /stringtype ne { =string cvs } if dup length 6 mul /tx exch def
  24.       /ty 10 def currentpoint /toy exch def /tox exch def 1 setgray newpath
  25.       tox toy 2 sub moveto 0 ty rlineto tx 0 rlineto 0 ty neg rlineto
  26.       closepath fill tox toy moveto 0 setgray show
  27.     } bind def
  28.     /nl { currentpoint exch pop lmargin exch moveto 0 -10 rmoveto } def
  29.     /doshowpage systemdict /showpage get def
  30.   } def
  31.   /printonly {
  32.     /nl { (\n) print } def
  33.     /prnt { dup type /stringtype ne { =string cvs } if print } def
  34.     /doshowpage null cvx def
  35.   } def
  36.   printpage
  37.   /typeprint { dup type dup currentdict exch known
  38.     { exec } { unknowntype } ifelse
  39.   } def
  40.   /lmargin 72 def /rmargin 72 def
  41.   /tprint { dup length cp add rmargin gt { nl /cp 0 def } if
  42.     dup length cp add /cp exch def prnt
  43.   } def
  44.   /cvsprint { =string cvs tprint( ) tprint } def
  45.   /unknowntype { exch pop cvlit (??) tprint cvsprint } def
  46.   /integertype { cvsprint } def
  47.   /realtype { cvsprint } def
  48.   /booleantype { cvsprint } def
  49.   /operatortype { (//) tprint cvsprint } def
  50.   /marktype { pop (-mark- ) tprint } def
  51.   /dicttype { pop (-dictionary- ) tprint } def
  52.   /nulltype { pop (-null- ) tprint } def
  53.   /filetype { pop (-filestream- ) tprint } def
  54.   /savetype { pop (-savelevel- ) tprint } def
  55.   /fonttype { pop (-fontid- ) tprint } def
  56.   /nametype { dup xcheck not { (/) tprint } if cvsprint } def
  57.   /stringtype {
  58.     dup rcheck
  59.       { (\() tprint tprint (\)) tprint }
  60.       { pop (-string- ) tprint }
  61.     ifelse
  62.   } def
  63.   /arraytype {
  64.     dup rcheck { dup xcheck
  65.       { ({) tprint { typeprint } forall (}) tprint }
  66.       { ([) tprint { typeprint } forall (]) tprint }
  67.     ifelse } { pop (-array- ) tprint } ifelse
  68.   } def
  69.   /packedarraytype {
  70.     dup rcheck { dup xcheck
  71.       { ({) tprint { typeprint } forall (}) tprint }
  72.       { ([) tprint { typeprint } forall (]) tprint }
  73.     ifelse } { pop (-packedarray- ) tprint } ifelse
  74.   } def
  75.   /stackmax 10 def
  76.   /execmax 5 def
  77.   /filemax 5 def
  78.   /courier /Courier findfont 10 scalefont def
  79.   /OLDhandleerror errordict /handleerror get def
  80. end %$brkpage
  81. errordict /handleerror {
  82.   systemdict begin $error begin $brkpage begin newerror {
  83.     {
  84.       /newerror false store
  85.       vmstatus pop pop 0 ne { grestoreall } if initgraphics courier setfont
  86.       lmargin 750 moveto
  87.       statusdict /jobname get dup null ne
  88.         { (Jobname: ) prnt prnt nl } { pop } ifelse
  89.       (Error: ) prnt errorname prnt nl
  90.       (Command: ) prnt /command load ==
  91.       $error /ostack known {
  92.         $error /ostack get dup length 0 ne {
  93.           (Stack \() prnt
  94.           aload length dup prnt (\):) prnt nl
  95.           /i 0 def
  96.           { /i i 1 add def i stackmax le { == } { pop } ifelse }
  97.           repeat
  98.         } { pop } ifelse
  99.       } if
  100.       $error /estack known {
  101.         $error /estack get dup dup length 1 sub get type /filetype ne {
  102.           (Execstack \() prnt
  103.           aload length dup prnt (\):) prnt nl
  104.           /i 0 def
  105.           { /i i 1 add def dup type /filetype eq { /i 99 def } if
  106.             i execmax le { == } { pop } ifelse
  107.           } repeat
  108.         } { pop } ifelse
  109.       } if
  110.       (%stdin) (r) file
  111.       dup =string readline {
  112.         (File:) prnt nl prnt nl
  113.         filemax 1 sub { dup =string readline { prnt nl } { exit } ifelse }
  114.         repeat
  115.       } if pop
  116.       userdict /debug known {
  117.         (Debug:) prnt nl
  118.         userdict /debug get stopped pop nl
  119.       } if
  120.     } stopped pop
  121.     doshowpage
  122.     /newerror true store
  123.     /OLDhandleerror load end end end exec
  124.   } { end end end }
  125.   ifelse
  126. } dup 0 systemdict put dup 4 $brkpage put bind put
  127. -------------------------------- cut here ------------------------------------
  128. Notes about the use of it:
  129. (A) The following information will be printed on the break page:
  130.     1) jobname
  131.        (useful in a multiuser environment)
  132.        It will be printed if the program has set it like this:
  133.          statusdict /jobname (informative string) def
  134.     2) error, the name of the error that terminated your program.
  135.     3) command, the name of the last command
  136.     4) stack
  137.        The top (maximum 10) elements of the operand stack.
  138.        The limit 10 is set by the line
  139.        /stackmax 10 def
  140.        and can be changed by modifying that line.
  141.     5) execstack
  142.        The top (maximum 5) elements of the execstack.
  143.        (For those of you who don't know, that's the stack of objects that
  144.        are currently executing, the part of a procedure that's still to be
  145.        done, the current index of a for-loop, etc)
  146.        To make it minimally confusing, it will not present elements
  147.        beyond a fileobject, so the surrounding server procedures are ignored.
  148.        (The maximum 5 can be changed on the line /execmax 5 def)
  149.     6) file
  150.        The next (maximum 5) lines of the file will be printed if available
  151.        making it possible for you to localise the error.
  152.        This is read from a stdin-file and I guess that it might not work for
  153.        some io-arrangements.
  154.        Lines longer than 128 characters will be not be read.
  155.        (The maximum 5 can be changed on the line /filemax 5 def)
  156.     7) debug
  157.        If a procedure /debug is found in userdict, it will be executed.
  158.        It can use the break page procedure == to present its information.
  159.        It might for instance print the value of a variable /counter like this:
  160.        /debug {
  161.          counter ==
  162.        } def
  163.  
  164. (B) By default the break-page handler will be downloaded, that is it will
  165.     be read in to printer memory and stay there until poweroff.
  166.     Commenting or removing the lines before /$brkpage 64 dict def
  167.     will make it volatile: append your file to the end of it and the
  168.     error handler will only affect this job only.
  169.  
  170. (C) By default the break-page handler will print a page with the information
  171.     (like Abode's program).
  172.     If the procedure printonly is executed, it will print to stdout instead
  173.     of wasting a page.
  174.     This can be downloaded after the break-page-handler with:
  175. -------------------------------- cut here ------------------------------------
  176. %!
  177. % Break-page printonly
  178. 0000 % serverloop password
  179. serverdict begin exitserver $brkpage begin printonly
  180. -------------------------------- cut here ------------------------------------
  181.     or made default by changeing the line
  182.     "printpage" to "printonly" in behandler.ps
  183.     or selected for this job only by adding this line to your program:
  184.     $brkpage begin printonly end
  185.     (files needing $brkpage to run should of course not be distributed)
  186.  
  187. (D) The error handler can be shut-off(on) without power-off-ing the printer by
  188. -------------------------------- cut here ------------------------------------
  189. %!
  190. % Break-page shut-off(on)
  191. 0000 % serverloop password
  192. serverdict begin exitserver errordict begin $brkpage begin
  193. /handleerror dup load /OLDhandleerror dup load 4 -1 roll exch store exch store
  194. -------------------------------- cut here ------------------------------------
  195.     or shut-off for this job only by adding this line to your program:
  196.     errordict /handleerror $brkpage /OLDhandleerror get put
  197.     (files needing $brkpage to run should of course not be distributed)
  198.  
  199. (E) Adobe will not keep maintenance over this program and
  200.     trouble/questions/support-needs should contact me, rather than Adobe.
  201.  
  202. Enjoy!
  203.  
  204. Fredric Ihren                            Tel. +46 8 755 35 77
  205. fred@nada.kth.se             Moerbydalen 17, S-182 32 D-RYD, Sweden
  206.  
  207.  
  208.  
  209. -- 
  210. Tim Theisen             Department of Computer Sciences
  211. Systems Programmer      University of Wisconsin-Madison
  212. tim@cs.wisc.edu         1210 West Dayton Street
  213. (608)262-0438           Madison, WI   53706
  214.  
  215.  
  216.