Debian Codegraph @

Resource/Init/gs_diskn.ps

raw
1 % Copyright (C) 2001-2023 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
16 % Initialization file for %disk device modifications
17 % When this is run, systemdict is still writable,
18
19 systemdict begin
20
21 % Collect the list of searchable IODevices in SearchOrder
22 % Efficiency here doesn't matter since we run this at the end
23 % of gs_init and convert it to a static array.
24 /.getsearchabledevs { % - .getsearchabledevs [ list_of_strings ]
25 //systemdict /.searchabledevs .knownget not {
26 .currentglobal //true .setglobal
27 mark (*) {
28 dup length string copy dup currentdevparams /Searchable
29 .knownget { not { pop } if } { pop } ifelse
30 } 8192 string /IODevice resourceforall
31 ]
32 % now process the array into correct SearchOrder
33 0 1 2 {
34 mark exch 2 index {
35 dup currentdevparams /SearchOrder get 2 index eq
36 { exch } { pop } ifelse
37 } forall % devices on the old list
38 pop
39 % make the array and sort it by name
40 ] { lt } bind .sort
41 exch
42 } for
43 % collect all devices with SearchOrder > 2
44 mark 2 index {
45 dup currentdevparams /SearchOrder get 2 gt
46 { exch } { pop } ifelse
47 } forall
48 ] exch pop
49 % We now have 4 arrays on the stack, SO=0 SO=1 SO=2 SO>2
50 % make them into a single array
51 mark 5 1 roll ] mark exch { { } forall } forall ]
52 //systemdict /.searchabledevs 2 index .forceput
53 exch .setglobal
54 } executeonly
55 if
56 } .forcebind odef % must be bound and hidden for .forceput
57
58 % Modify .putdevparams to force regeneration of .searchabledevs list
59 /.putdevparams {
60 % We could be smarter and check for %disk* device, but this
61 % doesn't get run enough to justify the complication
62 //.putdevparams
63 //systemdict /.searchabledevs .forceundef
64 } .forcebind odef % must be bound and hidden for .forceundef
65
66 % ------ extend filenameforall to handle wildcards in %dev% part of pattern -------%
67 /filenameforall {
68 count 3 ge {
69 2 index (%) search {
70 pop pop
71 } {
72 % no device specified, so search them all
73 pop (*%) 3 index concatstrings
74 % we need to suppress the device when we return the string
75 % in order to match Adobe's behaviour with %disk devices.
76 4 -2 roll % the callers procedure
77 [ { (%) search { pop pop (%) search { pop pop } if } if } /exec load
78 4 -1 roll % the callers procedure
79 /exec load
80 ] cvx
81 4 2 roll % put the modified procedure where it belongs
82 } ifelse
83 % extract device portion (up to end of string or next %)
84 (%) search { exch pop } if % stack: opat proc scratch npat device
85 dup (*) search { pop pop pop //true } { pop //false } ifelse
86 1 index (?) search { pop pop pop //true } { pop //false } ifelse
87 or not {
88 pop pop //filenameforall % device with no wildcard
89 } {
90 (%) concatstrings (%) exch concatstrings
91 .getsearchabledevs
92 % find all matching devices and add the rest of the search string
93 mark exch {
94 dup counttomark 1 add index .stringmatch {
95 counttomark 2 add index concatstrings
96 } {
97 pop
98 } ifelse
99 } forall
100 ]
101 3 1 roll pop pop
102 4 -1 roll pop
103 % now we need to invoke filenameforall for each of the strings
104 % in the array. We do this by building a procedure that is like
105 % an unrolled 'forall' loop. We do this to get the parameters
106 % for each filenameforall, since each execution will pop its
107 % parameters, but we can't use the operand stack for storage
108 % since each invocation must have the same operand stack.
109 mark exch {
110 counttomark dup 3 add index exch
111 2 add index
112 /filenameforall load
113 } forall
114 ] cvx
115 3 1 roll pop pop
116 exec % run our unrolled loop
117 }
118 ifelse
119 } {
120 //filenameforall % not enough parameters -- just let it fail
121 }
122 ifelse
123 } odef
124
125 % redefine file to search all devices in order
126 /file {
127 dup 0 get (r) 0 get eq dup {
128 pop //false % success code
129 2 index 0 get 37 eq { [ () ] } { .getsearchabledevs } ifelse
130 { 3 index concatstrings % prepend the device
131 {
132 2 index //file } //.internalstopped exec not {
133 4 1 roll pop pop pop //true
134 exit % exit with success
135 } {
136 pop pop
137 }
138 ifelse
139 }
140 forall
141 }
142 if
143 not { % just let standard file operator handle things
144 //file
145 }
146 if
147 } .internalbind odef
148
149 % redefine deletefile to search all devices in order
150 /deletefile {
151 //false % success code
152 1 index 0 get 37 eq { [ () ] } { .getsearchabledevs } ifelse
153 { 2 index concatstrings % prepend the device
154 { //deletefile } //.internalstopped exec exch pop not {
155 pop //true exit % exit with success
156 }
157 if
158 }
159 forall
160 not { $error /errorname get /deletefile .systemvar exch signalerror } if
161 } .internalbind odef
162
163 % redefine status to search all devices in order
164 /status {
165 dup type /stringtype eq {
166 //false % success code
167 1 index 0 get 37 eq { [ () ] } { .getsearchabledevs } ifelse
168 { 2 index concatstrings % prepend the device
169 { //status } //.internalstopped exec not {
170 { //true 7 -2 roll pop pop //true exit } % exit with success
171 if
172 }
173 if
174 }
175 forall
176 % If we made it this far, no devices were found to status the file
177 % clean up to return 'false'
178 exch pop
179 } {
180 //status
181 }
182 ifelse
183 } .internalbind odef
184
185 % Also redefine renamefile to search all devices in order
186 /renamefile {
187 //false % success code
188 2 index 0 get 37 eq { [ () ] } { .getsearchabledevs } ifelse
189 { dup 4 index concatstrings % prepend the device
190 { (r) //file } //.internalstopped exec
191 not {
192 closefile exch pop //true exit % exit with success
193 } {
194 pop pop
195 } ifelse
196 }
197 forall
198 not { $error /errorname get /renamefile .systemvar exch signalerror } if
199 3 -1 roll concatstrings exch
200 //renamefile
201 } .internalbind odef
202
203 % redefine devforall to process devices in numeric order
204 % Spec's for 'devforall' are unclear, but font downloaders may expect this
205 /devforall { % <proc> <scratch> devforall -
206 [ { dup length string copy } 2 index //devforall ]
207 % stack: proc scratch array_of_device_names
208 { lt } .sort
209 % We don't really invoke the procedure with the scratch string
210 % but rather with the strings from our array
211 exch pop exch forall
212 } odef
213 end % systemdict