home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / gs_cmdl.ps < prev    next >
Text File  |  2002-02-22  |  5KB  |  181 lines

  1. %    Copyright (C) 1994, 1996, 1999 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_cmdl.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
  14. % Parse and execute the command line.
  15. % C code handles the following switches: -h/-? -I -M -v
  16.  
  17. /cmddict 50 dict def
  18. cmddict begin
  19.  
  20. % ---------------- Utility procedures ---------------- %
  21.  
  22. % Get the next argument from the parsed argument list.
  23. /nextarg        % - nextarg <arg> true
  24.             % - nextarg false
  25.  { argv length 0 eq
  26.     { false }
  27.     { argv dup 0 get exch dup length 1 sub 1 exch getinterval /argv exch def }
  28.    ifelse
  29.  } bind def
  30.  
  31. % Run a file, under job control if implemented.
  32. /runjob            % <file> runjob -
  33.  { end        % cmddict
  34.    /startjob where { pop false () startjob pop }
  35.    run
  36.    //cmddict begin
  37.  } bind def
  38. /runfilejob        % <filename> runfilejob -
  39.  { findlibfile { exch pop } { (r) file } runjob
  40.  } bind def
  41.  
  42. % Expand arguments.  Free variables: expand@.
  43. /expandarg        % <string> expandarg <args...>
  44.  { dup () eq
  45.     { pop
  46.     }
  47.     { dup dup (--) eq exch (-+) eq or
  48.        { pop /expand@ false def
  49.        }
  50.        { expand@ { (@) anchorsearch } { false } ifelse
  51.       { pop findlibfile
  52.          { exch pop }
  53.          { (r) file }        % let the error happen
  54.         expandargfile
  55.       }
  56.      if
  57.        }
  58.       ifelse
  59.     }
  60.  } bind def
  61. /expandargfile        % <file> expandargfile <args...>
  62.  { [ exch cvlit
  63.     { token not { exit } if
  64.       dup type /stringtype ne { =string cvs dup length string copy } if
  65.       expandarg
  66.     }
  67.    /exec cvx
  68.    ] cvx loop
  69.  } bind def
  70.  
  71. % ---------------- Recognized switches ---------------- %
  72.  
  73. % Switches with arguments are defined as <x>;
  74. % switches without arguments are defined as -<x>.
  75.  
  76. % Switches without arguments
  77. /--
  78.  { nextarg not
  79.     { (-- and -+ require a file name.) = flush }
  80.     { //systemdict /ARGUMENTS argv put /argv [] def runjob }
  81.    ifelse
  82.  } bind def
  83. /-+ /-- load def
  84. /-@ /-- load def
  85. /-A { (@) Z } bind def
  86. /-c
  87.  {  { argv length 0 eq { exit } if
  88.       argv 0 get (-) anchorsearch { pop pop exit } if
  89.       pop nextarg token
  90.        { exch pop            % Probably should check for empty.
  91.      end exec //cmddict begin
  92.        }
  93.       if
  94.     }
  95.    loop
  96.  } bind def
  97. /-e { (#) Z } bind def
  98. /-E /-e load def
  99. /-f { } def
  100. /-q { //systemdict /QUIET true put } bind def
  101.  
  102. % Switches with arguments
  103. /d
  104.  { (=) search not { (#) search not { () exch dup } if } if
  105.    exch pop cvn dup where
  106.     { pop (Redefining ) print print ( is not allowed.) = flush pop }
  107.     { exch token
  108.        { exch pop }        % Probably should check for empty.
  109.        { true }
  110.       ifelse
  111.       //systemdict 3 1 roll put
  112.     }
  113.    ifelse
  114.  } bind def
  115. /D /d load def
  116. /f { dup length 0 ne { runfilejob } if } bind def
  117. /g
  118.  { (x) search { cvi pop exch cvi } { cvi dup } ifelse
  119.    //systemdict begin /DEVICEHEIGHT exch def /DEVICEWIDTH exch def end
  120.  } bind def
  121. /r
  122.  { (x) search { cvr pop exch cvr } { cvr dup } ifelse
  123.    //systemdict begin /DEVICEYRESOLUTION exch def /DEVICEXRESOLUTION exch def end
  124.  } bind def
  125. /s
  126.  { (=) search not { (#) search not { () exch dup } if } if
  127.    exch pop cvn dup where { pop dup load } { () } ifelse
  128.    type /stringtype ne
  129.     { (Redefining ) print print ( is not allowed.) = flush pop }
  130.     { exch //systemdict 3 1 roll put }
  131.    ifelse
  132.  } bind def
  133. /S /s load def
  134. /Z { true .setdebug } bind def
  135.  
  136. % ---------------- Main program ---------------- %
  137.  
  138. % We process the command line in two passes.  In the first pass,
  139. % we read and expand any @-files as necessary.  The second pass
  140. % does the real work.
  141.  
  142. /cmdstart
  143.  { //cmddict begin
  144.    /expand@ true def
  145.    [
  146.         % Process the GS_OPTIONS environment variable.
  147.    (GS_OPTIONS) getenv { 0 () /SubFileDecode filter expandargfile } if
  148.         % Process the actual command line.
  149.    .getargv { expandarg } forall
  150.    ] readonly /argv exch def
  151.         % Now interpret the commands.
  152.     { nextarg not { exit } if
  153.       dup 0 get (-) 0 get eq
  154.        { dup length 1 eq
  155.       { pop (%stdin) (r) file runjob
  156.       }
  157.       { dup length 2 gt
  158.          { dup dup length 2 sub 2 exch getinterval exch 1 1 getinterval }
  159.         if currentdict .knownget
  160.          { exec
  161.          }
  162.          { (Ignoring unknown switch ) print
  163.            dup length 1 eq { (-) print print } if print
  164.            () = flush
  165.          }
  166.         ifelse
  167.       }
  168.      ifelse
  169.        }
  170.        { runfilejob
  171.        }
  172.       ifelse
  173.     }
  174.    loop end
  175.  } bind def
  176.  
  177. end        % cmddict
  178.