%    Copyright (C) 1990, 1991 Aladdin Enterprises.  All rights reserved.
%
% This file is part of Ghostscript.
%
% Ghostscript is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
% to anyone for the consequences of using it or for whether it serves any
% particular purpose or works at all, unless he says so in writing.  Refer
% to the Ghostscript General Public License for full details.
%
% Everyone is granted permission to copy, modify and redistribute
% Ghostscript, but only under the conditions described in the Ghostscript
% General Public License.  A copy of this license is supposed to have been
% given to you along with Ghostscript so you can know your rights and
% responsibilities.  It should be in a file named COPYING.  Among other
% things, the copyright notice and this notice must be preserved on all
% copies.

% Initialization file for analogs of Display PostScript functions
% that are also included in Level 2.
% When this is run, systemdict is still writable,
% but everything defined here goes into level2dict.

level2dict begin

% ------ Binary token support ------ %

% Initialization for the system name table.

mark
% 0
	/abs /add /aload /anchorsearch /and
	/arc /arcn /arct /arcto /array
	/ashow /astore /awidthshow /begin /bind
	/bitshift /ceiling /charpath /clear /cleartomark
% 20
	/clip /clippath /closepath /concat /concatmatrix
	/copy /count /counttomark /currentcmykcolor /currentdash
	/currentdict /currentfile /currentfont /currentgray /currentgstate
	/currenthsbcolor /currentlinecap /currentlinejoin /currentlinewidth /currentmatrix
% 40
	/currentpoint /currentrgbcolor /currentshared /curveto /cvi
	/cvlit /cvn /cvr /cvrs /cvs
	/cvx /def /defineusername /dict /div
	/dtransform /dup /end /eoclip /eofill
% 60
	/eoviewclip /eq /exch /exec /exit
	/file /fill /findfont /flattenpath /floor
	/flush /flushfile /for /forall /eg
	/get /getinterval /grestore /gsave /gstate
% 80
	/gt /identmatrix /idiv /idtransform /if
	/ifelse /image /imagemask /index /ineofill
	/infill /initviewclip /inueofill /inufill /invertmatrix
	/itransform /known /le /length /lineto
% 100
	/load /loop /lt /makefont /matrix
	/maxlength /mod /moveto /mul /ne
	/neg /newpath /not /null /or
	/pathbbox /pathfoall /pop /print /printobject
% 120
	/put /putinterval /rcurveto /read /readhexstring
	/readline /readstring /rectclip /rectfill /rectstroke
	/rectviewclip /repeat /restore /rlineto /rmoveto
	/roll /rotate /round /save /scale
% 140
	/scalefont /search /selectfont /setbbox /setcachedevice
	/setcachedevice2 /setcharwidth /setcmykcolor /setdash /setfont
	/setgray /setgstate /sethsbcolor /setlinecap /setlinejoin
	/setlinewidth /setmatrix /setrgbcolor /setshared /shareddict
% 160
	/show /showpage /stop /stopped /store
	/string /stringwidth /stroke /strokepath /sub
	/systemdict /token /transform /translate /truncate
	/type /uappend /ucache /ueofill /ufill
% 180
	/undef /upath /userdict /ustroke /viewclip
	/viewclippath /where /widthshow /write /writehexstring
	/writeobject /writestring /wtranslation /xor /xshow
	/xyshow /yshow /FontDirectory /SharedFontDirectory /Courier
% 200
	/Courier-Bold /Courier-BoldOblique /Courier-Oblique /Helvetica /Helvetica-Bold
	/Helvetica-BoldOblique /Helvetica-Oblique /Symbol /Times-Bold /Times-BoldItalic
	/Times-Italic /Times-Roman /execuserobject /currentcolor /currentcolorspace
	/currentglobal /execform /filter /findresource /globaldict
% 220
	/makepattern /setcolor /setcolorspace /setglobal /setpagedevice
	/setpattern
% pad to 256
	counttomark 256 exch sub { 0 } repeat
% 256
	/= /== /ISOLatin1Encoding /StandardEncoding
% 260
	/[ /] /atan /banddevice /bytesavailable
	/cachestatus /closefile /colorimage /condition /copypage
	/cos /countdictstack /countexecstack /cshow /currentblackgeneration
	/currentcacheparams /currentcolorscreen /currentcolortransfer /currentcontext /currentflat
% 280
	/currenthalftone /currenthalftonephase /currentmiterlimit /currentobjectformat /currentpacking
	/currentscreen /currentstrokeadjust /currenttransfer /currentundercolorremoval /defaultmatrix
	/definefont /deletefile /detach /deviceinfo /dictstack
	/echo /erasepage /errordict /execstack /executeonly
% 300
	/exp /false /filenameforall /fileposition /fork
	/framedevice /grestoreall /handleerror /initclip /initgraphics
	/initmatrix /instroke /inustroke /join /kshow
	/ln /lock /log /mark /monitor
% 320
	/noaccess /notify /nulldevice /packedarray /quit
	/rand /rcheck /readonly /realtime /renamefile
	/renderbands /resetfile /reversepath /rootfont /rrand
	/run /scheck /setblackgeneration /setcachelimit /setcacheparams
% 340
	/setcolorscreen /setcolortransfer /setfileposition /setflat /sethalftone
	/sethalftonephase /setmiterlimit /setobjectformat /setpacking /setscreen
	/setstrokeadjust /settransfer /setucacheparams /setundercolorremoval /sin
	/sqrt /srand /stack /status /statusdict
% 360
	/true /ucachestatus /undefinefont /usertime /ustrokepath
	/version /vmreclaim /vmstatus /wait /wcheck
	/xcheck /yield /defineuserobject /undefineuserobject /UserObjects
	/cleardictstack
% 376
	/A /B /C /D /E /F /G /H /I /J /K /L /M
	/N /O /P /Q /R /S /T /U /V /W /X /Y /Z
	/a /b /c /d /e /f /g /h /i /j /k /l /m
	/n /o /p /q /r /s /t /u /v /w /x /y /z
% 428
	/setvmthreshold (<<) cvn
	(>>) cvn /currentcolorrendering /currentdevparams /currentoverprint /currentpagedevice
	/currentsystemparams /currentuserparams /defineresource /findencoding /gcheck
% 440
	/glyphshow /languagelevel /product /pstack /resourceforall
	/resourcestatus /revision /serialnumber /setcolorrendering /setdevparams
	/setoverprint /setsystemparams /setuserparams /startjob /undefineresource
	/GlobalFontDirectory /ASCII85Decode /ASCII85Encode /ASCIIHexDecode /ASCIIHexEncode
% 460
	/CCITTFaxDecode /CCITTFaxEncode /DCTDecode /DCTEncode /LZWDecode
	/LZWEncode /NullEncode /RunLengthDecode /RunLengthEncode /SubFileDecode
	/CIEBasedA /CIEBasedABC /DeviceCMYK /DeviceGray /DeviceRGB
	/Indexed /Pattern /Separation
% 478 -- end
counttomark packedarray exch pop

% Install the system and user name tables.
% The user name table is read-only for ordinary programs,
% since it doesn't obey save/restore and must be managed specially.
 
dup /SystemNames exch def
100 array readonly dup /UserNames exch def
.installnames

% Define printobject and writeobject.

/printobject { .stdout 3 1 roll writeobject } odef

/.writeobjectbuf 1 array def
/writeobject { exch .writeobjectbuf dup 0 4 -1 roll put .writeobjects } odef

% Implement binary error message output.
errordict begin
  /.printerror
   { $error /binary get .languagelevel 2 eq and
      { currentobjectformat 0 ne
         { [ /Error $error /errorname get $error /command get false
	   ] 250 printobject
	 }
	 //.printerror
	ifelse
      }
      //.printerror
     ifelse
   } bind def
end

% ------ Fonts ------ %

/selectfont
	{ exch findfont exch
	  dup type /arraytype eq { makefont } { scalefont } ifelse
	  setfont
	} odef
/undefinefont
	{ FontDirectory exch undef
	} odef

% ------ Halftones ------ %

/.currenthalftonetypes [
	{ exch pop } bind		% halftone
	{ /HalftoneType 1		% screen
	   { /Frequency /Angle /SpotFunction }
	  .makestackdict
	}
	{ /HalftoneType 2		% colorscreen
	   { /RedFrequency /RedAngle /RedSpotFunction
	     /GreenFrequency /GreenAngle /GreenSpotFunction
	     /BlueFrequency /BlueAngle /BlueSpotFunction
	     /GrayFrequency /GrayAngle /GraySpotFunction
	   }
	  .makestackdict
	}
] def
/.makestackdict
	{ { counttomark -1 roll } forall .dicttomark
	} bind def
/currenthalftone
	{ mark .currenthalftone .currenthalftonetypes exch get exec
	} odef
/sethalftone
	{ dup /HalftoneType get 1 sub
	   { .sethalftone1 .sethalftone2 .sethalftone3 .sethalftone4
	     .sethalftone5
	   } exch get exec
	} odef
% Redefine setscreen to recognize halftone dictionaries.
/..setscreen /setscreen load def
/setscreen
	{ dup type /dicttype eq
	   { sethalftone pop pop }
	   { ..setscreen }
	  ifelse
	} bind odef
% Redefine currentscreen and currentcolorscreen similarly.
/.currentscreentypes [
	{ 60 exch 0 exch } bind			% halftone
	{ }					% screen
	{ 12 3 roll 9 { pop } repeat }		% colorscreen
] def
/currentscreen
	{ .currenthalftone .currentscreentypes exch get exec
	} odef
/.currentcolorscreentypes [
	{ 60 exch 0 exch 3 copy 6 copy } bind	% halftone
	{ 3 copy 6 copy } bind			% screen
	{ }					% colorscreen
] def
/currentcolorscreen
	{ .currenthalftone .currentcolorscreentypes exch get exec
	} odef

% ------ User objects ------ %

% **************** We have to disable .localarray
% **************** because local/global VM isn't really implemented yet.
/.localarray
	{ currentshared false setshared
	  exch array exch setshared
	} bind def
/.localarray /array load def	% ****************
/defineuserobject
	{ userdict /UserObjects known
	   { 1 index userdict /UserObjects get length ge
	      { 1 index 1 add .localarray userdict /UserObjects get
	        1 index copy pop
	        userdict /UserObjects 3 -1 roll put
	      }
	     if
	   }
	   { userdict /UserObjects 3 index 1 add .localarray put
	   }
	  ifelse
	  userdict /UserObjects get 3 1 roll put
	} odef
/execuserobject
	{ userdict /UserObjects get exch get exec
	} odef
/undefineuserobject
	{ userdict /UserObjects get exch null put
	} odef

% ------ User paths ------ %

/upath
	{ [ exch {/ucache cvx} if pathbbox /setbbox cvx
	  {/moveto cvx} {/lineto cvx} {/curveto cvx} {/closepath cvx}
	  pathforall ] cvx
	} odef

% Dummy definitions for cache control operators

/ucachestatus
	{ mark 0 0 0 0 0 } odef
/setucacheparams
	{ cleartomark } odef

% ------ Virtual memory ------ %

%**************** Everything here is a stub. ****************%

/setvmthreshold { pop } odef
/shareddict currentdict /globaldict .knownget not { 20 dict } if def
/SharedFontDirectory FontDirectory def
/vmreclaim { pop } odef

% End of level2dict

end
