home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / gs_init.ps < prev    next >
Text File  |  2004-09-07  |  73KB  |  2,202 lines

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