]> git.ipfire.org Git - thirdparty/cups.git/blob - pstoraster/gs_cmdl.ps
Import cups.org releases
[thirdparty/cups.git] / pstoraster / gs_cmdl.ps
1 % Copyright (C) 1994, 1996 Aladdin Enterprises. All rights reserved.
2 %
3 % This file is part of GNU Ghostscript.
4 %
5 % GNU Ghostscript is distributed in the hope that it will be useful, but
6 % WITHOUT ANY WARRANTY. No author or distributor accepts responsibility to
7 % anyone for the consequences of using it or for whether it serves any
8 % particular purpose or works at all, unless he says so in writing. Refer to
9 % the GNU General Public License for full details.
10 %
11 % Everyone is granted permission to copy, modify and redistribute GNU
12 % Ghostscript, but only under the conditions described in the GNU General
13 % Public License. A copy of this license is supposed to have been given to
14 % you along with GNU Ghostscript so you can know your rights and
15 % responsibilities. It should be in a file named COPYING. Among other
16 % things, the copyright notice and this notice must be preserved on all
17 % copies.
18 %
19 % Aladdin Enterprises is not affiliated with the Free Software Foundation or
20 % the GNU Project. GNU Ghostscript, as distributed by Aladdin Enterprises,
21 % does not depend on any other GNU software.
22
23 % Parse and execute the command line.
24 % C code handles the following switches: -h/-? -I -M -v
25
26 /cmddict 50 dict def
27 cmddict begin
28
29 % ---------------- Utility procedures ---------------- %
30
31 % Get the next argument from the parsed argument list.
32 /nextarg % - nextarg <arg> true
33 % - nextarg false
34 { argv length 0 eq
35 { false }
36 { argv dup 0 get exch dup length 1 sub 1 exch getinterval /argv exch def }
37 ifelse
38 } bind def
39
40 % Run a file, under job control if implemented.
41 /runjob % <file> runjob -
42 { end % cmddict
43 /startjob where { pop false () startjob pop }
44 run
45 //cmddict begin
46 } bind def
47 /runfilejob % <filename> runfilejob -
48 { findlibfile { exch pop } { (r) file } runjob
49 } bind def
50
51 % Expand arguments. Free variables: expand@.
52 /expandarg % <string> expandarg <args...>
53 { dup () eq
54 { pop
55 }
56 { dup dup (--) eq exch (-+) eq or
57 { pop /expand@ false def
58 }
59 { expand@ { (@) anchorsearch } { false } ifelse
60 { pop findlibfile
61 { exch pop }
62 { (r) file } % let the error happen
63 expandargfile
64 }
65 if
66 }
67 ifelse
68 }
69 } bind def
70 /expandargfile % <file> expandargfile <args...>
71 { [ exch cvlit
72 { token not { exit } if
73 dup type /stringtype ne { =string cvs dup length string copy } if
74 expandarg
75 }
76 /exec cvx
77 ] cvx loop
78 } bind def
79
80 % ---------------- Recognized switches ---------------- %
81
82 % Switches with arguments are defined as <x>;
83 % switches without arguments are defined as -<x>.
84
85 % Switches without arguments
86 /--
87 { nextarg not
88 { (-- and -+ require a file name.\n) print flush }
89 { //systemdict /ARGUMENTS argv put /argv [] def runjob }
90 ifelse
91 } bind def
92 /-+ /-- load def
93 /-@ /-- load def
94 /-A { (@) Z } bind def
95 /-c
96 { { argv length 0 eq { exit } if
97 argv 0 get (-) anchorsearch { pop pop exit } if
98 pop nextarg token
99 { exch pop % Probably should check for empty.
100 end exec //cmddict begin
101 }
102 if
103 }
104 loop
105 } bind def
106 /-e { (#) Z } bind def
107 /-E /-e load def
108 /-f { } def
109 /-q { //systemdict /QUIET true put } bind def
110
111 % Switches with arguments
112 /d
113 { (=) search not { (#) search not { () exch dup } if } if
114 exch pop cvn dup where
115 { pop (Redefining ) print print ( is not allowed.\n) print flush pop }
116 { exch token
117 { exch pop } % Probably should check for empty.
118 { true }
119 ifelse
120 //systemdict 3 1 roll put
121 }
122 ifelse
123 } bind def
124 /D /d load def
125 /f { dup length 0 ne { runfilejob } if } bind def
126 /g
127 { (x) search { cvi pop exch cvi } { cvi dup } ifelse
128 //systemdict begin /DEVICEHEIGHT exch def /DEVICEWIDTH exch def end
129 } bind def
130 /r
131 { (x) search { cvr pop exch cvr } { cvr dup } ifelse
132 //systemdict begin /DEVICEYRESOLUTION exch def /DEVICEXRESOLUTION exch def end
133 } bind def
134 /s
135 { (=) search not { (#) search not { () exch dup } if } if
136 exch pop cvn dup where { pop dup load } { () } ifelse
137 type /stringtype ne
138 { (Redefining ) print print ( is not allowed.\n) print flush pop }
139 { exch //systemdict 3 1 roll put }
140 ifelse
141 } bind def
142 /S /s load def
143 /Z { true .setdebug } bind def
144
145 % ---------------- Main program ---------------- %
146
147 % We process the command line in two passes. In the first pass,
148 % we read and expand any @-files as necessary. The second pass
149 % does the real work.
150
151 /cmdstart
152 { //cmddict begin
153 /expand@ true def
154 [
155 % Process the GS_OPTIONS environment variable.
156 (GS_OPTIONS) getenv { 0 () /SubFileDecode filter expandargfile } if
157 % Process the actual command line.
158 .getargv { expandarg } forall
159 ] readonly /argv exch def
160 % Now interpret the commands.
161 { nextarg not { exit } if
162 dup 0 get (-) 0 get eq
163 { dup length 1 eq
164 { pop (%stdin) (r) file runjob
165 }
166 { dup length 2 gt
167 { dup dup length 2 sub 2 exch getinterval exch 1 1 getinterval }
168 if currentdict .knownget
169 { exec
170 }
171 { (Ignoring unknown switch ) print
172 dup length 1 eq { (-) print print } if print
173 (\n) print flush
174 }
175 ifelse
176 }
177 ifelse
178 }
179 { runfilejob
180 }
181 ifelse
182 }
183 loop end
184 } bind def
185
186 end % cmddict