program UNPACK ( input, output, tty );
 
(* This program converts the concatenated sources of
   the runtime library into sepate files. Each module
   must start with one line giving the file name and
   end with one line containing '****'.
   Such packing is performed by the program PACK.   *)
 
type TEXT = file of char;
 
var   FILNAM: array (.0..20.) of char;
      I,J,NSTAR: integer;
      C: CHAR;
      EOM: boolean;
 
procedure attach( var f: text );  extern;
 
procedure detach( var f: text );  extern;
 
begin   write( tty, 'Name of packed file: ');   break;
 readln(tty);   J:=0;   FILNAM:='                     ';
 ATTACH( tty );
 while not eoln(ttyin) do
   begin   read(tty,FILNAM(.J.));  J := J+1   end;
 reset( input, FILNAM );
 if eof(input) then writeln( tty, FILNAM, 'not found' )
 else   while not eof(input) do
  begin     FILNAM := '                     ';   I := 0;
   while not eoln(input) and ( I<20 ) do
    begin   read( FILNAM(.I.) );   I := I+1   end;
   readln;     rewrite( output, FILNAM );   EOM := false;
   writeln(tty, FILNAM );
   while not EOM do
    begin        NSTAR := 0;
     for I:=1 to 4 do
      if input^ = '*' then
       begin   NSTAR := NSTAR+1;   get(input)   end;
     if NSTAR = 4 then EOM := true
     else
      begin   for I:=1 to NSTAR do write('*');
       while not eoln(input) do
        begin   read(C);   write(C)   end;
       writeln;
      end;
     readln;
    end;
  end
end.
