errpage.ps 8.6 KB

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