{%%%%%%%%%%%%%%%%%%% copyright 1984 by Neil J. Rubenking %%%%%%%%%%%%%%%%%%%

driver for procedure ALLFILES.  Pass upper left and lower right corners
of a window to ALLFILES, along with a template of the required files.
ALLFILES returns the selected fileNAME, or an error code.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
{$I filename.typ}
{$I regpack.typ}
{$I getkeys.lib}
{$I monitor.lib}
{$I screen.lib}
{$I getfile.lib}
{$I allfiles.lib}

var
  error_return,
  x1,y1,x2,y2 : byte;
  FullPath,
  template    : filename_type;

{@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
function lastPos(C: char; S:filename_type):byte;
var
  temp, holder : byte;
begin
  temp := 0;
  while pos(C,S) <> 0 do
    begin
      temp := temp + pos(C,S);
      delete(S,1,pos(C,S));
    end;
  lastPos := temp;
end;
{@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}

begin
  CheckColor;  {in order to use the procedures in SCREEN.LIB, you must
                   first set the value of SCREENSEG by doing CheckColor}
  Write('Enter the upper left column for choice window (2 to 43): ');
  read(x1);WriteLn;
  Write('Enter the upper left row for choice window (3 to 20) : ');
  read(y1);WriteLn;
  Write('Enter the lower right column for choice window: (');
  Write(x1+36,' to 79)');
  read(x2);WriteLn;
  Write('Enter the lower right row for choice window: (');
  Write(y1+3,' to 23)');
  read(y2);WriteLn;
  if (x1 < x2) and (y1 < y2) and (x1 in [2..43]) and ( y1 in [3..22]) and
      (x2 in [(x1+36)..79]) and (y2 in [(y1+3)..23]) then
    begin
      ClrScr;
      WriteLn('Enter the template for files from which you want to select.');
      WriteLn('Full PathNames are fine.  e.g., d:\accounts\overdue\*.*,');
      WriteLn('C:\programs\*.bas, and so on.');
      Write('->');ReadLn(template);
      FullPath := template;
      if lastPos('\',FullPath) <> 0 then
        FullPath := copy(FullPath,1,lastPos('\',FullPath))
      else
        if pos(':',FullPath) <> 0 then
          FullPath := copy(FullPath,1,2)
        else FullPath := '';
      ClrScr;
      AllFiles(x1,y1,x2,y2,template,error_return);
      GotoXY(1,1);
      if error_return = 0 then
        WriteLn(FullPath,template,' has been selected.')
      else WriteLn('Error--no such files available.');
    end
  else WriteLn('Invalid set of coordinates.  Try again.');
end.


inter at those      }
      end;                                         {