You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2875 lines
99 KiB

1 month ago
  1. % Copyright (C) 2001-2024 Artifex Software, Inc.
  2. % All Rights Reserved.
  3. %
  4. % This software is provided AS-IS with no warranty, either express or
  5. % implied.
  6. %
  7. % This software is distributed under license and may not be copied,
  8. % modified or distributed except as expressly authorized under the terms
  9. % of the license contained in the file LICENSE in this distribution.
  10. %
  11. % Refer to licensing information at http://www.artifex.com or contact
  12. % Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  13. % CA 94129, USA, for further information.
  14. %
  15. % Initialization file for the interpreter.
  16. % When this is run, systemdict is still writable.
  17. % Comment lines of the form
  18. % %% Replace <n> <file(s)>
  19. % indicate places where the next <n> lines should be replaced by
  20. % the contents of <file(s)>, when creating a single merged init file.
  21. %
  22. % For reasons not clear to me, some cases of %% are being treated as
  23. % DSC comments when (and only when) the resource files are disk based
  24. % This can kill DSC parsing for pdfwrite at least, so avoid using
  25. % double % comments in this file.
  26. % The interpreter can call out to PostScript code. All procedures
  27. % called in this way, and no other procedures defined in these
  28. % initialization files, have names that begin with %, e.g.,
  29. % (%Type1BuildChar) cvn.
  30. % Interpreter library version number
  31. % NOTE: the interpreter code requires that the first non-comment token
  32. % in this file be an integer, and that it match the compiled-in version!
  33. 10040
  34. % Check the interpreter revision.
  35. dup revision ne
  36. { (gs: Interpreter revision \() print revision 10 string cvs print
  37. (\) does not match gs_init.ps revision \() print 10 string cvs print
  38. (\).\n) print flush //null 1 .quit
  39. }
  40. if pop
  41. % Acquire userdict, and set its length if necessary.
  42. /userdict where
  43. { pop userdict maxlength 0 eq }
  44. { //true }
  45. ifelse
  46. systemdict exch
  47. { % userdict wasn't already set up by iinit.c.
  48. dup /userdict
  49. currentdict dup 200 .setmaxlength % userdict
  50. .forceput % userdict is local, systemdict is global
  51. } executeonly
  52. if begin
  53. % Init to global memory (possibly not needed, but left in for legacy purposes)
  54. //true .setglobal
  55. % Define .languagelevel if needed.
  56. systemdict /.languagelevel known not { /.languagelevel 1 def } if
  57. % Optionally choose a default paper size other than U.S. letter.
  58. % The default page size for many devices is set at compile time to
  59. % letter, but this can be changed to A4 although this is rarely done.
  60. % Some devices such as bbox have a different default page size,
  61. % and should not be set to A4 or letter.
  62. % When ghostscript is used in countries that use the international
  63. % standard page size A4 rather than US letter, the page size of
  64. % devices that default to letter or A4 can be changed by setting
  65. % DEFAULTPAPERSIZE.
  66. % /DEFAULTPAPERSIZE (a4) def
  67. % Turn on array packing for the rest of initialization.
  68. //true setpacking
  69. % Define the old MS-DOS EOF character as a no-op.
  70. % This is a hack to get around the absurd habit of MS-DOS editors
  71. % of adding an EOF character at the end of the file.
  72. <1a> cvn { } def
  73. % Acquire the debugging flags.
  74. currentdict /DEBUG known /DEBUG exch def
  75. % if DEBUG is set, set ALL of the subset debugging flags
  76. mark % '[' isn't defined yet
  77. /CCFONTDEBUG % Compiled Fonts
  78. /CFFDEBUG % CFF Fonts
  79. /CMAPDEBUG % CMAP
  80. /DOCIEDEBUG % CIE color
  81. /EPSDEBUG % EPS handling
  82. /FAPIDEBUG % Font API
  83. /INITDEBUG % Initialization
  84. /PDFDEBUG % PDF Interpreter
  85. /PDFWRDEBUG % PDF Writer
  86. /SETPDDEBUG % setpagedevice
  87. /TTFDEBUG % TTF Fonts
  88. /VGIFDEBUG % ViewGIF
  89. /VJPGDEBUG % ViewJPEG
  90. /RESMPDEBUG % Resource map
  91. counttomark array astore exch pop % ']' isn't defined yet
  92. { dup currentdict exch known DEBUG or def } forall
  93. currentdict /PDFSTEP known /PDFSTEP exch def
  94. % if PDFSTEP is on, turn on PDFDEBUG
  95. PDFSTEP { /PDFDEBUG //true def } if
  96. currentdict /PDFSTOPONERROR known /PDFSTOPONERROR exch def
  97. currentdict /PDFSTOPONWARNING known {/PDFSTOPONWARNING //true def /PDFSTOPONERROR //true def}{/PDFSTOPONWARNING //false def} ifelse
  98. currentdict /PDFNOCIDFALLBACK known /PDFNOCIDFALLBACK exch def
  99. % Versions of bind for use during startup:
  100. % bind - normal "bind", honors DELAYBIND
  101. % .bind - normal "bind", but ignores DELAYBIND
  102. % .internalbind - as "bind" but forces the executeonly attribute
  103. % .forcebind - as ".bind" but forces the executeonly attribute
  104. %
  105. % In general, for security and consistency startup code should use
  106. % .internalbind or .forcebind, and only use bind/.bind when we
  107. % cannot enforce executeonly on a given proc
  108. /.bind /bind load def
  109. /.internalbind {bind executeonly} .bind 1 index exch .makeoperator def
  110. /.forcebind {.bind executeonly} .bind 1 index exch .makeoperator def
  111. /VMDEBUG
  112. INITDEBUG {{print mark
  113. systemdict /level2dict known
  114. { .currentglobal dup //false .setglobal vmstatus
  115. //true .setglobal vmstatus 3 -1 roll pop
  116. 6 -2 roll pop .setglobal
  117. }
  118. { vmstatus 3 -1 roll pop
  119. }
  120. ifelse usertime 16#fffff and counttomark
  121. { ( ) print ( ) cvs print }
  122. repeat pop
  123. ( ) print systemdict length ( ) cvs print
  124. ( ) print countdictstack ( ) cvs print
  125. ( <) print count ( ) cvs print (>\n) print flush
  126. }}
  127. {{pop
  128. }}
  129. ifelse
  130. .forcebind def
  131. % This was a debugging switch removed in 9.22, no other software
  132. % should have had any regard for it, and even if testing its value
  133. % should have checked its existence first. However pstotext, an
  134. % ancient and no longer maintained piece of softare, did check
  135. % its value unconditionally. So we retain this key in the dictionary
  136. % purely for backward compatibility.
  137. /NOBIND //false def
  138. currentdict /BATCH known /BATCH exch def
  139. currentdict /DELAYBIND known /DELAYBIND exch def
  140. currentdict /DOINTERPOLATE .knownget { { -1 } { 1 } ifelse /InterpolateControl exch def } if
  141. currentdict /NOINTERPOLATE .knownget { { 0 } { 1 } ifelse /InterpolateControl exch def } if
  142. currentdict /ESTACKPRINT known /ESTACKPRINT exch def
  143. currentdict /FAKEFONTS known /FAKEFONTS exch def
  144. currentdict /FIXEDMEDIA known /FIXEDMEDIA exch def
  145. currentdict /FIXEDRESOLUTION known /FIXEDRESOLUTION exch def
  146. currentdict /LOCALFONTS known /LOCALFONTS exch def
  147. currentdict /JOBSERVER known /JOBSERVER exch def
  148. currentdict /NOCACHE known /NOCACHE exch def
  149. currentdict /NOCCFONTS known /NOCCFONTS exch def
  150. currentdict /NOCIE known /NOCIE exch def
  151. currentdict /NOPSICC known /NOPSICC exch def
  152. currentdict /NODISPLAY known not /DISPLAYING exch def
  153. currentdict /NOFONTMAP known /NOFONTMAP exch def
  154. currentdict /NOFONTPATH known /NOFONTPATH exch def
  155. currentdict /NOGC known /NOGC exch def
  156. currentdict /NOMEDIAATTRS known /NOMEDIAATTRS exch def
  157. currentdict /NOOUTERSAVE known /NOOUTERSAVE exch def
  158. currentdict /NOPAGEPROMPT known /NOPAGEPROMPT exch def
  159. currentdict /NOPAUSE known /NOPAUSE exch def
  160. currentdict /NOPLATFONTS known /NOPLATFONTS exch def
  161. currentdict /NOPROMPT known /NOPROMPT exch def
  162. currentdict /NOTRANSPARENCY known /NOTRANSPARENCY exch def
  163. currentdict /DOPS known /DOPS exch def
  164. currentdict /NOSUBSTDEVICECOLORS known /NOSUBSTDEVICECOLORS exch def
  165. % The default value of ORIENT1 is true, not false.
  166. currentdict /ORIENT1 known not { /ORIENT1 //true def } if
  167. currentdict /OSTACKPRINT known /OSTACKPRINT exch def
  168. currentdict /OUTPUTFILE known % obsolete
  169. { /OutputFile /OUTPUTFILE load def
  170. currentdict /OUTPUTFILE .undef
  171. } if
  172. currentdict /QUIET known /QUIET exch def
  173. % DELAYSAFER is effectively the same as newer NOSAFER
  174. currentdict /DELAYSAFER known { /DELAYSAFER //true def /NOSAFER //true def } if
  175. /SAFER currentdict /NOSAFER known {
  176. //false
  177. } {
  178. //true
  179. }
  180. ifelse def
  181. /OLDSAFER currentdict /OLDSAFER known def
  182. /SAFERERRORS
  183. currentdict /NOSAFERERRORS known
  184. {
  185. //false
  186. }
  187. {
  188. currentdict /SAFERERRORS known
  189. } ifelse def
  190. currentdict /ALLOWPSTRANSPARENCY known not
  191. {
  192. /ALLOWPSTRANSPARENCY //false def
  193. } if
  194. currentdict /SHORTERRORS known /SHORTERRORS exch def
  195. currentdict /TTYPAUSE known /TTYPAUSE exch def
  196. currentdict /WRITESYSTEMDICT known /WRITESYSTEMDICT exch def
  197. currentdict /RENDERTTNOTDEF known /RENDERTTNOTDEF exch def
  198. currentdict /SCANCONVERTERTYPE known
  199. {
  200. currentdict /SCANCONVERTERTYPE get .setscanconverter
  201. } if
  202. currentdict /EPSFitPage known { /PSFitPage //true def } if
  203. % This is a "convenience" option that sets a combination of EPSFitPage, PDFFitPage and PSFitPage
  204. currentdict /FitPage known { /EPSFitPage //true def /PDFFitPage //true def /PSFitPage //true def } if
  205. currentdict /SimulateOverprint known {
  206. (\n**** -dSimulateOverprint={true|false} is no longer supported. ****\n) print
  207. (**** It has been replaced by -dOverprint={enable|disable|simulate} ****\n\n) print
  208. % Set the new variable appropriately.
  209. /Overprint SimulateOverprint { /enable } { /disable } ifelse def
  210. } if
  211. % Acquire environment variables.
  212. currentdict /DEVICE known not
  213. { (GS_DEVICE) getenv { /DEVICE exch def } if } if
  214. (START) VMDEBUG
  215. % Open the standard files, so they will be open at the outermost save level.
  216. (%stdin) (r) file pop
  217. (%stdout) (w) file pop
  218. (%stderr) (w) file pop
  219. /.currentuserparams where {
  220. pop mark
  221. % The Adobe implementations appear to have very large maximum
  222. % stack sizes. This turns out to actually make a difference,
  223. % since some badly-behaved files include extremely long procedures,
  224. % or construct huge arrays on the operand stack.
  225. % We reset the stack sizes now so that we don't have to worry
  226. % about overflowing the (rather small) built-in stack sizes
  227. % during initialization.
  228. /MaxDictStack 500
  229. /MaxExecStack 5000
  230. /MaxOpStack 300000
  231. .dicttomark .setuserparams
  232. } if
  233. % Define a procedure for skipping over an unneeded section of code.
  234. % This avoids allocating space for the skipped procedures.
  235. % We can't use readline, because that imposes a line length limit.
  236. /.skipeof % <string> .skipeof -
  237. { currentfile exch 1 exch .subfiledecode flushfile
  238. } .forcebind def
  239. % Define procedures to assist users who don't read the documentation.
  240. userdict begin
  241. /help
  242. { (Enter PostScript commands. '(filename) run' runs a file, 'quit' exits.\n)
  243. print flush
  244. } .forcebind def
  245. end
  246. % Define =string, which is used by some PostScript programs even though
  247. % it isn't documented anywhere.
  248. % Put it in userdict so that each context can have its own copy.
  249. userdict /=string 256 string put
  250. % Print the greeting.
  251. /printgreeting
  252. { mark
  253. product (GPL Ghostscript) search
  254. { pop pop pop
  255. (This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:\nsee the file COPYING for details.\n)
  256. }
  257. { pop
  258. }
  259. ifelse
  260. (\n) copyright
  261. (\)\n) revisiondate 10 mod revisiondate 10 idiv 10 mod (-)
  262. revisiondate 100 idiv 10 mod revisiondate 1000 idiv 10 mod (-)
  263. revisiondate 10000 idiv ( \()
  264. .revisionstring ( )
  265. product
  266. counttomark
  267. { (%stdout) (w) file exch 0 .writecvp
  268. } repeat pop
  269. } .forcebind def
  270. QUIET not { //printgreeting exec flush } if
  271. currentdict /printgreeting .undef
  272. % Define a special version of def for making operator procedures.
  273. /obind { % <name> <proc> obind <name> <oper>
  274. 1 index exch .makeoperator
  275. } .forcebind def
  276. /odef { % <name> <proc> odef -
  277. 1 index exch .makeoperator def
  278. } .forcebind def
  279. % Define procedures for accessing variables in systemdict and userdict
  280. % regardless of the contents of the dictionary stack.
  281. /.systemvar { % <name> .systemvar <value>
  282. //systemdict exch get
  283. } .forcebind odef
  284. /.systemexec {
  285. .systemvar exec
  286. } .forcebind odef
  287. /.userdict { % - .userdict <dict>
  288. /userdict .systemvar
  289. } .forcebind odef
  290. /.uservar { % <name> .uservar <value>
  291. .userdict exch get
  292. } .forcebind odef
  293. % If we're delaying binding, remember everything that needs to be bound later.
  294. DELAYBIND
  295. {
  296. SAFER {
  297. (\n *** WARNING - you have selected SAFER, indicating you want Ghostscript\n) print
  298. ( to execute in a safer environment, but at the same time\n) print
  299. ( have selected DELAYBIND. Unless you use this option with\n) print
  300. ( care \(and specifically, remember to call .bindnow\) it is\n) print
  301. ( possible that malicious code may be able to evade the\n) print
  302. ( limited security offered by the SAFER option.\n) print flush
  303. } if
  304. .currentglobal //false .setglobal
  305. systemdict /.delaybind 2000 array .forceput
  306. systemdict /.delayinternalbind 2000 array .forceput
  307. .setglobal
  308. userdict /.delaycount 0 put
  309. userdict /.delayinternalcount 0 put
  310. % When we've done the delayed bind, we want to stop saving.
  311. % Detect this by the disappearance of .delaybind.
  312. /bind
  313. { /.delaybind .systemvar dup length 0 ne
  314. { .delaycount 2 index put
  315. .userdict /.delaycount .delaycount 1 add put
  316. }
  317. { pop /.bind cvx exec
  318. }
  319. ifelse
  320. } .forcebind odef
  321. /.internalbind
  322. { /.delayinternalbind .systemvar dup length 0 ne
  323. { .delayinternalcount 2 index put
  324. .userdict /.delayinternalcount .delayinternalcount 1 add put
  325. }
  326. { pop /.forcebind cvx exec
  327. }
  328. ifelse
  329. } .forcebind odef
  330. } executeonly if
  331. .currentglobal //true .setglobal
  332. /.undefinternalnameslist 10 dict def
  333. .setglobal
  334. % Under normal operation .undefinternalnames simply removes
  335. % the keys in the array parameter from the dictionary parameter.
  336. % Under DELAYBIND operation, we accumulate the names in dictionaries,
  337. % stored in .undefinternalnameslist, and then .bindow calls
  338. % .applyundefinternalnames once all binds have been applied.
  339. % The .undefinternalnameslist dictionary is a little odd in that it
  340. % uses the dictionary from which the keys should be undefined as the
  341. % 'key' and then the value is a dictionary whose key/value pairs are
  342. % both the names to be undefined.
  343. %
  344. % [array of names] <<dict from which to undef>> .undefinternalnames -
  345. /.undefinternalnames
  346. {
  347. DELAYBIND
  348. {
  349. .currentglobal //true .setglobal 3 1 roll
  350. dup //.undefinternalnameslist exch .knownget not
  351. {
  352. 128 dict dup 3 1 roll
  353. //.undefinternalnameslist 3 1 roll put
  354. }{exch pop} ifelse
  355. exch
  356. {
  357. dup 2 index 3 1 roll put
  358. } forall
  359. pop
  360. .setglobal
  361. }
  362. {
  363. exch
  364. {
  365. 1 index exch .forceundef
  366. } executeonly forall
  367. pop
  368. } executeonly ifelse
  369. } .forcebind def
  370. /.applyundefinternalnames
  371. {
  372. //.undefinternalnameslist
  373. {
  374. {
  375. pop
  376. 1 index exch .forceundef
  377. } executeonly forall
  378. pop
  379. } executeonly forall
  380. } .forcebind def
  381. %**************** BACKWARD COMPATIBILITY ****************
  382. /hwsizedict mark /HWSize //null .dicttomark readonly def
  383. /copyscanlines { % <device> <y> <string> copyscanlines <substr>
  384. 0 3 1 roll 3 index //hwsizedict .getdeviceparams
  385. exch pop exch pop aload pop 3 2 roll
  386. 0 exch //null exch .getbitsrect exch pop
  387. } .internalbind odef
  388. currentdict /hwsizedict .undef
  389. /getdeviceprops
  390. { //null .getdeviceparams
  391. } .internalbind odef
  392. % NOTE: Note sure why/if this needs to be a separate operator. Consider rolling this
  393. % implementation into /putdeviceprops ?
  394. /.putdeviceprops
  395. { //null //true counttomark 1 add 3 roll .putdeviceparams
  396. dup type /booleantype ne
  397. { dup mark eq { /unknown /rangecheck } if
  398. counttomark 4 add 1 roll cleartomark pop pop pop
  399. /.putdeviceprops .systemvar exch signalerror
  400. }
  401. if
  402. } .internalbind odef
  403. /.writecvs { 0 .writecvp } .internalbind odef
  404. %**************** DEPRECATED PROCEDURES ****************
  405. %**************** DO NOT USE THESE IN NEW CODE ****************
  406. % Keeping these because they have been around a long time and we don't want to break old code that's out in the wild
  407. /max { .max } .internalbind def % use .max instead
  408. /min { .min } .internalbind def % use .min instead
  409. %**************** END OF BACKWARD COMPATIBILITY SECTION ****************
  410. % Utility for removing all entries from a dictionary
  411. /.PurgeDict % <dict> .PurgeDict -
  412. { { //true
  413. 1 index { pop exch pop //false exit
  414. } forall
  415. { exit
  416. } if
  417. 1 index exch undef
  418. } loop
  419. pop
  420. } .internalbind def
  421. % Define predefined procedures substituting for operators,
  422. % in alphabetical order.
  423. userdict /#copies 1 put
  424. % Adobe implementations don't accept /[ or /], so we don't either.
  425. ([) cvn
  426. /mark load def
  427. (]) cvn
  428. {counttomark array astore exch pop} odef
  429. %
  430. % - initgraphics -
  431. %
  432. % Although the internal routine gs_initgraphics resets the color space,
  433. % it does not reset the color space we store in the 'interpreter'
  434. % graphics state (so that we can hand it back in currentcolorspace).
  435. % So we need to do that in the PostScript world.
  436. %
  437. %
  438. /initgraphics
  439. { initgraphics systemdict /DeviceGray_array get setcolorspace }
  440. .forcebind odef
  441. /currentmatrix {
  442. dup type /arraytype ne
  443. { /currentmatrix load /typecheck signalerror } if
  444. dup length 6 ne
  445. { /currentmatrix load /rangecheck signalerror } if
  446. .currentmatrix 6 .argindex astore pop
  447. } odef
  448. % We have to guard against the BeginPage procedure not popping its operand.
  449. % This is really stupid, but the Genoa CET does it.
  450. /.beginpage { % - .beginpage -
  451. .updatematrices
  452. .currentshowpagecount {
  453. .currentpagedevice pop
  454. dup //null ne { /BeginPage .knownget } { pop //false } ifelse {
  455. % Stack: ... pagecount proc
  456. count 2 .execn
  457. % Stack: ... ..???.. oldcount
  458. count 1 add exch sub { pop } repeat
  459. } {
  460. pop
  461. } ifelse
  462. } if
  463. } .forcebind odef
  464. % Guard similarly against EndPage not popping its operand.
  465. /.endpage { % <reason> .endpage <print_bool>
  466. .updatematrices
  467. .currentshowpagecount {
  468. 1 index .currentpagedevice pop
  469. dup //null ne { /EndPage .knownget } { pop //false } ifelse {
  470. % Stack: ... reason pagecount reason proc
  471. count 2 .execn
  472. % Stack: ... ..???.. print oldcount
  473. count 2 add exch sub { exch pop } repeat
  474. } {
  475. pop pop 2 ne
  476. } ifelse
  477. } {
  478. 2 ne
  479. } ifelse
  480. } .forcebind odef
  481. % Define .currentnumcopies so it consults the NumCopies device parameter.
  482. /.numcopiesdict mark
  483. /NumCopies dup
  484. .dicttomark readonly def
  485. /.currentnumcopies
  486. { currentdevice //.numcopiesdict .getdeviceparams
  487. dup type /integertype eq
  488. { exch pop exch pop }
  489. { cleartomark #copies }
  490. ifelse
  491. } .forcebind odef
  492. /setcolorscreen where { pop % not in all Level 1 configurations
  493. /currentcolorscreen
  494. { .currenthalftone
  495. { { 60.0 exch 0.0 exch 3 copy 6 copy } % halftone - not possible
  496. { 3 copy 6 copy } % screen
  497. { } % colorscreen
  498. }
  499. exch get exec
  500. } odef
  501. } if
  502. /currentscreen
  503. { .currenthalftone
  504. { { 60.0 exch 0.0 exch } % halftone - not possible
  505. { } % screen
  506. { 12 3 roll 9 { pop } repeat } % colorscreen
  507. }
  508. exch get exec
  509. } odef
  510. /.echo /echo load def
  511. userdict /.echo.mode //true put
  512. /echo {dup /.echo.mode exch store .echo} odef
  513. /.eexec_param_dict mark
  514. /eexec //true
  515. /seed 55665
  516. .dicttomark readonly def
  517. /eexec {
  518. % Rebind .currentresourcefile if it is the source for the eexec.
  519. dup //.eexec_param_dict //filterdict /eexecDecode get exec
  520. cvx exch .currentresourcefile eq
  521. //systemdict begin { {exec} .execasresource } { exec } ifelse
  522. % Only pop systemdict if it is still the top element,
  523. % because this is apparently what Adobe interpreters do.
  524. currentdict //systemdict eq { end } if
  525. } odef
  526. % erasepage mustn't use gsave/grestore, because we call it before
  527. % the graphics state stack has been fully initialized.
  528. /erasepage
  529. { /currentcolor where
  530. { pop currentcolor currentcolorspace { setcolorspace setcolor } }
  531. { /currentcmykcolor where
  532. { pop currentcmykcolor { setcmykcolor } }
  533. { currentrgbcolor { setrgbcolor } }
  534. ifelse
  535. }
  536. ifelse
  537. currentoverprint //false setoverprint 1 setgray .fillpage setoverprint
  538. exec
  539. } odef
  540. % Define a procedure for clearing the error indication.
  541. /.clearerror
  542. { $error /newerror //false put
  543. $error /errorname //null put
  544. $error /errorinfo //null put
  545. 0 .setoserrno
  546. } .internalbind def
  547. % To satisfy the Genoa FTS, executive must be a procedure, not an operator.
  548. % Define the procedure used by .runfile, .runstdin and .runstring
  549. % for executing user input.
  550. % This is called with a procedure or executable file on the operand stack.
  551. /.execute { % <obj> .execute <stopped>
  552. stopped $error /newerror get and
  553. { /handleerror .systemvar exec flush //true } { //false } ifelse
  554. } .internalbind def
  555. % Define an execute analogue of runlibfile0.
  556. /execute0 { % <obj> execute0 -
  557. //.execute exec { /execute0 cvx 1 .quit } if
  558. } .internalbind def
  559. /executive
  560. { { prompt
  561. { (%statementedit) (r) .systemvmfile } stopped
  562. { pop pop $error /errorname get /undefinedfilename eq
  563. { //.clearerror exec exit } if % EOF
  564. /handleerror .systemvar exec //null % ioerror??
  565. }
  566. if
  567. cvx { .runexec } //.execute exec pop
  568. } loop
  569. } .internalbind def
  570. currentdict /.execute .undef
  571. /filter
  572. { //filterdict 1 .argindex .knownget
  573. { exch pop exec }
  574. { /filter .systemvar /undefined signalerror }
  575. ifelse
  576. } odef
  577. % Internal uses of stopped that aren't going to do a stop if an error occurs
  578. % should use .internalstopped to avoid setting newerror et al.
  579. /.internalstopped { //null 1 .stopped //null ne } .internalbind def
  580. % handleerror procedure as mentioned in the "Operators" section of the PLRM Section 8.2
  581. % This invokes the handleerror procedure from errordict (unless we are running under a
  582. % JOBSERVER where we want to always use a defined error handler (many error handlers in
  583. % 'wild' PostScript files are broken and don't indicate the error in any useful fashion).
  584. %
  585. % We run the handleerror procedure using .internalstopped so that broken error handlers
  586. % won't cause nested errors (Unexpected Error conditions).
  587. /handleerror
  588. //systemdict /JOBSERVER get{
  589. { /.GShandleerror .systemvar //.internalstopped exec pop } .internalbind % always use .GShandleerror.
  590. } {
  591. { /errordict .systemvar /handleerror get //.internalstopped exec pop } .internalbind % PLRM standard errorhandling
  592. } ifelse def
  593. /identmatrix [1.0 0.0 0.0 1.0 0.0 0.0] readonly def
  594. /identmatrix {
  595. dup type /arraytype ne { /identmatrix load /typecheck signalerror } if
  596. dup length 6 ne { /identmatrix load /rangecheck signalerror } if
  597. dup 0 //identmatrix putinterval
  598. } odef
  599. /languagelevel 1 def % gs_lev2.ps may change this
  600. /makeimagedevice { //false makewordimagedevice } odef
  601. /matrix { 6 array identmatrix } odef
  602. /.promptmsg {
  603. (GS) print
  604. count 0 ne { (<) print count =only } if
  605. (>) print flush
  606. } .internalbind def
  607. /prompt { flush flushpage //systemdict /NOPROMPT get not { //.promptmsg exec} if } .internalbind def
  608. currentdict /.promptmsg .undef
  609. /pstack { 0 1 count 3 sub { index == } for } .internalbind def
  610. /putdeviceprops
  611. { .putdeviceprops { erasepage } if } .internalbind odef
  612. /quit { /quit load 0 .quit } odef
  613. /run { dup type /filetype ne { (r) .systemvmfile } if
  614. % We must close the file when execution terminates,
  615. % regardless of the state of the stack,
  616. % and then propagate an error, if any.
  617. cvx //null {.runexec} .errorexec
  618. } odef
  619. % Execute a file.
  620. % Level 2 uses 2 .stop to clear the e-stack for a successful startjob:
  621. % we detect that here, since we need to handle this even if we start out
  622. % without job control in effect.
  623. %
  624. % What we push on the e-stack is the following to be executed in this order:
  625. % <lit-file|fileproc> .runexec1 <lit-file|fileproc> .runexec2
  626. /.runexec1 { % <file|fileproc> .runexec1 -
  627. dup type /filetype ne { cvx exec } if
  628. cvx //null 2 .stopped
  629. % If we got back here from a startjob, just keep going.
  630. % startjob replaces the null on the o-stack with a procedure
  631. % to be executed when we get back here.
  632. dup //null ne { exec //true } { pop //false } ifelse
  633. } .internalbind def
  634. /.runexec2 { % <continue> <file|fileproc> .runexec2 -
  635. exch {
  636. .runexec
  637. } {
  638. dup type /filetype ne { cvx exec } if
  639. closefile
  640. } ifelse
  641. } .internalbind def
  642. /.runexec { % <file|fileproc> .runexec -
  643. cvlit /.runexec1 cvx 1 index /.runexec2 cvx 4 .execn
  644. } .internalbind def
  645. % The following is only for compatibility with Adobe interpreters.
  646. /setdash {
  647. 0 .argindex type dup /integertype eq exch /realtype eq or not {
  648. /setdash .systemvar /typecheck signalerror
  649. } if
  650. //setdash
  651. } odef
  652. /setdevice
  653. {
  654. .setdevice
  655. {
  656. mark
  657. { % Reset the halftone since the device may differ
  658. currenthalftone
  659. dup type /dicttype eq
  660. { sethalftone }
  661. { pop }
  662. ifelse
  663. }
  664. stopped
  665. cleartomark
  666. erasepage
  667. }
  668. if
  669. }
  670. odef
  671. /setlinecap {
  672. dup 2 gt { /setlinecap .systemvar /rangecheck signalerror } if
  673. .setlinecap
  674. } odef
  675. /setlinejoin {
  676. dup 2 gt { /setlinejoin .systemvar /rangecheck signalerror } if
  677. .setlinejoin
  678. } odef
  679. /setmatrix {
  680. dup type /arraytype ne {
  681. dup type /packedarraytype ne {
  682. /setmatrix load /typecheck signalerror
  683. } if
  684. } if
  685. dup length 6 ne { /setmatrix load /rangecheck signalerror } if
  686. dup aload pop .setmatrix pop
  687. } odef
  688. /.confirmread {
  689. //systemdict /TTYPAUSE get {
  690. (/dev/tty) (r) file dup read pop pop closefile
  691. } {
  692. .echo.mode //false echo
  693. (%stdin) (r) file dup read {
  694. dup (\n) 0 get eq { pop pop } { .unread } ifelse
  695. } {
  696. pop
  697. } ifelse echo
  698. } ifelse
  699. } .internalbind def
  700. /.confirm {
  701. //systemdict /DISPLAYING get //systemdict /NOPAUSE get not //systemdict /TTYPAUSE get or and {
  702. % Print a message (unless NOPAGEPROMPT or NOPROMPT is true)
  703. % and wait for the user to type something.
  704. % If the user just types a newline, flush it.
  705. //systemdict /NOPAGEPROMPT get //systemdict /NOPROMPT get or { pop } { print flush } ifelse
  706. //.confirmread exec
  707. } {
  708. pop
  709. } ifelse
  710. } .internalbind def
  711. % In LanguageLevel 3, copypage erases the page.
  712. /copypage {
  713. .languagelevel 3 ge
  714. dup { 0 } { 1 } ifelse .endpage .doneshowpage {
  715. .currentnumcopies 1 index .outputpage
  716. (>>copypage, press <return> to continue<<\n) //.confirm exec
  717. dup { erasepage } if
  718. } if pop
  719. systemdict /..page_default_spaces .knownget { //.PurgeDict exec } if
  720. .beginpage
  721. } .forcebind odef
  722. /showpage {
  723. 0 .endpage .doneshowpage {
  724. .currentnumcopies //true .outputpage
  725. (>>showpage, press <return> to continue<<\n) //.confirm exec
  726. % Uncomment the following line, and use a Memento build to track
  727. % blocks that are created and not destroyed between each successive
  728. % page.
  729. % 2 .vmreclaim .mementolistnewblocks
  730. initgraphics
  731. currentoverprint //false setoverprint 1 setcolor
  732. .fillpage
  733. setoverprint 0 setcolor
  734. }
  735. { initgraphics } ifelse
  736. systemdict /..page_default_spaces .knownget { //.PurgeDict exec } if
  737. .beginpage
  738. } .forcebind odef
  739. % Code output by Adobe Illustrator relies on the fact that
  740. % `stack' is a procedure, not an operator!!!
  741. /stack { 0 1 count 3 sub { index = } for } .internalbind def
  742. /start { //systemdict /BATCH get { //null 0 .quit } { executive } ifelse } def
  743. /store { % Don't alter operands before completing.
  744. 1 .argindex where { 2 index 2 index put pop pop } { def } ifelse
  745. } odef
  746. /.typenames mark .typenames counttomark packedarray exch pop def
  747. /type {
  748. //.typenames .type
  749. } odef
  750. currentdict /.typenames .undef
  751. % When running in Level 1 mode, this interpreter is supposed to be
  752. % compatible with PostScript "version" 54.0 (I think).
  753. /version (54.0) readonly def
  754. /.wheredict 10 dict def
  755. /.where /where load def
  756. /where {
  757. //.wheredict 1 .argindex .knownget { exec } { .where } ifelse
  758. } odef
  759. % internaldict is defined in systemdict, but the dictionary is allocated
  760. % in local VM. However, the procedure must be global, since it is an
  761. % "operator" and must be bind-able into global procedures.
  762. /.makeinternaldict {
  763. .currentglobal //true .setglobal
  764. [ /dup .systemvar 1183615869 /eq .systemvar
  765. [ /pop .systemvar //null ] cvx
  766. //false .setglobal
  767. dup 1 10 dict .forceput % proc is global, dict is local
  768. //true .setglobal
  769. [ /internaldict /cvx .systemvar /invalidaccess /signalerror cvx ] cvx
  770. /ifelse .systemvar
  771. ] cvx executeonly
  772. exch .setglobal
  773. } def
  774. systemdict /internaldict dup .makeinternaldict .makeoperator
  775. .forceput % proc is local, systemdict is global
  776. currentdict /.makeinternaldict .undef
  777. % Define some additional built-in procedures (beyond the ones defined by
  778. % the PostScript Language Reference Manual).
  779. % Warning: these are not guaranteed to stay the same from one release
  780. % to the next!
  781. /concatstrings % (str1) (str2) concatstrings (str1str2)
  782. { exch dup length 2 index length add string % str2 str1 new
  783. dup dup 4 2 roll copy % str2 new new new1
  784. length 4 -1 roll putinterval
  785. } .internalbind def
  786. /copyarray
  787. { dup length array copy } .internalbind def
  788. % Copy a dictionary per the Level 2 spec even in Level 1.
  789. /.copydict % <fromdict> <todict> .copydict <todict>
  790. { dup 3 -1 roll { put dup } forall pop } .internalbind def
  791. /findlibfile {
  792. .systemvmlibfile { dup .filename pop exch //true } { //false } ifelse
  793. } odef
  794. /.growdictlength % get size for growing a dictionary
  795. { length 3 mul 2 idiv 1 add
  796. } .internalbind def
  797. /.growdict % grow a dictionary
  798. { dup //.growdictlength exec .setmaxlength
  799. } .internalbind def
  800. /.growput % put, grow the dictionary if needed
  801. { 2 index length 3 index maxlength eq
  802. { 3 copy pop known not { 2 index //.growdict exec} if
  803. } if
  804. put
  805. } .internalbind def
  806. % .localvmarray may be an operator: see zsysvm.c.
  807. /.localvmarray where {
  808. pop
  809. } {
  810. /.localvmarray {
  811. .currentglobal //false .setglobal
  812. exch array exch .setglobal
  813. } .internalbind def
  814. } ifelse
  815. /.localvmdict where {
  816. pop
  817. } {
  818. /.localvmdict {
  819. .currentglobal //false .setglobal
  820. exch dict exch .setglobal
  821. } .internalbind def
  822. } ifelse
  823. /.packtomark
  824. { counttomark packedarray exch pop } .internalbind def
  825. /runlibfile
  826. { % We don't want to .internalbind 'run' into this procedure,
  827. % since run may get redefined.
  828. findlibfile
  829. { exch pop /run .systemvar exec }
  830. { /undefinedfilename signalerror }
  831. ifelse
  832. } .internalbind def
  833. /selectdevice
  834. { finddevice setdevice .setdefaultscreen } .internalbind odef
  835. /signalerror % <object> <errorname> signalerror -
  836. { /errordict .systemvar exch get exec } .internalbind def
  837. /signaloperror { % <object> <errorname> signaloperror -
  838. % Same as signalerror, except that if we are inside a pseudo-operator
  839. % or .errorexec, we use its error object, just as errors generated by
  840. % real operators do.
  841. /errordict .systemvar exch get
  842. .finderrorobject { 3 -1 roll pop exch } if
  843. exec
  844. } .internalbind def
  845. % Define the =[only] procedures. Also define =print,
  846. % which is used by some PostScript programs even though
  847. % it isn't documented anywhere.
  848. /write=only {
  849. .writecvs
  850. } .internalbind def
  851. /write= {
  852. 1 index exch write=only (\n) writestring
  853. } .internalbind def
  854. /=only { (%stdout) (w) file exch write=only } .internalbind odef
  855. /= { =only (\n) print } .internalbind def
  856. /=print /=only load def
  857. % Temporarily define == as = for the sake of runlibfile0.
  858. /== /= load def
  859. % Function to purge a named device from the device cache. This is required if we
  860. % want to 'reset' a device. The setpagedevice implementation, when it creates a
  861. % device instance, stores it in a cache. Next time we select a device we look in
  862. % the cache and, if we find we cached it, then we use the cached device.
  863. %
  864. % Presumably this is intended as an optimisation, but it defeats the expected use
  865. % of save and restore wihth devices because, after we restore a device away it is
  866. % not destroyed, it is in the cache. Requesting the same named device will return
  867. % the cached device, crucially *without* resetting any of its parameters. In
  868. % particular NumPages which is used to number output files and is a read-only parameter.
  869. %
  870. % /name uncachedevice -
  871. %
  872. /uncachedevice
  873. {
  874. % Check we've been given a name
  875. dup type /nametype eq
  876. {
  877. % Check the name isn't the current device. Check both /Name
  878. % and /OutputDevice. There seem to be some conditions where
  879. % only one is present.
  880. %
  881. currentpagedevice /Name known
  882. {
  883. dup currentpagedevice /Name get eq
  884. }
  885. {
  886. //false
  887. }ifelse
  888. currentpagedevice /OutputDevice known
  889. {
  890. 1 index currentpagedevice /OutputDevice get eq
  891. }
  892. {
  893. //false
  894. }ifelse
  895. % We tested /Name and /OutputDevice to see if they exist, if they do
  896. % we checked them against the requested device. If either matches the requested
  897. % device we report an error, otherwise we remove the device from the cache.
  898. %
  899. or
  900. {
  901. (*** ERROR: Can't uncache the current device\n) print
  902. /uncachedevice /invalidaccess signalerror
  903. }
  904. {
  905. % Make sure devicedict exists, if it does not, ignore
  906. % the request because this code doesn't know how to
  907. % deal with this PostScript itnerpreter.
  908. /devicedict where
  909. {
  910. % Get devicedict out of its containing dictionary
  911. /devicedict get dup % stack: /device -devicedict- -devicedict-
  912. % Check if the device we were given is known
  913. 2 index known % stack: /device -devicedict- bool
  914. {
  915. % device was known, get the key/value pair from devicedict
  916. dup 2 index get % stack: /device -devicedict- value
  917. % We expect the value in devicedict to be an array, check it is
  918. dup type /arraytype eq
  919. {
  920. dup 1 null put % stack: /device -devicedict- [-device- null]
  921. 3 -1 roll exch % stack: -devicedict- /device [-device- null]
  922. put % stack: -
  923. }
  924. {
  925. % Value in devicedict associated with the named key is not an array
  926. /uncachedevice /typecheck signalerror
  927. } ifelse
  928. }
  929. {
  930. % The named key is not present in devicedict
  931. /uncachedevice /undefined signalerror
  932. } ifelse
  933. } if
  934. } ifelse
  935. }
  936. {
  937. % The parameter we were given wasn't a name type
  938. /uncachedevice /typecheck signalerror
  939. } ifelse
  940. } bind readonly odef
  941. % Function to purge all but the current device from the device cache
  942. %
  943. % - purgedevicecache -
  944. %
  945. /purgedevicecache
  946. {
  947. % Find devicedict, if it doesn't exist just exit silently, we don't know
  948. % how to deal with this PostScript interpreter
  949. /devicedict where
  950. {
  951. % Get devicedict from the containing dictionary
  952. /devicedict get
  953. % For each key/value pair in devicedict
  954. {
  955. pop % Discard the value
  956. dup currentpagedevice /Name get eq not % Check if the key is the same as the current device
  957. {
  958. uncachedevice % If not, purge the device from the cache
  959. }
  960. {
  961. pop % Don't purge the current device
  962. } ifelse
  963. } forall
  964. } if
  965. } bind readonly odef
  966. /finddevice { % <devicename> finddevice <device>
  967. /devicedict .systemvar exch get
  968. dup 1 get //null eq {
  969. % This is the first request for this type of device.
  970. % Create a default instance now.
  971. % Stack: [proto null]
  972. .currentglobal //true .setglobal exch
  973. dup dup 0 get //false .copydevice2 1 exch put
  974. exch .setglobal
  975. } if 1 get
  976. } .internalbind odef
  977. % The following procedures are documented.
  978. % Run a resource file. This allows us to distinguish resource objects
  979. % from objects coming from input files.
  980. userdict /.currentresourcefile //null put
  981. /.execasresource { % <file> <proc|runfile> .execasresource -
  982. /stopped .systemvar
  983. /.currentresourcefile .uservar
  984. % Stack: file proc -stopped- currfile
  985. .userdict /.currentresourcefile 5 index cvlit put
  986. 2 .execn % stopped <file>
  987. .userdict /.currentresourcefile 3 -1 roll put
  988. { stop } if
  989. } .internalbind def
  990. /.runresource { % <file> .runresource -
  991. { /run .systemvar exec } .execasresource
  992. } .internalbind def
  993. % Convenience function (documented extension)
  994. /.shellarguments % -> shell_arguments true (or) false
  995. { /ARGUMENTS where
  996. { /ARGUMENTS get dup type /arraytype eq
  997. { aload pop /ARGUMENTS //null store //true }
  998. { pop //false }
  999. ifelse }
  1000. { //false } ifelse
  1001. } .internalbind def
  1002. % Define the procedure that the C code uses for running files
  1003. % named on the command line.
  1004. /.runfile {
  1005. { runlibfile } execute0
  1006. } def
  1007. % Define the procedure that the C code uses for running piped input.
  1008. % We don't use the obvious { (%stdin) run }, because we want the file to be
  1009. % reopened if a startjob does a restore.
  1010. /.runstdin {
  1011. { { (%stdin) (r) file cvx } .runexec } execute0
  1012. } .internalbind def
  1013. % Define the procedure that the C code uses for running commands
  1014. % given on the command line with -c. We turn the string into a file so that
  1015. % .runexec can do the right thing with a startjob.
  1016. /.runstring {
  1017. 0 0 .systemvmstring .systemvmSFD cvx { .runexec } execute0
  1018. } .internalbind def
  1019. % Define the procedure that the C code uses to set up for executing
  1020. % a string that may be received in pieces.
  1021. %
  1022. % Immediate evaluation doesn't work on operators (like .needinput)
  1023. % so calling .runstringbegin will throw an undefined error if we
  1024. % undefined .needinput so it cannot be accessed outside the init
  1025. % code. But, we can store the operator in an array, use immediate
  1026. % evaluation on the array to get the operator, then undefined the
  1027. % array (and because they are both of the same name, the operator
  1028. % get undefined too).
  1029. % This prevents random Postscript from erroneously calling .needinput
  1030. % and forcing the interpreter into an invalid state.
  1031. /.needinput
  1032. 1 .systemvmarray dup 0 /.needinput load put
  1033. def
  1034. /.runstringbegin {
  1035. 1 .systemvmarray dup 0 //.needinput 0 get put cvx % { .needinput } in systemvm
  1036. 0 0 .systemvmstring .systemvmSFD cvx .runexec
  1037. } .internalbind def
  1038. % Define a special version of runlibfile that aborts on errors.
  1039. /runlibfile0
  1040. { cvlit dup dup /.currentfilename exch def
  1041. { findlibfile not { stop } if }
  1042. stopped
  1043. { (Can't find \(or open\) initialization file ) print
  1044. .currentfilename == flush /runlibfile0 cvx 1 .quit
  1045. } if
  1046. exch pop cvx
  1047. { stopped } 0 get 3 -1 roll 2 array astore cvx exec
  1048. /.currentfilename exch store
  1049. { (While reading ) print .currentfilename print (:\n) print flush
  1050. /handleerror .systemvar exec /runlibfile0 1 .quit
  1051. } if
  1052. } .internalbind def
  1053. % Temporarily substitute it for the real runlibfile.
  1054. /.runlibfile /runlibfile load def
  1055. /runlibfile //runlibfile0 def
  1056. currentdict /runlibfile0 .undef
  1057. % Create the error handling machinery.
  1058. % Define the standard error handlers.
  1059. % The interpreter has created the ErrorNames array.
  1060. /.unstoppederrorhandler % <command> <errorname> .unstoppederrorhandler -
  1061. { % This is the handler that gets used for recursive errors,
  1062. % or errors outside the scope of a 'stopped'.
  1063. 2 copy //systemdict /SHORTERRORS get
  1064. { (%%[ Error: ) print =only flush
  1065. (; OffendingCommand: ) print =only ( ]%%) =
  1066. }
  1067. { (Unrecoverable error: ) print =only flush
  1068. ( in ) print =only (\n) print flush
  1069. count 2 gt
  1070. { (Operand stack:\n ) print
  1071. count 1 sub -1 2 { ( ) print index =only flush } for
  1072. (\n) =only flush
  1073. } if
  1074. }
  1075. ifelse
  1076. -1 0 1 //ErrorNames length 1 sub
  1077. { dup //ErrorNames exch get 3 index eq
  1078. { not exch pop exit } { pop } ifelse
  1079. }
  1080. for exch pop .quit
  1081. } .internalbind def
  1082. /.acquire_$error {
  1083. //systemdict /$error get
  1084. } .internalbind def
  1085. /.errorhandler % <command> <errorname> .errorhandler -
  1086. { % Detect an internal 'stopped'.
  1087. 1 .instopped { //null eq { pop pop stop } if } if
  1088. //.acquire_$error exec /.inerror get 1 .instopped { pop } { pop //true } ifelse
  1089. { //.unstoppederrorhandler exec
  1090. } if % detect error recursion
  1091. //.acquire_$error exec /globalmode .currentglobal //false .setglobal put
  1092. //.acquire_$error exec /.inerror //true put
  1093. //.acquire_$error exec /newerror //true put
  1094. //.acquire_$error exec exch /errorname exch put
  1095. //.acquire_$error exec exch /command exch put
  1096. //.acquire_$error exec /errorinfo known not { //.acquire_$error exec /errorinfo //null put } if
  1097. //.acquire_$error exec /recordstacks get //.acquire_$error exec /errorname get /VMerror ne and
  1098. { % Attempt to store the stack contents atomically.
  1099. count array astore dup //.acquire_$error exec /ostack 4 -1 roll
  1100. % Grab the execstack, then remove to two elements that are from
  1101. % this error handler (not interesting).
  1102. countexecstack array execstack dup length 2 sub 0 exch getinterval
  1103. //.acquire_$error exec /estack 3 -1 roll
  1104. countdictstack array dictstack //.acquire_$error exec /dstack 3 -1 roll
  1105. put put put aload pop
  1106. }
  1107. { //.acquire_$error exec /dstack .undef
  1108. //.acquire_$error exec /estack .undef
  1109. //.acquire_$error exec /ostack .undef
  1110. }
  1111. ifelse
  1112. //.acquire_$error exec /position currentfile status
  1113. { currentfile { fileposition } //.internalstopped exec { pop //null } if
  1114. }
  1115. { % If this was a scanner error, the file is no longer current,
  1116. % but the command holds the file, which may still be open.
  1117. //.acquire_$error exec /command get dup type /filetype eq
  1118. { { fileposition } //.internalstopped exec { pop //null } if }
  1119. { pop //null }
  1120. ifelse
  1121. }
  1122. ifelse put
  1123. % During initialization, we don't reset the allocation
  1124. % mode on errors.
  1125. //.acquire_$error exec /globalmode get //.acquire_$error exec /.nosetlocal get and .setglobal
  1126. //.acquire_$error exec /.inerror //false put
  1127. stop
  1128. } .internalbind def
  1129. currentdict /.unstoppederrorhandler .undef
  1130. % Define the standard handleerror. We break out the printing procedure
  1131. % (.printerror) so that it can be extended for binary output
  1132. % if the Level 2 facilities are present.
  1133. /.printerror_long % long error printout,
  1134. % $error is on the dict stack
  1135. { % Push the (anonymous) stack printing procedure.
  1136. % <heading> <==flag> <override-name> <stackname> proc
  1137. {
  1138. currentdict exch .knownget % stackname defined in $error?
  1139. {
  1140. 4 1 roll % stack: <stack> <head> <==flag> <over>
  1141. /errordict .systemvar exch .knownget % overridename defined?
  1142. {
  1143. exch pop exch pop exec % call override with <stack>
  1144. }
  1145. {
  1146. exch print exch % print heading. stack <==flag> <stack>
  1147. 1 index not { (\n) =only } if
  1148. { 1 index { (\n ) } { ( ) } ifelse print
  1149. dup type /dicttype eq
  1150. {
  1151. (--dict:) print
  1152. dup rcheck {
  1153. dup length =only (/) print dup maxlength =only
  1154. dup wcheck not { ((ro)) print } if
  1155. } if
  1156. /gcheck where {
  1157. pop gcheck { ((G)) } { ((L)) } ifelse print
  1158. } {
  1159. pop
  1160. } ifelse (--) print
  1161. }
  1162. {
  1163. dup type /stringtype eq 2 index or
  1164. { ==only } { =only } ifelse
  1165. } ifelse
  1166. } forall
  1167. pop
  1168. }
  1169. ifelse % overridden
  1170. }
  1171. { pop pop pop
  1172. }
  1173. ifelse % stack known
  1174. }
  1175. (\nOperand stack:) OSTACKPRINT /.printostack /ostack 4 index exec
  1176. (\nExecution stack:) ESTACKPRINT /.printestack /estack 4 index exec
  1177. (\nBacktrace:) //true /.printbacktrace /backtrace 4 index exec
  1178. (\nDictionary stack:) //false /.printdstack /dstack 4 index exec
  1179. () =
  1180. pop % printing procedure
  1181. errorname /VMerror eq
  1182. { (VM status:) print mark vmstatus
  1183. counttomark { ( ) print counttomark -1 roll dup =only } repeat
  1184. cleartomark (\n) =only
  1185. } if
  1186. .languagelevel 2 ge
  1187. { (Current allocation mode is ) print
  1188. globalmode { (global\n) } { (local\n) } ifelse print
  1189. } if
  1190. .oserrno dup 0 ne
  1191. { (Last OS error: ) print
  1192. errorname /VMerror ne
  1193. { dup .oserrorstring { =only (\n) print pop } { =only (\n) print } ifelse }
  1194. { =only }
  1195. ifelse
  1196. }
  1197. { pop
  1198. }
  1199. ifelse
  1200. position //null ne
  1201. { (Current file position is ) print position = }
  1202. if
  1203. } .internalbind def
  1204. /.printerror
  1205. {
  1206. //.acquire_$error exec begin newerror
  1207. {
  1208. /command load errorname //systemdict /SHORTERRORS get
  1209. { (%%[ Error: ) print =only flush
  1210. (; OffendingCommand: ) print =only
  1211. errorinfo dup //null eq {
  1212. pop
  1213. } {
  1214. (;\nErrorInfo:) print
  1215. dup type /arraytype eq
  1216. { { ( ) print =only } forall }
  1217. { ( ) print =only }
  1218. ifelse
  1219. } ifelse
  1220. ( ]%%) = flush
  1221. }
  1222. { (Error: ) print ==only flush
  1223. ( in ) print ==only flush
  1224. errorinfo dup //null eq {
  1225. pop
  1226. } {
  1227. (\nAdditional information: ) print ==only flush
  1228. } ifelse
  1229. //.printerror_long exec
  1230. }
  1231. ifelse
  1232. //.clearerror exec flush
  1233. }
  1234. { % newerror is //false, test to see if user has set handleerror to a different
  1235. % routine, if so execute it, otherwise, just return. This code deals with the
  1236. % Genoa issue of setting /handleerror, and then calling it, without an error
  1237. % being set. We were erroring in this case, due to /command load failing.
  1238. //JOBSERVER {
  1239. /errordict .systemvar /handleerror get /.GShandleerror .systemvar ne
  1240. } {
  1241. //false
  1242. } ifelse
  1243. { /errordict .systemvar begin /handleerror load //.internalstopped exec pop end
  1244. }
  1245. if
  1246. }
  1247. ifelse % newerror
  1248. end
  1249. flush
  1250. } .internalbind def
  1251. currentdict /.acquire_$error .undef
  1252. currentdict /.printerror_long .undef
  1253. % Define $error. This must be in local VM.
  1254. .currentglobal //false .setglobal
  1255. currentdict /$error 40 dict .forceput % $error is local, systemdict is global
  1256. % newerror, errorname, command, errorinfo,
  1257. % ostack, estack, dstack, recordstacks,
  1258. % binary, globalmode,
  1259. % .inerror, .nosetlocal, position,
  1260. % plus extra space for badly designed error handers.
  1261. $error begin
  1262. /newerror //false def
  1263. /recordstacks //true def
  1264. /binary //false def
  1265. /globalmode .currentglobal def
  1266. /.inerror //false def
  1267. /.nosetlocal //true def
  1268. /position //null def
  1269. /errorinfo //null def
  1270. end
  1271. % Define errordict similarly. It has one entry per error name,
  1272. % plus handleerror. However, some astonishingly badly written PostScript
  1273. % files require it to have at least one empty slot.
  1274. currentdict /errordict ErrorNames length 3 add dict
  1275. .forceput % errordict is local, systemdict is global
  1276. .setglobal % back to global VM
  1277. % gserrordict contains all the default error handling methods, but unlike
  1278. % errordict it is noaccess after creation (also it is in global VM).
  1279. % When running 'SAFER', we'll ignore the contents of errordict, which
  1280. % may have been tampered with by the running job, and always use gserrordict
  1281. % gserrordict also contains any non-standard errors, for better compatibility
  1282. % with Adobe.
  1283. %
  1284. % NOTE: the name gserrordict is known to the interpreter.
  1285. /gserrordict ErrorNames length 3 add dict def
  1286. % Register an error in errordict. We make this a procedure because we only
  1287. % register the Level 1 errors here: the rest are registered by "feature"
  1288. % files. However, ErrorNames contains all of the error names regardless of
  1289. % what features are included, so we have to "know" that VMerror is the last
  1290. % Level 1 error.
  1291. /.registererror2 % <dict> <name> .registererror -
  1292. { .currentglobal //true .setglobal % create procs in global VM
  1293. 3 1 roll
  1294. mark 1 index systemdict /.errorhandler get /exec load //.packtomark exec cvx put
  1295. .setglobal
  1296. } .internalbind def
  1297. /.registererror % <name> .registererror -
  1298. { errordict exch //.registererror2 exec
  1299. } .internalbind def
  1300. currentdict /.registererror2 .undef
  1301. ErrorNames
  1302. { .registererror} forall
  1303. errordict begin
  1304. % The handlers for interrupt and timeout are special; there is no
  1305. % 'current object', so they push their own name.
  1306. { /interrupt /timeout }
  1307. { mark 1 index dup systemdict /.errorhandler get /exec load //.packtomark exec cvx def
  1308. } forall
  1309. /handleerror % this key is 'well known' and some PS may redefine it
  1310. { /.printerror .systemvar exec
  1311. } .internalbind def
  1312. end % errordict
  1313. gserrordict /unknownerror errordict /unknownerror get put
  1314. errordict /unknownerror .undef
  1315. /.SAFERERRORLIST ErrorNames def
  1316. /.setsafererrors
  1317. {
  1318. % Put all the requested handlers in gserrordict
  1319. gserrordict
  1320. //.SAFERERRORLIST
  1321. {
  1322. dup /unknownerror eq
  1323. {pop}
  1324. {
  1325. dup errordict exch get 2 index 3 1 roll put
  1326. }ifelse
  1327. }forall
  1328. noaccess pop
  1329. //systemdict /.setsafeerrors .forceundef
  1330. //systemdict /.SAFERERRORLIST .forceundef
  1331. } .internalbind odef
  1332. SAFERERRORS {.setsafererrors} if
  1333. % Define a stable private copy of handleerror that we will always use under
  1334. % JOBSERVER mode.
  1335. /.GShandleerror errordict /handleerror get def
  1336. % Define the [write]==[only] procedures.
  1337. /.dict 8 dict dup
  1338. begin def
  1339. /.cvp {1 index exch 1 .writecvp} .internalbind def
  1340. /.p {1 index exch writestring} .internalbind def
  1341. /.p1 {2 index exch writestring} .internalbind def
  1342. /.p2 {3 index exch writestring} .internalbind def
  1343. /.print
  1344. { dup type .dict exch .knownget { exec } { .cvp } ifelse
  1345. } .internalbind def
  1346. /arraytype
  1347. {dup rcheck
  1348. {() exch dup xcheck
  1349. {({) .p2
  1350. {exch .p1
  1351. 1 index exch .print pop ( )} forall
  1352. (})}
  1353. {([) .p2
  1354. {exch .p1
  1355. 1 index exch .print pop ( )} forall
  1356. (])}
  1357. ifelse exch pop .p}
  1358. {.cvp}
  1359. ifelse} .internalbind def
  1360. /packedarraytype /arraytype load def
  1361. {//.dict begin .print pop end}
  1362. .bind
  1363. end
  1364. /write==only exch def
  1365. /write== {1 index exch write==only (\n) writestring} .internalbind def
  1366. /==only { (%stdout) (w) file exch write==only } .internalbind def
  1367. /== {==only (\n) print} .internalbind def
  1368. % Define [write]===[only], an extension that prints dictionaries
  1369. % in readable form and doesn't truncate strings.
  1370. /.dict /write==only load 0 get dup length 2 add dict .copydict dup
  1371. begin def
  1372. /dicttype
  1373. { dup rcheck
  1374. { (<< ) .p1
  1375. { 2 index 3 -1 roll .print pop ( ) .p1
  1376. 1 index exch .print pop ( ) .p
  1377. }
  1378. forall (>>) .p
  1379. }
  1380. { .cvp
  1381. }
  1382. ifelse
  1383. } .internalbind def
  1384. /stringtype
  1385. { 1 index exch 2 .writecvp
  1386. } .internalbind def
  1387. {//.dict begin .print pop end}
  1388. .internalbind
  1389. end
  1390. /write===only exch def
  1391. /write=== {1 index exch write===only (\n) writestring} .internalbind def
  1392. /===only { (%stdout) (w) file exch write===only } .internalbind def
  1393. /=== { ===only (\n) print } .internalbind def
  1394. % Create the initialization queue.
  1395. 1183615869 internaldict dup
  1396. /.delayed_init_queue 10 dict put
  1397. /.schedule_init % <priority> <proc> .schedule_init -
  1398. {
  1399. 1183615869 internaldict begin
  1400. .delayed_init_queue 2 index known {
  1401. end
  1402. (.delayed_init_queue priority conflict with ) print 1 index =
  1403. /.schedule_init cvx /configurationerror signalerror
  1404. } if
  1405. .delayed_init_queue 3 1 roll .growput
  1406. end
  1407. } .internalbind def
  1408. begin
  1409. /.execute_scheduled_inits % - .execute_scheduled_inits -
  1410. {
  1411. 2 dict begin
  1412. /.newdelayed_init_queue
  1413. mark
  1414. 1183615869 internaldict /.delayed_init_queue get {} forall
  1415. .dicttomark def
  1416. {
  1417. 0 //null .newdelayed_init_queue { % maxp {} p {}
  1418. 3 index 2 index lt {
  1419. 4 2 roll
  1420. } if
  1421. pop pop
  1422. } forall
  1423. exch .newdelayed_init_queue exch undef
  1424. dup //null eq {
  1425. pop exit
  1426. } if
  1427. exec
  1428. } loop
  1429. currentdict /.newdelayed_init_queue undef
  1430. end
  1431. } .internalbind def
  1432. end
  1433. (END PROCS) VMDEBUG
  1434. % Define the font directory.
  1435. currentdict
  1436. /FontDirectory //false .setglobal 100 dict //true .setglobal
  1437. .forceput % FontDirectory is local, systemdict is global
  1438. % Define the encoding dictionary.
  1439. /EncodingDirectory 16 dict def % enough for Level 2 + PDF standard encodings
  1440. % Define .findencoding. (This is redefined in Level 2.)
  1441. /.findencoding
  1442. { //EncodingDirectory exch get exec
  1443. } .internalbind def
  1444. /.defineencoding
  1445. { //EncodingDirectory 3 1 roll put
  1446. } .internalbind def
  1447. % If we've got the composite font extensions, define findencoding.
  1448. % To satisfy the Genoa FTS, findencoding must be a procedure, not an operator.
  1449. /rootfont where { pop /findencoding { .findencoding } def } if
  1450. % Define .registerencoding.
  1451. % NOTE: This procedure no longer does anything, but it must continue to
  1452. % exist for the sake of toolbin/encs2c.ps.
  1453. /.registerencoding { % <index> <array> .registerencoding -
  1454. pop pop
  1455. } .internalbind odef
  1456. % Load StandardEncoding.
  1457. %% Replace 1 (gs_std_e.ps)
  1458. (gs_std_e.ps) dup runlibfile VMDEBUG
  1459. % Load ISOLatin1Encoding.
  1460. %% Replace 1 (gs_il1_e.ps)
  1461. (gs_il1_e.ps) dup runlibfile VMDEBUG
  1462. % Define stubs for the Symbol and Dingbats encodings.
  1463. % Note that the first element of the procedure must be the file name,
  1464. % since gs_lev2.ps extracts it to set up the Encoding resource category.
  1465. /SymbolEncoding { /SymbolEncoding .findencoding } bind def
  1466. %% Replace 3 (gs_sym_e.ps)
  1467. EncodingDirectory /SymbolEncoding
  1468. { (gs_sym_e.ps) //systemdict begin runlibfile SymbolEncoding end }
  1469. bind put
  1470. /DingbatsEncoding { /DingbatsEncoding .findencoding } bind def
  1471. %% Replace 3 (gs_dbt_e.ps)
  1472. EncodingDirectory /DingbatsEncoding
  1473. { (gs_dbt_e.ps) //systemdict begin runlibfile DingbatsEncoding end }
  1474. bind put
  1475. (END FONTDIR/ENCS) VMDEBUG
  1476. % Special handling for device parameters. Must follow definition of 'type'
  1477. % make -dPDFA equivalent to -dPDFA=1 (backwards compatible)
  1478. currentdict /PDFA known { PDFA type /booleantype eq { /PDFA 1 def } if } if
  1479. % Construct a dictionary of all available devices.
  1480. % These are (read-only) device prototypes that can't be
  1481. % installed or have their parameters changed. For this reason,
  1482. % the value in the dictionary is actually a 2-element writable array,
  1483. % to allow us to create a default instance of the prototype on demand.
  1484. % Loop until the .getdevice gets a rangecheck.
  1485. errordict /rangecheck 2 copy get
  1486. errordict /rangecheck { pop stop } put % pop the command
  1487. 0 { {dup .getdevice exch 1 add} loop} //.internalstopped exec pop
  1488. 1 add dict /devicedict 1 index def
  1489. begin % 2nd copy of count is on stack
  1490. { dup .devicename exch
  1491. dup wcheck { dup } { //null } ifelse 2 array astore def
  1492. } repeat
  1493. end
  1494. put % errordict /rangecheck
  1495. .clearerror
  1496. /devicenames devicedict { pop } forall devicedict length packedarray def
  1497. % Determine the default device.
  1498. /defaultdevice //systemdict /DISPLAYING get
  1499. { //systemdict /DEVICE .knownget
  1500. { devicedict 1 index known not
  1501. { (Unknown device: ) print =
  1502. flush /defaultdevice cvx 1 .quit
  1503. }
  1504. if
  1505. }
  1506. { .getdefaultdevice .devicename
  1507. }
  1508. ifelse
  1509. }
  1510. { /nullpage
  1511. }
  1512. ifelse
  1513. /.defaultdevicename 1 index def
  1514. finddevice % make a copy
  1515. def
  1516. devicedict /Default devicedict .defaultdevicename get put
  1517. (END DEVS) VMDEBUG
  1518. % Define statusdict, for the benefit of programs
  1519. % that think they are running on a LaserWriter or similar printer.
  1520. %% Replace 1 (gs_statd.ps)
  1521. (gs_statd.ps) runlibfile
  1522. (END STATD) VMDEBUG
  1523. % Load the standard font environment.
  1524. %% Replace 1 (gs_fonts.ps)
  1525. (gs_fonts.ps) runlibfile
  1526. (END GS_FONTS) VMDEBUG
  1527. % Define the default halftone screen and BG/UCR functions now, so that
  1528. % it will bind in the original definitions of set[color]screen.
  1529. % We make this a procedure so we can call it again when switching devices.
  1530. % Use an ordered dither for low-resolution devices.
  1531. /.setloreshalftone { % <dpi> .setloreshalftone -
  1532. % The following 'ordered dither' spot function was contributed by
  1533. % Gregg Townsend. Thanks, Gregg!
  1534. 16.001 div 0 % not 16: avoids rounding problems
  1535. { 1 add 7.9999 mul cvi exch 1 add 7.9999 mul cvi 16 mul add <
  1536. 0E 8E 2E AE 06 86 26 A6 0C 8C 2C AC 04 84 24 A4
  1537. CE 4E EE 6E C6 46 E6 66 CC 4C EC 6C C4 44 E4 64
  1538. 3E BE 1E 9E 36 B6 16 96 3C BC 1C 9C 34 B4 14 94
  1539. FE 7E DE 5E F6 76 D6 56 FC 7C DC 5C F4 74 D4 54
  1540. 01 81 21 A1 09 89 29 A9 03 83 23 A3 0B 8B 2B AB
  1541. C1 41 E1 61 C9 49 E9 69 C3 43 E3 63 CB 4B EB 6B
  1542. 31 B1 11 91 39 B9 19 99 33 B3 13 93 3B BB 1B 9B
  1543. F1 71 D1 51 F9 79 D9 59 F3 73 D3 53 FB 7B DB 5B
  1544. 0D 8D 2D AD 05 85 25 A5 0F 8F 2F AF 07 87 27 A7
  1545. CD 4D ED 6D C5 45 E5 65 CF 4F EF 6F C7 47 E7 67
  1546. 3D BD 1D 9D 35 B5 15 95 3F BF 1F 9F 37 B7 17 97
  1547. FD 7D DD 5D F5 75 D5 55 FF 7F DF 5F F7 77 D7 57
  1548. 02 82 22 A2 0A 8A 2A AA 00 80 20 A0 08 88 28 A8
  1549. C2 42 E2 62 CA 4A EA 6A C0 40 E0 60 C8 48 E8 68
  1550. 32 B2 12 92 3A BA 1A 9A 30 B0 10 90 38 B8 18 98
  1551. F2 72 D2 52 FA 7A DA 5A F0 70 D0 50 F8 78 D8 58
  1552. > exch get 256 div
  1553. }
  1554. bind
  1555. % Use correct, per-plane screens for CMYK devices only.
  1556. //systemdict /setcolorscreen known processcolors 4 eq and
  1557. { 3 copy 6 copy //setcolorscreen }
  1558. { //setscreen }
  1559. ifelse
  1560. } .internalbind def
  1561. /.setloresscreen { % <dpi> .setloresscreen -
  1562. .setloreshalftone
  1563. 0 array cvx settransfer % Genoa CET won't accept a packed array!
  1564. /setstrokeadjust where { pop //true setstrokeadjust } if
  1565. } .internalbind def
  1566. % Use a 45-degree spot screen for high-resolution devices.
  1567. % The PS3 CET insists that the screen be an array and not a packedarray (!).
  1568. currentpacking //false setpacking
  1569. /.linescreen
  1570. % The following screen algorithm is used by permission of the author.
  1571. { ((C) 1989 Berthold K.P. Horn) pop
  1572. 1 add 180 mul cos 1 0.08 add mul exch 2 add 180 mul cos
  1573. 1 0.08 sub mul add 2 div
  1574. }
  1575. bind readonly def
  1576. setpacking
  1577. /.sethireshalftone { % <dpi> .sethireshalftone <doscreen>
  1578. % According to information published by Hewlett-Packard,
  1579. % they use a 60 line screen on 300 DPI printers and
  1580. % an 85 line screen on 600 DPI printers.
  1581. % However, we use a 106 line screen, which produces smoother-
  1582. % looking shades but fewer of them (32 vs. 50).
  1583. % 46 was suggested as a good frequency value for printers
  1584. % between 200 and 400 DPI, so we use it for lower resolutions.
  1585. % Imagesetters need even higher frequency screens.
  1586. //systemdict /DITHERPPI known
  1587. { //systemdict /DITHERPPI get
  1588. }
  1589. { dup cvi 100 idiv 15 .min
  1590. {//null 46 46 60 60 60 106 106 106 106 133 133 133 133 133 150}
  1591. exch get
  1592. }
  1593. ifelse
  1594. 1 index 4.01 div .min % at least a 4x4 cell
  1595. 45
  1596. //.linescreen
  1597. % Determine whether we have lots of process colors.
  1598. % If so, don't bother with color screening or gamma correction.
  1599. % Also don't do gamma correction on very high-resolution devices.
  1600. % (This should depend on dot gain, not resolution, but we don't
  1601. % currently have a way to determine this.) Ignore missing components
  1602. % (*Values = 1).
  1603. currentdevice mark
  1604. /RedValues 0 /GreenValues 0 /BlueValues 0 /GrayValues 0
  1605. .dicttomark .getdeviceparams
  1606. counttomark 2 idiv 1 sub
  1607. { exch pop dup 1 le
  1608. { pop }
  1609. { exch dup 1 le
  1610. { pop }
  1611. { .min }
  1612. ifelse
  1613. }
  1614. ifelse
  1615. }
  1616. repeat
  1617. exch pop exch pop 32 lt 4 index 800 lt and 5 1 roll
  1618. % Stack: doscreen dpi freq angle proc
  1619. % Ghostscript currently doesn't use correct, per-plane halftones
  1620. % unless setcolorscreen has been executed. Since these are
  1621. % computationally much more expensive than binary halftones,
  1622. % we check to make sure they are really warranted, i.e., we have
  1623. % a high-resolution CMYK device (i.e., not a display) with
  1624. % fewer than 5 bits per plane (i.e., not a true-color device).
  1625. 4 -1 roll 150 ge
  1626. { /setcolorscreen where
  1627. { pop //systemdict /COLORSCREEN known
  1628. { //systemdict /COLORSCREEN get}
  1629. { 3 index }
  1630. ifelse
  1631. dup //false ne
  1632. { 4 1 roll 3 copy 6 copy 13 -1 roll
  1633. % For really high-quality screening on printers, we need to
  1634. % give each plane its own screen angle. Unfortunately,
  1635. % this currently has very large space and time costs.
  1636. //true eq % true => different angles,
  1637. % 0 => same angles
  1638. { { 45 90 15 75 } { 3 1 roll exch pop 12 3 roll } forall
  1639. }
  1640. if //setcolorscreen
  1641. }
  1642. { pop //setscreen % false => single binary screen
  1643. }
  1644. ifelse
  1645. }
  1646. { //setscreen % setcolorscreen not known
  1647. }
  1648. ifelse
  1649. }
  1650. { //setscreen % not high resolution
  1651. }
  1652. ifelse
  1653. } .internalbind def
  1654. /.sethiresscreen { % <dpi> .sethiresscreen
  1655. .sethireshalftone % pushes true if a screen halftone used
  1656. % Stack: doscree
  1657. {
  1658. % Set the transfer function to lighten up the grays.
  1659. % Parameter values closer to 1 are better for devices with
  1660. % less dot spreading; lower values are better with more spreading.
  1661. % The value 0.8 is a compromise that will probably please no one!
  1662. %
  1663. % Because of a bug in FrameMaker, we have to accept operands
  1664. % outside the valid range of [0..1].
  1665. {
  1666. dup dup 0.0 gt exch 1.0 lt and
  1667. {
  1668. 0.8 exp
  1669. }
  1670. if
  1671. }
  1672. }
  1673. {
  1674. % Set the transfer function to the identity.
  1675. 0 array cvx % Genoa CET won't accept a packed array!
  1676. }
  1677. ifelse
  1678. settransfer
  1679. /setstrokeadjust where
  1680. { pop //false setstrokeadjust }
  1681. if
  1682. % Increase fill adjustment so that we effectively use Adobe's
  1683. % any-part-of-pixel rule.
  1684. 0.5 dup .setfilladjust2
  1685. } .internalbind def
  1686. % Set the default screen and BG/UCR.
  1687. % We define the proc here, rather than inline in .setdefaultbgucr
  1688. % for the benefit of gs_cet.ps so jobs that do anything that causes
  1689. % .setdefaultbgucr to be called will still get the redefined proc
  1690. % in gs_cet.ps
  1691. (%.defaultbgrucrproc) cvn { pop 0 } def
  1692. /.setdefaultbgucr {
  1693. systemdict /setblackgeneration known {
  1694. (%.defaultbgrucrproc) cvn load dup
  1695. setblackgeneration setundercolorremoval
  1696. } if
  1697. } .internalbind def
  1698. /.useloresscreen { % - .useloresscreen <bool>
  1699. % Compute min(|dpi x|,|dpi y|) as the definition of the resolution.
  1700. 72 72 matrix defaultmatrix dtransform abs exch abs .min
  1701. dup 150 lt //systemdict /DITHERPPI known not and
  1702. } .internalbind def
  1703. /.gsgetdeviceprop % <device> <propname> gsgetdeviceprop <value>
  1704. { 2 copy mark exch //null .dicttomark .getdeviceparams
  1705. dup mark eq % if true, not found
  1706. { pop dup /undefined signalerror }
  1707. { 5 1 roll pop pop pop pop }
  1708. ifelse
  1709. } .internalbind def
  1710. % The following implementation uses LL2 extensions, but only in stopped
  1711. % contexts so that with LL1, the .set??reshalftone will be used.
  1712. %
  1713. % - .getdefaulthalftone <halftonedict> true if default found
  1714. % false
  1715. /.getdefaulthalftone {
  1716. % try the device to see if it has a default halftone
  1717. { currentdevice /HalftoneDefault //.gsgetdeviceprop exec } //.internalstopped exec
  1718. { pop pop //false } % no device property
  1719. { dup type /dicttype eq { //true } { pop //false } ifelse }
  1720. ifelse
  1721. % stack: <halftonedict> true if default found
  1722. % false not found
  1723. dup not
  1724. { % device did not provide a default, try Resource
  1725. pop { /Default /Halftone /findresource .systemvar exec } //.internalstopped exec
  1726. { pop pop //false } { //true } ifelse
  1727. }
  1728. if
  1729. } .internalbind def
  1730. currentdict /.gsgetdeviceprop .forceundef
  1731. /.setdefaulthalftone {
  1732. //.getdefaulthalftone exec
  1733. { sethalftone }
  1734. { % default not found
  1735. //.useloresscreen exec { .setloreshalftone } { .sethireshalftone pop } ifelse
  1736. }
  1737. ifelse
  1738. } .internalbind def
  1739. /.setdefaultscreen {
  1740. //.useloresscreen exec { .setloresscreen } { .sethiresscreen } ifelse
  1741. //.setdefaultbgucr exec
  1742. } .internalbind def
  1743. currentdict /.setdefaultbgucr .undef
  1744. currentdict /.useloresscreen .undef
  1745. % Rendering intent mapping for setcolorrendering1 and PDF interpreter
  1746. /.renderingintentdict mark
  1747. /Perceptual 0
  1748. /RelativeColorimetric 1
  1749. /Saturation 2
  1750. /AbsoluteColorimetric 3
  1751. .dicttomark readonly def
  1752. % Load basic color support
  1753. %% Replace 1 (gs_cspace.ps)
  1754. (gs_cspace.ps) runlibfile
  1755. (END BASIC COLOR) VMDEBUG
  1756. % Load image support
  1757. %% Replace 1 (gs_img.ps)
  1758. (gs_img.ps) runlibfile
  1759. (END IMAGE) VMDEBUG
  1760. % Auxiliary procedures for generating file name templates.
  1761. % Convert a path name into a string suitable for filenameforall
  1762. % For example: (a\\b*?c) to (a\\\\b\\*\\?c)
  1763. /.makepathtemplate { % str1 -- str2
  1764. dup length dup add string 0 % result string up to twice the size
  1765. 0 1 4 index length 1 sub {
  1766. 3 index exch get
  1767. dup 92 eq { % \ -> \\
  1768. 2 index 2 index 92
  1769. put
  1770. exch 1 add exch
  1771. }
  1772. if
  1773. dup 42 eq { % * -> \*
  1774. 2 index 2 index 92
  1775. put
  1776. exch 1 add exch
  1777. }
  1778. if
  1779. dup 63 eq { % ? -> \?
  1780. 2 index 2 index 92
  1781. put
  1782. exch 1 add exch
  1783. }
  1784. if
  1785. 2 index 2 index 3 -1 roll put 1 add
  1786. } for
  1787. 0 exch getinterval exch pop
  1788. } .internalbind def
  1789. % false <dir_list> <template> .generate_dir_list_templates_with_length <t1> ... <tN>
  1790. % true <dir_list> <template> .generate_dir_list_templates_with_length <t1> <l1> ... <tN> <ln>
  1791. %
  1792. % Generates various valid templates combining a directory list with a given template.
  1793. % With 'true' operand it also returns lengths of directory pathes.
  1794. %
  1795. % Example1 (DOS, Windows) :
  1796. % false [(/gs/lib) (/gs/Resource/) (\gs8.00\Resource)] (*/*) -->
  1797. % (/gs/lib/*/*) (/gs/Resource/*/*) (\\gs8.00\\Resource/*/*)
  1798. %
  1799. % Example2 (OpenVMS) :
  1800. % false [(gs:[lib]) (gs:[Resource]) (gs800:[Resource)] (*]*) -->
  1801. % ((gs:[lib.*]*) [gs:[Resource.*]*) ([gs800:[Resource.*]*)
  1802. %
  1803. /.generate_dir_list_templates_with_length
  1804. { % [dl] (templ)
  1805. % We need to convert paths into templates,
  1806. % because it can include '\' on DOS.
  1807. % In same time, the <template> must not convert,
  1808. % because it is already a template.
  1809. % Besides that, we cannot combine template using .file_name_combine,
  1810. % because template syntax breaks the platform path syntax.
  1811. % To resolve this, we first convert the <template> into
  1812. % a fake filename, and combine it with path,
  1813. % obtaining a correct separator. Then we replace
  1814. % the fake file name with the given template.
  1815. %
  1816. % Create the fake file name :
  1817. dup dup length string copy % b [dl] (templ) (ffn)
  1818. (*) 0 get (?) 0 get (\\) 0 get (x) 0 get 0 0 % b [dl] (templ) (ffn) * ? \ x i j
  1819. { 1 index 7 index length ge { exit } if
  1820. 6 index 2 index get % b [dl] (templ) (ffn) * ? \ x i j c
  1821. dup 7 index eq % b [dl] (templ) (ffn) * ? \ x i j c bool
  1822. 1 index 7 index eq or { % *?
  1823. pop 2 index
  1824. } if % b [dl] (templ) (ffn) * ? \ x i j C
  1825. dup 5 index eq { % \
  1826. 3 2 roll 1 add 3 1 roll % b [dl] (templ) (ffn) * ? \ x i' j C
  1827. 2 index 8 index length ge { pop exit } if
  1828. pop 6 index 2 index get % b [dl] (templ) (ffn) * ? \ x i' j C'
  1829. } if
  1830. 7 index 2 index 3 2 roll put % b [dl] (templ) (ffn) * ? \ x i' j
  1831. 1 add exch 1 add exch % b [dl] (templ) (ffn) * ? \ x i'' j'
  1832. } loop % b [dl] (templ) (ffn) * ? \ x i j
  1833. 6 1 roll pop % b [dl] (templ) (ffn) j * ? \ x
  1834. exch pop exch pop exch pop exch % b [dl] (templ) (ffn) x j
  1835. { dup 3 index length ge { exit } if
  1836. 3 copy exch put
  1837. 1 add
  1838. } loop
  1839. pop pop % b [dl] (templ) (ffn)
  1840. % An internal procedure :
  1841. { % {} b [dl] (templ) (ffn) (dffn)
  1842. dup length
  1843. 2 index length sub % drop "ffn", remaining "ldffn" = length of the "directory" part
  1844. exch % {} b [dl] (templ) (ffn) ldffn (dffn)
  1845. //.makepathtemplate exec % {} b [dl] (templ) (ffn) ldffn (Dffn)
  1846. dup % {} b [dl] (templ) (ffn) ldffn (Dffn) (Dffn)
  1847. 4 index length dup % {} b [dl] (templ) (ffn) ldffn (Dffn) (Dffn) templL templL
  1848. 2 index length % {} b [dl] (templ) (ffn) ldffn (Dffn) (Dffn) templL templL DffnL
  1849. exch sub % {} b [dl] (templ) (ffn) ldffn (Dffn) (Dffn) templL i
  1850. exch getinterval % {} b [dl] (templ) (ffn) ldffn (Dffn) (suffix)
  1851. 4 index exch copy pop % {} b [dl] (templ) (ffn) ldffn (dt)
  1852. 5 index {
  1853. exch % {} b [dl] (templ) (ffn) (dt) ldffn
  1854. 7 2 roll % (dt) ldffn {} b [dl] (templ) (ffn)
  1855. } {
  1856. exch pop % {} b [dl] (templ) (ffn) (dt)
  1857. 6 1 roll % (dt) {} b [dl] (templ) (ffn)
  1858. } ifelse
  1859. }
  1860. 5 1 roll % {} b [dl] (templ) (ffn)
  1861. % Generate templates :
  1862. dup .file_name_is_absolute {
  1863. dup % {} b [dl] (templ) (ffn) (ffn)
  1864. 5 index exec % (t1) {} b [dl] (templ) (ffn)
  1865. } {
  1866. 2 index { % ... {} b [dl] (templ) (ffn) (d)
  1867. 1 index % ... {} b [dl] (templ) (ffn) (d) (ffn)
  1868. //false .file_name_combine { % ... {} b [dl] (templ) (ffn) (dffn)
  1869. 5 index exec % ... (t1) ?l1 {} b [dl] (templ) (ffn)
  1870. } { % ... {} b [dl] (templ) (ffn) (d) (ffn)
  1871. pop pop % ... {} b [dl] (templ) (ffn)
  1872. } ifelse
  1873. } forall
  1874. } ifelse % (t1) ?l1 (t2) ?l2 ... (tN) ?ln {} b [dl] (templ) (ffn)
  1875. pop pop pop pop pop % (t1) ?l1 (t2) ?l2 ... (tN) ?ln
  1876. } .forcebind odef
  1877. currentdict /.makepathtemplate .undef
  1878. % <dir_list> <template> .generate_dir_list_templates <t1> ... <tN>
  1879. %
  1880. % Generates various valid templates combining a directory list with a given template.
  1881. % It's the 'false' case of the function above.
  1882. %
  1883. /.generate_dir_list_templates
  1884. { //false 3 1 roll //.generate_dir_list_templates_with_length
  1885. } .forcebind odef
  1886. % Load the initialization files for optional features.
  1887. %% Replace 4 INITFILES
  1888. systemdict /INITFILES known
  1889. { INITFILES { <00> search { exch pop dup runlibfile VMDEBUG }{ dup runlibfile VMDEBUG exit } ifelse } .forcebind loop
  1890. }
  1891. if
  1892. % If Level 2 (or higher) functionality is implemented, enable it now.
  1893. /.setlanguagelevel where {
  1894. pop 2 .setlanguagelevel
  1895. % If the resource machinery is loaded, fix up some things now.
  1896. /.fixresources where { pop .fixresources } if
  1897. } if
  1898. /ll3dict where {
  1899. pop 3 .setlanguagelevel
  1900. } if
  1901. (END INITFILES) VMDEBUG
  1902. % Create a null font. This is the initial font.
  1903. 8 dict dup begin
  1904. /FontMatrix [ 1 0 0 1 0 0 ] readonly def
  1905. /FontType 3 def
  1906. /FontName () def
  1907. /Encoding StandardEncoding def
  1908. /FontBBox { 0 0 0 0 } readonly def % executable is bogus, but customary ...
  1909. /BuildChar { pop pop 0 0 setcharwidth } .internalbind def
  1910. /PaintType 0 def % shouldn't be needed!
  1911. end
  1912. /NullFont exch definefont setfont
  1913. % Define NullFont as the font.
  1914. /NullFont currentfont def
  1915. % Load initial fonts from FONTPATH directories, Fontmap file,
  1916. % and/or .getccfont as appropriate.
  1917. .loadinitialfonts
  1918. currentdict /.loadinitialfonts .undef
  1919. % Remove NullFont from FontDirectory, so it can't be accessed by mistake.
  1920. /undefinefont where {
  1921. pop /NullFont undefinefont
  1922. } {
  1923. FontDirectory /NullFont .undef
  1924. } ifelse
  1925. (END FONTS) VMDEBUG
  1926. % Restore the real definition of runlibfile.
  1927. /runlibfile /.runlibfile load def
  1928. currentdict /.runlibfile .undef
  1929. % Bind all the operators defined as procedures.
  1930. /.bindoperators % binds operators in currentdict
  1931. {
  1932. currentdict
  1933. { dup type /operatortype eq
  1934. {
  1935. % This might be a real operator, so bind might cause a typecheck
  1936. {.forcebind} //.internalstopped exec pop
  1937. }
  1938. if pop pop
  1939. } forall
  1940. } def
  1941. DELAYBIND not {
  1942. .bindoperators
  1943. %% if not DELAYBIND, undef this now. Otherwise defer to .bindnow
  1944. //systemdict /.bindoperators .undef
  1945. } if
  1946. % Establish a default environment.
  1947. defaultdevice
  1948. % The following line used to skip setting of page size and resolution if
  1949. % NODISPLAY was selected. We think this was only to save time and memory,
  1950. % and it is a bad idea because it prevents setting the resolution in this
  1951. % situation, which pstoedit (among other programs) relies on.
  1952. %DISPLAYING not { setdevice (%END DISPLAYING) .skipeof } if
  1953. % If the paper size is not specifed and the device defaults to
  1954. % letter or A4 paper, select the DEFAULTPAPERSIZE.
  1955. systemdict /DEFAULTPAPERSIZE known not {
  1956. % Use .defaultpapersize if it returns a known paper size
  1957. .defaultpapersize {
  1958. statusdict /.pagetypeprocs get 1 index known {
  1959. systemdict exch /DEFAULTPAPERSIZE exch put
  1960. } {
  1961. QUIET {
  1962. pop
  1963. } {
  1964. (Unknown .defaultpapersize: ) print ==only (.) =
  1965. } ifelse
  1966. } ifelse
  1967. } if
  1968. } if
  1969. systemdict /DEFAULTPAPERSIZE known
  1970. systemdict /PAPERSIZE known not and
  1971. systemdict /DEVICEWIDTH known not and
  1972. systemdict /DEVICEHEIGHT known not and
  1973. systemdict /DEVICEWIDTHPOINTS known not and
  1974. systemdict /DEVICEHEIGHTPOINTS known not and
  1975. {
  1976. defaultdevice mark /PageSize //null .dicttomark .getdeviceparams
  1977. .dicttomark /PageSize get
  1978. dup 0 get 0.5 add cvi 612 eq 1 index 1 get 0.5 add cvi 792 eq and
  1979. 1 index 0 get 0.5 add cvi 595 eq 2 index 1 get 0.5 add cvi 842 eq and
  1980. or exch pop
  1981. {
  1982. % the default paper size was letter, so replace it with DEFAULTPAPERSIZE
  1983. /PAPERSIZE DEFAULTPAPERSIZE def
  1984. } if
  1985. }
  1986. if
  1987. systemdict /DEVICEWIDTH known
  1988. systemdict /DEVICEHEIGHT known or
  1989. systemdict /DEVICEWIDTHPOINTS known or
  1990. systemdict /DEVICEHEIGHTPOINTS known or
  1991. systemdict /DEVICEXRESOLUTION known or
  1992. systemdict /DEVICEYRESOLUTION known or
  1993. systemdict /PAPERSIZE known or
  1994. not { (%END DEVICE) .skipeof } if
  1995. % Let DEVICE{WIDTH,HEIGHT}[POINTS] override PAPERSIZE.
  1996. systemdict /PAPERSIZE known
  1997. systemdict /DEVICEWIDTH known not and
  1998. systemdict /DEVICEHEIGHT known not and
  1999. systemdict /DEVICEWIDTHPOINTS known not and
  2000. systemdict /DEVICEHEIGHTPOINTS known not and {
  2001. % Convert the paper size to device dimensions.
  2002. statusdict /.pagetypeprocs get PAPERSIZE .knownget {
  2003. dup 0 get /DEVICEWIDTHPOINTS exch def
  2004. 1 get /DEVICEHEIGHTPOINTS exch def
  2005. } {
  2006. (Unknown paper size: ) print PAPERSIZE ==only (.) =
  2007. } ifelse
  2008. } if
  2009. % Adjust the device parameters per the command line.
  2010. % It is possible to specify resolution, pixel size, and page size;
  2011. % since any two of these determine the third, conflicts are possible.
  2012. % We simply pass them to .setdeviceparams and let it sort things out.
  2013. mark /HWResolution //null /HWSize //null /PageSize //null .dicttomark
  2014. .getdeviceparams .dicttomark begin
  2015. mark
  2016. % Check for resolution.
  2017. /DEVICEXRESOLUTION where dup
  2018. { exch pop HWResolution 0 DEVICEXRESOLUTION put }
  2019. if
  2020. /DEVICEYRESOLUTION where dup
  2021. { exch pop HWResolution 1 DEVICEYRESOLUTION put }
  2022. if
  2023. or { /HWResolution HWResolution } if
  2024. % Check for device sizes specified in pixels.
  2025. /DEVICEWIDTH where dup
  2026. { exch pop HWSize 0 DEVICEWIDTH put }
  2027. if
  2028. /DEVICEHEIGHT where dup
  2029. { exch pop HWSize 1 DEVICEHEIGHT put }
  2030. if
  2031. or { /HWSize HWSize } if
  2032. % Check for device sizes specified in points.
  2033. /DEVICEWIDTHPOINTS where dup
  2034. { exch pop PageSize 0 DEVICEWIDTHPOINTS put }
  2035. if
  2036. /DEVICEHEIGHTPOINTS where dup
  2037. { exch pop PageSize 1 DEVICEHEIGHTPOINTS put }
  2038. if
  2039. or { /PageSize PageSize } if
  2040. % Check whether any parameters were set.
  2041. dup mark eq { pop defaultdevice } { defaultdevice putdeviceprops } ifelse
  2042. end
  2043. %END DEVICE
  2044. % Set any device properties defined on the command line.
  2045. % If BufferSpace is defined but not MaxBitmap, set MaxBitmap to BufferSpace.
  2046. systemdict /BufferSpace known
  2047. systemdict /MaxBitmap known not and
  2048. { systemdict /MaxBitmap BufferSpace put
  2049. } if
  2050. dup getdeviceprops
  2051. counttomark 2 idiv
  2052. { systemdict 2 index known
  2053. { pop dup load counttomark 2 roll }
  2054. { pop pop }
  2055. ifelse
  2056. } repeat
  2057. counttomark dup 0 ne
  2058. { 2 add -1 roll putdeviceprops }
  2059. { pop pop }
  2060. ifelse
  2061. % If the initial device parameters are invalid, the setdevice may fail.
  2062. % Trap this and produce a reasonable error message.
  2063. { setdevice } % does an erasepage
  2064. INITDEBUG { exec //false } { //.internalstopped exec } ifelse {
  2065. (%stderr) (w) file dup
  2066. (**** Unable to open the initial device, quitting.\n) writestring
  2067. flushfile
  2068. 1 .quit
  2069. } if
  2070. % If the media size is fixed, update the current page device dictionary.
  2071. FIXEDMEDIA
  2072. dup { pop systemdict /.currentpagedevice known } if
  2073. dup { pop .currentpagedevice exch pop } if
  2074. not { (%END MEDIA) .skipeof } if
  2075. currentpagedevice dup length dict .copydict
  2076. dup /Policies
  2077. % Stack: <pagedevice> <pagedevice> /Policies
  2078. 1 index /InputAttributes
  2079. 2 copy get dup length dict .copydict
  2080. % Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
  2081. % /InputAttributes <inputattrs'>
  2082. dup 0 2 copy get dup length dict .copydict
  2083. % Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
  2084. % /InputAttributes <inputattrs'> <inputattrs'> 0 <attrs0'>
  2085. dup /PageSize 7 index /PageSize get
  2086. put % PageSize in 0
  2087. put % 0 in InputAttributes
  2088. put % InputAttributes in pagedevice
  2089. % Also change the page size policy so we don't get an error.
  2090. % Stack: <pagedevice> <pagedevice> /Policies
  2091. 2 copy get dup length dict .copydict
  2092. % Stack: <pagedevice> <pagedevice> /Policies <policies'>
  2093. dup /PageSize 7 put % PageSize in Policies
  2094. put % Policies in pagedevice
  2095. .setpagedevice
  2096. %END MEDIA
  2097. % Set up the interpreter context version of -dUSeCIEColor option
  2098. % so that .getuseciecolor has the correct value (see gs_setpd.ps)
  2099. /setpagedevice where {
  2100. pop systemdict /UseCIEColor known {
  2101. mark /UseCIEColor UseCIEColor /..StartupGlobal //true .dicttomark setpagedevice
  2102. } if
  2103. } if
  2104. %END DISPLAYING
  2105. (END DEVICE) VMDEBUG
  2106. % Establish a default upper limit in the character cache,
  2107. % namely, enough room for a 18-point character at the resolution
  2108. % of the default device, or for a character consuming 1% of the
  2109. % maximum cache size, whichever is larger.
  2110. mark
  2111. % Compute limit based on character size.
  2112. 18 dup dtransform
  2113. exch abs cvi 31 add 32 idiv 4 mul % X raster
  2114. exch abs cvi mul % Y
  2115. % Compute limit based on allocated space.
  2116. cachestatus pop pop pop pop pop exch pop 0.01 mul cvi
  2117. .max dup 10 idiv exch
  2118. setcacheparams
  2119. % Conditionally disable the character cache.
  2120. NOCACHE { 0 setcachelimit } if
  2121. (END CONFIG) VMDEBUG
  2122. % Initialize graphics.
  2123. .setdefaultscreen
  2124. initgraphics
  2125. % The interpreter relies on there being at least 2 entries
  2126. % on the graphics stack. Establish the second one now.
  2127. gsave
  2128. % Define some control sequences as no-ops.
  2129. % This is a hack to get around problems
  2130. % in some common PostScript-generating applications.
  2131. <04> cvn JOBSERVER {
  2132. { { clear cleardictstack //false 0 .startnewjob } 2 .stop } .internalbind
  2133. } {
  2134. { }
  2135. } ifelse def
  2136. <1b> cvn
  2137. .actonuel % UEL is <esc>%-12345X and acts the same as ^D
  2138. {systemdict (.forceinterp_exit) cvn known {//true} {//false} ifelse}
  2139. {//false} ifelse
  2140. {
  2141. {
  2142. currentfile (%-12345X) .peekstring pop (%-12345X) eq
  2143. { currentfile .forceinterp_exit } if
  2144. }
  2145. }
  2146. {
  2147. {currentfile (%-12345X) .peekstring pop (%-12345X) eq <04> cvn load if}
  2148. } ifelse .internalbind def
  2149. <1b45> cvn { } def % PJL reset prologue (ESC E)
  2150. <1b451b> cvn <1b> cvn load def % PJL reset epilogue (ESC E + UEL)
  2151. (\001M) cvn % TBCP initiator
  2152. { currentfile /TBCPDecode filter cvx exec
  2153. } .internalbind def
  2154. /@PJL % H-P job control
  2155. {
  2156. % Windows 2000 driver includes PJL into %%BeginFeature block.
  2157. % Identify this from the pattern on the stack: countdictstack lucas mark
  2158. % and fail the feature request.
  2159. count 3 ge {
  2160. dup mark eq {
  2161. 2 index countdictstack eq {
  2162. 1 index /lucas where { /lucas get eq } { pop //false } ifelse {
  2163. stop
  2164. } if
  2165. } if
  2166. } if
  2167. } if
  2168. currentfile //=string readline pop pop
  2169. } .internalbind def
  2170. % Install the EPS handler if needed
  2171. systemdict /EPSBoundingBoxInit known { EPSBoundingBoxInit } if
  2172. systemdict /EPSBoundingBoxInit .forceundef
  2173. %% ---------------- SAFER stuff BEGIN -------------------%%
  2174. % If we want a "safer" system, disable some obvious ways to cause havoc.
  2175. .currentglobal //true .setglobal
  2176. /SAFETY 2 dict
  2177. dup /safe //false put
  2178. dup /tempfiles 10 dict noaccess put
  2179. readonly def
  2180. .setglobal
  2181. /SAFERUndefinePostScriptOperators {
  2182. [
  2183. % Used by our own test suite files
  2184. /.setdotlength % Bug687720.ps
  2185. /.sort /.setdebug /.mementolistnewblocks /getenv
  2186. /unread
  2187. /makeimagedevice
  2188. ]
  2189. {systemdict exch .forceundef} forall
  2190. //systemdict /SAFERUndefinePostScriptOperators .forceundef
  2191. } .forcebind def % must be bound and hidden for .forceundef
  2192. /tempfilepaths
  2193. [
  2194. (TMPDIR) getenv not
  2195. {
  2196. (TEMP) getenv not
  2197. {
  2198. (TMP) getenv not
  2199. {
  2200. (/temp) (/tmp)
  2201. } if
  2202. } if
  2203. } if
  2204. ] def
  2205. /.lockfileaccess {
  2206. .currentpathcontrolstate
  2207. {
  2208. //QUIET not
  2209. {
  2210. (\n **** WARNING: .lockfileaccess or .setsafe called ****\n) print
  2211. ( **** when file access controls are already active ****\n) print flush
  2212. } if
  2213. }
  2214. {
  2215. [
  2216. //tempfilepaths (*) .generate_dir_list_templates
  2217. /FONTPATH .systemvar (*) .generate_dir_list_templates
  2218. /level2dict where {
  2219. pop
  2220. % Default resources :
  2221. [ currentsystemparams /GenericResourceDir get] (*) .generate_dir_list_templates
  2222. } if
  2223. /LIBPATH .systemvar (*) .generate_dir_list_templates
  2224. currentuserparams /ICCProfilesDir known {
  2225. [currentuserparams /ICCProfilesDir get] (*)
  2226. .generate_dir_list_templates
  2227. } if
  2228. ] {/PermitFileReading exch .addcontrolpath} forall
  2229. [
  2230. //tempfilepaths (*) .generate_dir_list_templates
  2231. ] {/PermitFileWriting exch .addcontrolpath} forall
  2232. [
  2233. //tempfilepaths (*) .generate_dir_list_templates
  2234. ] {/PermitFileControl exch .addcontrolpath} forall
  2235. .activatepathcontrol
  2236. } ifelse
  2237. } .internalbind def
  2238. /.locksafe_userparams {
  2239. SAFETY /safe get not {
  2240. <<
  2241. /PermitFileReading [
  2242. currentuserparams /PermitFileReading get aload pop
  2243. //tempfilepaths (*) .generate_dir_list_templates
  2244. /FONTPATH .systemvar (*) .generate_dir_list_templates
  2245. % Library files :
  2246. /LIBPATH .systemvar (*) .generate_dir_list_templates
  2247. % Resource files on OpenVMS requires a separate template (gs:[dir.*]*)
  2248. % because the (gs:[dir]*) doesn't cover them.
  2249. /LIBPATH .systemvar (*) .file_name_separator (*)
  2250. concatstrings concatstrings .generate_dir_list_templates
  2251. .languagelevel 2 ge {
  2252. % Default resources :
  2253. [ currentsystemparams /GenericResourceDir get] (*) .generate_dir_list_templates
  2254. % Default resources (OpenVMS, see comment above.) :
  2255. [ currentsystemparams /GenericResourceDir get] (*) .file_name_separator (*)
  2256. concatstrings concatstrings .generate_dir_list_templates
  2257. } if
  2258. currentuserparams /ICCProfilesDir known {
  2259. [currentuserparams /ICCProfilesDir get] (*)
  2260. .generate_dir_list_templates
  2261. } if
  2262. ]
  2263. /PermitFileWriting [
  2264. currentuserparams /PermitFileWriting get aload pop
  2265. //tempfilepaths (*) .generate_dir_list_templates
  2266. ]
  2267. /PermitFileControl [
  2268. currentuserparams /PermitFileControl get aload pop
  2269. //tempfilepaths (*) .generate_dir_list_templates
  2270. ]
  2271. /LockFilePermissions //true
  2272. >> setuserparams
  2273. }
  2274. if
  2275. } .forcebind def
  2276. currentdict /tempfilepaths undef
  2277. %% --- These are documented extensions ---
  2278. /.locksafe {
  2279. //.locksafe_userparams exec
  2280. //systemdict /getenv {pop //false} .forceput
  2281. % setpagedevice has the side effect of clearing the page, but
  2282. % we will just document that. Using setpagedevice keeps the device
  2283. % properties and pagedevice .LockSafetyParams in agreement even
  2284. % after a restore that changes the value to false.
  2285. currentglobal currentpagedevice gcheck setglobal % use correct VM space
  2286. << /.LockSafetyParams //true >> setpagedevice
  2287. setglobal
  2288. //SAFETY /safe //true .forceput % overrides readonly
  2289. } .forcebind odef
  2290. /.setsafe
  2291. {
  2292. OLDSAFER {
  2293. SAFETY /safe get not {
  2294. <<
  2295. /PermitFileReading [ ]
  2296. /PermitFileWriting [ ]
  2297. /PermitFileControl [ ]
  2298. >> setuserparams
  2299. }
  2300. if
  2301. .locksafe
  2302. }
  2303. {
  2304. //.lockfileaccess exec
  2305. DELAYBIND not {
  2306. //systemdict /SAFERUndefinePostScriptOperators .knownget {exec} if
  2307. } if
  2308. }
  2309. ifelse
  2310. } .forcebind odef
  2311. %% --- End documented extensions ---
  2312. % This is only used during startup. Its required so that
  2313. % we can detect in setpagdevice that we are in fact in startup
  2314. % and allocate a *global* instead of local VM. We need it to be
  2315. % global to satisfy Display PostScript (see start of /setpagdevice
  2316. % in gs_setpd.ps)
  2317. %
  2318. /.locksafeglobal {
  2319. //.locksafe_userparams exec
  2320. systemdict /getenv {pop //false} put
  2321. % setpagedevice has the side effect of clearing the page, but
  2322. % we will just document that. Using setpagedevice keeps the device
  2323. % properties and pagedevice .LockSafetyParams in agreement even
  2324. % after a restore that changes the value to false.
  2325. currentglobal currentpagedevice gcheck setglobal % use correct VM space
  2326. << /.LockSafetyParams //true
  2327. /..StartupGlobal //true
  2328. >> setpagedevice
  2329. setglobal
  2330. //SAFETY /safe //true .forceput % overrides readonly
  2331. } .forcebind def
  2332. % See /.locksafeglobal above.
  2333. %
  2334. /.setsafeglobal {
  2335. OLDSAFER
  2336. {
  2337. SAFETY /safe get not {
  2338. <<
  2339. /PermitFileReading [ ]
  2340. /PermitFileWriting [ ]
  2341. /PermitFileControl [ ]
  2342. >> setuserparams
  2343. }
  2344. if
  2345. //.locksafeglobal exec
  2346. }
  2347. {
  2348. //.lockfileaccess exec
  2349. DELAYBIND not {
  2350. //systemdict /SAFERUndefinePostScriptOperators .knownget {exec} if
  2351. } if
  2352. }
  2353. ifelse
  2354. } .forcebind odef
  2355. % If we are running in SAFER mode, lock things down
  2356. SAFER { .setsafeglobal } if
  2357. currentdict /.locksafe_userparams .undef
  2358. currentdict /.setsafeglobal .undef
  2359. currentdict /.locksafeglobal .undef
  2360. %% ---------------- SAFER stuff END -------------------%%
  2361. /UndefinePostScriptFilters {
  2362. [
  2363. /BCPEncode /TBCPEncode /PNGPredictorEncode /PNGPredictorDecode /PixelDifferenceDecode /PixelDifferenceEncode
  2364. /zlibEncode /zlibDecode /PWGDecode /eexecEncode /ArcfourEncode /PSStringEncode /BCPDecode
  2365. /OLDPDF where {/OLDPDF get not {/SHA256Encode /MD5Encode /AESDecode /JPXDecode /JBIG2Decode /ArcfourDecode /.EOFDecode} if} if
  2366. ]
  2367. {filterdict exch undef} forall
  2368. } .forcebind def
  2369. /UndefinePostScriptOperators {
  2370. % This list is of operators which no longer appear to be used, and which we do not believe
  2371. % to have any real use. For now we will undefine the operstors so they cannot easily be used
  2372. % but can be easily restored (just delete the name from the list in the array). In future
  2373. % we may remove the operator and the code implementation entirely.
  2374. [
  2375. /.bitadd /.charboxpath /.cond /.runandhide /.popdevicefilter
  2376. /.execfile /.filenamesplit /.file_name_parent
  2377. /.setdefaultmatrix /.updatematrices /.isprocfilter /.unread /.psstringencode
  2378. /.buildsampledfunction /.isencapfunction /.currentaccuratecurves /.currentcurvejoin /.currentdashadapt /.currentdotlength
  2379. /.currentlimitclamp /.dotorientation /.setaccuratecurves /.setcurvejoin /.setdashadapt /.setdotorientation
  2380. /.setlimitclamp /.currentscreenlevels /.dashpath /.pathbbox /.identeq /.identne /.tokenexec /.forgetsave /.pantonecallback
  2381. % Used by our own test suite files
  2382. %/.setdotlength % Bug687720.ps
  2383. ]
  2384. {systemdict exch .forceundef} forall
  2385. % This list of operators are used internally by various parts of the Ghostscript startup code.
  2386. % Since each operator is a potential security vulnerability, and any operator listed here
  2387. % is not required once the initialisation is complete and functions are bound, we undefine
  2388. % the ones that aren't needed at runtime.
  2389. [
  2390. /.callinstall /.callbeginpage /.callendpage
  2391. /.currentstackprotect /.setstackprotect /.errorexec /.finderrorobject /.installsystemnames /.bosobject /.fontbbox
  2392. /.type1execchar /.type2execchar /.type42execchar /.setweightvector /.getuseciecolor /processcolors /.includecolorspace
  2393. /.execn /.instopped /.stop /.stopped /.setcolorrendering /.setdevicecolorrendering /.buildcolorrendering1 /.builddevicecolorrendering1
  2394. /.TransformPQR_scale_WB0 /.TransformPQR_scale_WB1 /.TransformPQR_scale_WB2 /.currentoverprintmode /.copydevice2
  2395. /.devicename /.doneshowpage /.getbitsrect /.getdevice /.getdefaultdevice /.getdeviceparams /.gethardwareparams
  2396. /makewordimagedevice /.outputpage /.putdeviceparams /.setdevice /.currentshowpagecount
  2397. /.setpagedevice /.currentpagedevice /.knownundef /.setmaxlength /.rectappend /.initialize_dsc_parser /.parse_dsc_comments
  2398. /.fillCIDMap /.fillIdentityCIDMap /.buildcmap /.filenamelistseparator /.libfile /.getfilename
  2399. /.file_name_combine /.file_name_is_absolute /.file_name_separator /.file_name_directory_separator /.file_name_current /.filename
  2400. /.peekstring /.writecvp /.subfiledecode /.setupUnicodeDecoder /.jbig2makeglobalctx /.registerfont /.parsecff
  2401. /.getshowoperator /.getnativefonts /.beginform /.endform /.get_form_id /.repeatform /.reusablestream /.rsdparams
  2402. /.buildfunction /.sethpglpathmode /.currenthpglpathmode
  2403. /.currenthalftone /.sethalftone5 /.image1 /.imagemask1 /.image3 /.image4
  2404. /.getiodevice /.getdevparms /.putdevparams
  2405. /.matchmedia /.matchpagesize /.defaultpapersize
  2406. /.oserrno /.setoserrno /.oserrorstring /.getCPSImode
  2407. /.getscanconverter /.setscanconverter /.type1encrypt /.type1decrypt/.languagelevel /.setlanguagelevel /.eqproc /.fillpage
  2408. /.shfill /.argindex /.bytestring /.namestring /.stringbreak /.stringmatch /.globalvmarray /.globalvmdict /.globalvmpackedarray /.globalvmstring
  2409. /.localvmarray /.localvmdict /.localvmpackedarray /.localvmstring /.systemvmarray /.systemvmdict /.systemvmpackedarray /.systemvmstring /.systemvmfile /.systemvmlibfile
  2410. /.systemvmSFD /.settrapparams /.currentsystemparams /.currentuserparams /.getsystemparam /.getuserparam /.setsystemparams /.setuserparams
  2411. /.checkpassword /.locale_to_utf8 /.currentglobal /.gcheck /.imagepath /.currentoutputdevice
  2412. /.type /.writecvs /.setSMask /.currentSMask /.needinput /.countexecstack /.execstack
  2413. /filterdict /.cidfonttypes /.colorrenderingtypes
  2414. /.formtypes /.halftonetypes /.imagetypes /.imagemasktypes
  2415. /.patterntypes /.shadingtypes /.wheredict /.renderingintentdict
  2416. /.currentmatrix /.setmatrix
  2417. /.setlinecap /.setlinejoin /.sizeimagebox /.systemvmcheck
  2418. /.forceinterp_exit /.actonuel
  2419. /.init_otto_font_file
  2420. /.composefontdict
  2421. /.type1build
  2422. /.buildnativefontmap
  2423. /.completefont
  2424. /.definefakefonts
  2425. /.fontnameproperties
  2426. /.growfontdict
  2427. /.substitutefont /.substitutefontname
  2428. /.FontDirectory
  2429. /.charkeys
  2430. /.makesfnts
  2431. /.pickcmap
  2432. /.loadttcidfont
  2433. /.loadpdfttfont
  2434. /obind
  2435. /odef
  2436. /.packtomark
  2437. /.putdeviceprops
  2438. /putdeviceprops
  2439. /getdeviceprops
  2440. /finddevice
  2441. /.growdict /.growdictlength
  2442. /.userdict /.uservar
  2443. /.getdefaulthalftone
  2444. /.registererror
  2445. /.PurgeDict
  2446. /.runresource
  2447. /.numicc_components
  2448. /.set_outputintent
  2449. /.internalstopped
  2450. /.generate_dir_list_templates /.generate_dir_list_templates_with_length
  2451. /.type11mapcid /.type9mapcid
  2452. /.clearerror
  2453. /.beginpage /.endpage
  2454. /.getpath
  2455. /.confirm /.confirmread
  2456. % Used by a free user in the Library of Congress. Apparently this is used to
  2457. % draw a partial page, which is then filled in by the results of a barcode
  2458. % scanner and SQL database lookup. Its not clear to us exactly why this needs to be
  2459. % done as a partial page, but its easiest to restore the operator, and it seems like
  2460. % its a reasonably safe operator to restore, for the *very* few devices on which
  2461. % it will have any effect. Currently this uses the 'sync_output' device method
  2462. % to transfer the partial page, in future we may use a spec_op instead.
  2463. %/flushpage
  2464. % Used by our own test suite files
  2465. %/.fileposition %image-qa.ps
  2466. % Either our code uses these in ways which mean they can't be undefined, or they are used directly by
  2467. % test files/utilities, or engineers expressed a desire to keep them visible.
  2468. %
  2469. %/currentdevice /.sort /.buildfont0 /.buildfont1 /.buildfont2 /.buildfont3 /.buildfont4 /.buildfont9 /.buildfont10 /.buildfont11
  2470. %/.buildfont32 /.buildfont42 /.swapcolors
  2471. %/currentdevice /.quit /.setuseciecolor /.needinput /.setoverprintmode /.special_op /.dicttomark /.knownget
  2472. %/.FAPIBuildGlyph /.FAPIBuildChar /.FAPIBuildGlyph9
  2473. %/.tempfile /.max /.min /.setglobal
  2474. %/.setdebug /.mementolistnewblocks /getenv
  2475. ]
  2476. {systemdict exch .forceundef} forall
  2477. % level 2 operators, undefine from both systemdict and level2dict
  2478. [
  2479. /.execform1
  2480. /.getdevparams
  2481. /.setuserparams2
  2482. /.startjob
  2483. /.checkFilePermitparams
  2484. /.copyparam
  2485. /.setdevicecolorrendering1
  2486. /.buildpattern1
  2487. /.findcategory
  2488. /.execinstall
  2489. /.findfontop
  2490. % Couldn't figure out how to do these yet
  2491. % /.checkparamtype
  2492. % /.startnewjob
  2493. ]
  2494. dup {level2dict exch .forceundef} forall
  2495. {systemdict exch .forceundef} forall
  2496. % undef stuff from statusdict
  2497. [
  2498. % /.setpagesize
  2499. ]
  2500. {statusdict exch .forceundef} forall
  2501. //systemdict /UndefinePostScriptFilters .forceundef
  2502. //systemdict /UndefinePostScriptOperators .forceundef
  2503. } .forcebind def % must be bound and hidden for .forceundef
  2504. % If we delayed binding, make it possible to do it later.
  2505. /.bindnow {
  2506. currentuserparams /IdiomRecognition .knownget {
  2507. 1 dict dup /IdiomRecognition //false put setuserparams
  2508. } if
  2509. //systemdict begin .bindoperators end
  2510. % Temporarily disable the typecheck error.
  2511. errordict /typecheck 2 copy get
  2512. errordict /typecheck { pop } put % pop the command
  2513. 0 1 .delaycount 1 sub { .delaybind exch get .forcebind pop } for
  2514. 0 1 .delayinternalcount 1 sub { .delayinternalbind exch get .forcebind pop } for
  2515. //systemdict /.delaybind {} .forceput % reclaim the space
  2516. //systemdict /.delayinternalbind {} .forceput % reclaim the space
  2517. //systemdict /.bindnow .forceundef % ditto
  2518. .applyundefinternalnames
  2519. put
  2520. SAFER {
  2521. //systemdict /SAFERUndefinePostScriptOperators get exec
  2522. } if
  2523. //systemdict /UndefinePostScriptFilters get exec
  2524. //systemdict /UndefinePostScriptOperators get exec
  2525. //systemdict /.forcecopynew .forceundef % remove temptation
  2526. //systemdict /.forceput .forceundef % ditto
  2527. //systemdict /.undef .forceundef % ditto
  2528. //systemdict /.bindoperators .forceundef
  2529. //systemdict /.forceundef .forceundef % ditto
  2530. //systemdict /.undefinternalnames .forceundef
  2531. //systemdict /.applyundefinternalnames .forceundef
  2532. //systemdict /.undefinternalnameslist .forceundef
  2533. //systemdict /.internalbind .forceundef
  2534. //systemdict /.forcebind .forceundef
  2535. currentuserparams /IdiomRecognition known {
  2536. 1 dict dup /IdiomRecognition 4 -1 roll put setuserparams
  2537. } if
  2538. } .forcebind def
  2539. % Turn off array packing, since some PostScript code assumes that
  2540. % procedures are writable.
  2541. //false setpacking
  2542. (END INIT) VMDEBUG
  2543. /.currentuserparams where {
  2544. pop
  2545. % Remove real user params from psuserparams.
  2546. mark .currentuserparams counttomark 2 idiv {
  2547. pop psuserparams exch undef
  2548. } repeat pop
  2549. % Update the copy of the user parameters.
  2550. mark .currentuserparams counttomark 2 idiv {
  2551. userparams 3 1 roll .forceput % userparams is read-only
  2552. } executeonly repeat pop
  2553. % Turn on idiom recognition, if available.
  2554. currentuserparams /IdiomRecognition known {
  2555. /IdiomRecognition //true .definepsuserparam
  2556. } if
  2557. psuserparams readonly pop
  2558. systemdict /.definepsuserparam undef
  2559. % Save a copy of userparams for use with save/restore
  2560. % (and, if implemented, context switching).
  2561. .currentglobal //false .setglobal
  2562. mark userparams { } forall .dicttomark readonly
  2563. currentdict exch /userparams exch .forceput % systemdict is read-only
  2564. .setglobal
  2565. } executeonly if
  2566. /.currentsystemparams where {
  2567. pop
  2568. % Remove real system params from pssystemparams.
  2569. mark .currentsystemparams counttomark 2 idiv {
  2570. pop pssystemparams exch .forceundef
  2571. } executeonly repeat pop
  2572. } if
  2573. % Set up AlignToPixels :
  2574. /AlignToPixels where {
  2575. mark /AlignToPixels 2 index /AlignToPixels get .dicttomark setuserparams
  2576. /AlignToPixels undef
  2577. } if
  2578. % Set up GridFitTT :
  2579. /GridFitTT where {
  2580. mark /GridFitTT 2 index /GridFitTT get .dicttomark setuserparams
  2581. /GridFitTT undef
  2582. } if
  2583. % Establish local VM as the default.
  2584. //false /setglobal where { pop setglobal } { .setglobal } ifelse
  2585. $error /.nosetlocal //false put
  2586. (END GLOBAL) VMDEBUG
  2587. % Add the fake fonts to LocalFontDirectory.
  2588. //.definefakefonts exec % current VM is local
  2589. % Execute scheduled inits :
  2590. 1183615869 internaldict /.execute_scheduled_inits get exec
  2591. currentdict /.schedule_init undef
  2592. %currentdict /.execute_scheduled_inits undef
  2593. %currentdict /.delayed_init_queue undef
  2594. % Make global and local FontDirectory read-only.
  2595. FontDirectory readonly pop
  2596. /GlobalFontDirectory where { pop GlobalFontDirectory readonly pop } if
  2597. % If we are using DELAYBIND we have to defer the undefinition
  2598. % until .bindnow.
  2599. DELAYBIND not {
  2600. //systemdict /UndefinePostScriptFilters get exec
  2601. //systemdict /UndefinePostScriptOperators get exec
  2602. } if
  2603. end
  2604. % Clean up VM, and enable GC. Use .vmreclaim to force the GC.
  2605. /vmreclaim where
  2606. { pop //systemdict /NOGC get not { 2 .vmreclaim 0 vmreclaim } if
  2607. } if
  2608. systemdict /.vmreclaim .undef
  2609. level2dict /.vmreclaim .undef
  2610. % Do this before systemdict is locked (see below for additional CETMODE setup using gs_cet.ps)
  2611. systemdict /CETMODE .knownget {
  2612. {
  2613. (gs_cet.ps) runlibfile
  2614. } if
  2615. } if
  2616. systemdict /.makeoperator .undef % must be after gs_cet.ps
  2617. systemdict /.setCPSImode .undef % must be after gs_cet.ps
  2618. DELAYBIND not {
  2619. systemdict /.bindnow .undef % We only need this for DELAYBIND
  2620. systemdict /.internalbind .undef
  2621. systemdict /.forcebind .undef
  2622. systemdict /.forcecopynew .undef % remove temptation
  2623. systemdict /.forceput .undef % ditto
  2624. systemdict /.forceundef .undef % ditto
  2625. systemdict /.undefinternalnames .undef
  2626. systemdict /.applyundefinternalnames .undef
  2627. systemdict /.undefinternalnameslist .undef
  2628. } if
  2629. % Can't remove this one until the last minute :-)
  2630. DELAYBIND not {
  2631. systemdict /.undef .undef
  2632. } if
  2633. WRITESYSTEMDICT {
  2634. SAFER {
  2635. (\n *** WARNING - you have selected SAFER, indicating you want Ghostscript\n) print
  2636. ( to execute in a safer environment, but at the same time\n) print
  2637. ( have selected WRITESYSTEMDICT. Unless you use this option with\n) print
  2638. ( care and specifically, remember to execute code like:\n) print
  2639. ( "systemdict readonly pop"\n) print
  2640. ( it is possible that malicious code may be able to evade the\n) print
  2641. ( limited security offered by the SAFER option.\n) print flush
  2642. }if
  2643. }
  2644. {
  2645. systemdict readonly pop
  2646. } ifelse
  2647. (END GC) VMDEBUG
  2648. % The Adobe AGM_Core used by Illustrator 9 has some code that breaks
  2649. % if the 'product' is not (Adobe PostScript Parser). A bug has been
  2650. % submitted to Adobe since this also fails with Acrobat Distiller.
  2651. % As a temporary work around, the following HACK will work for
  2652. % devices without spot color support. Once Ghostscript can
  2653. % support DeviceN and spot color separations this will need to
  2654. % be 'true' in some cases.
  2655. userdict /AGM_preserve_spots //false put
  2656. % The interpreter will run the initial procedure (start).