{Purpose: Remove two file names from input string, open first	}
{	  as input text file, second as output text file	}
{Input:   string containing two file names separated by blank(s)}
{	  two file descriptors of type TEXT			}
{Output:  first two names are removed from string		}
{	  fin and fout are initialized				}
{Return:  TRUE if both files opened succesfully, else FALSE	}

module get2text;

  external function cpmname(st: string): boolean;


  function g2text(var str: string;
		  var fin, fout: text): boolean;

    var
      name: string;
      ch: char;


    procedure gname;

      var
	i: integer;

      begin  {gname}
	name := '';
	i := 1;
	while (i <= length(str)) and (str[i] = ' ') do
	  i := i + 1;  {skip leading blanks}
	while (i <= length(str)) and (str[i] <> ' ') do
	  begin  {copy up to next blank}
	  ch := str[i];
	  i := i + 1;
	  if ch in ['a'..'z'] then
	    ch := chr(ord(ch) - $20);  {ensure upper case}
	  name := concat(name, ch);
	  end;
	if i > 1 then  {remove name}
	  delete(str, 1, i - 1);
      end;  {gname}

    begin  {g2text}
      g2text := false;  {assume the worst}
      gname;  {get input file name}
      assign(fin, name);
      reset(fin);
      if ioresult = 255 then
	begin
	writeln('Unable to open ', name, ' for input');
	exit
	end;
      gname;  {get output file name}
      if not cpmname(name) then
	begin
	writeln('Illegal CP/M name: ', name);
	exit
	end;
      assign(fout, name);
      rewrite(fout);
      if ioresult = 255 then
	begin
	writeln('Unable to open ', name, ' for output');
	exit
	end;
      g2text := true
    end;

modend .
