home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / GhostScript / !GhostScr / 6_01 / lib / gs_init.ps < prev    next >
Text File  |  2000-03-29  |  54KB  |  1,697 lines

  1. %    Copyright (C) 1989, 2000 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % $Id: gs_init.ps,v 1.3 2000/03/10 18:47:31 lpd Exp $
  16. % Initialization file for the interpreter.
  17. % When this is run, systemdict is still writable.
  18.  
  19. % Comment lines of the form
  20. %    %% Replace <n> <file(s)>
  21. % indicate places where the next <n> lines should be replaced by
  22. % the contents of <file(s)>, when creating a single merged init file.
  23.  
  24. % The interpreter can call out to PostScript code.  All procedures
  25. % called in this way, and no other procedures defined in these
  26. % initialization files, have names that begin with %, e.g.,
  27. % (%Type1BuildChar) cvn.
  28.  
  29. % Check the interpreter revision.  NOTE: the interpreter code requires
  30. % that the first non-comment token in this file be an integer.
  31. 601
  32. dup revision ne
  33.  { (gs: Interpreter revision \() print revision 10 string cvs print
  34.    (\) does not match gs_init.ps revision \() print 10 string cvs print
  35.    (\).\n) print flush null 1 .quit
  36.  }
  37. if pop
  38.  
  39. % Acquire userdict, and set its length if necessary.
  40. /userdict where
  41.  { pop userdict maxlength 0 eq }
  42.  { true }
  43. ifelse
  44. systemdict exch
  45.  {        % userdict wasn't already set up by iinit.c.
  46.    dup /userdict
  47.    currentdict dup 200 .setmaxlength        % userdict
  48.    .forceput            % userdict is local, systemdict is global
  49.  }
  50. if begin
  51.  
  52. % Define dummy local/global operators if needed.
  53. systemdict /.setglobal known
  54.  { true .setglobal
  55.  }
  56.  { /.setglobal { pop } bind def
  57.    /.currentglobal { false } bind def
  58.    /.gcheck { pop false } bind def
  59.  }
  60. ifelse
  61.  
  62. % Define .languagelevel if needed.
  63. systemdict /.languagelevel known not { /.languagelevel 1 def } if
  64.  
  65. % Optionally choose a default paper size other than U.S. letter.
  66. % (a4) /PAPERSIZE where { pop pop } { /PAPERSIZE exch def } ifelse
  67.  
  68. % Turn on array packing for the rest of initialization.
  69. true setpacking
  70.  
  71. % Define the old MS-DOS EOF character as a no-op.
  72. % This is a hack to get around the absurd habit of MS-DOS editors
  73. % of adding an EOF character at the end of the file.
  74. <1a> cvn { } def
  75.  
  76. % Acquire the debugging flags.
  77. currentdict /DEBUG known   /DEBUG exch def
  78.   /VMDEBUG
  79.     DEBUG {{print mark
  80.             systemdict /level2dict known
  81.          { .currentglobal dup false .setglobal vmstatus
  82.            true .setglobal vmstatus 3 -1 roll pop
  83.            6 -2 roll pop .setglobal
  84.          }
  85.          { vmstatus 3 -1 roll pop
  86.          }
  87.         ifelse usertime 16#fffff and counttomark
  88.           { ( ) print (           ) cvs print }
  89.         repeat pop
  90.         ( ) print systemdict length (    ) cvs print
  91.         ( ) print countdictstack (  ) cvs print
  92.         ( <) print count (    ) cvs print (>\n) print flush
  93.       }}
  94.       {{pop
  95.       }}
  96.      ifelse
  97.   def
  98.  
  99. currentdict /BATCH known   /BATCH exch def
  100. currentdict /DELAYBIND known   /DELAYBIND exch def
  101. currentdict /DISKFONTS known   /DISKFONTS exch def
  102. currentdict /DOINTERPOLATE .knownget { /INTERPOLATE exch def } if
  103. currentdict /ESTACKPRINT known   /ESTACKPRINT exch def
  104. currentdict /FAKEFONTS known   /FAKEFONTS exch def
  105. currentdict /FIXEDMEDIA known   /FIXEDMEDIA exch def
  106. currentdict /FIXEDRESOLUTION known   /FIXEDRESOLUTION exch def
  107. currentdict /LOCALFONTS known   /LOCALFONTS exch def
  108. currentdict /NOBIND known   /NOBIND exch def
  109. /.bind /bind load def
  110. NOBIND { /bind { } def } if
  111. currentdict /NOCACHE known   /NOCACHE exch def
  112. currentdict /NOCIE known   /NOCIE exch def
  113. currentdict /NODISPLAY known   not /DISPLAYING exch def
  114. currentdict /NOFONTMAP known   /NOFONTMAP exch def
  115. currentdict /NOFONTPATH known   /NOFONTPATH exch def
  116. currentdict /NOGC known   /NOGC exch def
  117. currentdict /NOINTERPOLATE .knownget { /INTERPOLATE exch not def } if
  118. currentdict /NOPAGEPROMPT known   /NOPAGEPROMPT exch def
  119. currentdict /NOPAUSE known   /NOPAUSE exch def
  120. currentdict /NOPLATFONTS known   /NOPLATFONTS exch def
  121. currentdict /NOPROMPT known   /NOPROMPT exch def
  122. % The default value of ORIENT1 is true, not false.
  123. currentdict /ORIENT1 known not { /ORIENT1 true def } if
  124. currentdict /OSTACKPRINT known   /OSTACKPRINT exch def
  125. currentdict /OUTPUTFILE known    % obsolete
  126.  { /OutputFile /OUTPUTFILE load def
  127.    currentdict /OUTPUTFILE .undef
  128.  } if
  129. currentdict /QUIET known   /QUIET exch def
  130. currentdict /SAFER known   /SAFER exch def
  131. currentdict /SHORTERRORS known   /SHORTERRORS exch def
  132. currentdict /STRICT known   /STRICT exch def
  133. currentdict /TTYPAUSE known   /TTYPAUSE exch def
  134. currentdict /WRITESYSTEMDICT known   /WRITESYSTEMDICT exch def
  135.  
  136. % Acquire environment variables.
  137. currentdict /DEVICE known not
  138.  { (GS_DEVICE) getenv { /DEVICE exch def } if } if
  139.  
  140. (START) VMDEBUG
  141.  
  142. % Open the standard files, so they will be open at the outermost save level.
  143. (%stdin) (r) file pop
  144. (%stdout) (w) file pop
  145. (%stderr) (w) file pop
  146.  
  147. /.currentuserparams where {
  148.   pop mark
  149.     % The Adobe implementations appear to have very large maximum
  150.     % stack sizes.  This turns out to actually make a difference,
  151.     % since some badly-behaved files include extremely long procedures,
  152.     % or construct huge arrays on the operand stack.
  153.     % We reset the stack sizes now so that we don't have to worry
  154.     % about overflowing the (rather small) built-in stack sizes
  155.     % during initialization.
  156.   /MaxDictStack 500
  157.   /MaxExecStack 5000
  158.   /MaxOpStack 50000
  159.   .dicttomark .setuserparams
  160. } if
  161.  
  162. % Define a procedure for skipping over an unneeded section of code.
  163. % This avoids allocating space for the skipped procedures.
  164. % We can't use readline, because that imposes a line length limit.
  165. /.skipeof    % <string> .skipeof -
  166.  { currentfile exch 1 exch .subfiledecode flushfile
  167.  } .bind def
  168.  
  169. % Define procedures to assist users who don't read the documentation.
  170. userdict begin
  171. /help
  172.  { (Enter PostScript commands.  '(filename) run' runs a file, 'quit' exits.\n)
  173.    print flush
  174.  } .bind def
  175. /? /help load def
  176. end
  177.  
  178. % Define =string, which is used by some PostScript programs even though
  179. % it isn't documented anywhere.
  180. % Put it in userdict so that each context can have its own copy.
  181. userdict /=string 256 string put
  182.  
  183. % Print the greeting.
  184.  
  185. /printgreeting
  186.  { mark
  187.    product (Ghostscript) search
  188.     { pop pop pop
  189.       (This software comes with NO WARRANTY: see the file PUBLIC for details.\n)
  190.     }
  191.     { pop
  192.     }
  193.    ifelse
  194.    (\n) copyright
  195.    (\)\n) revisiondate 10 mod revisiondate 10 idiv 10 mod (-)
  196.    revisiondate 100 idiv 10 mod revisiondate 1000 idiv 10 mod (-)
  197.    revisiondate 10000 idiv ( \()
  198.    revision 10 mod
  199.    revision 100 mod dup 0 ne { 10 idiv } { pop } ifelse (.)
  200.    revision 100 idiv ( )
  201.    product
  202.    counttomark
  203.     { (%stdout) (w) file exch 0 .writecvp
  204.     } repeat pop
  205.  } .bind def
  206.  
  207. QUIET not { printgreeting flush } if
  208.  
  209. % Define a special version of def for making operator procedures.
  210. /obind {    % <name> <proc> obind <name> <oper>
  211.   1 index exch .makeoperator
  212. } .bind def
  213. /odef {        % <name> <proc> odef -
  214.   1 index exch .makeoperator def
  215. } .bind def
  216.  
  217. % Define a special version of def for storing local objects into global
  218. % dictionaries.  Like .forceput, this exists only during initialization.
  219. /.forcedef {        % <key> <value> .forcedef -
  220.   currentdict 3 1 roll .forceput
  221. } .bind odef
  222.  
  223. % Define procedures for accessing variables in systemdict and userdict
  224. % regardless of the contents of the dictionary stack.
  225. /.systemvar {        % <name> .systemvar <value>
  226.   //systemdict exch get
  227. } .bind odef
  228. /.userdict {        % - .userdict <dict>
  229.   /userdict .systemvar
  230. } .bind odef
  231. /.uservar {        % <name> .uservar <value>
  232.   .userdict exch get
  233. } .bind odef
  234.  
  235. % If we're delaying binding, remember everything that needs to be bound later.
  236. DELAYBIND NOBIND not and
  237.  { .currentglobal false .setglobal
  238.    systemdict /.delaybind 1500 array .forceput
  239.    .setglobal
  240.    userdict /.delaycount 0 put
  241.     % When we've done the delayed bind, we want to stop saving.
  242.     % Detect this by the disappearance of .delaybind.
  243.    /bind
  244.     { /.delaybind .systemvar dup length 0 ne
  245.        { .delaycount 2 index put
  246.          .userdict /.delaycount .delaycount 1 add put
  247.        }
  248.        { pop .bind
  249.        }
  250.       ifelse
  251.     } .bind def
  252.  } if
  253.  
  254. %**************** BACKWARD COMPATIBILITY
  255. /hwsizedict mark /HWSize null .dicttomark readonly def
  256. /copyscanlines {        % <device> <y> <string> copyscanlines <substr>
  257.   0 3 1 roll 3 index //hwsizedict .getdeviceparams
  258.   exch pop exch pop aload pop 3 2 roll
  259.   0 exch null exch .getbitsrect exch pop
  260. } bind odef
  261. currentdict /hwsizedict .undef
  262. /getdeviceprops
  263.  { null .getdeviceparams
  264.  } bind odef
  265. /.putdeviceprops
  266.  { null true counttomark 1 add 3 roll .putdeviceparams
  267.    dup type /booleantype ne
  268.     { dup mark eq { /unknown /rangecheck } if
  269.       counttomark 4 add 1 roll cleartomark pop pop pop
  270.       /.putdeviceprops load exch signalerror
  271.     }
  272.    if
  273.  } bind odef
  274. /max { .max } bind def
  275. /min { .min } bind def
  276. /.currentfilladjust { .currentfilladjust2 pop } bind odef
  277. /.setfilladjust { dup .setfilladjust2 } bind odef
  278. /.writecvs { 0 .writecvp } bind odef
  279.  
  280. % Define predefined procedures substituting for operators,
  281. % in alphabetical order.
  282.  
  283. userdict /#copies 1 put
  284. % Adobe implementations don't accept /[ or /], so we don't either.
  285. ([) cvn
  286.     /mark load def
  287. (]) cvn
  288.     {counttomark array astore exch pop} odef
  289. % .beginpage is redefined if setpagedevice is present.
  290. /.beginpage { } odef
  291. % In LanguageLevel 3, copypage erases the page.
  292. /copypage {
  293.     .languagelevel 3 ge
  294.     dup { 0 } { 1 } ifelse .endpage {
  295.       .currentnumcopies 1 index .outputpage
  296.       (>>copypage, press <return> to continue<<\n) .confirm
  297.       dup { erasepage } if
  298.     } if pop .beginpage
  299. } odef
  300. /currentmatrix {
  301.     .currentmatrix 6 index astore pop
  302. } odef
  303. % .currentnumcopies is redefined in Level 2.
  304. /.currentnumcopies { #copies } odef
  305. /setcolorscreen where { pop        % not in all Level 1 configurations
  306.    /currentcolorscreen
  307.     { .currenthalftone
  308.        { { 60 exch 0 exch 3 copy 6 copy }    % halftone - not possible
  309.          { 3 copy 6 copy }            % screen
  310.          { }                % colorscreen
  311.        }
  312.       exch get exec
  313.     } odef
  314. } if
  315. /currentscreen
  316.     { .currenthalftone
  317.        { { 60 exch 0 exch }            % halftone - not possible
  318.          { }                % screen
  319.          { 12 3 roll 9 { pop } repeat }    % colorscreen
  320.        }
  321.       exch get exec
  322.     } odef
  323. /.echo /echo load def
  324. userdict /.echo.mode true put
  325. /echo    {dup /.echo.mode exch store .echo} odef
  326. /eexec {
  327.     % Rebind .currentresourcefile if it is the source for the eexec.
  328.   dup 55665 //filterdict /eexecDecode get exec
  329.   cvx exch .currentresourcefile eq
  330.   //systemdict begin { {exec} .execasresource } { exec } ifelse
  331.     % Only pop systemdict if it is still the top element,
  332.     % because this is apparently what Adobe interpreters do.
  333.   currentdict //systemdict eq { end } if
  334. } odef
  335. % .endpage is redefined if setpagedevice is present.
  336. /.endpage { 2 ne } odef
  337. % erasepage mustn't use gsave/grestore, because we call it before
  338. % the graphics state stack has been fully initialized.
  339. /erasepage
  340.     { /currentcolor where
  341.        { pop currentcolor currentcolorspace { setcolorspace setcolor } }
  342.        { /currentcmykcolor where
  343.           { pop currentcmykcolor { setcmykcolor } }
  344.           { currentrgbcolor { setrgbcolor } }
  345.          ifelse
  346.        }
  347.       ifelse 1 setgray .fillpage exec
  348.     } odef
  349. % To satisfy the Genoa FTS, executive must be a procedure, not an operator.
  350. /executive
  351.     { { NOPROMPT not { prompt } if
  352.          { (%statementedit) (r) file } stopped
  353.          { pop pop $error /errorname get /undefinedfilename eq
  354.         { .clearerror exit } if        % EOF
  355.            handleerror null        % ioerror??
  356.          }
  357.         if
  358.         cvx { .runexec } execute
  359.       } loop
  360.     } bind def
  361. /filter
  362.     { //filterdict 1 index .knownget
  363.        { exch pop exec }
  364.        { /filter load /undefined signalerror }
  365.       ifelse
  366.     } odef
  367. /handleerror
  368.     { /errordict .systemvar /handleerror get exec } bind def
  369. /identmatrix [1.0 0.0 0.0 1.0 0.0 0.0] readonly def
  370. /identmatrix
  371.     { dup 0 //identmatrix putinterval } odef
  372. /languagelevel 1 def        % gs_lev2.ps may change this
  373. /makeimagedevice { false makewordimagedevice } odef
  374. /matrix    { 6 array identmatrix } odef
  375. /pathbbox
  376.     { false .pathbbox
  377.     } odef
  378. % .promptmsg is redefined if the interpreter includes readline support.
  379. /.promptmsg {
  380.     (GS) print
  381.     count 0 ne { (<) print count =only } if
  382.     (>) print flush
  383. } bind def
  384. /prompt    { flush flushpage .promptmsg } bind def
  385. /pstack    { 0 1 count 3 sub { index == } for } bind def
  386. /putdeviceprops
  387.     { .putdeviceprops { erasepage } if } odef
  388. /quit    { /quit load 0 .quit } odef
  389. /run    { dup type /filetype ne { (r) file } if
  390.         % We must close the file when execution terminates,
  391.         % regardless of the state of the stack,
  392.         % and then propagate an error, if any.
  393.       cvx .runexec
  394.     } odef
  395. % Execute a file.
  396. % Level 2 uses 2 .stop to clear the e-stack for a successful startjob:
  397. % we detect that here, since we need to handle this even if we start out
  398. % without job control in effect.
  399. %
  400. % What we push on the e-stack is the following to be executed in this order:
  401. %    <lit-file|fileproc> .runexec1 <lit-file|fileproc> .runexec2
  402. /.runexec1 {        % <file|fileproc> .runexec1 -
  403.   dup type /filetype ne { cvx exec } if
  404.   cvx null 2 .stopped
  405.     % If we got back here from a startjob, just keep going.
  406.     % startjob replaces the null on the o-stack with a procedure
  407.     % to be executed when we get back here.
  408.   dup null ne { exec true } { pop false } ifelse
  409. } bind def
  410. /.runexec2 {        % <continue> <file|fileproc> .runexec2 -
  411.   exch {
  412.     .runexec
  413.   } {
  414.     dup type /filetype ne { cvx exec } if
  415.     closefile
  416.   } ifelse
  417. } bind def
  418. /.runexec {        % <file|fileproc> .runexec -
  419.   cvlit /.runexec1 cvx 1 index /.runexec2 cvx 4 .execn
  420. } bind def
  421. % The following is only for compatibility with Adobe interpreters.
  422. /setdash {
  423.     1 index length 11 gt { /setdash load /limitcheck signalerror } if
  424.     //setdash
  425. } odef
  426. /setdevice
  427.     { .setdevice { erasepage } if } odef
  428. /setlinecap {
  429.     dup 2 gt { /setlinecap load /rangecheck signalerror } if
  430.     .setlinecap
  431. } odef
  432. /setlinejoin {
  433.     dup 2 gt { /setlinejoin load /rangecheck signalerror } if
  434.     .setlinejoin
  435. } odef
  436. /setmatrix {
  437.     dup aload pop .setmatrix pop
  438. } odef
  439. /showpage {
  440.     0 .endpage .doneshowpage {
  441.       .currentnumcopies true .outputpage
  442.       (>>showpage, press <return> to continue<<\n) .confirm
  443.       erasepage
  444.     } if initgraphics .beginpage
  445. } odef
  446. % Code output by Adobe Illustrator relies on the fact that
  447. % `stack' is a procedure, not an operator!!!
  448. /stack    { 0 1 count 3 sub { index = } for } bind def
  449. /start    { BATCH { null 0 .quit } { executive } ifelse } def
  450. % Internal uses of stopped that aren't going to do a stop if an error occurs
  451. % should use .internalstopped to avoid setting newerror et al.
  452. /.internalstopped { null 1 .stopped null ne } bind def
  453. /store {    % Don't alter operands before completing.
  454.     1 index where { 2 index 2 index put pop pop } { def } ifelse
  455. } odef
  456. /.typenames mark .typenames counttomark packedarray exch pop def
  457. /type {
  458.     //.typenames .type
  459. } odef
  460. currentdict /.typenames .undef
  461. % When running in Level 1 mode, this interpreter is supposed to be
  462. % compatible with PostScript "version" 54.0 (I think).
  463. /version (54.0) readonly def
  464. /.wheredict 10 dict def
  465. /.where /where load def
  466. /where {
  467.     //.wheredict 1 index .knownget { exec } { .where } ifelse
  468. } odef
  469.  
  470. % internaldict is defined in systemdict, but is allocated in local VM.
  471. % We make a procedure for creating it, since we must create a new one
  472. % for each context with private local VM.
  473. /.makeinternaldict {
  474.   .currentglobal false .setglobal
  475.     [ /dup .systemvar 1183615869 /eq .systemvar
  476.     [ /pop .systemvar 10 dict ] cvx
  477.     [ /internaldict /cvx .systemvar /invalidaccess /signalerror cvx ] cvx
  478.       /ifelse .systemvar
  479.     ] cvx executeonly
  480.   exch .setglobal
  481. } odef
  482. systemdict /internaldict dup .makeinternaldict .makeoperator
  483. .forceput        % proc is local, systemdict is global
  484. % Move superexec to internaldict if superexec is defined.
  485. currentdict /superexec .knownget {
  486.   1183615869 internaldict /superexec 3 -1 roll put
  487.   currentdict /superexec .undef
  488. } if
  489.  
  490. % Define some additional built-in procedures (beyond the ones defined by
  491. % the PostScript Language Reference Manual).
  492. % Warning: these are not guaranteed to stay the same from one release
  493. % to the next!
  494. /concatstrings
  495.     { exch dup length 2 index length add string    % str2 str1 new
  496.       dup dup 4 2 roll copy        % str2 new new new1
  497.       length 4 -1 roll putinterval
  498.     } bind def
  499. /copyarray
  500.     { dup length array copy } bind def
  501. % Copy a dictionary per the Level 2 spec even in Level 1.
  502. /.copydict        % <fromdict> <todict> .copydict <todict>
  503.     { dup 3 -1 roll { put dup } forall pop } bind def
  504. /copystring
  505.     { dup length string copy } bind def
  506. /finddevice
  507.     { /devicedict .systemvar exch get
  508.       dup 1 get null eq
  509.        {        % This is the first request for this type of device.
  510.             % Create a default instance now.
  511.             % Stack: [proto null]
  512.          .currentglobal true .setglobal exch
  513.          dup dup 0 get copydevice 1 exch put
  514.          exch .setglobal
  515.        }
  516.       if 1 get
  517.     } bind def
  518. /.growdictlength    % get size for growing a dictionary
  519.     { length 3 mul 2 idiv 1 add
  520.     } bind def
  521. /.growdict        % grow a dictionary
  522.     { dup .growdictlength .setmaxlength
  523.     } bind def
  524. /.growput        % put, grow the dictionary if needed
  525.     { 2 index length 3 index maxlength eq
  526.        { 3 copy pop known not { 2 index .growdict } if
  527.        } if
  528.       put
  529.     } bind def
  530. /.packtomark
  531.     { counttomark packedarray exch pop } bind def
  532. /ppstack
  533.     { 0 1 count 3 sub { index === } for } bind def
  534. /runlibfile
  535.     {        % We don't want to bind 'run' into this procedure,
  536.             % since run may get redefined.
  537.       findlibfile
  538.        { exch pop /run .systemvar exec }
  539.        { /undefinedfilename signalerror }
  540.       ifelse
  541.     } bind def
  542. /selectdevice
  543.     { finddevice setdevice .setdefaultscreen } bind def
  544. /signalerror        % <object> <errorname> signalerror -
  545.     { /errordict .systemvar exch get exec } bind def
  546.  
  547. % Define the =[only] procedures.  Also define =print,
  548. % which is used by some PostScript programs even though
  549. % it isn't documented anywhere.
  550. /write=only {
  551.     .writecvs
  552. } bind def
  553. /write= {
  554.     1 index exch write=only (\n) writestring
  555. } bind def
  556. /=only    { (%stdout) (w) file exch write=only } bind def
  557. /=    { =only (\n) print } bind def
  558. /=print    /=only load def
  559. % Temporarily define == as = for the sake of runlibfile0.
  560. /== /= load def
  561.  
  562. % Run a resource file.  This allows us to distinguish resource objects
  563. % from objects coming from input files.
  564. userdict /.currentresourcefile null put
  565. /.execasresource {    % <file> <proc|runfile> .execasresource -
  566.   /stopped .systemvar
  567.   /.currentresourcefile .uservar
  568.         % Stack: file proc -stopped- currfile
  569.   .userdict /.currentresourcefile 5 index cvlit put
  570.   2 .execn        % stopped <file>
  571.   .userdict /.currentresourcefile 3 -1 roll put
  572.   { stop } if
  573. } bind def
  574. /.runresource {        % <file> .runresource -
  575.   { /run .systemvar exec } .execasresource
  576. } bind def
  577.  
  578. % Define procedures for getting and setting the current device resolution.
  579.  
  580. /gsgetdeviceprop    % <device> <propname> gsgetdeviceprop <value>
  581.  { 2 copy mark exch null .dicttomark .getdeviceparams
  582.    dup mark eq        % if true, not found
  583.     { pop dup /undefined signalerror }
  584.     { 5 1 roll pop pop pop pop }
  585.    ifelse
  586.  } bind def
  587. /gscurrentresolution    % - gscurrentresolution <[xres yres]>
  588.  { currentdevice /HWResolution gsgetdeviceprop
  589.  } bind def
  590. /gssetresolution    % <[xres yres]> gssetresolution -
  591.  { 2 array astore mark exch /HWResolution exch
  592.    currentdevice copydevice putdeviceprops setdevice
  593.  } bind def
  594.  
  595. % Define auxiliary procedures needed for the above.
  596. /shellarguments        % -> shell_arguments true (or) false
  597.     { /ARGUMENTS where
  598.        { /ARGUMENTS get dup type /arraytype eq
  599.           { aload pop /ARGUMENTS null store true }
  600.           { pop false }
  601.          ifelse }
  602.        { false } ifelse
  603.     } bind def
  604. /.confirm {
  605.   DISPLAYING NOPAUSE not TTYPAUSE or and {
  606.     % Print a message (unless NOPAGEPROMPT or NOPROMPT is true)
  607.     % and wait for the user to type something.
  608.     % If the user just types a newline, flush it.
  609.     NOPAGEPROMPT NOPROMPT or { pop } { print flush } ifelse
  610.     .confirmread
  611.   } {
  612.     pop
  613.   } ifelse
  614. } bind def
  615. /.confirmread {
  616.   TTYPAUSE {
  617.     (/dev/tty) (r) file dup read pop pop closefile
  618.   } {
  619.     .echo.mode false echo
  620.     (%stdin) (r) file dup read {
  621.       dup (\n) 0 get eq { pop pop } { unread } ifelse
  622.     } {
  623.       pop
  624.     } ifelse echo
  625.   } ifelse
  626. } bind def
  627.  
  628. % Define the procedure used by .runfile, .runstdin and .runstring
  629. % for executing user input.
  630. % This is called with a procedure or executable file on the operand stack.
  631. /.execute {        % <obj> .execute <stopped>
  632.   stopped $error /newerror get and
  633.    { handleerror flush true } { false } ifelse
  634. } bind def
  635. /execute {        % <obj> execute -
  636.   .execute pop
  637. } odef
  638. % Define an execute analogue of runlibfile0.
  639. /execute0 {        % <obj> execute0 -
  640.   .execute { /execute0 cvx 1 .quit } if
  641. } bind def
  642. % Define the procedure that the C code uses for running files
  643. % named on the command line.
  644. /.runfile {
  645.   { runlibfile } execute0
  646. } def
  647. % Define the procedure that the C code uses for running piped input.
  648. % We don't use the obvious { (%stdin) run }, because we want the file to be
  649. % reopened if a startjob does a restore.
  650. /.runstdin {
  651.   { { (%stdin) (r) file cvx } .runexec } execute0
  652. } bind def
  653. % Define the procedure that the C code uses for running commands
  654. % given on the command line with -c.  We turn the string into a file so that
  655. % .runexec can do the right thing with a startjob.
  656. /.runstring {
  657.   .currentglobal exch true .setglobal
  658.   0 () .subfiledecode
  659.   exch .setglobal cvx { .runexec } execute0
  660. } bind def
  661. % Define the procedure that the C code uses to set up for executing
  662. % a string that may be received in pieces.
  663. /.runstringbegin {
  664.   .currentglobal true .setglobal
  665.   { .needinput } bind 0 () .subfiledecode
  666.   exch .setglobal cvx .runexec
  667. } bind def
  668.  
  669. % Define a special version of runlibfile that aborts on errors.
  670. /runlibfile0
  671.     { cvlit dup /.currentfilename exch def
  672.        { findlibfile not { stop } if }
  673.       stopped
  674.        { (Can't find \(or open\) initialization file ) print
  675.          .currentfilename == flush /runlibfile0 cvx 1 .quit
  676.        } if
  677.       exch pop cvx stopped
  678.        { (While reading ) print .currentfilename print (:\n) print flush
  679.          handleerror /runlibfile0 1 .quit
  680.        } if
  681.     } bind def
  682. % Temporarily substitute it for the real runlibfile.
  683. /.runlibfile /runlibfile load def
  684. /runlibfile /runlibfile0 load def
  685.  
  686. % Create the error handling machinery.
  687. % Define the standard error handlers.
  688. % The interpreter has created the ErrorNames array.
  689. /.unstoppederrorhandler    % <command> <errorname> .unstoppederrorhandler -
  690.  {    % This is the handler that gets used for recursive errors,
  691.     % or errors outside the scope of a 'stopped'.
  692.    2 copy SHORTERRORS
  693.     { (%%[ Error: ) print =only flush
  694.       (; OffendingCommand: ) print =only ( ]%%) =
  695.     }
  696.     { (Unrecoverable error: ) print =only flush
  697.       ( in ) print = flush
  698.       count 2 gt
  699.        { (Operand stack:\n  ) print
  700.      2 1 count 3 sub { (  ) print index =only flush } for
  701.      () = flush
  702.        } if
  703.     }
  704.    ifelse
  705.    -1 0 1 //ErrorNames length 1 sub
  706.     { dup //ErrorNames exch get 3 index eq
  707.        { not exch pop exit } { pop } ifelse
  708.     }
  709.    for exch pop .quit
  710.  } bind def
  711. /.errorhandler        % <command> <errorname> .errorhandler -
  712.   {        % Detect an internal 'stopped'.
  713.     1 .instopped { null eq { pop pop stop } if } if
  714.     $error /.inerror get 1 .instopped { pop } { pop true } ifelse
  715.      { .unstoppederrorhandler
  716.      } if    % detect error recursion
  717.     $error /globalmode .currentglobal false .setglobal put
  718.     $error /.inerror true put
  719.     $error /newerror true put
  720.     $error exch /errorname exch put
  721.     $error exch /command exch put
  722.     $error /recordstacks get $error /errorname get /VMerror ne and
  723.      {        % Attempt to store the stack contents atomically.
  724.        count array astore dup $error /ostack 4 -1 roll
  725.        countexecstack array execstack $error /estack 3 -1 roll
  726.        countdictstack array dictstack $error /dstack 3 -1 roll
  727.        put put put aload pop
  728.      }
  729.      { $error /dstack .undef
  730.        $error /estack .undef
  731.        $error /ostack .undef
  732.      }
  733.     ifelse
  734.     $error /position currentfile status
  735.      { currentfile { fileposition } .internalstopped { pop null } if
  736.      }
  737.      {        % If this was a scanner error, the file is no longer current,
  738.         % but the command holds the file, which may still be open.
  739.        $error /command get dup type /filetype eq
  740.         { { fileposition } .internalstopped { pop null } if }
  741.         { pop null }
  742.        ifelse
  743.      }
  744.     ifelse put
  745.         % During initialization, we don't reset the allocation
  746.         % mode on errors.
  747.     $error /globalmode get $error /.nosetlocal get and .setglobal
  748.     $error /.inerror false put
  749.     stop
  750.   } bind def
  751. % Define the standard handleerror.  We break out the printing procedure
  752. % (.printerror) so that it can be extended for binary output
  753. % if the Level 2 facilities are present.
  754.   /.printerror
  755.    { $error begin
  756.        /command load errorname SHORTERRORS
  757.     { (%%[ Error: ) print =only flush
  758.       (; OffendingCommand: ) print =only
  759.       errorinfo dup null eq {
  760.         pop
  761.       } {
  762.         (;\nErrorInfo:) print
  763.         dup type /arraytype eq
  764.           { { ( ) print =only } forall }
  765.           { ( ) print =only }
  766.         ifelse
  767.       } ifelse
  768.           ( ]%%) = flush
  769.     }
  770.     { (Error: ) print ==only flush
  771.       ( in ) print ==only flush
  772.       errorinfo dup null eq {
  773.         pop
  774.       } {
  775.         (\nAdditional information: ) print ==only flush
  776.       } ifelse
  777.       .printerror_long
  778.     }
  779.        ifelse
  780.        .clearerror
  781.      end
  782.      flush
  783.     } bind def     
  784.   /.printerror_long            % long error printout,
  785.                     % $error is on the dict stack
  786.    {    % Push the (anonymous) stack printing procedure.
  787.     %  <heading> <==flag> <override-name> <stackname> proc
  788.        {
  789.      currentdict exch .knownget    % stackname defined in $error?
  790.      {
  791.        4 1 roll            % stack: <stack> <head> <==flag> <over>
  792.        errordict exch .knownget    % overridename defined?
  793.        { 
  794.          exch pop exch pop exec    % call override with <stack>
  795.        }
  796.        { 
  797.          exch print exch        % print heading. stack <==flag> <stack>
  798.          1 index not { () = } if
  799.          { 1 index { (\n    ) } { (   ) } ifelse print
  800.            dup type /dicttype eq
  801.            {
  802.          (--dict:) print
  803.          dup rcheck {
  804.            dup length =only (/) print dup maxlength =only
  805.            dup wcheck not { ((ro)) print } if
  806.          } if
  807.          /gcheck where {
  808.            pop gcheck { ((G)) } { ((L)) } ifelse print
  809.          } {
  810.            pop
  811.          } ifelse (--) print
  812.            }
  813.            {
  814.          dup type /stringtype eq 2 index or
  815.          { ==only } { =only } ifelse
  816.            } ifelse
  817.          } forall
  818.          pop
  819.        }
  820.        ifelse            % overridden
  821.      }
  822.      { pop pop pop
  823.      }
  824.      ifelse                % stack known
  825.        }
  826.  
  827.        (\nOperand stack:) OSTACKPRINT /.printostack /ostack 4 index exec
  828.        (\nExecution stack:) ESTACKPRINT /.printestack /estack 4 index exec
  829.        (\nBacktrace:) true /.printbacktrace /backtrace 4 index exec
  830.        (\nDictionary stack:) false /.printdstack /dstack 4 index exec
  831.        () =
  832.        pop    % printing procedure
  833.  
  834.        errorname /VMerror eq
  835.     { (VM status:) print mark vmstatus
  836.       counttomark { ( ) print counttomark -1 roll dup =only } repeat
  837.       cleartomark () =
  838.     } if
  839.  
  840.        .languagelevel 2 ge
  841.     { (Current allocation mode is ) print
  842.       globalmode { (global\n) } { (local\n) } ifelse print
  843.     } if
  844.  
  845.        .oserrno dup 0 ne
  846.     { (Last OS error: ) print
  847.       errorname /VMerror ne
  848.        { dup .oserrorstring { = pop } { = } ifelse }
  849.        { = }
  850.       ifelse
  851.     }
  852.     { pop
  853.     }
  854.        ifelse
  855.  
  856.        position null ne
  857.     { (Current file position is ) print position = }
  858.        if
  859.  
  860.    } bind def
  861. % Define a procedure for clearing the error indication.
  862. /.clearerror
  863.  { $error /newerror false put
  864.    $error /errorname null put
  865.    $error /errorinfo null put
  866.    0 .setoserrno
  867.  } bind def
  868.  
  869. % Define $error.  This must be in local VM.
  870. .currentglobal false .setglobal
  871. /$error 40 dict .forcedef    % $error is local, systemdict is global
  872.         % newerror, errorname, command, errorinfo,
  873.         % ostack, estack, dstack, recordstacks,
  874.         % binary, globalmode,
  875.         % .inerror, .nosetlocal, position,
  876.         % plus extra space for badly designed error handers.
  877. $error begin
  878.   /newerror false def
  879.   /recordstacks true def
  880.   /binary false def
  881.   /globalmode .currentglobal def
  882.   /.inerror false def
  883.   /.nosetlocal true def
  884.   /position null def
  885. end
  886. % Define errordict similarly.  It has one entry per error name,
  887. %   plus handleerror.
  888. /errordict ErrorNames length 1 add dict
  889. .forcedef        % errordict is local, systemdict is global
  890. .setglobal        % contents of errordict are global
  891. errordict begin
  892.   ErrorNames
  893.    { mark 1 index systemdict /.errorhandler get /exec load .packtomark cvx def
  894.    } forall
  895. % The handlers for interrupt and timeout are special; there is no
  896. % 'current object', so they push their own name.
  897.    { /interrupt /timeout }
  898.    { mark 1 index dup systemdict /.errorhandler get /exec load .packtomark cvx def
  899.    } forall
  900. /handleerror
  901.  { /.printerror .systemvar exec
  902.  } bind def
  903. end
  904.  
  905. % Define the [write]==[only] procedures.
  906. /.dict 8 dict dup
  907. begin def
  908.   /.cvp {1 index exch 1 .writecvp} bind def
  909.   /.p {1 index exch writestring} bind def
  910.   /.p1 {2 index exch writestring} bind def
  911.   /.p2 {3 index exch writestring} bind def
  912.   /.print
  913.     { dup type .dict exch .knownget { exec } { .cvp } ifelse
  914.     } bind def
  915.   /arraytype
  916.     {dup rcheck
  917.       {() exch dup xcheck
  918.         {({) .p2
  919.          {exch .p1
  920.           1 index exch .print pop ( )} forall
  921.          (})}
  922.         {([) .p2
  923.          {exch .p1
  924.           1 index exch .print pop ( )} forall
  925.          (])}
  926.        ifelse exch pop .p}
  927.       {.cvp}
  928.      ifelse} bind def
  929.   /packedarraytype /arraytype load def
  930. {//.dict begin .print pop end}
  931.   bind
  932. end
  933.  
  934. /write==only exch def
  935. /write== {1 index exch write==only (\n) writestring} bind def
  936. /==only { (%stdout) (w) file exch write==only } bind def
  937. /== {==only (\n) print} bind def
  938.  
  939. % Define [write]===[only], an extension that prints dictionaries
  940. % in readable form and doesn't truncate strings.
  941. /.dict /write==only load 0 get dup length 2 add dict .copydict dup
  942. begin def
  943.   /dicttype
  944.     { dup rcheck
  945.        { (<< ) .p1
  946.           { 2 index 3 -1 roll .print pop ( ) .p1
  947.         1 index exch .print pop ( ) .p
  948.           }
  949.          forall (>>) .p
  950.        }
  951.        { .cvp
  952.        }
  953.       ifelse
  954.     } bind def
  955.   /stringtype
  956.     { 1 index exch 2 .writecvp
  957.     } bind def
  958.  
  959. {//.dict begin .print pop end}
  960.   bind
  961. end
  962.  
  963. /write===only exch def
  964. /write=== {1 index exch write===only (\n) writestring} bind def
  965. /===only { (%stdout) (w) file exch write===only } bind def
  966. /=== { ===only (\n) print } bind def
  967.  
  968. (END PROCS) VMDEBUG
  969.  
  970. % Define the font directory.
  971. /FontDirectory false .setglobal 100 dict true .setglobal
  972. .forcedef        % FontDirectory is local, systemdict is global
  973.  
  974. % Define the encoding dictionary.
  975. /EncodingDirectory 10 dict def    % enough for Level 2 + PDF standard encodings
  976.  
  977. % Define .findencoding.  (This is redefined in Level 2.)
  978. /.findencoding
  979.  { //EncodingDirectory exch get exec
  980.  } bind def
  981. /.defineencoding
  982.  { //EncodingDirectory 3 1 roll put
  983.  } bind def
  984. % If we've got the composite font extensions, define findencoding.
  985. % To satisfy the Genoa FTS, findencoding must be a procedure, not an operator.
  986. /rootfont where { pop /findencoding { .findencoding } def } if
  987.  
  988. % Define .registerencoding.
  989. % NOTE: the name registeredencodings is known to (initialized by and shared
  990. % with) the interpreter.
  991. /.registerencoding {    % <index> <array> .registerencoding -
  992.     % Check that the array is indexable.
  993.     % (It might still be a string, but then the .namestring will fail.)
  994.   dup 0 0 getinterval pop
  995.     % Check that all the elements of the array are names.
  996.   dup { .namestring pop } forall
  997.     % Do the store.
  998.   //registeredencodings 2 index 2 index readonly put pop pop
  999. } bind odef
  1000. systemdict /registeredencodings .undef
  1001.  
  1002. % Load StandardEncoding.
  1003. %% Replace 1 (gs_std_e.ps)
  1004. (gs_std_e.ps) dup runlibfile VMDEBUG
  1005.  
  1006. % Load ISOLatin1Encoding.
  1007. %% Replace 1 (gs_il1_e.ps)
  1008. (gs_il1_e.ps) dup runlibfile VMDEBUG
  1009.  
  1010. % Define stubs for the Symbol and Dingbats encodings.
  1011. % Note that the first element of the procedure must be the file name,
  1012. % since gs_lev2.ps extracts it to set up the Encoding resource category.
  1013.  
  1014.   /SymbolEncoding { /SymbolEncoding .findencoding } bind def
  1015. %% Replace 3 (gs_sym_e.ps)
  1016.   EncodingDirectory /SymbolEncoding
  1017.    { (gs_sym_e.ps) //systemdict begin runlibfile SymbolEncoding end }
  1018.   bind put
  1019.  
  1020.   /DingbatsEncoding { /DingbatsEncoding .findencoding } bind def
  1021. %% Replace 3 (gs_dbt_e.ps)
  1022.   EncodingDirectory /DingbatsEncoding
  1023.    { (gs_dbt_e.ps) //systemdict begin runlibfile DingbatsEncoding end }
  1024.   bind put
  1025.  
  1026. (END FONTDIR/ENCS) VMDEBUG
  1027.  
  1028. % Construct a dictionary of all available devices.
  1029. % These are (read-only) device prototypes that can't be
  1030. % installed or have their parameters changed.  For this reason,
  1031. % the value in the dictionary is actually a 2-element writable array,
  1032. % to allow us to create a default instance of the prototype on demand.
  1033.  
  1034.     % Loop until the .getdevice gets a rangecheck.
  1035. errordict /rangecheck 2 copy get
  1036. errordict /rangecheck { pop stop } put    % pop the command
  1037.   0 { {dup .getdevice exch 1 add} loop} .internalstopped pop
  1038.   1 add dict  /devicedict 1 index def
  1039.   begin            % 2nd copy of count is on stack
  1040.    { dup .devicename exch
  1041.      dup wcheck { dup } { null } ifelse 2 array astore def
  1042.    } repeat
  1043.   end
  1044. put        % errordict /rangecheck
  1045. .clearerror
  1046. /devicenames devicedict { pop } forall devicedict length packedarray def
  1047.  
  1048. % Determine the default device.
  1049. /defaultdevice DISPLAYING
  1050.  { systemdict /DEVICE .knownget
  1051.     { devicedict 1 index known not
  1052.        { (Unknown device: ) print =
  1053.      flush /defaultdevice cvx 1 .quit
  1054.        }
  1055.       if
  1056.     }
  1057.     { 0 .getdevice .devicename
  1058.     }
  1059.    ifelse
  1060.  }
  1061.  { /nullpage
  1062.  }
  1063. ifelse
  1064. /.defaultdevicename 1 index def
  1065. finddevice    % make a copy
  1066. def
  1067. devicedict /Default devicedict .defaultdevicename get put
  1068.  
  1069. (END DEVS) VMDEBUG
  1070.  
  1071. % Define statusdict, for the benefit of programs
  1072. % that think they are running on a LaserWriter or similar printer.
  1073. %% Replace 1 (gs_statd.ps)
  1074. (gs_statd.ps) runlibfile
  1075.  
  1076. (END STATD) VMDEBUG
  1077.  
  1078. % Load the standard font environment.
  1079. %% Replace 1 (gs_fonts.ps)
  1080. (gs_fonts.ps) runlibfile
  1081.  
  1082. (END GS_FONTS) VMDEBUG
  1083.  
  1084. % Define the default halftone screen and BG/UCR functions now, so that
  1085. % it will bind in the original definitions of set[color]screen.
  1086. % We make this a procedure so we can call it again when switching devices.
  1087.  
  1088. % Use an ordered dither for low-resolution devices.
  1089. /.setloreshalftone {    % <dpi> .setloreshalftone -
  1090.     % The following 'ordered dither' spot function was contributed by
  1091.     % Gregg Townsend.  Thanks, Gregg!
  1092.    16.001 div 0            % not 16: avoids rounding problems
  1093.     { 1 add 7.9999 mul cvi exch 1 add 7.9999 mul cvi 16 mul add <
  1094.     0E 8E 2E AE 06 86 26 A6 0C 8C 2C AC 04 84 24 A4
  1095.     CE 4E EE 6E C6 46 E6 66 CC 4C EC 6C C4 44 E4 64
  1096.     3E BE 1E 9E 36 B6 16 96 3C BC 1C 9C 34 B4 14 94
  1097.     FE 7E DE 5E F6 76 D6 56 FC 7C DC 5C F4 74 D4 54
  1098.     01 81 21 A1 09 89 29 A9 03 83 23 A3 0B 8B 2B AB
  1099.     C1 41 E1 61 C9 49 E9 69 C3 43 E3 63 CB 4B EB 6B
  1100.     31 B1 11 91 39 B9 19 99 33 B3 13 93 3B BB 1B 9B
  1101.     F1 71 D1 51 F9 79 D9 59 F3 73 D3 53 FB 7B DB 5B
  1102.     0D 8D 2D AD 05 85 25 A5 0F 8F 2F AF 07 87 27 A7
  1103.     CD 4D ED 6D C5 45 E5 65 CF 4F EF 6F C7 47 E7 67
  1104.     3D BD 1D 9D 35 B5 15 95 3F BF 1F 9F 37 B7 17 97
  1105.     FD 7D DD 5D F5 75 D5 55 FF 7F DF 5F F7 77 D7 57
  1106.     02 82 22 A2 0A 8A 2A AA 00 80 20 A0 08 88 28 A8
  1107.     C2 42 E2 62 CA 4A EA 6A C0 40 E0 60 C8 48 E8 68
  1108.     32 B2 12 92 3A BA 1A 9A 30 B0 10 90 38 B8 18 98
  1109.     F2 72 D2 52 FA 7A DA 5A F0 70 D0 50 F8 78 D8 58
  1110.      > exch get 256 div
  1111.     }
  1112.    bind
  1113.         % Use correct, per-plane screens for CMYK devices only.
  1114.    //systemdict /setcolorscreen known processcolors 4 eq and
  1115.     { 3 copy 6 copy //setcolorscreen }
  1116.     { //setscreen }
  1117.    ifelse
  1118. } bind def
  1119. /.setloresscreen {    % <dpi> .setloresscreen -
  1120.   .setloreshalftone
  1121.   0 array cvx settransfer    % Genoa CET won't accept a packed array!
  1122.   /setstrokeadjust where { pop true setstrokeadjust } if
  1123. } bind def
  1124. % Use a 45-degree spot screen for high-resolution devices.
  1125. /.sethireshalftone {    % <dpi> .sethireshalftone <doscreen>
  1126.     % According to information published by Hewlett-Packard,
  1127.     % they use a 60 line screen on 300 DPI printers and
  1128.     % an 85 line screen on 600 DPI printers.
  1129.     % However, we use a 106 line screen, which produces smoother-
  1130.     % looking shades but fewer of them (32 vs. 50).
  1131.     % 46 was suggested as a good frequency value for printers
  1132.     % between 200 and 400 DPI, so we use it for lower resolutions.
  1133.     % Imagesetters need even higher frequency screens.
  1134.    //systemdict /DITHERPPI known
  1135.     { DITHERPPI
  1136.     }
  1137.     { dup cvi 100 idiv 15 .min
  1138.        {null 46 46 60 60 60 106 106 106 106 133 133 133 133 133 150}
  1139.       exch get
  1140.      }
  1141.    ifelse
  1142.    1 index 4.01 div .min    % at least a 4x4 cell
  1143.    45
  1144.     % The following screen algorithm is used by permission of the author.
  1145.     { 1 add 180 mul cos 1 0.08 add mul exch 2 add 180 mul cos 
  1146.       1 0.08 sub mul add 2 div % (C) 1989 Berthold K.P. Horn
  1147.     }
  1148.    bind
  1149.     % Determine whether we have lots of process colors.
  1150.     % If so, don't bother with color screening or gamma correction.
  1151.     % Also don't do gamma correction on very high-resolution devices.
  1152.     % (This should depend on dot gain, not resolution, but we don't
  1153.     % currently have a way to determine this.)
  1154.    currentdevice mark
  1155.      /RedValues 0 /GreenValues 0 /BlueValues 0 /GrayValues 0
  1156.    .dicttomark .getdeviceparams
  1157.    counttomark 2 idiv 1 sub { exch pop min } repeat
  1158.    exch pop exch pop 32 lt 4 index 800 lt and 5 1 roll
  1159.     % Stack: doscreen dpi freq angle proc
  1160.     % Ghostscript currently doesn't use correct, per-plane halftones
  1161.     % unless setcolorscreen has been executed.  Since these are
  1162.     % computationally much more expensive than binary halftones,
  1163.     % we check to make sure they are really warranted, i.e., we have
  1164.     % a high-resolution CMYK device (i.e., not a display) with
  1165.     % fewer than 5 bits per plane (i.e., not a true-color device).
  1166.    4 -1 roll 150 ge
  1167.     { /setcolorscreen where
  1168.        { pop //systemdict /COLORSCREEN known
  1169.       { COLORSCREEN }
  1170.       { 3 index }
  1171.      ifelse
  1172.      dup false ne
  1173.       { 4 1 roll 3 copy 6 copy 13 -1 roll
  1174.     % For really high-quality screening on printers, we need to
  1175.     % give each plane its own screen angle.  Unfortunately,
  1176.     % this currently has very large space and time costs.
  1177.         true eq        % true => different angles,
  1178.                 % 0 => same angles
  1179.          { { 45 90 15 75 } { 3 1 roll exch pop 12 3 roll } forall
  1180.          }
  1181.         if //setcolorscreen
  1182.       }
  1183.       { pop //setscreen    % false => single binary screen
  1184.       }
  1185.      ifelse
  1186.        }
  1187.        { //setscreen        % setcolorscreen not known
  1188.        }
  1189.       ifelse
  1190.     }
  1191.     { //setscreen            % not high resolution
  1192.     }
  1193.    ifelse
  1194. } bind def
  1195. /.sethiresscreen {    % <dpi> .sethiresscreen -
  1196.   .sethireshalftone
  1197.             % Stack: doscreen
  1198.     {    % Set the transfer function to lighten up the grays.
  1199.     % We correct at the high end so that very light grays
  1200.     % don't disappear completely if they darken <1 screen pixel.
  1201.     % Parameter values closer to 1 are better for devices with
  1202.     % less dot spreading; lower values are better with more spreading.
  1203.     % The value 0.8 is a compromise that will probably please no one!
  1204.     %
  1205.     % Because of a bug in FrameMaker, we have to accept operands
  1206.     % outside the valid range of [0..1].
  1207.       { dup dup 0.0 gt exch 1.0 lt and
  1208.      { 0.8 exp dup dup 0.9375 gt exch 0.999 lt and    % > 15/16
  1209.         { .currentscreenlevels 1 sub    % tweak to avoid boundary
  1210.           1 exch div 1 exch sub .min
  1211.         }
  1212.        if
  1213.      }
  1214.     if
  1215.       }
  1216.     }
  1217.     {    % Set the transfer function to the identity.
  1218.       0 array cvx        % Genoa CET won't accept a packed array!
  1219.     }
  1220.    ifelse settransfer
  1221.    /setstrokeadjust where { pop false setstrokeadjust } if
  1222.     % Increase fill adjustment so that we effectively use Adobe's
  1223.     % any-part-of-pixel rule.
  1224.    0.5 .setfilladjust
  1225. } bind def
  1226. % Set the default screen and BG/UCR.
  1227. /.setdefaultbgucr {
  1228.   systemdict /setblackgeneration known {
  1229.     { pop 0 } dup setblackgeneration setundercolorremoval
  1230.   } if
  1231. } bind def
  1232. /.useloresscreen {    % - .useloresscreen <bool>
  1233.     % Compute min(|dpi x|,|dpi y|) as the definition of the resolution.
  1234.   72 72 matrix defaultmatrix dtransform abs exch abs .min
  1235.   dup 150 lt //systemdict /DITHERPPI known not and
  1236. } bind def
  1237.  
  1238. % The following implementation uses LL2 extensions, but only in stopped
  1239. % contexts so that with LL1, the .set??reshalftone will be used.
  1240. %
  1241. %    - .getdefaulthalftone <halftonedict> true    if default found
  1242. %                  false            
  1243. /.getdefaulthalftone {
  1244.   % try the device to see if it has a default halftone
  1245.   { currentdevice /HalftoneDefault gsgetdeviceprop } stopped
  1246.   { pop pop false }        % no device property
  1247.   { dup type /dicttype eq { true } { pop false } ifelse }
  1248.   ifelse
  1249.   % stack: <halftonedict> true    if default found
  1250.   %         false          not found
  1251.   dup not
  1252.   { % device did not provide a default, try Resource
  1253.     pop { /Default /Halftone /findresource .systemvar exec } stopped 
  1254.     { pop pop false } { true } ifelse
  1255.   }
  1256.   if
  1257. } bind def
  1258.  
  1259. /.setdefaulthalftone {
  1260.   .getdefaulthalftone 
  1261.   { sethalftone }
  1262.   { % default not found
  1263.     .useloresscreen { .setloreshalftone } { .sethireshalftone pop } ifelse
  1264.   }
  1265.   ifelse
  1266. } bind def
  1267.  
  1268. /.setdefaultscreen {
  1269.   .useloresscreen { .setloresscreen } { .sethiresscreen } ifelse
  1270.   .setdefaultbgucr
  1271. } bind def
  1272.  
  1273. % Load the initialization files for optional features.
  1274. %% Replace 4 INITFILES
  1275. systemdict /INITFILES known
  1276.  { INITFILES { dup runlibfile VMDEBUG } forall
  1277.  }
  1278. if
  1279.  
  1280. % If Level 2 (or higher) functionality is implemented, enable it now.
  1281. /.setlanguagelevel where {
  1282.   pop 2 .setlanguagelevel
  1283.     % If the resource machinery is loaded, fix up some things now.
  1284.   /.fixresources where { pop .fixresources } if
  1285. } if
  1286. /ll3dict where {
  1287.   pop 3 .setlanguagelevel
  1288. } if
  1289.  
  1290. (END INITFILES) VMDEBUG
  1291.  
  1292. % Create a null font.  This is the initial font.
  1293. 8 dict dup begin
  1294.   /FontMatrix [ 1 0 0 1 0 0 ] readonly def
  1295.   /FontType 3 def
  1296.   /FontName () def
  1297.   /Encoding StandardEncoding def
  1298.   /FontBBox { 0 0 0 0 } readonly def % executable is bogus, but customary ...
  1299.   /BuildChar { pop pop 0 0 setcharwidth } bind def
  1300.   /PaintType 0 def        % shouldn't be needed!
  1301. end
  1302. /NullFont exch definefont setfont
  1303.  
  1304. % Define NullFont as the font.
  1305. /NullFont currentfont def
  1306.  
  1307. % Load initial fonts from FONTPATH directories, Fontmap file,
  1308. % and/or .getccfont as appropriate.
  1309. .loadinitialfonts
  1310.  
  1311. % Remove NullFont from FontDirectory, so it can't be accessed by mistake.
  1312. /undefinefont where {
  1313.   pop /NullFont undefinefont
  1314. } {
  1315.   FontDirectory /NullFont .undef
  1316. } ifelse
  1317.  
  1318. (END FONTS) VMDEBUG
  1319.  
  1320. % Restore the real definition of runlibfile.
  1321. /runlibfile /.runlibfile load def
  1322. currentdict /.runlibfile .undef
  1323.  
  1324. % Bind all the operators defined as procedures.
  1325. /.bindoperators        % binds operators in currentdict
  1326.  { % Temporarily disable the typecheck error.
  1327.    errordict /typecheck 2 copy get
  1328.    errordict /typecheck { pop } put    % pop the command
  1329.    currentdict
  1330.     { dup type /operatortype eq
  1331.        { % This might be a real operator, so bind might cause a typecheck,
  1332.      % but we've made the error a no-op temporarily.
  1333.      .bind        % do a real bind even if NOBIND is set
  1334.        }
  1335.       if pop pop
  1336.     } forall
  1337.    put
  1338.  } def
  1339. NOBIND DELAYBIND or not { .bindoperators } if
  1340.  
  1341. % Establish a default environment.
  1342.  
  1343. defaultdevice
  1344. % The following line used to skip setting of page size and resolution if
  1345. % NODISPLAY was selected.  We think this was only to save time and memory,
  1346. % and it is a bad idea because it prevents setting the resolution in this
  1347. % situation, which pstoedit (among other programs) relies on.
  1348. %DISPLAYING not { setdevice (%END DISPLAYING) .skipeof } if
  1349. systemdict /DEVICEWIDTH known
  1350. systemdict /DEVICEHEIGHT known or
  1351. systemdict /DEVICEWIDTHPOINTS known or
  1352. systemdict /DEVICEHEIGHTPOINTS known or
  1353. systemdict /DEVICEXRESOLUTION known or
  1354. systemdict /DEVICEYRESOLUTION known or
  1355. systemdict /PAPERSIZE known or
  1356. not { (%END DEVICE) .skipeof } if
  1357. % Let DEVICE{WIDTH,HEIGHT}[POINTS] override PAPERSIZE.
  1358. systemdict /PAPERSIZE known
  1359. systemdict /DEVICEWIDTH known not and
  1360. systemdict /DEVICEHEIGHT known not and
  1361. systemdict /DEVICEWIDTHPOINTS known not and
  1362. systemdict /DEVICEHEIGHTPOINTS known not and
  1363.  {    % Convert the paper size to device dimensions.
  1364.    true statusdict /.pagetypenames get
  1365.     { PAPERSIZE eq
  1366.        { PAPERSIZE load
  1367.          dup 0 get /DEVICEWIDTHPOINTS exch def
  1368.          1 get /DEVICEHEIGHTPOINTS exch def
  1369.          pop false exit
  1370.        }
  1371.       if
  1372.     }
  1373.    forall
  1374.     { (Unknown paper size: ) print PAPERSIZE ==only (.) =
  1375.     }
  1376.    if
  1377.  }
  1378. if
  1379. % Adjust the device parameters per the command line.
  1380. % It is possible to specify resolution, pixel size, and page size;
  1381. % since any two of these determine the third, conflicts are possible.
  1382. % We simply pass them to .setdeviceparams and let it sort things out.
  1383.    mark /HWResolution null /HWSize null /PageSize null .dicttomark
  1384.    .getdeviceparams .dicttomark begin
  1385.    mark
  1386.     % Check for resolution.
  1387.    /DEVICEXRESOLUTION where dup
  1388.     { exch pop HWResolution 0 DEVICEXRESOLUTION put }
  1389.    if
  1390.    /DEVICEYRESOLUTION where dup
  1391.     { exch pop HWResolution 1 DEVICEYRESOLUTION put }
  1392.    if
  1393.    or { /HWResolution HWResolution } if
  1394.     % Check for device sizes specified in pixels.
  1395.    /DEVICEWIDTH where dup
  1396.     { exch pop HWSize 0 DEVICEWIDTH put }
  1397.    if
  1398.    /DEVICEHEIGHT where dup
  1399.     { exch pop HWSize 1 DEVICEHEIGHT put }
  1400.    if
  1401.    or { /HWSize HWSize } if
  1402.     % Check for device sizes specified in points.
  1403.    /DEVICEWIDTHPOINTS where dup
  1404.     { exch pop PageSize 0 DEVICEWIDTHPOINTS put }
  1405.    if
  1406.    /DEVICEHEIGHTPOINTS where dup
  1407.     { exch pop PageSize 1 DEVICEHEIGHTPOINTS put }
  1408.    if
  1409.    or { /PageSize PageSize } if
  1410.     % Check whether any parameters were set.
  1411.    dup mark eq { pop } { defaultdevice putdeviceprops } ifelse
  1412.    end
  1413. %END DEVICE
  1414. % Set any device properties defined on the command line.
  1415. % If BufferSpace is defined but not MaxBitmap, set MaxBitmap to BufferSpace.
  1416. systemdict /BufferSpace known
  1417. systemdict /MaxBitmap known not and
  1418.  { systemdict /MaxBitmap BufferSpace put
  1419.  } if
  1420. dup getdeviceprops
  1421. counttomark 2 idiv
  1422.  { systemdict 2 index known
  1423.     { pop dup load counttomark 2 roll }
  1424.     { pop pop }
  1425.    ifelse
  1426.  } repeat
  1427. counttomark dup 0 ne
  1428.  { 2 add -1 roll putdeviceprops }
  1429.  { pop pop }
  1430. ifelse
  1431. % If the initial device parameters are invalid, the setdevice may fail.
  1432. % Trap this and produce a reasonable error message.
  1433. { setdevice }        % does an erasepage
  1434. DEBUG { exec false } { .internalstopped } ifelse {
  1435.   (**** Unable to open the initial device, quitting.) = 1 .quit
  1436. } if
  1437.  
  1438. % If the media size is fixed, update the current page device dictionary.
  1439. FIXEDMEDIA
  1440. dup { pop systemdict /.currentpagedevice known } if
  1441. dup { pop .currentpagedevice exch pop } if
  1442. not { (%END MEDIA) .skipeof } if
  1443. currentpagedevice dup length dict .copydict
  1444. dup /Policies
  1445.     % Stack: <pagedevice> <pagedevice> /Policies
  1446. 1 index /InputAttributes
  1447. 2 copy get dup length dict .copydict
  1448.     % Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
  1449.     %   /InputAttributes <inputattrs'>
  1450. dup 0 2 copy get dup length dict .copydict
  1451.     % Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
  1452.     %   /InputAttributes <inputattrs'> <inputattrs'> 0 <attrs0'>
  1453. dup /PageSize 7 index /PageSize get
  1454. put                % PageSize in 0
  1455. put                % 0 in InputAttributes
  1456. put                % InputAttributes in pagedevice
  1457. % Also change the page size policy so we don't get an error.
  1458.     % Stack: <pagedevice> <pagedevice> /Policies
  1459. 2 copy get dup length dict .copydict
  1460.     % Stack: <pagedevice> <pagedevice> /Policies <policies'>
  1461. dup /PageSize 7 put        % PageSize in Policies
  1462. put                % Policies in pagedevice
  1463. .setpagedevice
  1464. %END MEDIA
  1465. %END DISPLAYING
  1466.  
  1467. (END DEVICE) VMDEBUG
  1468.  
  1469. % Establish a default upper limit in the character cache,
  1470. % namely, enough room for a 18-point character at the resolution
  1471. % of the default device, or for a character consuming 1% of the
  1472. % maximum cache size, whichever is larger.
  1473. mark
  1474.     % Compute limit based on character size.
  1475.   18 dup dtransform
  1476.   exch abs cvi 31 add 32 idiv 4 mul    % X raster
  1477.   exch abs cvi mul        % Y
  1478.     % Compute limit based on allocated space.
  1479.   cachestatus pop pop pop pop pop exch pop 0.01 mul cvi
  1480.   .max dup 10 idiv exch
  1481. setcacheparams
  1482. % Conditionally disable the character cache.
  1483. NOCACHE { 0 setcachelimit } if
  1484.  
  1485. (END CONFIG) VMDEBUG
  1486.  
  1487. % Initialize graphics.
  1488.  
  1489. .setdefaultscreen
  1490. initgraphics
  1491.  
  1492. % The interpreter relies on there being at least 2 entries
  1493. % on the graphics stack.  Establish the second one now.
  1494. gsave
  1495.  
  1496. % Define some control sequences as no-ops.
  1497. % This is a hack to get around problems
  1498. % in some common PostScript-generating applications.
  1499. <04> cvn { } def        % Apple job separator
  1500. <0404> cvn { } def        % two of the same
  1501. <1b> cvn { } def        % MS Windows LaserJet 4 prologue
  1502.                 % (UEL = ESC %-12345X)
  1503. <1b45> cvn { } def        % PJL reset prologue (ESC E)
  1504. <1b451b> cvn { } def        % PJL reset epilogue (ESC E + UEL)
  1505. <041b> cvn { } def        % MS Windows LaserJet 4 epilogue (^D + UEL)
  1506. (\001M) cvn            % TBCP initiator
  1507.  { currentfile /TBCPDecode filter cvx exec
  1508.  } bind def
  1509. /@PJL                % H-P job control
  1510.  { currentfile //=string readline { pop } if
  1511.  } bind def
  1512.  
  1513. % If we want a "safer" system, disable some obvious ways to cause havoc.
  1514. SAFER not { (%END SAFER) .skipeof } if
  1515. /file
  1516.  { dup (r) eq 2 index (%pipe*) .stringmatch not and
  1517.    2 index (%std*) .stringmatch or
  1518.     { file }
  1519.     { /invalidfileaccess signalerror }
  1520.    ifelse
  1521.  } .bind odef
  1522. /renamefile { /invalidfileaccess signalerror } odef
  1523. /deletefile { /invalidfileaccess signalerror } odef
  1524. /putdeviceprops
  1525.  { counttomark
  1526.    dup 2 mod 0 eq { pop /rangecheck signalerror } if
  1527.    3 2 3 2 roll
  1528.     { dup index /OutputFile eq  
  1529.        { -2 roll 
  1530.          dup () ne { /putdeviceprops load /invalidfileaccess signalerror } if
  1531.          3 -1 roll
  1532.        }
  1533.        { pop
  1534.        }
  1535.       ifelse
  1536.     } for
  1537.    putdeviceprops
  1538.  } .bind odef
  1539.  
  1540. %END SAFER
  1541.  
  1542. % If we delayed binding, make it possible to do it later.
  1543. /.bindnow {
  1544.   //systemdict begin .bindoperators end
  1545.   % Temporarily disable the typecheck error.
  1546.   errordict /typecheck 2 copy get
  1547.   errordict /typecheck { pop } put    % pop the command
  1548.   0 1 .delaycount 1 sub { .delaybind exch get .bind pop } for
  1549.   //systemdict /.delaybind {} .forceput    % reclaim the space
  1550.   //systemdict /.bindnow .forceundef    % ditto
  1551.   put
  1552.   //systemdict /.forcedef .forceundef        % remove temptation
  1553.   //systemdict /.forceput .forceundef        % ditto
  1554.   //systemdict /.forceundef .forceundef        % ditto
  1555. } .bind odef
  1556.  
  1557. % Turn off array packing, since some PostScript code assumes that
  1558. % procedures are writable.
  1559. false setpacking
  1560.  
  1561. (END INIT) VMDEBUG
  1562.  
  1563. /.currentuserparams where {
  1564.   pop
  1565.     % Remove real user params from psuserparams.
  1566.   mark .currentuserparams counttomark 2 idiv {
  1567.     pop psuserparams exch undef
  1568.   } repeat pop
  1569.     % Update the copy of the user parameters.
  1570.   mark .currentuserparams counttomark 2 idiv {
  1571.     userparams 3 1 roll .forceput    % userparams is read-only
  1572.   } repeat pop
  1573.     % Turn on idiom recognition, if available.
  1574.   currentuserparams /IdiomRecognition known {
  1575.     /IdiomRecognition true .definepsuserparam
  1576.   } if
  1577.   psuserparams readonly pop
  1578.   systemdict /.definepsuserparam undef
  1579.     % Save a copy of userparams for use with save/restore
  1580.     % (and, if implemented, context switching).
  1581.   .currentglobal false .setglobal
  1582.      mark .currentuserparams psuserparams { } forall .dicttomark readonly
  1583.      /userparams exch .forcedef        % systemdict is read-only
  1584.   .setglobal
  1585. } if
  1586. /.currentsystemparams where {
  1587.   pop
  1588.     % Remove real system params from pssystemparams.
  1589.   mark .currentsystemparams counttomark 2 idiv {
  1590.     pop pssystemparams exch .forceundef
  1591.   } repeat pop
  1592. } if
  1593.  
  1594. % Conditionally turn image interpolation on or off.
  1595. currentdict /INTERPOLATE known not { (%END INTERPOLATE) .skipeof } if
  1596. /.interpolate {
  1597.   dup /Interpolate .knownget not { false } if
  1598.   /INTERPOLATE .systemvar ne {
  1599.     dup gcheck .currentglobal exch .setglobal
  1600.     exch dup length dict copy
  1601.     dup /Interpolate /INTERPOLATE .systemvar put
  1602.     exch .setglobal
  1603.   } if
  1604. } bind odef
  1605. /image {
  1606.   dup type /dicttype eq {
  1607.     .interpolate image
  1608.   } {
  1609.     /INTERPOLATE .systemvar {
  1610.       8 dict begin
  1611.       /ImageType 1 def
  1612.       /DataSource 1 index def
  1613.       /ImageMatrix 2 index def
  1614.       /BitsPerComponent 3 index def
  1615.       /Decode {0 1} def
  1616.       /Height 4 index def
  1617.       /Width 5 index def
  1618.       /Interpolate true def
  1619.       currentdict end
  1620.       gsave /DeviceGray setcolorspace image grestore
  1621.       5 { pop } repeat
  1622.     } {
  1623.       image
  1624.     } ifelse
  1625.   } ifelse
  1626. } bind odef
  1627. /imagemask {
  1628.   dup type /dicttype eq {
  1629.     .interpolate imagemask
  1630.   } {
  1631.     /INTERPOLATE .systemvar {
  1632.       8 dict begin
  1633.       /ImageType 1 def
  1634.       /DataSource 1 index def
  1635.       /ImageMatrix 2 index def
  1636.       /BitsPerComponent 1 def
  1637.       2 index { {1 0} } { {0 1} } ifelse /Decode exch def
  1638.       /Height 4 index def
  1639.       /Width 5 index def
  1640.       /Interpolate true def
  1641.       currentdict end imagemask 5 { pop } repeat
  1642.     } {
  1643.       imagemask
  1644.     } ifelse
  1645.   } ifelse
  1646. } bind odef
  1647. %END INTERPOLATE
  1648.  
  1649. % Establish local VM as the default.
  1650. false /setglobal where { pop setglobal } { .setglobal } ifelse
  1651. $error /.nosetlocal false put
  1652.  
  1653. (END GLOBAL) VMDEBUG
  1654.  
  1655. /.savelocalstate where {
  1656.     % If we might create new contexts, save away copies of all dictionaries
  1657.     % referenced from systemdict that are stored in local VM,
  1658.     % and also save a copy of the initial gstate.
  1659.   pop .savelocalstate
  1660. } {
  1661.     % If we're *not* running in a multi-context system and FAKEFONTS is
  1662.     % defined, add the fake fonts to LocalFontDirectory.
  1663.   .definefakefonts    % current VM is local
  1664. } ifelse
  1665.  
  1666. % Remove systemdict entries for things that have been bound in where used
  1667. % and that shouldn't be accessible by name, and close up systemdict.
  1668. currentdict /filterdict .undef
  1669. currentdict /.cidfonttypes .undef
  1670. currentdict /.colorrenderingtypes .undef
  1671. currentdict /.formtypes .undef
  1672. currentdict /.halftonetypes .undef
  1673. currentdict /.imagetypes .undef
  1674. currentdict /.imagemasktypes .undef
  1675. currentdict /.patterntypes .undef
  1676. currentdict /.shadingtypes .undef
  1677. currentdict /.wheredict .undef
  1678. end
  1679.  
  1680. % Clean up VM, and enable GC.
  1681. /vmreclaim where
  1682.  { pop NOGC not { 2 vmreclaim 0 vmreclaim } if
  1683.  } if
  1684. DELAYBIND not {
  1685.   systemdict /.forcedef .undef        % remove temptation
  1686.   systemdict /.forceput .undef        % ditto
  1687.   systemdict /.forceundef .undef    % ditto
  1688. } if
  1689. WRITESYSTEMDICT not { systemdict readonly pop } if
  1690.  
  1691. (END GC) VMDEBUG
  1692.  
  1693. % The interpreter will run the initial procedure (start).
  1694.