1 % Copyright (C) 1994, 1996, 1999 Aladdin Enterprises. All rights reserved.
3 % This software is provided AS-IS with no warranty, either express or
6 % This software is distributed under license and may not be copied,
7 % modified or distributed except as expressly authorized under the terms
8 % of the license contained in the file LICENSE in this distribution.
10 % For more information about licensing, please refer to
11 % http://www.ghostscript.com/licensing/. For information on
12 % commercial licensing, go to http://www.artifex.com/licensing/ or
13 % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
16 % $Id: gs_cmdl.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
17 % Parse and execute the command line.
18 % C code handles the following switches: -h/-? -I -M -v
23 % ---------------- Utility procedures ---------------- %
25 % Get the next argument from the parsed argument list.
26 /nextarg % - nextarg <arg> true
30 { argv dup 0 get exch dup length 1 sub 1 exch getinterval /argv exch def }
34 % Run a file, under job control if implemented.
35 /runjob % <file> runjob -
37 /startjob where { pop false () startjob pop }
41 /runfilejob % <filename> runfilejob -
42 { findlibfile { exch pop } { (r) file } runjob
45 % Expand arguments. Free variables: expand@.
46 /expandarg % <string> expandarg <args...>
50 { dup dup (--) eq exch (-+) eq or
51 { pop /expand@ false def
53 { expand@ { (@) anchorsearch } { false } ifelse
56 { (r) file } % let the error happen
64 /expandargfile % <file> expandargfile <args...>
66 { token not { exit } if
67 dup type /stringtype ne { =string cvs dup length string copy } if
74 % ---------------- Recognized switches ---------------- %
76 % Switches with arguments are defined as <x>;
77 % switches without arguments are defined as -<x>.
79 % Switches without arguments
82 { (-- and -+ require a file name.) = flush }
83 { //systemdict /ARGUMENTS argv put /argv [] def runjob }
88 /-A { (@) Z } bind def
90 { { argv length 0 eq { exit } if
91 argv 0 get (-) anchorsearch { pop pop exit } if
93 { exch pop % Probably should check for empty.
94 end exec //cmddict begin
100 /-e { (#) Z } bind def
103 /-q { //systemdict /QUIET true put } bind def
105 % Switches with arguments
107 { (=) search not { (#) search not { () exch dup } if } if
108 exch pop cvn dup where
109 { pop (Redefining ) print print ( is not allowed.) = flush pop }
111 { exch pop } % Probably should check for empty.
114 //systemdict 3 1 roll put
119 /f { dup length 0 ne { runfilejob } if } bind def
121 { (x) search { cvi pop exch cvi } { cvi dup } ifelse
122 //systemdict begin /DEVICEHEIGHT exch def /DEVICEWIDTH exch def end
125 { (x) search { cvr pop exch cvr } { cvr dup } ifelse
126 //systemdict begin /DEVICEYRESOLUTION exch def /DEVICEXRESOLUTION exch def end
129 { (=) search not { (#) search not { () exch dup } if } if
130 exch pop cvn dup where { pop dup load } { () } ifelse
132 { (Redefining ) print print ( is not allowed.) = flush pop }
133 { exch //systemdict 3 1 roll put }
137 /Z { true .setdebug } bind def
139 % ---------------- Main program ---------------- %
141 % We process the command line in two passes. In the first pass,
142 % we read and expand any @-files as necessary. The second pass
143 % does the real work.
149 % Process the GS_OPTIONS environment variable.
150 (GS_OPTIONS) getenv { 0 () /SubFileDecode filter expandargfile } if
151 % Process the actual command line.
152 .getargv { expandarg } forall
153 ] readonly /argv exch def
154 % Now interpret the commands.
155 { nextarg not { exit } if
156 dup 0 get (-) 0 get eq
158 { pop (%stdin) (r) file runjob
161 { dup dup length 2 sub 2 exch getinterval exch 1 1 getinterval }
162 if currentdict .knownget
165 { (Ignoring unknown switch ) print
166 dup length 1 eq { (-) print print } if print