home *** CD-ROM | disk | FTP | other *** search
- % Copyright (C) 1992, 1993 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.
-
- % mergeini.ps - utility for merging all the Ghostscript initialization files
- % (gs_*.ps) into a single file, optionally converting them to C data.
-
- /infile { findlibfile { exch pop } { (r) file } ifelse } def
- /lstring =string length string def
- /rl { in lstring readline } def
- /wcstring 3 string def
- /wl
- { toC
- { 0 exch
- { wcstring cvs out exch writestring out (,) writestring
- 1 add dup 20 eq { out (\n) writestring pop 0 } if
- } forall
- pop (10,)
- }
- if out exch writestring out (\n) writestring
- } def
-
- /merge % <in_name> <out_name> <squash> <C>
- { /C exch def
- /squash exch def
- exch infile /in exch def
- (w) file /out exch def
- /toC false def
-
- % Copy comments up to the first blank line,
- % since this is the legal notice for the file.
- C
- { (/*) wl
- { rl pop dup () eq { pop exit } if wl
- }
- loop
- (*/) wl
- () wl
- (/* Pre-compiled initialization string for Ghostscript. */) wl
- (#include "stdpre.h") wl
- () wl
- (const byte gs_ccinit_string[] = {) wl
- /toC true def
- }
- { { rl pop dup wl
- () eq { exit } if
- }
- loop
- }
- ifelse
-
- in mergefile
- C
- { /toC false def
- (10};) wl
- (const uint gs_ccinit_string_sizeof = sizeof\(gs_ccinit_string\);) wl
- }
- if
- out closefile
- } def
-
- /strip % <string> strip <string>
- { { ( ) anchorsearch
- { pop }
- { (\t) anchorsearch { pop } { exit } ifelse }
- ifelse
- }
- loop
- } def
-
- /doit % <string> -> <string> true | false
- { % We use loop and exit to avoid deeply nested conditionals.
- { squash not { true exit } if
- strip dup () eq { pop false exit } if
- dup (%END) anchorsearch { pop pop true exit } if pop
- (%) anchorsearch { pop pop false exit } if
- dup (%) search
- { exch pop exch (\)) search
- { pop pop pop }
- { pop exch }
- ifelse
- }
- if pop
- true exit
- } loop
- } def
-
- /mergefile % <in_file>
- { /in exch def
- { rl not { pop exit } if
- (%% Replace ) anchorsearch
- { pop
- in exch
- token pop % # of lines
- exch token pop exch pop % file name or list name
- exch
- { rl pop pop }
- repeat
- exec dup type /stringtype eq { [ exch ] } if
- { infile mergefile
- }
- forall
- /in exch def
- }
- { doit { wl } if
- }
- ifelse
- } loop
- in closefile
- } def
-
- % Check for C conversion requested from the command line.
- /Cfile where
- { pop (gs_init.ps) Cfile true true merge }
- { (gs_init.ps) (gs_xinit.ps) true false merge }
- ifelse
- quit
-