GIF89a; EcchiShell v1.0
//proc/self/root/usr/share/ghostscript/ to write to the underlying dictionary, % and put it back after the enumeration is completed. end { 0 1 2 { en_local_dict exch /status exch put InstancesStatus { en_local_dict /status get eq { scr cvs % ... (Font) proc exec % } { pop } ifelse % ... } forall } for % ... } stopped Category begin { stop } if } bind def % An auxiliary proc for BindWithCurrentdict : /.BindAux % BindAux { 0 exec } bind def setpacking /BindWithCurrentdict % BindWithCurrentdict { % Make a copy of the given procedure, binding in the values of all names % defined in currentdict. % Caution1 : this code cannot handle procedures that were already % bound recursively. % Caution2 : this code don't bind packedarrays. This was done % intentionally for a termination of the procedure tree. dup length array copy dup length 1 sub -1 0 { 2 copy get % {precopy} i {elem} dup dup type /arraytype eq exch xcheck and { % {precopy} i {elem} //.BindAux exec % {precopy} i {elem_copy} 2 index 3 1 roll put % {precopy} } { dup dup type /nametype eq exch xcheck and { % {precopy} i {elem} currentdict exch .knownget { 2 index 3 1 roll put % {precopy} } { pop } ifelse } { pop pop } ifelse } ifelse % {precopy} } for % {copy} cvx } bind def //.BindAux 0 //BindWithCurrentdict put % bind the recursive call in 'Bind'. /MakeResourceEnumerator % MakeResourceEnumerator { % Build the enumeration procedure : % Since the resourceforall procedure may leave values on the operand stack, % we cannot simply store the enumerator's local data on the stack. % We also cannot use a static dictionary to store local variables, % because of possible recursion in the resourceforall procedure. % To work around this, we create a copy of the enumeration procedure and % bind it dynamically with a temporary dictionary, which contains % local variables for the currently executing instance of resourceforall. % Always place the enumerator in local VM, % because its elements may be in local VM. currentglobal 4 1 roll //false setglobal currentdict % Category 6 dict begin % the temporary dictionary /Category exch def /InstancesStatus exch def /scr exch def /proc exch def /en_local_dict currentdict def //InstanceEnumeratorPattern //BindWithCurrentdict exec % Enumerator /status 0 def % variable for the current status to enumerate - do not bind with it ! end exch setglobal } bind def /execstack_lookup % execstack_lookup % execstack_lookup null { % Checks whether execution stack contains a procedure starting with , % and retrives the 2nd element of the procedure, % or null if the procedure was not found. % % Since 'execstack' actually renders subarrays of procedures, % the pattern for recognition must be like this : % % { % CallSomething % } loop % % The solution with 'loop' depends on how GS implements cycles, % so it must not appear in documents, which are required to be interpreter independent. % Any other type of cycles are also acceptable. % If no repitition is really needed, just insert 'exit' into its body. % If are not needed for the caller, insert "pop pop" after them. % If is really unuseful, the pattern may be simplified : % % { pop % CallSomething % exit % } loop % % It will retrieve 'pop' or 'null'. % % Note that 2 topmost execstack elements are the execstack_lookup procedure and its caller. % We don't check them. currentglobal //false setglobal % bGlobal //false .countexecstack array //false .execstack % bGlobal [execstack] dup //null exch % bGlobal [execstack] null [execstack] length 3 sub -1 0 { % bGlobal [execstack] null i 2 index exch get % bGlobal [execstack] null proc dup type dup /packedarraytype eq exch /arraytype eq or { dup rcheck { dup length 1 gt { % bGlobal [execstack] null proc dup 0 get % bGlobal [execstack] null proc elem0 5 index eq { % bGlobal [execstack] null proc 1 get % bGlobal [execstack] null object1 exch pop exit % bGlobal [execstack] object1 } { pop } ifelse } { pop % bGlobal [execstack] false } ifelse } { pop % bGlobal [execstack] false } ifelse } { pop % bGlobal [execstack] false } ifelse } for % bGlobal [execstack] bResult exch pop exch setglobal exch pop % bResult } bind def currentpacking //false setpacking /MethodsToRedefine 5 dict begin % Procedures in this dictionary really are patterns for new category methods. % The following names will be replaced with specific objects during BindWithCurrentdict : % .map - the map dictionary; % DefineResource, ResourceStatus, ResourceFileName, FindResource, ResourceForAll % - procedures from the original resource category. /FindResource % FindResource { RESMPDEBUG { (resmp FindResource beg ) print dup = } if dup ResourceStatus exec { pop 2 lt } { //false } ifelse % bInVirtualMemory { FindResource exec } { dup dup .map exch .knownget { % /Name /Name <> dup dup /RecordVirtualMethods get /IsActive get exec { 1 index .getvminstance { % /Name /Name <> holder 1 get 1 eq } { //true } ifelse % /Name /Name <> bStatusIs1 4 1 roll % bStatusIs1 /Name /Name <> dup /RecordVirtualMethods get /MakeInstance get exec % bStatusIs1 /Name /Name Instance size 5 1 roll % size bStatusIs1 /Name /Name Instance DefineResource exec % size bStatusIs1 /Name Instance % Make ResourceStatus to return correct values for this instance : % Hack: we replace status values in the instance holder : exch .getvminstance pop % size bStatusIs1 Instance holder dup 5 -1 roll 2 exch put % bStatusIs1 Instance holder 3 2 roll { % Instance holder 1 1 put % Instance } { pop } ifelse % Instance } { % /Name /Name <> pop pop FindResource exec } ifelse } { % /Name /Name pop FindResource exec } ifelse } ifelse RESMPDEBUG { (resmp FindResource end) = } if } bind def /ResourceStatus % ResourceStatus true % ResourceStatus false { RESMPDEBUG { (resmp ResourceStatus beg ) print dup //== exec } if dup ResourceStatus exec { % /Name status size 1 index 2 lt { % In VM - return with it. 3 2 roll pop //true } { % Not in VM. exch pop exch % size /Name dup .map exch .knownget { % size /Name <> dup dup /RecordVirtualMethods get /IsActive get exec { 3 2 roll pop % /Name <> dup /RecordVirtualMethods get /GetSize get exec 2 exch //true } { % size /Name <> pop pop 2 exch //true } ifelse } { % size /Name pop 2 exch //true } ifelse } ifelse } { % /Name dup .map exch .knownget { % /Name <> dup dup /RecordVirtualMethods get /IsActive get exec { dup /RecordVirtualMethods get /GetSize get exec 2 exch //true } { % /Name <> pop pop //false } ifelse } { % /Name pop //false } ifelse } ifelse RESMPDEBUG { (resmp ResourceStatus end) = } if } bind def /ResourceFileName % ResourceFileName { RESMPDEBUG { (resmp ResourceFileName beg ) print 1 index = } if exch % (scratch) /Name .map 1 index .knownget { % (scratch) /Name <> RESMPDEBUG { (resmp ResourceFileName : have a map record.) = } if dup dup /RecordVirtualMethods get /IsActive get exec { RESMPDEBUG { (resmp ResourceFileName : record is active.) = } if dup /RecordVirtualMethods get /GetFilePath get exec % (string) RESMPDEBUG { (resmp ResourceFileName : retrieving ) print dup = } if } { % (scratch) /Name <> RESMPDEBUG { (resmp ResourceFileName : record is NOT active.) = } if pop exch ResourceFileName exec RESMPDEBUG { (resmp ResourceFileName : retrieving ) print dup = } if } ifelse } { RESMPDEBUG { (resmp ResourceFileName : have NO map record.) = } if exch ResourceFileName exec RESMPDEBUG { (resmp ResourceFileName : retrieving ) print dup = } if } ifelse RESMPDEBUG { (resmp ResourceFileName end) = } if } bind def /ResourceForAll %