home *** CD-ROM | disk | FTP | other *** search
/ swCHIP 1991 January / swCHIP_95-1.bin / utility / gs333ini / gs3.33 / mergeini.ps < prev    next >
Text File  |  1995-12-09  |  4KB  |  160 lines

  1. %    Copyright (C) 1992, 1993, 1994 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % mergeini.ps - utility for merging all the Ghostscript initialization files
  16. % (gs_*.ps) into a single file, optionally converting them to C data.
  17.  
  18. /infile { findlibfile { exch pop } { (r) file } ifelse } def
  19. /lstring =string length string def
  20. /rl { in lstring readline } def
  21. /wcstring 3 string def
  22. /wl
  23.  { toC
  24.     { 0 exch
  25.        { wcstring cvs out exch writestring out (,) writestring
  26.      1 add dup 20 eq { out (\n) writestring pop 0 } if
  27.        } forall
  28.       pop (10,)
  29.     }
  30.    if out exch writestring out (\n) writestring
  31.  } def
  32.  
  33. /merge            % <in_name> <out_name> <squash> <C>
  34.  { /C exch def
  35.    /squash exch def
  36.    exch infile /in exch def
  37.    (w) file /out exch def
  38.    /toC false def
  39.  
  40.         % Copy comments up to the first blank line,
  41.         % since this is the legal notice for the file.
  42.    C
  43.     { (/*) wl
  44.        { rl pop dup () eq { pop exit } if wl
  45.        }
  46.       loop
  47.       (*/) wl
  48.       () wl
  49.       (/* Pre-compiled initialization string for Ghostscript. */) wl
  50.       (#include "stdpre.h") wl
  51.       () wl
  52.       (const byte gs_ccinit_string[] = {) wl
  53.       /toC true def
  54.     }
  55.     {  { rl pop dup wl
  56.      () eq { exit } if
  57.        }
  58.       loop
  59.     }
  60.    ifelse
  61.  
  62.    in mergefile
  63.    C
  64.     { /toC false def
  65.       (10};) wl
  66.       (const uint gs_ccinit_string_sizeof = sizeof\(gs_ccinit_string\);) wl
  67.     }
  68.    if
  69.    out closefile
  70.  } def
  71.  
  72. /strip            % <string> strip <string>
  73.  {  { ( ) anchorsearch
  74.        { pop }
  75.        { (\t) anchorsearch { pop } { exit } ifelse }
  76.       ifelse
  77.     }
  78.    loop
  79.  } def
  80.  
  81. /doit            % <string> -> <string> true | false
  82.  {    % We use loop and exit to avoid deeply nested conditionals.
  83.     { squash not { true exit } if
  84.       strip dup () eq { pop false exit } if
  85.       dup (%END) anchorsearch { pop pop true exit } if pop
  86.       (%) anchorsearch { pop pop false exit } if
  87.       dup (%) search
  88.        { exch pop exch (\)) search
  89.           { pop pop pop }
  90.       { pop exch }
  91.      ifelse
  92.        }
  93.       if pop
  94.       true exit
  95.     } loop
  96.  } def
  97.  
  98. /mergefile        % <in_file>
  99.  { /in exch def
  100.     { rl not { pop exit } if
  101.       (%% Replace ) anchorsearch
  102.        { pop
  103.          in exch
  104.          token pop            % # of lines
  105.      exch token pop exch pop    % file name or list name
  106.      exch
  107.           { rl pop pop }
  108.      repeat
  109.      exec dup type /stringtype eq { [ exch ] } if
  110.       { infile mergefile
  111.       }
  112.      forall
  113.      /in exch def
  114.        }
  115.        { doit { wl } if
  116.        }
  117.       ifelse
  118.     } loop
  119.    in closefile
  120.  } def
  121.  
  122. % If the program was invoked from the command line, run it now.
  123. % The various invocation methods are:
  124. %    mergeini.ps
  125. %    -sCfile=<C-file> mergeini.ps
  126. %    -- mergeini.ps <orig-init-file> <merged-init-file>
  127. %    -sCfile=<C-file> -- mergeini.ps <orig-init-file>
  128.  
  129. [ shellarguments
  130.  { counttomark dup 2 eq
  131.     { pop true false
  132.     }
  133.     { 1 eq /Cfile where { pop true } { false } ifelse and
  134.        { Cfile true true
  135.        }
  136.        { cleartomark
  137.      (Usage: gs [-sCfile=<C-file>] mergeini.ps\n) print
  138.      (   or: gs -sCfile=<C-file> -- mergeini.ps <orig-init-file>\n) print
  139.      (   or: gs -- mergeini.ps <orig-init-file> <merged-init-file>\n) print
  140.      flush quit
  141.        }
  142.       ifelse
  143.     }
  144.    ifelse
  145.  }
  146.  { /Cfile where
  147.     { pop (gs_init.ps) Cfile true true }
  148.     { (gs_init.ps) (gs_xinit.ps) true false }
  149.    ifelse
  150.  }
  151. ifelse
  152. (Merging ) print 3 index print
  153. ( to ) print 2 index print ( ... ) print flush
  154. merge pop
  155. (Done.\n) print flush
  156. quit
  157.