]> git.lizzy.rs Git - plan9front.git/blob - sys/lib/ghostscript/gs_init.ps
merge
[plan9front.git] / sys / lib / ghostscript / gs_init.ps
1 % Copyright (C) 1989-2004 artofcode LLC. All rights reserved.
2
3 % This software is provided AS-IS with no warranty, either express or
4 % implied.
5
6 % This software is distributed under license and may not be copied,
7 % modified or distributed except as expressly authorized under the terms
8 % of the license contained in the file LICENSE in this distribution.
9
10 % For more information about licensing, please refer to
11 % http://www.ghostscript.com/licensing/. For information on
12 % commercial licensing, go to http://www.artifex.com/licensing/ or
13 % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15
16 % $Id: gs_init.ps,v 1.120 2005/10/07 19:46:35 ray Exp $
17 % Initialization file for the interpreter.
18 % When this is run, systemdict is still writable.
19
20 % Comment lines of the form
21 %       %% Replace <n> <file(s)>
22 % indicate places where the next <n> lines should be replaced by
23 % the contents of <file(s)>, when creating a single merged init file.
24
25 % The interpreter can call out to PostScript code.  All procedures
26 % called in this way, and no other procedures defined in these
27 % initialization files, have names that begin with %, e.g.,
28 % (%Type1BuildChar) cvn.
29
30 % Check the interpreter revision.  NOTE: the interpreter code requires
31 % that the first non-comment token in this file be an integer.
32 853
33 dup revision ne
34  { (gs: Interpreter revision \() print revision 10 string cvs print
35    (\) does not match gs_init.ps revision \() print 10 string cvs print
36    (\).\n) print flush //null 1 .quit
37  }
38 if pop
39
40 % Acquire userdict, and set its length if necessary.
41 /userdict where
42  { pop userdict maxlength 0 eq }
43  { true }
44 ifelse
45 systemdict exch
46  {              % userdict wasn't already set up by iinit.c.
47    dup /userdict
48    currentdict dup 200 .setmaxlength            % userdict
49    .forceput                    % userdict is local, systemdict is global
50  }
51 if begin
52
53 % Define dummy local/global operators if needed.
54 systemdict /.setglobal known
55  { true .setglobal
56  }
57  { /.setglobal { pop } bind def
58    /.currentglobal { false } bind def
59    /.gcheck { pop false } bind def
60  }
61 ifelse
62
63 % Define .languagelevel if needed.
64 systemdict /.languagelevel known not { /.languagelevel 1 def } if
65
66 % Optionally choose a default paper size other than U.S. letter.
67 % The default page size for many devices is set at compile time to 
68 % letter, but this can be changed to A4 although this is rarely done.  
69 % Some devices such as bbox have a different default page size,
70 % and should not be set to A4 or letter.
71 % When ghostscript is used in countries that use the international
72 % standard page size A4 rather than US letter, the page size of 
73 % devices that default to letter or A4 can be changed by setting
74 % DEFAULTPAPERSIZE.
75 % /DEFAULTPAPERSIZE (a4) def
76
77 % Turn on array packing for the rest of initialization.
78 true setpacking
79
80 % Define the old MS-DOS EOF character as a no-op.
81 % This is a hack to get around the absurd habit of MS-DOS editors
82 % of adding an EOF character at the end of the file.
83 <1a> cvn { } def
84
85 % Acquire the debugging flags.
86 currentdict /DEBUG known   /DEBUG exch def
87
88 % if DEBUG is set, set ALL of the subset debugging flags
89 mark    % '[' isn't defined yet
90   /CCFONTDEBUG          % Compiled Fonts
91   /CFFDEBUG             % CFF Fonts
92   /CMAPDEBUG            % CMAP 
93   /DOCIEDEBUG           % CIE color
94   /EPSDEBUG             % EPS handling
95   /FAPIDEBUG            % Font API
96   /INITDEBUG            % Initialization
97   /PDFDEBUG             % PDF Interpreter
98   /PDFOPTDEBUG          % PDF Optimizer (Linearizer)
99   /PDFWRDEBUG           % PDF Writer
100   /SETPDDEBUG           % setpagedevice
101   /STRESDEBUG           % Static Resources
102   /TTFDEBUG             % TTF Fonts
103   /VGIFDEBUG            % ViewGIF
104   /VJPGDEBUG            % ViewJPEG
105   /RESMPDEBUG           % Resource map
106 counttomark array astore exch pop % ']' isn't defined yet
107 { dup currentdict exch known DEBUG or def } forall
108
109 currentdict /PDFSTEP known /PDFSTEP exch def
110 % if PDFSTEP is on, turn on PDFDEBUG
111 PDFSTEP { /PDFDEBUG true def } if
112
113   /VMDEBUG
114     INITDEBUG {{print mark
115             systemdict /level2dict known
116              { .currentglobal dup false .setglobal vmstatus
117                true .setglobal vmstatus 3 -1 roll pop
118                6 -2 roll pop .setglobal
119              }
120              { vmstatus 3 -1 roll pop
121              }
122             ifelse usertime 16#fffff and counttomark
123               { ( ) print (           ) cvs print }
124             repeat pop
125             ( ) print systemdict length (    ) cvs print
126             ( ) print countdictstack (  ) cvs print
127             ( <) print count (    ) cvs print (>\n) print flush
128           }}
129           {{pop
130           }}
131          ifelse
132   def
133
134 currentdict /BATCH known   /BATCH exch def
135 currentdict /DELAYBIND known   /DELAYBIND exch def
136 currentdict /DISKFONTS known   /DISKFONTS exch def
137 currentdict /DOINTERPOLATE .knownget { /INTERPOLATE exch def } if
138 currentdict /ESTACKPRINT known   /ESTACKPRINT exch def
139 currentdict /FAKEFONTS known   /FAKEFONTS exch def
140 currentdict /FIXEDMEDIA known   /FIXEDMEDIA exch def
141 currentdict /FIXEDRESOLUTION known   /FIXEDRESOLUTION exch def
142 currentdict /LOCALFONTS known   /LOCALFONTS exch def
143 currentdict /JOBSERVER known   /JOBSERVER exch def
144 currentdict /NOBIND known   /NOBIND exch def
145 /.bind /bind load def
146 NOBIND { /bind { } def } if
147 currentdict /NOCACHE known   /NOCACHE exch def
148 currentdict /NOCCFONTS known   /NOCCFONTS exch def
149 currentdict /NOCIE known   /NOCIE exch def
150 currentdict /NOPSICC known   /NOPSICC exch def
151 currentdict /NODISPLAY known   not /DISPLAYING exch def
152 currentdict /NOFONTMAP known   /NOFONTMAP exch def
153 currentdict /NOFONTPATH known   /NOFONTPATH exch def
154 currentdict /NOGC known   /NOGC exch def
155 currentdict /NOINTERPOLATE .knownget { /INTERPOLATE exch not def } if
156 currentdict /NOOUTERSAVE known   /NOOUTERSAVE exch def
157 currentdict /NOPAGEPROMPT known   /NOPAGEPROMPT exch def
158 currentdict /NOPAUSE known   /NOPAUSE exch def
159 currentdict /NOPLATFONTS known   /NOPLATFONTS exch def
160 currentdict /NOPROMPT known   /NOPROMPT exch def
161 currentdict /NOTRANSPARENCY known   /NOTRANSPARENCY exch def
162 currentdict /DOPS known   /DOPS exch def
163 currentdict /NOSUBSTDEVICECOLORS known   /NOSUBSTDEVICECOLORS exch def
164 % The default value of ORIENT1 is true, not false.
165 currentdict /ORIENT1 known not { /ORIENT1 true def } if
166 currentdict /OSTACKPRINT known   /OSTACKPRINT exch def
167 currentdict /OUTPUTFILE known   % obsolete
168  { /OutputFile /OUTPUTFILE load def
169    currentdict /OUTPUTFILE .undef
170  } if
171 currentdict /QUIET known   /QUIET exch def
172 % DELAYSAFER is effectively the same as newer NOSAFER
173 currentdict /DELAYSAFER known { /DELAYSAFER true def /NOSAFER true def } if
174 /SAFER currentdict /NOSAFER known {
175   false
176 } {
177   currentdict /SAFER known
178   currentdict /PARANOIDSAFER known or   % PARANOIDSAFER is equivalent
179 }
180 ifelse def
181 currentdict /SHORTERRORS known   /SHORTERRORS exch def
182 currentdict /STRICT known   /STRICT exch def
183 currentdict /TTYPAUSE known   /TTYPAUSE exch def
184 currentdict /WRITESYSTEMDICT known   /WRITESYSTEMDICT exch def
185
186 % Acquire environment variables.
187 currentdict /DEVICE known not
188  { (GS_DEVICE) getenv { /DEVICE exch def } if } if
189
190 (START) VMDEBUG
191
192 % Open the standard files, so they will be open at the outermost save level.
193 (%stdin) (r) file pop
194 (%stdout) (w) file pop
195 (%stderr) (w) file pop
196
197 /.currentuserparams where {
198   pop mark
199         % The Adobe implementations appear to have very large maximum
200         % stack sizes.  This turns out to actually make a difference,
201         % since some badly-behaved files include extremely long procedures,
202         % or construct huge arrays on the operand stack.
203         % We reset the stack sizes now so that we don't have to worry
204         % about overflowing the (rather small) built-in stack sizes
205         % during initialization.
206   /MaxDictStack 500
207   /MaxExecStack 5000
208   /MaxOpStack 50000
209   .dicttomark .setuserparams
210 } if
211
212 % Define a procedure for skipping over an unneeded section of code.
213 % This avoids allocating space for the skipped procedures.
214 % We can't use readline, because that imposes a line length limit.
215 /.skipeof       % <string> .skipeof -
216  { currentfile exch 1 exch .subfiledecode flushfile
217  } .bind def
218
219 % Define procedures to assist users who don't read the documentation.
220 userdict begin
221 /help
222  { (Enter PostScript commands.  '(filename) run' runs a file, 'quit' exits.\n)
223    print flush
224  } .bind def
225 end
226
227 % Define =string, which is used by some PostScript programs even though
228 % it isn't documented anywhere.
229 % Put it in userdict so that each context can have its own copy.
230 userdict /=string 256 string put
231
232 % Print the greeting.
233
234 /printgreeting
235  { mark
236    product (Ghostscript) search
237     { pop pop pop
238       (This software comes with NO WARRANTY: see the file PUBLIC for details.\n)
239     }
240     { pop
241     }
242    ifelse
243    (\n) copyright
244    (\)\n) revisiondate 10 mod revisiondate 10 idiv 10 mod (-)
245    revisiondate 100 idiv 10 mod revisiondate 1000 idiv 10 mod (-)
246    revisiondate 10000 idiv ( \()
247    revision 10 mod
248    revision 100 mod 10 idiv (.)
249    revision 100 idiv ( )
250    product
251    counttomark
252     { (%stdout) (w) file exch 0 .writecvp
253     } repeat pop
254  } .bind def
255
256 QUIET not { printgreeting flush } if
257
258 % Define a special version of def for making operator procedures.
259 /obind {        % <name> <proc> obind <name> <oper>
260   1 index exch .makeoperator
261 } .bind def
262 /odef {         % <name> <proc> odef -
263   1 index exch .makeoperator def
264 } .bind def
265
266 % Define a special version of def for storing local objects into global
267 % dictionaries.  Like .forceput, this exists only during initialization.
268 /.forcedef {            % <key> <value> .forcedef -
269   currentdict 3 1 roll .forceput
270 } .bind odef
271
272 % Define procedures for accessing variables in systemdict and userdict
273 % regardless of the contents of the dictionary stack.
274 /.systemvar {           % <name> .systemvar <value>
275   //systemdict exch get
276 } .bind odef
277 /.userdict {            % - .userdict <dict>
278   /userdict .systemvar
279 } .bind odef
280 /.uservar {             % <name> .uservar <value>
281   .userdict exch get
282 } .bind odef
283
284 % If we're delaying binding, remember everything that needs to be bound later.
285 DELAYBIND NOBIND not and
286  { .currentglobal false .setglobal
287    systemdict /.delaybind 1500 array .forceput
288    .setglobal
289    userdict /.delaycount 0 put
290         % When we've done the delayed bind, we want to stop saving.
291         % Detect this by the disappearance of .delaybind.
292    /bind
293     { /.delaybind .systemvar dup length 0 ne
294        { .delaycount 2 index put
295          .userdict /.delaycount .delaycount 1 add put
296        }
297        { pop /.bind cvx exec
298        }
299       ifelse
300     } .bind def
301  } if
302
303 %**************** BACKWARD COMPATIBILITY ****************
304 /hwsizedict mark /HWSize //null .dicttomark readonly def
305 /copyscanlines {                % <device> <y> <string> copyscanlines <substr>
306   0 3 1 roll 3 index //hwsizedict .getdeviceparams
307   exch pop exch pop aload pop 3 2 roll
308   0 exch //null exch .getbitsrect exch pop
309 } bind odef
310 currentdict /hwsizedict .undef
311 /getdeviceprops
312  { //null .getdeviceparams
313  } bind odef
314 /.putdeviceprops
315  { //null true counttomark 1 add 3 roll .putdeviceparams
316    dup type /booleantype ne
317     { dup mark eq { /unknown /rangecheck } if
318       counttomark 4 add 1 roll cleartomark pop pop pop
319       /.putdeviceprops load exch signalerror
320     }
321    if
322  } bind odef
323 /.currentfilladjust { .currentfilladjust2 pop } bind odef
324 /.setfilladjust { dup .setfilladjust2 } bind odef
325 /.writecvs { 0 .writecvp } bind odef
326 %**************** DEPRECATED PROCEDURES ****************
327 %**************** DO NOT USE THESE IN NEW CODE ****************
328 /max { .max } bind def          % use .max instead
329 /min { .min } bind def          % use .min instead
330 /unread /.unread load def       % use .peekstring instead
331 %**************** END OF BACKWARD COMPATIBILITY SECTION ****************
332
333 % Utility procedure to sort an array
334 % <array> <lt-proc> .sort <array>
335 /.sort {
336   1 index length 1 sub -1 1 {
337     2 index exch 2 copy get 3 copy      % arr proc arr i arr[i] arr i arr[i]
338     0 1 3 index 1 sub {
339       3 index 1 index get       % arr proc arr i arr[i] arr imax amax j arr[j]
340       2 index 1 index 10 index exec {   % ... amax < arr[j]
341         4 2 roll
342       } if pop pop
343     } for                       % arr proc arr i arr[i] arr imax amax
344     4 -1 roll exch 4 1 roll put put
345   } for pop
346 } bind def
347
348 % Utility for removing all entries from a dictionary
349 /.PurgeDict   % <dict> .PurgeDict -
350 { { true
351     1 index { pop exch pop false exit
352     } forall
353     { exit
354     } if
355     1 index exch undef
356   } loop
357   pop
358 } bind def
359
360 % Define predefined procedures substituting for operators,
361 % in alphabetical order.
362
363 userdict /#copies 1 put
364 % Adobe implementations don't accept /[ or /], so we don't either.
365 ([) cvn
366         /mark load def
367 (]) cvn
368         {counttomark array astore exch pop} odef
369 % .beginpage is redefined if setpagedevice is present.
370 /.beginpage { } odef
371 % In LanguageLevel 3, copypage erases the page.
372 /copypage {
373         .languagelevel 3 ge
374         dup { 0 } { 1 } ifelse .endpage {
375           .currentnumcopies 1 index .outputpage
376           (>>copypage, press <return> to continue<<\n) .confirm
377           dup { erasepage } if
378         } if pop
379     systemdict /..page_default_spaces .knownget { //.PurgeDict exec } if
380     .beginpage
381 } odef
382 /currentmatrix {
383         .currentmatrix 6 index astore pop
384 } odef
385 % .currentnumcopies is redefined in Level 2.
386 /.currentnumcopies { #copies } odef
387 /setcolorscreen where { pop             % not in all Level 1 configurations
388    /currentcolorscreen
389         { .currenthalftone
390            { { 60 exch 0 exch 3 copy 6 copy }   % halftone - not possible
391              { 3 copy 6 copy }                  % screen
392              { }                                % colorscreen
393            }
394           exch get exec
395         } odef
396 } if
397 /currentscreen
398         { .currenthalftone
399            { { 60 exch 0 exch }                 % halftone - not possible
400              { }                                % screen
401              { 12 3 roll 9 { pop } repeat }     % colorscreen
402            }
403           exch get exec
404         } odef
405 /.echo /echo load def
406 userdict /.echo.mode true put
407 /echo   {dup /.echo.mode exch store .echo} odef
408 /.eexec_param_dict mark
409   /eexec true
410   /seed 55665
411 .dicttomark readonly def
412 /eexec {
413         % Rebind .currentresourcefile if it is the source for the eexec.
414   dup //.eexec_param_dict //filterdict /eexecDecode get exec
415   cvx exch .currentresourcefile eq
416   //systemdict begin { {exec} .execasresource } { exec } ifelse
417         % Only pop systemdict if it is still the top element,
418         % because this is apparently what Adobe interpreters do.
419   currentdict //systemdict eq { end } if
420 } odef
421 % .endpage is redefined if setpagedevice is present.
422 /.endpage { 2 ne } odef
423 % erasepage mustn't use gsave/grestore, because we call it before
424 % the graphics state stack has been fully initialized.
425 /erasepage
426         { /currentcolor where
427            { pop currentcolor currentcolorspace { setcolorspace setcolor } }
428            { /currentcmykcolor where
429               { pop currentcmykcolor { setcmykcolor } }
430               { currentrgbcolor { setrgbcolor } }
431              ifelse
432            }
433           ifelse
434           currentoverprint false setoverprint 1 setgray .fillpage setoverprint
435           exec
436         } odef
437 % To satisfy the Genoa FTS, executive must be a procedure, not an operator.
438 /executive
439         { { prompt
440              { (%statementedit) (r) file } stopped
441              { pop pop $error /errorname get /undefinedfilename eq
442                 { .clearerror exit } if         % EOF
443                /handleerror .systemvar exec //null              % ioerror??
444              }
445             if
446             cvx { .runexec } execute
447           } loop
448         } bind def
449 /filter
450         { //filterdict 1 index .knownget
451            { exch pop exec }
452            { /filter load /undefined signalerror }
453           ifelse
454         } odef
455 % handleerror procedure as mentioned in the "Operators" section of the PLRM Section 8.2
456 % This invokes the handleerror procedure from errordict (unless we are running under a
457 % JOBSERVER where we want to always use a defined error handler (many error handlers in
458 % 'wild' PostScript files are broken and don't indicate the error in any useful fashion).
459 %
460 % We run the handleerror procedure using .internalstopped so that broken error handlers
461 % won't cause nested errors (Unexpected Error conditions).
462 /handleerror
463         JOBSERVER {
464           { /errordict .systemvar /.GShandleerror get .internalstopped pop } bind % always use .GShandleerror.
465         } {
466           { /errordict .systemvar /handleerror get .internalstopped pop } bind % PLRM standard errorhandling
467         } ifelse def
468 /identmatrix [1.0 0.0 0.0 1.0 0.0 0.0] readonly def
469 /identmatrix
470         { dup 0 //identmatrix putinterval } odef
471 /languagelevel 1 def            % gs_lev2.ps may change this
472 /makeimagedevice { false makewordimagedevice } odef
473 /matrix { 6 array identmatrix } odef
474 /pathbbox
475         { false .pathbbox
476         } odef
477 % .promptmsg is redefined if the interpreter includes readline support.
478 /.promptmsg {
479         (GS) print
480         count 0 ne { (<) print count =only } if
481         (>) print flush
482 } bind def
483 /prompt { flush flushpage NOPROMPT not { .promptmsg } if } bind def
484 /pstack { 0 1 count 3 sub { index == } for } bind def
485 /putdeviceprops
486         { .putdeviceprops { erasepage } if } odef
487 /quit   { /quit load 0 .quit } odef
488 /run    { dup type /filetype ne { (r) file } if
489                 % We must close the file when execution terminates,
490                 % regardless of the state of the stack,
491                 % and then propagate an error, if any.
492           cvx .runexec
493         } odef
494 % Execute a file.
495 % Level 2 uses 2 .stop to clear the e-stack for a successful startjob:
496 % we detect that here, since we need to handle this even if we start out
497 % without job control in effect.
498 %
499 % What we push on the e-stack is the following to be executed in this order:
500 %       <lit-file|fileproc> .runexec1 <lit-file|fileproc> .runexec2
501 /.runexec1 {            % <file|fileproc> .runexec1 -
502   dup type /filetype ne { cvx exec } if
503   cvx //null 2 .stopped
504         % If we got back here from a startjob, just keep going.
505         % startjob replaces the null on the o-stack with a procedure
506         % to be executed when we get back here.
507   dup //null ne { exec true } { pop false } ifelse
508 } bind def
509 /.runexec2 {            % <continue> <file|fileproc> .runexec2 -
510   exch {
511     .runexec
512   } {
513     dup type /filetype ne { cvx exec } if
514     closefile
515   } ifelse
516 } bind def
517 /.runexec {             % <file|fileproc> .runexec -
518   cvlit /.runexec1 cvx 1 index /.runexec2 cvx 4 .execn
519 } bind def
520 % The following is only for compatibility with Adobe interpreters.
521 /setdash {
522         1 index length 11 gt { /setdash load /limitcheck signalerror } if
523         //setdash
524 } odef
525 /setdevice
526   {
527     .setdevice
528       {
529         mark
530           {             % Reset the halftone since the device may differ
531             currenthalftone
532             dup type /dicttype eq
533               { sethalftone }
534               { pop }
535             ifelse
536           }
537         stopped
538         cleartomark
539         erasepage
540       }
541     if
542   }
543 odef
544 /setlinecap {
545         dup 2 gt { /setlinecap load /rangecheck signalerror } if
546         .setlinecap
547 } odef
548 /setlinejoin {
549         dup 2 gt { /setlinejoin load /rangecheck signalerror } if
550         .setlinejoin
551 } odef
552 /setmatrix {
553         dup aload pop .setmatrix pop
554 } odef
555 /showpage {
556         0 .endpage .doneshowpage {
557           .currentnumcopies true .outputpage
558           (>>showpage, press <return> to continue<<\n) .confirm
559           initgraphics
560           currentoverprint false setoverprint 1 setcolor
561           .fillpage
562           setoverprint 0 setcolor
563         }
564         { initgraphics } ifelse
565     systemdict /..page_default_spaces .knownget { //.PurgeDict exec } if
566     .beginpage
567 } odef
568 % Code output by Adobe Illustrator relies on the fact that
569 % `stack' is a procedure, not an operator!!!
570 /stack  { 0 1 count 3 sub { index = } for } bind def
571 /start  { BATCH { //null 0 .quit } { executive } ifelse } def
572 % Internal uses of stopped that aren't going to do a stop if an error occurs
573 % should use .internalstopped to avoid setting newerror et al.
574 /.internalstopped { //null 1 .stopped //null ne } bind def
575 /store {        % Don't alter operands before completing.
576         1 index where { 2 index 2 index put pop pop } { def } ifelse
577 } odef
578 /.typenames mark .typenames counttomark packedarray exch pop def
579 /type {
580         //.typenames .type
581 } odef
582 currentdict /.typenames .undef
583 % When running in Level 1 mode, this interpreter is supposed to be
584 % compatible with PostScript "version" 54.0 (I think).
585 /version (54.0) readonly def
586 /.wheredict 10 dict def
587 /.where /where load def
588 /where {
589         //.wheredict 1 index .knownget { exec } { .where } ifelse
590 } odef
591
592 % internaldict is defined in systemdict, but the dictionary is allocated
593 % in local VM.  However, the procedure must be global, since it is an
594 % "operator" and must be bind-able into global procedures.
595 % We make a procedure for creating it, since we must create a new one
596 % for each context with private local VM.
597 /.makeinternaldict {
598   .currentglobal true .setglobal
599     [ /dup .systemvar 1183615869 /eq .systemvar
600         [ /pop .systemvar //null ] cvx
601         false .setglobal
602         dup 1 10 dict .forceput % proc is global, dict is local
603         true .setglobal
604         [ /internaldict /cvx .systemvar /invalidaccess /signalerror cvx ] cvx
605       /ifelse .systemvar
606     ] cvx executeonly
607   exch .setglobal
608 } odef
609 systemdict /internaldict dup .makeinternaldict .makeoperator
610 .forceput               % proc is local, systemdict is global
611 % Move superexec to internaldict if superexec is defined.
612 currentdict /superexec .knownget {
613   1183615869 internaldict /superexec 3 -1 roll put
614   currentdict /superexec .undef
615 } if
616
617 % Define some additional built-in procedures (beyond the ones defined by
618 % the PostScript Language Reference Manual).
619 % Warning: these are not guaranteed to stay the same from one release
620 % to the next!
621 /concatstrings  %       (str1) (str2) concatstrings (str1str2)
622         { exch dup length 2 index length add string     % str2 str1 new
623           dup dup 4 2 roll copy         % str2 new new new1
624           length 4 -1 roll putinterval
625         } bind def
626 /copyarray
627         { dup length array copy } bind def
628 % Copy a dictionary per the Level 2 spec even in Level 1.
629 /.copydict              % <fromdict> <todict> .copydict <todict>
630         { dup 3 -1 roll { put dup } forall pop } bind def
631 /copystring
632         { dup length string copy } bind def
633 /findlibfile {
634         .libfile { dup .filename pop exch true } { false } ifelse
635 } odef
636 /.growdictlength        % get size for growing a dictionary
637         { length 3 mul 2 idiv 1 add
638         } bind def
639 /.growdict              % grow a dictionary
640         { dup .growdictlength .setmaxlength
641         } bind def
642 /.growput               % put, grow the dictionary if needed
643         { 2 index length 3 index maxlength eq
644            { 3 copy pop known not { 2 index .growdict } if
645            } if
646           put
647         } bind def
648 % .localvmarray may be an operator: see zsysvm.c.
649 /.localvmarray where {
650   pop
651 } {
652   /.localvmarray {
653     .currentglobal false .setglobal
654     exch array exch .setglobal
655   } bind def
656 } ifelse
657 /.localvmdict where {
658   pop
659 } {
660   /.localvmdict {
661     .currentglobal false .setglobal
662     exch dict exch .setglobal
663   } bind def
664 } ifelse
665 /.packtomark
666         { counttomark packedarray exch pop } bind def
667 /ppstack
668         { 0 1 count 3 sub { index === } for } bind def
669 /runlibfile
670         {               % We don't want to bind 'run' into this procedure,
671                         % since run may get redefined.
672           findlibfile
673            { exch pop /run .systemvar exec }
674            { /undefinedfilename signalerror }
675           ifelse
676         } bind def
677 /selectdevice
678         { finddevice setdevice .setdefaultscreen } bind def
679 /signalerror            % <object> <errorname> signalerror -
680         { /errordict .systemvar exch get exec } bind def
681
682 % Define the =[only] procedures.  Also define =print,
683 % which is used by some PostScript programs even though
684 % it isn't documented anywhere.
685 /write=only {
686         .writecvs
687 } bind def
688 /write= {
689         1 index exch write=only (\n) writestring
690 } bind def
691 /=only  { (%stdout) (w) file exch write=only } bind def
692 /=      { =only (\n) print } bind def
693 /=print /=only load def
694 % Temporarily define == as = for the sake of runlibfile0.
695 /== /= load def
696
697 % The following procedures are documented.
698 /copydevice {           % <device> copydevice <newdevice>
699   false .copydevice2
700 } odef
701 /finddevice {           % <devicename> finddevice <device>
702   /devicedict .systemvar exch get
703   dup 1 get //null eq {
704                 % This is the first request for this type of device.
705                 % Create a default instance now.
706                 % Stack: [proto null]
707     .currentglobal true .setglobal exch
708     dup dup 0 get copydevice 1 exch put
709     exch .setglobal
710   } if 1 get
711 } bind def
712 /findprotodevice {      % <devicename> findprotodevice <protodevice>
713   /devicedict .systemvar exch get 0 get
714 } bind def
715
716 % Run a resource file.  This allows us to distinguish resource objects
717 % from objects coming from input files.
718 userdict /.currentresourcefile //null put
719 /.execasresource {      % <file> <proc|runfile> .execasresource -
720   /stopped .systemvar
721   /.currentresourcefile .uservar
722                 % Stack: file proc -stopped- currfile
723   .userdict /.currentresourcefile 5 index cvlit put
724   2 .execn              % stopped <file>
725   .userdict /.currentresourcefile 3 -1 roll put
726   { stop } if
727 } bind def
728 /.runresource {         % <file> .runresource -
729   { /run .systemvar exec } .execasresource
730 } bind def
731
732 % Define procedures for getting and setting the current device resolution.
733
734 /gsgetdeviceprop        % <device> <propname> gsgetdeviceprop <value>
735  { 2 copy mark exch //null .dicttomark .getdeviceparams
736    dup mark eq          % if true, not found
737     { pop dup /undefined signalerror }
738     { 5 1 roll pop pop pop pop }
739    ifelse
740  } bind def
741 /gscurrentresolution    % - gscurrentresolution <[xres yres]>
742  { currentdevice /HWResolution gsgetdeviceprop
743  } bind def
744 /gssetresolution        % <[xres yres]> gssetresolution -
745  { 2 array astore mark exch /HWResolution exch
746    currentdevice copydevice putdeviceprops setdevice
747  } bind def
748
749 % Define auxiliary procedures needed for the above.
750 /shellarguments         % -> shell_arguments true (or) false
751         { /ARGUMENTS where
752            { /ARGUMENTS get dup type /arraytype eq
753               { aload pop /ARGUMENTS //null store true }
754               { pop false }
755              ifelse }
756            { false } ifelse
757         } bind def
758 /.confirm {
759   DISPLAYING NOPAUSE not TTYPAUSE or and {
760         % Print a message (unless NOPAGEPROMPT or NOPROMPT is true)
761         % and wait for the user to type something.
762         % If the user just types a newline, flush it.
763     NOPAGEPROMPT NOPROMPT or { pop } { print flush } ifelse
764     .confirmread
765   } {
766     pop
767   } ifelse
768 } bind def
769 /.confirmread {
770   TTYPAUSE {
771     (/dev/tty) (r) file dup read pop pop closefile
772   } {
773     .echo.mode false echo
774     (%stdin) (r) file dup read {
775       dup (\n) 0 get eq { pop pop } { unread } ifelse
776     } {
777       pop
778     } ifelse echo
779   } ifelse
780 } bind def
781
782 % Define the procedure used by .runfile, .runstdin and .runstring
783 % for executing user input.
784 % This is called with a procedure or executable file on the operand stack.
785 /.execute {             % <obj> .execute <stopped>
786   stopped $error /newerror get and
787    { /handleerror .systemvar exec flush true } { false } ifelse
788 } bind def
789 /execute {              % <obj> execute -
790   .execute pop
791 } odef
792 % Define an execute analogue of runlibfile0.
793 /execute0 {             % <obj> execute0 -
794   .execute { /execute0 cvx 1 .quit } if
795 } bind def
796 % Define the procedure that the C code uses for running files
797 % named on the command line.
798 /.runfile {
799   { runlibfile } execute0
800 } def
801 % Define the procedure that the C code uses for running piped input.
802 % We don't use the obvious { (%stdin) run }, because we want the file to be
803 % reopened if a startjob does a restore.
804 /.runstdin {
805   { { (%stdin) (r) file cvx } .runexec } execute0
806 } bind def
807 % Define the procedure that the C code uses for running commands
808 % given on the command line with -c.  We turn the string into a file so that
809 % .runexec can do the right thing with a startjob.
810 /.runstring {
811   .currentglobal exch true .setglobal
812   0 () .subfiledecode
813   exch .setglobal cvx { .runexec } execute0
814 } bind def
815 % Define the procedure that the C code uses to set up for executing
816 % a string that may be received in pieces.
817 /.runstringbegin {
818   .currentglobal true .setglobal
819   { .needinput } bind 0 () .subfiledecode
820   exch .setglobal cvx .runexec
821 } bind def
822
823 % Define a special version of runlibfile that aborts on errors.
824 /runlibfile0
825         { cvlit dup /.currentfilename exch def
826            { findlibfile not { stop } if }
827           stopped
828            { (Can't find \(or open\) initialization file ) print
829              .currentfilename == flush /runlibfile0 cvx 1 .quit
830            } if
831           exch pop cvx stopped
832            { (While reading ) print .currentfilename print (:\n) print flush
833              /handleerror .systemvar exec /runlibfile0 1 .quit
834            } if
835         } bind def
836 % Temporarily substitute it for the real runlibfile.
837 /.runlibfile /runlibfile load def
838 /runlibfile /runlibfile0 load def
839
840 % Create the error handling machinery.
841 % Define the standard error handlers.
842 % The interpreter has created the ErrorNames array.
843 /.unstoppederrorhandler % <command> <errorname> .unstoppederrorhandler -
844  {      % This is the handler that gets used for recursive errors,
845         % or errors outside the scope of a 'stopped'.
846    2 copy SHORTERRORS
847     { (%%[ Error: ) print =only flush
848       (; OffendingCommand: ) print =only ( ]%%) =
849     }
850     { (Unrecoverable error: ) print =only flush
851       ( in ) print = flush
852       count 2 gt
853        { (Operand stack:\n  ) print
854          count 1 sub -1 2 { (  ) print index =only flush } for
855          () = flush
856        } if
857     }
858    ifelse
859    -1 0 1 //ErrorNames length 1 sub
860     { dup //ErrorNames exch get 3 index eq
861        { not exch pop exit } { pop } ifelse
862     }
863    for exch pop .quit
864  } bind def
865 /.errorhandler          % <command> <errorname> .errorhandler -
866   {             % Detect an internal 'stopped'.
867     1 .instopped { //null eq { pop pop stop } if } if
868     (I) false .setdebug
869     $error /.inerror get 1 .instopped { pop } { pop true } ifelse
870      { .unstoppederrorhandler
871      } if       % detect error recursion
872     $error /globalmode .currentglobal false .setglobal put
873     $error /.inerror true put
874     $error /newerror true put
875     $error exch /errorname exch put
876     $error exch /command exch put
877     $error /recordstacks get $error /errorname get /VMerror ne and
878      {          % Attempt to store the stack contents atomically.
879        count array astore dup $error /ostack 4 -1 roll
880        % Grab the execstack, then remove to two elements that are from
881        % this error handler (not interesting).
882        countexecstack array execstack dup length 2 sub 0 exch getinterval
883        $error /estack 3 -1 roll
884        countdictstack array dictstack $error /dstack 3 -1 roll
885        put put put aload pop
886      }
887      { $error /dstack .undef
888        $error /estack .undef
889        $error /ostack .undef
890      }
891     ifelse
892     $error /position currentfile status
893      { currentfile { fileposition } .internalstopped { pop //null } if
894      }
895      {          % If this was a scanner error, the file is no longer current,
896                 % but the command holds the file, which may still be open.
897        $error /command get dup type /filetype eq
898         { { fileposition } .internalstopped { pop //null } if }
899         { pop //null }
900        ifelse
901      }
902     ifelse put
903                 % During initialization, we don't reset the allocation
904                 % mode on errors.
905     $error /globalmode get $error /.nosetlocal get and .setglobal
906     $error /.inerror false put
907     stop
908   } bind def
909 % Define the standard handleerror.  We break out the printing procedure
910 % (.printerror) so that it can be extended for binary output
911 % if the Level 2 facilities are present.
912   /.printerror
913    { $error begin newerror
914      {
915        /command load errorname SHORTERRORS
916         { (%%[ Error: ) print =only flush
917           (; OffendingCommand: ) print =only
918           errorinfo dup //null eq {
919             pop
920           } {
921             (;\nErrorInfo:) print
922             dup type /arraytype eq
923               { { ( ) print =only } forall }
924               { ( ) print =only }
925             ifelse
926           } ifelse
927           ( ]%%) = flush
928         }
929         { (Error: ) print ==only flush
930           ( in ) print ==only flush
931           errorinfo dup //null eq {
932             pop
933           } {
934             (\nAdditional information: ) print ==only flush
935           } ifelse
936           .printerror_long
937         }
938        ifelse
939        .clearerror flush
940      }
941      { % newerror is false, test to see if user has set handleerror to a different
942        % routine, if so execute it, otherwise, just return.  This code deals with the
943        % Genoa issue of setting /handleerror, and then calling it, without an error
944        % being set.  We were erroring in this case, due to /command load failing.
945
946        /errordict .systemvar dup /handleerror get exch
947          //JOBSERVER { /.GShandleerror } { /handleerror } ifelse
948          get ne
949          { /errordict .systemvar begin /handleerror load .internalstopped pop end
950          }
951          if
952      }
953      ifelse     % newerror 
954      end
955      flush
956     } bind def     
957   /.printerror_long                     % long error printout,
958                                         % $error is on the dict stack
959    {    % Push the (anonymous) stack printing procedure.
960         %  <heading> <==flag> <override-name> <stackname> proc
961        {
962          currentdict exch .knownget     % stackname defined in $error?
963          {
964            4 1 roll                     % stack: <stack> <head> <==flag> <over>
965            /errordict .systemvar exch .knownget % overridename defined?
966            { 
967              exch pop exch pop exec     % call override with <stack>
968            }
969            { 
970              exch print exch            % print heading. stack <==flag> <stack>
971              1 index not { () = } if
972              { 1 index { (\n    ) } { (   ) } ifelse print
973                dup type /dicttype eq
974                {
975                  (--dict:) print
976                  dup rcheck {
977                    dup length =only (/) print dup maxlength =only
978                    dup wcheck not { ((ro)) print } if
979                  } if
980                  /gcheck where {
981                    pop gcheck { ((G)) } { ((L)) } ifelse print
982                  } {
983                    pop
984                  } ifelse (--) print
985                }
986                {
987                  dup type /stringtype eq 2 index or
988                  { ==only } { =only } ifelse
989                } ifelse
990              } forall
991              pop
992            }
993            ifelse                       % overridden
994          }
995          { pop pop pop
996          }
997          ifelse                         % stack known
998        }
999
1000        (\nOperand stack:) OSTACKPRINT /.printostack /ostack 4 index exec
1001        (\nExecution stack:) ESTACKPRINT /.printestack /estack 4 index exec
1002        (\nBacktrace:) true /.printbacktrace /backtrace 4 index exec
1003        (\nDictionary stack:) false /.printdstack /dstack 4 index exec
1004        () =
1005        pop      % printing procedure
1006
1007        errorname /VMerror eq
1008         { (VM status:) print mark vmstatus
1009           counttomark { ( ) print counttomark -1 roll dup =only } repeat
1010           cleartomark () =
1011         } if
1012
1013        .languagelevel 2 ge
1014         { (Current allocation mode is ) print
1015           globalmode { (global\n) } { (local\n) } ifelse print
1016         } if
1017
1018        .oserrno dup 0 ne
1019         { (Last OS error: ) print
1020           errorname /VMerror ne
1021            { dup .oserrorstring { = pop } { = } ifelse }
1022            { = }
1023           ifelse
1024         }
1025         { pop
1026         }
1027        ifelse
1028
1029        position //null ne
1030         { (Current file position is ) print position = }
1031        if
1032
1033    } bind def
1034 % Define a procedure for clearing the error indication.
1035 /.clearerror
1036  { $error /newerror false put
1037    $error /errorname //null put
1038    $error /errorinfo //null put
1039    0 .setoserrno
1040  } bind def
1041
1042 % Define $error.  This must be in local VM.
1043 .currentglobal false .setglobal
1044 /$error 40 dict .forcedef       % $error is local, systemdict is global
1045                 % newerror, errorname, command, errorinfo,
1046                 % ostack, estack, dstack, recordstacks,
1047                 % binary, globalmode,
1048                 % .inerror, .nosetlocal, position,
1049                 % plus extra space for badly designed error handers.
1050 $error begin
1051   /newerror false def
1052   /recordstacks true def
1053   /binary false def
1054   /globalmode .currentglobal def
1055   /.inerror false def
1056   /.nosetlocal true def
1057   /position //null def
1058 end
1059 % Define errordict similarly.  It has one entry per error name,
1060 %   plus handleerror.  However, some astonishingly badly written PostScript
1061 %   files require it to have at least one empty slot.
1062 /errordict ErrorNames length 3 add dict
1063 .forcedef               % errordict is local, systemdict is global
1064 .setglobal              % contents of errordict are global
1065 errordict begin
1066   ErrorNames
1067    { mark 1 index systemdict /.errorhandler get /exec load .packtomark cvx def
1068    } forall
1069 % The handlers for interrupt and timeout are special; there is no
1070 % 'current object', so they push their own name.
1071    { /interrupt /timeout }
1072    { mark 1 index dup systemdict /.errorhandler get /exec load .packtomark cvx def
1073    } forall
1074 /handleerror    % this key is 'well known' and some PS may redefine it
1075  { /.printerror .systemvar exec
1076  } bind def
1077         % a private entry that we will always use under JOBSERVER mode
1078 /.GShandleerror
1079  { /.printerror .systemvar exec
1080  } bind def
1081  
1082 end
1083
1084 % Define the [write]==[only] procedures.
1085 /.dict 8 dict dup
1086 begin def
1087   /.cvp {1 index exch 1 .writecvp} bind def
1088   /.p {1 index exch writestring} bind def
1089   /.p1 {2 index exch writestring} bind def
1090   /.p2 {3 index exch writestring} bind def
1091   /.print
1092         { dup type .dict exch .knownget { exec } { .cvp } ifelse
1093         } bind def
1094   /arraytype
1095         {dup rcheck
1096           {() exch dup xcheck
1097             {({) .p2
1098              {exch .p1
1099               1 index exch .print pop ( )} forall
1100              (})}
1101             {([) .p2
1102              {exch .p1
1103               1 index exch .print pop ( )} forall
1104              (])}
1105            ifelse exch pop .p}
1106           {.cvp}
1107          ifelse} bind def
1108   /packedarraytype /arraytype load def
1109 {//.dict begin .print pop end}
1110   bind
1111 end
1112
1113 /write==only exch def
1114 /write== {1 index exch write==only (\n) writestring} bind def
1115 /==only { (%stdout) (w) file exch write==only } bind def
1116 /== {==only (\n) print} bind def
1117
1118 % Define [write]===[only], an extension that prints dictionaries
1119 % in readable form and doesn't truncate strings.
1120 /.dict /write==only load 0 get dup length 2 add dict .copydict dup
1121 begin def
1122   /dicttype
1123         { dup rcheck
1124            { (<< ) .p1
1125               { 2 index 3 -1 roll .print pop ( ) .p1
1126                 1 index exch .print pop ( ) .p
1127               }
1128              forall (>>) .p
1129            }
1130            { .cvp
1131            }
1132           ifelse
1133         } bind def
1134   /stringtype
1135         { 1 index exch 2 .writecvp
1136         } bind def
1137
1138 {//.dict begin .print pop end}
1139   bind
1140 end
1141
1142 /write===only exch def
1143 /write=== {1 index exch write===only (\n) writestring} bind def
1144 /===only { (%stdout) (w) file exch write===only } bind def
1145 /=== { ===only (\n) print } bind def
1146
1147 % Create the initialization queue.
1148
1149 /.delayed_init_queue 10 dict def
1150
1151 /.schedule_init   %   <priority> <proc> .schedule_init -
1152 {
1153   //.delayed_init_queue 2 index known {
1154     (.delayed_init_queue priority conflict with ) print 1 index =
1155     /.schedule_init cvx /configurationerror signalerror
1156   } if
1157   //.delayed_init_queue 3 1 roll .growput
1158 } bind def
1159
1160 /.execute_schedulled_inits %   - .execute_schedulled_inits -
1161 {
1162   { 0 //null //.delayed_init_queue {     % maxp {} p {}
1163       3 index 2 index lt {
1164         4 2 roll
1165       } if
1166       pop pop
1167     } forall
1168     exch //.delayed_init_queue exch undef
1169     dup //null eq {
1170       pop exit
1171     } if
1172     exec
1173   } loop
1174 } bind def
1175
1176 (END PROCS) VMDEBUG
1177
1178 % Define the font directory.
1179 /FontDirectory false .setglobal 100 dict true .setglobal
1180 .forcedef               % FontDirectory is local, systemdict is global
1181
1182 % Define the encoding dictionary.
1183 /EncodingDirectory 16 dict def  % enough for Level 2 + PDF standard encodings
1184
1185 % Define .findencoding.  (This is redefined in Level 2.)
1186 /.findencoding
1187  { //EncodingDirectory exch get exec
1188  } bind def
1189 /.defineencoding
1190  { //EncodingDirectory 3 1 roll put
1191  } bind def
1192 % If we've got the composite font extensions, define findencoding.
1193 % To satisfy the Genoa FTS, findencoding must be a procedure, not an operator.
1194 /rootfont where { pop /findencoding { .findencoding } def } if
1195
1196 % Define .registerencoding.
1197 % NOTE: This procedure no longer does anything, but it must continue to
1198 % exist for the sake of toolbin/encs2c.ps.
1199 /.registerencoding {    % <index> <array> .registerencoding -
1200   pop pop
1201 } bind odef
1202
1203 % Load StandardEncoding.
1204 %% Replace 1 (gs_std_e.ps)
1205 (gs_std_e.ps) dup runlibfile VMDEBUG
1206
1207 % Load ISOLatin1Encoding.
1208 %% Replace 1 (gs_il1_e.ps)
1209 (gs_il1_e.ps) dup runlibfile VMDEBUG
1210
1211 % Define stubs for the Symbol and Dingbats encodings.
1212 % Note that the first element of the procedure must be the file name,
1213 % since gs_lev2.ps extracts it to set up the Encoding resource category.
1214
1215   /SymbolEncoding { /SymbolEncoding .findencoding } bind def
1216 %% Replace 3 (gs_sym_e.ps)
1217   EncodingDirectory /SymbolEncoding
1218    { (gs_sym_e.ps) //systemdict begin runlibfile SymbolEncoding end }
1219   bind put
1220
1221   /DingbatsEncoding { /DingbatsEncoding .findencoding } bind def
1222 %% Replace 3 (gs_dbt_e.ps)
1223   EncodingDirectory /DingbatsEncoding
1224    { (gs_dbt_e.ps) //systemdict begin runlibfile DingbatsEncoding end }
1225   bind put
1226
1227 (END FONTDIR/ENCS) VMDEBUG
1228
1229 % Construct a dictionary of all available devices.
1230 % These are (read-only) device prototypes that can't be
1231 % installed or have their parameters changed.  For this reason,
1232 % the value in the dictionary is actually a 2-element writable array,
1233 % to allow us to create a default instance of the prototype on demand.
1234
1235         % Loop until the .getdevice gets a rangecheck.
1236 errordict /rangecheck 2 copy get
1237 errordict /rangecheck { pop stop } put  % pop the command
1238   0 { {dup .getdevice exch 1 add} loop} .internalstopped pop
1239   1 add dict  /devicedict 1 index def
1240   begin                 % 2nd copy of count is on stack
1241    { dup .devicename exch
1242      dup wcheck { dup } { //null } ifelse 2 array astore def
1243    } repeat
1244   end
1245 put             % errordict /rangecheck
1246 .clearerror
1247 /devicenames devicedict { pop } forall devicedict length packedarray def
1248
1249 % Determine the default device.
1250 /defaultdevice DISPLAYING
1251  { systemdict /DEVICE .knownget
1252     { devicedict 1 index known not
1253        { (Unknown device: ) print =
1254          flush /defaultdevice cvx 1 .quit
1255        }
1256       if
1257     }
1258     { 0 .getdevice .devicename
1259     }
1260    ifelse
1261  }
1262  { /nullpage
1263  }
1264 ifelse
1265 /.defaultdevicename 1 index def
1266 finddevice      % make a copy
1267 def
1268 devicedict /Default devicedict .defaultdevicename get put
1269
1270 (END DEVS) VMDEBUG
1271
1272 % Define statusdict, for the benefit of programs
1273 % that think they are running on a LaserWriter or similar printer.
1274 %% Replace 1 (gs_statd.ps)
1275 (gs_statd.ps) runlibfile
1276
1277 (END STATD) VMDEBUG
1278
1279 % Load the standard font environment.
1280 %% Replace 1 (gs_fonts.ps)
1281 (gs_fonts.ps) runlibfile
1282
1283 (END GS_FONTS) VMDEBUG
1284
1285 % Define the default halftone screen and BG/UCR functions now, so that
1286 % it will bind in the original definitions of set[color]screen.
1287 % We make this a procedure so we can call it again when switching devices.
1288
1289 % Use an ordered dither for low-resolution devices.
1290 /.setloreshalftone {    % <dpi> .setloreshalftone -
1291         % The following 'ordered dither' spot function was contributed by
1292         % Gregg Townsend.  Thanks, Gregg!
1293    16.001 div 0                 % not 16: avoids rounding problems
1294     { 1 add 7.9999 mul cvi exch 1 add 7.9999 mul cvi 16 mul add <
1295         0E 8E 2E AE 06 86 26 A6 0C 8C 2C AC 04 84 24 A4
1296         CE 4E EE 6E C6 46 E6 66 CC 4C EC 6C C4 44 E4 64
1297         3E BE 1E 9E 36 B6 16 96 3C BC 1C 9C 34 B4 14 94
1298         FE 7E DE 5E F6 76 D6 56 FC 7C DC 5C F4 74 D4 54
1299         01 81 21 A1 09 89 29 A9 03 83 23 A3 0B 8B 2B AB
1300         C1 41 E1 61 C9 49 E9 69 C3 43 E3 63 CB 4B EB 6B
1301         31 B1 11 91 39 B9 19 99 33 B3 13 93 3B BB 1B 9B
1302         F1 71 D1 51 F9 79 D9 59 F3 73 D3 53 FB 7B DB 5B
1303         0D 8D 2D AD 05 85 25 A5 0F 8F 2F AF 07 87 27 A7
1304         CD 4D ED 6D C5 45 E5 65 CF 4F EF 6F C7 47 E7 67
1305         3D BD 1D 9D 35 B5 15 95 3F BF 1F 9F 37 B7 17 97
1306         FD 7D DD 5D F5 75 D5 55 FF 7F DF 5F F7 77 D7 57
1307         02 82 22 A2 0A 8A 2A AA 00 80 20 A0 08 88 28 A8
1308         C2 42 E2 62 CA 4A EA 6A C0 40 E0 60 C8 48 E8 68
1309         32 B2 12 92 3A BA 1A 9A 30 B0 10 90 38 B8 18 98
1310         F2 72 D2 52 FA 7A DA 5A F0 70 D0 50 F8 78 D8 58
1311      > exch get 256 div
1312     }
1313    bind
1314                 % Use correct, per-plane screens for CMYK devices only.
1315    //systemdict /setcolorscreen known processcolors 4 eq and
1316     { 3 copy 6 copy //setcolorscreen }
1317     { //setscreen }
1318    ifelse
1319 } bind def
1320 /.setloresscreen {      % <dpi> .setloresscreen -
1321   .setloreshalftone
1322   0 array cvx settransfer       % Genoa CET won't accept a packed array!
1323   /setstrokeadjust where { pop true setstrokeadjust } if
1324 } bind def
1325 % Use a 45-degree spot screen for high-resolution devices.
1326 /.sethireshalftone {    % <dpi> .sethireshalftone <doscreen>
1327         % According to information published by Hewlett-Packard,
1328         % they use a 60 line screen on 300 DPI printers and
1329         % an 85 line screen on 600 DPI printers.
1330         % However, we use a 106 line screen, which produces smoother-
1331         % looking shades but fewer of them (32 vs. 50).
1332         % 46 was suggested as a good frequency value for printers
1333         % between 200 and 400 DPI, so we use it for lower resolutions.
1334         % Imagesetters need even higher frequency screens.
1335    //systemdict /DITHERPPI known
1336     { DITHERPPI
1337     }
1338     { dup cvi 100 idiv 15 .min
1339        {//null 46 46 60 60 60 106 106 106 106 133 133 133 133 133 150}
1340       exch get
1341      }
1342    ifelse
1343    1 index 4.01 div .min        % at least a 4x4 cell
1344    45
1345         % The following screen algorithm is used by permission of the author.
1346     { 1 add 180 mul cos 1 0.08 add mul exch 2 add 180 mul cos 
1347       1 0.08 sub mul add 2 div % (C) 1989 Berthold K.P. Horn
1348     }
1349    bind
1350         % Determine whether we have lots of process colors.
1351         % If so, don't bother with color screening or gamma correction.
1352         % Also don't do gamma correction on very high-resolution devices.
1353         % (This should depend on dot gain, not resolution, but we don't
1354         % currently have a way to determine this.) Ignore missing components
1355         % (*Values = 1).
1356    currentdevice mark
1357      /RedValues 0 /GreenValues 0 /BlueValues 0 /GrayValues 0
1358    .dicttomark .getdeviceparams
1359    counttomark 2 idiv 1 sub
1360     { exch pop dup 1 le
1361        { pop }
1362        { exch dup 1 le
1363           { pop }
1364           { .min }
1365         ifelse
1366        }
1367       ifelse
1368     }
1369    repeat
1370    exch pop exch pop 32 lt 4 index 800 lt and 5 1 roll
1371         % Stack: doscreen dpi freq angle proc
1372         % Ghostscript currently doesn't use correct, per-plane halftones
1373         % unless setcolorscreen has been executed.  Since these are
1374         % computationally much more expensive than binary halftones,
1375         % we check to make sure they are really warranted, i.e., we have
1376         % a high-resolution CMYK device (i.e., not a display) with
1377         % fewer than 5 bits per plane (i.e., not a true-color device).
1378    4 -1 roll 150 ge
1379     { /setcolorscreen where
1380        { pop //systemdict /COLORSCREEN known
1381           { COLORSCREEN }
1382           { 3 index }
1383          ifelse
1384          dup false ne
1385           { 4 1 roll 3 copy 6 copy 13 -1 roll
1386         % For really high-quality screening on printers, we need to
1387         % give each plane its own screen angle.  Unfortunately,
1388         % this currently has very large space and time costs.
1389             true eq             % true => different angles,
1390                                 % 0 => same angles
1391              { { 45 90 15 75 } { 3 1 roll exch pop 12 3 roll } forall
1392              }
1393             if //setcolorscreen
1394           }
1395           { pop //setscreen     % false => single binary screen
1396           }
1397          ifelse
1398        }
1399        { //setscreen            % setcolorscreen not known
1400        }
1401       ifelse
1402     }
1403     { //setscreen                       % not high resolution
1404     }
1405    ifelse
1406 } bind def
1407 /.sethiresscreen {      % <dpi> .sethiresscreen 
1408   .sethireshalftone     % pushes true if a screen halftone used
1409                         % Stack: doscree
1410   {
1411     % Set the transfer function to lighten up the grays.
1412     % Parameter values closer to 1 are better for devices with
1413     % less dot spreading; lower values are better with more spreading.
1414     % The value 0.8 is a compromise that will probably please no one!
1415     %
1416     % Because of a bug in FrameMaker, we have to accept operands
1417     % outside the valid range of [0..1].
1418     {
1419       dup dup 0.0 gt exch 1.0 lt and
1420       {
1421         0.8 exp
1422       }
1423       if
1424     }
1425   }
1426   {
1427      % Set the transfer function to the identity.
1428      0 array cvx     % Genoa CET won't accept a packed array!
1429   }
1430   ifelse
1431   settransfer
1432   /setstrokeadjust where
1433   { pop false setstrokeadjust }
1434   if
1435
1436   % Increase fill adjustment so that we effectively use Adobe's
1437   % any-part-of-pixel rule.
1438   0.5 .setfilladjust
1439 } bind def
1440 % Set the default screen and BG/UCR.
1441 /.setdefaultbgucr {
1442   systemdict /setblackgeneration known {
1443     { pop 0 } dup setblackgeneration setundercolorremoval
1444   } if
1445 } bind def
1446 /.useloresscreen {      % - .useloresscreen <bool>
1447         % Compute min(|dpi x|,|dpi y|) as the definition of the resolution.
1448   72 72 matrix defaultmatrix dtransform abs exch abs .min
1449   dup 150 lt //systemdict /DITHERPPI known not and
1450 } bind def
1451
1452 % The following implementation uses LL2 extensions, but only in stopped
1453 % contexts so that with LL1, the .set??reshalftone will be used.
1454 %
1455 %       - .getdefaulthalftone <halftonedict> true       if default found
1456 %                             false                     
1457 /.getdefaulthalftone {
1458   % try the device to see if it has a default halftone
1459   { currentdevice /HalftoneDefault gsgetdeviceprop } .internalstopped
1460   { pop pop false }             % no device property
1461   { dup type /dicttype eq { true } { pop false } ifelse }
1462   ifelse
1463   % stack: <halftonedict> true    if default found
1464   %         false                 not found
1465   dup not
1466   { % device did not provide a default, try Resource
1467     pop { /Default /Halftone /findresource .systemvar exec } .internalstopped 
1468     { pop pop false } { true } ifelse
1469   }
1470   if
1471 } bind def
1472
1473 /.setdefaulthalftone {
1474   .getdefaulthalftone 
1475   { sethalftone }
1476   { % default not found
1477     .useloresscreen { .setloreshalftone } { .sethireshalftone pop } ifelse
1478   }
1479   ifelse
1480 } bind def
1481
1482 /.setdefaultscreen {
1483   .useloresscreen { .setloresscreen } { .sethiresscreen } ifelse
1484   .setdefaultbgucr
1485 } bind def
1486
1487 % Load basic color support
1488 %% Replace 1 (gs_cspace.ps)
1489 (gs_cspace.ps) runlibfile
1490
1491 (END BASIC COLOR) VMDEBUG
1492
1493 %% Replace 1 (gs_devcs.ps)
1494 (gs_devcs.ps) runlibfile
1495
1496 (END LEVEL 1 COLOR) VMDEBUG
1497
1498 % Load image support
1499 %% Replace 1 (gs_img.ps)
1500 (gs_img.ps) runlibfile
1501
1502 (END IMAGE) VMDEBUG
1503
1504 % Auxiliary procedures for generating file name templates.
1505
1506 % Convert a path name into a string suitable for filenameforall
1507 % For example: (a\\b*?c) to (a\\\\b\\*\\?c)
1508 /.makepathtemplate {    % str1 -- str2
1509    dup length dup add string 0  % result string up to twice the size
1510    0 1 4 index length 1 sub {
1511      3 index exch get
1512      dup 92 eq {                % \ -> \\
1513         2 index 2 index 92
1514         put
1515         exch 1 add exch
1516      } 
1517      if
1518      dup 42 eq {                % * -> \*
1519         2 index 2 index 92
1520         put
1521         exch 1 add exch
1522      } 
1523      if
1524      dup 63 eq {                % ? -> \?
1525         2 index 2 index 92
1526         put
1527         exch 1 add exch
1528      } 
1529      if
1530      2 index 2 index 3 -1 roll put 1 add
1531    } for
1532    0 exch getinterval exch pop
1533 } bind def
1534
1535 %   <dir_list> <template> .generate_dir_list_templates <t1> ... <tN>
1536 %
1537 % Generates various valid templates combining a directory list with a given template.
1538 %
1539 % Example1 (DOS, Windows) :
1540 %       [(/gs/lib) (/gs/Resource/) (\gs8.00\Resource)] (*/*) -->
1541 %       (/gs/lib/*/*) (/gs/Resource/*/*) (\\gs8.00\\Resource/*/*)
1542 %
1543 % Example2 (OpenVMS) :
1544 %       [(gs:[lib]) (gs:[Resource]) (gs800:[Resource)] (*]*) -->
1545 %       ((gs:[lib.*]*) [gs:[Resource.*]*) ([gs800:[Resource.*]*)
1546 %
1547 /.generate_dir_list_templates
1548 {                                                  % [dl] (templ)
1549   % We need to convert paths into templates,
1550   % because it can include '\' on DOS.
1551   % In same time, the <template> must not convert,
1552   % because it is already a template.
1553   % Besides that, we cannot combine template using .file_name_combine,
1554   % because template syntax breaks the platform path syntax.
1555   % To resolve this, we first convert the <template> into 
1556   % a fake filename, and combine it with path,
1557   % obtaining a correct separator. Then we replace
1558   % the fake file name with the given template.
1559   %
1560
1561   % Create the fake file name :
1562   dup dup length string copy                       % [dl] (templ) (ffn)
1563   (*) 0 get (?) 0 get (\\) 0 get (x) 0 get 0 0     % [dl] (templ) (ffn) * ? \ x i j
1564   { 1 index 7 index length ge { exit } if
1565     6 index 2 index get                            % [dl] (templ) (ffn) * ? \ x i j c
1566     dup 7 index eq                                 % [dl] (templ) (ffn) * ? \ x i j c bool
1567     1 index 7 index eq or { % *?
1568       pop 2 index
1569     } if                                           % [dl] (templ) (ffn) * ? \ x i j C
1570     dup 5 index eq {        % \
1571       3 2 roll 1 add 3 1 roll                      % [dl] (templ) (ffn) * ? \ x i' j C
1572       2 index 8 index length ge { pop exit } if
1573       pop 6 index 2 index get                      % [dl] (templ) (ffn) * ? \ x i' j C'
1574     } if
1575     7 index 2 index 3 2 roll put                   % [dl] (templ) (ffn) * ? \ x i' j
1576     1 add exch 1 add exch                          % [dl] (templ) (ffn) * ? \ x i'' j'
1577   } loop                                           % [dl] (templ) (ffn) * ? \ x i j
1578   6 1 roll pop                                     % [dl] (templ) (ffn) j * ? \ x
1579   exch pop exch pop exch pop exch                  % [dl] (templ) (ffn) x j
1580   { dup 3 index length ge { exit } if
1581     3 copy exch put
1582     1 add
1583   } loop
1584   pop pop                                          % [dl] (templ) (ffn)
1585
1586   % An internal procedure : 
1587   {                                 % {} [dl] (templ) (ffn) (dffn)
1588     .makepathtemplate               % {} [dl] (templ) (ffn) (Dffn)
1589     dup                             % {} [dl] (templ) (ffn) (Dffn) (Dffn)
1590     3 index length dup              % {} [dl] (templ) (ffn) (Dffn) (Dffn) templL templL
1591     2 index length                  % {} [dl] (templ) (ffn) (Dffn) (Dffn) templL templL DffnL
1592     exch sub                        % {} [dl] (templ) (ffn) (Dffn) (Dffn) templL i
1593     exch getinterval                % {} [dl] (templ) (ffn) (Dffn) (suffix)
1594     3 index exch copy pop           % {} [dl] (templ) (ffn) (dt)
1595     5 1 roll                        % (dt) {} [dl] (templ) (ffn)
1596   }
1597   4 1 roll                                         % {} [dl] (templ) (ffn)
1598
1599   % Generate templates :
1600   dup .file_name_is_absolute {
1601     dup                                            % {} [dl] (templ) (ffn) (ffn)
1602     4 index exec                                   % (t1) {} [dl] (templ) (ffn)
1603   } {
1604     2 index {                                      % {} [dl] (templ) (ffn) (d)
1605       1 index                                      % {} [dl] (templ) (ffn) (d) (ffn)
1606       false .file_name_combine {                   % {} [dl] (templ) (ffn) (dffn)
1607         4 index exec                               % (t1) {} [dl] (templ) (ffn)
1608       } {                                          % {} [dl] (templ) (ffn) (d) (ffn)
1609         pop pop                                    % {} [dl] (templ) (ffn)
1610       } ifelse
1611     } forall
1612   } ifelse                                         % (t1) (t2) ... (tN) {} [dl] (templ) (ffn)
1613   pop pop pop pop                                  % (t1) (t2) ... (tN)
1614 } bind def
1615
1616 % Load the initialization files for optional features.
1617 %% Replace 4 INITFILES
1618 systemdict /INITFILES known
1619  { INITFILES { dup runlibfile VMDEBUG } forall
1620  }
1621 if
1622
1623 % If Level 2 (or higher) functionality is implemented, enable it now.
1624 /.setlanguagelevel where {
1625   pop 2 .setlanguagelevel
1626         % If the resource machinery is loaded, fix up some things now.
1627   /.fixresources where { pop .fixresources } if
1628 } if
1629 /ll3dict where {
1630   pop 3 .setlanguagelevel
1631 } if
1632
1633 (END INITFILES) VMDEBUG
1634
1635 %% Replace 1 (gs_stres.ps)
1636 (gs_stres.ps) dup runlibfile VMDEBUG
1637 (END STATIC RESOURCES) VMDEBUG
1638
1639 % Create a null font.  This is the initial font.
1640 8 dict dup begin
1641   /FontMatrix [ 1 0 0 1 0 0 ] readonly def
1642   /FontType 3 def
1643   /FontName () def
1644   /Encoding StandardEncoding def
1645   /FontBBox { 0 0 0 0 } readonly def % executable is bogus, but customary ...
1646   /BuildChar { pop pop 0 0 setcharwidth } bind def
1647   /PaintType 0 def              % shouldn't be needed!
1648 end
1649 /NullFont exch definefont setfont
1650
1651 % Define NullFont as the font.
1652 /NullFont currentfont def
1653
1654 % Load initial fonts from FONTPATH directories, Fontmap file,
1655 % and/or .getccfont as appropriate.
1656 .loadinitialfonts
1657
1658 % Remove NullFont from FontDirectory, so it can't be accessed by mistake.
1659 /undefinefont where {
1660   pop /NullFont undefinefont
1661 } {
1662   FontDirectory /NullFont .undef
1663 } ifelse
1664
1665 (END FONTS) VMDEBUG
1666
1667 % Restore the real definition of runlibfile.
1668 /runlibfile /.runlibfile load def
1669 currentdict /.runlibfile .undef
1670
1671 % Bind all the operators defined as procedures.
1672 /.bindoperators         % binds operators in currentdict
1673  { % Temporarily disable the typecheck error.
1674    errordict /typecheck 2 copy get
1675    errordict /typecheck { pop } put     % pop the command
1676    currentdict
1677     { dup type /operatortype eq
1678        { % This might be a real operator, so bind might cause a typecheck,
1679          % but we've made the error a no-op temporarily.
1680          .bind          % do a real bind even if NOBIND is set
1681        }
1682       if pop pop
1683     } forall
1684    put
1685  } def
1686 NOBIND DELAYBIND or not { .bindoperators } if
1687
1688 % Establish a default environment.
1689
1690 defaultdevice
1691 % The following line used to skip setting of page size and resolution if
1692 % NODISPLAY was selected.  We think this was only to save time and memory,
1693 % and it is a bad idea because it prevents setting the resolution in this
1694 % situation, which pstoedit (among other programs) relies on.
1695 %DISPLAYING not { setdevice (%END DISPLAYING) .skipeof } if
1696
1697 % If the paper size is not specifed and the device defaults to 
1698 % letter or A4 paper, select the DEFAULTPAPERSIZE.
1699 systemdict /DEFAULTPAPERSIZE known
1700 systemdict /PAPERSIZE known not and
1701 systemdict /DEVICEWIDTH known not and
1702 systemdict /DEVICEHEIGHT known not and
1703 systemdict /DEVICEWIDTHPOINTS known not and
1704 systemdict /DEVICEHEIGHTPOINTS known not and
1705  {
1706    defaultdevice mark /PageSize //null .dicttomark .getdeviceparams 
1707    .dicttomark /PageSize get
1708    dup 0 get 0.5 add cvi 612 eq 1 index 1 get 0.5 add cvi 792 eq and
1709    1 index 0 get 0.5 add cvi 595 eq 2 index 1 get 0.5 add cvi 842 eq and
1710    or exch pop
1711    {
1712      % the default paper size was letter, so replace it with DEFAULTPAPERSIZE
1713      /PAPERSIZE DEFAULTPAPERSIZE def
1714    } if
1715  }
1716 if
1717
1718 systemdict /DEVICEWIDTH known
1719 systemdict /DEVICEHEIGHT known or
1720 systemdict /DEVICEWIDTHPOINTS known or
1721 systemdict /DEVICEHEIGHTPOINTS known or
1722 systemdict /DEVICEXRESOLUTION known or
1723 systemdict /DEVICEYRESOLUTION known or
1724 systemdict /PAPERSIZE known or
1725 not { (%END DEVICE) .skipeof } if
1726 % Let DEVICE{WIDTH,HEIGHT}[POINTS] override PAPERSIZE.
1727 systemdict /PAPERSIZE known
1728 systemdict /DEVICEWIDTH known not and
1729 systemdict /DEVICEHEIGHT known not and
1730 systemdict /DEVICEWIDTHPOINTS known not and
1731 systemdict /DEVICEHEIGHTPOINTS known not and
1732  {      % Convert the paper size to device dimensions.
1733    true statusdict /.pagetypenames get
1734     { PAPERSIZE eq
1735        { PAPERSIZE load
1736          dup 0 get /DEVICEWIDTHPOINTS exch def
1737          1 get /DEVICEHEIGHTPOINTS exch def
1738          pop false exit
1739        }
1740       if
1741     }
1742    forall
1743     { (Unknown paper size: ) print PAPERSIZE ==only (.) =
1744     }
1745    if
1746  }
1747 if
1748 % Adjust the device parameters per the command line.
1749 % It is possible to specify resolution, pixel size, and page size;
1750 % since any two of these determine the third, conflicts are possible.
1751 % We simply pass them to .setdeviceparams and let it sort things out.
1752    mark /HWResolution //null /HWSize //null /PageSize //null .dicttomark
1753    .getdeviceparams .dicttomark begin
1754    mark
1755         % Check for resolution.
1756    /DEVICEXRESOLUTION where dup
1757     { exch pop HWResolution 0 DEVICEXRESOLUTION put }
1758    if
1759    /DEVICEYRESOLUTION where dup
1760     { exch pop HWResolution 1 DEVICEYRESOLUTION put }
1761    if
1762    or { /HWResolution HWResolution } if
1763         % Check for device sizes specified in pixels.
1764    /DEVICEWIDTH where dup
1765     { exch pop HWSize 0 DEVICEWIDTH put }
1766    if
1767    /DEVICEHEIGHT where dup
1768     { exch pop HWSize 1 DEVICEHEIGHT put }
1769    if
1770    or { /HWSize HWSize } if
1771         % Check for device sizes specified in points.
1772    /DEVICEWIDTHPOINTS where dup
1773     { exch pop PageSize 0 DEVICEWIDTHPOINTS put }
1774    if
1775    /DEVICEHEIGHTPOINTS where dup
1776     { exch pop PageSize 1 DEVICEHEIGHTPOINTS put }
1777    if
1778    or { /PageSize PageSize } if
1779         % Check whether any parameters were set.
1780    dup mark eq { pop } { defaultdevice putdeviceprops } ifelse
1781    end
1782 %END DEVICE
1783 % Set any device properties defined on the command line.
1784 % If BufferSpace is defined but not MaxBitmap, set MaxBitmap to BufferSpace.
1785 systemdict /BufferSpace known
1786 systemdict /MaxBitmap known not and
1787  { systemdict /MaxBitmap BufferSpace put
1788  } if
1789 dup getdeviceprops
1790 counttomark 2 idiv
1791  { systemdict 2 index known
1792     { pop dup load counttomark 2 roll }
1793     { pop pop }
1794    ifelse
1795  } repeat
1796 counttomark dup 0 ne
1797  { 2 add -1 roll putdeviceprops }
1798  { pop pop }
1799 ifelse
1800 % If the initial device parameters are invalid, the setdevice may fail.
1801 % Trap this and produce a reasonable error message.
1802 { setdevice }           % does an erasepage
1803 INITDEBUG { exec false } { .internalstopped } ifelse {
1804   (**** Unable to open the initial device, quitting.) = flush 1 .quit
1805 } if
1806
1807 % If the media size is fixed, update the current page device dictionary.
1808 FIXEDMEDIA
1809 dup { pop systemdict /.currentpagedevice known } if
1810 dup { pop .currentpagedevice exch pop } if
1811 not { (%END MEDIA) .skipeof } if
1812 currentpagedevice dup length dict .copydict
1813 dup /Policies
1814         % Stack: <pagedevice> <pagedevice> /Policies
1815 1 index /InputAttributes
1816 2 copy get dup length dict .copydict
1817         % Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
1818         %   /InputAttributes <inputattrs'>
1819 dup 0 2 copy get dup length dict .copydict
1820         % Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
1821         %   /InputAttributes <inputattrs'> <inputattrs'> 0 <attrs0'>
1822 dup /PageSize 7 index /PageSize get
1823 put                             % PageSize in 0
1824 put                             % 0 in InputAttributes
1825 put                             % InputAttributes in pagedevice
1826 % Also change the page size policy so we don't get an error.
1827         % Stack: <pagedevice> <pagedevice> /Policies
1828 2 copy get dup length dict .copydict
1829         % Stack: <pagedevice> <pagedevice> /Policies <policies'>
1830 dup /PageSize 7 put             % PageSize in Policies
1831 put                             % Policies in pagedevice
1832 .setpagedevice
1833 %END MEDIA
1834
1835 % Set up the interpreter context version of -dUSeCIEColor option
1836 % so that .getuseciecolor has the correct value (see gs_setpd.ps)
1837 /setpagedevice where {
1838   pop systemdict /UseCIEColor known {
1839     mark /UseCIEColor UseCIEColor .dicttomark setpagedevice
1840   } if
1841 } if
1842
1843 %END DISPLAYING
1844
1845 (END DEVICE) VMDEBUG
1846
1847 % Establish a default upper limit in the character cache,
1848 % namely, enough room for a 18-point character at the resolution
1849 % of the default device, or for a character consuming 1% of the
1850 % maximum cache size, whichever is larger.
1851 mark
1852         % Compute limit based on character size.
1853   18 dup dtransform
1854   exch abs cvi 31 add 32 idiv 4 mul     % X raster
1855   exch abs cvi mul              % Y
1856         % Compute limit based on allocated space.
1857   cachestatus pop pop pop pop pop exch pop 0.01 mul cvi
1858   .max dup 10 idiv exch
1859 setcacheparams
1860 % Conditionally disable the character cache.
1861 NOCACHE { 0 setcachelimit } if
1862
1863 (END CONFIG) VMDEBUG
1864
1865 % Initialize graphics.
1866
1867 .setdefaultscreen
1868 initgraphics
1869
1870 % The interpreter relies on there being at least 2 entries
1871 % on the graphics stack.  Establish the second one now.
1872 gsave
1873
1874 % Define some control sequences as no-ops.
1875 % This is a hack to get around problems
1876 % in some common PostScript-generating applications.
1877 <04> cvn JOBSERVER {
1878     { { clear cleardictstack //false 0 .startnewjob } 2 .stop } bind
1879   } {
1880     { }
1881   } ifelse def
1882 <1b> cvn {                      % UEL is <esc>%-12345X and acts the same as ^D
1883   currentfile (%-12345X) .peekstring pop (%-12345X) eq <04> cvn load if
1884 } bind def
1885 <1b45> cvn { } def              % PJL reset prologue (ESC E)
1886 <1b451b> cvn <1b> cvn load def  % PJL reset epilogue (ESC E + UEL)
1887 (\001M) cvn                     % TBCP initiator
1888  { currentfile /TBCPDecode filter cvx exec
1889  } bind def
1890 /@PJL                           % H-P job control
1891  {
1892    % Windows 2000 driver includes PJL into %%BeginFeature block.
1893    % Identify this from the pattern on the stack: countdictstack lucas mark
1894    % and fail the feature request.
1895
1896    count 3 ge {
1897      dup mark eq {
1898        2 index countdictstack eq {
1899           1 index /lucas where { /lucas get eq } { pop false } ifelse {
1900             stop
1901          } if
1902        } if
1903      } if
1904    } if
1905    currentfile //=string readline pop pop
1906  } bind def
1907
1908 % Install the EPS handler if needed
1909 systemdict /EPSBoundingBoxInit known { EPSBoundingBoxInit } if
1910
1911 % If we want a "safer" system, disable some obvious ways to cause havoc.
1912 .currentglobal true .setglobal
1913 /SAFETY 2 dict
1914   dup /safe false put
1915   dup /tempfiles 10 dict readonly put
1916 readonly def
1917 .setglobal
1918
1919 /.locksafe {
1920   SAFETY /safe get not {
1921     <<
1922       /PermitFileReading [
1923         currentuserparams /PermitFileReading get aload pop
1924         /FONTPATH .systemvar (*) .generate_dir_list_templates
1925           % Library files : 
1926         /LIBPATH  .systemvar (*) .generate_dir_list_templates       
1927           % Resource files on OpenVMS requires a separate template (gs:[dir.*]*)
1928           % because the (gs:[dir]*) doesn't cover them.
1929         /LIBPATH  .systemvar (*) .file_name_separator (*)
1930           concatstrings concatstrings .generate_dir_list_templates
1931         .languagelevel 2 ge {
1932             % Default resources :
1933           [ currentsystemparams /GenericResourceDir get] (*) .generate_dir_list_templates
1934             % Default resources (OpenVMS, see comment above.) :
1935           [ currentsystemparams /GenericResourceDir get] (*) .file_name_separator (*)
1936             concatstrings concatstrings .generate_dir_list_templates
1937         } if
1938       ]
1939       /LockFilePermissions true
1940     >> setuserparams
1941   }
1942   if
1943   % setpagedevice has the side effect of clearing the page, but
1944   % we will just document that. Using setpagedevice keeps the device
1945   % properties and pagedevice .LockSafetyParams in agreement even
1946   % after a restore that changes the value to false.
1947   currentglobal currentpagedevice gcheck setglobal % use correct VM space
1948   << /.LockSafetyParams true >> setpagedevice
1949   setglobal
1950   //SAFETY /safe //true .forceput % overrides readonly
1951 } .bind executeonly odef
1952
1953 /.setsafe
1954 {
1955   SAFETY /safe get not {
1956     <<
1957       /PermitFileReading [ ]
1958       /PermitFileWriting [ (/fd/*) ]
1959       /PermitFileControl [ ]
1960     >> setuserparams
1961   }
1962   if
1963   .locksafe
1964 } .bind executeonly odef
1965
1966 /deletefile {
1967   count 1 lt {
1968     //deletefile /stackunderflow signalerror
1969   }
1970   if
1971   dup { deletefile } stopped {
1972     pop //deletefile $error /errorname get signalerror
1973   } {
1974     % deletefile succeeded. Remove from tempfile list if present
1975     //SAFETY /tempfiles get exch cvn 2 copy known {
1976       .forceundef
1977     } {
1978       pop pop
1979     }
1980     ifelse
1981   }
1982   ifelse
1983 } .bind executeonly odef
1984
1985 % If a file is opened with .tempfile with SAFER not (yet) set,
1986 % the file can be deleted later, even if SAFER is set.
1987 /.tempfile {
1988   .tempfile     % filename file
1989   //SAFETY /tempfiles get 2 index true .forceput
1990 } .bind executeonly odef
1991
1992 % If we are running in SAFER mode, lock things down
1993 SAFER { .setsafe } if
1994
1995 /UndefinePostScriptOperators {
1996   [
1997   /condition /currentcontext /detach /.fork /join /.localfork /lock /monitor /notify
1998   /wait /yield /.currentscreenphase /.setscreenphase /.image2 /eoviewclip /initviewclip
1999   /viewclip /viewclippath /defineusername
2000   /currentalpha /setalpha /.alphaimage /composite /compositerect /dissolve /sizeimagebox /.sizeimageparams
2001   ]
2002   {systemdict exch .forceundef} forall
2003   //systemdict /UndefinePostScriptOperators .forceundef
2004 } bind def
2005
2006 % If we delayed binding, make it possible to do it later.
2007 /.bindnow {
2008   currentuserparams /IdiomRecognition .knownget {
2009     1 dict dup /IdiomRecognition //false put setuserparams
2010   } if
2011   //systemdict begin .bindoperators end
2012   % Temporarily disable the typecheck error.
2013   errordict /typecheck 2 copy get
2014   errordict /typecheck { pop } put      % pop the command
2015   0 1 .delaycount 1 sub { .delaybind exch get .bind pop } for
2016   //systemdict /.delaybind {} .forceput % reclaim the space
2017   //systemdict /.bindnow .forceundef    % ditto
2018   put
2019   //systemdict /UndefinePostScriptOperators get exec
2020   //systemdict /.forcedef .forceundef           % remove temptation
2021   //systemdict /.forceput .forceundef           % ditto
2022   //systemdict /.forceundef .forceundef         % ditto
2023   currentuserparams /IdiomRecognition known {
2024     1 dict dup /IdiomRecognition 4 -1 roll put setuserparams
2025   } if
2026 } .bind odef
2027
2028 % Turn off array packing, since some PostScript code assumes that
2029 % procedures are writable.
2030 false setpacking
2031
2032 (END INIT) VMDEBUG
2033
2034 /.currentuserparams where {
2035   pop
2036         % Remove real user params from psuserparams.
2037   mark .currentuserparams counttomark 2 idiv {
2038     pop psuserparams exch undef
2039   } repeat pop
2040         % Update the copy of the user parameters.
2041   mark .currentuserparams counttomark 2 idiv {
2042     userparams 3 1 roll .forceput       % userparams is read-only
2043   } repeat pop
2044         % Turn on idiom recognition, if available.
2045   currentuserparams /IdiomRecognition known {
2046     /IdiomRecognition true .definepsuserparam
2047   } if
2048   psuserparams readonly pop
2049   systemdict /.definepsuserparam undef
2050         % Save a copy of userparams for use with save/restore
2051         % (and, if implemented, context switching).
2052   .currentglobal false .setglobal
2053      mark userparams { } forall .dicttomark readonly
2054      /userparams exch .forcedef         % systemdict is read-only
2055   .setglobal
2056 } if
2057 /.currentsystemparams where {
2058   pop
2059         % Remove real system params from pssystemparams.
2060   mark .currentsystemparams counttomark 2 idiv {
2061     pop pssystemparams exch .forceundef
2062   } repeat pop
2063 } if
2064
2065 % Set up AlignToPixels :
2066
2067 /AlignToPixels where {
2068   mark /AlignToPixels 2 index /AlignToPixels get .dicttomark setuserparams
2069   /AlignToPixels undef
2070 } if
2071
2072 % Set up GridFitTT :
2073
2074 /GridFitTT where {
2075   mark /GridFitTT 2 index /GridFitTT get .dicttomark setuserparams
2076   /GridFitTT undef
2077 } if
2078
2079 % Conditionally turn image interpolation on or off.
2080 currentdict /INTERPOLATE known not { (%END INTERPOLATE) .skipeof } if
2081
2082 /.interpolate {
2083   dup /Interpolate .knownget not { //false } if
2084   /INTERPOLATE .systemvar ne {
2085     dup gcheck .currentglobal exch .setglobal
2086     exch dup length dict copy
2087     dup /Interpolate /INTERPOLATE .systemvar put
2088     exch .setglobal
2089   } if
2090 } bind odef
2091
2092 /colorimage
2093   { /INTERPOLATE .systemvar
2094       { .currentglobal                    % w h bit [] {}...{} multi ncomp glob
2095         //false .setglobal
2096         9 dict begin                      % w h bit [] {}...{} multi ncomp glob
2097         2 index { 1 index 7 add } { 8 } ifelse
2098         copy gsave pop                    % preserve the arguments
2099         { 0 /DeviceGray 0 /DeviceRGB /DeviceCMYK }
2100         1 index get setcolorspace         % ... glob w h bit [] {}...{} multi ncomp
2101         {0 1 0 1 0 1 0 1}
2102         1 index 2 mul 0 exch              % ... glob w h bit [] {}...{} multi ncomp {0 1 ...} 0 2*ncomp
2103         getinterval /Decode exch def      % ... glob w h bit [] {}...{} multi ncomp
2104         exch dup                          % ... glob w h bit [] {}...{} ncomp multi multi
2105         /MultipleDataSources exch def     % ... glob w h bit [] {}...{} ncomp multi
2106         { array astore} { pop } ifelse    % ... glob w h bit [] [{}...{}]
2107         /DataSource exch def              % ... glob w h bit []
2108         /ImageMatrix exch def             % ... glob w h bit
2109         /BitsPerComponent exch def        % ... glob w h
2110         /Height exch def                  % ... glob w
2111         /Width exch def                   % ... glob 
2112         /ImageType 1 def
2113         /Interpolate //true def
2114         .setglobal currentdict end        % ... <<>>
2115         image grestore
2116         exch { 4 add } { 6 } ifelse
2117         { pop } repeat                    % -
2118       }
2119       { colorimage
2120       }
2121     ifelse
2122   } bind odef
2123
2124 /image
2125   { dup type /dicttype eq
2126       { dup /ImageType get 3 eq
2127           { .currentglobal //false .setglobal exch
2128             dup length dict copy begin .setglobal 
2129             /DataDict DataDict .interpolate def
2130             /MaskDict MaskDict .interpolate def
2131             currentdict end
2132           }
2133           { .interpolate 
2134           }
2135         ifelse
2136         image
2137       }
2138       { /INTERPOLATE .systemvar
2139           { .currentglobal //false .setglobal
2140             8 dict begin .setglobal
2141             /ImageType 1 def
2142             /DataSource 1 index def
2143             /ImageMatrix 2 index def
2144             /BitsPerComponent 3 index def
2145             /Decode {0 1} def
2146             /Height 4 index def
2147             /Width 5 index def
2148             /Interpolate //true def
2149             currentdict end
2150             gsave /DeviceGray setcolorspace image grestore
2151             5 { pop } repeat
2152           }
2153           { image
2154           }
2155         ifelse
2156       }
2157     ifelse
2158   } bind odef
2159
2160 /imagemask {
2161   dup type /dicttype eq {
2162     .interpolate imagemask
2163   } {
2164     /INTERPOLATE .systemvar {
2165       .currentglobal //false .setglobal
2166       8 dict begin .setglobal
2167       /ImageType 1 def
2168       /DataSource 1 index def
2169       /ImageMatrix 2 index def
2170       /BitsPerComponent 1 def
2171       2 index { {1 0} } { {0 1} } ifelse /Decode exch def
2172       /Height 4 index def
2173       /Width 5 index def
2174       /Interpolate //true def
2175       currentdict end imagemask 5 { pop } repeat
2176     } {
2177       imagemask
2178     } ifelse
2179   } ifelse
2180 } bind odef
2181
2182 currentdict /.interpolate undef
2183
2184 %END INTERPOLATE
2185
2186 % Establish local VM as the default.
2187 false /setglobal where { pop setglobal } { .setglobal } ifelse
2188 $error /.nosetlocal false put
2189
2190 (END GLOBAL) VMDEBUG
2191
2192 /.savelocalstate where {
2193         % If we might create new contexts, save away copies of all dictionaries
2194         % referenced from systemdict that are stored in local VM,
2195         % and also save a copy of the initial gstate.
2196   pop .savelocalstate
2197 } {
2198         % If we're *not* running in a multi-context system and FAKEFONTS is
2199         % defined, add the fake fonts to LocalFontDirectory.
2200   .definefakefonts      % current VM is local
2201 } ifelse
2202
2203 % Execude schedilled inits :
2204 //.execute_schedulled_inits exec
2205 currentdict /.execute_schedulled_inits undef
2206 currentdict /.delayed_init_queue undef
2207 currentdict /.delayed_init_queue undef
2208
2209 % Remove systemdict entries for things that have been bound in where used
2210 % and that shouldn't be accessible by name, and close up systemdict.
2211 currentdict /filterdict .undef
2212 currentdict /.cidfonttypes .undef
2213 currentdict /.colorrenderingtypes .undef
2214 currentdict /.formtypes .undef
2215 currentdict /.halftonetypes .undef
2216 currentdict /.imagetypes .undef
2217 currentdict /.imagemasktypes .undef
2218 currentdict /.patterntypes .undef
2219 currentdict /.shadingtypes .undef
2220 currentdict /.wheredict .undef
2221 end
2222
2223 % Clean up VM, and enable GC.
2224 /vmreclaim where
2225  { pop NOGC not { 2 vmreclaim 0 vmreclaim } if
2226  } if
2227 DELAYBIND not {
2228   systemdict /.forcedef .undef          % remove temptation
2229   systemdict /.forceput .undef          % ditto
2230   systemdict /.forceundef .undef        % ditto
2231 } if
2232 WRITESYSTEMDICT not { systemdict readonly pop } if
2233 (END GC) VMDEBUG
2234
2235 % The Adobe AGM_Core used by Illustrator 9 has some code that breaks
2236 % if the 'product' is not (Adobe PostScript Parser). A bug has been
2237 % submitted to Adobe since this also fails with Acrobat Distiller.
2238 % As a temporary work around, the following HACK will work for
2239 % devices without spot color support. Once Ghostscript can
2240 % support DeviceN and spot color separations this will need to
2241 % be 'true' in some cases.
2242 userdict /AGM_preserve_spots false put
2243
2244 % Start the job as encapsulated if requested, if not, perform an
2245 % outer save so that jobs which depend on global VM not being
2246 % restored will operate correctly.
2247
2248 % Note that .setsafe is already in effect if in SAFER mode.
2249 % so an exitserver will restore with SAFER mode still in effect.
2250 JOBSERVER
2251   { false 0 .startnewjob }
2252   { NOOUTERSAVE not { save pop } if }   % do the outermost save unless disabled
2253 ifelse
2254
2255 % The interpreter will run the initial procedure (start).