summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlgs/lib/gs_cmdl.ps
blob: 848b5c73a3e5402899360208458cf5a215047540 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
%    Copyright (C) 1994, 1996, 1999 Aladdin Enterprises.  All rights reserved.
%
% This software is provided AS-IS with no warranty, either express or
% implied.
%
% This software is distributed under license and may not be copied,
% modified or distributed except as expressly authorized under the terms
% of the license contained in the file LICENSE in this distribution.
%
% For more information about licensing, please refer to
% http://www.ghostscript.com/licensing/. For information on
% commercial licensing, go to http://www.artifex.com/licensing/ or
% contact Artifex Software, Inc., 101 Lucas Valley Road #110,
% San Rafael, CA  94903, U.S.A., +1(415)492-9861.

% $Id$
% Parse and execute the command line.
% C code handles the following switches: -h/-? -I -M -v

/cmddict 50 dict def
cmddict begin

% ---------------- Utility procedures ---------------- %

% Get the next argument from the parsed argument list.
/nextarg		% - nextarg <arg> true
                        % - nextarg false
 { argv length 0 eq
    { false }
    { argv dup 0 get exch dup length 1 sub 1 exch getinterval /argv exch def }
   ifelse
 } bind def

% Run a file, under job control if implemented.
/runjob			% <file> runjob -
 { end		% cmddict
   /startjob where { pop false () startjob pop }
   run
   //cmddict begin
 } bind def
/runfilejob		% <filename> runfilejob -
 { findlibfile { exch pop } { (r) file } runjob
 } bind def

% Expand arguments.  Free variables: expand@.
/expandarg		% <string> expandarg <args...>
 { dup () eq
    { pop
    }
    { dup dup (--) eq exch (-+) eq or
       { pop /expand@ false def
       }
       { expand@ { (@) anchorsearch } { false } ifelse
          { pop findlibfile
             { exch pop }
             { (r) file }		% let the error happen
            expandargfile
          }
         if
       }
      ifelse
    }
 } bind def
/expandargfile		% <file> expandargfile <args...>
 { [ exch cvlit
    { token not { exit } if
      dup type /stringtype ne { =string cvs dup length string copy } if
      expandarg
    }
   /exec cvx
   ] cvx loop
 } bind def

% ---------------- Recognized switches ---------------- %

% Switches with arguments are defined as <x>;
% switches without arguments are defined as -<x>.

% Switches without arguments
/--
 { nextarg not
    { (-- and -+ require a file name.) = flush }
    { //systemdict /ARGUMENTS argv put /argv [] def runjob }
   ifelse
 } bind def
/-+ /-- load def
/-@ /-- load def
/-A { (@) Z } bind def
/-c
 {  { argv length 0 eq { exit } if
      argv 0 get (-) anchorsearch { pop pop exit } if
      pop nextarg token
       { exch pop			% Probably should check for empty.
         end exec //cmddict begin
       }
      if
    }
   loop
 } bind def
/-e { (#) Z } bind def
/-E /-e load def
/-f { } def
/-q { //systemdict /QUIET true put } bind def

% Switches with arguments
/d
 { (=) search not { (#) search not { () exch dup } if } if
   exch pop cvn dup where
    { pop (Redefining ) print print ( is not allowed.) = flush pop }
    { exch token
       { exch pop }		% Probably should check for empty.
       { true }
      ifelse
      //systemdict 3 1 roll put
    }
   ifelse
 } bind def
/D /d load def
/f { dup length 0 ne { runfilejob } if } bind def
/g
 { (x) search { cvi pop exch cvi } { cvi dup } ifelse
   //systemdict begin /DEVICEHEIGHT exch def /DEVICEWIDTH exch def end
 } bind def
/r
 { (x) search { cvr pop exch cvr } { cvr dup } ifelse
   //systemdict begin /DEVICEYRESOLUTION exch def /DEVICEXRESOLUTION exch def end
 } bind def
/s
 { (=) search not { (#) search not { () exch dup } if } if
   exch pop cvn dup where { pop dup load } { () } ifelse
   type /stringtype ne
    { (Redefining ) print print ( is not allowed.) = flush pop }
    { exch //systemdict 3 1 roll put }
   ifelse
 } bind def
/S /s load def
/Z { true .setdebug } bind def

% ---------------- Main program ---------------- %

% We process the command line in two passes.  In the first pass,
% we read and expand any @-files as necessary.  The second pass
% does the real work.

/cmdstart
 { //cmddict begin
   /expand@ true def
   [
                % Process the GS_OPTIONS environment variable.
   (GS_OPTIONS) getenv { 0 () /SubFileDecode filter expandargfile } if
                % Process the actual command line.
   .getargv { expandarg } forall
   ] readonly /argv exch def
                % Now interpret the commands.
    { nextarg not { exit } if
      dup 0 get (-) 0 get eq
       { dup length 1 eq
          { pop (%stdin) (r) file runjob
          }
          { dup length 2 gt
             { dup dup length 2 sub 2 exch getinterval exch 1 1 getinterval }
            if currentdict .knownget
             { exec
             }
             { (Ignoring unknown switch ) print
               dup length 1 eq { (-) print print } if print
               () = flush
             }
            ifelse
          }
         ifelse
       }
       { runfilejob
       }
      ifelse
    }
   loop end
 } bind def

end		% cmddict