1 % Copyright 1993-2001 by Easy Software Products.
2 % Copyright 1994, 1996, 1997, 1998 Aladdin Enterprises. All rights reserved.
4 % This file is part of GNU Ghostscript.
6 % GNU Ghostscript is distributed in the hope that it will be useful, but
7 % WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
8 % to anyone for the consequences of using it or for whether it serves any
9 % particular purpose or works at all, unless he says so in writing. Refer
10 % to the GNU General Public License for full details.
12 % Everyone is granted permission to copy, modify and redistribute GNU
13 % Ghostscript, but only under the conditions described in the GNU General
14 % Public License. A copy of this license is supposed to have been given
15 % to you along with GNU Ghostscript so you can know your rights and
16 % responsibilities. It should be in a file named COPYING. Among other
17 % things, the copyright notice and this notice must be preserved on all
20 % Aladdin Enterprises supports the work of the GNU Project, but is not
21 % affiliated with the Free Software Foundation or the GNU Project. GNU
22 % Ghostscript, as distributed by Aladdin Enterprises, does not require any
23 % GNU software to build or run it.
25 % $Id: gs_btokn.ps 1605 2001-03-02 22:34:21Z andy $
26 % Initialization file for binary tokens.
27 % When this is run, systemdict is still writable,
28 % but everything defined here goes into level2dict.
30 % Define whether or not to allow writing dictionaries.
33 languagelevel 1 .setlanguagelevel
36 % Initialization for the system name table.
40 /abs /add /aload /anchorsearch /and
41 /arc /arcn /arct /arcto /array
42 /ashow /astore /awidthshow /begin /bind
43 /bitshift /ceiling /charpath /clear /cleartomark
45 /clip /clippath /closepath /concat /concatmatrix
46 /copy /count /counttomark /currentcmykcolor /currentdash
47 /currentdict /currentfile /currentfont /currentgray /currentgstate
48 /currenthsbcolor /currentlinecap /currentlinejoin /currentlinewidth /currentmatrix
50 /currentpoint /currentrgbcolor /currentshared /curveto /cvi
51 /cvlit /cvn /cvr /cvrs /cvs
52 /cvx /def /defineusername /dict /div
53 /dtransform /dup /end /eoclip /eofill
55 /eoviewclip /eq /exch /exec /exit
56 /file /fill /findfont /flattenpath /floor
57 /flush /flushfile /for /forall /ge
58 /get /getinterval /grestore /gsave /gstate
60 /gt /identmatrix /idiv /idtransform /if
61 /ifelse /image /imagemask /index /ineofill
62 /infill /initviewclip /inueofill /inufill /invertmatrix
63 /itransform /known /le /length /lineto
65 /load /loop /lt /makefont /matrix
66 /maxlength /mod /moveto /mul /ne
67 /neg /newpath /not /null /or
68 /pathbbox /pathforall /pop /print /printobject
70 /put /putinterval /rcurveto /read /readhexstring
71 /readline /readstring /rectclip /rectfill /rectstroke
72 /rectviewclip /repeat /restore /rlineto /rmoveto
73 /roll /rotate /round /save /scale
75 /scalefont /search /selectfont /setbbox /setcachedevice
76 /setcachedevice2 /setcharwidth /setcmykcolor /setdash /setfont
77 /setgray /setgstate /sethsbcolor /setlinecap /setlinejoin
78 /setlinewidth /setmatrix /setrgbcolor /setshared /shareddict
80 /show /showpage /stop /stopped /store
81 /string /stringwidth /stroke /strokepath /sub
82 /systemdict /token /transform /translate /truncate
83 /type /uappend /ucache /ueofill /ufill
85 /undef /upath /userdict /ustroke /viewclip
86 /viewclippath /where /widthshow /write /writehexstring
87 /writeobject /writestring /wtranslation /xor /xshow
88 /xyshow /yshow /FontDirectory /SharedFontDirectory /Courier
90 /Courier-Bold /Courier-BoldOblique /Courier-Oblique /Helvetica /Helvetica-Bold
91 /Helvetica-BoldOblique /Helvetica-Oblique /Symbol /Times-Bold /Times-BoldItalic
92 /Times-Italic /Times-Roman /execuserobject /currentcolor /currentcolorspace
93 /currentglobal /execform /filter /findresource /globaldict
95 /makepattern /setcolor /setcolorspace /setglobal /setpagedevice
98 counttomark 256 exch sub { 0 } repeat
100 /= /== /ISOLatin1Encoding /StandardEncoding
102 ([) cvn (]) cvn /atan /banddevice /bytesavailable
103 /cachestatus /closefile /colorimage /condition /copypage
104 /cos /countdictstack /countexecstack /cshow /currentblackgeneration
105 /currentcacheparams /currentcolorscreen /currentcolortransfer /currentcontext /currentflat
107 /currenthalftone /currenthalftonephase /currentmiterlimit /currentobjectformat /currentpacking
108 /currentscreen /currentstrokeadjust /currenttransfer /currentundercolorremoval /defaultmatrix
109 /definefont /deletefile /detach /deviceinfo /dictstack
110 /echo /erasepage /errordict /execstack /executeonly
112 /exp /false /filenameforall /fileposition /fork
113 /framedevice /grestoreall /handleerror /initclip /initgraphics
114 /initmatrix /instroke /inustroke /join /kshow
115 /ln /lock /log /mark /monitor
117 /noaccess /notify /nulldevice /packedarray /quit
118 /rand /rcheck /readonly /realtime /renamefile
119 /renderbands /resetfile /reversepath /rootfont /rrand
120 /run /scheck /setblackgeneration /setcachelimit /setcacheparams
122 /setcolorscreen /setcolortransfer /setfileposition /setflat /sethalftone
123 /sethalftonephase /setmiterlimit /setobjectformat /setpacking /setscreen
124 /setstrokeadjust /settransfer /setucacheparams /setundercolorremoval /sin
125 /sqrt /srand /stack /status /statusdict
127 /true /ucachestatus /undefinefont /usertime /ustrokepath
128 /version /vmreclaim /vmstatus /wait /wcheck
129 /xcheck /yield /defineuserobject /undefineuserobject /UserObjects
132 /A /B /C /D /E /F /G /H /I /J /K /L /M
133 /N /O /P /Q /R /S /T /U /V /W /X /Y /Z
134 /a /b /c /d /e /f /g /h /i /j /k /l /m
135 /n /o /p /q /r /s /t /u /v /w /x /y /z
137 /setvmthreshold (<<) cvn
138 (>>) cvn /currentcolorrendering /currentdevparams /currentoverprint /currentpagedevice
139 /currentsystemparams /currentuserparams /defineresource /findencoding /gcheck
141 /glyphshow /languagelevel /product /pstack /resourceforall
142 /resourcestatus /revision /serialnumber /setcolorrendering /setdevparams
143 /setoverprint /setsystemparams /setuserparams /startjob /undefineresource
144 /GlobalFontDirectory /ASCII85Decode /ASCII85Encode /ASCIIHexDecode /ASCIIHexEncode
146 /CCITTFaxDecode /CCITTFaxEncode /DCTDecode /DCTEncode /LZWDecode
147 /LZWEncode /NullEncode /RunLengthDecode /RunLengthEncode /SubFileDecode
148 /CIEBasedA /CIEBasedABC /DeviceCMYK /DeviceGray /DeviceRGB
149 /Indexed /Pattern /Separation
152 dup /SystemNames exch def .installsystemnames
154 % Define printobject and writeobject.
155 % These are mostly implemented in PostScript, so that we don't have to
156 % worry about interrupts or callbacks when writing to the output file.
158 % Define procedures for accumulating the space required to represent
159 % an object in binary form.
160 /cntdict mark % <#refs> <#chars> <obj> -proc- <#refs> <#chars>
161 /integertype /pop load
166 /nametype { length add } bind
169 WRITEDICTS { /dicttype null } if
172 { dup dup length 5 -1 roll add 4 2 roll
173 { dup type //cntdict exch get exec } forall
177 { dup dup length 2 mul 5 -1 roll add 4 2 roll
178 { 4 1 roll dup type //cntdict exch get exec
179 3 -1 roll dup type //cntdict exch get exec
185 /nametype { 2 copy .writecvs pop } bind
189 /.bosheader { % <top_length> <total_length> <string8> .bosheader
191 dup 0 currentobjectformat 127 add put % object format => BOS tag
192 2 index 255 le 2 index 65531 le and {
193 % Use the short header format: tag toplen(1) totlen(2)
198 % Use the long header format: tag 0(1) toplen(2) totlen(4)
200 0 0 4 2 roll .bosobject exch pop exch pop % store with byte swapping
201 } ifelse % Stack: shortlen str
202 exch dup -8 bitshift exch 255 and % str hibyte lobyte
203 currentobjectformat 1 and 0 eq { % lsb first
206 2 index 3 3 -1 roll put
207 1 index 2 3 -1 roll put
210 /.writeobjects % <file> <tag> <array> .writeobjects -
214 % Count the space required for refs and strings.
215 dup length 0 3 -1 roll
216 % Stack: <file> <tag> -mark- <#refs> <#chars> <array>
219 { dup type //cntdict exch get exec
223 % Stack: <file> <tag> -mark- <array1> ... <array|dictN> <#refs> <#chars>
224 counttomark 3 add -2 roll 4 1 roll
225 % Stack: -mark- <array1> ... <array|dictN> <tag> <#refs> <#chars> <file>
226 dup counttomark 1 sub index length
227 4 index 3 bitshift 4 index add
228 (xxxxxxxx) .bosheader writestring
230 % Write the objects per se.
232 counttomark 1 sub index length 3 bitshift exch
234 % Stack: -mark- <array1> ... <array|dictN> <tag> <file> <ref#> <char#>
237 { counttomark -1 roll dup 6 1 roll
238 dup type /dicttype eq % can't be first object
239 { { 5 1 roll (xxxxxxxx) .bosobject
240 3 index exch writestring
241 4 -1 roll (xxxxxxxx) .bosobject
242 3 index exch writestring
245 { { (xxxxxxxx) .bosobject
247 3 index exch writestring
248 4 -1 roll pop 0 4 1 roll % clear tag
255 % Write the strings and names.
257 % Stack: -mark- <array1> ... <array|dictN> <file>
260 { counttomark -1 roll
261 { % The counting pass ensured that the keys and values
262 % of any dictionary must be writable objects.
263 % Hence, we are processing a dictionary iff
264 % the next-to-top stack element is not a file.
265 1 index type /filetype ne
266 { exch 2 index exch dup type //w2dict exch .knownget
267 { exec } { pop } ifelse pop
270 dup type //w2dict exch .knownget { exec } { pop } ifelse
276 % Stack: -mark- <file>
281 currentdict /cntdict .undef
282 currentdict /w2dict .undef
284 %%%% MRS - stderr instead of stdout, which is used for output...
285 /printobject { % <obj> <tag> printobject -
286 (%stderr) (w) file 2 index 2 index writeobject pop pop
288 /writeobject { % <file> <obj> <tag> writeobject -
290 % We must allocate the array in local VM
291 % to avoid a possible invalidaccess.
292 .currentglobal false .setglobal exch 1 array astore exch .setglobal
293 .writeobjects pop pop pop
296 % Implement binary error message output.
298 { $error /binary get .languagelevel 2 ge and
299 { currentobjectformat 0 ne
300 { [ /Error $error /errorname get $error /command get false