2 % Copyright (C) 1992, 1996, 1998 Aladdin Enterprises. All rights reserved.
4 % This software is provided AS-IS with no warranty, either express or
7 % This software is distributed under license and may not be copied,
8 % modified or distributed except as expressly authorized under the terms
9 % of the license contained in the file LICENSE in this distribution.
11 % For more information about licensing, please refer to
12 % http://www.ghostscript.com/licensing/. For information on
13 % commercial licensing, go to http://www.artifex.com/licensing/ or
14 % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
15 % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
17 % $Id: errpage.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
18 % Print an informative error page if an error occurs.
19 % Inspired by Adobe's `ehandler.ps' and David Holzgang's PinPoint.
25 /efont /Helvetica findfont escale scalefont def
26 /eheight escale 1.2 mul def
28 % Miscellaneous utilities
33 % Define `show' equivalents of = and ==
36 { =string { cvs } stopped { pop pop (==unprintable==) } if show
42 /.cvp {.buf cvs show} bind def
43 /.nop {(-) .p type .cvp (-) .p} bind def
45 /.p1 {( ) dup 0 4 -1 roll put show} bind def
47 {dup type .dict exch known
48 {dup type exec} {.nop} ifelse
50 /integertype /.cvp load def
51 /nulltype { pop (null) .p } bind def
52 /realtype /.cvp load def
53 /booleantype /.cvp load def
55 {dup xcheck not {(/) .p} if
56 dup length .buf length gt
59 ifelse cvs .p} bind def
62 {dup xcheck {(})({)} {(])([)} ifelse .p
64 {exch .p .print ( )} forall pop .p}
68 {(--) .p .cvp (--) .p} bind def
69 /packedarraytype /arraytype load def
74 .ch 32 lt .ch 127 ge or
75 {(\\) .p .ch 8#1000 add 8 .buf cvrs 1 3 getinterval .p}
76 {.ch 40 eq .ch 41 eq or .ch 92 eq or
85 { .dict begin .print end
91 { /ey ey eheight sub def
95 { /ex xdef ex ey moveto
103 ( ) show currentpoint setxy
109 % Get the name of the n'th dictionary on the (saved) dictionary stack.
110 /nthdictname % n -> name true | false
111 { dup dstack exch get
114 { 2 index eq { exch pop exit } { pop } ifelse
117 dup type /nametype eq { exit } if
120 dup type /nametype eq { true } { pop false } ifelse
123 % Find the name of a currently executing procedure.
124 /findprocname % <proctail> findprocname <dstackindex> <procname> true
125 % <proctail> findprocname false
126 { dup length /proclength xdef
127 dup type cvlit /proctype xdef
128 dstack length 1 sub -1 0
129 { dup dstack exch get
130 { dup type proctype eq
131 { dup rcheck { dup length } { -1 } ifelse proclength gt
132 { dup length proclength sub proclength getinterval 3 index eq
133 { 3 -1 roll pop exit }
146 dup type /nametype eq { exit } if
150 dup type /nametype eq { true } { pop false } ifelse
153 % Error printing routine.
154 % The top 2 elements of the o-stack are systemdict and EPdict.
155 % For the moment, we ignore the possibility of stack overflow or VMerror.
156 /showerror % <command> <countexecstack> <errorname> showerror -
158 % Restore the error handlers.
160 saveerrordict { errordict 3 1 roll put } forall
161 $error /recordstacks false put
163 % Save information from the stacks.
166 countexecstack array execstack
167 0 3 -1 roll 1 sub getinterval
171 countdictstack array dictstack
172 dup length 2 sub 0 exch getinterval
175 % Save state variables that will be reset.
176 % (We could save and print a lot more of the graphics state.)
178 /savefont currentfont def
179 mark { savefont /FontName get =string cvs cvn } stopped
181 { exch pop dup length 0 eq { pop null } if }
182 ifelse /savefontname xdef
185 { currentpoint } stopped { null null } if
186 /savey xdef /savex xdef
190 { pop pop pop pop pop pop exch 1 add exch }
193 /savelines xdef /savecurves xdef
194 /savepathbbox { [ pathbbox ] } stopped { pop null } if def
199 /savecliptop xdef /saveclipright xdef
200 /saveclipbottom xdef /saveclipleft xdef
205 % Eject the current page.
209 % Print the page heading.
211 18 clippath pathbbox newpath
212 4 1 roll pop pop pop eheight sub 12 sub setxy
214 statusdict /printername known
215 { 100 string statusdict begin printername end
217 { exch pop exch pop (Printer name: ) }
222 (Interpreter version ) show version show eol
223 (Error: ) show saveerror show= eol
224 (Command being executed: ) show /savecommand load show= eol
225 currentfile { fileposition } stopped
227 { (Position in input file: ) show show= eol }
230 % Print the current graphics state.
232 (Page parameters:) show eol indent
234 gsave clippath pathbbox grestore
235 exch 3 index sub show= (pt x ) show
236 exch sub show= (pt) show pop eol
237 (current position: ) show
240 { (x = ) show savex show= (, y = ) show savey show= }
242 savelines savecurves add 0 eq
243 { (current path is empty) show
245 { (current path: ) show savelines show= ( line(s), ) show
246 savecurves show= ( curve(s)) show eol
247 (path bounding box: ) show savepathbbox show==
250 (current font: ) show
251 savefontname dup null eq
252 { pop (--no name--) show }
255 savefontname findfont /FontMatrix get matrix invertmatrix
257 savefont /FontMatrix get matrix concatmatrix
258 dup 1 get 0 eq 1 index 2 get 0 eq and
259 1 index 4 get 0 eq and 1 index 5 get 0 eq and
260 1 index 0 get 2 index 3 get eq and
261 { 0 get show= (pt) show }
262 { (scaled by ) show show= }
268 % Print the operand stack.
271 (Operand stack:) show eol indent
272 count { show== eol } repeat
275 % Print the dictionary stack.
277 (Dictionary stack:) show eol indent
278 dstack length 1 sub -1 0
279 { nthdictname { show= } { (<unknown>) show } ifelse eol
283 % Print the execution stack.
286 (Execution stack:) show eol indent
287 estack length 1 sub -1 1
289 dup type /operatortype eq
292 { dup type dup /arraytype eq exch /packedarraytype eq or
296 { show= nthdictname { ( in ) show show= } if eol
315 % Print the next few lines of input.
316 % Unfortunately, this crashes on an Adobe printer.
319 (Next few lines of input:) show eol indent
320 /input currentfile def
322 { input ( ) readstring not { pop exit } if
324 { pop pop eol 1 sub dup 0 eq { pop exit } if }
325 { dup 13 eq { pop pop } { pop show } ifelse }
328 loop } stopped cleartomark eol unindent
338 % Define the common procedure for handling errors.
340 { systemdict begin EPdict begin showerror
345 % Install our own error handlers.
349 /saveerrordict errordict length dict def
350 errordict saveerrordict copy pop
352 { pop [ /countexecstack load 2 index cvlit /doerror load /exec load ] cvx
353 errordict 3 1 roll put
355 errordict /handleerror
356 [ /countexecstack load /handleerror /doerror load /exec load