 an external file.
                % Stack for pattern procedures: infile line

/CSRName OutDot (CSR) concatstrings def
/csr CSRName (w) file def
QUIET not { (Writing ) print CSRName = flush } if

/encoding 256 array def

/patterns [
                % Patterns specific to the Roman supplement, in which
                % the outlines are in an eexec section.
 { (/Encoding 256 array) {
   pop out (/Encoding ) writestring
    { dup buffer readline pop
      dup (dup) search { exit } if pop pop
    }
   loop
    {	% Stack: infile dupline postdup (dup) predup
      pop pop exch pop
        % The top element of the stack is a string beginning with
        % an index and value to put into the Encoding.
      token pop exch token pop exch pop encoding 3 1 roll put
      dup buffer readline pop
      dup (dup) search not { pop exit } if
    }
   loop
   out encoding cvx write== out ( cvlit ) writestring
   out exch writestring out (\n) writestring
 } }
 { (/FontType 1 def) {
   pop out (/FontType 4 def\n) writestring
   out (/BuildChar{AltsysCFD3 begin BuildChr end}bind def\n) writestring
   out (/FileNames[) writestring
   2 { out OutBase (.CSR) concatstrings write==only } repeat
   out (]def\n) writestring
 } }
 { (currentfile eexec) {
   pop out (systemdict begin\n) writestring
   dup //.eexec_param_dict /eexecDecode filter
 } }
 { (dup/CharStrings ) {
        % Copy the individual CharStrings to the CSR file,
        % recording the lengths and offsets.
   pop out (dup/CharStrings AltsysCFD3 /CharStrings get put\n) writestring
   /offsets 256 dict def
    { dup token pop		% char name
      dup dup type /nametype eq exch xcheck not and not { pop exit } if
      1 index token pop		% length of binary data
      2 index token pop pop	% skip RD
      2 index buffer 0 3 index getinterval readstring pop	% charstring
      offsets 3 index csr fileposition 16 bitshift 4 index add put
      csr exch writestring pop pop
      dup buffer readline pop pop	% skip ND
    }
   loop
        % We skipped the 'end'; skip the 'readonly put' as well.
   2 { dup token pop pop } repeat
   out (dup/PGOffsets ) writestring
     out csr fileposition write=only
     out ( put\n) writestring
   encoding
    { offsets exch .knownget not { 0 } if
      2 { csr 0 write } repeat
      4 { dup -24 bitshift csr exch write 8 bitshift } repeat pop
    }
   forall
 } }
 { (/OtherSubrs[) {
   pop
    { dup buffer readline pop
      (]noaccess def) search { pop pop pop exit } if pop
    }
   loop
 } }
 { (/Subrs 5 array) {
   pop out (/Subrs AltsysCFD3 /Subrs get def\n) writestring
   6 { dup buffer readline pop pop } repeat
 } }
 { (currentfile closefile) {
   pop out (end % systemdict\n) writestring
   closefile
 } }
                % Patterns for other supplements.
 { (pgfonts/) {
    { cdfromstr search not { exit } if
      out exch writestring pop out cdstr writestring
    }
   loop out exch writestring out (\n) writestring
 } }
 { (/BuildChar{AltsysCFD3 begin 64 BuildCh end}bind def) {
   pop out (\t/BuildChar AltsysCFD3 /BuildChar get def\n) writestring
 } }
 { (/CDevProc{pop pop pop pop 0 exch -1000 exch 2 div ) {
   pop out (\t/CDevProc AltsysCFD3 /CDevProc get def\n) writestring
 } }
 { (/CharStrings 1 dict dup begin) {
   pop out (\t/CharStrings AltsysCFD3 /CharStrings get def\n) writestring
   2 { dup buffer readline pop pop } repeat
 } }
 { (/FontMatrix[0.001 0.0 0.0 0.001 0.0 0.0]def) {
   pop out (\t/FontMatrix AltsysCFD3 /FontMatrix get def\n) writestring
 } }
 { (/Private 14 dict dup begin) {
   pop out (\t/Private) writestring
    { dup buffer readline pop
      (end def) search { pop pop pop exit } if
      (/Std) search
       { pop pop dup length 3 sub 3 exch getinterval
         (]) search pop out ( ) writestring out exch writestring pop
       }
      if pop
    }
   loop out ( AltsysCFD3 begin BuildPr end def\n) writestring
 } }
 { (UniqueID) { pop } }
 { () {
   out exch writestring out (\n) writestring
 } }
] def
[ (SR) (SA) (SK) (SB) (UG) ]
 { 0 1 255 { encoding exch /.notdef put } for
   inprefix exch concatstrings macrfile
    { dup buffer readline not { pop exit } if
      /patterns load
       { 2 copy 0 get search { pop pop pop 1 get exec exit } if pop pop }
      forall
    }
   loop closefile
 }
forall
csr closefile

                % Copy the definition of the root font.

dup buffer readstring pop out exch writestring closefile
out (
setpacking
) writestring
out closefile

                % Remove the Mac garbage from the outline files.

[ (COD) (CSA) ]
 { CDir (/) concatstrings (JIS83-1_) concatstrings
     1 index concatstrings macrfile
   exch OutDot exch concatstrings
     QUIET not { (Writing ) print dup = flush } if
     (w) file
                % Stack: infile outfile
    { 1 index buffer readstring exch
                % Stack: infile outfile noteof substring
      2 index exch writestring not { exit } if
    }
   loop closefile closefile
 }
forall

 } bind def

% If the program was invoked from the command line, run it now.
[ .shellarguments
 { counttomark 5 eq
    { convert
      QUIET not { (Done.\n) print flush } if
    }
    { cleartomark
      (Usage: gsnd -- rollconv.ps FName OutBase InDir CDir OutDir\n) print
      ( e.g.: gsnd -- rollconv.ps HGMinchoE mincho HGfonts/Mincho HGfonts/Mincho HGfonts/gs\n) print flush
      mark
    }
   ifelse
 }
if pop
