henesyinit from p9fce6d0435 years agoHistory
1158 lines · 33.0 KB · Text
RawDownload
%    Copyright (C) 1989, 1992, 1993, 1994 Aladdin Enterprises.  All rights reserved.% % This file is part of Aladdin Ghostscript.% % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author% or distributor accepts any responsibility for the consequences of using it,% or for whether it serves any particular purpose or works at all, unless he% or she says so in writing.  Refer to the Aladdin Ghostscript Free Public% License (the "License") for full details.% % Every copy of Aladdin Ghostscript must include a copy of the License,% normally in a plain ASCII text file named PUBLIC.  The License grants you% the right to copy, modify and redistribute Aladdin Ghostscript, but only% under certain conditions described in the License.  Among other things, the% License requires that the copyright notice and this notice be preserved on% all copies. % Initialization file for the interpreter.% When this is run, systemdict is still writable. % Comment lines of the form%	%% Replace <n> <file(s)>% indicate places where the next <n> lines should be replaced by% the contents of <file(s)>, when creating a single merged init file. % Check the interpreter revision.  NOTE: the interpreter code requires% that the first non-comment token in this file be an integer% that matches the interpreter's revision.323dup revision ne { (gs: Interpreter revision \() print revision 10 string cvs print   (\) does not match gs_init.ps revision \() print 10 string cvs print   (\).\n) print flush null 1 .quit }if pop % Acquire userdict, and set its length if necessary./userdict where { pop userdict maxlength 0 eq } { true }ifelse {		% userdict wasn't already set up by iinit.c.   /userdict   currentdict dup 200 .setmaxlength		% userdict   systemdict begin def		% can't use 'put', userdict is local } { systemdict begin }ifelse % Define true and false./true 0 0 eq def/false 0 1 eq def % Define dummy local/global operators if needed.systemdict /.setglobal known { true .setglobal } { /.setglobal { pop } def   /.currentglobal { false } def   /.gcheck { pop false } def }ifelse % Define .languagelevel if needed.systemdict /.languagelevel known not { /.languagelevel 1 def } if % Optionally choose a default paper size other than U.S. letter.% (a4) /PAPERSIZE where { pop pop } { /PAPERSIZE exch def } ifelse % Turn on array packing for the rest of initialization.true setpacking % Acquire the debugging flags.currentdict /DEBUG known   /DEBUG exch def  /VMDEBUG    DEBUG {{print mark            systemdict /level2dict known	     { .currentglobal false .setglobal vmstatus	       true .setglobal vmstatus 3 -1 roll pop	       6 -2 roll pop .setglobal	     }	     { vmstatus 3 -1 roll pop	     }	    ifelse usertime 16#fffff and counttomark	      { ( ) print (           ) cvs print }	    repeat pop	    ( ) print systemdict length (    ) cvs print	    ( <) print count (    ) cvs print (>\n) print flush	  }}	  {{pop	  }}	 ifelse  def currentdict /DISKFONTS known   /DISKFONTS exch defcurrentdict /ESTACKPRINT known   /ESTACKPRINT exch defcurrentdict /FAKEFONTS known   /FAKEFONTS exch defcurrentdict /NOBIND known   /NOBIND exch def/.bind /bind load defNOBIND { /bind { } def } ifcurrentdict /NOCACHE known   /NOCACHE exch defcurrentdict /NODISPLAY known   not /DISPLAYING exch defcurrentdict /NOGC known   /NOGC exch defcurrentdict /NOPAUSE known   /NOPAUSE exch defcurrentdict /NOPLATFONTS known   /NOPLATFONTS exch defcurrentdict /OSTACKPRINT known   /OSTACKPRINT exch defcurrentdict /OUTPUTFILE known	% obsolete { /OutputFile /OUTPUTFILE load def   currentdict /OUTPUTFILE undef } ifcurrentdict /QUIET known   /QUIET exch defcurrentdict /SAFER known   /SAFER exch defcurrentdict /WRITESYSTEMDICT known   /WRITESYSTEMDICT exch def % Acquire environment variables.currentdict /DEVICE known not { (GS_DEVICE) getenv { /DEVICE exch def } if } if (START) VMDEBUG % Acquire the standard files./.stdin (%stdin) (r) file def/.stdout (%stdout) (w) file def/.stderr (%stderr) (w) file def % Define a procedure for skipping over an unneeded section of code.% This avoids allocating space for the skipped procedures./.skipeof	% string -> { { dup currentfile =string readline pop eq { exit } if } loop pop } bind def % Define =string, which is used by some PostScript programs even though% it isn't documented anywhere.% Put it in userdict so that each context can have its own copy.userdict /=string 128 string put % Print the greeting. /printgreeting { mark   product (Ghostscript) search    { pop pop pop      (This software comes with NO WARRANTY: see the file PUBLIC for details.\n)    }    { pop    }   ifelse   (\n) copyright   (\)\n) revisiondate 10000 idiv (/)   revisiondate 100 mod (/)   revisiondate 100 idiv 100 mod ( \()   revision 10 mod   revision 10 idiv 10 mod (.)   revision 100 idiv ( )   product   counttomark { =string cvs print } repeat pop } bind def QUIET not { printgreeting flush } if % Define a special version of def for making operator procedures./odef	{1 index exch .makeoperator def} bind def %**************** BACKWARD COMPATIBILITY/getdeviceprops { null .getdeviceparams } bind odef/.putdeviceprops { null true counttomark 1 add 3 roll .putdeviceparams   dup type /nametype eq    { counttomark 4 add 1 roll cleartomark pop pop pop      /.putdeviceprops load exch signalerror    }   if } bind odef/.devicenamedict 1 dict dup /OutputDevice dup put def/.devicename { //.devicenamedict .getdeviceparams exch pop exch pop } bind odef/max { .max } bind def/min { .min } bind def % Define predefined procedures substituting for operators,% in alphabetical order. userdict /#copies 1 put/[	/mark load def/] 	{counttomark array astore exch pop} odef/abs	{dup 0 lt {neg} if} odef% .beginpage is an operator in Level 2./.beginpage { } odef/copypage	{ 1 .endpage	   { #copies false .outputpage	     (>>copypage, press <return> to continue<<\n) .confirm	   }	  if .beginpage	} odef/setcolorscreen where { pop		% not in all Level 1 configurations   /currentcolorscreen	{ .currenthalftone	   { { 60 exch 0 exch 3 copy 6 copy }	% halftone	     { 3 copy 6 copy }			% screen	     { }				% colorscreen	   }	  exch get exec	} odef} if/currentscreen	{ .currenthalftone	   { { 60 exch 0 exch }			% halftone	     { }				% screen	     { 12 3 roll 9 { pop } repeat }	% colorscreen	   }	  exch get exec	} odef/.echo /echo load defuserdict /.echo.mode true put/echo	{dup /.echo.mode exch store .echo} odef/eexec	{ 55665 //filterdict /eexecDecode get exec	  cvx systemdict begin stopped		% Only pop systemdict if it is still the top element,		% because this is apparently what Adobe interpreters do.	  currentdict systemdict eq { end } if	  { stop } if	} odef% .endpage is an operator in Level 2./.endpage { 2 ne } odef% erasepage mustn't use gsave/grestore, because we call it before% the graphics state stack has been fully initialized./erasepage	{ /currentcolor where	   { pop currentcolor currentcolorspace { setcolorspace setcolor } }	   { /currentcmykcolor where	      { pop currentcmykcolor { setcmykcolor } }	      { currentrgbcolor { setrgbcolor } }	     ifelse	   }	  ifelse 1 setgray .fillpage exec	} odef/executive	{ { prompt	     { (%statementedit) (r) file } stopped	     { pop pop $error /errorname get /undefinedfilename eq		{ exit } if		% EOF	       handleerror null		% ioerror??	     }	    if	    cvx execute	  } loop	} odef/filter	{ //filterdict 1 index .knownget	   { exch pop exec }	   { /filter load /undefined signalerror }	  ifelse	} odef/handleerror	{errordict /handleerror get exec} bind def/identmatrix [1.0 0.0 0.0 1.0 0.0 0.0] readonly def/identmatrix	{ //identmatrix exch copy} odef/initgraphics	{initmatrix newpath initclip 1 setlinewidth 0 setlinecap 0 setlinejoin	 [] 0 setdash 0 setgray 10 setmiterlimit} odef/languagelevel 1 def		% gs_lev2.ps may change this/matrix	{6 array identmatrix} odef/prompt	{flush flushpage	 (GS) print count 0 ne	  {(<) print count =only}	 if (>) print flush} bind def/pstack	{0 1 count 3 sub {index ==} for} bind def/putdeviceprops	{ .putdeviceprops { erasepage } if } odef/quit	{/quit load 0 .quit} odef/run	{dup type /filetype ne { (r) file } if cvx execute} odef/setdevice	{ .setdevice { erasepage } if } odef/showpage	{ 0 .endpage	   { #copies true .outputpage	     (>>showpage, press <return> to continue<<\n) .confirm	     erasepage	   }	  if initgraphics .beginpage	} odef% Code output by Adobe Illustrator relies on the fact that% `stack' is a procedure, not an operator!!!/stack	{0 1 count 3 sub {index =} for} bind def/start	{ executive } def/stop	{ true .stop } odef/stopped { false .stopped } odef/store	{ 1 index where { 3 1 roll put } { def } ifelse } odef% When running in Level 1 mode, this interpreter is supposed to be% compatible with PostScript "version" 54.0 (I think)./version (54.0) def % Define some additional built-in procedures (beyond the ones defined by% the PostScript Language Reference Manual).% Warning: these are not guaranteed to stay the same from one release% to the next!/concatstrings	{ exch dup length 2 index length add string	% str2 str1 new	  dup dup 4 2 roll copy		% str2 new new new1	  length 4 -1 roll putinterval	} bind def/copyarray	{ dup length array copy } bind def/copystring	{ dup length string copy } bind def/.dicttomark		% (the Level 2 >> operator)	{ counttomark dup 1 and 0 ne	   { pop /.dicttomark cvx /rangecheck signalerror	   }	   { 2 idiv dict dup	     2 2 2 index maxlength 2 mul	      {  {	% Stack: mark key1 value1 ... keyN valueN dict dict index		   dup 2 add index exch 1 add index put dup		 } for	      }	     stopped	      {	% The error must have occurred in the 'put'.		pop pop pop pop stop	      }	      { counttomark 1 add 1 roll cleartomark	      }	     ifelse	   }	  ifelse	} bind def/finddevice	{ systemdict /devicedict get exch get	} bind def/.growdictlength	% get size for growing a dictionary	{ length 3 mul 2 idiv 1 add	} bind def/.growdict		% grow a dictionary	{ dup .growdictlength .setmaxlength	} bind def/.growput		% put, grow the dictionary if needed	{ 2 index length 3 index maxlength eq	   { 3 copy pop known not { 2 index .growdict } if	   } if	  put	} bind def/.packtomark	{ counttomark packedarray exch pop } bind def/runlibfile	{ findlibfile	   { exch pop run }	   { /undefinedfilename signalerror }	  ifelse	} bind def/selectdevice	{ finddevice setdevice } bind def/signalerror		% <object> <errorname> signalerror -	{ errordict exch get exec } bind def % Define the =[only] procedures.  Also define =print,% which is used by some PostScript programs even though% it isn't documented anywhere./write=only	{ { .writecvs } null .stopped null ne	   { pop (--nostringval--) writestring	   }	  if	} bind def/write=	{ 1 index exch write=only (\n) writestring	} bind def/=only	{ .stdout exch write=only } bind def/=	{ =only (\n) print } bind def/=print	/=only load def% Temporarily define == as = for the sake of runlibfile0./== /= load def % Define procedures for getting and setting the current device resolution. /gsgetdeviceprop { 1 index getdeviceprops    { 1 index counttomark 1 add index eq { exit } if pop pop } loop   dup mark eq		% if true, not found    { pop dup /undefined signalerror }    { counttomark 1 add 1 roll cleartomark exch pop exch pop }   ifelse } bind def/gscurrentresolution { currentdevice /HWResolution gsgetdeviceprop } bind def/gssetresolution { 2 array astore mark exch /HWResolution exch   currentdevice copydevice putdeviceprops setdevice } bind def % Define auxiliary procedures needed for the above./shellarguments		% -> shell_arguments true (or) false	{ /ARGUMENTS where	   { /ARGUMENTS get dup type /arraytype eq	      { aload pop /ARGUMENTS null store true }	      { pop false }	     ifelse }	   { false } ifelse	} bind def/.confirm	{ DISPLAYING NOPAUSE not and	   {	% Print a message and wait for the user to type something.		% If the user just types a newline, flush it.	     print flush	     .echo.mode false echo	     .stdin dup read	      { dup (\n) 0 get eq { pop pop } { unread } ifelse }	      { pop }	     ifelse echo	   }	   { pop	   }	  ifelse	} bind def % Define the procedure used by the C executive for executing user input,% and also by the run operator.% This is called with a procedure or file on the operand stack./execute	{stopped $error /newerror get and {handleerror} if} odef% Define an execute analogue of runlibfile0./execute0	{ stopped $error /newerror get and	   { handleerror flush /execute0 cvx 1 .quit	   } if	} bind def% Define the procedure that the C code uses for running files% named on the command line./.runfile /runlibfile load def % Define a special version of runlibfile that aborts on errors./runlibfile0	{ cvlit dup /.currentfilename exch def	   { findlibfile not { stop } if }	  stopped	   { (Can't find (or open) initialization file ) print	     .currentfilename == flush /runlibfile0 cvx 1 .quit	   } if	  exch pop cvx stopped	   { (While reading ) print .currentfilename print (:\n) print flush	     handleerror /runlibfile0 1 .quit	   } if	} bind def% Temporarily substitute it for the real runlibfile./.runlibfile /runlibfile load def/runlibfile /runlibfile0 load def % Create the error handling machinery.% Define the standard error handlers.% The interpreter has created the ErrorNames array./.unstoppederrorhandler	% <command> <errorname> .unstoppederrorhandler - {	% This is the handler that gets used for recursive errors,	% or errors outside the scope of a 'stopped'.   (Unrecoverable error: ) print dup =only flush   ( in ) print 1 index = flush   count 2 gt    { (Operand stack:\n  ) print      2 1 count 3 sub { (  ) print index =only flush } for      (\n) print flush    } if   -1 0 1 //ErrorNames length 1 sub    { dup //ErrorNames exch get 3 index eq       { not exch pop exit } { pop } ifelse    }   for exch pop .quit } bind def/.errorhandler		% <command> <errorname> .errorhandler -  {		% Detect an internal 'stopped'.    .instopped { null eq { pop pop stop } if } if    $error /.inerror get .instopped { pop } { pop true } ifelse     { .unstoppederrorhandler     } if	% detect error recursion    $error /globalmode .currentglobal false .setglobal put    $error /.inerror true put    $error /newerror true put    $error exch /errorname exch put    $error exch /command exch put    $error /recordstacks get $error /errorname get /VMerror ne and     {		% Attempt to store the stack contents atomically.       count array astore dup $error /ostack 4 -1 roll       countexecstack array execstack $error /estack 3 -1 roll       countdictstack array dictstack $error /dstack 3 -1 roll       put put put aload pop     }     { $error /dstack undef       $error /estack undef       $error /ostack undef     }    ifelse    $error /position currentfile status     { currentfile { fileposition } null .stopped null ne { pop null } if     }     { null

Lines 1–500 of 1158.