home *** CD-ROM | disk | FTP | other *** search
- % Copyright (C) 1994 Aladdin Enterprises. All rights reserved.
- %
- % This file is part of Aladdin Ghostscript.
- %
- % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author
- % or distributor accepts any responsibility for the consequences of using it,
- % or for whether it serves any particular purpose or works at all, unless he
- % or she says so in writing. Refer to the Aladdin Ghostscript Free Public
- % License (the "License") for full details.
- %
- % Every copy of Aladdin Ghostscript must include a copy of the License,
- % normally in a plain ASCII text file named PUBLIC. The License grants you
- % the right to copy, modify and redistribute Aladdin Ghostscript, but only
- % under certain conditions described in the License. Among other things, the
- % License requires that the copyright notice and this notice be preserved on
- % all copies.
-
- % 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.\n) print 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.\n) print 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.\n) print 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
- (\n) print flush
- }
- ifelse
- }
- ifelse
- }
- { runfilejob
- }
- ifelse
- }
- loop end
- } bind def
-
- end % cmddict
-