program SELECT ( 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.   *)
 
label	99;
 
type TEXT = file of char;
 
var   FILNAM,SEARCHED,PACKFILE: 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;   PACKFILE:='                     ';
 ATTACH( tty );
 read ( tty, PACKFILE );
 loop
 reset( input, PACKFILE );
 if eof(input) then writeln( tty, PACKFILE, 'not found' )
 else
  begin   SEARCHED := '                     ';
   write(tty,'Searched file: ');  break;  readln(tty);
  end;
 exit if eof(input) or eoln(tty);
   read ( tty, SEARCHED );
     loop
	read ( FILNAM );
     exit if (SEARCHED = FILNAM) or eof(input);
	while (input^ # '*') and not eof(input) do readln;
	readln;
     end;
   if eof(input) then
     begin writeln(tty,SEARCHED,'not found'); goto 99 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;
99:
  end;
end.
