home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / errpage.ps < prev    next >
Text File  |  2002-02-22  |  9KB  |  363 lines

  1. %!
  2. %    Copyright (C) 1992, 1996, 1998 Aladdin Enterprises.  All rights reserved.
  3. % This software is provided AS-IS with no warranty, either express or
  4. % implied.
  5. % This software is distributed under license and may not be copied,
  6. % modified or distributed except as expressly authorized under the terms
  7. % of the license contained in the file LICENSE in this distribution.
  8. % For more information about licensing, please refer to
  9. % http://www.ghostscript.com/licensing/. For information on
  10. % commercial licensing, go to http://www.artifex.com/licensing/ or
  11. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  12. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  13.  
  14. % $Id: errpage.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
  15. % Print an informative error page if an error occurs.
  16. % Inspired by Adobe's `ehandler.ps' and David Holzgang's PinPoint.
  17.  
  18. /EPdict 80 dict def
  19. EPdict begin
  20.  
  21. /escale 12 def
  22. /efont /Helvetica findfont escale scalefont def
  23. /eheight escale 1.2 mul def
  24.  
  25. % Miscellaneous utilities
  26. /xdef
  27.  { exch def
  28.  } bind def
  29.  
  30. % Define `show' equivalents of = and ==
  31.  
  32. /show=
  33.  { =string { cvs } stopped { pop pop (==unprintable==) } if show
  34.  } bind def
  35.  
  36. /.dict 18 dict def
  37. .dict begin
  38.   /.buf =string def
  39.   /.cvp {.buf cvs show} bind def
  40.   /.nop {(-) .p type .cvp (-) .p} bind def
  41.   /.p {show} bind def
  42.   /.p1 {( ) dup 0 4 -1 roll put show} bind def
  43.   /.print
  44.     {dup type .dict exch known
  45.      {dup type exec} {.nop} ifelse
  46.     } bind def
  47.   /integertype /.cvp load def
  48.   /nulltype { pop (null) .p } bind def
  49.   /realtype /.cvp load def
  50.   /booleantype /.cvp load def
  51.   /nametype
  52.     {dup xcheck not {(/) .p} if
  53.      dup length .buf length gt
  54.       {dup length string}
  55.       {.buf}
  56.      ifelse cvs .p} bind def
  57.   /arraytype
  58.     {dup rcheck
  59.       {dup xcheck {(})({)} {(])([)} ifelse .p
  60.        exch () exch
  61.        {exch .p .print ( )} forall pop .p}
  62.       {.nop}
  63.      ifelse} bind def
  64.   /operatortype
  65.       {(--) .p .cvp (--) .p} bind def
  66.   /packedarraytype /arraytype load def
  67.   /stringtype
  68.     {dup rcheck
  69.       {(\() .p
  70.        {/.ch exch def
  71.         .ch 32 lt .ch 127 ge or
  72.         {(\\) .p .ch 8#1000 add 8 .buf cvrs 1 3 getinterval .p}
  73.         {.ch 40 eq .ch 41 eq or .ch 92 eq or
  74.          {(\\) .p} if
  75.          .ch .p1}
  76.         ifelse}
  77.        forall (\)) .p}
  78.       {.nop}
  79.      ifelse} bind def
  80. end
  81. /show==
  82.  { .dict begin .print end
  83.  } bind def
  84.  
  85. % Printing utilities
  86.  
  87. /eol
  88.  { /ey ey eheight sub def
  89.    ex ey moveto
  90.  } bind def
  91. /setx
  92.  { /ex xdef ex ey moveto
  93.  } bind def
  94. /setxy
  95.  { /ey xdef /ex xdef
  96.    ex ey moveto
  97.  } bind def
  98. /indent
  99.  { /lx ex def
  100.    (    ) show currentpoint setxy
  101.  } bind def
  102. /unindent
  103.  { lx setx
  104.  } bind def
  105.  
  106. % Get the name of the n'th dictionary on the (saved) dictionary stack.
  107. /nthdictname    % n -> name true | false
  108.  { dup dstack exch get
  109.    exch -1 0
  110.     { dstack exch get
  111.        { 2 index eq { exch pop exit } { pop } ifelse
  112.        }
  113.       forall
  114.       dup type /nametype eq { exit } if
  115.     }
  116.    for
  117.    dup type /nametype eq { true } { pop false } ifelse
  118.  } bind def
  119.  
  120. % Find the name of a currently executing procedure.
  121. /findprocname    % <proctail> findprocname <dstackindex> <procname> true
  122.         % <proctail> findprocname false
  123.  { dup length /proclength xdef
  124.    dup type cvlit /proctype xdef
  125.    dstack length 1 sub -1 0
  126.     { dup dstack exch get
  127.        { dup type proctype eq
  128.           { dup rcheck { dup length } { -1 } ifelse proclength gt
  129.          { dup length proclength sub proclength getinterval 3 index eq
  130.             { 3 -1 roll pop exit }
  131.         { pop }
  132.            ifelse
  133.          }
  134.          { pop pop
  135.          }
  136.         ifelse
  137.       }
  138.       { pop pop
  139.       }
  140.      ifelse
  141.        }
  142.       forall
  143.       dup type /nametype eq { exit } if
  144.       pop
  145.     }
  146.    for
  147.    dup type /nametype eq { true } { pop false } ifelse
  148.  } bind def
  149.  
  150. % Error printing routine.
  151. % The top 2 elements of the o-stack are systemdict and EPdict.
  152. % For the moment, we ignore the possibility of stack overflow or VMerror.
  153. /showerror    % <command> <countexecstack> <errorname> showerror -
  154.  {
  155.     % Restore the error handlers.
  156.  
  157.    saveerrordict { errordict 3 1 roll put } forall
  158.    $error /recordstacks false put
  159.  
  160.     % Save information from the stacks.
  161.  
  162.    /saveerror xdef
  163.    countexecstack array execstack
  164.    0 3 -1 roll 1 sub getinterval
  165.    /estack xdef
  166.    /savecommand xdef
  167.  
  168.    countdictstack array dictstack
  169.    dup length 2 sub 0 exch getinterval
  170.    /dstack xdef
  171.  
  172.     % Save state variables that will be reset.
  173.     % (We could save and print a lot more of the graphics state.)
  174.  
  175.    /savefont currentfont def
  176.    mark { savefont /FontName get =string cvs cvn } stopped
  177.     { cleartomark null }
  178.     { exch pop dup length 0 eq { pop null } if }
  179.    ifelse /savefontname xdef
  180.    efont setfont
  181.  
  182.     { currentpoint } stopped { null null } if
  183.    /savey xdef /savex xdef
  184.    0 0
  185.     { pop pop }
  186.     { pop pop 1 add }
  187.     { pop pop pop pop pop pop exch 1 add exch }
  188.     { }
  189.    pathforall
  190.    /savelines xdef /savecurves xdef
  191.    /savepathbbox { [ pathbbox ] } stopped { pop null } if def
  192.  
  193.    initmatrix
  194.  
  195.    clippath pathbbox
  196.      /savecliptop xdef /saveclipright xdef
  197.      /saveclipbottom xdef /saveclipleft xdef
  198.    initclip
  199.  
  200.    initgraphics
  201.  
  202.     % Eject the current page.
  203.  
  204.    showpage
  205.  
  206.     % Print the page heading.
  207.  
  208.    18 clippath pathbbox newpath
  209.    4 1 roll pop pop pop eheight sub 12 sub setxy
  210.    product (Product: )
  211.    statusdict /printername known
  212.     { 100 string statusdict begin printername end
  213.       dup length 0 gt
  214.        { exch pop exch pop (Printer name: ) }
  215.        { pop }
  216.       ifelse
  217.     }
  218.    if show show eol
  219.    (Interpreter version ) show version show eol
  220.    (Error: ) show saveerror show= eol
  221.    (Command being executed: ) show /savecommand load show= eol
  222.    currentfile { fileposition } stopped
  223.     { pop }
  224.     { (Position in input file: ) show show= eol }
  225.    ifelse eol
  226.  
  227.     % Print the current graphics state.
  228.  
  229.    (Page parameters:) show eol indent
  230.    (page size: ) show
  231.      gsave clippath pathbbox grestore
  232.      exch 3 index sub show= (pt x ) show
  233.      exch sub show= (pt) show pop eol
  234.    (current position: ) show
  235.    savex null eq
  236.     { (none) show }
  237.     { (x = ) show savex show= (, y = ) show savey show= }
  238.    ifelse eol
  239.    savelines savecurves add 0 eq
  240.     { (current path is empty) show
  241.     }
  242.     { (current path: ) show savelines show= ( line(s), ) show
  243.       savecurves show= ( curve(s)) show eol
  244.       (path bounding box: ) show savepathbbox show==
  245.     }
  246.    ifelse eol
  247.    (current font: ) show
  248.      savefontname dup null eq
  249.       { pop (--no name--) show }
  250.       { show= ( ) show
  251.         gsave
  252.         savefontname findfont /FontMatrix get matrix invertmatrix
  253.     grestore
  254.         savefont /FontMatrix get matrix concatmatrix
  255.     dup 1 get 0 eq 1 index 2 get 0 eq and
  256.     1 index 4 get 0 eq and 1 index 5 get 0 eq and
  257.     1 index 0 get 2 index 3 get eq and
  258.      { 0 get show= (pt) show }
  259.      { (scaled by ) show show= }
  260.     ifelse
  261.       }
  262.      ifelse eol
  263.    eol unindent
  264.  
  265.     % Print the operand stack.
  266.  
  267.    /stky ey def
  268.    (Operand stack:) show eol indent
  269.    count { show== eol } repeat
  270.    eol unindent
  271.  
  272.     % Print the dictionary stack.
  273.  
  274.    (Dictionary stack:) show eol indent
  275.    dstack length 1 sub -1 0
  276.     { nthdictname { show= } { (<unknown>) show } ifelse eol
  277.     } for
  278.    eol unindent
  279.  
  280.     % Print the execution stack.
  281.  
  282.    280 stky setxy
  283.    (Execution stack:) show eol indent
  284.    estack length 1 sub -1 1
  285.     { estack exch get
  286.       dup type /operatortype eq
  287.        { show= eol
  288.        }
  289.        { dup type dup /arraytype eq exch /packedarraytype eq or
  290.           { dup xcheck
  291.          { dup rcheck
  292.             { findprocname
  293.            { show= nthdictname { ( in ) show show= } if eol
  294.            }
  295.           if
  296.         }
  297.         { pop
  298.         }
  299.            ifelse
  300.          }
  301.          { pop
  302.          }
  303.         ifelse
  304.       }
  305.       { pop
  306.       }
  307.      ifelse
  308.        }
  309.       ifelse
  310.     } for eol unindent
  311.  
  312.     % Print the next few lines of input.
  313.     % Unfortunately, this crashes on an Adobe printer.
  314.  
  315. (
  316.    (Next few lines of input:) show eol indent
  317.    /input currentfile def
  318.    mark { 4
  319.     { input ( ) readstring not { pop exit } if
  320.       dup 0 get dup 10 eq
  321.        { pop pop eol 1 sub dup 0 eq { pop exit } if }
  322.        { dup 13 eq { pop pop } { pop show } ifelse }
  323.       ifelse
  324.     }
  325.    loop } stopped cleartomark eol unindent
  326. ) pop
  327.  
  328.     % Wrap up.
  329.  
  330.    showpage
  331.    quit
  332.  
  333.  } def
  334.  
  335. % Define the common procedure for handling errors.
  336. /doerror
  337.  { systemdict begin EPdict begin showerror
  338.  } bind def
  339.  
  340. end
  341.  
  342. % Install our own error handlers.
  343.  
  344. /EPinstall
  345.  { EPdict begin
  346.    /saveerrordict errordict length dict def
  347.    errordict saveerrordict copy pop
  348.    errordict
  349.     { pop [ /countexecstack load 2 index cvlit /doerror load /exec load ] cvx
  350.       errordict 3 1 roll put
  351.     } forall
  352.    errordict /handleerror
  353.      [ /countexecstack load /handleerror /doerror load /exec load
  354.      ] cvx
  355.    put
  356.    end
  357.  } bind def
  358.  
  359. EPinstall
  360.