1
0

errpage.ps 8.4 KB

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