1 % Copyright (C) 1989-2004 artofcode LLC. All rights reserved.
3 % This software is provided AS-IS with no warranty, either express or
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.
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.
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.
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.
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.
30 % Check the interpreter revision. NOTE: the interpreter code requires
31 % that the first non-comment token in this file be an integer.
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
40 % Acquire userdict, and set its length if necessary.
42 { pop userdict maxlength 0 eq }
46 { % userdict wasn't already set up by iinit.c.
48 currentdict dup 200 .setmaxlength % userdict
49 .forceput % userdict is local, systemdict is global
53 % Define dummy local/global operators if needed.
54 systemdict /.setglobal known
57 { /.setglobal { pop } bind def
58 /.currentglobal { false } bind def
59 /.gcheck { pop false } bind def
63 % Define .languagelevel if needed.
64 systemdict /.languagelevel known not { /.languagelevel 1 def } if
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
75 % /DEFAULTPAPERSIZE (a4) def
77 % Turn on array packing for the rest of initialization.
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.
85 % Acquire the debugging flags.
86 currentdict /DEBUG known /DEBUG exch def
88 % if DEBUG is set, set ALL of the subset debugging flags
89 mark % '[' isn't defined yet
90 /CCFONTDEBUG % Compiled Fonts
93 /DOCIEDEBUG % CIE color
94 /EPSDEBUG % EPS handling
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
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
109 currentdict /PDFSTEP known /PDFSTEP exch def
110 % if PDFSTEP is on, turn on PDFDEBUG
111 PDFSTEP { /PDFDEBUG true def } if
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
120 { vmstatus 3 -1 roll pop
122 ifelse usertime 16#fffff and counttomark
123 { ( ) print ( ) cvs print }
125 ( ) print systemdict length ( ) cvs print
126 ( ) print countdictstack ( ) cvs print
127 ( <) print count ( ) cvs print (>\n) print flush
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
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 {
177 currentdict /SAFER known
178 currentdict /PARANOIDSAFER known or % PARANOIDSAFER is equivalent
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
186 % Acquire environment variables.
187 currentdict /DEVICE known not
188 { (GS_DEVICE) getenv { /DEVICE exch def } if } if
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
197 /.currentuserparams where {
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.
209 .dicttomark .setuserparams
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
219 % Define procedures to assist users who don't read the documentation.
222 { (Enter PostScript commands. '(filename) run' runs a file, 'quit' exits.\n)
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
232 % Print the greeting.
236 product (Ghostscript) search
238 (This software comes with NO WARRANTY: see the file PUBLIC for details.\n)
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 ( \()
248 revision 100 mod 10 idiv (.)
249 revision 100 idiv ( )
252 { (%stdout) (w) file exch 0 .writecvp
256 QUIET not { printgreeting flush } if
258 % Define a special version of def for making operator procedures.
259 /obind { % <name> <proc> obind <name> <oper>
260 1 index exch .makeoperator
262 /odef { % <name> <proc> odef -
263 1 index exch .makeoperator def
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
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
277 /.userdict { % - .userdict <dict>
280 /.uservar { % <name> .uservar <value>
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
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.
293 { /.delaybind .systemvar dup length 0 ne
294 { .delaycount 2 index put
295 .userdict /.delaycount .delaycount 1 add put
297 { pop /.bind cvx exec
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
310 currentdict /hwsizedict .undef
312 { //null .getdeviceparams
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
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 ****************
333 % Utility procedure to sort an array
334 % <array> <lt-proc> .sort <array>
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]
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]
343 } for % arr proc arr i arr[i] arr imax amax
344 4 -1 roll exch 4 1 roll put put
348 % Utility for removing all entries from a dictionary
349 /.PurgeDict % <dict> .PurgeDict -
351 1 index { pop exch pop false exit
360 % Define predefined procedures substituting for operators,
361 % in alphabetical order.
363 userdict /#copies 1 put
364 % Adobe implementations don't accept /[ or /], so we don't either.
368 {counttomark array astore exch pop} odef
369 % .beginpage is redefined if setpagedevice is present.
371 % In LanguageLevel 3, copypage erases the page.
374 dup { 0 } { 1 } ifelse .endpage {
375 .currentnumcopies 1 index .outputpage
376 (>>copypage, press <return> to continue<<\n) .confirm
379 systemdict /..page_default_spaces .knownget { //.PurgeDict exec } if
383 .currentmatrix 6 index astore pop
385 % .currentnumcopies is redefined in Level 2.
386 /.currentnumcopies { #copies } odef
387 /setcolorscreen where { pop % not in all Level 1 configurations
390 { { 60 exch 0 exch 3 copy 6 copy } % halftone - not possible
391 { 3 copy 6 copy } % screen
399 { { 60 exch 0 exch } % halftone - not possible
401 { 12 3 roll 9 { pop } repeat } % colorscreen
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
411 .dicttomark readonly def
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
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.
426 { /currentcolor where
427 { pop currentcolor currentcolorspace { setcolorspace setcolor } }
428 { /currentcmykcolor where
429 { pop currentcmykcolor { setcmykcolor } }
430 { currentrgbcolor { setrgbcolor } }
434 currentoverprint false setoverprint 1 setgray .fillpage setoverprint
437 % To satisfy the Genoa FTS, executive must be a procedure, not an operator.
440 { (%statementedit) (r) file } stopped
441 { pop pop $error /errorname get /undefinedfilename eq
442 { .clearerror exit } if % EOF
443 /handleerror .systemvar exec //null % ioerror??
446 cvx { .runexec } execute
450 { //filterdict 1 index .knownget
452 { /filter load /undefined signalerror }
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).
460 % We run the handleerror procedure using .internalstopped so that broken error handlers
461 % won't cause nested errors (Unexpected Error conditions).
464 { /errordict .systemvar /.GShandleerror get .internalstopped pop } bind % always use .GShandleerror.
466 { /errordict .systemvar /handleerror get .internalstopped pop } bind % PLRM standard errorhandling
468 /identmatrix [1.0 0.0 0.0 1.0 0.0 0.0] readonly def
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
477 % .promptmsg is redefined if the interpreter includes readline support.
480 count 0 ne { (<) print count =only } if
483 /prompt { flush flushpage NOPROMPT not { .promptmsg } if } bind def
484 /pstack { 0 1 count 3 sub { index == } for } bind def
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.
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.
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
509 /.runexec2 { % <continue> <file|fileproc> .runexec2 -
513 dup type /filetype ne { cvx exec } if
517 /.runexec { % <file|fileproc> .runexec -
518 cvlit /.runexec1 cvx 1 index /.runexec2 cvx 4 .execn
520 % The following is only for compatibility with Adobe interpreters.
522 1 index length 11 gt { /setdash load /limitcheck signalerror } if
530 { % Reset the halftone since the device may differ
532 dup type /dicttype eq
545 dup 2 gt { /setlinecap load /rangecheck signalerror } if
549 dup 2 gt { /setlinejoin load /rangecheck signalerror } if
553 dup aload pop .setmatrix pop
556 0 .endpage .doneshowpage {
557 .currentnumcopies true .outputpage
558 (>>showpage, press <return> to continue<<\n) .confirm
560 currentoverprint false setoverprint 1 setcolor
562 setoverprint 0 setcolor
564 { initgraphics } ifelse
565 systemdict /..page_default_spaces .knownget { //.PurgeDict exec } if
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
578 /.typenames mark .typenames counttomark packedarray exch pop def
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
589 //.wheredict 1 index .knownget { exec } { .where } ifelse
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.
598 .currentglobal true .setglobal
599 [ /dup .systemvar 1183615869 /eq .systemvar
600 [ /pop .systemvar //null ] cvx
602 dup 1 10 dict .forceput % proc is global, dict is local
604 [ /internaldict /cvx .systemvar /invalidaccess /signalerror cvx ] cvx
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
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
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
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
632 { dup length string copy } bind def
634 .libfile { dup .filename pop exch true } { false } ifelse
636 /.growdictlength % get size for growing a dictionary
637 { length 3 mul 2 idiv 1 add
639 /.growdict % grow a dictionary
640 { dup .growdictlength .setmaxlength
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
648 % .localvmarray may be an operator: see zsysvm.c.
649 /.localvmarray where {
653 .currentglobal false .setglobal
654 exch array exch .setglobal
657 /.localvmdict where {
661 .currentglobal false .setglobal
662 exch dict exch .setglobal
666 { counttomark packedarray exch pop } bind def
668 { 0 1 count 3 sub { index === } for } bind def
670 { % We don't want to bind 'run' into this procedure,
671 % since run may get redefined.
673 { exch pop /run .systemvar exec }
674 { /undefinedfilename signalerror }
678 { finddevice setdevice .setdefaultscreen } bind def
679 /signalerror % <object> <errorname> signalerror -
680 { /errordict .systemvar exch get exec } bind def
682 % Define the =[only] procedures. Also define =print,
683 % which is used by some PostScript programs even though
684 % it isn't documented anywhere.
689 1 index exch write=only (\n) writestring
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.
697 % The following procedures are documented.
698 /copydevice { % <device> copydevice <newdevice>
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
712 /findprotodevice { % <devicename> findprotodevice <protodevice>
713 /devicedict .systemvar exch get 0 get
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 -
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
728 /.runresource { % <file> .runresource -
729 { /run .systemvar exec } .execasresource
732 % Define procedures for getting and setting the current device resolution.
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 }
741 /gscurrentresolution % - gscurrentresolution <[xres yres]>
742 { currentdevice /HWResolution gsgetdeviceprop
744 /gssetresolution % <[xres yres]> gssetresolution -
745 { 2 array astore mark exch /HWResolution exch
746 currentdevice copydevice putdeviceprops setdevice
749 % Define auxiliary procedures needed for the above.
750 /shellarguments % -> shell_arguments true (or) false
752 { /ARGUMENTS get dup type /arraytype eq
753 { aload pop /ARGUMENTS //null store true }
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
771 (/dev/tty) (r) file dup read pop pop closefile
773 .echo.mode false echo
774 (%stdin) (r) file dup read {
775 dup (\n) 0 get eq { pop pop } { unread } ifelse
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
789 /execute { % <obj> execute -
792 % Define an execute analogue of runlibfile0.
793 /execute0 { % <obj> execute0 -
794 .execute { /execute0 cvx 1 .quit } if
796 % Define the procedure that the C code uses for running files
797 % named on the command line.
799 { runlibfile } execute0
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.
805 { { (%stdin) (r) file cvx } .runexec } execute0
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.
811 .currentglobal exch true .setglobal
813 exch .setglobal cvx { .runexec } execute0
815 % Define the procedure that the C code uses to set up for executing
816 % a string that may be received in pieces.
818 .currentglobal true .setglobal
819 { .needinput } bind 0 () .subfiledecode
820 exch .setglobal cvx .runexec
823 % Define a special version of runlibfile that aborts on errors.
825 { cvlit dup /.currentfilename exch def
826 { findlibfile not { stop } if }
828 { (Can't find \(or open\) initialization file ) print
829 .currentfilename == flush /runlibfile0 cvx 1 .quit
832 { (While reading ) print .currentfilename print (:\n) print flush
833 /handleerror .systemvar exec /runlibfile0 1 .quit
836 % Temporarily substitute it for the real runlibfile.
837 /.runlibfile /runlibfile load def
838 /runlibfile /runlibfile0 load def
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'.
847 { (%%[ Error: ) print =only flush
848 (; OffendingCommand: ) print =only ( ]%%) =
850 { (Unrecoverable error: ) print =only flush
853 { (Operand stack:\n ) print
854 count 1 sub -1 2 { ( ) print index =only flush } for
859 -1 0 1 //ErrorNames length 1 sub
860 { dup //ErrorNames exch get 3 index eq
861 { not exch pop exit } { pop } ifelse
865 /.errorhandler % <command> <errorname> .errorhandler -
866 { % Detect an internal 'stopped'.
867 1 .instopped { //null eq { pop pop stop } if } if
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
887 { $error /dstack .undef
888 $error /estack .undef
889 $error /ostack .undef
892 $error /position currentfile status
893 { currentfile { fileposition } .internalstopped { pop //null } if
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 }
903 % During initialization, we don't reset the allocation
905 $error /globalmode get $error /.nosetlocal get and .setglobal
906 $error /.inerror false put
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.
913 { $error begin newerror
915 /command load errorname SHORTERRORS
916 { (%%[ Error: ) print =only flush
917 (; OffendingCommand: ) print =only
918 errorinfo dup //null eq {
921 (;\nErrorInfo:) print
922 dup type /arraytype eq
923 { { ( ) print =only } forall }
929 { (Error: ) print ==only flush
930 ( in ) print ==only flush
931 errorinfo dup //null eq {
934 (\nAdditional information: ) print ==only flush
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.
946 /errordict .systemvar dup /handleerror get exch
947 //JOBSERVER { /.GShandleerror } { /handleerror } ifelse
949 { /errordict .systemvar begin /handleerror load .internalstopped pop end
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
962 currentdict exch .knownget % stackname defined in $error?
964 4 1 roll % stack: <stack> <head> <==flag> <over>
965 /errordict .systemvar exch .knownget % overridename defined?
967 exch pop exch pop exec % call override with <stack>
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
977 dup length =only (/) print dup maxlength =only
978 dup wcheck not { ((ro)) print } if
981 pop gcheck { ((G)) } { ((L)) } ifelse print
987 dup type /stringtype eq 2 index or
988 { ==only } { =only } ifelse
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
1005 pop % printing procedure
1007 errorname /VMerror eq
1008 { (VM status:) print mark vmstatus
1009 counttomark { ( ) print counttomark -1 roll dup =only } repeat
1014 { (Current allocation mode is ) print
1015 globalmode { (global\n) } { (local\n) } ifelse print
1019 { (Last OS error: ) print
1020 errorname /VMerror ne
1021 { dup .oserrorstring { = pop } { = } ifelse }
1030 { (Current file position is ) print position = }
1034 % Define a procedure for clearing the error indication.
1036 { $error /newerror false put
1037 $error /errorname //null put
1038 $error /errorinfo //null put
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.
1052 /recordstacks true def
1054 /globalmode .currentglobal def
1056 /.nosetlocal true def
1057 /position //null def
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
1067 { mark 1 index systemdict /.errorhandler get /exec load .packtomark cvx def
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
1074 /handleerror % this key is 'well known' and some PS may redefine it
1075 { /.printerror .systemvar exec
1077 % a private entry that we will always use under JOBSERVER mode
1079 { /.printerror .systemvar exec
1084 % Define the [write]==[only] procedures.
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
1092 { dup type .dict exch .knownget { exec } { .cvp } ifelse
1099 1 index exch .print pop ( )} forall
1103 1 index exch .print pop ( )} forall
1108 /packedarraytype /arraytype load def
1109 {//.dict begin .print pop end}
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
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
1125 { 2 index 3 -1 roll .print pop ( ) .p1
1126 1 index exch .print pop ( ) .p
1135 { 1 index exch 2 .writecvp
1138 {//.dict begin .print pop end}
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
1147 % Create the initialization queue.
1149 /.delayed_init_queue 10 dict def
1151 /.schedule_init % <priority> <proc> .schedule_init -
1153 //.delayed_init_queue 2 index known {
1154 (.delayed_init_queue priority conflict with ) print 1 index =
1155 /.schedule_init cvx /configurationerror signalerror
1157 //.delayed_init_queue 3 1 roll .growput
1160 /.execute_schedulled_inits % - .execute_schedulled_inits -
1162 { 0 //null //.delayed_init_queue { % maxp {} p {}
1163 3 index 2 index lt {
1168 exch //.delayed_init_queue exch undef
1178 % Define the font directory.
1179 /FontDirectory false .setglobal 100 dict true .setglobal
1180 .forcedef % FontDirectory is local, systemdict is global
1182 % Define the encoding dictionary.
1183 /EncodingDirectory 16 dict def % enough for Level 2 + PDF standard encodings
1185 % Define .findencoding. (This is redefined in Level 2.)
1187 { //EncodingDirectory exch get exec
1190 { //EncodingDirectory 3 1 roll put
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
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 -
1203 % Load StandardEncoding.
1204 %% Replace 1 (gs_std_e.ps)
1205 (gs_std_e.ps) dup runlibfile VMDEBUG
1207 % Load ISOLatin1Encoding.
1208 %% Replace 1 (gs_il1_e.ps)
1209 (gs_il1_e.ps) dup runlibfile VMDEBUG
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.
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 }
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 }
1227 (END FONTDIR/ENCS) VMDEBUG
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.
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
1245 put % errordict /rangecheck
1247 /devicenames devicedict { pop } forall devicedict length packedarray def
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
1258 { 0 .getdevice .devicename
1265 /.defaultdevicename 1 index def
1266 finddevice % make a copy
1268 devicedict /Default devicedict .defaultdevicename get put
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
1279 % Load the standard font environment.
1280 %% Replace 1 (gs_fonts.ps)
1281 (gs_fonts.ps) runlibfile
1283 (END GS_FONTS) VMDEBUG
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.
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
1314 % Use correct, per-plane screens for CMYK devices only.
1315 //systemdict /setcolorscreen known processcolors 4 eq and
1316 { 3 copy 6 copy //setcolorscreen }
1320 /.setloresscreen { % <dpi> .setloresscreen -
1322 0 array cvx settransfer % Genoa CET won't accept a packed array!
1323 /setstrokeadjust where { pop true setstrokeadjust } if
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
1338 { dup cvi 100 idiv 15 .min
1339 {//null 46 46 60 60 60 106 106 106 106 133 133 133 133 133 150}
1343 1 index 4.01 div .min % at least a 4x4 cell
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
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
1357 /RedValues 0 /GreenValues 0 /BlueValues 0 /GrayValues 0
1358 .dicttomark .getdeviceparams
1359 counttomark 2 idiv 1 sub
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).
1379 { /setcolorscreen where
1380 { pop //systemdict /COLORSCREEN known
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,
1391 { { 45 90 15 75 } { 3 1 roll exch pop 12 3 roll } forall
1395 { pop //setscreen % false => single binary screen
1399 { //setscreen % setcolorscreen not known
1403 { //setscreen % not high resolution
1407 /.sethiresscreen { % <dpi> .sethiresscreen
1408 .sethireshalftone % pushes true if a screen halftone used
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!
1416 % Because of a bug in FrameMaker, we have to accept operands
1417 % outside the valid range of [0..1].
1419 dup dup 0.0 gt exch 1.0 lt and
1427 % Set the transfer function to the identity.
1428 0 array cvx % Genoa CET won't accept a packed array!
1432 /setstrokeadjust where
1433 { pop false setstrokeadjust }
1436 % Increase fill adjustment so that we effectively use Adobe's
1437 % any-part-of-pixel rule.
1440 % Set the default screen and BG/UCR.
1442 systemdict /setblackgeneration known {
1443 { pop 0 } dup setblackgeneration setundercolorremoval
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
1452 % The following implementation uses LL2 extensions, but only in stopped
1453 % contexts so that with LL1, the .set??reshalftone will be used.
1455 % - .getdefaulthalftone <halftonedict> true if default found
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 }
1463 % stack: <halftonedict> true if default found
1466 { % device did not provide a default, try Resource
1467 pop { /Default /Halftone /findresource .systemvar exec } .internalstopped
1468 { pop pop false } { true } ifelse
1473 /.setdefaulthalftone {
1476 { % default not found
1477 .useloresscreen { .setloreshalftone } { .sethireshalftone pop } ifelse
1482 /.setdefaultscreen {
1483 .useloresscreen { .setloresscreen } { .sethiresscreen } ifelse
1487 % Load basic color support
1488 %% Replace 1 (gs_cspace.ps)
1489 (gs_cspace.ps) runlibfile
1491 (END BASIC COLOR) VMDEBUG
1493 %% Replace 1 (gs_devcs.ps)
1494 (gs_devcs.ps) runlibfile
1496 (END LEVEL 1 COLOR) VMDEBUG
1498 % Load image support
1499 %% Replace 1 (gs_img.ps)
1500 (gs_img.ps) runlibfile
1504 % Auxiliary procedures for generating file name templates.
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 {
1512 dup 92 eq { % \ -> \\
1518 dup 42 eq { % * -> \*
1524 dup 63 eq { % ? -> \?
1530 2 index 2 index 3 -1 roll put 1 add
1532 0 exch getinterval exch pop
1535 % <dir_list> <template> .generate_dir_list_templates <t1> ... <tN>
1537 % Generates various valid templates combining a directory list with a given template.
1539 % Example1 (DOS, Windows) :
1540 % [(/gs/lib) (/gs/Resource/) (\gs8.00\Resource)] (*/*) -->
1541 % (/gs/lib/*/*) (/gs/Resource/*/*) (\\gs8.00\\Resource/*/*)
1543 % Example2 (OpenVMS) :
1544 % [(gs:[lib]) (gs:[Resource]) (gs800:[Resource)] (*]*) -->
1545 % ((gs:[lib.*]*) [gs:[Resource.*]*) ([gs800:[Resource.*]*)
1547 /.generate_dir_list_templates
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.
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 { % *?
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'
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
1584 pop pop % [dl] (templ) (ffn)
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)
1597 4 1 roll % {} [dl] (templ) (ffn)
1599 % Generate templates :
1600 dup .file_name_is_absolute {
1601 dup % {} [dl] (templ) (ffn) (ffn)
1602 4 index exec % (t1) {} [dl] (templ) (ffn)
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)
1612 } ifelse % (t1) (t2) ... (tN) {} [dl] (templ) (ffn)
1613 pop pop pop pop % (t1) (t2) ... (tN)
1616 % Load the initialization files for optional features.
1617 %% Replace 4 INITFILES
1618 systemdict /INITFILES known
1619 { INITFILES { dup runlibfile VMDEBUG } forall
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
1630 pop 3 .setlanguagelevel
1633 (END INITFILES) VMDEBUG
1635 %% Replace 1 (gs_stres.ps)
1636 (gs_stres.ps) dup runlibfile VMDEBUG
1637 (END STATIC RESOURCES) VMDEBUG
1639 % Create a null font. This is the initial font.
1641 /FontMatrix [ 1 0 0 1 0 0 ] readonly 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!
1649 /NullFont exch definefont setfont
1651 % Define NullFont as the font.
1652 /NullFont currentfont def
1654 % Load initial fonts from FONTPATH directories, Fontmap file,
1655 % and/or .getccfont as appropriate.
1658 % Remove NullFont from FontDirectory, so it can't be accessed by mistake.
1659 /undefinefont where {
1660 pop /NullFont undefinefont
1662 FontDirectory /NullFont .undef
1667 % Restore the real definition of runlibfile.
1668 /runlibfile /.runlibfile load def
1669 currentdict /.runlibfile .undef
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
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
1686 NOBIND DELAYBIND or not { .bindoperators } if
1688 % Establish a default environment.
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
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
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
1712 % the default paper size was letter, so replace it with DEFAULTPAPERSIZE
1713 /PAPERSIZE DEFAULTPAPERSIZE def
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
1736 dup 0 get /DEVICEWIDTHPOINTS exch def
1737 1 get /DEVICEHEIGHTPOINTS exch def
1743 { (Unknown paper size: ) print PAPERSIZE ==only (.) =
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
1755 % Check for resolution.
1756 /DEVICEXRESOLUTION where dup
1757 { exch pop HWResolution 0 DEVICEXRESOLUTION put }
1759 /DEVICEYRESOLUTION where dup
1760 { exch pop HWResolution 1 DEVICEYRESOLUTION put }
1762 or { /HWResolution HWResolution } if
1763 % Check for device sizes specified in pixels.
1764 /DEVICEWIDTH where dup
1765 { exch pop HWSize 0 DEVICEWIDTH put }
1767 /DEVICEHEIGHT where dup
1768 { exch pop HWSize 1 DEVICEHEIGHT put }
1770 or { /HWSize HWSize } if
1771 % Check for device sizes specified in points.
1772 /DEVICEWIDTHPOINTS where dup
1773 { exch pop PageSize 0 DEVICEWIDTHPOINTS put }
1775 /DEVICEHEIGHTPOINTS where dup
1776 { exch pop PageSize 1 DEVICEHEIGHTPOINTS put }
1778 or { /PageSize PageSize } if
1779 % Check whether any parameters were set.
1780 dup mark eq { pop } { defaultdevice putdeviceprops } ifelse
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
1791 { systemdict 2 index known
1792 { pop dup load counttomark 2 roll }
1796 counttomark dup 0 ne
1797 { 2 add -1 roll putdeviceprops }
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
1807 % If the media size is fixed, update the current page device dictionary.
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
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
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
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
1845 (END DEVICE) VMDEBUG
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.
1852 % Compute limit based on character size.
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
1860 % Conditionally disable the character cache.
1861 NOCACHE { 0 setcachelimit } if
1863 (END CONFIG) VMDEBUG
1865 % Initialize graphics.
1870 % The interpreter relies on there being at least 2 entries
1871 % on the graphics stack. Establish the second one now.
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
1882 <1b> cvn { % UEL is <esc>%-12345X and acts the same as ^D
1883 currentfile (%-12345X) .peekstring pop (%-12345X) eq <04> cvn load if
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
1890 /@PJL % H-P job control
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.
1898 2 index countdictstack eq {
1899 1 index /lucas where { /lucas get eq } { pop false } ifelse {
1905 currentfile //=string readline pop pop
1908 % Install the EPS handler if needed
1909 systemdict /EPSBoundingBoxInit known { EPSBoundingBoxInit } if
1911 % If we want a "safer" system, disable some obvious ways to cause havoc.
1912 .currentglobal true .setglobal
1915 dup /tempfiles 10 dict readonly put
1920 SAFETY /safe get not {
1922 /PermitFileReading [
1923 currentuserparams /PermitFileReading get aload pop
1924 /FONTPATH .systemvar (*) .generate_dir_list_templates
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
1939 /LockFilePermissions true
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
1950 //SAFETY /safe //true .forceput % overrides readonly
1951 } .bind executeonly odef
1955 SAFETY /safe get not {
1957 /PermitFileReading [ ]
1958 /PermitFileWriting [ (/fd/*) ]
1959 /PermitFileControl [ ]
1964 } .bind executeonly odef
1968 //deletefile /stackunderflow signalerror
1971 dup { deletefile } stopped {
1972 pop //deletefile $error /errorname get signalerror
1974 % deletefile succeeded. Remove from tempfile list if present
1975 //SAFETY /tempfiles get exch cvn 2 copy known {
1983 } .bind executeonly odef
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.
1988 .tempfile % filename file
1989 //SAFETY /tempfiles get 2 index true .forceput
1990 } .bind executeonly odef
1992 % If we are running in SAFER mode, lock things down
1993 SAFER { .setsafe } if
1995 % If we delayed binding, make it possible to do it later.
1997 currentuserparams /IdiomRecognition .knownget {
1998 1 dict dup /IdiomRecognition //false put setuserparams
2000 //systemdict begin .bindoperators end
2001 % Temporarily disable the typecheck error.
2002 errordict /typecheck 2 copy get
2003 errordict /typecheck { pop } put % pop the command
2004 0 1 .delaycount 1 sub { .delaybind exch get .bind pop } for
2005 //systemdict /.delaybind {} .forceput % reclaim the space
2006 //systemdict /.bindnow .forceundef % ditto
2008 //systemdict /.forcedef .forceundef % remove temptation
2009 //systemdict /.forceput .forceundef % ditto
2010 //systemdict /.forceundef .forceundef % ditto
2011 currentuserparams /IdiomRecognition known {
2012 1 dict dup /IdiomRecognition 4 -1 roll put setuserparams
2016 % Turn off array packing, since some PostScript code assumes that
2017 % procedures are writable.
2022 /.currentuserparams where {
2024 % Remove real user params from psuserparams.
2025 mark .currentuserparams counttomark 2 idiv {
2026 pop psuserparams exch undef
2028 % Update the copy of the user parameters.
2029 mark .currentuserparams counttomark 2 idiv {
2030 userparams 3 1 roll .forceput % userparams is read-only
2032 % Turn on idiom recognition, if available.
2033 currentuserparams /IdiomRecognition known {
2034 /IdiomRecognition true .definepsuserparam
2036 psuserparams readonly pop
2037 systemdict /.definepsuserparam undef
2038 % Save a copy of userparams for use with save/restore
2039 % (and, if implemented, context switching).
2040 .currentglobal false .setglobal
2041 mark userparams { } forall .dicttomark readonly
2042 /userparams exch .forcedef % systemdict is read-only
2045 /.currentsystemparams where {
2047 % Remove real system params from pssystemparams.
2048 mark .currentsystemparams counttomark 2 idiv {
2049 pop pssystemparams exch .forceundef
2053 % Set up AlignToPixels :
2055 /AlignToPixels where {
2056 mark /AlignToPixels 2 index /AlignToPixels get .dicttomark setuserparams
2057 /AlignToPixels undef
2060 % Set up GridFitTT :
2063 mark /GridFitTT 2 index /GridFitTT get .dicttomark setuserparams
2067 % Conditionally turn image interpolation on or off.
2068 currentdict /INTERPOLATE known not { (%END INTERPOLATE) .skipeof } if
2071 dup /Interpolate .knownget not { //false } if
2072 /INTERPOLATE .systemvar ne {
2073 dup gcheck .currentglobal exch .setglobal
2074 exch dup length dict copy
2075 dup /Interpolate /INTERPOLATE .systemvar put
2081 { /INTERPOLATE .systemvar
2082 { .currentglobal % w h bit [] {}...{} multi ncomp glob
2084 9 dict begin % w h bit [] {}...{} multi ncomp glob
2085 2 index { 1 index 7 add } { 8 } ifelse
2086 copy gsave pop % preserve the arguments
2087 { 0 /DeviceGray 0 /DeviceRGB /DeviceCMYK }
2088 1 index get setcolorspace % ... glob w h bit [] {}...{} multi ncomp
2090 1 index 2 mul 0 exch % ... glob w h bit [] {}...{} multi ncomp {0 1 ...} 0 2*ncomp
2091 getinterval /Decode exch def % ... glob w h bit [] {}...{} multi ncomp
2092 exch dup % ... glob w h bit [] {}...{} ncomp multi multi
2093 /MultipleDataSources exch def % ... glob w h bit [] {}...{} ncomp multi
2094 { array astore} { pop } ifelse % ... glob w h bit [] [{}...{}]
2095 /DataSource exch def % ... glob w h bit []
2096 /ImageMatrix exch def % ... glob w h bit
2097 /BitsPerComponent exch def % ... glob w h
2098 /Height exch def % ... glob w
2099 /Width exch def % ... glob
2101 /Interpolate //true def
2102 .setglobal currentdict end % ... <<>>
2104 exch { 4 add } { 6 } ifelse
2113 { dup type /dicttype eq
2114 { dup /ImageType get 3 eq
2115 { .currentglobal //false .setglobal exch
2116 dup length dict copy begin .setglobal
2117 /DataDict DataDict .interpolate def
2118 /MaskDict MaskDict .interpolate def
2126 { /INTERPOLATE .systemvar
2127 { .currentglobal //false .setglobal
2128 8 dict begin .setglobal
2130 /DataSource 1 index def
2131 /ImageMatrix 2 index def
2132 /BitsPerComponent 3 index def
2136 /Interpolate //true def
2138 gsave /DeviceGray setcolorspace image grestore
2149 dup type /dicttype eq {
2150 .interpolate imagemask
2152 /INTERPOLATE .systemvar {
2153 .currentglobal //false .setglobal
2154 8 dict begin .setglobal
2156 /DataSource 1 index def
2157 /ImageMatrix 2 index def
2158 /BitsPerComponent 1 def
2159 2 index { {1 0} } { {0 1} } ifelse /Decode exch def
2162 /Interpolate //true def
2163 currentdict end imagemask 5 { pop } repeat
2170 currentdict /.interpolate undef
2174 % Establish local VM as the default.
2175 false /setglobal where { pop setglobal } { .setglobal } ifelse
2176 $error /.nosetlocal false put
2178 (END GLOBAL) VMDEBUG
2180 /.savelocalstate where {
2181 % If we might create new contexts, save away copies of all dictionaries
2182 % referenced from systemdict that are stored in local VM,
2183 % and also save a copy of the initial gstate.
2186 % If we're *not* running in a multi-context system and FAKEFONTS is
2187 % defined, add the fake fonts to LocalFontDirectory.
2188 .definefakefonts % current VM is local
2191 % Execude schedilled inits :
2192 //.execute_schedulled_inits exec
2193 currentdict /.execute_schedulled_inits undef
2194 currentdict /.delayed_init_queue undef
2195 currentdict /.delayed_init_queue undef
2197 % Remove systemdict entries for things that have been bound in where used
2198 % and that shouldn't be accessible by name, and close up systemdict.
2199 currentdict /filterdict .undef
2200 currentdict /.cidfonttypes .undef
2201 currentdict /.colorrenderingtypes .undef
2202 currentdict /.formtypes .undef
2203 currentdict /.halftonetypes .undef
2204 currentdict /.imagetypes .undef
2205 currentdict /.imagemasktypes .undef
2206 currentdict /.patterntypes .undef
2207 currentdict /.shadingtypes .undef
2208 currentdict /.wheredict .undef
2211 % Clean up VM, and enable GC.
2213 { pop NOGC not { 2 vmreclaim 0 vmreclaim } if
2216 systemdict /.forcedef .undef % remove temptation
2217 systemdict /.forceput .undef % ditto
2218 systemdict /.forceundef .undef % ditto
2220 WRITESYSTEMDICT not { systemdict readonly pop } if
2223 % The Adobe AGM_Core used by Illustrator 9 has some code that breaks
2224 % if the 'product' is not (Adobe PostScript Parser). A bug has been
2225 % submitted to Adobe since this also fails with Acrobat Distiller.
2226 % As a temporary work around, the following HACK will work for
2227 % devices without spot color support. Once Ghostscript can
2228 % support DeviceN and spot color separations this will need to
2229 % be 'true' in some cases.
2230 userdict /AGM_preserve_spots false put
2232 % Start the job as encapsulated if requested, if not, perform an
2233 % outer save so that jobs which depend on global VM not being
2234 % restored will operate correctly.
2236 % Note that .setsafe is already in effect if in SAFER mode.
2237 % so an exitserver will restore with SAFER mode still in effect.
2239 { false 0 .startnewjob }
2240 { NOOUTERSAVE not { save pop } if } % do the outermost save unless disabled
2243 % The interpreter will run the initial procedure (start).