home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / servis / ovladace / drivers / CPPLW9xNTgb.exe / CPP_L / Driver / GS_INIT.PS < prev    next >
Encoding:
Text File  |  1995-11-15  |  34.7 KB  |  1,166 lines

  1. %    Copyright (C) 1989, 1995 Aladdin Enterprises.  All rights reserved.
  2. %    Licensed to Zenographics Inc. (Irvine, California) by Artifex Software Inc.
  3. %    under the OEM Agreement of December 21st, 1993.
  4.  
  5. % Initialization file for the interpreter.
  6. % When this is run, systemdict is still writable.
  7.  
  8. % Comment lines of the form
  9. %    %% Replace <n> <file(s)>
  10. % indicate places where the next <n> lines should be replaced by
  11. % the contents of <file(s)>, when creating a single merged init file.
  12.  
  13. % Check the interpreter revision.  NOTE: the interpreter code requires
  14. % that the first non-comment token in this file be an integer.
  15. 333
  16. dup revision ne
  17.  { (gs: Interpreter revision \() print revision 10 string cvs print
  18.    (\) does not match gs_init.ps revision \() print 10 string cvs print
  19.    (\).\n) print flush null 1 .quit
  20.  }
  21. if pop
  22.  
  23. % Acquire userdict, and set its length if necessary.
  24. /userdict where
  25.  { pop userdict maxlength 0 eq }
  26.  { true }
  27. ifelse
  28.  {        % userdict wasn't already set up by iinit.c.
  29.    /userdict
  30.    currentdict dup 200 .setmaxlength        % userdict
  31.    systemdict begin def        % can't use 'put', userdict is local
  32.  }
  33.  { systemdict begin
  34.  }
  35. ifelse
  36.  
  37. % Define true and false.
  38. /true 0 0 eq def
  39. /false 0 1 eq def
  40.  
  41. % Define dummy local/global operators if needed.
  42. systemdict /.setglobal known
  43.  { true .setglobal
  44.  }
  45.  { /.setglobal { pop } def
  46.    /.currentglobal { false } def
  47.    /.gcheck { pop false } def
  48.  }
  49. ifelse
  50.  
  51. % Define .languagelevel if needed.
  52. systemdict /.languagelevel known not { /.languagelevel 1 def } if
  53.  
  54. % Optionally choose a default paper size other than U.S. letter.
  55. % (a4) /PAPERSIZE where { pop pop } { /PAPERSIZE exch def } ifelse
  56.  
  57. % Turn on array packing for the rest of initialization.
  58. true setpacking
  59.  
  60. % Acquire the debugging flags.
  61. currentdict /DEBUG known   /DEBUG exch def
  62.   /VMDEBUG
  63.     DEBUG {{print mark
  64.             systemdict /level2dict known
  65.          { .currentglobal false .setglobal vmstatus
  66.            true .setglobal vmstatus 3 -1 roll pop
  67.            6 -2 roll pop .setglobal
  68.          }
  69.          { vmstatus 3 -1 roll pop
  70.          }
  71.         ifelse usertime 16#fffff and counttomark
  72.           { ( ) print (           ) cvs print }
  73.         repeat pop
  74.         ( ) print systemdict length (    ) cvs print
  75.         ( <) print count (    ) cvs print (>\n) print flush
  76.       }}
  77.       {{pop
  78.       }}
  79.      ifelse
  80.   def
  81.  
  82. currentdict /DISKFONTS known   /DISKFONTS exch def
  83. currentdict /ESTACKPRINT known   /ESTACKPRINT exch def
  84. currentdict /FAKEFONTS known   /FAKEFONTS exch def
  85. currentdict /NOBIND known   /NOBIND exch def
  86. /.bind /bind load def
  87. NOBIND { /bind { } def } if
  88. currentdict /NOCACHE known   /NOCACHE exch def
  89. currentdict /NOCIE known   /NOCIE exch def
  90. currentdict /NODISPLAY known   not /DISPLAYING exch def
  91. currentdict /NOGC known   /NOGC exch def
  92. currentdict /NOPAUSE known   /NOPAUSE exch def
  93. currentdict /NOPLATFONTS known   /NOPLATFONTS exch def
  94. currentdict /ORIENT1 known   /ORIENT1 exch def
  95. currentdict /OSTACKPRINT known   /OSTACKPRINT exch def
  96. currentdict /OUTPUTFILE known    % obsolete
  97.  { /OutputFile /OUTPUTFILE load def
  98.    currentdict /OUTPUTFILE undef
  99.  } if
  100. currentdict /QUIET known   /QUIET exch def
  101. currentdict /SAFER known   /SAFER exch def
  102. currentdict /WRITESYSTEMDICT known   /WRITESYSTEMDICT exch def
  103.  
  104. % Acquire environment variables.
  105. currentdict /DEVICE known not
  106.  { (GS_DEVICE) getenv { /DEVICE exch def } if } if
  107.  
  108. (START) VMDEBUG
  109.  
  110. % Open the standard files, so they will be open at the outermost save level.
  111. (%stdin) (r) file pop
  112. (%stdout) (w) file pop
  113. (%stderr) (w) file pop
  114.  
  115. % Define a procedure for skipping over an unneeded section of code.
  116. % This avoids allocating space for the skipped procedures.
  117. /.skipeof    % string ->
  118.  { { dup currentfile =string readline pop eq { exit } if } loop pop
  119.  } bind def
  120.  
  121. % Define =string, which is used by some PostScript programs even though
  122. % it isn't documented anywhere.
  123. % Put it in userdict so that each context can have its own copy.
  124. userdict /=string 128 string put
  125.  
  126. % Print the greeting.
  127.  
  128. /printgreeting
  129.  { mark
  130.    (\n) copyright
  131.    (\)\n) revisiondate 10000 idiv (/)
  132.    revisiondate 100 mod (/)
  133.    revisiondate 100 idiv 100 mod ( \()
  134.    revision 10 mod
  135.    revision 10 idiv 10 mod (.)
  136.    revision 100 idiv ( )
  137.    product
  138.    counttomark
  139.     { (%stdout) (w) file exch .writecvs
  140.     } repeat pop
  141.  } bind def
  142.  
  143. % QUIET not { printgreeting flush } if
  144.  
  145. % Define a special version of def for making operator procedures.
  146. /odef
  147.     {1 index exch .makeoperator def} bind def
  148.  
  149. %**************** BACKWARD COMPATIBILITY
  150. /getdeviceprops
  151.  { null .getdeviceparams
  152.  } bind odef
  153. /.putdeviceprops
  154.  { null true counttomark 1 add 3 roll .putdeviceparams
  155.    dup type /nametype eq
  156.     { counttomark 4 add 1 roll cleartomark pop pop pop
  157.       /.putdeviceprops load exch signalerror
  158.     }
  159.    if
  160.  } bind odef
  161. /.devicenamedict 1 dict dup /OutputDevice dup put def
  162. /.devicename
  163.  { //.devicenamedict .getdeviceparams exch pop exch pop
  164.  } bind odef
  165. /max { .max } bind def
  166. /min { .min } bind def
  167.  
  168. % Define predefined procedures substituting for operators,
  169. % in alphabetical order.
  170.  
  171. userdict /#copies 1 put
  172. /[    /mark load def
  173. /]     {counttomark array astore exch pop} odef
  174. /abs    {dup 0 lt {neg} if} odef
  175. % .beginpage is an operator in Level 2.
  176. /.beginpage { } odef
  177. /copypage
  178.     { 1 .endpage
  179.        { #copies false .outputpage
  180. %         (>>copypage, press <return> to continue<<\n) .confirm
  181.        }
  182.       if .beginpage
  183.     } odef
  184. /setcolorscreen where { pop        % not in all Level 1 configurations
  185.    /currentcolorscreen
  186.     { .currenthalftone
  187.        { { 60 exch 0 exch 3 copy 6 copy }    % halftone
  188.          { 3 copy 6 copy }            % screen
  189.          { }                % colorscreen
  190.        }
  191.       exch get exec
  192.     } odef
  193. } if
  194. /currentscreen
  195.     { .currenthalftone
  196.        { { 60 exch 0 exch }            % halftone
  197.          { }                % screen
  198.          { 12 3 roll 9 { pop } repeat }    % colorscreen
  199.        }
  200.       exch get exec
  201.     } odef
  202. /.echo /echo load def
  203. userdict /.echo.mode true put
  204. /echo    {dup /.echo.mode exch store .echo} odef
  205. /eexec
  206.     { 55665 //filterdict /eexecDecode get exec
  207.       cvx systemdict begin stopped
  208.         % Only pop systemdict if it is still the top element,
  209.         % because this is apparently what Adobe interpreters do.
  210.       currentdict systemdict eq { end } if
  211.       { stop } if
  212.     } odef
  213. % .endpage is an operator in Level 2.
  214. /.endpage { 2 ne } odef
  215. % erasepage mustn't use gsave/grestore, because we call it before
  216. % the graphics state stack has been fully initialized.
  217. /erasepage
  218.     { /currentcolor where
  219.        { pop currentcolor currentcolorspace { setcolorspace setcolor } }
  220.        { /currentcmykcolor where
  221.           { pop currentcmykcolor { setcmykcolor } }
  222.           { currentrgbcolor { setrgbcolor } }
  223.          ifelse
  224.        }
  225.       ifelse 1 setgray .fillpage exec
  226.     } odef
  227. /executive
  228.     { { prompt
  229.          { (%statementedit) (r) file } stopped
  230.          { pop pop $error /errorname get /undefinedfilename eq
  231.         { exit } if        % EOF
  232.            handleerror null        % ioerror??
  233.          }
  234.         if
  235.         cvx execute
  236.       } loop
  237.     } odef
  238. /filter
  239.     { //filterdict 1 index .knownget
  240.        { exch pop exec }
  241.        { /filter load /undefined signalerror }
  242.       ifelse
  243.     } odef
  244. /handleerror
  245.     { errordict /handleerror get exec } bind def
  246. /identmatrix [1.0 0.0 0.0 1.0 0.0 0.0] readonly def
  247. /identmatrix
  248.     { //identmatrix exch copy } odef
  249. /initgraphics
  250.     { initmatrix newpath initclip
  251.       1 setlinewidth 0 setlinecap 0 setlinejoin
  252.       [] 0 setdash 0 setgray 10 setmiterlimit
  253.     } odef
  254. /languagelevel 1 def        % gs_lev2.ps may change this
  255. /matrix    { 6 array identmatrix } odef
  256. /prompt    { flush flushpage
  257.       (GS) print
  258.       count 0 ne { (<) print count =only } if
  259.       (>) print flush
  260.     } bind def
  261. /pstack    { 0 1 count 3 sub { index == } for } bind def
  262. /putdeviceprops
  263.     { .putdeviceprops { erasepage } if } odef
  264. /quit    { /quit load 0 .quit } odef
  265.  
  266. %kept John's definition of '/run', discarded GS330
  267. /run    { dup type /filetype ne
  268.        { (r) file }
  269.           if
  270.            { dup bytesavailable 0 gt { dup read }{ false } ifelse
  271.           { dup 4 eq { pop }{ 1 index exch unread exit } ifelse }
  272.               { exit }
  273.              ifelse
  274.        }
  275.           loop
  276.       cvx execute
  277.     } odef
  278.  
  279. /setdevice
  280.     { .setdevice { erasepage } if } odef
  281. /showpage
  282.     { 0 .endpage
  283.        { #copies true .outputpage
  284. %         (>>showpage, press <return> to continue<<\n) .confirm
  285. %         erasepage
  286.        }
  287.       if initgraphics .beginpage
  288.     } odef
  289. % Code output by Adobe Illustrator relies on the fact that
  290. % `stack' is a procedure, not an operator!!!
  291. /stack    { 0 1 count 3 sub { index = } for } bind def
  292. /start    { executive } def
  293. /stop    { true .stop } odef
  294. /stopped { false .stopped } odef
  295. /store    { 1 index where { 3 1 roll put } { def } ifelse } odef
  296. % When running in Level 1 mode, this interpreter is supposed to be
  297. % compatible with PostScript "version" 54.0 (I think).
  298. /version (54.0) def
  299.  
  300. % Define some additional built-in procedures (beyond the ones defined by
  301. % the PostScript Language Reference Manual).
  302. % Warning: these are not guaranteed to stay the same from one release
  303. % to the next!
  304. /concatstrings
  305.     { exch dup length 2 index length add string    % str2 str1 new
  306.       dup dup 4 2 roll copy        % str2 new new new1
  307.       length 4 -1 roll putinterval
  308.     } bind def
  309. /copyarray
  310.     { dup length array copy } bind def
  311. /copystring
  312.     { dup length string copy } bind def
  313. /.dicttomark        % (the Level 2 >> operator)
  314.     { counttomark dup 1 and 0 ne
  315.        { pop /.dicttomark cvx /rangecheck signalerror
  316.        }
  317.        { 2 idiv dict dup
  318.          2 2 2 index maxlength 2 mul
  319.           {  {    % Stack: mark key1 value1 ... keyN valueN dict dict index
  320.            dup 2 add index exch 1 add index put dup
  321.          } for
  322.           }
  323.          stopped
  324.           {    % The error must have occurred in the 'put'.
  325.         pop pop pop pop stop
  326.           }
  327.           { counttomark 1 add 1 roll cleartomark
  328.           }
  329.          ifelse
  330.        }
  331.       ifelse
  332.     } bind def
  333. /finddevice
  334.     { systemdict /devicedict get exch get
  335.     } bind def
  336. /.growdictlength    % get size for growing a dictionary
  337.     { length 3 mul 2 idiv 1 add
  338.     } bind def
  339. /.growdict        % grow a dictionary
  340.     { dup .growdictlength .setmaxlength
  341.     } bind def
  342. /.growput        % put, grow the dictionary if needed
  343.     { 2 index length 3 index maxlength eq
  344.        { 3 copy pop known not { 2 index .growdict } if
  345.        } if
  346.       put
  347.     } bind def
  348. /.packtomark
  349.     { counttomark packedarray exch pop } bind def
  350. /runlibfile
  351.     { findlibfile
  352.        { exch pop run }
  353.        { /undefinedfilename signalerror }
  354.       ifelse
  355.     } bind def
  356. /selectdevice
  357.     { finddevice setdevice } bind def
  358. /signalerror        % <object> <errorname> signalerror -
  359.     { errordict exch get exec } bind def
  360.  
  361. % Define the =[only] procedures.  Also define =print,
  362. % which is used by some PostScript programs even though
  363. % it isn't documented anywhere.
  364. /write=only
  365.     { { .writecvs } null .stopped null ne
  366.        { pop (--nostringval--) writestring
  367.        }
  368.       if
  369.     } bind def
  370. /write=
  371.     { 1 index exch write=only (\n) writestring
  372.     } bind def
  373. /=only    { (%stdout) (w) file exch write=only } bind def
  374. /=    { =only (\n) print } bind def
  375. /=print    /=only load def
  376. % Temporarily define == as = for the sake of runlibfile0.
  377. /== /= load def
  378.  
  379. % Define procedures for getting and setting the current device resolution.
  380.  
  381. /gsgetdeviceprop    % <device> <propname> gsgetdeviceprop <value>
  382.  { 2 copy mark exch null .dicttomark .getdeviceparams
  383.    dup mark eq        % if true, not found
  384.     { pop dup /undefined signalerror }
  385.     { 5 1 roll pop pop pop pop }
  386.    ifelse
  387.  } bind def
  388. /gscurrentresolution    % - gscurrentresolution <[xres yres]>
  389.  { currentdevice /HWResolution gsgetdeviceprop
  390.  } bind def
  391. /gssetresolution    % <[xres yres]> gssetresolution -
  392.  { 2 array astore mark exch /HWResolution exch
  393.    currentdevice copydevice putdeviceprops setdevice
  394.  } bind def
  395.  
  396. % Define auxiliary procedures needed for the above.
  397. /shellarguments        % -> shell_arguments true (or) false
  398.     { /ARGUMENTS where
  399.        { /ARGUMENTS get dup type /arraytype eq
  400.           { aload pop /ARGUMENTS null store true }
  401.           { pop false }
  402.          ifelse }
  403.        { false } ifelse
  404.     } bind def
  405. /.confirm
  406.     { DISPLAYING NOPAUSE not and
  407.        {    % Print a message and wait for the user to type something.
  408.         % If the user just types a newline, flush it.
  409.          print flush
  410.          .echo.mode false echo
  411.          (%stdin) (r) file dup read
  412.           { dup (\n) 0 get eq { pop pop } { unread } ifelse }
  413.           { pop }
  414.          ifelse echo
  415.        }
  416.        { pop
  417.        }
  418.       ifelse
  419.     } bind def
  420.  
  421. % Define the procedure used by .runfile, .runstdin and .runstring
  422. % for executing user input.
  423. % This is called with a procedure or executable file on the operand stack.
  424. /execute
  425.     { stopped $error /newerror get and
  426.        { handleerror flush
  427.        } if
  428.     } odef
  429. % Define an execute analogue of runlibfile0.
  430. /execute0
  431.     { stopped $error /newerror get and
  432.        { handleerror flush /execute0 cvx 1 .quit
  433.        } if
  434.     } bind def
  435. % Define the procedure that the C code uses for running files
  436. % named on the command line.
  437. /.runfile { { runlibfile } execute } def
  438. % Define the procedure that the C code uses for running piped input.
  439. /.runstdin { (%stdin) (r) file cvx execute0 } bind def
  440. % Define the procedure that the C code uses for running commands
  441. % given on the command line with -c.
  442. /.runstring { cvx execute } def
  443.  
  444. % Define a special version of runlibfile that aborts on errors.
  445. /runlibfile0
  446.     { cvlit dup /.currentfilename exch def
  447.        { findlibfile not { stop } if }
  448.       stopped
  449.        { (Can't find \(or open\) initialization file ) print
  450.          .currentfilename == flush /runlibfile0 cvx 1 .quit
  451.        } if
  452.       exch pop cvx stopped
  453.        { (While reading ) print .currentfilename print (:\n) print flush
  454.          handleerror /runlibfile0 1 .quit
  455.        } if
  456.     } bind def
  457. % Temporarily substitute it for the real runlibfile.
  458. /.runlibfile /runlibfile load def
  459. /runlibfile /runlibfile0 load def
  460.  
  461. % Create the error handling machinery.
  462. % Define the standard error handlers.
  463. % The interpreter has created the ErrorNames array.
  464. /.unstoppederrorhandler    % <command> <errorname> .unstoppederrorhandler -
  465.  {    % This is the handler that gets used for recursive errors,
  466.     % or errors outside the scope of a 'stopped'.
  467.    (Unrecoverable error: ) print dup =only flush
  468.    ( in ) print 1 index = flush
  469.    count 2 gt
  470.     { (Operand stack:\n  ) print
  471.       2 1 count 3 sub { (  ) print index =only flush } for
  472.       (\n) print flush
  473.     } if
  474.    -1 0 1 //ErrorNames length 1 sub
  475.     { dup //ErrorNames exch get 3 index eq
  476.        { not exch pop exit } { pop } ifelse
  477.     }
  478.    for exch pop .quit
  479.  } bind def
  480. /.errorhandler        % <command> <errorname> .errorhandler -
  481.   {        % Detect an internal 'stopped'.
  482.     .instopped { null eq { pop pop stop } if } if
  483.     $error /.inerror get .instopped { pop } { pop true } ifelse
  484.      { .unstoppederrorhandler
  485.      } if    % detect error recursion
  486.     $error /globalmode .currentglobal false .setglobal put
  487.     $error /.inerror true put
  488.     $error /newerror true put
  489.     $error exch /errorname exch put
  490.     $error exch /command exch put
  491.     $error /recordstacks get $error /errorname get /VMerror ne and
  492.      {        % Attempt to store the stack contents atomically.
  493.        count array astore dup $error /ostack 4 -1 roll
  494.        countexecstack array execstack $error /estack 3 -1 roll
  495.        countdictstack array dictstack $error /dstack 3 -1 roll
  496.        put put put aload pop
  497.      }
  498.      { $error /dstack undef
  499.        $error /estack undef
  500.        $error /ostack undef
  501.      }
  502.     ifelse
  503.     $error /position currentfile status
  504.      { currentfile { fileposition } null .stopped null ne { pop null } if
  505.      }
  506.      { null
  507.      }
  508.     ifelse put
  509.         % During initialization, we don't reset the allocation
  510.         % mode on errors.
  511.     $error /globalmode get $error /.nosetlocal get and .setglobal
  512.     $error /.inerror false put
  513.     stop
  514.   } bind def
  515. % Define the standard handleerror.  We break out the printing procedure
  516. % (.printerror) so that it can be extended for binary output
  517. % if the Level 2 facilities are present.
  518.   /.printerror
  519.    { (Error: ) print
  520.      $error begin
  521.        errorname ==only flush
  522.        ( in ) print
  523.        /command load ==only flush
  524.        currentdict /errorinfo .knownget
  525.     { (\nAdditional information: ) print ==only flush
  526.     } if
  527.  
  528.        % Push the (anonymous) stack printing procedure.
  529.        %  <heading> <==flag> <override-name> <stackname> proc
  530.        {
  531.      currentdict exch .knownget    % stackname defined in $error?
  532.      {
  533.        4 1 roll            % stack: <stack> <head> <==flag> <over>
  534.        errordict exch .knownget    % overridename defined?
  535.        { 
  536.          exch pop exch pop exec    % call override with <stack>
  537.        }
  538.        { 
  539.          exch print exch        % print heading. stack <==flag> <stack>
  540.          1 index not { (\n) print } if
  541.          { 1 index { (\n    ) } { (   ) } ifelse print
  542.            dup type /dicttype eq
  543.            {
  544.          (--dict:) print
  545.          dup rcheck
  546.           { dup length =only (/) print maxlength =only }
  547.           { pop }
  548.          ifelse
  549.          (--) print
  550.            }
  551.            {
  552.          dup type /stringtype eq 2 index or
  553.          { ==only } { =only } ifelse
  554.            } ifelse
  555.          } forall
  556.          pop
  557.        }
  558.        ifelse            % overridden
  559.      }
  560.      { pop pop pop
  561.      }
  562.      ifelse                % stack known
  563.        }
  564.  
  565.        (\nOperand stack:) OSTACKPRINT /.printostack /ostack 4 index exec
  566.        (\nExecution stack:) ESTACKPRINT /.printestack /estack 4 index exec
  567.        (\nBacktrace:) true /.printbacktrace /backtrace 4 index exec
  568.        (\nDictionary stack:) false /.printdstack /dstack 4 index exec
  569.        (\n) print
  570.        pop    % printing procedure
  571.  
  572.        errorname /VMerror eq
  573.     { (VM status:) print mark vmstatus
  574.       counttomark { ( ) print counttomark -1 roll dup =only } repeat
  575.       cleartomark (\n) print
  576.     } if
  577.  
  578.        .languagelevel 2 ge
  579.     { (Current allocation mode is ) print
  580.       globalmode { (global\n) } { (local\n) } ifelse print
  581.     } if
  582.  
  583.        .oserrno dup 0 ne
  584.     { (Last OS error: ) print
  585.       errorname /VMerror ne
  586.        { dup .oserrorstring { = pop } { = } ifelse }
  587.        { = }
  588.       ifelse
  589.     }
  590.     { pop
  591.     }
  592.        ifelse
  593.  
  594.        position null ne
  595.     { (Current file position is ) print position = }
  596.        if
  597.  
  598.        .clearerror
  599.      end
  600.      flush
  601.    } bind def
  602. % Define a procedure for clearing the error indication.
  603. /.clearerror
  604.  { $error /newerror false put
  605.    $error /errorinfo undef
  606.    0 .setoserrno
  607.  } bind def
  608.  
  609. % Define $error.  This must be in local VM.
  610. .currentglobal false .setglobal
  611. /$error 40 dict def        % newerror, errorname, command, errorinfo,
  612.                 % ostack, estack, dstack, recordstacks,
  613.                 % binary, globalmode,
  614.                 % .inerror, .nosetlocal, position,
  615.         % plus extra space for badly designed error handers.
  616. $error begin
  617.   /newerror false def
  618.   /recordstacks true def
  619.   /binary false def
  620.   /globalmode .currentglobal def
  621.   /.inerror false def
  622.   /.nosetlocal true def
  623.   /position null def
  624. end
  625. % Define errordict similarly.  It has one entry per error name,
  626. %   plus handleerror.
  627. /errordict ErrorNames length 1 add dict def
  628. .setglobal        % contents of errordict are global
  629. errordict begin
  630.   ErrorNames
  631.    { mark 1 index systemdict /.errorhandler get /exec load .packtomark cvx def
  632.    } forall
  633. % The handlers for interrupt and timeout are special; there is no
  634. % 'current object', so they push their own name.
  635.    { /interrupt /timeout }
  636.    { mark 1 index dup systemdict /.errorhandler get /exec load .packtomark cvx def
  637.    } forall
  638. /handleerror
  639.  { systemdict /.printerror get exec
  640.  } bind def
  641. end
  642.  
  643. % Define the [write]==[only] procedures.
  644. /.dict 26 dict dup
  645. begin def
  646.   /.cvp {1 index exch .writecvs} bind def
  647.   /.nop {exch pop .p} bind def
  648.   /.p {1 index exch writestring} bind def
  649.   /.p1 {2 index exch writestring} bind def
  650.   /.p2 {3 index exch writestring} bind def
  651.   /.print
  652.     { dup type .dict exch .knownget
  653.        { dup type /stringtype eq { .nop } { exec } ifelse }
  654.        { (-) .p1 type .cvp (-) .p }
  655.       ifelse
  656.     } bind def
  657.   /.pstring
  658.     {  { dup dup 32 lt exch 127 ge or
  659.           { (\\) .p1 2 copy -6 bitshift 48 add write
  660.         2 copy -3 bitshift 7 and 48 add write
  661.         7 and 48 add
  662.           }
  663.           { dup dup -2 and 40 eq exch 92 eq or {(\\) .p1} if
  664.           }
  665.          ifelse 1 index exch write
  666.        }
  667.       forall
  668.     } bind def  
  669.   /booleantype /.cvp load def
  670.   /conditiontype (-condition-) def
  671.   /devicetype (-device-) def
  672.   /dicttype (-dict-) def
  673.   /filetype (-file-) def
  674.   /fonttype (-fontID-) def
  675.   /gstatetype (-gstate-) def
  676.   /integertype /.cvp load def
  677.   /locktype (-lock-) def
  678.   /marktype (-mark-) def
  679.   /nulltype (-null-) def
  680.   /realtype /.cvp load def
  681.   /savetype (-save-) def
  682.   /nametype
  683.     {dup xcheck not {(/) .p1} if
  684.      1 index exch .writecvs} bind def
  685.   /arraytype
  686.     {dup rcheck
  687.       {() exch dup xcheck
  688.         {({) .p2
  689.          {exch .p1
  690.           1 index exch .print pop ( )} forall
  691.          (})}
  692.         {([) .p2
  693.          {exch .p1
  694.           1 index exch .print pop ( )} forall
  695.          (])}
  696.        ifelse exch pop .p}
  697.       {(-array-) .nop}
  698.      ifelse} bind def
  699.   /operatortype
  700.       {(--) .p1 .cvp (--) .p} bind def
  701.   /packedarraytype
  702.     { dup rcheck
  703.        { arraytype }
  704.        { (-packedarray-) .nop }
  705.       ifelse
  706.     } bind def
  707.   /stringtype
  708.     { dup rcheck
  709.        { (\() .p1 dup length 200 le
  710.           { .pstring }
  711.           { 0 200 getinterval .pstring (...) .p }
  712.          ifelse (\)) .p
  713.        }
  714.        { (-string-) .nop
  715.        }
  716.       ifelse
  717.     } bind def
  718. {//.dict begin .print pop end}
  719.   bind cvx
  720. end
  721.  
  722. /write==only exch def
  723. /write==
  724.     {1 index exch write==only (\n) writestring} bind def
  725. /==only    { (%stdout) (w) file exch write==only } bind def
  726. /==    {==only (\n) print} bind def
  727.  
  728. (END PROCS) VMDEBUG
  729.  
  730. % Define the font directory.
  731. % Make it big to leave room for transformed fonts.
  732. /FontDirectory false .setglobal 100 dict true .setglobal def
  733.  
  734. % Define the encoding dictionary.
  735. /.encodingdict 10 dict def    % enough for Level 2 + PDF standard encodings
  736.  
  737. % Define findencoding.  (This is redefined in Level 2.)
  738. /.findencoding
  739.  { //.encodingdict exch get exec
  740.  } bind def
  741. /.defineencoding
  742.  { //.encodingdict 3 1 roll put
  743.  } bind def
  744.  
  745. % Load StandardEncoding.
  746. %% Replace 1 (gs_std_e.ps)
  747. (gs_std_e.ps) dup runlibfile VMDEBUG
  748.  
  749. % Load ISOLatin1Encoding.
  750. %% Replace 1 (gs_iso_e.ps)
  751. (gs_iso_e.ps) dup runlibfile VMDEBUG
  752.  
  753. % Define stubs for the Symbol and Dingbats encodings.
  754. % Note that the first element of the procedure must be the file name,
  755. % since gs_lev2.ps extracts it to set up the Encoding resource category.
  756.  
  757.   /SymbolEncoding { /SymbolEncoding .findencoding } bind def
  758. %% Replace 3 (gs_sym_e.ps)
  759.   .encodingdict /SymbolEncoding
  760.    { (gs_sym_e.ps) systemdict begin runlibfile SymbolEncoding end }
  761.   bind put
  762.  
  763.   /DingbatsEncoding { /DingbatsEncoding .findencoding } bind def
  764. %% Replace 3 (gs_dbt_e.ps)
  765.   .encodingdict /DingbatsEncoding
  766.    { (gs_dbt_e.ps) systemdict begin runlibfile DingbatsEncoding end }
  767.   bind put
  768.  
  769. (END FONTDIR/ENCS) VMDEBUG
  770.  
  771. % Construct a dictionary of all available devices.
  772. mark
  773.     % Loop until the .getdevice gets a rangecheck.
  774.   errordict /rangecheck 2 copy get
  775.   errordict /rangecheck { pop stop } put    % pop the command
  776.   0 { {dup .getdevice exch 1 add} loop} stopped pop
  777.   dict /devicedict exch def
  778.   devicedict begin        % 2nd copy of count is on stack
  779.    { dup .devicename dup 3 -1 roll def
  780.      counttomark 1 roll
  781.    } repeat
  782.   end put
  783. counttomark packedarray /devicenames exch def pop
  784. .clearerror
  785.  
  786. (END DEVS) VMDEBUG
  787.  
  788. % Define statusdict, for the benefit of programs
  789. % that think they are running on a LaserWriter or similar printer.
  790. %% Replace 1 (gs_statd.ps)
  791. (gs_statd.ps) runlibfile
  792.  
  793. (END STATD) VMDEBUG
  794.  
  795. % Load the standard font environment.
  796. %% Replace 1 (gs_fonts.ps)
  797. (gs_fonts.ps) runlibfile
  798.  
  799. (END GS_FONTS) VMDEBUG
  800.  
  801. % Create a null font.  This is the initial font.
  802. 8 dict dup begin
  803.   /FontMatrix [ 1 0 0 1 0 0 ] readonly def
  804.   /FontType 3 def
  805.   /FontName () def
  806.   /Encoding StandardEncoding def
  807.   /FontBBox { 0 0 0 0 } readonly def % executable is bogus, but customary ...
  808.   /BuildChar { pop pop 0 0 setcharwidth } bind def
  809.   /PaintType 0 def        % shouldn't be needed!
  810. end
  811. /NullFont exch definefont setfont
  812.  
  813. % Define NullFont as the font, but remove it from FontDirectory.
  814. /NullFont currentfont def
  815. FontDirectory /NullFont undef
  816. (zsfont.ps)runlibfile
  817. (END FONTS) VMDEBUG
  818.  
  819. % Load the initialization files for optional features.
  820. %% Replace 4 INITFILES
  821. systemdict /INITFILES known
  822.  { INITFILES { dup runlibfile VMDEBUG } forall
  823.  }
  824. if
  825.  
  826. % If Level 2 functionality is implemented, enable it now.
  827. /.setlanguagelevel where
  828.  { pop 2 .setlanguagelevel
  829.  } if
  830.  
  831. % If the resource machinery was loaded, convert encodings to resources.
  832. /defineresource where
  833.  { pop .encodingdict
  834.     { dup length 256 eq
  835.        { /Encoding defineresource pop }
  836.        { pop pop }
  837.       ifelse
  838.     } forall
  839.  } if
  840.  
  841. (END INITFILES) VMDEBUG
  842.  
  843. % Restore the real definition of runlibfile.
  844. /runlibfile /.runlibfile load def
  845. currentdict /.runlibfile undef
  846.  
  847. % Bind all the operators defined as procedures.
  848. /.bindoperators        % binds operators in currentdict
  849.  { % Temporarily disable the typecheck error.
  850.    errordict /typecheck 2 copy get
  851.    errordict /typecheck { pop } put    % pop the command
  852.    currentdict
  853.     { dup type /operatortype eq
  854.        { % This might be a real operator, so bind might cause a typecheck,
  855.      % but we've made the error a no-op temporarily.
  856.      .bind        % do a real bind even if NOBIND is set
  857.        }
  858.       if pop pop
  859.     } forall
  860.    put
  861.  } def
  862. NOBIND not { .bindoperators } if
  863.  
  864. % Establish a default environment.
  865.  
  866. DISPLAYING not
  867.  { nulldevice (%END DISPLAYING) .skipeof
  868.  } if
  869. /defaultdevice 0 .getdevice systemdict /DEVICE known
  870.  { pop devicedict DEVICE known not
  871.     { (Unknown device: ) print DEVICE =
  872.       flush /defaultdevice cvx 1 .quit
  873.     }
  874.    if DEVICE finddevice
  875.  }
  876. if def
  877. defaultdevice
  878. systemdict /DEVICEWIDTH known
  879. systemdict /DEVICEHEIGHT known or
  880. systemdict /DEVICEWIDTHPOINTS known or
  881. systemdict /DEVICEHEIGHTPOINTS known or
  882. systemdict /DEVICEXRESOLUTION known or
  883. systemdict /DEVICEYRESOLUTION known or
  884. systemdict /PAPERSIZE known or
  885. not { (%END DEVICE) .skipeof } if
  886. systemdict /PAPERSIZE known
  887.  {    % Convert the paper size to device dimensions.
  888.    true statusdict /.pagetypenames get
  889.     { PAPERSIZE eq
  890.        { PAPERSIZE load
  891.          dup 0 get /DEVICEWIDTHPOINTS exch def
  892.          1 get /DEVICEHEIGHTPOINTS exch def
  893.          pop false exit
  894.        }
  895.       if
  896.     }
  897.    forall
  898.     { (Unknown paper size: ) print PAPERSIZE ==only (.\n) print
  899.     }
  900.    if
  901.  }
  902. if
  903. % Adjust the device parameters per the command line.
  904. % It is possible to specify resolution, pixel size, and page size;
  905. % since any two of these determine the third, conflicts are possible.
  906. % We simply pass them to .setdeviceparams and let it sort things out.
  907.    mark /HWResolution null /HWSize null /PageSize null .dicttomark
  908.    .getdeviceparams .dicttomark begin
  909.    mark
  910.     % Check for resolution.
  911.    /DEVICEXRESOLUTION where dup
  912.     { exch pop HWResolution 0 DEVICEXRESOLUTION put }
  913.    if
  914.    /DEVICEYRESOLUTION where dup
  915.     { exch pop HWResolution 1 DEVICEYRESOLUTION put }
  916.    if
  917.    or { /HWResolution HWResolution } if
  918.     % Check for device sizes specified in pixels.
  919.    /DEVICEWIDTH where dup
  920.     { exch pop HWSize 0 DEVICEWIDTH put }
  921.    if
  922.    /DEVICEHEIGHT where dup
  923.     { exch pop HWSize 1 DEVICEHEIGHT put }
  924.    if
  925.    or { /HWSize HWSize } if
  926.     % Check for device sizes specified in points.
  927.    /DEVICEWIDTHPOINTS where dup
  928.     { exch pop PageSize 0 DEVICEWIDTHPOINTS put }
  929.    if
  930.    /DEVICEHEIGHTPOINTS where dup
  931.     { exch pop PageSize 1 DEVICEHEIGHTPOINTS put }
  932.    if
  933.    or { /PageSize PageSize } if
  934.     % Check whether any parameters were set.
  935.    dup mark eq { pop } { defaultdevice putdeviceprops } ifelse
  936.    end
  937. %END DEVICE
  938. % Set any device properties defined on the command line.
  939. dup getdeviceprops
  940. counttomark 2 idiv
  941.  { systemdict 2 index known
  942.     { pop dup load counttomark 2 roll }
  943.     { pop pop }
  944.    ifelse
  945.  } repeat
  946. systemdict /BufferSpace known
  947. systemdict /MaxBitmap known not and
  948.  { /MaxBitmap BufferSpace
  949.  } if
  950. counttomark dup 0 ne
  951.  { 2 add -1 roll putdeviceprops }
  952.  { pop pop }
  953. ifelse
  954. setdevice        % does an erasepage
  955. %END DISPLAYING
  956.  
  957. (END DEVICE) VMDEBUG
  958.  
  959.  
  960. % Establish a default upper limit in the character cache,
  961. % namely, enough room for a 1/4" x 1/4" character at the resolution
  962. % of the default device, or for 5 x the "average" character size,
  963. % whichever is larger.
  964. mark
  965.     % Compute limit based on character size.
  966.   3 72 mul dup dtransform    % 3" x 3"
  967. %  18 dup dtransform        % 1/4" x 1/4"
  968.   exch abs cvi 31 add 32 idiv 4 mul    % X raster
  969.   exch abs cvi mul        % Y
  970.     % Compute limit based on allocated space.
  971.   cachestatus 5 2 roll pop pop pop pop div 5 mul cvi exch pop
  972.   .max dup 10 idiv exch
  973. setcacheparams
  974. % Conditionally disable the character cache.
  975. NOCACHE { 0 setcachelimit } if
  976.  
  977. (END CONFIG) VMDEBUG
  978.  
  979. % Establish an appropriate halftone screen.
  980.  
  981. 72 72 dtransform abs exch abs .min    % min(|dpi x|,|dpi y|)
  982. dup 150 lt systemdict /DITHERPPI known not and
  983.  {        % Low-res device, use ordered dither spot function
  984.     % The following 'ordered dither' spot function was contributed by
  985.     % Gregg Townsend.  Thanks, Gregg!
  986.   16.001 div 0            % not 16: avoids rounding problems
  987.    { 1 add 7.9999 mul cvi exch 1 add 7.9999 mul cvi 16 mul add <
  988.     0E 8E 2E AE 06 86 26 A6 0C 8C 2C AC 04 84 24 A4
  989.     CE 4E EE 6E C6 46 E6 66 CC 4C EC 6C C4 44 E4 64
  990.     3E BE 1E 9E 36 B6 16 96 3C BC 1C 9C 34 B4 14 94
  991.     FE 7E DE 5E F6 76 D6 56 FC 7C DC 5C F4 74 D4 54
  992.     01 81 21 A1 09 89 29 A9 03 83 23 A3 0B 8B 2B AB
  993.     C1 41 E1 61 C9 49 E9 69 C3 43 E3 63 CB 4B EB 6B
  994.     31 B1 11 91 39 B9 19 99 33 B3 13 93 3B BB 1B 9B
  995.     F1 71 D1 51 F9 79 D9 59 F3 73 D3 53 FB 7B DB 5B
  996.     0D 8D 2D AD 05 85 25 A5 0F 8F 2F AF 07 87 27 A7
  997.     CD 4D ED 6D C5 45 E5 65 CF 4F EF 6F C7 47 E7 67
  998.     3D BD 1D 9D 35 B5 15 95 3F BF 1F 9F 37 B7 17 97
  999.     FD 7D DD 5D F5 75 D5 55 FF 7F DF 5F F7 77 D7 57
  1000.     02 82 22 A2 0A 8A 2A AA 00 80 20 A0 08 88 28 A8
  1001.     C2 42 E2 62 CA 4A EA 6A C0 40 E0 60 C8 48 E8 68
  1002.     32 B2 12 92 3A BA 1A 9A 30 B0 10 90 38 B8 18 98
  1003.     F2 72 D2 52 FA 7A DA 5A F0 70 D0 50 F8 78 D8 58
  1004.      > exch get 256 div
  1005.    }
  1006.   bind
  1007.         % Use correct, per-plane screens for all CMYK devices.
  1008.   systemdict /setcolorscreen known processcolors 4 eq and
  1009.    { 3 copy 6 copy setcolorscreen }
  1010.    { setscreen }
  1011.   ifelse
  1012.   0 array cvx    % transfer -- Genoa CET won't accept a packed array!
  1013.   true        % strokeadjust
  1014.  }
  1015.  {        % Hi-res device, use 45 degree dot spot function.
  1016.     % According to information published by Hewlett-Packard,
  1017.     % they use a 60 line screen on 300 DPI printers and
  1018.     % an 85 line screen on 600 DPI printers.
  1019.     % 46 was suggested as a good frequency value for printers
  1020.     % between 200 and 400 DPI, so we use it for lower resolutions.
  1021.    systemdict /DITHERPPI known
  1022.     { DITHERPPI }
  1023.     { dup cvi 100 idiv 6 .min {null 46 46 60 60 60 85} exch get }
  1024.    ifelse
  1025.    1 index 4.01 div .min    % at least a 4x4 cell
  1026.    45
  1027.     % The following screen algorithm is used by permission of the author.
  1028.     { 1 add 180 mul cos 1 0.08 add mul exch 2 add 180 mul cos 
  1029.       1 0.08 sub mul add 2 div % (C) 1989 Berthold K.P. Horn
  1030.     }
  1031.    bind
  1032.     % Ghostscript currently doesn't use correct, per-plane halftones
  1033.     % unless setcolorscreen has been executed.  Since these are
  1034.     % computationally much more expensive than binary halftones,
  1035.     % we check to make sure they are really warranted, i.e., we have
  1036.     % a high-resolution CMYK device (i.e., not a display) with
  1037.     % fewer than 5 bits per plane (i.e., not a true-color device).
  1038.    4 -1 roll 150 ge
  1039.     { /setcolorscreen where
  1040.        { pop defaultdevice getdeviceprops .dicttomark
  1041.          dup dup dup /RedValues known exch /GreenValues known and
  1042.        exch /BlueValues known and
  1043.       { dup dup /RedValues get 32 lt
  1044.           exch /GreenValues get 32 lt and
  1045.           exch /BlueValues get 32 lt and
  1046.          { 3 copy 6 copy
  1047.     % For really high-quality screening on printers, we need to
  1048.     % give each plane its own screen angle.  Unfortunately,
  1049.     % this currently has very large space and time costs.
  1050.     %**************** Uncomment the next line for high-quality screening.
  1051.     %    { 45 90 15 75 } { 3 1 roll exch pop 12 3 roll } forall
  1052.            setcolorscreen
  1053.          }
  1054.          { setscreen
  1055.          }
  1056.         ifelse
  1057.       }
  1058.       { pop setscreen
  1059.       }
  1060.      ifelse
  1061.        }
  1062.        { setscreen
  1063.        }
  1064.       ifelse
  1065.     }
  1066.     { setscreen
  1067.     }
  1068.    ifelse
  1069.     % Set the transfer function to lighten up the grays.
  1070.     % We correct at the high end so that very light grays
  1071.     % don't disappear completely if they darken <1 screen pixel.
  1072.     % Parameter values closer to 1 are better for devices with
  1073.     % less dot spreading; lower values are better with more spreading.
  1074.     % The value 0.8 is a compromise that will probably please no one!
  1075.     {
  1076.     %Null Transfer function
  1077.     %    0.8 exp dup dup 0.9375 gt exch 0.999 lt and    % > 15/16
  1078.     %       { .currentscreenlevels 1 sub    % tweak to avoid boundary
  1079.     %     1 exch div 1 exch sub .min
  1080.     %       }
  1081.     %      if
  1082.     }        % transfer
  1083.    false    % strokeadjust
  1084.     % Increase fill adjustment so that we effectively use Adobe's
  1085.     % any-part-of-pixel rule.
  1086.    0.5 .setfilladjust
  1087.  }
  1088. ifelse
  1089.   /setstrokeadjust where { pop setstrokeadjust } { pop } ifelse
  1090.   settransfer
  1091. initgraphics
  1092. % The interpreter relies on there being at least 2 entries
  1093. % on the graphics stack.  Establish the second one now.
  1094. gsave
  1095.  
  1096. % Define some control sequences as no-ops.
  1097. % This is a hack to get around problems
  1098. % in some common PostScript-generating applications.
  1099. % Note that <04> and <1a> are self-delimiting characters, like [.
  1100. <04> cvn { } def        % Apple job separator
  1101. %<0404> cvn { } def        % two of the same
  1102. <1b> cvn { } def        % MS Windows LaserJet 4 prologue
  1103. %<041b> cvn { } def        % MS Windows LaserJet 4 epilogue
  1104. <1a> cvn { } def        % MS-DOS EOF
  1105. (\001M) cvn { } def        % TBCP initiator
  1106. /@PJL                % H-P job control
  1107.  { currentfile //=string readline { pop } if
  1108.  } bind def
  1109.  
  1110. % If we want a "safer" system, disable some obvious ways to cause havoc.
  1111. SAFER not { (%END SAFER) .skipeof } if
  1112. /file
  1113.  { dup (r) eq 2 index (%pipe*) .stringmatch not and
  1114.     { file }
  1115.     { /invalidfileaccess signalerror }
  1116.    ifelse
  1117.  } bind odef
  1118. /renamefile { /invalidfileaccess signalerror } odef
  1119. /deletefile { /invalidfileaccess signalerror } odef
  1120. /putdeviceprops
  1121.  { counttomark
  1122.    dup 2 mod 0 eq { pop /rangecheck signalerror } if
  1123.    3 2 3 2 roll
  1124.     { dup index /OutputFile eq  
  1125.        { -2 roll 
  1126.          dup () ne { /putdeviceprops load /invalidfileaccess signalerror } if
  1127.          3 -1 roll
  1128.        }
  1129.        { pop
  1130.        }
  1131.       ifelse
  1132.     } for
  1133.    putdeviceprops
  1134.  } bind odef
  1135.  
  1136. %END SAFER
  1137.  
  1138.  
  1139. % Turn off array packing, since some PostScript code assumes that
  1140. % procedures are writable.
  1141. false setpacking
  1142.  
  1143. (zserver.ps)runlibfile
  1144.  
  1145. % Close up systemdict.
  1146. currentdict /.forceput undef        % remove temptation
  1147. currentdict /filterdict undef        % bound in where needed
  1148. end
  1149. WRITESYSTEMDICT not { systemdict readonly pop } if
  1150.  
  1151.  
  1152. (END INIT) VMDEBUG
  1153.  
  1154. % Establish local VM as the default.
  1155. false /setglobal where { pop setglobal } { .setglobal } ifelse
  1156. $error /.nosetlocal false put
  1157.  
  1158. % Clean up VM, and enable GC.
  1159. %/vmreclaim where
  1160. % { pop NOGC not { 2 vmreclaim 0 vmreclaim } if
  1161. % } if
  1162.  
  1163. (END GC) VMDEBUG
  1164.  
  1165. % The interpreter will run the initial procedure (start).
  1166.