summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/dvips/base/ehandler.ps
blob: af40d6e528751540723c900bd14fa671bcf81e6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
%!PS-Adobe-2.0
% This is based on: ehandler.ps -- Downloaded Error Break-page handler
% Copyright (C) 1984, 1985, 1986 Adobe Systems Incorporated.
% All Rights Reserved.

% Modifications Copyright (C) 1990, 1991 Y&Y.
% 	 print names of dictionaries on dictionary stack
% 	 print first few lines of input stream after error
% 	 print top of execution stack
%	 make visible offending commands that are control characters
% 	 print jobname if it exists
%	 catch errors in error handler and print them
% 	 permit overloading (for debugging of error handler)
% 	 ignore timeout errors
% 	 control hardcopy versus softcopy output
%	 avoid multiple pages with error message

%  NOTE: For hardcopy paper/film output:	set showflag true
%  NOTE: For screen/file output:		set printflag true

0 % exitserver password
/$brkpage where
% {pop} if false % UNCOMMENT THIS LINE TO PERMIT OVERLOADING
    { % ifelse  
    pop pop
    (Error Handler in place - not loaded again\n)
    print flush stop
}{ % else
    dup serverdict begin
    statusdict begin checkpassword { % ifelse
	(Error Handler downloaded.\n) print flush
	exitserver
    }{ % else
	pop
	(Bad Password on loading error handler!!!\n)
	print flush stop
    } ifelse
} ifelse
/$brkpage where {pop} { % to allow overloading
 /$brkpage 64 dict def 
} ifelse % to allow overloading
$brkpage begin
/showflag true def	% set to true for hardcopy paper/film output
/printflag false def	% set to true for sending back to screen/file
/prnt { % def
    dup type /stringtype ne {=string cvs} if
    dup length 1 eq { dup 0 get 32 lt { dup 0 get  % new
    64 add exch pop (control-X) dup 8 4 -1 roll put} if} if % new
    dup length 6 mul
    /tx exch def /ty 10 def
    currentpoint /toy exch def /tox exch def
    1 setgray newpath
    tox toy 2 sub moveto
    0 ty rlineto tx 0 rlineto
    0 ty neg rlineto
    closepath showflag{fill}if
    tox toy moveto 0 setgray 
    showflag{dup show}if printflag{print}{pop}ifelse
} bind def
/nl { % def
    currentpoint exch pop lmargin exch moveto
    0 -10 rmoveto
    printflag{(\n) print flush}if
} def

/== {/cp 0 def typeprint nl} def
/typeprint {
    dup type dup currentdict exch known {exec}{unknowntype}ifelse
} readonly def
/lmargin 72 def /rmargin 72 def
/tprint { % def
    dup length cp add rmargin gt {nl /cp 0 def} if
    dup length cp add /cp exch def
    prnt
} readonly def
/cvsprint {=string cvs tprint ( ) tprint} readonly def
/unknowntype { % def
    exch pop cvlit (??) tprint cvsprint
} readonly def
/integertype {cvsprint} readonly def
/realtype {cvsprint} readonly def
/booleantype {cvsprint} readonly def
/operatortype {(//) tprint cvsprint} readonly def
/marktype {pop (-mark- ) tprint} readonly def
% /dicttype {pop (-dictionary- ) tprint} readonly def % do more:
/dicttype {namedict cvsprint} readonly def
/nulltype {pop (-null- ) tprint} readonly def
/filetype {pop (-filestream- ) tprint} readonly def
/savetype {pop (-savelevel- ) tprint} readonly def
/fonttype {pop (-fontid- ) tprint} readonly def
/nametype { % def
    dup xcheck not {(/) tprint} if cvsprint
}readonly def
/stringtype { % def
    dup rcheck { % ifelse
	(\() tprint tprint (\)) tprint
    }{ % else
	pop (-string- ) tprint
    } ifelse
} readonly def
/arraytype { % def
    dup rcheck { % ifelse
	dup xcheck { % ifelse
	    ({) tprint {typeprint} forall (}) tprint
	}{ % else
	    ([) tprint {typeprint} forall (]) tprint
	} ifelse
    }{ % else
	pop (-array- ) tprint
    } ifelse
} readonly def
/packedarraytype { % def
    dup rcheck { % ifelse
	dup xcheck { % ifelse
	    ({) tprint {typeprint} forall (}) tprint
	}{ % else
	    ([) tprint {typeprint} forall (]) tprint
	} ifelse
    }{ % else
	pop (-packedarray- ) tprint
    } ifelse
} readonly def
/courier /Courier findfont 10 scalefont def
/OLDhandleerror where not { % to allow overloading
 /OLDhandleerror errordict /handleerror get def
}{pop} ifelse % to allow overloading
end % $brkpage

% read lines terminated by EITHER newline or return
% (to deal with brain-damage of AppleTalk connection)

/readsafeline{ % def
    dup length exch 0
    { % loop
    	3 index read
	{ % ifelse
	    dup 10 eq 1 index 13 eq or 
	    { % ifelse
	        pop 
		0 exch getinterval exch pop exch pop 
		true exit % normal exit
	    }{ % ifelse
		3 index 2 index le 
		{  % ifelse
		    pop pop exch pop exch pop true
		    stop % rangecheck long line
		}{ % ifelse
		    3 copy put pop 1 add
		} ifelse
	    } ifelse
	}{ % ifelse
	    0 exch getinterval exch pop exch pop 
	    false exit % EOF exit
	} ifelse
    } loop
} def

% Find name for dictionary in tree of dictionaries - ignore font dictionaries
% Discard intermediate dictionary info - return first match

/lookfordict { % name and dict to search
 dup % save for self reference detection
 { % forall
  dup type /dicttype eq
   { % is a dictionary
    dup 3 index ne
     { % not self reference
      1 index /unknowndict ne
       { % not the place we saved
	dup unknowndict eq
	 { % found it
	  pop 3 1 roll pop pop true exit % return name and true
	 }{ % not the unknown dict
	  dup rcheck
	  { % safe to read
	   1 index /FontDirectory ne 
	   { % not Font Directory 
	    lookfordict % recurse
	    { % found it
	     3 1 roll pop pop true exit % return name and true
	    }{
	     0 0 % replace key and value
	    } ifelse % lookfordict
	  } if % FontDirectory 
	} if % safe to read
       } ifelse % equals unknown
      } if % place we hid dict
     } if % self reference
    } if % is a dictionary
  pop pop % flush key and value
 } forall
 dup true ne {pop pop false} if % flush name and dictionary 
} readonly def

/namedict{ % get name for dictionary 
	dup systemdict eq {/systemdict}
	{/unknowndict exch def % store unknown dictionary
	 /systemdict dup load lookfordict not {/-no-name-} if} ifelse
} readonly def

/handleerror { % put
    systemdict begin $error begin $brkpage begin
    newerror { % ifelse
	errorname /timeout ne { 
	{			
	/newerror false store
	vmstatus % pop pop
	3 -1 roll
	0 ne {grestoreall} if	% free up some VM is possible
	initgraphics courier setfont
	lmargin 720 moveto 
 	exch sub 4096 lt {stop} if % nearly out of VM ?
	statusdict /jobname known { % if
	    statusdict /jobname get dup type /stringtype eq {
		nl (JOBNAME: ) prnt
		prnt nl
	   } {pop} ifelse
	} if
	nl (ERROR: ) prnt
	errorname prnt nl
	nl (OFFENDING COMMAND: ) prnt
	/command load prnt
	$error /ostack known { % if
	    nl nl (OPERAND STACK:) prnt nl nl
	    $error /ostack get aload length {==} repeat
	} if
	$error /estack known { % if
	    nl nl (TOP OF EXECUTION STACK:) prnt nl nl
	    $error /estack get aload length 
	    true exch 
	    {dup {1 index == 1 index type cvlit /filetype eq {not} if} if
	    exch pop} repeat pop % avoid system stuff
	} if
	$error /dstack known { % if
	    nl nl (DICTIONARY STACK:) prnt nl nl
	    $error /dstack get aload length {namedict cvx ==} repeat
	} if
	systemdict /file known 
	{ % if
	    nl nl (FILE STREAM:) prnt nl nl
	    true 7 
	    { % repeat
	    	(%stdin) (r) file =string {readsafeline} stopped
		{
			pop (long line:\n) prnt =string prnt nl
		}{
			{
				prnt nl
			}{
				prnt nl (EOF) prnt nl nl pop false exit
			} ifelse
		}  ifelse
	    } repeat
	    {3 {(.) prnt nl} repeat nl} if
	} if
	showflag{/#copies 1 def systemdict /showpage get exec}if
	/newerror true store
	/OLDhandleerror load end end end exec
	} stopped {
		nl nl (VMError (or error in error handler)) prnt nl
		nl (ERROR: ) prnt	%
		errorname prnt nl	%
		nl (OFFENDING COMMAND: ) prnt
		/command load prnt nl	%
		showflag{/#copies 1 def systemdict /showpage get exec}if
		/newerror true store
		/OLDhandleerror load end end end exec
		} if %% get some output at least if handler dies
      } if % ignore timeout
    }{ % else already in error handler ...
	end end end
%%	systemdict /showpage get exec %% get some output if internal error ?
    } ifelse
}
dup 0 systemdict put % replace name by actual dict object
dup 4 $brkpage put   % replace name by dict object
bind readonly

errordict 3 1 roll put % put proc in errordict as /handleerror