home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / gs_diskn.ps < prev    next >
Text File  |  2003-12-13  |  7KB  |  215 lines

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